Ver Fonte

统计及执行日期

lipenghui há 2 semanas atrás
pai
commit
bd1d278e42
13 ficheiros alterados com 174 adições e 7 exclusões
  1. 1 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/inspect/order/vo/IotInspectOrderRespVO.java
  2. 4 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogPageReqVO.java
  3. 2 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/IotMaintainController.java
  4. 2 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/vo/IotMaintainRespVO.java
  5. 3 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/vo/IotMaintainSaveReqVO.java
  6. 129 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java
  7. 2 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/inspect/IotInspectOrderDO.java
  8. 3 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/maintain/IotMaintainDO.java
  9. 6 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java
  10. 1 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/inspect/IotInspectOrderServiceImpl.java
  11. 1 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintain/IotMaintainService.java
  12. 5 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintain/IotMaintainServiceImpl.java
  13. 15 0
      yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceRunLogMapper.xml

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/inspect/order/vo/IotInspectOrderRespVO.java

@@ -53,6 +53,7 @@ public class IotInspectOrderRespVO {
     private Long deviceCount;
     private Long exceptionCount;
     private Integer needDevice;
+    private LocalDateTime executeDate;
 
     private List<IotInspectOrderController.OrderDetail> details;
 }

+ 4 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotdevicerunlog/vo/IotDeviceRunLogPageReqVO.java

@@ -9,6 +9,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 
@@ -68,5 +69,6 @@ public class IotDeviceRunLogPageReqVO extends PageParam {
     @Schema(description = "创建时间")
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;
-
-}
+    @Schema(description = "部门ids")
+    private List<Long> deptIds;
+}

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/IotMaintainController.java

@@ -27,6 +27,7 @@ import cn.iocoder.yudao.module.system.api.dept.DeptApi;
 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import com.alibaba.fastjson.JSON;
 import com.xingyuv.captcha.util.StringUtils;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -107,6 +108,7 @@ public class IotMaintainController {
         }
         IotDeviceDO iotDevice = iotDeviceService.getIotDevice(iotMaintain.getDeviceId());
         IotMaintainRespVO bean = BeanUtils.toBean(iotMaintain, IotMaintainRespVO.class);
