|
|
@@ -0,0 +1,188 @@ |
|
|
|
package com.taauav.admin.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.exceptions.ApiException; |
|
|
|
import com.taauav.admin.entity.SysCity; |
|
|
|
import com.taauav.admin.entity.TauvDriver; |
|
|
|
import com.taauav.admin.mapper.SysCityMapper; |
|
|
|
import com.taauav.admin.mapper.TauvDriverMapper; |
|
|
|
import com.taauav.common.bean.Response; |
|
|
|
import com.taauav.common.service.impl.BaseServiceImpl; |
|
|
|
import com.taauav.common.util.*; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.taauav.admin.mapper.TauvWaterTrendMapper; |
|
|
|
import com.taauav.admin.entity.TauvWaterTrend; |
|
|
|
import com.taauav.admin.service.ITauvWaterTrendService; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* 水环境趋势模拟Service业务层处理 |
|
|
|
* |
|
|
|
* @author daixiantong |
|
|
|
* @date 20200515 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class TauvWaterTrendServiceImpl extends BaseServiceImpl<TauvWaterTrendMapper, TauvWaterTrend> implements ITauvWaterTrendService { |
|
|
|
@Autowired |
|
|
|
private Response response; |
|
|
|
@Autowired |
|
|
|
private SysCityMapper cityMapper; |
|
|
|
@Autowired |
|
|
|
private TauvDriverMapper driverMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入Excel数据 |
|
|
|
* |
|
|
|
* @param file |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Response importTrend(MultipartFile file) { |
|
|
|
List<List<Object>> objectList = null; |
|
|
|
try { |
|
|
|
List<String> headList = ExcelUtil.getHeadList(file, 0, 0); |
|
|
|
String[] titleList = new String[]{"*区属", "*河湖名称", "*预测时间", "化学需氧量", "氨氮", "总磷", "总氮", "溶解氧", "浊度"}; |
|
|
|
for (int i = 0; i < titleList.length; i++) { |
|
|
|
if (!titleList[i].equals(headList.get(i))) { |
|
|
|
throw new ApiException("请使用正确的导入模板"); |
|
|
|
} |
|
|
|
} |
|
|
|
objectList = ExcelUtil.importExcel(file, 0, 0); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
return response.failure(e.getMessage()); |
|
|
|
} |
|
|
|
if (objectList.size() == 0) { |
|
|
|
throw new ApiException("导入数据不能为空"); |
|
|
|
} |
|
|
|
Integer m = 2; |
|
|
|
for (List<Object> data : objectList) { |
|
|
|
String areaName = data.get(0).toString().trim(); |
|
|
|
String driverName = data.get(1).toString().trim(); |
|
|
|
String trendTime = data.get(2).toString().trim(); |
|
|
|
String waterCod = data.get(3).toString().trim(); |
|
|
|
String waterNh3n = data.get(4).toString().trim(); |
|
|
|
String waterTp = data.get(5).toString().trim(); |
|
|
|
String waterTn = data.get(6).toString().trim(); |
|
|
|
String waterDo = data.get(7).toString().trim(); |
|
|
|
String waterTub = data.get(8).toString().trim(); |
|
|
|
if (StringUtils.isEmpty(areaName)) { |
|
|
|
throw new ApiException("第" + m + "行区属不能为空"); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(driverName)) { |
|
|
|
throw new ApiException("第" + m + "行河湖名称不能为空"); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(trendTime)) { |
|
|
|
throw new ApiException("第" + m + "行预测时间不能为空"); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(waterCod) && StringUtils.isEmpty(waterNh3n) && StringUtils.isEmpty(waterTp) && |
|
|
|
StringUtils.isEmpty(waterTn) && StringUtils.isEmpty(waterDo) && StringUtils.isEmpty(waterTub)) { |
|
|
|
throw new ApiException("第" + m + "行六个水质数据指标不能全部为空"); |
|
|
|
} |
|
|
|
// 区属校验 |
|
|
|
QueryWrapper cityWrapper = new QueryWrapper(); |
|
|
|
cityWrapper.eq("mark", 1); |
|
|
|
cityWrapper.eq("name", areaName); |
|
|
|
cityWrapper.last("limit 1"); |
|
|
|
SysCity city = cityMapper.selectOne(cityWrapper); |
|
|
|
if (city == null) { |
|
|
|
throw new ApiException("第" + m + "行区属错误"); |
|
|
|
} |
|
|
|
// 河湖校验 |
|
|
|
QueryWrapper driverWrapper = new QueryWrapper(); |
|
|
|
driverWrapper.eq("mark", 1); |
|
|
|
driverWrapper.eq("name", driverName); |
|
|
|
driverWrapper.eq("driver_area", city.getId()); |
|
|
|
driverWrapper.last("limit 1"); |
|
|
|
TauvDriver driver = driverMapper.selectOne(driverWrapper); |
|
|
|
if (driver == null) { |
|
|
|
throw new ApiException("第" + m + "行河湖名称错误"); |
|
|
|
} |
|
|
|
// 唯一性校验 |
|
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|
wrapper.eq("driver_area", city.getId()); |
|
|
|
wrapper.eq("driver_id", driver.getId()); |
|
|
|
wrapper.eq("trend_time", trendTime); |
|
|
|
wrapper.last("limit 1"); |
|
|
|
TauvWaterTrend waterTrend = getOne(wrapper); |
|
|
|
if (waterTrend == null) { |
|
|
|
waterTrend = new TauvWaterTrend(); |
|
|
|
waterTrend.setTrendCode(createTrendCode()); |
|
|
|
waterTrend.setCreateUser(ShiroUtils.getAdminId()); |
|
|
|
waterTrend.setCreateTime(DateUtil.now()); |
|
|
|
} else { |
|
|
|
waterTrend.setUpdateUser(ShiroUtils.getAdminId()); |
|
|
|
waterTrend.setUpdateTime(DateUtil.now()); |
|
|
|
} |
|
|
|
waterTrend.setDriverArea(city.getId()); |
|
|
|
waterTrend.setAreaName(city.getName()); |
|
|
|
waterTrend.setDriverId(driver.getId()); |
|
|
|
waterTrend.setDriverName(driverName); |
|
|
|
waterTrend.setForecastTime(FunctionUtils.strToDate(trendTime, "yyyy-MM-dd")); |
|
|
|
if (StringUtils.isNotEmpty(waterCod)) { |
|
|
|
waterTrend.setWaterCod(new BigDecimal(waterCod)); |
|
|
|
} |
|
|
|
if (StringUtils.isNotEmpty(waterNh3n)) { |
|
|
|
waterTrend.setWaterNh3n(new BigDecimal(waterNh3n)); |
|
|
|
} |
|
|
|
if (StringUtils.isNotEmpty(waterTp)) { |
|
|
|
waterTrend.setWaterTp(new BigDecimal(waterTp)); |
|
|
|
} |
|
|
|
if (StringUtils.isNotEmpty(waterTn)) { |
|
|
|
waterTrend.setWaterTn(new BigDecimal(waterTn)); |
|
|
|
} |
|
|
|
if (StringUtils.isNotEmpty(waterDo)) { |
|
|
|
waterTrend.setWaterDo(new BigDecimal(waterDo)); |
|
|
|
} |
|
|
|
if (StringUtils.isNotEmpty(waterTub)) { |
|
|
|
waterTrend.setWaterTub(new BigDecimal(waterTub)); |
|
|
|
} |
|
|
|
Boolean res = saveOrUpdate(waterTrend); |
|
|
|
if (!res) { |
|
|
|
throw new ApiException("第" + m + "行添加失败"); |
|
|
|
} |
|
|
|
m++; |
|
|
|
} |
|
|
|
return response.success("操作成功"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成趋势模拟编号 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String createTrendCode() { |
|
|
|
Calendar date = Calendar.getInstance(); |
|
|
|
String year = String.valueOf(date.get(Calendar.YEAR)).substring(2); |
|
|
|
String month = String.format("%02d", date.get(Calendar.MONTH) + 1); |
|
|
|
String code = "40" + year + month + (int) ((Math.random() * 9 + 1) * 100000); |
|
|
|
return code; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取趋势图数据 |
|
|
|
* @param id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Response getTrendList(Integer id) { |
|
|
|
TauvWaterTrend waterTrend = getInfo(id); |
|
|
|
if (waterTrend == null) { |
|
|
|
return response.failure("趋势模拟数据不存在"); |
|
|
|
} |
|
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|
wrapper.eq("driver_area", waterTrend.getDriverArea()); |
|
|
|
wrapper.eq("driver_id", waterTrend.getDriverId()); |
|
|
|
wrapper.eq("mark", 1); |
|
|
|
List<TauvWaterTrend> list = baseMapper.selectList(wrapper); |
|
|
|
return response.success(list); |
|
|
|
} |
|
|
|
} |