浏览代码

运行记录优化0923

yuanchao 1 周之前
父节点
当前提交
cbfc3fc917
共有 16 个文件被更改,包括 422 次插入191 次删除
  1. 10 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/failure/IotFailureReportController.java
  2. 4 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/failure/vo/IotFailureReportRespVO.java
  3. 55 17
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotopeationfill/IotOpeationFillController.java
  4. 6 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockPageReqVO.java
  5. 8 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockRespVO.java
  6. 6 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockSaveReqVO.java
  7. 2 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java
  8. 8 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotsapstock/IotSapStockDO.java
  9. 1 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotDeviceMapper.java
  10. 5 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotInfoMapper.java
  11. 5 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotopeationfill/IotOpeationFillMapper.java
  12. 90 151
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/IotOperationPlanJob.java
  13. 148 11
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/sap/service/IotSapServiceImpl.java
  14. 21 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotTreeServiceImpl.java
  15. 19 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotopeationfill/IotOpeationFillServiceImpl.java
  16. 34 5
      yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotOpeationFillMapper.xml

+ 10 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/failure/IotFailureReportController.java

@@ -7,7 +7,9 @@ import cn.iocoder.yudao.module.pms.controller.admin.failure.vo.IotFailureReportS
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainSaveVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.failure.IotFailureReportDO;
 import cn.iocoder.yudao.module.pms.service.failure.IotFailureReportService;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import org.springframework.validation.annotation.Validated;
