Bläddra i källkod

'水环境趋势模拟'

master
daixiantong 4 år sedan
förälder
incheckning
60a380e2dc
8 ändrade filer med 422 tillägg och 0 borttagningar
  1. +90
    -0
      src/main/java/com/taauav/admin/controller/TauvWaterTrendController.java
  2. +75
    -0
      src/main/java/com/taauav/admin/entity/TauvWaterTrend.java
  3. +15
    -0
      src/main/java/com/taauav/admin/mapper/TauvWaterTrendMapper.java
  4. +7
    -0
      src/main/java/com/taauav/admin/mapper/TauvWaterTrendMapper.xml
  5. +29
    -0
      src/main/java/com/taauav/admin/service/ITauvWaterTrendService.java
  6. +188
    -0
      src/main/java/com/taauav/admin/service/impl/TauvWaterTrendServiceImpl.java
  7. +18
    -0
      src/main/java/com/taauav/common/util/FunctionUtils.java
  8. +0
    -0
      src/main/java/trend/Menu.sql

+ 90
- 0
src/main/java/com/taauav/admin/controller/TauvWaterTrendController.java Visa fil

@@ -0,0 +1,90 @@
package com.taauav.admin.controller;

import com.taauav.admin.controller.BaseController;
import com.taauav.common.bean.Response;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.taauav.common.core.mps.BaseQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.taauav.admin.entity.TauvWaterTrend;
import com.taauav.admin.service.ITauvWaterTrendService;
import org.springframework.web.multipart.MultipartFile;


/**
* 水环境趋势模拟Controller
*
* @author daixiantong
* @date 20200515
*/
@RestController
@RequestMapping("/admin/trend")
public class TauvWaterTrendController extends BaseController
{
@Autowired
private ITauvWaterTrendService tauvWaterTrendService;

@Autowired
private Response response;
/**
* 查询水环境趋势模拟列表
*/
@RequiresPermissions("admin:trend:list")
@GetMapping("/list")
public Response list(TauvWaterTrend tauvWaterTrend, BaseQuery query)
{
return tauvWaterTrendService.pageData(query,tauvWaterTrend);
}



/**
* 获取水环境趋势模拟详细信息
*/
@RequiresPermissions("admin:trend:query")
@GetMapping(value = "/{id}")
public Response getInfo(@PathVariable("id") Integer id)
{
return tauvWaterTrendService.getTrendList(id);
}

/**
* 新增水环境趋势模拟
*/
@RequiresPermissions("admin:trend:add")
@PostMapping
public Response add(@RequestBody TauvWaterTrend tauvWaterTrend)
{
return response.success(tauvWaterTrendService.save(tauvWaterTrend));
}

/**
* 修改水环境趋势模拟
*/
@RequiresPermissions("admin:trend:edit")
@PutMapping
public Response edit(@RequestBody TauvWaterTrend tauvWaterTrend)
{
return response.success(tauvWaterTrendService.updateById(tauvWaterTrend));
}

/**
* 删除水环境趋势模拟
*/
@RequiresPermissions("admin:trend:remove")
@DeleteMapping("/{ids}")
public Response remove(@PathVariable Integer[] ids)
{
return response.success(tauvWaterTrendService.deleteByIds(ids, new TauvWaterTrend()));
}

/**
* 导入趋势数据
* @param file
* @return
*/
@PostMapping("/import")
public Response importExcel(@RequestParam("file") MultipartFile file) {
return tauvWaterTrendService.importTrend(file);
}
}

+ 75
- 0
src/main/java/com/taauav/admin/entity/TauvWaterTrend.java Visa fil

@@ -0,0 +1,75 @@
package com.taauav.admin.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.taauav.common.domain.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;

/**
* 水环境趋势模拟对象 tauv_water_trend
*
* @author daixiantong
* @date 20200515
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class TauvWaterTrend extends Entity {

private static final long serialVersionUID = 1L;

/**
* 趋势编号
*/
private String trendCode;
/**
* 区属id
*/
private BigInteger driverArea;
/**
* 区属名称
*/
private String areaName;
/**
* 河湖id
*/
private Integer driverId;
/**
* 河湖名称
*/
private String driverName;
/**
* 预测日期
*/
@JsonFormat(pattern = "yyyy-MM-dd")
private Date forecastTime;
/**
* 化学需氧量
*/
private BigDecimal waterCod;
/**
* 氨氮
*/
private BigDecimal waterNh3n;
/**
* 总磷
*/
private BigDecimal waterTp;
/**
* 总氮
*/
private BigDecimal waterTn;
/**
* 溶解氧
*/
private BigDecimal waterDo;
/**
* 浊度
*/
private BigDecimal waterTub;
}

+ 15
- 0
src/main/java/com/taauav/admin/mapper/TauvWaterTrendMapper.java Visa fil

@@ -0,0 +1,15 @@
package com.taauav.admin.mapper;

import com.taauav.admin.entity.TauvWaterTrend;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
* 水环境趋势模拟Mapper接口
*
* @author daixiantong
* @date 20200515
*/
public interface TauvWaterTrendMapper extends BaseMapper<TauvWaterTrend>
{

}

+ 7
- 0
src/main/java/com/taauav/admin/mapper/TauvWaterTrendMapper.xml Visa fil

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.taauav.admin.mapper.TauvWaterTrendMapper">

</mapper>

+ 29
- 0
src/main/java/com/taauav/admin/service/ITauvWaterTrendService.java Visa fil

@@ -0,0 +1,29 @@
package com.taauav.admin.service;

import com.taauav.admin.entity.TauvWaterTrend;
import com.taauav.common.bean.Response;
import com.taauav.common.service.IBaseService;
import org.springframework.web.multipart.MultipartFile;

/**
* 水环境趋势模拟Service接口
*
* @author daixiantong
* @date 20200515
*/
public interface ITauvWaterTrendService extends IBaseService<TauvWaterTrend>
{
/**
* 导入Excel数据
* @param file
* @return
*/
Response importTrend(MultipartFile file);

/**
* 获取趋势图数据
* @param id
* @return
*/
Response getTrendList(Integer id);
}

+ 188
- 0
src/main/java/com/taauav/admin/service/impl/TauvWaterTrendServiceImpl.java Visa fil

@@ -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);
}
}

+ 18
- 0
src/main/java/com/taauav/common/util/FunctionUtils.java Visa fil

@@ -479,4 +479,22 @@ public class FunctionUtils {
}
return newMap;
}
/**
* 字符串转日期
* @return
*/
public static Date strToDate(String str, String formatStr) {
if (StringUtils.isEmpty(formatStr)) {
formatStr = "yyyy-MM-dd HH:mm:ss";
}
SimpleDateFormat format = new SimpleDateFormat(formatStr);
Date date = null;
try {
date = format.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
}

+ 0
- 0
src/main/java/trend/Menu.sql Visa fil


Laddar…
Avbryt
Spara