|
@@ -1,11 +1,26 @@
|
|
package com.huimv.admin.service.impl;
|
|
package com.huimv.admin.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.huimv.admin.common.utils.DataUill;
|
|
|
|
+import com.huimv.admin.common.utils.Result;
|
|
|
|
+import com.huimv.admin.common.utils.ResultCode;
|
|
import com.huimv.admin.entity.EnvWarning;
|
|
import com.huimv.admin.entity.EnvWarning;
|
|
|
|
+import com.huimv.admin.entity.vo.WarningCountVo;
|
|
|
|
+import com.huimv.admin.entity.vo.WarningTopVo;
|
|
|
|
+import com.huimv.admin.entity.vo.WarningVo;
|
|
import com.huimv.admin.mapper.EnvWarningMapper;
|
|
import com.huimv.admin.mapper.EnvWarningMapper;
|
|
import com.huimv.admin.service.IEnvWarningService;
|
|
import com.huimv.admin.service.IEnvWarningService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
* 服务实现类
|
|
* 服务实现类
|
|
@@ -16,4 +31,68 @@ import org.springframework.stereotype.Service;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class EnvWarningServiceImpl extends ServiceImpl<EnvWarningMapper, EnvWarning> implements IEnvWarningService {
|
|
public class EnvWarningServiceImpl extends ServiceImpl<EnvWarningMapper, EnvWarning> implements IEnvWarningService {
|
|
|
|
+ @Resource
|
|
|
|
+ private EnvWarningMapper envWarningMapper;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result listCount(Map<String, String> paramsMap) {
|
|
|
|
+ Date timesMonthmorning = DataUill.getTimesMonthmorning();
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+
|
|
|
|
+ String farmId = paramsMap.get("farmId");
|
|
|
|
+ QueryWrapper<EnvWarning> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("farm_id",farmId)
|
|
|
|
+ .ge("update_time",timesMonthmorning);
|
|
|
|
+ Map resultMap = new HashMap();
|
|
|
|
+ List<WarningCountVo> warningCountVos = envWarningMapper.getMonthCount(queryWrapper);
|
|
|
|
+ resultMap.put("data",warningCountVos);
|
|
|
|
+ Integer currentCount = envWarningMapper.getCount(queryWrapper);
|
|
|
|
+ resultMap.put("currentValue",currentCount);
|
|
|
|
+ //上个月
|
|
|
|
+ //获取上个月的第一天
|
|
|
|
+ Calendar cal_1 = Calendar.getInstance();//获取当前日期
|
|
|
|
+ cal_1.add(Calendar.MONTH, -1);
|
|
|
|
+ cal_1.set(Calendar.DAY_OF_MONTH, 1);//设置为1号
|
|
|
|
+ cal_1.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
+ cal_1.set(Calendar.MINUTE, 0);
|
|
|
|
+ cal_1.set(Calendar.SECOND, 0);
|
|
|
|
+ String firstDay = format.format(cal_1.getTime());
|
|
|
|
+ //获取上个月的最后一天
|
|
|
|
+ Calendar cal_2 = Calendar.getInstance();
|
|
|
|
+ cal_2.set(Calendar.DAY_OF_MONTH, 0);//设置为1号,当前日期既为本月第一天
|
|
|
|
+ cal_2.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
|
+ cal_2.set(Calendar.MINUTE, 59);
|
|
|
|
+ cal_2.set(Calendar.SECOND, 59);
|
|
|
|
+ String lastDay = format.format(cal_2.getTime());
|
|
|
|
+ QueryWrapper<EnvWarning> wrapper = new QueryWrapper<>();
|
|
|
|
+ wrapper.eq("farm_id",farmId);
|
|
|
|
+ Integer lastCount = envWarningMapper.getCount(wrapper.between("update_time",firstDay,lastDay));
|
|
|
|
+ if (ObjectUtil.isNull(lastCount)){
|
|
|
|
+ resultMap.put("lastValue",0);
|
|
|
|
+ resultMap.put("gap",100);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,resultMap);
|
|
|
|
+ }
|
|
|
|
+ resultMap.put("lastValue",lastCount) ;
|
|
|
|
+ double gap = ((currentCount.doubleValue() - lastCount.doubleValue()) / lastCount.doubleValue()) * 100;
|
|
|
|
+ if (ObjectUtil.isNull(gap)){
|
|
|
|
+ gap = 0.0;
|
|
|
|
+ }
|
|
|
|
+ BigDecimal bg = new BigDecimal(gap).setScale(2, RoundingMode.UP);
|
|
|
|
+ resultMap.put("gap",bg);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,resultMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result listWarning(Map<String, String> paramsMap) {
|
|
|
|
+ String farmId = paramsMap.get("farmId");
|
|
|
|
+ List<WarningVo> warningVos = envWarningMapper.listWarning(farmId);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,warningVos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result listTop(Map<String, String> paramsMap) {
|
|
|
|
+ String farmId = paramsMap.get("farmId");
|
|
|
|
+ List<WarningTopVo> warningCountVos = envWarningMapper.listTop(farmId);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,warningCountVos);
|
|
|
|
+ }
|
|
}
|
|
}
|