@@ -41,6 +43,8 @@ public class IotFailureReportController {
 
     @Resource
     private IotFailureReportService iotFailureReportService;
+    @Autowired
+    private AdminUserApi adminUserApi;
 
     @PostMapping("/create")
     @Operation(summary = "创建故障上报")
@@ -72,7 +76,12 @@ public class IotFailureReportController {
     @PreAuthorize("@ss.hasPermission('rq:iot-failure-report:query')")
     public CommonResult<IotFailureReportRespVO> getIotFailureReport(@RequestParam("id") Long id) {
         IotFailureReportDO iotFailureReport = iotFailureReportService.getIotFailureReport(id);
-        return success(BeanUtils.toBean(iotFailureReport, IotFailureReportRespVO.class));
+        IotFailureReportRespVO bean = BeanUtils.toBean(iotFailureReport, IotFailureReportRespVO.class);
+        if (Objects.nonNull(bean.getApprovalId())) {
+            AdminUserRespDTO user = adminUserApi.getUser(bean.getApprovalId());
+            bean.setApprovalName(Objects.nonNull(user) ? user.getNickname() : "");
+        }
+        return success(bean);
     }
 
     @GetMapping("/page")

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/failure/vo/IotFailureReportRespVO.java

@@ -99,4 +99,8 @@ public class IotFailureReportRespVO {
 
     @Schema(description = "设备编码")
     private String deviceCode;
+    /**审批人id*/
+    private Long approvalId;
+
+    private String approvalName;
 }

+ 55 - 17
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotopeationfill/IotOpeationFillController.java

@@ -10,6 +10,8 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeati
 import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillRespVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportSaveReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
@@ -32,6 +34,7 @@ import cn.iocoder.yudao.module.pms.service.IDeviceService;
 import cn.iocoder.yudao.module.pms.service.iotopeationfill.IotOpeationFillService;
 
 import cn.iocoder.yudao.module.pms.service.iotrhdailyreport.IotRhDailyReportService;
+import cn.iocoder.yudao.module.pms.service.iotrydailyreport.IotRyDailyReportService;
 import cn.iocoder.yudao.module.pms.service.yanfan.YfDeviceService;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import com.aliyun.tea.utils.StringUtils;
@@ -87,6 +90,8 @@ public class IotOpeationFillController {
     private DeptService deptService;
     @Resource
     private IotRhDailyReportService iotRhDailyReportService;
+    @Resource
+    private IotRyDailyReportService iotRyDailyReportService;
 
     @PostMapping("/create")
     @Operation(summary = "创建运行记录填报")
@@ -206,37 +211,71 @@ public class IotOpeationFillController {
             }
         }
 
-        IotDeviceRunLogDO runDo = logDO.get(0);
+        Set<Long> rhIdList = deptService.getChildDeptIdListFromCache(157L);
+        rhIdList.add(157L);
+
+
+        Set<Long> ryIdList =  deptService.getChildDeptIdListFromCache(158L);
+        ryIdList.add(158L);
 
+
+        IotDeviceRunLogDO runDo = logDO.get(0);
         IotOpeationFillDO reportDO = new IotOpeationFillDO();
         reportDO.setDeviceId(runDo.getDeviceId());
         reportDO.setCreateTime(runDo.getCreateTime());
         IotOpeationFillDO fillDO1 = iotOpeationFillService.isReport(reportDO);
 
         //虚拟设备插入日报
-        if(fillDO1.getIsReport()==1){
+        if(fillDO1.getIsReport()!=null && fillDO1.getIsReport()==1){
 
             IotRhDailyReportSaveReqVO saveReqVO = new IotRhDailyReportSaveReqVO();
-            Map<String, Object> stringObjectMap = BeanUtil.beanToMap(saveReqVO);
+            IotRyDailyReportPageReqVO saveReqRyVO = new IotRyDailyReportPageReqVO();
 
-            for (IotDeviceRunLogDO logDO1:logDO) {
+            Map<String,Object> stringRhObjectMap = BeanUtil.beanToMap(saveReqVO);
+            Map<String,Object> stringRyObjectMap = BeanUtil.beanToMap(saveReqRyVO);
 
-                IotDeviceRunLogDO descDO = iotOpeationFillService.getDesc(logDO1);
+            if(rhIdList.contains(fillDO1.getDeptId())){
+                for (IotDeviceRunLogDO logDO1:logDO) {
 
-                if(descDO!=null){
-                    stringObjectMap.forEach((k,v)->{
-                        if(k.equals(descDO.getPointName())){
-                            stringObjectMap.put(k,logDO1.getFillContent());
-                        }
-                    });
+                    IotDeviceRunLogDO descDO = iotOpeationFillService.getDesc(logDO1);
+
+                    if(descDO!=null){
+                        stringRhObjectMap.forEach((k,v)->{
+                            if(k.equals(descDO.getPointName())){
+                                stringRhObjectMap.put(k,logDO1.getFillContent());
+                            }
+                        });
+                    }
                 }
-            }
-                IotRhDailyReportSaveReqVO saveReqVO1 = BeanUtil.mapToBean(stringObjectMap,IotRhDailyReportSaveReqVO.class,false);
+
+                IotRhDailyReportSaveReqVO saveReqVO1 = BeanUtil.mapToBean(stringRhObjectMap,IotRhDailyReportSaveReqVO.class,false);
                 saveReqVO1.setDeptId(fillDO1.getDeptId());
                 saveReqVO1.setFillOrderCreateTime(fillList.get(0).getCreateTime().atStartOfDay());
                 iotRhDailyReportService.createIotRhDailyReport(saveReqVO1);
+            }else if(ryIdList.contains(fillDO1.getDeptId())){
+                for (IotDeviceRunLogDO logDO1:logDO) {
+
+                    IotDeviceRunLogDO descDO = iotOpeationFillService.getDesc(logDO1);
+
+                    if(descDO!=null){
+                        stringRyObjectMap.forEach((k,v)->{
+                            if(k.equals(descDO.getPointName())){
+                                stringRyObjectMap.put(k,logDO1.getFillContent());
+                            }
+                        });
+                    }
+                }
+
+                IotRyDailyReportSaveReqVO saveReqVO1 = BeanUtil.mapToBean(stringRyObjectMap, IotRyDailyReportSaveReqVO.class,false);
+                saveReqVO1.setDeptId(fillDO1.getDeptId());
+                saveReqVO1.setFillOrderCreateTime(fillList.get(0).getCreateTime().atStartOfDay());
+                iotRyDailyReportService.createIotRyDailyReport(saveReqVO1);
             }
 
+
+
+        }
+
         return success(1);
     }
 
@@ -430,7 +469,7 @@ public class IotOpeationFillController {
         List<IotModelTemplateAttrsDO1> resut = new ArrayList<>();
         List<IotModelTemplateAttrsDO> list = iotOpeationFillService.getAttrsById(vo );
 
-        if(fillDO1.getIsReport()==1){
+        if(fillDO1.getIsReport() !=null && fillDO1.getIsReport()==1){
 
             IotOpeationFillDO fillDO2 = iotOpeationFillService.orderDO(fillDO);
 
@@ -446,8 +485,8 @@ public class IotOpeationFillController {
             for (IotModelTemplateAttrsDO attrsDO:list) {
 
 
-                //根据日报取值设备赋值
-                if(reportList.size()>0){
+
+
 
                     List<IotOpeationFillDO> cxLixt = reportList.stream().filter(e->e.getOrgName().equals(attrsDO.getName())).collect(Collectors.toList());
                     //虚拟设备取值
@@ -513,7 +552,6 @@ public class IotOpeationFillController {
                         }
                     }
 
-                }
 
                 attrsDO.setIsCollection(0);
                 attrsDO.setIsSum(0);

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockPageReqVO.java

@@ -22,12 +22,18 @@ public class IotSapStockPageReqVO extends PageParam {
     @Schema(description = "组织部门id", example = "10123")
     private Long deptId;
 
+    @Schema(description = "工厂(SAP) 专业公司 sap code")
+    private String factoryCode;
+
     @Schema(description = "工厂id (system_sap_org表id)", example = "10123")
     private Long factoryId;
 
     @Schema(description = "工厂(SAP) 专业公司")
     private String factory;
 
+    @Schema(description = "库存地点 sap code", example = "10123")
+    private String storageLocationCode;
+
     @Schema(description = "库存地点id", example = "10123")
     private Long storageLocationId;
 

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockRespVO.java

@@ -21,6 +21,10 @@ public class IotSapStockRespVO {
     @ExcelProperty("组织部门id")
     private Long deptId;
 
+    @Schema(description = "工厂(SAP) 专业公司 sap code")
+    @ExcelProperty("工厂(SAP) 专业公司 sap code")
+    private String factoryCode;
+
     @Schema(description = "工厂id (system_sap_org表id)", example = "10123")
     @ExcelProperty("工厂(SAP) 专业公司")
     private Long factoryId;
@@ -29,6 +33,10 @@ public class IotSapStockRespVO {
     @ExcelProperty("工厂(SAP) 专业公司 名称")
     private String factory;
 
+    @Schema(description = "库存地点 sap code", example = "10123")
+    @ExcelProperty("库存地点 sap code")
+    private String storageLocationCode;
+
     @Schema(description = "库存地点id", example = "10123")
     @ExcelProperty("库存地点id")
     private Long storageLocationId;

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockSaveReqVO.java

@@ -16,12 +16,18 @@ public class IotSapStockSaveReqVO {
     @Schema(description = "组织部门id", example = "10123")
     private Long deptId;
 
+    @Schema(description = "工厂 sap code", example = "10123")
+    private String factoryCode;
+
     @Schema(description = "工厂id (system_sap_org表id)", example = "10123")
     private Long factoryId;
 
     @Schema(description = "工厂(SAP) 专业公司")
     private String factory;
 
+    @Schema(description = "库存地点 sap code", example = "10123")
+    private String storageLocationCode;
+
     @Schema(description = "库存地点id", example = "10123")
     private Long storageLocationId;
 

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

@@ -495,7 +495,7 @@ public class IotStaticController {
     public CommonResult<List<Map<String, Object>>> getDeviceStatusStat(@PathVariable("dept") String dept) {
         Set<Long> ids = getDeptIds(dept);
         IotDevicePageReqVO iotDevicePageReqVO = new IotDevicePageReqVO();
-        iotDevicePageReqVO.setDeviceIds(new ArrayList<>(ids));
+        iotDevicePageReqVO.setDeptIds(new ArrayList<>(ids));
         List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList(iotDevicePageReqVO);
         Map<String, Long> order = iotDeviceDOS.stream().collect(Collectors.groupingBy(IotDeviceDO::getDeviceStatus, Collectors.counting()));
         List<Map<String, Object>> results = new ArrayList<>();
@@ -515,7 +515,7 @@ public class IotStaticController {
     public CommonResult<List<Map<String, Object>>> getDeviceTypeStat(@PathVariable("dept") String dept) {
         Set<Long> ids = getDeptIds(dept);
         IotDevicePageReqVO iotDevicePageReqVO = new IotDevicePageReqVO();
-        iotDevicePageReqVO.setDeviceIds(new ArrayList<>(ids));
+        iotDevicePageReqVO.setDeptIds(new ArrayList<>(ids));
         List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList(iotDevicePageReqVO);
         LinkedList<Map<String, Object>> results = new LinkedList<>();
         if ("rh".equals(dept)) {

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotsapstock/IotSapStockDO.java

@@ -33,6 +33,10 @@ public class IotSapStockDO extends BaseDO {
      * 组织部门id
      */
     private Long deptId;
+    /**
+     * 工厂(SAP) 专业公司 SAP code
+     */
+    private String factoryCode;
     /**
      * 工厂id (system_sap_org表id)
      */
@@ -41,6 +45,10 @@ public class IotSapStockDO extends BaseDO {
      * 工厂(SAP) 专业公司
      */
     private String factory;
+    /**
+     * 库存地点 - SAP code
+     */
+    private String storageLocationCode;
     /**
      * 库存地点id
      */

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

@@ -77,7 +77,7 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
 
     default List<IotDeviceDO> selectList(IotDevicePageReqVO reqVO) {
         return selectList(new LambdaQueryWrapperX<IotDeviceDO>()
-                .inIfPresent(IotDeviceDO::getId, reqVO.getDeviceIds())
+                .inIfPresent(IotDeviceDO::getDeptId, reqVO.getDeptIds())
                 .likeIfPresent(IotDeviceDO::getDeviceCode, reqVO.getDeviceCode())
                 .likeIfPresent(IotDeviceDO::getDeviceName, reqVO.getDeviceName())
                 .eqIfPresent(IotDeviceDO::getDeptId, reqVO.getDeptId())

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotInfoMapper.java

@@ -5,6 +5,7 @@ import java.util.*;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoPageReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
@@ -31,4 +32,8 @@ public interface IotInfoMapper extends BaseMapperX<IotInfoDO> {
                 .orderByDesc(IotInfoDO::getId));
     }
 
+    default void deleteListByClassId(List<Long> classIds) {
+        delete(new LambdaQueryWrapperX<IotInfoDO>()
+                .inIfPresent(IotInfoDO::getClassId, classIds));
+    }
 }

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotopeationfill/IotOpeationFillMapper.java

@@ -140,6 +140,9 @@ public interface IotOpeationFillMapper extends BaseMapperX<IotOpeationFillDO> {
     @TenantIgnore
     List<IotOpeationFillDO> pdList(@Param("deviceIds")Collection<Long> deviceIds);
 
+    @TenantIgnore
+    List<IotOpeationFillDO> pdListRh(@Param("deviceIds")Collection<Long> deviceIds);
+
     @TenantIgnore
     List<IotOpeationFillDO> pdList2(@Param("deviceIds")Collection<Long> deviceIds);
 
@@ -168,6 +171,7 @@ public interface IotOpeationFillMapper extends BaseMapperX<IotOpeationFillDO> {
     List<IotDeviceRunLogDO> getDeivceFillInfo(IotDeviceRunLogDO vo);
     @TenantIgnore
     IotDeviceRunLogDO getLogInfo(IotDeviceRunLogDO vo);
+    @TenantIgnore
     IotDeviceRunLogDO getMaxFillInfo(IotDeviceRunLogDO vo);
 
 
@@ -216,6 +220,7 @@ public interface IotOpeationFillMapper extends BaseMapperX<IotOpeationFillDO> {
     @TenantIgnore
     IPage<IotDeviceCountData> deviceCountList(IPage<IotOpeationFillPageReqVO> page, @Param("deptId") Long deptId,
                                               @Param("createTime")LocalDateTime[] createTime,@Param("isFill") Integer isFill,@Param("orderName") String orderName);
+    @TenantIgnore
     List<IotOpeationFillOrderDO> childList(IotOpeationFillOrderDO fillDO);
 
     @TenantIgnore

+ 90 - 151
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/IotOperationPlanJob.java

@@ -21,7 +21,6 @@ import cn.iocoder.yudao.module.pms.service.iotopeationfill.IotOpeationFillServic
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Component;
@@ -63,7 +62,6 @@ public class IotOperationPlanJob implements JobHandler {
     private DeptService deptService;
     @Resource
     private IotOpeationFillService opeationFillService;
-
     /**
      * 1、查询开启状态运行计划
      * 2、根据计划获取设备
@@ -76,7 +74,6 @@ public class IotOperationPlanJob implements JobHandler {
     @Override
     public String execute(String param) throws Exception {
         TenantContextHolder.setIgnore(true);
-        System.out.println("***********创建运行记录填报工单开始执行*********8");
 
 
         //1、查询开启,非删除状态运行计划
@@ -226,192 +223,134 @@ public class IotOperationPlanJob implements JobHandler {
                 .filter(obj -> idList.contains(obj.getUserId()))
                 .collect(Collectors.toList());
 
-        Set<Long> idList1 = new HashSet<>();
-        idList1 =  deptService.getChildDeptIdListFromCache(157L);
-        idList1.add(157L);
 
-        boolean containPlan = idList1.contains(plan.getDeptId());
+        //插入工单主表
+        iotOpeationFillOrderMapper.insertBatch(orderList1);
 
-        List<IotOpeationFillOrderDO> orderList2 = new ArrayList<>();
-        List<IotOperationPlanDO> rpList = new ArrayList<>();
 
         Set<Long> pdeptList = new HashSet<>();
         pdeptList =  deptService.getChildDeptIdListFromCache(plan.getDeptId());
         pdeptList.add(plan.getDeptId());
 
         //查询日报计划
-        rpList = planMapper.getReportPlan(pdeptList);
+        List<IotOperationPlanDO> rpList = planMapper.getReportPlan(pdeptList);
         List<Long> rpdList = rpList.stream().map(IotOperationPlanDO::getDeptId).collect(Collectors.toList());
 
-        if(rpdList.size()>0){
-            orderList2 = orderList.stream().filter(e->rpdList.contains(e.getDeptId())).collect(Collectors.toList());
-        }
 
+        Set<Long> rdIdList = new HashSet<>();
+        rdIdList =  deptService.getChildDeptIdListFromCache(163L);
+        rdIdList.add(163L);
 
+        Set<Long> rhIdList = new HashSet<>();
+        rhIdList =  deptService.getChildDeptIdListFromCache(157L);
+        rhIdList.add(157L);
 
-        if(containPlan){
 
+        boolean exist = rdIdList.contains(plan.getDeptId());
 
+        if(!exist){
+            //1、有指定队伍插入指定队伍日报设备
 
             if(rpList.size()>0){
+                //筛选日报工单
+                List<IotOpeationFillOrderDO> virOrderList = orderList1.stream().filter(e->rpdList.contains(e.getDeptId())).collect(Collectors.toList());
+                if(virOrderList.size()>0){
+                    //创建日报设备
+                    List <IotOpeationFillDO> devList = opeationFillService.reportMethod(virOrderList);
+                    //插入日报设备
+                    iotOpeationFillMapper.insertFill(devList);
 
-                //有责任人,但设备不满足条件,而且属于瑞恒
-                List<IotOpeationFillDO> pdList2 = iotOpeationFillMapper.pdList2(pdeptList);
-                //有责任人,且满足条件,而且属于瑞恒
-
-                //判断是否与日报计划所属部门一致
-                pdList2 = pdList2.stream().filter(e->rpdList.contains(e.getDeptId())).collect(Collectors.toList());
-
-                if(pdList2.size()>0){
-                    orderList2 = new ArrayList<>();
-                    try{
-                        for (IotOpeationFillDO pd:pdList2) {
-
-                            IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
-
-                            fillDO.setOrderName(pd.getOrgName()+"/"+LocalDate.now()+"运行记录填报");
-                            fillDO.setDeptId(pd.getDeptId());
-                            fillDO.setOrderStatus(0);
-                            fillDO.setCreateTime(LocalDateTime.now());
-                            fillDO.setUserName(pd.getUserName());
-                            fillDO.setUserId(pd.getUserId());
-                            fillDO.setMobile(pd.getMobile());
-                            orderList2.add(fillDO);
-
-                        }
-
-                        orderList1.addAll(orderList2);
-
-                    }catch (Exception e){
-                        e.printStackTrace();
-                    }
-                }else if(orderList2.size()>0){
-                    orderList1.addAll(orderList2);
                 }
 
-            }else{
-                List<IotOpeationFillDO> pdList2 = iotOpeationFillMapper.pdList2(pdeptList);
-
-                if(pdList2.size()>0){
-
-                    try{
-                        for (IotOpeationFillDO pd:pdList2) {
-
-                            IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
-
-                            fillDO.setOrderName(pd.getOrgName()+"/"+LocalDate.now()+"运行记录填报");
-                            fillDO.setDeptId(pd.getDeptId());
-                            fillDO.setOrderStatus(0);
-                            fillDO.setCreateTime(LocalDateTime.now());
-                            fillDO.setUserName(pd.getUserName());
-                            fillDO.setUserId(pd.getUserId());
-                            fillDO.setMobile(pd.getMobile());
-                            orderList1.add(fillDO);
-                        }
-
-                    }catch (Exception e){
-                        e.printStackTrace();
-                    }
-                }
             }
-        }
-
-        IotOpeationFillOrderDO todayTime = new IotOpeationFillOrderDO();
-        todayTime.setCreateTime(localDateTime);
-
-        List<String> userList = orderList1.stream().map(IotOpeationFillOrderDO::getUserName).collect(Collectors.toList());
-
-        List<IotOpeationFillOrderDO> allOrder = iotOpeationFillMapper.allOrder(localDateTime,userList);
-
-        if(allOrder.size()>0){
-
-        }else{
-
-            iotOpeationFillOrderMapper.insertBatch(orderList1);
 
-
-                 /* //发送钉钉通知
-            pmsThreadPoolTaskExecutor.execute(()->{
-                try{
-                    for (IotOpeationFillOrderDO order:orderList1) {
-                        pmsMessage.sendMessage(order.getId(), order.getOrderName(), PmsConstants.GENERATE_OPERATION, (long)order.getUserId(), order.getMobile());
+            boolean rhContain = rhIdList.contains(plan.getDeptId());
+
+            if(rhContain){
+                //2、瑞恒无指定队伍全部队伍插入日报设备
+                //筛选正常工单部门id
+                List<Long> deptIdList = orderList1.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
+                //查询瑞恒所有责任人数据
+                Set<Long> pIdList = new HashSet<>();
+                pIdList =  deptService.getChildDeptIdListFromCache(plan.getDeptId());
+                pIdList.add(plan.getDeptId());
+                List<IotOpeationFillDO> rhPdList = iotOpeationFillMapper.pdListRh(pIdList);
+                //筛选与正常工单不同部门的责任人数据
+                List<IotOpeationFillDO> verRPList = rhPdList.stream().filter(e->!deptIdList.contains(e.getDeptId())).collect(Collectors.toList());
+                //筛选小队责任人数据
+                // 使用迭代器遍历集合
+                Iterator<IotOpeationFillDO> iterator = verRPList.iterator();
+                while (iterator.hasNext()) {
+                    IotOpeationFillDO rp = iterator.next();
+                    IotOpeationFillOrderDO rpOrder = new IotOpeationFillOrderDO();
+                    rpOrder.setDeptId(rp.getDeptId());
+                    List<IotOpeationFillOrderDO> childList = iotOpeationFillMapper.childList(rpOrder);
+
+                    // 当childList有元素时,通过迭代器删除当前元素
+                    if (childList.size() > 0) {
+                        iterator.remove(); // 使用迭代器的remove方法安全删除
                     }
-                }catch (Exception e){
-                    e.printStackTrace();
                 }
-            });*/
+                //创建虚拟工单
+                if(verRPList.size()>0){
+                    List<IotOpeationFillOrderDO> virOrderList = new ArrayList<>();
+                    for (IotOpeationFillDO pd:verRPList) {
+                        IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
+                        fillDO.setOrderName(pd.getOrgName()+"/"+LocalDate.now()+"运行记录填报");
+                        fillDO.setDeptId(pd.getDeptId());
+                        fillDO.setOrderStatus(0);
+                        fillDO.setCreateTime(LocalDateTime.now());
+                        fillDO.setUserName(pd.getUserName());
+                        fillDO.setUserId(pd.getUserId());
+                        fillDO.setMobile(pd.getMobile());
+                        virOrderList.add(fillDO);
+                    }
+                    if(virOrderList.size()>0){
+                        orderList1.addAll(virOrderList);
+                        //插入虚拟工单工单
+                        iotOpeationFillOrderMapper.insertBatch(virOrderList);
 
-            for (IotOpeationFillDO device:deviceList) {
-                System.out.println("deviceUser"+device.getUserId());
-                for (IotOpeationFillOrderDO order:orderList1) {
-                    System.out.println("orderId"+order.getUserId());
-                    if(device.getUserId().intValue()==order.getUserId().intValue()){
-                        System.out.println("-----相等-------");
-                        device.setOrderId(order.getId());
                     }
                 }
+                //创建日报设备
+                List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList1);
+                //插入日报设备
+                iotOpeationFillMapper.insertFill(devList);
             }
 
 
-            System.out.println("***********创建运行记录填报工单执行结束*********8");
+        }
 
 
-            System.out.println("*****************插入运行记录设备表***********************");
 
-            for (IotOpeationFillDO re:deviceList) {
-                re.setDeviceId(re.getId());
-                re.setIsReport(0);
+        /*//发送钉钉通知
+        pmsThreadPoolTaskExecutor.execute(()->{
+            try{
+                for (IotOpeationFillOrderDO order:orderList1) {
+                    pmsMessage.sendMessage(order.getId(), order.getOrderName(), PmsConstants.GENERATE_OPERATION, (long)order.getUserId(), order.getMobile());
+                }
+            }catch (Exception e){
+                e.printStackTrace();
             }
-            iotOpeationFillMapper.insertFill(deviceList);
-
-
+        });*/
 
 
-            List<Long> oDeptList = new ArrayList<>();
-
-            if(rpList.size()>0){
-                oDeptList = orderList2.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
-
-                // 先判断oDeptList是否为空,如果为空则根据业务需求设置exist的值
-                boolean exist;
-                if (oDeptList.isEmpty()) {
-                    // 当oDeptList为空时,这里可以根据实际场景设置默认值
-                    // 例如:空列表认为所有元素都被包含,设置为true
-                    exist = false;
-                    // 或者认为不满足,设置为false
-                    // exist = false;
-                } else {
-                    exist = idList1.containsAll(oDeptList);
+        //正常工单设备
+        for (IotOpeationFillDO device:deviceList) {
+            for (IotOpeationFillOrderDO order:orderList1) {
+                if(device.getUserId().intValue()==order.getUserId().intValue()){
+                    device.setOrderId(order.getId());
                 }
+            }
+        }
 
-                if(exist){
-                    List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList2);
-                    //插入虚拟设备
-                    iotOpeationFillMapper.insertFill(devList);
-                }
-
-
-            }else{
-                oDeptList = orderList1.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
+        //插入子表
+        for (IotOpeationFillDO re:deviceList) {
+            re.setDeviceId(re.getId());
+        }
+        iotOpeationFillMapper.insertFill(deviceList);
 
-                // 先判断oDeptList是否为空,如果为空则根据业务需求设置exist的值
-                boolean exist;
-                if (oDeptList.isEmpty()) {
-                    // 当oDeptList为空时,这里可以根据实际场景设置默认值
-                    // 例如:空列表认为所有元素都被包含,设置为true
-                    exist = false;
-                    // 或者认为不满足,设置为false
-                    // exist = false;
-                } else {
-                    exist = idList1.containsAll(oDeptList);
-                }
 
-                if(exist){
-                    List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList1);
-                    //插入虚拟设备
-                    iotOpeationFillMapper.insertFill(devList);
-                }
-            }
-        }
     }
-}
+
+}

+ 148 - 11
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/sap/service/IotSapServiceImpl.java

@@ -513,13 +513,13 @@ public class IotSapServiceImpl implements IotSapService {
         Map<String, Long> factoryIdPair = new HashMap<>();
         // key工厂code    value工厂名称
         Map<String, String> factoryNamePair = new HashMap<>();
-        // key库存地点code    value库存地点id
+        // key工厂code-库存地点code    value库存地点id
         Map<String, Long> storageLocationIdPair = new HashMap<>();
-        // key库存地点id    value库存地点code
+        // key库存地点id    value工厂code-库存地点code
         Map<Long, String> stockLocationCodeIdPair = new HashMap<>();
         // key库存地点code  value部门id
         Map<String, Long> locationCodeDeptIdPair = new HashMap<>();
-        // key库存地点code    value库存地点名称描述
+        // key工厂code-库存地点code    value库存地点名称描述
         Map<String, String> stockLocationNamePair = new HashMap<>();
         // 工厂集合
         factories.forEach(factory -> {
@@ -530,15 +530,13 @@ public class IotSapServiceImpl implements IotSapService {
         storageLocations.forEach(location -> {
             System.out.println("当前库存地点信息:" + location.getFactoryCode() + " - " + location.getStorageLocationCode());
             String uniqueKey = StrUtil.join("-", location.getFactoryCode(), location.getStorageLocationCode());
-            // stockLocationCodeIdPair.put(location.getId(), location.getStorageLocationCode());
             stockLocationCodeIdPair.put(location.getId(), uniqueKey);
-            // storageLocationIdPair.put(location.getStorageLocationCode(), location.getId());
             storageLocationIdPair.put(uniqueKey, location.getId());
-            // stockLocationNamePair.put(location.getStorageLocationCode(), location.getStorageLocationName());
             stockLocationNamePair.put(uniqueKey, location.getStorageLocationName());
         });
         // 筛选出pms系统中未维护的 库存地点 信息(工厂-库存地点编码)
         Set<String> notExistStorageLocations = new HashSet<>();
+        // 系统中未维护的 工厂 库存地点 也需要存储到数据库 但是 不设置 deptId
         sapStocks.forEach(stock -> {
             String uniqueKey = StrUtil.join("-", stock.getWERKS(), stock.getLGORT());
             if (!storageLocationIdPair.containsKey(uniqueKey)) {
@@ -566,7 +564,7 @@ public class IotSapServiceImpl implements IotSapService {
                 });
             }
         });
-        // 查询所有SAP库存集合A,以 ‘库存地点+物料编码’ 为唯一key 如果 sapStocks 中有物料不在A中 新增物料
+        // 查询所有SAP库存集合A,以 ‘库存地点id+物料编码’ 为唯一key 如果 sapStocks 中有物料不在A中 新增物料
         Set<String> existStockKeys = new HashSet<>();
         List<IotSapStockDO> existStocks = TenantUtils.execute(1L, () -> iotSapStockMapper.selectList());
         if (CollUtil.isNotEmpty(existStocks)) {
@@ -576,6 +574,19 @@ public class IotSapServiceImpl implements IotSapService {
                     .map(stk -> StrUtil.join("-", String.valueOf(stk.getStorageLocationId()), stk.getMaterialCode()))
                     .collect(Collectors.toSet());
         }
+        System.out.println(factoryCode + "当前库中已有sap库存数量:" + existStockKeys.size());
+
+        // todo 没有维护SAP工厂 库存地点的组织 已经存在的库存数据
+        Set<String> noFactoryExistStockKeys = new HashSet<>();
+        if (CollUtil.isNotEmpty(existStocks)) {
+            noFactoryExistStockKeys = existStocks.stream()
+                    // 过滤非空对象和非空code
+                    .filter(stk -> ObjUtil.isNotEmpty(stk) && StrUtil.isNotBlank(stk.getMaterialCode())
+                            && StrUtil.isNotBlank(stk.getFactoryCode()) && StrUtil.isNotBlank(stk.getStorageLocationCode()))
+                    .map(stk -> StrUtil.join("-", stk.getFactoryCode(), stk.getStorageLocationCode(), stk.getMaterialCode()))
+                    .collect(Collectors.toSet());
+        }
+
         // 将已经存在的库存数据 设置成 Map<String, IotSapStockDO> 的形式 便于后续更新
         // key库存地点id-物料编码       value库存对象   从此集合中筛选将要被更新的库存对象
         Map<String, IotSapStockDO> tobeUpdatedStockPair = new HashMap<>();
@@ -588,7 +599,19 @@ public class IotSapServiceImpl implements IotSapService {
                         (existing, replacement) -> existing // 处理键冲突: 保留先出现的元素
                 ));
 
-        System.out.println(factoryCode + "当前库中已有sap库存数量:" + existStockKeys.size());
+        // todo 没有配置SAP 工厂 库存地点 的组织库存更新
+        // 将已经存在的库存数据 设置成 Map<String, IotSapStockDO> 的形式 便于后续更新
+        // key工厂code-库存地点code-物料编码       value库存对象   从此集合中筛选将要被更新的库存对象
+        Map<String, IotSapStockDO> noFactoryTobeUpdatedStockPair = new HashMap<>();
+        noFactoryTobeUpdatedStockPair = existStocks.stream()
+                .filter(stk -> StrUtil.isNotBlank(stk.getMaterialCode()) && StrUtil.isNotBlank(stk.getFactoryCode())
+                        && StrUtil.isNotBlank(stk.getStorageLocationCode()))
+                .collect(Collectors.toMap(
+                        stk -> StrUtil.join("-", stk.getFactoryCode(), stk.getStorageLocationCode(), stk.getMaterialCode()),
+                        stk -> stk, // 值为对象本身
+                        (existing, replacement) -> existing // 处理键冲突: 保留先出现的元素
+                ));
+
         // 找出需要新增的库存(SAP物料编码去掉前导零后,不在现有物料集合中的记录)
         Set<String> finalExistStockKeys = existStockKeys;
         List<IotSapStockVO> newStocks = sapStocks.stream()
@@ -602,7 +625,22 @@ public class IotSapServiceImpl implements IotSapService {
                     return !finalExistStockKeys.contains(StrUtil.join("-", storageLocationId, processedCode));
                 })
                 .collect(Collectors.toList());
+
         System.out.println(factoryCode + "需要新增的sap库存数量:" + newStocks.size());
+
+        // todo 没有维护SAP工厂 库存地点的组织 新增的库存数据
+        // 找出需要新增的库存(SAP物料编码去掉前导零后,不在现有物料集合中的记录)
+        Set<String> noFactoryFinalExistStockKeys = noFactoryExistStockKeys;
+        List<IotSapStockVO> noFactoryNewStocks = sapStocks.stream()
+                .filter(stk -> StrUtil.isNotBlank(stk.getMATNR()) && StrUtil.isNotBlank(stk.getLGORT()) && StrUtil.isNotBlank(stk.getWERKS()))
+                .filter(stk -> {
+                    // 处理前导零:移除MATNR前的 00000000
+                    String processedCode = stk.getMATNR().replaceFirst("^0+", "");
+                    // 本地已经配置过库存地点 包含SAP库存接口返回的库存地点
+                    return !noFactoryFinalExistStockKeys.contains(StrUtil.join("-", stk.getWERKS(), stk.getLGORT(), processedCode));
+                })
+                .collect(Collectors.toList());
+
         // 新增SAP库存数据
         List<IotSapStockDO> tobeAddedStocks = new ArrayList<>();
         if (CollUtil.isNotEmpty(newStocks)) {
@@ -645,6 +683,51 @@ public class IotSapServiceImpl implements IotSapService {
                 }
             });
         }
+
+        // todo 新增 没有配置组织部门的 SAP库存数据
+        List<IotSapStockDO> noFactoryTobeAddedStocks = new ArrayList<>();
+        if (CollUtil.isNotEmpty(noFactoryNewStocks)) {
+            noFactoryNewStocks.forEach(stock -> {
+                // 只保存pms维护过库存地点的数据
+                String uniqueKey = StrUtil.join("-", stock.getWERKS(), stock.getLGORT());
+                IotSapStockDO sapStock = new IotSapStockDO();
+                // 部门统一设置为 科瑞石油技术
+                sapStock.setDeptId(156l);
+                // 工厂id
+                /* if (factoryIdPair.containsKey(stock.getWERKS())) {
+                    sapStock.setFactoryId(factoryIdPair.get(stock.getWERKS()));
+                } */
+                sapStock.setFactoryCode(stock.getWERKS());
+                // 工厂名称
+                if (factoryNamePair.containsKey(stock.getWERKS())) {
+                    sapStock.setFactory(factoryNamePair.get(stock.getWERKS()));
+                }
+                // 库存地点 code
+                sapStock.setStorageLocationCode(stock.getLGORT());
+                // 库存地点id
+                /* if (storageLocationIdPair.containsKey(uniqueKey)) {
+                    sapStock.setStorageLocationId(storageLocationIdPair.get(uniqueKey));
+                } */
+                // 库存地点名称
+                if (stockLocationNamePair.containsKey(uniqueKey)) {
+                    sapStock.setProjectDepartment(stockLocationNamePair.get(uniqueKey));
+                }
+                // 物料编码 需要去掉前缀 00000000
+                sapStock.setMaterialCode(stock.getMATNR().replaceFirst("^0+", ""));
+                // 物料描述
+                sapStock.setMaterialName(stock.getMAKTX());
+                // 库存数量
+                sapStock.setQuantity(stock.getLABST());
+                // 单价
+                sapStock.setUnitPrice(stock.getJIAGE());
+                // 基本单位
+                sapStock.setUnit(stock.getMEINS());
+                // 同步时间
+                sapStock.setSyncTime(LocalDateTime.now());
+                noFactoryTobeAddedStocks.add(sapStock);
+            });
+        }
+
         // 使用返回的SAP库存数据更新已有的 库存数据
         // pms中已有 SAP返回数据中也存在 则更新
         List<IotSapStockDO> actualUpdatedStocks = new ArrayList<>();
@@ -663,8 +746,27 @@ public class IotSapServiceImpl implements IotSapService {
             });
         }
         System.out.println(factoryCode + "需要更新的SAP库存数量:" + actualUpdatedStocks.size());
-        // pms中已有 但是 SAP返回数据不存在 如果设置了安全库存,则库存为0,若没有设置安全库存,则可以删除
 
+        // todo sap 工厂 库存地点 未关联组织部门
+        // 使用返回的SAP库存数据更新已有的 库存数据 pms中已有 SAP返回数据中也存在 则更新
+        List<IotSapStockDO> noFactoryActualUpdatedStocks = new ArrayList<>();
+        // key工厂code-库存地点code-物料编码      value库存对象
+        Map<String, IotSapStockVO> noFactoryExistStockPair = createNoFactoryExistStockMap(sapStocks, noFactoryExistStockKeys, storageLocationIdPair);
+        if (CollUtil.isNotEmpty(noFactoryExistStockPair)) {
+            Map<String, IotSapStockDO> finalTobeUpdatedStockPair = noFactoryTobeUpdatedStockPair;
+            noFactoryExistStockPair.forEach((k, v) -> {
+                if (finalTobeUpdatedStockPair.containsKey(k)) {
+                    IotSapStockDO sapStock = finalTobeUpdatedStockPair.get(k);
+                    sapStock.setUnitPrice(v.getJIAGE());    // 更新库存价格
+                    sapStock.setQuantity(v.getLABST());     // 更新库存数量
+                    sapStock.setUnit(v.getMEINS());         // 更新基本单位
+                    noFactoryActualUpdatedStocks.add(sapStock);
+                }
+            });
+        }
+        System.out.println(factoryCode + "SAP工厂库存地点未关联组织部门-需要更新的SAP库存数量:" + noFactoryActualUpdatedStocks.size());
+
+        // pms中已有 但是 SAP返回数据不存在 如果设置了安全库存,则库存为0,若没有设置安全库存,则可以删除
 
         // 遍历明细数据 新增 修改 SAP库存数据
         /* List<IotSapStockDO> tobeSapStocks = new ArrayList<>();
@@ -705,14 +807,22 @@ public class IotSapServiceImpl implements IotSapService {
                 tobeSapStocks.add(sapStock);
             }
         }); */
-        // 本地库存 初始化 批量插入本地库存 记录
+        // 本地库存 初始化 批量插入SAP 库存 工厂 库存地点 已经关联了组织架构部门
         if (CollUtil.isNotEmpty(tobeAddedStocks)) {
             TenantUtils.execute(1L, () -> iotSapStockMapper.insertBatch(tobeAddedStocks));
         }
+        // 本地库存 初始化 批量插入本地库存 记录 工厂 库存地点 未关联了组织架构部门
+        if (CollUtil.isNotEmpty(noFactoryTobeAddedStocks)) {
+            TenantUtils.execute(1L, () -> iotSapStockMapper.insertBatch(noFactoryTobeAddedStocks));
+        }
         // pms中存在而且SAP接口也返回的库存数据:更新
         if (CollUtil.isNotEmpty(actualUpdatedStocks)) {
             TenantUtils.execute(1L, () -> iotSapStockMapper.updateBatch(actualUpdatedStocks));
         }
+        // pms中存在而且SAP接口也返回的库存数据:更新 工厂 库存地点 未关联了组织架构部门
+        if (CollUtil.isNotEmpty(noFactoryActualUpdatedStocks)) {
+            TenantUtils.execute(1L, () -> iotSapStockMapper.updateBatch(noFactoryActualUpdatedStocks));
+        }
     }
 
     /**
@@ -772,7 +882,7 @@ public class IotSapServiceImpl implements IotSapService {
     private Map<String, IotSapStockVO> createExistStockMap(List<IotSapStockVO> sapStocks, Set<String> existStockKeys, Map<String, Long> storageLocationIdPair) {
         return sapStocks.stream()
                 .filter(sapStock -> StrUtil.isNotBlank(sapStock.getMATNR()) &&
-                        ObjUtil.isNotEmpty(sapStock.getLGORT()) &&
+                        StrUtil.isNotBlank(sapStock.getLGORT()) &&
                         storageLocationIdPair.containsKey(StrUtil.join("-", sapStock.getWERKS(), sapStock.getLGORT())))
                 .map(sapStock -> {
                     // 处理前导零:移除MATNR前的 00000000
@@ -788,4 +898,31 @@ public class IotSapServiceImpl implements IotSapService {
                         (existing, replacement) -> existing // 如果有重复的key,保留第一个值
                 ));
     }
+
+    /**
+     * 处理本地未维护的工厂 库存地点 同步过来的物料
+     * sap库存 更新 创建 唯一key(工厂code+库存地点code-物料编码) 到 sap库存对象 的映射
+     * pms中已有的库存  SAP库存接口也返回了 需要更新
+     * @param sapStocks SAP库存列表
+     * @param existStockKeys 数据库中已存在的 sap库存 集合
+     * @param storageLocationIdPair key库存地点code    value库存地点id
+     * @return 物料编码到描述的映射
+     */
+    private Map<String, IotSapStockVO> createNoFactoryExistStockMap(List<IotSapStockVO> sapStocks,
+                                                                    Set<String> existStockKeys, Map<String, Long> storageLocationIdPair) {
+        return sapStocks.stream()
+                .filter(sapStock -> StrUtil.isNotBlank(sapStock.getMATNR()) && StrUtil.isNotBlank(sapStock.getLGORT()))
+                .map(sapStock -> {
+                    // 处理前导零:移除MATNR前的 00000000
+                    String processedCode = sapStock.getMATNR().replaceFirst("^0+", "");
+                    // 本地已经配置过库存地点 包含SAP库存接口返回的库存地点
+                    return new AbstractMap.SimpleEntry<>(StrUtil.join("-", sapStock.getWERKS(), sapStock.getLGORT(), processedCode), sapStock);
+                })
+                .filter(entry -> existStockKeys.contains(entry.getKey()))
+                .collect(Collectors.toMap(
+                        Map.Entry::getKey,
+                        Map.Entry::getValue,
+                        (existing, replacement) -> existing // 如果有重复的key,保留第一个值
+                ));
+    }
 }

+ 21 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotTreeServiceImpl.java

@@ -14,11 +14,13 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotTreeDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.IotInfoClassifyMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.IotInfoMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.IotTreeMapper;
 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.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -27,6 +29,7 @@ import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 
@@ -49,6 +52,17 @@ public class IotTreeServiceImpl implements IotTreeService {
     private IotDeviceMapper iotDeviceMapper;
     @Autowired
     private IotInfoClassifyMapper iotInfoClassifyMapper;
+    @Autowired
+    private IotInfoMapper iotInfoMapper;
+
+    @Override
+    public List<IotTreeDO> getIotDeviceTree(Long deviceId) {
+        IotTreeListReqVO reqVO = new IotTreeListReqVO();
+        reqVO.setType("device");
+        reqVO.setOriginId(deviceId);
+        List<IotTreeDO> iotTreeDOS = iotTreeMapper.selectList(reqVO);
+        return iotTreeDOS;
+    }
 
     @Override
     public List<IotTreeDO> getIotDeviceTree(Long deviceId) {
@@ -125,8 +139,13 @@ public class IotTreeServiceImpl implements IotTreeService {
     public void deleteIotTree(Long id) {
         // 校验存在
         validateIotTreeExists(id);
-        // 删除
-        iotTreeMapper.deleteById(id);
+
+        List<Long> childIds = getChildTreeList(ImmutableList.of(id)).stream().map(IotTreeDO::getId).collect(Collectors.toList());
+        childIds.add(id);
+        //删除iot的树形结构
+        iotTreeMapper.deleteByIds(childIds);
+        // 删除资料
+        iotInfoMapper.deleteListByClassId(childIds);
     }
 
     private void validateIotTreeExists(Long id) {

+ 19 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotopeationfill/IotOpeationFillServiceImpl.java

@@ -53,6 +53,8 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
 
     private static Long RH_CLASS_ID = 226L;
 
+    private static Long RY_CLASS_ID = 227L;
+
     @Override
     public Long createIotOpeationFill(IotOpeationFillSaveReqVO createReqVO) {
         // 插入
@@ -323,6 +325,16 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
     @Override
     public List<IotOpeationFillDO> reportMethod(List<IotOpeationFillOrderDO> orderList) {
         List<IotOpeationFillDO> devList = new ArrayList<>();
+
+
+        Set<Long> rhIdList = deptService.getChildDeptIdListFromCache(157L);
+        rhIdList.add(157L);
+
+
+        Set<Long> ryIdList =  deptService.getChildDeptIdListFromCache(158L);
+        ryIdList.add(158L);
+
+
         //判断工单主数据是否有值
         if(orderList.size()>0){
             //遍历工单主数据,根据dept_id查询是否为根节点
@@ -336,7 +348,13 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
                     IotOpeationFillDO devOrder = new IotOpeationFillDO();
                     devOrder.setDeviceCode("");
                     devOrder.setDeviceName("生产日报");
-                    devOrder.setDeviceCategoryId(RH_CLASS_ID);
+
+                    if(rhIdList.contains(orderDO.getDeptId())){
+                        devOrder.setDeviceCategoryId(RH_CLASS_ID);
+                    }else if(ryIdList.contains(orderDO.getDeptId())){
+                        devOrder.setDeviceCategoryId(RY_CLASS_ID);
+                    }
+
                     devOrder.setDeptId(orderDO.getDeptId());
                     devOrder.setIsReport(1);
                     devOrder.setOrderId(orderDO.getId());

+ 34 - 5
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotOpeationFillMapper.xml

@@ -307,7 +307,7 @@
         JOIN rq_iot_model_template_attrs c ON a.device_category_id = c.device_category_id
         JOIN rq_iot_opeation_fill_order d ON a.order_id = d.id
         WHERE
-        a.dept_id IN (
+        <!--a.dept_id IN (
         SELECT id FROM (
         SELECT d1.id FROM system_dept d1 WHERE d1.id = #{deptId}
         UNION ALL
@@ -318,9 +318,10 @@
         SELECT d4.id FROM system_dept d1 JOIN system_dept d2 ON d2.parent_id = d1.id JOIN system_dept d3 ON d3.parent_id = d2.id JOIN system_dept d4 ON d4.parent_id = d3.id WHERE d1.id = #{deptId}
         ) AS dept_hierarchy
         )
-        AND (
+        AND -->(
+        1=1
         <if test="orderId != null and orderId != ''">
-            a.order_id = #{orderId}
+           and  a.order_id = #{orderId}
         </if>
         <!--<if test="orgName != null and orgName != ''">
             (
@@ -556,6 +557,33 @@
         </if>
     </select>
 
+    <select id="pdListRh" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
+        select
+        distinct
+        b.id user_id,
+        b.nickname user_name,
+        c.id dept_id,
+        b.mobile,
+        c.name orgName
+        from
+        rq_iot_device_person a
+        left join
+        system_users b
+        on
+        a.person_id = b.id
+        left join
+        system_dept c
+        on
+        b.dept_id = c.id
+        where b.id is not null
+        <if test="deviceIds != null and !deviceIds.isEmpty()">
+            and c.id  in
+            <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+    </select>
+
 
     <select id="allOrder" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
         select distinct user_name
@@ -1026,7 +1054,7 @@
         where
             device_id = #{deviceId}
         and
-            DATE(create_time) = #{createTime}
+            DATE(create_time) = DATE(#{createTime})
         LIMIT 1
     </select>
 
@@ -1079,8 +1107,9 @@
                        b2.daily_report = 1
                 ))
             -- 第二个查询的条件(通过OR代替UNION)
-             OR (a.is_report = 0 AND b.daily_report = 1)
+             OR (a.is_report is null AND b.daily_report = 1)
             )
+          and a.device_code != ''
     </select>
 
     <select id="reportList1" parameterType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO"