|
|
@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
@@ -82,7 +83,7 @@ public class TauvWaterDataServiceImpl extends BaseServiceImpl<TauvWaterDataMappe |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional |
|
|
|
public Response importData(MultipartFile file) { |
|
|
|
List<List<Object>> objectList = null; |
|
|
|
try { |
|
|
@@ -90,16 +91,19 @@ public class TauvWaterDataServiceImpl extends BaseServiceImpl<TauvWaterDataMappe |
|
|
|
String[] titleList = new String[]{"*任务单号", "*区属", "*河湖名称", "化学需氧量", "氨氮", "总磷", "总氮", "溶解氧", "浊度"}; |
|
|
|
for (int i = 0; i < titleList.length; i++) { |
|
|
|
if (!titleList[i].equals(headList.get(i))) { |
|
|
|
throw new ApiException("请使用正确的导入模板"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("请使用正确的导入模板"); |
|
|
|
} |
|
|
|
} |
|
|
|
objectList = ExcelUtil.importExcel(file, 0, 0); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure(e.getMessage()); |
|
|
|
} |
|
|
|
if (objectList.size() == 0) { |
|
|
|
throw new ApiException("导入数据不能为空"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("导入数据不能为空"); |
|
|
|
} |
|
|
|
Integer m = 2; |
|
|
|
for (List<Object> data : objectList) { |
|
|
@@ -107,13 +111,16 @@ public class TauvWaterDataServiceImpl extends BaseServiceImpl<TauvWaterDataMappe |
|
|
|
String areaName = data.get(1).toString().trim(); |
|
|
|
String driverName = data.get(2).toString().trim(); |
|
|
|
if (StringUtils.isEmpty(inspectNo)) { |
|
|
|
throw new ApiException("第" + m + "行任务单号不能为空"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("第" + m + "行任务单号不能为空"); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(areaName)) { |
|
|
|
throw new ApiException("第" + m + "行区属不能为空"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("第" + m + "行区属不能为空"); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(driverName)) { |
|
|
|
throw new ApiException("第" + m + "行河湖名称不能为空"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("第" + m + "行河湖名称不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
// 任务校验 |
|
|
@@ -123,7 +130,8 @@ public class TauvWaterDataServiceImpl extends BaseServiceImpl<TauvWaterDataMappe |
|
|
|
inspectWrapper.last("limit 1"); |
|
|
|
TauvInspectDriver inspectDriver = inspectDriverMapper.selectOne(inspectWrapper); |
|
|
|
if (inspectDriver == null) { |
|
|
|
throw new ApiException("第" + m + "行任务单号错误"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("第" + m + "行任务单号错误"); |
|
|
|
} |
|
|
|
// 区属校验 |
|
|
|
QueryWrapper cityWrapper = new QueryWrapper(); |
|
|
@@ -132,7 +140,8 @@ public class TauvWaterDataServiceImpl extends BaseServiceImpl<TauvWaterDataMappe |
|
|
|
cityWrapper.last("limit 1"); |
|
|
|
SysCity city = cityMapper.selectOne(cityWrapper); |
|
|
|
if (city == null) { |
|
|
|
throw new ApiException("第" + m + "行区属错误"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("第" + m + "行区属错误"); |
|
|
|
} |
|
|
|
// 河湖校验 |
|
|
|
QueryWrapper driverWrapper = new QueryWrapper(); |
|
|
@@ -142,7 +151,8 @@ public class TauvWaterDataServiceImpl extends BaseServiceImpl<TauvWaterDataMappe |
|
|
|
driverWrapper.last("limit 1"); |
|
|
|
TauvDriver driver = driverMapper.selectOne(driverWrapper); |
|
|
|
if (driver == null) { |
|
|
|
throw new ApiException("第" + m + "行河湖名称错误"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("第" + m + "行河湖名称错误"); |
|
|
|
} |
|
|
|
// 关系校验 |
|
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
@@ -154,10 +164,12 @@ public class TauvWaterDataServiceImpl extends BaseServiceImpl<TauvWaterDataMappe |
|
|
|
wrapper.last("limit 1"); |
|
|
|
TauvInspectDriver tauvInspectDriver = inspectDriverMapper.selectOne(wrapper); |
|
|
|
if (tauvInspectDriver == null) { |
|
|
|
throw new ApiException("第" + m + "行任务单号、区属、河湖名称关系错误"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("第" + m + "行任务单号、区属、河湖名称关系错误"); |
|
|
|
} |
|
|
|
if (tauvInspectDriver.getStatus() != 4) { |
|
|
|
throw new ApiException("第" + m + "行任务未完成"); |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
return response.failure("第" + m + "行任务未完成"); |
|
|
|
} |
|
|
|
// 判断水质数据表该任务、区属、河湖对应数据是否存在 |
|
|
|
QueryWrapper dataWrapper = new QueryWrapper(); |