Browse Source

后端上传

lipenghui 3 months ago
parent
commit
825f2838e5

+ 43 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java

@@ -1,22 +1,28 @@
 package cn.iocoder.yudao.module.pms.controller.admin;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
 import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
 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.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+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;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSaveReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotbom.IotBomDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.YfDeviceDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.TDDeviceMapper;
+import cn.iocoder.yudao.module.pms.service.DeviceServiceImpl;
 import cn.iocoder.yudao.module.pms.service.IotDeviceService;
 import cn.iocoder.yudao.module.pms.service.IotProductClassifyService;
 import cn.iocoder.yudao.module.pms.service.iotbom.IotBomService;
 import cn.iocoder.yudao.module.pms.service.iotmodel.IotModelService;
+import cn.iocoder.yudao.module.pms.service.yanfan.YfDeviceService;
 import cn.iocoder.yudao.module.pms.util.IotDeviceConvert;
 import cn.iocoder.yudao.module.supplier.dal.dataobject.product.SupplierDO;
 import cn.iocoder.yudao.module.supplier.service.product.SupplierService;
@@ -27,14 +33,18 @@ import cn.iocoder.yudao.module.system.service.dict.DictDataService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.annotation.security.PermitAll;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
@@ -63,6 +73,10 @@ public class IotDeviceController {
     private IotModelService iotModelService;
     @Resource
     private IotBomService iotBomService;
+    @Autowired
+    private YfDeviceService yfDeviceService;
+    @Autowired
+    private DeviceServiceImpl deviceServiceImpl;
 
     @PostMapping("/create")
     @Operation(summary = "创建设备台账")
@@ -125,11 +139,19 @@ public class IotDeviceController {
                 pageResult.getTotal()));
     }
 