+        bean.setPics(JSON.parseArray(bean.getPic(), String.class));
         if (Objects.nonNull(iotDevice)&&Objects.nonNull(iotDevice.getManufacturerId())) {
             SupplierDO supplierDO1 = supplierService.get(iotDevice.getManufacturerId());
             bean.setSupplierName(Objects.nonNull(supplierDO1)?supplierDO1.getName():"");

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/vo/IotMaintainRespVO.java

@@ -127,4 +127,6 @@ public class IotMaintainRespVO {
     private String deptName;
 
     private String createName;
+    private LocalDateTime executeDate;
+    private List<String> pics;
 }

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/vo/IotMaintainSaveReqVO.java

@@ -6,6 +6,7 @@ import lombok.*;
 import javax.validation.constraints.*;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.List;
 
 //@Schema(description = "管理后台 - 维修工单新增/修改 Request VO")
 @Data
@@ -101,4 +102,6 @@ public class IotMaintainSaveReqVO {
     private String maintainType;
 
     private String deviceCode;
+
+    private List<String> pics;
 }

+ 129 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java

@@ -2,11 +2,13 @@ package cn.iocoder.yudao.module.pms.controller.admin.stat;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.pojo.Pms;
 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.failure.vo.IotFailureReportPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectOrderPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
@@ -28,6 +30,7 @@ import cn.iocoder.yudao.module.pms.dal.mysql.TDDeviceMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.failure.IotFailureReportMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.inspect.IotInspectOrderDetailMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.inspect.IotInspectOrderMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicerunlog.IotDeviceRunLogMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorder.IotMainWorkOrderMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotsapstock.IotSapStockMapper;
@@ -56,7 +59,6 @@ import javax.annotation.Resource;
 import javax.annotation.security.PermitAll;
 import javax.validation.Valid;
 import java.io.Serializable;
-import java.sql.Array;
 import java.sql.Timestamp;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -107,6 +109,8 @@ public class IotStaticController {
     private DeptService deptService;
     @Autowired
     private IotOpeationFillMapper iotOpeationFillMapper;
+    @Autowired
+    private IotDeviceRunLogMapper iotDeviceRunLogMapper;
 
     @GetMapping("/main/day")
     public CommonResult<Map<String, Object>> getMaintainDay() {
@@ -661,6 +665,59 @@ public class IotStaticController {
 
     }
 
+    public static LinkedHashMap<String, Long> sumTotalByDate(List<Map<String, Object>> records, int days, String key) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate today = LocalDate.now();
+
+        // 生成近days天的日期列表,初始值为0
+        LinkedHashMap<String, Long> dateMap = new LinkedHashMap<>();
+        for (int i = days - 1; i >= 0; i--) {
+            LocalDate date = today.minusDays(i);
+            dateMap.put(date.format(formatter), 0L);
+        }
+
+        // 统计每天的total字段之和
+        Map<String, Long> sumMap = records.stream()
+                .collect(Collectors.groupingBy(
+                        record -> {
+                            try {
+                                // 提取日期部分(假设createTime格式为yyyy-MM-dd...)
+                                return String.valueOf(record.get("createTime")).substring(0, 10);
+                            } catch (Exception e) {
+                                System.err.println("日期格式错误: " + record.get("createTime"));
+                                return "invalid_date";
+                            }
+                        },
+                        // 累加每天的total字段值,处理可能的格式问题
+                        Collectors.summingLong(record -> {
+                            try {
+                                Object totalObj = record.get(key);
+                                if (totalObj instanceof Number) {
+                                    return ((Number) totalObj).longValue();
+                                } else if (totalObj instanceof String) {
+                                    return Long.parseLong((String) totalObj);
+                                } else {
+                                    System.err.println("total字段格式错误: " + totalObj);
+                                    return 0L;
+                                }
+                            } catch (Exception e) {
+                                System.err.println("处理total字段出错: " + e.getMessage());
+                                return 0L;
+                            }
+                        })
+                ));
+
+        // 合并结果,确保所有日期都在返回结果中
+        dateMap.forEach((date, sum) -> {
+            if (sumMap.containsKey(date)) {
+                dateMap.put(date, sumMap.get(date));
+            }
+        });
+
+        return dateMap;
+    }
+
+
     public static LinkedHashMap<String, Long> countRecordsByDate(List<Map<String, Object>> records, int days) {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         LocalDate today = LocalDate.now();
@@ -696,5 +753,76 @@ public class IotStaticController {
 
         return dateMap;
     }
+
+    @GetMapping("/rh/zql/{dept}")
+    @PermitAll
+    public CommonResult<Map<String, Object>> rhOrder(@PathVariable("dept") String dept) {
+        Set<Long> ids = getDeptIds(dept);
+        List<String> lastSevenDays = DateUtils.getLastSevenDays();
+        String first = lastSevenDays.get(0);
+        String last = lastSevenDays.get(lastSevenDays.size() - 1);
+        LocalDateTime startOfDay = getStartOfDay(first);
+        LocalDateTime endOfDay = getEndOfDay(last);
+        LocalDateTime[] createTime = new LocalDateTime[]{endOfDay, startOfDay};
+
+        IotDeviceRunLogPageReqVO iotDeviceRunLogPageReqVO = new IotDeviceRunLogPageReqVO();
+        iotDeviceRunLogPageReqVO.setCreateTime(createTime);
+        iotDeviceRunLogPageReqVO.setDeptIds(new ArrayList<>(ids));
+        iotDeviceRunLogPageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<Map<String, Object>> fills = iotDeviceRunLogMapper.selectListByCreateTimeAndDeptList(iotDeviceRunLogPageReqVO).stream().filter(e -> "累计注气量".equals(e.getPointName())).map(e -> {
+            Map<String, Object> abc = new HashMap<>();
+            abc.put("id", e.getId());
+            abc.put("createTime", e.getCreateTime());
+            abc.put("total", e.getTotalRunTime());
+            abc.put("today", e.getFillContent());
+            return abc;
+        }).collect(Collectors.toList());
+        LinkedHashMap<String, Long> fillMap = sumTotalByDate(fills, 7,"total");
+        LinkedList<Object> xAxis = new LinkedList<>();
+        LinkedList<Object> fillData = new LinkedList<>();
+        fillMap.forEach( (k,v)->{
+            xAxis.add(k);
+            fillData.add(v);
+        });
+
+        ImmutableMap<String, Serializable> fillResult = ImmutableMap.of("name", "累计注气量", "data", fillData);
+        return success(ImmutableMap.of("xAxis", xAxis, "series", ImmutableList.of(fillResult)));
+
+    }
+    @GetMapping("/rh/zql/today/{dept}")
+    @PermitAll
+    public CommonResult<Map<String, Object>> rhOrderToday(@PathVariable("dept") String dept) {
+        Set<Long> ids = getDeptIds(dept);
+        List<String> lastSevenDays = DateUtils.getLastSevenDays();
+        String first = lastSevenDays.get(0);
+        String last = lastSevenDays.get(lastSevenDays.size() - 1);
+        LocalDateTime startOfDay = getStartOfDay(first);
+        LocalDateTime endOfDay = getEndOfDay(last);
+        LocalDateTime[] createTime = new LocalDateTime[]{endOfDay, startOfDay};
+
+        IotDeviceRunLogPageReqVO iotDeviceRunLogPageReqVO = new IotDeviceRunLogPageReqVO();
+        iotDeviceRunLogPageReqVO.setCreateTime(createTime);
+        iotDeviceRunLogPageReqVO.setDeptIds(new ArrayList<>(ids));
+        iotDeviceRunLogPageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<Map<String, Object>> fills = iotDeviceRunLogMapper.selectListByCreateTimeAndDeptList(iotDeviceRunLogPageReqVO).stream().filter(e -> "当日注气量".equals(e.getPointName())).map(e -> {
+            Map<String, Object> abc = new HashMap<>();
+            abc.put("id", e.getId());
+            abc.put("createTime", e.getCreateTime());
+            abc.put("total", e.getTotalRunTime());
+            abc.put("today", e.getFillContent());
+            return abc;
+        }).collect(Collectors.toList());
+        LinkedHashMap<String, Long> fillMap = sumTotalByDate(fills, 7,"today");
+        LinkedList<Object> xAxis = new LinkedList<>();
+        LinkedList<Object> fillData = new LinkedList<>();
+        fillMap.forEach( (k,v)->{
+            xAxis.add(k);
+            fillData.add(v);
+        });
+
+        ImmutableMap<String, Serializable> fillResult = ImmutableMap.of("name", "当日注气量", "data", fillData);
+        return success(ImmutableMap.of("xAxis", xAxis, "series", ImmutableList.of(fillResult)));
+
+    }
 }
 

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/inspect/IotInspectOrderDO.java

@@ -57,4 +57,6 @@ public class IotInspectOrderDO extends BaseDO {
     private Long charge;
     private String planCode;
     private String chargeName;
+
+    private LocalDateTime executeDate;
 }

+ 3 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/maintain/IotMaintainDO.java

@@ -15,7 +15,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
 /**
  * 维修工单 DO
  *
- * @author 袁超
+ * @author phli
  */
 @TableName("rq_iot_maintain")
 @KeySequence("rq_iot_maintain_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@@ -142,4 +142,6 @@ public class IotMaintainDO extends BaseDO {
     private String deviceCode;
 
     private String maintainPersonName;
+
+    private LocalDateTime executeDate;
 }

+ 6 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java

@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pms.dal.mysql.iotdevicerunlog;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
@@ -55,4 +56,8 @@ public interface IotDeviceRunLogMapper extends BaseMapperX<IotDeviceRunLogDO> {
      */
     List<IotDeviceRunLogRespVO> multipleAccumulatedData(@Param("deviceIds") Collection<Long> deviceIds,
                                                         @Param("attrNames") Collection<String> attrNames);
-}
+
+
+    @TenantIgnore
+    List<IotDeviceRunLogRespVO> selectListByCreateTimeAndDeptList(IotDeviceRunLogPageReqVO reqVO);
+}

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/inspect/IotInspectOrderServiceImpl.java

@@ -108,6 +108,7 @@ public class IotInspectOrderServiceImpl implements IotInspectOrderService {
         boolean ma = orderId1.stream().anyMatch(f -> Objects.isNull(f.getIfNormal()));
         if (!ma) {
             order.setStatus("finished");
+            order.setExecuteDate(LocalDateTime.now());
         }
         iotInspectOrderMapper.updateById(order);
     }

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintain/IotMaintainService.java

@@ -18,7 +18,7 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.maintain.material.IotMaintainM
 /**
  * 维修工单 Service 接口
  *
- * @author 袁超
+ * @author phli
  */
 public interface IotMaintainService {
     PageResult<OrderVo> getNotice(OrderVo pageReqVO);

+ 5 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintain/IotMaintainServiceImpl.java

@@ -49,6 +49,7 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.ImmutableMap;
@@ -60,6 +61,7 @@ import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 
@@ -69,7 +71,7 @@ import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.*;
 /**
  * 维修工单 Service 实现类
  *
- * @author 袁超
+ * @author phli
  */
 @Service
 @Validated
@@ -160,6 +162,8 @@ public class IotMaintainServiceImpl implements IotMaintainService {
         if (Objects.isNull(user)) throw new ServiceException(new ErrorCode(22,"责任人不存在"));
         iotMaintain.setMaintainPersonName(user.getNickname());
         iotMaintain.setMaintainType("手动新增");
+        iotMaintain.setExecuteDate(LocalDateTime.now());
+        iotMaintain.setPic(JSON.toJSONString(createReqVO.getMaintain().getPics()));
         iotMaintainMapper.insert(iotMaintain);
         //插入工单bom
         List<IotMaintainBomSaveReqVO> maintainMaterials = createReqVO.getMaintainMaterials();

+ 15 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceRunLogMapper.xml

@@ -28,6 +28,21 @@
         GROUP BY drl.device_id, mta.`code`
     </select>
 
+
+    <select id="selectListByCreateTimeAndDeptList" parameterType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO"
+            resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">
+        SELECT a.id, a.create_time,a.total_run_time,a.fill_content
+        FROM rq_iot_device_run_log a
+        WHERE a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
+        <if test="deptIds != null and deptIds.size &gt; 0">
+            AND a.dept_id IN
+            <foreach collection="deptIds" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
+    </select>
+
+
     <!-- 查询指定设备 指定运行模板属性的累计时长 累计公里数 -->
     <select id="multipleAccumulatedData"
             resultType="cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO">