丁治程 hai 8 meses
pai
achega
2af616bc1d
Modificáronse 13 ficheiros con 588 adicións e 1 borrados
  1. 1 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/mapper/InterlockCountDayMapper.java
  2. 8 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/mapper/xml/InterlockCountDayMapper.xml
  3. 3 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/service/IInterlockCountDayService.java
  4. 11 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/service/impl/InterlockCountDayServiceImpl.java
  5. 177 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/controller/InterlockCountMonthController.java
  6. 71 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/entity/InterlockCountMonth.java
  7. 17 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/mapper/InterlockCountMonthMapper.java
  8. 5 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/mapper/xml/InterlockCountMonthMapper.xml
  9. 14 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/service/IInterlockCountMonthService.java
  10. 19 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/service/impl/InterlockCountMonthServiceImpl.java
  11. 3 1
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockjob/DayStatisticsJob.java
  12. 237 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockjob/MonthStatisticsJob.java
  13. 22 0
      jeecg-module-interlock/src/main/java/org/jeecg/modules/util/CountType.java

+ 1 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/mapper/InterlockCountDayMapper.java

@@ -14,4 +14,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface InterlockCountDayMapper extends BaseMapper<InterlockCountDay> {
 
+    List<InterlockCountDay> getCountByYearmonth(@Param("counttype") String counttype,@Param("lastmonth") String lastmonth);
 }

+ 8 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/mapper/xml/InterlockCountDayMapper.xml

@@ -2,4 +2,12 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.interlockCountDay.mapper.InterlockCountDayMapper">
 
+
+
+    <select id="getCountByYearmonth" resultType="org.jeecg.modules.interlockCountDay.entity.InterlockCountDay">
+        select device_id,interlock_system_id,interlock_name,count_name,count_num,count_type
+        from interlock_count_day
+        where count_type = #{counttype} and yearmonth = #{lastmonth}
+        order by device_id,interlock_system_id
+    </select>
 </mapper>

+ 3 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/service/IInterlockCountDayService.java

@@ -3,6 +3,8 @@ package org.jeecg.modules.interlockCountDay.service;
 import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * @Description: interlock_count_day
  * @Author: jeecg-boot
@@ -11,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IInterlockCountDayService extends IService<InterlockCountDay> {
 
+    List<InterlockCountDay> getCountByYearmonth(String counttype, String lastmonth);
 }

+ 11 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountDay/service/impl/InterlockCountDayServiceImpl.java

@@ -3,10 +3,13 @@ package org.jeecg.modules.interlockCountDay.service.impl;
 import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
 import org.jeecg.modules.interlockCountDay.mapper.InterlockCountDayMapper;
 import org.jeecg.modules.interlockCountDay.service.IInterlockCountDayService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import java.util.List;
+
 /**
  * @Description: interlock_count_day
  * @Author: jeecg-boot
@@ -16,4 +19,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 @Service
 public class InterlockCountDayServiceImpl extends ServiceImpl<InterlockCountDayMapper, InterlockCountDay> implements IInterlockCountDayService {
 
+    @Autowired
+    @SuppressWarnings("all")
+    private InterlockCountDayMapper mapper;
+
+    @Override
+    public List<InterlockCountDay> getCountByYearmonth(String counttype, String lastmonth) {
+        return mapper.getCountByYearmonth(counttype, lastmonth);
+    }
 }

+ 177 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/controller/InterlockCountMonthController.java

@@ -0,0 +1,177 @@
+package org.jeecg.modules.interlockCountMonth.controller;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.interlockCountMonth.entity.InterlockCountMonth;
+import org.jeecg.modules.interlockCountMonth.service.IInterlockCountMonthService;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
+
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.jeecg.common.system.base.controller.JeecgController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+import com.alibaba.fastjson.JSON;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.jeecg.common.aspect.annotation.AutoLog;
+
+ /**
+ * @Description: interlock_count_month
+ * @Author: jeecg-boot
+ * @Date:   2024-06-28
+ * @Version: V1.0
+ */
+@Api(tags="interlock_count_month")
+@RestController
+@RequestMapping("/interlockCountMonth/interlockCountMonth")
+@Slf4j
+public class InterlockCountMonthController extends JeecgController<InterlockCountMonth, IInterlockCountMonthService> {
+	@Autowired
+	private IInterlockCountMonthService interlockCountMonthService;
+	
+	/**
+	 * 分页列表查询
+	 *
+	 * @param interlockCountMonth
+	 * @param pageNo
+	 * @param pageSize
+	 * @param req
+	 * @return
+	 */
+	//@AutoLog(value = "interlock_count_month-分页列表查询")
+	@ApiOperation(value="interlock_count_month-分页列表查询", notes="interlock_count_month-分页列表查询")
+	@GetMapping(value = "/list")
+	public Result<IPage<InterlockCountMonth>> queryPageList(InterlockCountMonth interlockCountMonth,
+								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+								   HttpServletRequest req) {
+		QueryWrapper<InterlockCountMonth> queryWrapper = QueryGenerator.initQueryWrapper(interlockCountMonth, req.getParameterMap());
+		Page<InterlockCountMonth> page = new Page<InterlockCountMonth>(pageNo, pageSize);
+		IPage<InterlockCountMonth> pageList = interlockCountMonthService.page(page, queryWrapper);
+		return Result.OK(pageList);
+	}
+	
+	/**
+	 *   添加
+	 *
+	 * @param interlockCountMonth
+	 * @return
+	 */
+	@AutoLog(value = "interlock_count_month-添加")
+	@ApiOperation(value="interlock_count_month-添加", notes="interlock_count_month-添加")
+	//@RequiresPermissions("org.jeecg.modules:interlock_count_month:add")
+	@PostMapping(value = "/add")
+	public Result<String> add(@RequestBody InterlockCountMonth interlockCountMonth) {
+		interlockCountMonthService.save(interlockCountMonth);
+		return Result.OK("添加成功!");
+	}
+	
+	/**
+	 *  编辑
+	 *
+	 * @param interlockCountMonth
+	 * @return
+	 */
+	@AutoLog(value = "interlock_count_month-编辑")
+	@ApiOperation(value="interlock_count_month-编辑", notes="interlock_count_month-编辑")
+	//@RequiresPermissions("org.jeecg.modules:interlock_count_month:edit")
+	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
+	public Result<String> edit(@RequestBody InterlockCountMonth interlockCountMonth) {
+		interlockCountMonthService.updateById(interlockCountMonth);
+		return Result.OK("编辑成功!");
+	}
+	
+	/**
+	 *   通过id删除
+	 *
+	 * @param id
+	 * @return
+	 */
+	@AutoLog(value = "interlock_count_month-通过id删除")
+	@ApiOperation(value="interlock_count_month-通过id删除", notes="interlock_count_month-通过id删除")
+	//@RequiresPermissions("org.jeecg.modules:interlock_count_month:delete")
+	@DeleteMapping(value = "/delete")
+	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
+		interlockCountMonthService.removeById(id);
+		return Result.OK("删除成功!");
+	}
+	
+	/**
+	 *  批量删除
+	 *
+	 * @param ids
+	 * @return
+	 */
+	@AutoLog(value = "interlock_count_month-批量删除")
+	@ApiOperation(value="interlock_count_month-批量删除", notes="interlock_count_month-批量删除")
+	//@RequiresPermissions("org.jeecg.modules:interlock_count_month:deleteBatch")
+	@DeleteMapping(value = "/deleteBatch")
+	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
+		this.interlockCountMonthService.removeByIds(Arrays.asList(ids.split(",")));
+		return Result.OK("批量删除成功!");
+	}
+	
+	/**
+	 * 通过id查询
+	 *
+	 * @param id
+	 * @return
+	 */
+	//@AutoLog(value = "interlock_count_month-通过id查询")
+	@ApiOperation(value="interlock_count_month-通过id查询", notes="interlock_count_month-通过id查询")
+	@GetMapping(value = "/queryById")
+	public Result<InterlockCountMonth> queryById(@RequestParam(name="id",required=true) String id) {
+		InterlockCountMonth interlockCountMonth = interlockCountMonthService.getById(id);
+		if(interlockCountMonth==null) {
+			return Result.error("未找到对应数据");
+		}
+		return Result.OK(interlockCountMonth);
+	}
+
+    /**
+    * 导出excel
+    *
+    * @param request
+    * @param interlockCountMonth
+    */
+    //@RequiresPermissions("org.jeecg.modules:interlock_count_month:exportXls")
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, InterlockCountMonth interlockCountMonth) {
+        return super.exportXls(request, interlockCountMonth, InterlockCountMonth.class, "interlock_count_month");
+    }
+
+    /**
+      * 通过excel导入数据
+    *
+    * @param request
+    * @param response
+    * @return
+    */
+    //@RequiresPermissions("interlock_count_month:importExcel")
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        return super.importExcel(request, response, InterlockCountMonth.class);
+    }
+
+}

+ 71 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/entity/InterlockCountMonth.java

@@ -0,0 +1,71 @@
+package org.jeecg.modules.interlockCountMonth.entity;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+import java.math.BigDecimal;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import lombok.Data;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.jeecg.common.aspect.annotation.Dict;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * @Description: interlock_count_month
+ * @Author: jeecg-boot
+ * @Date:   2024-06-28
+ * @Version: V1.0
+ */
+@Data
+@TableName("interlock_count_month")
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="interlock_count_month对象", description="interlock_count_month")
+public class InterlockCountMonth implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+	/**主键*/
+	@TableId(type = IdType.ASSIGN_ID)
+    @ApiModelProperty(value = "主键")
+    private java.lang.String id;
+	/**系统id*/
+	@Excel(name = "系统id", width = 15)
+    @ApiModelProperty(value = "系统id")
+    private java.lang.String interlockSystemId;
+	/**系统名称*/
+	@Excel(name = "系统名称", width = 15)
+    @ApiModelProperty(value = "系统名称")
+    private java.lang.String interlockName;
+	/**统计名称(A/B/C/D、正常/异常、投用/未投用、投用率)*/
+	@Excel(name = "统计名称(A/B/C/D、正常/异常、投用/未投用、投用率)", width = 15)
+    @ApiModelProperty(value = "统计名称(A/B/C/D、正常/异常、投用/未投用、投用率)")
+    private java.lang.String countName;
+	/**统计数量*/
+	@Excel(name = "统计数量", width = 15)
+    @ApiModelProperty(value = "统计数量")
+    private java.lang.String countNum;
+	/**统计类型(健康等级0/联锁状态1/投用率2/仪表状态3/系统状态4)*/
+	@Excel(name = "统计类型(健康等级0/联锁状态1/投用率2/仪表状态3/系统状态4)", width = 15)
+    @ApiModelProperty(value = "统计类型(健康等级0/联锁状态1/投用率2/仪表状态3/系统状态4)")
+    private java.lang.String countType;
+	/**按月统计的时间*/
+	@Excel(name = "按月统计的时间", width = 15)
+    @ApiModelProperty(value = "按月统计的时间")
+    private java.lang.String time;
+	/**年*/
+	@Excel(name = "年", width = 15)
+    @ApiModelProperty(value = "年")
+    private java.lang.String year;
+	/**装置id*/
+	@Excel(name = "装置id", width = 15)
+    @ApiModelProperty(value = "装置id")
+    private java.lang.String deviceId;
+}

+ 17 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/mapper/InterlockCountMonthMapper.java

@@ -0,0 +1,17 @@
+package org.jeecg.modules.interlockCountMonth.mapper;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.modules.interlockCountMonth.entity.InterlockCountMonth;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * @Description: interlock_count_month
+ * @Author: jeecg-boot
+ * @Date:   2024-06-28
+ * @Version: V1.0
+ */
+public interface InterlockCountMonthMapper extends BaseMapper<InterlockCountMonth> {
+
+}

+ 5 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/mapper/xml/InterlockCountMonthMapper.xml

@@ -0,0 +1,5 @@
+<?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="org.jeecg.modules.interlockCountMonth.mapper.InterlockCountMonthMapper">
+
+</mapper>

+ 14 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/service/IInterlockCountMonthService.java