+    @Autowired
+    private TDDeviceMapper deviceMapper;
+
     @GetMapping("/td/page")
     @Operation(summary = "获得设备台账包含数采信息")
     @PreAuthorize("@ss.hasPermission('rq:iot-device:query')")
     public CommonResult<PageResult<IotDeviceRespVO>> getIotDeviceTdPage(@Valid IotDevicePageReqVO pageReqVO) {
-        PageResult<IotDeviceDO> pageResult = iotDeviceService.getIotDevicePage(pageReqVO);
+        List<String> codes = new ArrayList<>();
+        List<YfDeviceDO> allDevice = yfDeviceService.getAllDevice();
+        allDevice.forEach(d -> {
+            codes.add(d.getSerialNumber());
+        });
+        PageResult<IotDeviceDO> pageResult = iotDeviceService.getIotDeviceTdPage(pageReqVO, codes);
         if (CollUtil.isEmpty(pageResult.getList())) {
             return success(new PageResult<>(pageResult.getTotal()));
         }
@@ -138,12 +160,32 @@ public class IotDeviceController {
         PageResult<IotDeviceRespVO> result = new PageResult<>(IotDeviceConvert.INSTANCE.convertList(pageResult.getList(), deptMap),
                 pageResult.getTotal());
         for (IotDeviceRespVO iotDeviceRespVO : result.getList()) {
+            IotProductClassifyDO iotProductClassify = iotProductClassifyService.getIotProductClassify(iotDeviceRespVO.getAssetClass());
+            iotDeviceRespVO.setAssetClassName(iotProductClassify.getName());
             String deviceCode = iotDeviceRespVO.getDeviceCode();
+            allDevice.stream().filter(e -> e.getSerialNumber().equals(deviceCode)).findFirst().ifPresent(e -> {
+                iotDeviceRespVO.setIfInline(e.getStatus());
+                List<DeviceVO> deviceVOS = deviceMapper.selectNew(e.getSerialNumber());
+                if (CollUtil.isNotEmpty(deviceVOS)) {
+                    Timestamp ts = deviceVOS.get(0).getTs();
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    String format = sdf.format(ts);
+                    iotDeviceRespVO.setLastInlineTime(format);
+                }
+            });
 
         }
         return success(result);
     }
 
+    @GetMapping("/td/test")
+    @Operation(summary = "获得设备台账包含数采信息")
+    @PermitAll
+    public void getIotDeviceTdePage() {
+        List<YfDeviceDO> allDevice = yfDeviceService.getAllDevice();
+        System.out.println(allDevice);
+    }
+
     @GetMapping("/deviceAssociateBomPage")
     @Operation(summary = "获得设备台账分页")
     @PreAuthorize("@ss.hasPermission('rq:iot-device:query')")

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceRespVO.java

@@ -163,7 +163,7 @@ public class IotDeviceRespVO {
     @Schema(description = "设备累计运行时间")
     private BigDecimal totalRunTime;
     @Schema(description = "是否在线")
-    private Boolean ifInline;
+    private Integer ifInline;
 
     @Schema(description = "最后在线时间")
     private String lastInlineTime;

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/yanfan/YfDeviceDO.java

@@ -58,7 +58,7 @@ public class YfDeviceDO extends BaseDO {
     /**
      * 设备状态(1-未激活,2-禁用,3-在线,4-离线)
      */
-    private Boolean status;
+    private Integer status;
     /**
      * 信号强度(	信号极好4格[-55— 0],	信号好3格[-70— -55],	信号一般2格[-85— -70],	信号差1格[-100— -85])
      */

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

@@ -54,6 +54,40 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
                 .orderByDesc(IotDeviceDO::getId));
     }
 
+    default PageResult<IotDeviceDO> selectTdPage(IotDevicePageReqVO reqVO, Collection<Long> deptIds, Collection<String> codes) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<IotDeviceDO>()
+                .inIfPresent(IotDeviceDO::getDeviceCode, codes)
+                .likeIfPresent(IotDeviceDO::getDeviceName, reqVO.getDeviceName())
+                .eqIfPresent(IotDeviceDO::getBrand, reqVO.getBrand())
+                .eqIfPresent(IotDeviceDO::getModel, reqVO.getModel())
+                //.eqIfPresent(IotDeviceDO::getOrgId, reqVO.getOrgId())
+                .inIfPresent(IotDeviceDO::getDeptId, deptIds)
+                .eqIfPresent(IotDeviceDO::getDeviceStatus, reqVO.getDeviceStatus())
+                .eqIfPresent(IotDeviceDO::getAssetProperty, reqVO.getAssetProperty())
+                .eqIfPresent(IotDeviceDO::getPicUrl, reqVO.getPicUrl())
+                .eqIfPresent(IotDeviceDO::getRemark, reqVO.getRemark())
+                .eqIfPresent(IotDeviceDO::getManufacturerId, reqVO.getManufacturerId())
+                .eqIfPresent(IotDeviceDO::getSupplierId, reqVO.getSupplierId())
+                .eqIfPresent(IotDeviceDO::getNameplate, reqVO.getNameplate())
+                .eqIfPresent(IotDeviceDO::getExpires, reqVO.getExpires())
+                .eqIfPresent(IotDeviceDO::getPlPrice, reqVO.getPlPrice())
+                //.betweenIfPresent(IotDeviceDO::getPlDate, reqVO.getPlDate())
+                //.betweenIfPresent(IotDeviceDO::getManDate, reqVO.getManDate())
+                .eqIfPresent(IotDeviceDO::getPlYear, reqVO.getPlYear())
+                .betweenIfPresent(IotDeviceDO::getPlStartDate, reqVO.getPlStartDate())
+                .eqIfPresent(IotDeviceDO::getPlMonthed, reqVO.getPlMonthed())
+                .eqIfPresent(IotDeviceDO::getPlAmounted, reqVO.getPlAmounted())
+                .eqIfPresent(IotDeviceDO::getRemainAmount, reqVO.getRemainAmount())
+                .eqIfPresent(IotDeviceDO::getInfoId, reqVO.getInfoId())
+                .eqIfPresent(IotDeviceDO::getInfoType, reqVO.getInfoType())
+                .eqIfPresent(IotDeviceDO::getAssetClass, reqVO.getAssetClass())
+                .likeIfPresent(IotDeviceDO::getInfoName, reqVO.getInfoName())
+                .eqIfPresent(IotDeviceDO::getInfoRemark, reqVO.getInfoRemark())
+                .eqIfPresent(IotDeviceDO::getInfoUrl, reqVO.getInfoUrl())
+                .eqIfPresent(IotDeviceDO::getTemplateJson, reqVO.getTemplateJson())
+                .orderByDesc(IotDeviceDO::getId));
+    }
+
     /* default PageResult<IotDeviceDO> deviceAssociateBomPage(IotDevicePageReqVO reqVO, Collection<Long> deptIds) {
         MPJLambdaWrapperX<IotDeviceDO> query = new MPJLambdaWrapperX<IotDeviceDO>();
         query.innerJoin(IotBomDO.class, IotBomDO::getDeviceCategoryId, IotDeviceDO::getAssetClass)

+ 1 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/InspectCreateOrderJob.java

@@ -57,8 +57,7 @@ public class InspectCreateOrderJob implements JobHandler {
     private void deal(IotInspectPlanDO plan, Date date) {
         Date date1 = new Date();
         if ("hour".equals(plan.getPlanUnit())){
-            //todo
-            DateTime dateTime = DateUtil.offsetMinute(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
+            DateTime dateTime = DateUtil.offsetHour(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
             if (date1.compareTo(dateTime) > 0){
                 createPlan(plan);
             }

+ 1 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/mainworkorder/CreateMainWorkOrderJob.java

@@ -115,8 +115,7 @@ public class CreateMainWorkOrderJob implements JobHandler {
     private void deal(IotInspectPlanDO plan, Date date) {
         Date date1 = new Date();
         if ("hour".equals(plan.getPlanUnit())){
-            //todo
-            DateTime dateTime = DateUtil.offsetMinute(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
+            DateTime dateTime = DateUtil.offsetHour(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
             if (date1.compareTo(dateTime) > 0){
                 createPlan(plan);
             }

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

@@ -58,6 +58,7 @@ public interface IotDeviceService {
      * @return 设备台账分页
      */
     PageResult<IotDeviceDO> getIotDevicePage(IotDevicePageReqVO pageReqVO);
+    PageResult<IotDeviceDO> getIotDeviceTdPage(IotDevicePageReqVO pageReqVO, List<String> codes);
 
     /**
      * 获得 设备bom 关联 关系 分页

+ 14 - 7
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -12,10 +12,12 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
 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.dataobject.iotmodel.IotModelDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.YfDeviceDO;
 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.IotTreeMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotmodel.IotModelMapper;
+import cn.iocoder.yudao.module.pms.service.yanfan.YfDeviceService;
 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
@@ -57,13 +59,8 @@ public class IotDeviceServiceImpl implements IotDeviceService {
     private IotModelMapper iotModelMapper;
     @Resource
     private DictDataService dictDataService;
-
-    @Slave
-    public List<Map<String,Object>> getTdDevice() {
-        List<Map<String, Object>> devices = new ArrayList<>();
-
-        return devices;
-    }
+    @Resource
+    private YfDeviceService yfDeviceService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -158,6 +155,16 @@ public class IotDeviceServiceImpl implements IotDeviceService {
         return iotDeviceMapper.selectPage(pageReqVO,ids);
     }
 
+    @Override
+    public PageResult<IotDeviceDO> getIotDeviceTdPage(IotDevicePageReqVO pageReqVO, List<String> codes) {
+        Set<Long> ids = new HashSet<>();
+        if (Objects.nonNull(pageReqVO.getDeptId())) {
+            ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
+            ids.add(pageReqVO.getDeptId());
+        }
+        return iotDeviceMapper.selectTdPage(pageReqVO,ids, codes);
+    }
+
     /* @Override
     public PageResult<IotDeviceDO> deviceAssociateBomPage(IotDevicePageReqVO pageReqVO) {
         Set<Long> ids = new HashSet<>();

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/yanfan/YfDeviceService.java

@@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.module.pms.controller.admin.yanfan.vo.DevicePageReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.YfDeviceDO;
 
+import java.util.List;
+
 /**
  * 设备 Service 接口
  *
@@ -27,4 +29,6 @@ public interface YfDeviceService {
      */
     PageResult<YfDeviceDO> getDevicePage(DevicePageReqVO pageReqVO);
 
+    List<YfDeviceDO> getAllDevice();
+
 }

+ 14 - 3
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/yanfan/YfDeviceServiceImpl.java

@@ -1,13 +1,17 @@
 package cn.iocoder.yudao.module.pms.service.yanfan;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
 import cn.iocoder.yudao.module.pms.controller.admin.yanfan.vo.DevicePageReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.YfDeviceDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.yanfan.YfDeviceMapper;
+import com.baomidou.dynamic.datasource.annotation.Slave;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
+import java.util.Collections;
+import java.util.List;
 
 /**
  * 设备 Service 实现类
@@ -19,16 +23,23 @@ import javax.annotation.Resource;
 public class YfDeviceServiceImpl implements YfDeviceService {
 
     @Resource
-    private YfDeviceMapper deviceMapper;
+    private YfDeviceMapper yfDeviceMapper;
 
     @Override
     public YfDeviceDO getDevice(Long id) {
-        return deviceMapper.selectById(id);
+        return yfDeviceMapper.selectById(id);
     }
 
     @Override
     public PageResult<YfDeviceDO> getDevicePage(DevicePageReqVO pageReqVO) {
-        return deviceMapper.selectPage(pageReqVO);
+        return yfDeviceMapper.selectPage(pageReqVO);
+    }
+
+    @Override
+    @Slave
+    @TenantIgnore
+    public List<YfDeviceDO> getAllDevice() {
+        return yfDeviceMapper.selectList(null);
     }
 
 }

+ 1 - 1
yudao-server/src/main/resources/application-dev.yaml

@@ -78,7 +78,7 @@ spring:
     host: localhost # 地址
     port: 6379 # 端口
     database: 0  # 数据库索引
-    #password: 123456
+    password: 123456
 
 --- #################### 定时任务相关配置 ####################
 

+ 1 - 0
yudao-server/src/main/resources/application.yaml

@@ -274,6 +274,7 @@ yudao:
   tenant: # 多租户相关配置项
     enable: true
     ignore-urls:
+      - /admin-api/rq/iot-device/td/test
       - /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号
       - /admin-api/system/tenant/get-by-website # 基于域名获取租户,不许带租户编号
       - /admin-api/system/tenant/simple-list # 获取租户列表,不许带租户编号