Zimo 12 時間 前
コミット
a2c64f9730

+ 15 - 9
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java

@@ -122,16 +122,22 @@ public class IotThingModelController {
 
     @GetMapping("/import-common")
     @Operation(summary = "产品导入通用物模型")
-    public CommonResult<String> importCommon(Long commonId, Long productId) {
-        ThingModelCommonDO thingModelCommonDO = thingModelCommonMapper.selectById(commonId);
-        if (thingModelCommonDO == null) {
-            throw new ServiceException(new ErrorCode(2, "不存在通用物模型"));
+    public CommonResult<String> importCommon(String commonId, Long productId) {
+        for (String s : commonId.split(",")) {
+            ThingModelCommonDO thingModelCommonDO = thingModelCommonMapper.selectById(s);
+            if (thingModelCommonDO == null) {
+                throw new ServiceException(new ErrorCode(2, "不存在通用物模型"));
+            }
+            IotThingModelDO iotThingModelDO = new IotThingModelDO();
+            BeanUtils.copyProperties(thingModelCommonDO, iotThingModelDO);
+            iotThingModelDO.setProductId(productId);
+            IotProductDO product = productService.getProduct(productId);
+            if (java.util.Objects.nonNull(product)) {
+                iotThingModelDO.setProductKey(product.getProductKey());
+            }
+            iotThingModelDO.setDeleted(false);
+            iotThingModelMapper.insert(iotThingModelDO);
         }
-        IotThingModelDO iotThingModelDO = new IotThingModelDO();
-        BeanUtils.copyProperties(thingModelCommonDO, iotThingModelDO);
-        iotThingModelDO.setProductId(productId);
-        iotThingModelDO.setDeleted(false);
-        iotThingModelMapper.insert(iotThingModelDO);
         return success("导入成功");
     }
 }

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

@@ -4,6 +4,7 @@ import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
+import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
@@ -159,6 +160,42 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
                 .eqIfPresent(IotDeviceDO::getBomSyncStatus, reqVO.getBomSyncStatus()));
     }
 
+    @DataPermission
+    default List<IotDeviceDO> selectListNoDept(IotDevicePageReqVO reqVO) {
+        return selectList(new LambdaQueryWrapperX<IotDeviceDO>()
+                .inIfPresent(IotDeviceDO::getDeptId, reqVO.getDeptIds())
+                .likeIfPresent(IotDeviceDO::getYfDeviceCode, reqVO.getYfDeviceCode())
+                .likeIfPresent(IotDeviceDO::getDeviceCode, reqVO.getDeviceCode())
+                .likeIfPresent(IotDeviceDO::getDeviceName, reqVO.getDeviceName())
+//                .eqIfPresent(IotDeviceDO::getDeptId, reqVO.getDeptId())
+//                .inIfPresent(IotDeviceDO::getDeptId, reqVO.getDeptIds())
+                .eqIfPresent(IotDeviceDO::getBrand, reqVO.getBrand())
+                .eqIfPresent(IotDeviceDO::getModel, reqVO.getModel())
+                .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())
+                .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())
+                .inIfPresent(IotDeviceDO::getAssetClass, reqVO.getAssetClasses())
+                .likeIfPresent(IotDeviceDO::getInfoName, reqVO.getInfoName())
+                .eqIfPresent(IotDeviceDO::getInfoRemark, reqVO.getInfoRemark())
+                .eqIfPresent(IotDeviceDO::getInfoUrl, reqVO.getInfoUrl())
+                .eqIfPresent(IotDeviceDO::getTemplateJson, reqVO.getTemplateJson())
+                .eqIfPresent(IotDeviceDO::getBomSyncStatus, reqVO.getBomSyncStatus()));
+    }
+
     default List<IotDeviceDO> selectListAlone(IotDevicePageReqVO reqVO) {
         LambdaQueryWrapperX<IotDeviceDO> queryWrapper = new LambdaQueryWrapperX<>();
         queryWrapper

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

@@ -202,7 +202,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
     public String getMaxCode(String prefix) {
         IotDevicePageReqVO iotDevicePageReqVO = new IotDevicePageReqVO();
         iotDevicePageReqVO.setYfDeviceCode(prefix);
-        List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList(iotDevicePageReqVO);
+        List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectListNoDept(iotDevicePageReqVO);
         if (iotDeviceDOS == null || iotDeviceDOS.isEmpty()) {
             return "001"; // 列表为空时默认从001开始
         }