@@ -0,0 +1,14 @@
+package org.jeecg.modules.interlockCountMonth.service;
+
+import org.jeecg.modules.interlockCountMonth.entity.InterlockCountMonth;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: interlock_count_month
+ * @Author: jeecg-boot
+ * @Date:   2024-06-28
+ * @Version: V1.0
+ */
+public interface IInterlockCountMonthService extends IService<InterlockCountMonth> {
+
+}

+ 19 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockCountMonth/service/impl/InterlockCountMonthServiceImpl.java

@@ -0,0 +1,19 @@
+package org.jeecg.modules.interlockCountMonth.service.impl;
+
+import org.jeecg.modules.interlockCountMonth.entity.InterlockCountMonth;
+import org.jeecg.modules.interlockCountMonth.mapper.InterlockCountMonthMapper;
+import org.jeecg.modules.interlockCountMonth.service.IInterlockCountMonthService;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+/**
+ * @Description: interlock_count_month
+ * @Author: jeecg-boot
+ * @Date:   2024-06-28
+ * @Version: V1.0
+ */
+@Service
+public class InterlockCountMonthServiceImpl extends ServiceImpl<InterlockCountMonthMapper, InterlockCountMonth> implements IInterlockCountMonthService {
+
+}

+ 3 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockjob/DayStatisticsJob.java

@@ -299,8 +299,10 @@ public class DayStatisticsJob implements Job {
         List<InterlockCountDay> list = Stream.concat(Stream.concat(loopHealthLevelResultList.stream(), interlockStatusResultList.stream()),tylResultList.stream())
                 .collect(Collectors.toList());
 
+        QueryWrapper<InterlockCountDay> queryWapper = new QueryWrapper<>();
+        queryWapper.eq("time",yesterday);
+        boolean b = countService.remove(queryWapper);
         countService.saveBatch(list);
-
         log.info("日统计任务执行成功!");
     }
 

+ 237 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockjob/MonthStatisticsJob.java

@@ -0,0 +1,237 @@
+package org.jeecg.modules.interlockjob;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.base.entity.InterlockBase;
+import org.jeecg.modules.base.service.IInterlockBaseService;
+import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
+import org.jeecg.modules.interlockCountDay.service.IInterlockCountDayService;
+import org.jeecg.modules.interlockCountMonth.entity.InterlockCountMonth;
+import org.jeecg.modules.interlockCountMonth.service.IInterlockCountMonthService;
+import org.jeecg.modules.util.CountType;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.management.Query;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * @author dzc
+ * @date 2024/6/28 15:32
+ * @package org.jeecg.modules.interlockjob
+ * @project interlock_server
+ * @des 联锁 健康等级 仪表状态 投用率 月统计的定时任务
+ */
+@Slf4j
+public class MonthStatisticsJob implements Job {
+
+    @Autowired
+    @SuppressWarnings("all")
+    private IInterlockCountDayService countDayService;
+
+    @Autowired
+    @SuppressWarnings("all")
+    private IInterlockCountMonthService monthService;
+
+    @Autowired
+    @SuppressWarnings("all")
+    private IInterlockBaseService baseService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+        LocalDate yesterDate = LocalDate.now().minusMonths(1);  // 当前 00:00:00 执行定时任务 减一天获取昨天的日期
+        String lastmonth = yesterDate.format(formatter); // 上个月的月份
+        //String lastmonth = "2024-06"; // 测试模拟上个月的月份
+        String year = lastmonth.split("-")[0];
+
+        // 统计健康等级 count_type = 0
+        List<InterlockCountDay> loopHealthLevelList = countDayService.getCountByYearmonth(CountType.LOOPHEALTHLEVEL,lastmonth);
+
+        HashMap<String, List<InterlockCountDay>> loopHealthLevelMap = new HashMap<>();
+
+        ArrayList<InterlockCountMonth> loopHealthLevelResultList = new ArrayList<>();
+
+        for (InterlockCountDay item:loopHealthLevelList) {
+            if (loopHealthLevelMap.containsKey(item.getInterlockSystemId())){
+                loopHealthLevelMap.get(item.getInterlockSystemId()).add(item);
+            }else {
+                ArrayList<InterlockCountDay> countList = new ArrayList<>();
+                countList.add(item);
+                loopHealthLevelMap.put(item.getInterlockSystemId(),countList);
+            }
+        }
+
+        for (String key : loopHealthLevelMap.keySet()) {
+            List<InterlockCountDay> sonList = loopHealthLevelMap.get(key);
+            int countAnum = 0;
+            int countBnum = 0;
+            int countCnum = 0;
+            int countDnum = 0;
+            for (InterlockCountDay item : sonList) {
+                int num = Integer.parseInt(item.getCountNum());
+                switch (item.getCountName()){
+                    case "A" :
+                        countAnum += num;
+                        break;
+                    case "B" :
+                        countBnum += num;
+                        break;
+                    case "C" :
+                        countCnum += num;
+                        break;
+                    case "D" :
+                        countDnum += num;
+                        break;
+                }
+            }
+            String[] arr1 = {"A", "B", "C", "D"};
+            int[] arr2 = {countAnum,countBnum,countCnum,countDnum};
+
+            for (int i = 0; i < arr1.length; i++){
+                InterlockCountMonth interlockCountMonth = new InterlockCountMonth();
+                interlockCountMonth.setDeviceId(sonList.get(0).getDeviceId());
+                interlockCountMonth.setInterlockSystemId(sonList.get(0).getInterlockSystemId());
+                interlockCountMonth.setInterlockName(sonList.get(0).getInterlockName());
+                interlockCountMonth.setCountName(arr1[i]);
+                interlockCountMonth.setCountNum(String.valueOf(arr2[i]));
+                interlockCountMonth.setCountType(CountType.LOOPHEALTHLEVEL);
+                interlockCountMonth.setTime(lastmonth);
+                interlockCountMonth.setYear(year);
+                loopHealthLevelResultList.add(interlockCountMonth);
+            }
+        }
+
+        // 统计联锁状态(投用/未投用)  count_type = 1
+        List<InterlockCountDay> interlockStatusList = countDayService.getCountByYearmonth(CountType.INTERLOCKSTATUS,lastmonth);
+
+        HashMap<String, List<InterlockCountDay>> interlockStatusMap = new HashMap<>();
+
+        ArrayList<InterlockCountMonth> interlockStatusResultList = new ArrayList<>();
+
+        for (InterlockCountDay item:interlockStatusList) {
+            if (interlockStatusMap.containsKey(item.getInterlockSystemId())){
+                interlockStatusMap.get(item.getInterlockSystemId()).add(item);
+            }else {
+                ArrayList<InterlockCountDay> countList = new ArrayList<>();
+                countList.add(item);
+                interlockStatusMap.put(item.getInterlockSystemId(),countList);
+            }
+        }
+
+        for (String key : interlockStatusMap.keySet()) {
+            InterlockBase base = baseService.getById(key);
+            String ty = base.getInterlockStatusTyName();
+            String wty = base.getInterlockStatusWtyName();
+            List<InterlockCountDay> sonList = interlockStatusMap.get(key);
+            int countTyNum = 0;
+            int countWtyNum = 0;
+            for (InterlockCountDay item : sonList) {
+                if (ty.equals(item.getCountName())){
+                    countTyNum += Integer.parseInt(item.getCountNum());
+                }
+                if (wty.equals(item.getCountName())){
+                    countWtyNum += Integer.parseInt(item.getCountNum());
+                }
+            }
+
+            InterlockCountMonth interlockCountMonthTy = new InterlockCountMonth();
+
+            interlockCountMonthTy.setDeviceId(sonList.get(0).getDeviceId());
+            interlockCountMonthTy.setInterlockSystemId(sonList.get(0).getInterlockSystemId());
+            interlockCountMonthTy.setInterlockName(sonList.get(0).getInterlockName());
+            interlockCountMonthTy.setCountName(ty);
+            interlockCountMonthTy.setCountNum(String.valueOf(countTyNum));
+            interlockCountMonthTy.setCountType(CountType.INTERLOCKSTATUS);
+            interlockCountMonthTy.setTime(lastmonth);
+            interlockCountMonthTy.setYear(year);
+
+            InterlockCountMonth interlockCountMonthWty = new InterlockCountMonth();
+
+            interlockCountMonthWty.setDeviceId(sonList.get(0).getDeviceId());
+            interlockCountMonthWty.setInterlockSystemId(sonList.get(0).getInterlockSystemId());
+            interlockCountMonthWty.setInterlockName(sonList.get(0).getInterlockName());
+            interlockCountMonthWty.setCountName(wty);
+            interlockCountMonthWty.setCountNum(String.valueOf(countWtyNum));
+            interlockCountMonthWty.setCountType(CountType.INTERLOCKSTATUS);
+            interlockCountMonthWty.setTime(lastmonth);
+            interlockCountMonthWty.setYear(year);
+
+            interlockStatusResultList.add(interlockCountMonthTy);
+            interlockStatusResultList.add(interlockCountMonthWty);
+        }
+
+        // 统计投用率  count_type = 2
+        ArrayList<InterlockCountMonth> tylResultList = new ArrayList<>();
+
+        HashMap<String, List<InterlockCountMonth>> tylMap = new HashMap<>();
+        for (InterlockCountMonth item:interlockStatusResultList) {
+            if (tylMap.containsKey(item.getInterlockSystemId())){
+                tylMap.get(item.getInterlockSystemId()).add(item);
+            }else {
+                ArrayList<InterlockCountMonth> countList = new ArrayList<>();
+                countList.add(item);
+                tylMap.put(item.getInterlockSystemId(),countList);
+            }
+        }
+
+        for (String key : tylMap.keySet()) {
+            InterlockBase base = baseService.getById(key);
+            String tyName = base.getInterlockStatusTyName();
+            String wtyName = base.getInterlockStatusWtyName();
+            List<InterlockCountMonth> sonList = tylMap.get(key);
+            BigDecimal yty = BigDecimal.valueOf(0);
+            BigDecimal wty = BigDecimal.valueOf(0);
+            BigDecimal tyl = BigDecimal.valueOf(0);
+            for (InterlockCountMonth item : sonList) {
+                if (tyName.equals(item.getCountName())){
+                    yty = new BigDecimal(item.getCountNum());
+                }
+                if (wtyName.equals(item.getCountName())){
+                    wty = new BigDecimal(item.getCountNum());
+                }
+            }
+            BigDecimal total = yty.add(wty);
+            if ((total.compareTo(BigDecimal.valueOf(0)) != 0)){
+                tyl = yty.divide(total,2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
+            }
+
+            InterlockCountMonth interlockCountMonthTyl = new InterlockCountMonth();
+
+            interlockCountMonthTyl.setDeviceId(sonList.get(0).getDeviceId());
+            interlockCountMonthTyl.setInterlockSystemId(key);
+            interlockCountMonthTyl.setInterlockName(sonList.get(0).getInterlockName());
+            interlockCountMonthTyl.setCountName("投用率");
+            interlockCountMonthTyl.setCountNum(String.valueOf(tyl));
+            interlockCountMonthTyl.setCountType(CountType.UTILIZATIONRATE);
+            interlockCountMonthTyl.setTime(lastmonth);
+            interlockCountMonthTyl.setYear(year);
+
+            tylResultList.add(interlockCountMonthTyl);
+        }
+
+
+        List<InterlockCountMonth> list = Stream.concat(Stream.concat(loopHealthLevelResultList.stream(), interlockStatusResultList.stream()),tylResultList.stream())
+                .collect(Collectors.toList());
+
+
+        QueryWrapper<InterlockCountMonth> queryWapper = new QueryWrapper<>();
+        queryWapper.eq("time",lastmonth);
+        boolean b = monthService.remove(queryWapper);
+
+        monthService.saveBatch(list);
+        log.info("月统计任务执行成功!");
+    }
+}

+ 22 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/util/CountType.java

@@ -0,0 +1,22 @@
+package org.jeecg.modules.util;
+
+/**
+ * @author dzc
+ * @date 2024/6/28 17:03
+ * @package org.jeecg.modules.util
+ * @project interlock_server
+ * @des 统计类型
+ */
+public class CountType {
+
+
+    /** 健康等级 */
+    public static final String LOOPHEALTHLEVEL = "0";
+
+    /** 联锁状态 */
+    public static final String INTERLOCKSTATUS = "1";
+
+    /** 投用率 */
+    public static final String UTILIZATIONRATE = "2";
+
+}