hfxc226 3 years ago
parent
commit
4e8fb56748
19 changed files with 724 additions and 290 deletions
  1. 20 1
      platform-dao/src/main/java/com/platform/dao/dto/sqarepartmanage/SparePartInfoDTO.java
  2. 0 10
      platform-dao/src/main/java/com/platform/dao/dto/store/SpareStoreDTO.java
  3. 4 0
      platform-dao/src/main/java/com/platform/dao/entity/sqarepartmanage/SparePartInfo.java
  4. 32 0
      platform-dao/src/main/java/com/platform/dao/enums/SparePartMinStoclWarnStatusEnum.java
  5. 5 1
      platform-dao/src/main/java/com/platform/dao/enums/SysConfigEnum.java
  6. 2 0
      platform-dao/src/main/java/com/platform/dao/mapper/sqarepartmanage/SparePartInfoMapper.java
  7. 57 12
      platform-dao/src/main/java/com/platform/dao/util/CustomExcelImportUtil.java
  8. 8 0
      platform-dao/src/main/java/com/platform/dao/util/MessageTemplateUtil.java
  9. 4 4
      platform-dao/src/main/java/com/platform/dao/vo/export/sqarepartmanage/ExportSparePartInfoVO.java
  10. 6 1
      platform-dao/src/main/java/com/platform/dao/vo/query/sparepartmanage/SparePartInfoVO.java
  11. 10 0
      platform-dao/src/main/java/com/platform/dao/vo/query/store/SpareStoreVO.java
  12. 12 8
      platform-dao/src/main/resources/mapper/check/CheckStandardSpareMapper.xml
  13. 41 5
      platform-dao/src/main/resources/mapper/sqarepartmanage/SparePartInfoMapper.xml
  14. 8 7
      platform-dao/src/main/resources/mapper/store/SpareStoreMapper.xml
  15. 133 114
      platform-rest/src/main/java/com/platform/rest/controller/sqarepartmanage/SparePartInfoController.java
  16. 34 0
      platform-rest/src/main/java/com/platform/rest/task/SparePartInfoTask.java
  17. 15 0
      platform-service/src/main/java/com/platform/service/sqarepartmanage/SparePartInfoService.java
  18. 309 118
      platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SparePartInfoServiceImpl.java
  19. 24 9
      platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SpareTypeServiceImpl.java

+ 20 - 1
platform-dao/src/main/java/com/platform/dao/dto/sqarepartmanage/SparePartInfoDTO.java

@@ -27,14 +27,28 @@ import java.util.List;
 @Accessors(chain = true)
 @EqualsAndHashCode(callSuper = true)
 public class SparePartInfoDTO extends BaseDTO implements Serializable {
+
     /**
      * 指标参数
      */
     private String params;
     /**
-     * 预警状态:1:待处理,2询价中,3采购中,4已结束
+     * 预警状态:1:待处理,2询价中,3采购中,0正常
      */
     private Integer warnStatus;
+    /**
+     * 类型主键
+     */
+    private List<Integer> warnStatusList;
+    /**
+     * 保养预警状态:1:待处理,2询价中,3采购中,4已结束
+     */
+    private Integer forecastStatus;
+
+    /**
+     * 类型主键
+     */
+    private List<Integer> forecastStatusList;
     /**
    * 主键
    */
@@ -145,6 +159,11 @@ public class SparePartInfoDTO extends BaseDTO implements Serializable {
      * 最低库存
      */
     private BigDecimal minStock;
+    /**
+     * 查找库存小于最低库存的
+     */
+    @Transient
+    private Boolean searchMinStockWarn;
     /**
      * 初始库存
      */

+ 0 - 10
platform-dao/src/main/java/com/platform/dao/dto/store/SpareStoreDTO.java

@@ -113,16 +113,6 @@ public class SpareStoreDTO extends BaseDTO implements Serializable {
      * 数量
      */
     private BigDecimal num;
-    /**
-     * 查找小雨最低库存
-     */
-    @Transient
-    private Boolean minStock;
-    /**
-     * 查找大于最高库存
-     */
-    @Transient
-    private Boolean maxStock;
     /**
      * 排序
      */

+ 4 - 0
platform-dao/src/main/java/com/platform/dao/entity/sqarepartmanage/SparePartInfo.java

@@ -36,6 +36,10 @@ public class SparePartInfo implements Serializable {
      * 预警状态:1:待处理,2询价中,3采购中,4已结束
      */
     private Integer warnStatus;
+    /**
+     * 保养预警状态:1:待处理,2询价中,3采购中,4已结束
+     */
+    private Integer forecastStatus;
     /**
      * 备件编码
      */

+ 32 - 0
platform-dao/src/main/java/com/platform/dao/enums/SparePartMinStoclWarnStatusEnum.java

@@ -0,0 +1,32 @@
+package com.platform.dao.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @Description 备件使用状态枚举
+ * @Author liuyu
+ * @Date 2020/05/05
+ * @Version Copyright (c) 2020,安徽阡陌网络科技有限公司 All rights reserved.
+ */
+@Getter
+@AllArgsConstructor
+public enum SparePartMinStoclWarnStatusEnum {
+    /**
+     * 待处理
+     */
+    WAIT_DEAL(1),
+    /**
+     * 2询价中
+     */
+    XUN_JIA(2),
+    /**
+     * 3采购中
+     */
+    PURCHASE(3),
+    /**
+     * 0正常:
+     */
+    NORMAL(0);
+    private final Integer value;
+}

+ 5 - 1
platform-dao/src/main/java/com/platform/dao/enums/SysConfigEnum.java

@@ -28,6 +28,8 @@ public enum SysConfigEnum {
     IS_SEND_WX_MESSAGE("是否发送微信通知"),
     SYSTEM_NAME("系统名称"),
     SYSTEM_DOMAIN("系统域名"),
+    URL_SPARE_MIN_STOCK_WARN("最低库存预警查看页面"),
+    URL_SPARE_CHECK_STOCK_WARN("备件保养需求不足预警查看页面"),
     SYSTEM_DOMAIN_MOBILE("系统移动端域名"),
     SYSTEM_SB_URL("设备地址前缀"),
     REPAIR_ONLY_ONE("1"),// 是否维修中的设备不能再报修
@@ -36,7 +38,9 @@ public enum SysConfigEnum {
     REPAIR_OVERTIME_MINUTE_FIRST("维修超时预警第一阶段"),
     REPAIR_OVERTIME_MINUTE_SECOND("维修超时预警第二阶段"),
     REPAIR_OVERTIME_MINUTE_THIRD("维修超时预警第三阶段"),
-    CHECK_JOB_WORK("每周工作负荷");
+    CHECK_JOB_WORK("每周工作负荷"),
+    SPARE_WARN_EMAIL("最低库存邮箱"),
+    SPARE_WARN_FORREST_EMAIL("保养库存邮件邮箱");
     private final String typeName;
 
 }

+ 2 - 0
platform-dao/src/main/java/com/platform/dao/mapper/sqarepartmanage/SparePartInfoMapper.java

@@ -48,4 +48,6 @@ public interface SparePartInfoMapper extends MyMapper<SparePartInfo> {
     void updateBatch(List<SparePartInfoVO> addItems);
 
     List<SparePartInfoVO> selectSpareInfoListBySbId(String sbId);
+
+    String selectMaxNo(String typeId);
 }

+ 57 - 12
platform-dao/src/main/java/com/platform/dao/util/CustomExcelImportUtil.java

@@ -1,5 +1,6 @@
 package com.platform.dao.util;
 
+import com.mysql.cj.x.protobuf.MysqlxDatatypes;
 import com.platform.common.exception.BusinessException;
 import com.platform.common.model.UserInfo;
 import com.platform.common.util.*;
@@ -461,13 +462,13 @@ public class CustomExcelImportUtil {
     public static void main(String[] args) throws IOException, InvalidFormatException {
         //String path = "C:\\Users\\cyz\\Downloads\\老版维保计划\\noperson";
         //File dirFile = new File("C:\\Users\\cyz\\Downloads\\老版维保计划\\noperson");
-        String[] files = {"C:\\Users\\LTKJ\\Downloads\\设备台账 (1).xlsx"};
+        String[] files = {"C:\\Users\\LTKJ\\Downloads\\备件基础信息20220113205723195.xls"};
         for(String fileStr:files){
             System.out.println(fileStr);
             InputStream inputstream = new FileInputStream(fileStr);
             LocalDateTime now = LocalDateTime.now();
             //List<SbInfoVO> list = importSbInfoList(inputstream);
-            List<SbInfoMeasureVO> list = importSbInfoMeasureList(inputstream);
+            List<SparePartInfoVO> list = importSparePartInfoListForUpdate(inputstream);
             list.forEach(item -> {
                 System.out.println(item.toString());
             });
@@ -1708,13 +1709,12 @@ public class CustomExcelImportUtil {
     /**
      * 更新备件信息:类别,价格等
      *
-     * @param time
      * @param inputstream
      * @return
      * @throws IOException
      * @throws InvalidFormatException
      */
-    public static List<SparePartInfoVO> importSparePartInfoListForUpdate(LocalDateTime time, InputStream inputstream) throws IOException, InvalidFormatException {
+    public static List<SparePartInfoVO> importSparePartInfoListForUpdate(InputStream inputstream) throws IOException, InvalidFormatException {
         if (inputstream == null) {
             return Collections.emptyList();
         }
@@ -1747,19 +1747,49 @@ public class CustomExcelImportUtil {
                     record.setNo(no);
                 }
                 record.setName(row.getCell(2).getStringCellValue());
-                record.setParentName(row.getCell(3).getStringCellValue());
-                record.setMiddleName(row.getCell(4).getStringCellValue());
-                record.setChildName(getCellValue(row.getCell(5)));
-                String value = getCellValue(row.getCell(6));
+                record.setTypeName(row.getCell(3).getStringCellValue());
+                String value = getCellValue(row.getCell(4));
                 if (StringUtils.isBlank(value)) {
                     record.setInitialValue(0.0);
                 } else {
                     record.setInitialValue(new Double(value));
                 }
-                record.setUnit(getCellValue(row.getCell(7)));
-                record.setGgxh(getCellValue(row.getCell(8)));
-                record.setInitNo(getCellValue(row.getCell(9)));
-                record.setUpdateTime(time);
+                record.setUnit(getCellValue(row.getCell(5)));
+                record.setGgxh(getCellValue(row.getCell(6)));
+                record.setInitNo(getCellValue(row.getCell(7)));
+                record.setLevel(getSpareLevel(getCellValue(row.getCell(8))));
+                String usePeriod = getCellValue(row.getCell(9));
+                if(StringUtils.isBlank(usePeriod)){
+                    record.setUsePeriod(new BigDecimal(0));
+                }else{
+                    record.setUsePeriod(new BigDecimal(usePeriod));
+                }
+                String agePeriod = getCellValue(row.getCell(10));
+                if(StringUtils.isBlank(agePeriod)){
+                    record.setAgePeriod(new BigDecimal(0));
+                }else{
+                    record.setAgePeriod(new BigDecimal(agePeriod));
+                }
+                String purchasePeriod = getCellValue(row.getCell(11));
+                if(StringUtils.isBlank(purchasePeriod)){
+                    record.setPurchasePeriod(new BigDecimal(0));
+                }else{
+                    record.setPurchasePeriod(new BigDecimal(purchasePeriod));
+                }
+                record.setProducerId(getCellValue(row.getCell(12)));
+                String maxStock = getCellValue(row.getCell(13));
+                if(StringUtils.isBlank(maxStock)){
+                    record.setMaxStock(new BigDecimal(0));
+                }else{
+                    record.setMaxStock(new BigDecimal(maxStock));
+                }
+                String mixStock = getCellValue(row.getCell(14));
+                if(StringUtils.isBlank(mixStock)){
+                    record.setMinStock(new BigDecimal(0));
+                }else{
+                    record.setMinStock(new BigDecimal(mixStock));
+                }
+                record.setUpdateTime(LocalDateTime.now());
                 record.setUpdateUserId("1");
                 result.add(record);
 
@@ -1775,6 +1805,21 @@ public class CustomExcelImportUtil {
         return result;
     }
 
+    private static Integer getSpareLevel(String stringCellValue) {
+        if (StringUtils.isBlank(stringCellValue)) {
+            return 1;
+        }
+        if ("一级".equals(stringCellValue) ) {
+            return 1;
+        } else if ("二级".equals(stringCellValue)) {
+            return 2;
+        } else if ("三级".equals(stringCellValue)) {
+            return 3;
+        }else{
+            return 1;
+        }
+    }
+
     /**
      * 导入总需求计划明细-设备型号类
      *

+ 8 - 0
platform-dao/src/main/java/com/platform/dao/util/MessageTemplateUtil.java

@@ -120,6 +120,14 @@ public class MessageTemplateUtil {
         return String.format("近【%s】个月内有【%s】种备件不足,请注意:明细如下:" + System.getProperty("line.separator") + "【%s】", month, num, str);
     }
 
+    public static String getSpareMinStockWarnNotice( String url, int num) {
+        return String.format("有【%s】种备件低于最低库存,点击【%s】查看明细:", num, url);
+    }
+
+    public static String getSpareCheckStockWarnNotice( String url, int num) {
+        return String.format("有【%s】种备件低于库存6个月内的保养需求,点击【%s】查看明细:", num, url);
+    }
+
     public static String getRepairCheck(String id) {
         return String.format("报修【%s】已完成,请验收", id);
     }

+ 4 - 4
platform-dao/src/main/java/com/platform/dao/vo/export/sqarepartmanage/ExportSparePartInfoVO.java

@@ -65,7 +65,7 @@ public class ExportSparePartInfoVO implements Serializable {
      */
     @Excel(name = "原厂编号", orderNum = "8")
     private String initNo;
-    /**
+   /**
      * 备件等级:1-一级; 2-二级;3-三级
      */
     @Excel(name = "备件等级", orderNum = "9", dicCode = "SPARE_PART_INFO_LEVEL")
@@ -73,17 +73,17 @@ public class ExportSparePartInfoVO implements Serializable {
     /**
      * 使用周期:月
      */
-    @Excel(name = "原厂编号", orderNum = "10")
+    @Excel(name = "使用周期(月)", orderNum = "10")
     private BigDecimal usePeriod;
     /**
      * 寿命周期:月
      */
-    @Excel(name = "原厂编号", orderNum = "11")
+    @Excel(name = "寿命周期(月)", orderNum = "11")
     private BigDecimal agePeriod;
     /**
      * 采购到货周期:天
      */
-    @Excel(name = "原厂编号", orderNum = "12")
+    @Excel(name = "采购到货周期(天)", orderNum = "12")
     private BigDecimal purchasePeriod;
     /**
      * 生产商

+ 6 - 1
platform-dao/src/main/java/com/platform/dao/vo/query/sparepartmanage/SparePartInfoVO.java

@@ -32,9 +32,14 @@ public class SparePartInfoVO extends BaseVO implements Serializable {
      */
     private String params;
     /**
-     * 预警状态:1:待处理,2询价中,3采购中,4已结束
+     * 预警状态:1:待处理,2询价中,3采购中,0正常
      */
     private Integer warnStatus;
+
+    /**
+     * 保养预警状态:1:待处理,2询价中,3采购中,0正常
+     */
+    private Integer forecastStatus;
     /**
      * 使用周期:月
      */

+ 10 - 0
platform-dao/src/main/java/com/platform/dao/vo/query/store/SpareStoreVO.java

@@ -24,6 +24,16 @@ import java.time.LocalDate;
 @Accessors(chain = true)
 @EqualsAndHashCode(callSuper = true)
 public class SpareStoreVO extends BaseVO implements Serializable {
+
+    /**
+     * 预警状态:1:待处理,2询价中,3采购中,0正常
+     */
+    private Integer warnStatus;
+
+    /**
+     * 保养预警状态:1:待处理,2询价中,3采购中,0正常
+     */
+    private Integer forecastStatus;
     /**
      * 期初库存数量
      */

+ 12 - 8
platform-dao/src/main/resources/mapper/check/CheckStandardSpareMapper.xml

@@ -24,18 +24,22 @@
             spare.NAME spareName,
             spare.NO,
             spare.ggxh,
-            store.num storeNum
+            spare.forecast_status,
+            SUM( store.num ) storeNum
         FROM
         t_check_standard_spare cs
         LEFT JOIN t_spare_part_info spare ON cs.spare_id = spare.id
         LEFT JOIN t_spare_store store ON cs.spare_id = store.spare_id
-        where
-        <if test="checkIds != null and checkIds.size > 0">
-            cs.check_id in
-            <foreach item="item" index="index" collection="checkIds" open="(" close=")" separator=",">
-            #{item}
-            </foreach>
-        </if>
+        <where>
+            spare.forecast_status = 0
+            <if test="checkIds != null and checkIds.size > 0">
+            and  cs.check_id in
+                <foreach item="item" index="index" collection="checkIds" open="(" close=")" separator=",">
+                #{item}
+                </foreach>
+            </if>
+
+        </where>
         GROUP BY
             cs.spare_id
     </select>

+ 41 - 5
platform-dao/src/main/resources/mapper/sqarepartmanage/SparePartInfoMapper.xml

@@ -24,6 +24,7 @@
         <result column="supplier_id" jdbcType="VARCHAR" property="supplierId"/>
         <result column="unit" jdbcType="SMALLINT" property="unit"/>
         <result column="warn_status" jdbcType="SMALLINT" property="warnStatus"/>
+        <result column="forecast_status" jdbcType="SMALLINT" property="forecastStatus"/>
         <result column="unit_bz" jdbcType="SMALLINT" property="unitBz"/>
         <result column="unit_rate" jdbcType="DOUBLE" property="unitRate"/>
         <result column="max_stock" jdbcType="DOUBLE" property="maxStock"/>
@@ -55,9 +56,9 @@
         id, no, unite_no, gg_no, name_no, name, type_id, level, initial_value, producer_id,
     unit,
     purchase_period,
-    use_period,
+    use_period,age_period,
     unit_bz,
-warn_status,
+warn_status,forecast_status,
     unit_rate,
     image,
     qr_code,
@@ -78,7 +79,7 @@ warn_status,
     </sql>
     <select id="selectPageList" parameterType="com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO"
             resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
-        select info.*, SUM(spareStore.num) as currentStock
+        select info.*, SUM(spareStore.num) currentStock
         from t_spare_part_info info
         LEFT JOIN t_spare_store spareStore on spareStore.spare_id = info.id
         <if test="producerName != null and producerName != ''">
@@ -88,6 +89,22 @@ warn_status,
             LEFT JOIN t_supplier supplier on supplier.id = info.supplier_id
         </if>
         <where>
+            <if test="warnStatusList != null and warnStatusList.size > 0">
+                AND info.warn_status in
+                <foreach item="item" index="index" collection="warnStatusList" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="forecastStatusList != null and forecastStatusList.size > 0">
+                AND info.forecast_status in
+                <foreach item="item" index="index" collection="forecastStatusList" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+
+            <if test="typeId != null and typeId != ''">
+                and info.type_id = #{typeId}
+            </if>
             <if test="producerName != null and producerName != ''">
                 AND producer.name like concat('%',#{producerName},'%')
             </if>
@@ -104,6 +121,9 @@ warn_status,
             <if test="warnStatus != null and warnStatus != ''">
                 AND info.warn_status = #{warnStatus}
             </if>
+            <if test="forecastStatus != null and forecastStatus != ''">
+                AND info.forecast_status = #{forecastStatus}
+            </if>
             <if test="ggxh != null and ggxh != ''">
                 AND info.ggxh like concat('%',#{ggxh},'%')
             </if>
@@ -143,8 +163,21 @@ warn_status,
             <if test="childNo != null and childNo != ''">
                 AND info.child_no=#{childNo}
             </if>
+            <if test="searchMinStockWarn">
+                AND info.min_stock is not null
+            </if>
+            <if test="searchMinStockWarn">
+                AND info.warn_status = 0
+            </if>
         </where>
         group by info.id
+        <if test="searchMinStockWarn">
+            HAVING info.min_stock > SUM( spareStore.num )
+        </if>
+    </select>
+    <select id="selectMaxNo" parameterType="java.lang.Object" resultType="java.lang.String">
+        select max(no) from t_spare_part_info
+        where type_id = #{value}
     </select>
 
     <select id="selectById" parameterType="java.lang.Object" resultMap="BaseResultMap">
@@ -164,7 +197,7 @@ warn_status,
         select spare.id as spareId, spare.no, spare.unite_no, spare.name, spare.type_id, spare.level,
         spare.initial_value, spare.producer_id,
         spare.unit,
-        spare.unit_bz,spare.warn_status,
+        spare.unit_bz,spare.warn_status, spare.forecast_status,
         spare.unit_rate,
         spare.image,
         spare.qr_code,
@@ -190,7 +223,7 @@ warn_status,
         select spare.id as spareId, spare.no, spare.unite_no, spare.name, spare.type_id, spare.level,
                spare.initial_value, spare.producer_id,
                spare.unit,
-               spare.unit_bz,spare.warn_status,
+               spare.unit_bz,spare.warn_status, spare.forecast_status,
                spare.unit_rate,
                spare.image,
                spare.qr_code,
@@ -244,6 +277,9 @@ warn_status,
                 <if test="item.warnStatus != null">
                     warn_status = #{item.warnStatus},
                 </if>
+                <if test="item.forecastStatus != null">
+                    info.forecast_status = #{item.forecastStatus},
+                </if>
                 <if test="item.unit != null">
                     child_no = #{item.childNo},
                 </if>

+ 8 - 7
platform-dao/src/main/resources/mapper/store/SpareStoreMapper.xml

@@ -108,7 +108,10 @@
         info.NAME,
         info.unit,
         info.min_stock,
+        info.type_id,
         info.max_stock,
+        info.warn_status,
+        info.forecast_status,
         info.init_no AS initNo,
         info.ggxh,
         info.initial_value as price,
@@ -129,19 +132,17 @@
                     #{item}
                 </foreach>
             </if>
-            <if test="typeId != null and typeId != ''">
-                and info.type_id = #{typeId}
-            </if>
         </where>
         GROUP BY
         sparestore.spare_id
         )
         FIRST ON info.id = FIRST.spare_id
-        <if test="minStock != null">
-            and info.min_stock  > FIRST.totalStock
+        <if test="typeId != null and typeId != ''">
+            and info.type_id = #{typeId}
         </if>
-        <if test="maxStock != null">
-            and FIRST.totalStock > info.max_stock
+        <if test="keyword != null and keyword != ''">
+            AND ( info.name like concat('%',#{keyword},'%') or
+            info.ggxh like concat('%',#{keyword},'%'))
         </if>
     </select>
 

+ 133 - 114
platform-rest/src/main/java/com/platform/rest/controller/sqarepartmanage/SparePartInfoController.java

@@ -1,6 +1,7 @@
 package com.platform.rest.controller.sqarepartmanage;
 
 import com.platform.common.util.R;
+import com.platform.common.util.StringUtils;
 import com.platform.dao.dto.sb.SbModelDTO;
 import com.platform.dao.dto.sb.SbModelSpareBomDTO;
 import com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO;
@@ -43,39 +44,42 @@ import javax.servlet.http.HttpServletResponse;
 @RequestMapping("/sqarepartmanage/spare-part-info")
 public class SparePartInfoController {
 
-  private final SbModelSpareBomService sbModelSpareBomService;
-  private final  SparePartInfoService sparePartInfoService;
-  private final SbModelService sbModelService;
-
-  private final CheckStandardService checkStandardService;
-  /**
-   * 通过id查询单条记录
-   *
-   * @param id 主键
-   * @return R
-   */
-  @GetMapping("/{id}")
-  public R<SparePartInfo> getById(@PathVariable("id") String id){
-      return new R<>(sparePartInfoService.getModelById(id));
-  }
-
-  /**
-   * 新增记录
-   *
-   * @param sparePartInfoDTO 备件基础信息DTO
-   * @return R
-   */
-  @SysLog("新增备件基础信息")
-  @PostMapping
-  @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-add')")
-  public R save(@Validated({AddGroup.class}) @RequestBody SparePartInfoDTO sparePartInfoDTO) {
-      return new R<>(sparePartInfoService.saveModelByDTO(sparePartInfoDTO));
-  }
+    private final SbModelSpareBomService sbModelSpareBomService;
+    private final SparePartInfoService sparePartInfoService;
+    private final SbModelService sbModelService;
+
+    private final CheckStandardService checkStandardService;
+
+    /**
+     * 通过id查询单条记录
+     *
+     * @param id 主键
+     * @return R
+     */
+    @GetMapping("/{id}")
+    public R<SparePartInfo> getById(@PathVariable("id") String id) {
+        return new R<>(sparePartInfoService.getModelById(id));
+    }
+
+    /**
+     * 新增记录
+     *
+     * @param sparePartInfoDTO 备件基础信息DTO
+     * @return R
+     */
+    @SysLog("新增备件基础信息")
+    @PostMapping
+    @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-add')")
+    public R save(@Validated({AddGroup.class}) @RequestBody SparePartInfoDTO sparePartInfoDTO) {
+        return new R<>(sparePartInfoService.saveModelByDTO(sparePartInfoDTO));
+    }
+
     /**
      * 批量校正记录
      * 将备件修改为其他备件,并更新库存对应的备件id
+     *
      * @param spareId 修改的备件spareId
-     * @param ids 待修改的备件id列表
+     * @param ids     待修改的备件id列表
      * @return R
      */
     @SysLog("批量校正备件基础信息")
@@ -86,33 +90,45 @@ public class SparePartInfoController {
         return new R<>("校正成功");
     }
 
-  /**
-   * 修改记录
-   *
-   * @param model 备件基础信息DTO
-   * @return R
-   */
-  @SysLog("修改备件基础信息")
-  @PutMapping("/{id}")
-  @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-edit')")
-  public R update(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody SparePartInfoDTO model) {
-      sparePartInfoService.modModelByDTO(model);
-      return new R<>();
-  }
-
-  /**
-   * 通过id删除一条记录
-   *
-   * @param id 主键
-   * @return R
-   */
-  @SysLog("删除备件基础信息")
-  @DeleteMapping("/{id}")
-  @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-del')")
-  public R removeById(@PathVariable String id){
-    sparePartInfoService.deleteByPrimaryKey(id);
-    return new R<>();
-  }
+    /**
+     * 修改记录
+     *
+     * @param model 备件基础信息DTO
+     * @return R
+     */
+    @SysLog("修改备件基础信息")
+    @PutMapping("/{id}")
+    @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-edit')")
+    public R update(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody SparePartInfoDTO model) {
+        sparePartInfoService.modModelByDTO(model);
+        return new R<>();
+    }
+
+    /**
+     * 修改状态
+     *
+     * @return R
+     */
+    @SysLog("修改备件基础信息库存预警状态")
+    @PutMapping("/status/{id}/{type}/{warnStatus}")
+    public R update(@PathVariable("id") String id, @PathVariable("type") Integer type, @PathVariable("warnStatus") Integer warnStatus) {
+        sparePartInfoService.updateSpareWarnStatus(id, type, warnStatus);
+        return new R<>();
+    }
+
+    /**
+     * 通过id删除一条记录
+     *
+     * @param id 主键
+     * @return R
+     */
+    @SysLog("删除备件基础信息")
+    @DeleteMapping("/{id}")
+    @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-del')")
+    public R removeById(@PathVariable String id) {
+        sparePartInfoService.deleteByPrimaryKey(id);
+        return new R<>();
+    }
 
     /**
      * 批量记录
@@ -123,31 +139,30 @@ public class SparePartInfoController {
     @SysLog("批量删除备件基础信息")
     @DeleteMapping("")
     @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-del')")
-    public R removeIds(@RequestBody List<String> ids){
+    public R removeIds(@RequestBody List<String> ids) {
         sparePartInfoService.batchDelete(ids);
         return new R<>();
     }
 
-  /**
-   * 获取分页
-   *
-   * @param pageNum 当前页码
-   * @param pageSize 每页条数
-   * @param sparePartInfoDTO 备件基础信息DTO
-   * @return R
-   */
-  @GetMapping("/page")
-  public R<AbstractPageResultBean<SparePartInfo>> query(SparePartInfoDTO sparePartInfoDTO, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
-      return new R<>(sparePartInfoService.selectPageInfo(sparePartInfoDTO, pageNum, pageSize));
-  }
-
     /**
      * 获取分页
      *
-     * @param pageNum 当前页码
+     * @param pageNum          当前页码
+     * @param pageSize         每页条数
+     * @param sparePartInfoDTO 备件基础信息DTO
+     * @return R
+     */
+    @GetMapping("/page")
+    public R<AbstractPageResultBean<SparePartInfo>> query(SparePartInfoDTO sparePartInfoDTO, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
+        return new R<>(sparePartInfoService.selectPageInfo(sparePartInfoDTO, pageNum, pageSize));
+    }
+
+    /**
+     * 获取分页
+     * @param pageNum  当前页码
      * @param pageSize 每页条数
-     * @param month 查询最近几个月的-距离当前系统时间
-     * @param month 类别1点检,2保养
+     * @param month    查询最近几个月的-距离当前系统时间
+     * @param month    类别1点检,2保养
      * @return R
      */
     @GetMapping("/check/warn/page")
@@ -155,53 +170,59 @@ public class SparePartInfoController {
         return new R<>(checkStandardService.selectSpareWarnVOPage(month, type, pageNum, pageSize));
     }
 
-  /**
-   * 获取列表
-   *
-   * @param sparePartInfoDTO 备件基础信息DTO
-   * @return R
-   */
-  @GetMapping("")
-  public R query(SparePartInfoDTO sparePartInfoDTO) {
-      return new R<>(sparePartInfoService.getModelListByDTO(sparePartInfoDTO));
-  }
-
-  /**
+    /**
+     * 获取列表
+     *
+     * @param sparePartInfoDTO 备件基础信息DTO
+     * @return R
+     */
+    @GetMapping("")
+    public R query(SparePartInfoDTO sparePartInfoDTO) {
+        return new R<>(sparePartInfoService.getModelListByDTO(sparePartInfoDTO));
+    }
+
+    /**
      * 备件基础信息导出
      *
      * @param sparePartInfoDTO 备件基础信息DTO
      * @return R
      */
-  @GetMapping("/export")
-  @SysLog("备件基础信息导出")
-  @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-export')")
-  public void export(HttpServletResponse response, SparePartInfoDTO sparePartInfoDTO) {
-    List<SparePartInfo> list = sparePartInfoService.getModelListByDTO(sparePartInfoDTO);
-    // 查询备件关联的设备型号信息
-    List<SbModelVO> modelList = sbModelService.selectVOList(new SbModelDTO());
-    List<SbModelSpareBomVO> bomList =  sbModelSpareBomService.selectExportList(sparePartInfoDTO);
-    for(SparePartInfo sparePartInfo:list){
-        for(SbModelSpareBomVO sbModelSpareBomVO:bomList){
-            if(sparePartInfo.getId().equals(sbModelSpareBomVO.getSpareId())){
-                sparePartInfo.setModelName(sbModelSpareBomVO.getName());
-                sparePartInfo.setModelModel(sbModelSpareBomVO.getModel());
-                break;
+    @GetMapping("/export")
+    @SysLog("备件基础信息导出")
+    @PreAuthorize("@pms.hasPermission('sqarepartmanage-spare-part-info-export')")
+    public void export(HttpServletResponse response, SparePartInfoDTO sparePartInfoDTO) {
+        List<SparePartInfo> list = sparePartInfoService.getModelListByDTO(sparePartInfoDTO);
+        // 如果没有编码先更新编码
+        for (SparePartInfo sparePartInfo : list) {
+            if (StringUtils.isBlank(sparePartInfo.getNo())) {
+                sparePartInfoService.updateSpareNo(sparePartInfo);
+            }
+        }
+        // 查询备件关联的设备型号信息
+        List<SbModelVO> modelList = sbModelService.selectVOList(new SbModelDTO());
+        List<SbModelSpareBomVO> bomList = sbModelSpareBomService.selectExportList(sparePartInfoDTO);
+        for (SparePartInfo sparePartInfo : list) {
+            for (SbModelSpareBomVO sbModelSpareBomVO : bomList) {
+                if (sparePartInfo.getId().equals(sbModelSpareBomVO.getSpareId())) {
+                    sparePartInfo.setModelName(sbModelSpareBomVO.getName());
+                    sparePartInfo.setModelModel(sbModelSpareBomVO.getModel());
+                    break;
+                }
             }
         }
+        ExcelUtil.exportResponseDict(response, ExportSparePartInfoVO.class, BeanConverterUtil.copyListProperties(list, ExportSparePartInfoVO.class), "备件基础信息");
+    }
+
+    /**
+     * 获取下拉款
+     *
+     * @param sparePartInfoDTO 备件基础信息DTO
+     * @return R
+     */
+    @GetMapping("options")
+    public R queryOptions(SparePartInfoDTO sparePartInfoDTO) {
+        return new R<>(SelectUtil.buildSparePartInfoOptions(sparePartInfoService.getModelListByDTO(sparePartInfoDTO)));
     }
-    ExcelUtil.exportResponseDict(response, ExportSparePartInfoVO.class, BeanConverterUtil.copyListProperties(list, ExportSparePartInfoVO.class), "备件基础信息");
-  }
-
-  /**
-   * 获取下拉款
-   *
-   * @param sparePartInfoDTO 备件基础信息DTO
-   * @return R
-   */
-  @GetMapping("options")
-  public R queryOptions(SparePartInfoDTO sparePartInfoDTO) {
-    return new R<>(SelectUtil.buildSparePartInfoOptions(sparePartInfoService.getModelListByDTO(sparePartInfoDTO)));
-  }
 
     /**
      * 导入备件基础信息+仓库库存:
@@ -210,7 +231,6 @@ public class SparePartInfoController {
      * 指定的单个仓库
      *
      * @param file bom excel文件
-     *
      * @return R
      */
     @SysLog("导入备件基础信息+仓库库存")
@@ -225,7 +245,6 @@ public class SparePartInfoController {
      * 备件已经在仓库中,根据id进行匹配
      *
      * @param file bom excel文件
-     *
      * @return R
      */
     @SysLog("导入修改备件基础信息")

+ 34 - 0
platform-rest/src/main/java/com/platform/rest/task/SparePartInfoTask.java

@@ -0,0 +1,34 @@
+package com.platform.rest.task;
+
+import com.platform.service.sqarepartmanage.SparePartInfoService;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description 备件相关定时任务
+ * @Author liuyu
+ * @Date 2020-05-09 16:40:01
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Slf4j
+@Component("sparePartInfoTask")
+@AllArgsConstructor
+public class SparePartInfoTask {
+    private SparePartInfoService sparePartInfoService;
+
+    /**
+     * 最低库存预警判定
+     */
+    public void genMinStockWarn () {
+        sparePartInfoService.genMinStockWarn();
+    }
+
+    /**
+     * 预测的保养不足的问题
+     */
+    public void genCheckStockWarn () {
+        sparePartInfoService.genCheckStockWarn();
+    }
+
+}

+ 15 - 0
platform-service/src/main/java/com/platform/service/sqarepartmanage/SparePartInfoService.java

@@ -34,6 +34,8 @@ public interface SparePartInfoService extends IBaseService<SparePartInfo, SpareP
      */
     List<SparePartInfoVO> selectSpareInfoListByModelId(String modelId);
 
+    void updateSpareNo(SparePartInfo model);
+
     /**
      * 导入备件基础信息
      *
@@ -54,7 +56,20 @@ public interface SparePartInfoService extends IBaseService<SparePartInfo, SpareP
 
     void updateQrCode(SparePartInfoDTO sbInfoDTO);
 
+    /**
+     * 更新状态
+     *
+     * @param id
+     * @param type:1最低库存状态,2 预测状态
+     * @param status:变更后的状态
+     */
+    void updateSpareWarnStatus(String id, Integer type, Integer status);
+
     List<SparePartInfoVO> selectSpareInfoListBySbId(String sbId);
 
     AbstractPageResultBean<SparePartInfoVO> selectSpareInfoPageListBySbId(String sbId, int pageNum, int pageSize);
+
+    void genMinStockWarn();
+
+    void genCheckStockWarn();
 }

+ 309 - 118
platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SparePartInfoServiceImpl.java

@@ -4,16 +4,22 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import com.github.pagehelper.PageHelper;
 import com.platform.common.bean.AbstractPageResultBean;
+import com.platform.common.cache.ConfigCache;
 import com.platform.common.constant.CommonConstants;
 import com.platform.common.exception.BusinessException;
 import com.platform.common.model.UserInfo;
 import com.platform.common.util.*;
 import com.platform.dao.bean.MyPage;
+import com.platform.dao.dto.check.CheckStandardDTO;
+import com.platform.dao.dto.check.CheckStandardSpareDTO;
 import com.platform.dao.dto.repair.RepairApplicationFormDTO;
 import com.platform.dao.dto.sb.SbInfoDTO;
 import com.platform.dao.dto.sb.SbModelSpareBomDTO;
 import com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO;
 import com.platform.dao.dto.store.InStoreDetailDTO;
+import com.platform.dao.dto.store.SpareStoreDTO;
+import com.platform.dao.entity.check.CheckJob;
+import com.platform.dao.entity.check.CheckStandard;
 import com.platform.dao.entity.check.CheckStandardSpare;
 import com.platform.dao.entity.sb.SbInfo;
 import com.platform.dao.entity.sb.SbModel;
@@ -25,7 +31,9 @@ import com.platform.dao.entity.store.SpareStore;
 import com.platform.dao.entity.upms.SysDept;
 import com.platform.dao.entity.upms.SysFile;
 import com.platform.dao.entity.upms.SysUser;
-import com.platform.dao.enums.SysFileTypeEnum;
+import com.platform.dao.enums.*;
+import com.platform.dao.mapper.check.CheckJobMapper;
+import com.platform.dao.mapper.check.CheckStandardSpareMapper;
 import com.platform.dao.mapper.sb.SbInfoMapper;
 import com.platform.dao.mapper.sb.SbModelMapper;
 import com.platform.dao.mapper.sb.SbModelSpareBomMapper;
@@ -34,12 +42,18 @@ import com.platform.dao.mapper.sqarepartmanage.SpareTypeMapper;
 import com.platform.dao.mapper.store.SpareStoreMapper;
 import com.platform.dao.mapper.upms.SysFileMapper;
 import com.platform.dao.util.CustomExcelImportUtil;
+import com.platform.dao.util.MessageTemplateUtil;
+import com.platform.dao.vo.query.check.CheckStandardSpareVO;
 import com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO;
+import com.platform.dao.vo.query.store.SpareStoreVO;
 import com.platform.dao.vo.sb.SbInfoVO;
+import com.platform.service.check.CheckStandardService;
+import com.platform.service.event.WorkplaceBacklogEvent;
 import com.platform.service.sqarepartmanage.SparePartInfoService;
 import com.platform.service.sqarepartmanage.SpareTypeService;
 import com.platform.service.util.CodeFileUtils;
 import com.platform.service.util.SysFileUtils;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Service;
 import com.platform.service.base.impl.BaseServiceImpl;
@@ -51,7 +65,9 @@ import tk.mybatis.mapper.weekend.WeekendCriteria;
 import lombok.AllArgsConstructor;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -63,6 +79,7 @@ import java.util.stream.Collectors;
  */
 @AllArgsConstructor
 @Service("sparePartInfoService")
+@Slf4j
 public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMapper, SparePartInfo, SparePartInfoDTO> implements SparePartInfoService {
 
     private final SbInfoMapper sbInfoMapper;
@@ -72,6 +89,9 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
     private final SpareStoreMapper spareStoreMapper;
     private final Environment environment;
     private final SysFileMapper sysFileMapper;
+    private CheckJobMapper checkJobMapper;
+    private CheckStandardSpareMapper checkStandardSpareMapper;
+    private CheckStandardService checkStandardService;
     @Override
     public int batchDelete(List<String> ids) {
 
@@ -80,7 +100,7 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         WeekendCriteria<SpareStore, Object> weekendCriteriaStore = weekendStore.weekendCriteria();
         weekendCriteriaStore.andIn(SpareStore::getSpareId, ids).andGreaterThan(SpareStore::getNum, 0);
         List<SpareStore> spareStoreList = spareStoreMapper.selectByExample(weekendStore);
-        if(!CollectionUtils.isEmpty(spareStoreList)){
+        if (!CollectionUtils.isEmpty(spareStoreList)) {
             throw new BusinessException("该备件仓库有数据,不能删除,请先清空仓库库存");
         }
         // 删除
@@ -107,17 +127,122 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         return new MyPage(mapper.selectSpareInfoListBySbId(sbId));
     }
 
+    /**
+     * 定时扫描是否过期
+     * 1:增加warnStatus状态
+     * 增加warnStatus的枚举类型
+     * 2:每周定时扫描warnStatus为正常的,判断他的最低库存是否正常,有异常的交给人工来判定。并发送邮件通知
+     * 3:扫描的时候,是扫描总库存,有可能仓库里面的备件不在同一个库存。
+     * <p>
+     * 4:增加预警菜单,查出来所有异常的列表
+     * 5:增加人工干预,可以改变每条的状态。
+     */
+    @Override
+    public void genMinStockWarn() {
+        SparePartInfoDTO record = new SparePartInfoDTO();
+        record.setSearchMinStockWarn(true);
+        // 查找超过最低库存的备件
+        List<SparePartInfoVO> sparePartInfoVOList = mapper.selectPageList(record);
+        List<SparePartInfo> sparePartInfos = new ArrayList<>();
+        for (SparePartInfoVO sparePartInfoVO : sparePartInfoVOList) {
+            SparePartInfo sparePartInfo = new SparePartInfo();
+            sparePartInfo.setId(sparePartInfoVO.getId());
+            sparePartInfo.setWarnStatus(1);
+            sparePartInfos.add(sparePartInfo);
+            mapper.updateByPrimaryKeySelective(sparePartInfo);
+        }
+
+        if (!CollectionUtils.isEmpty(sparePartInfos)) {
+            // 发送邮件通知
+            String email = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SPARE_WARN_EMAIL.name());
+            String domain = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SYSTEM_DOMAIN.name());
+            String url = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.URL_SPARE_MIN_STOCK_WARN.name());
+            if (StringUtils.isNotBlank(email)) {
+                // 通过给邮件人员
+                SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.CHECK_SPARE_WARN.getValue(), WorkplaceBacklogDetailTypeEnum.CHECK_SPARE_WARN.getValue(),
+                        null, MessageTemplateUtil.getSpareMinStockWarnNotice(domain + url, sparePartInfos.size()),
+                        null, null, Arrays.asList(email)));
+            }
+        }
+    }
+
+    /**
+     * 定时扫描是否过期
+     * 1:增加warnStatus状态
+     * 增加warnStatus的枚举类型
+     * 2:每周定时扫描warnStatus为正常的,判断他的最低库存是否正常,有异常的交给人工来判定。并发送邮件通知
+     * 3:扫描的时候,是扫描总库存,有可能仓库里面的备件不在同一个库存。
+     * <p>
+     * 4:增加预警菜单,查出来所有异常的列表
+     * 5:增加人工干预,可以改变每条的状态。
+     */
+    @Override
+    public void genCheckStockWarn() {
+
+        // 查询近六个月待执行的任务列表。
+        LocalDate now = LocalDate.now();
+        LocalDate afterSixMonth = DateUtils.plus(now, 6, ChronoUnit.MONTHS);
+        Weekend<CheckJob> weekend = new Weekend<>(CheckJob.class);
+        weekend.weekendCriteria().andNotEqualTo(CheckJob::getStatus, CheckJobStatusEnum.FINISHED.getValue())
+                .andBetween(CheckJob::getStartTime, now, afterSixMonth);
+        List<CheckJob> checkJobs = checkJobMapper.selectByExample(weekend);
+
+        // 获取未执行的标准id,不能用stream获取id列表,会覆盖重复的标准id(不会重复,因为一个标准对应一个任务。)
+        List<CheckStandardSpareVO> voList = new ArrayList<CheckStandardSpareVO>();
+        if(CollectionUtil.isNotEmpty(checkJobs)){
+            List<String> ids = checkJobs.stream().map(CheckJob::getStandardId).collect(Collectors.toList());
+            ids = ids.stream().filter(item -> StringUtils.isNotBlank(item)).collect(Collectors.toList());
+            if(!CollectionUtils.isEmpty(ids) && ids.size()>0) {
+                CheckStandardSpareDTO dto = new CheckStandardSpareDTO();
+                dto.setCheckIds(ids);
+                voList = checkStandardSpareMapper.selectSpareWarn(dto);
+
+                // 判断总库存是否大于最近6个月的需求量
+                if(CollectionUtil.isNotEmpty(voList)){
+                    for(CheckStandardSpareVO checkStandardSpareVO:voList){
+                        if(checkStandardSpareVO.getNum().compareTo(checkStandardSpareVO.getStoreNum())>0){
+                            SparePartInfo sparePartInfo = new SparePartInfo();
+                            sparePartInfo.setId(checkStandardSpareVO.getId());
+                            sparePartInfo.setForecastStatus(1);
+                            mapper.updateByPrimaryKeySelective(sparePartInfo);
+                        }
+                    }
+
+                    // 发送邮件通知
+                    String email = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SPARE_WARN_EMAIL.name());
+                    String domain = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.SYSTEM_DOMAIN.name());
+                    String url = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.URL_SPARE_CHECK_STOCK_WARN.name());
+                    if (StringUtils.isNotBlank(email)) {
+                        // 通过给邮件人员
+                        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.CHECK_SPARE_WARN.getValue(), WorkplaceBacklogDetailTypeEnum.CHECK_SPARE_WARN.getValue(),
+                                null, MessageTemplateUtil.getSpareCheckStockWarnNotice(domain + url, voList.size()),
+                                null, null, Arrays.asList(email)));
+                    }
+
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) {
+        String ss = "TYPJ-CC-00002";
+        String newStr = ss.substring(ss.length() - 5);
+        int count = Integer.valueOf(newStr) + 1;
+        String str1 = String.format("%05d", count);
+        System.out.println(str1);
+    }
+
     @Override
     public List<SparePartInfo> getModelListByDTO(SparePartInfoDTO sparePartInfoDTO) {
-        if(sparePartInfoDTO.getTypeId() != null){
+        if (sparePartInfoDTO.getTypeId() != null) {
             Weekend<SpareType> weekend = new Weekend<>(SpareType.class);
             WeekendCriteria<SpareType, Object> weekendCriteria = weekend.weekendCriteria();
             weekendCriteria.andEqualTo(SpareType::getParentId, sparePartInfoDTO.getTypeId());
             List<SpareType> childList = spareTypeMapper.selectByExample(weekend);
             List<String> typeIds = new ArrayList<String>();
             typeIds.add(sparePartInfoDTO.getTypeId());
-            if(!CollectionUtils.isEmpty(childList)){
-                childList.forEach(item->{
+            if (!CollectionUtils.isEmpty(childList)) {
+                childList.forEach(item -> {
                     typeIds.add(item.getId());
                 });
             }
@@ -125,21 +250,21 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         }
         List<SparePartInfoVO> listVO = mapper.selectPageList(sparePartInfoDTO);
         List<SpareType> typeList = spareTypeMapper.selectAll();
-        for(SparePartInfoVO vo: listVO){
-            for(SpareType type:typeList){
-                if(StringUtils.isNotBlank(vo.getTypeId()) && vo.getTypeId().equals(type.getId())){
+        for (SparePartInfoVO vo : listVO) {
+            for (SpareType type : typeList) {
+                if (StringUtils.isNotBlank(vo.getTypeId()) && vo.getTypeId().equals(type.getId())) {
                     vo.setTypeName(type.getName());
                     vo.setTypeNo(type.getNo());
                 }
-                if(StringUtils.isNotBlank(vo.getParentTypeId()) && vo.getParentTypeId().equals(type.getId())){
+                if (StringUtils.isNotBlank(vo.getParentTypeId()) && vo.getParentTypeId().equals(type.getId())) {
                     vo.setParentName(type.getName());
                     vo.setParentNo(type.getNo());
                 }
-                if(StringUtils.isNotBlank(vo.getMiddleTypeId()) && vo.getMiddleTypeId().equals(type.getId())){
+                if (StringUtils.isNotBlank(vo.getMiddleTypeId()) && vo.getMiddleTypeId().equals(type.getId())) {
                     vo.setMiddleName(type.getName());
                     vo.setMiddleNo(type.getNo());
                 }
-                if(StringUtils.isNotBlank(vo.getChildTypeId()) && vo.getChildTypeId().equals(type.getId())){
+                if (StringUtils.isNotBlank(vo.getChildTypeId()) && vo.getChildTypeId().equals(type.getId())) {
                     vo.setChildName(type.getName());
                     vo.setChildNo(type.getNo());
                 }
@@ -153,15 +278,15 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
     @Override
     public AbstractPageResultBean<SparePartInfo> selectPageInfo(SparePartInfoDTO record, int pageNum, int pageSize) {
         // 选择设备对应的备件bom列表
-        if(record.getSbId()!=null){
+        if (record.getSbId() != null) {
             SbInfoVO sbInfo = sbInfoMapper.getById(record.getSbId());
             List<SparePartInfoVO> partList = mapper.selectSpareInfoList(sbInfo.getModelId());
             PageHelper.startPage(pageNum, pageSize);
             AbstractPageResultBean<SparePartInfo> pageInfo = new MyPage(partList);
             return pageInfo;
-        }else{
+        } else {
             List<SpareType> typeList = spareTypeMapper.selectAll();
-            if(StringUtils.isNotBlank(record.getTypeName())){
+            if (StringUtils.isNotBlank(record.getTypeName())) {
                 for (SpareType type : typeList) {
                     if (type.getName().equals(record.getTypeName())) {
                         record.setTypeId(type.getId());
@@ -169,15 +294,15 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                     }
                 }
             }
-            if(record.getTypeId() != null){
+            if (record.getTypeId() != null) {
                 Weekend<SpareType> weekend = new Weekend<>(SpareType.class);
                 WeekendCriteria<SpareType, Object> weekendCriteria = weekend.weekendCriteria();
                 weekendCriteria.andEqualTo(SpareType::getParentId, record.getTypeId());
                 List<SpareType> childList = spareTypeMapper.selectByExample(weekend);
                 List<String> typeIds = new ArrayList<String>();
                 typeIds.add(record.getTypeId());
-                if(!CollectionUtils.isEmpty(childList)){
-                    childList.forEach(item->{
+                if (!CollectionUtils.isEmpty(childList)) {
+                    childList.forEach(item -> {
                         typeIds.add(item.getId());
                     });
                 }
@@ -186,21 +311,21 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
 
             PageHelper.startPage(pageNum, pageSize);
             List<SparePartInfoVO> list = mapper.selectPageList(record);
-            for(SparePartInfoVO vo: list){
-                for(SpareType type:typeList){
-                    if(StringUtils.isNotBlank(vo.getTypeId()) && vo.getTypeId().equals(type.getId())){
+            for (SparePartInfoVO vo : list) {
+                for (SpareType type : typeList) {
+                    if (StringUtils.isNotBlank(vo.getTypeId()) && vo.getTypeId().equals(type.getId())) {
                         vo.setTypeName(type.getName());
                         vo.setTypeNo(type.getNo());
                     }
-                    if(StringUtils.isNotBlank(vo.getParentTypeId()) && vo.getParentTypeId().equals(type.getId())){
+                    if (StringUtils.isNotBlank(vo.getParentTypeId()) && vo.getParentTypeId().equals(type.getId())) {
                         vo.setParentName(type.getName());
                         vo.setParentNo(type.getNo());
                     }
-                    if(StringUtils.isNotBlank(vo.getMiddleTypeId()) && vo.getMiddleTypeId().equals(type.getId())){
+                    if (StringUtils.isNotBlank(vo.getMiddleTypeId()) && vo.getMiddleTypeId().equals(type.getId())) {
                         vo.setMiddleName(type.getName());
                         vo.setMiddleNo(type.getNo());
                     }
-                    if(StringUtils.isNotBlank(vo.getChildTypeId()) && vo.getChildTypeId().equals(type.getId())){
+                    if (StringUtils.isNotBlank(vo.getChildTypeId()) && vo.getChildTypeId().equals(type.getId())) {
                         vo.setChildName(type.getName());
                         vo.setChildNo(type.getNo());
                     }
@@ -215,35 +340,35 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
     public SparePartInfo getModelById(Object id) {
         SparePartInfo model = mapper.selectById(id);
         List<String> ids = new ArrayList<String>();
-        if(StringUtils.isNotBlank(model.getTypeId()) && !ids.contains(model.getTypeId())){
+        if (StringUtils.isNotBlank(model.getTypeId()) && !ids.contains(model.getTypeId())) {
             ids.add(model.getTypeId());
         }
-        if(StringUtils.isNotBlank(model.getParentTypeId()) && !ids.contains(model.getParentTypeId())){
+        if (StringUtils.isNotBlank(model.getParentTypeId()) && !ids.contains(model.getParentTypeId())) {
             ids.add(model.getParentTypeId());
         }
-        if(StringUtils.isNotBlank(model.getMiddleTypeId()) && !ids.contains(model.getMiddleTypeId())){
+        if (StringUtils.isNotBlank(model.getMiddleTypeId()) && !ids.contains(model.getMiddleTypeId())) {
             ids.add(model.getMiddleTypeId());
         }
-        if(StringUtils.isNotBlank(model.getChildTypeId()) && !ids.contains(model.getChildTypeId())){
+        if (StringUtils.isNotBlank(model.getChildTypeId()) && !ids.contains(model.getChildTypeId())) {
             ids.add(model.getChildTypeId());
         }
         Weekend<SpareType> weekend = new Weekend<>(SpareType.class);
         WeekendCriteria<SpareType, Object> weekendCriteria = weekend.weekendCriteria();
         weekendCriteria.andIn(SpareType::getId, ids);
         List<SpareType> typeList = spareTypeMapper.selectByExample(weekend);
-        for(SpareType type:typeList){
-            if(StringUtils.isNotBlank(model.getTypeId()) && model.getTypeId().equals(type.getId())){
+        for (SpareType type : typeList) {
+            if (StringUtils.isNotBlank(model.getTypeId()) && model.getTypeId().equals(type.getId())) {
                 model.setTypeName(type.getName());
             }
-            if(StringUtils.isNotBlank(model.getParentTypeId()) && model.getParentTypeId().equals(type.getId())){
+            if (StringUtils.isNotBlank(model.getParentTypeId()) && model.getParentTypeId().equals(type.getId())) {
                 model.setParentName(type.getName());
                 model.setParentNo(type.getNo());
             }
-            if(StringUtils.isNotBlank(model.getMiddleTypeId()) && model.getMiddleTypeId().equals(type.getId())){
+            if (StringUtils.isNotBlank(model.getMiddleTypeId()) && model.getMiddleTypeId().equals(type.getId())) {
                 model.setMiddleName(type.getName());
                 model.setMiddleNo(type.getNo());
             }
-            if(StringUtils.isNotBlank(model.getChildTypeId()) && model.getChildTypeId().equals(type.getId())){
+            if (StringUtils.isNotBlank(model.getChildTypeId()) && model.getChildTypeId().equals(type.getId())) {
                 model.setChildName(type.getName());
                 model.setChildNo(type.getNo());
             }
@@ -277,28 +402,28 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         SpareType middleType = spareTypeMapper.selectByPrimaryKey(model.getMiddleTypeId());
         String parentTypeNo = "";
         String middleTypeNo = "";
-        if(parentType !=null){
+        if (parentType != null) {
             parentTypeNo = parentType.getNo();
             model.setParentNo(parentTypeNo);
         }
-        if(middleType != null){
+        if (middleType != null) {
             middleTypeNo = middleType.getNo();
             model.setMiddleNo(middleTypeNo);
         }
         String nameNo = model.getNameNo();
         String ggNo = model.getGgNo();
         String childTypeNo = null;
-        if(StringUtils.isNotBlank(model.getChildTypeId())){
+        if (StringUtils.isNotBlank(model.getChildTypeId())) {
             SpareType childType = spareTypeMapper.selectByPrimaryKey(model.getChildTypeId());
             childTypeNo = childType.getNo();
             model.setChildNo(childTypeNo);
             model.setTypeId(model.getChildTypeId());
             model.setUniteNo(parentTypeNo + "-" + middleTypeNo + "-" + childTypeNo);
-        }else{
-            if(StringUtils.isNotBlank(model.getMiddleTypeId())){
+        } else {
+            if (StringUtils.isNotBlank(model.getMiddleTypeId())) {
                 model.setTypeId(model.getMiddleTypeId());
                 model.setUniteNo(parentTypeNo + "-" + middleTypeNo);
-            }else{
+            } else {
                 model.setTypeId(model.getParentTypeId());
                 model.setUniteNo(parentTypeNo);
             }
@@ -307,10 +432,14 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         Weekend<SparePartInfo> weekend = new Weekend<>(SparePartInfo.class);
         weekend.weekendCriteria().andEqualTo(SparePartInfo::getName, model.getName()).andEqualTo(SparePartInfo::getGgxh, model.getGgxh());
         int checkInfo = mapper.selectCountByExample(weekend);
-        if(checkInfo > 0){
+        if (checkInfo > 0) {
             throw new BusinessException("同名称同规格的备件已存在,请重新设置");
         }
         model.setId(IdGeneratorUtils.getObjectId());
+
+        // 设置编码
+        setSpareNo(model);
+
         // 保存二维码
         String path = CommonConstants.RESOURCE_PREFIX + "/png/" + DateUtil.formatDate(new Date()) + "/" + IdGeneratorUtils.getObjectId() + "/";
         String rootPath = environment.getProperty("upload.root-dir");
@@ -322,7 +451,7 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         UserInfo userInfo = SecurityUtils.getUserInfo();
         LocalDateTime time = LocalDateTime.now();
         // 如果由sbId,则要创建bom
-        if(StringUtils.isNotBlank(model.getSbId())){
+        if (StringUtils.isNotBlank(model.getSbId())) {
             SbModelSpareBom bom = new SbModelSpareBom();
             bom.setId(IdGeneratorUtils.getObjectId());
             bom.setSpareId(model.getId());
@@ -339,21 +468,21 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         this.saveFile(model);
 
         // 如果初始化数量有了,就需要更新库存
-        if(model.getInitStock() == null){
+        if (model.getInitStock() == null) {
             model.setInitStock(new BigDecimal(0));
         }
-        if(model.getInitStock() != null){
+        if (model.getInitStock() != null) {
             SpareStore spareStore = new SpareStore();
             spareStore.setSpareId(model.getId());
             spareStore.setId(IdGeneratorUtils.getObjectId());
-            if(StringUtils.isBlank(model.getStoreId())){
+            if (StringUtils.isBlank(model.getStoreId())) {
                 throw new BusinessException("请设置库位信息");
             }
             spareStore.setStoreId(model.getStoreId());
             BigDecimal price = model.getInitialValue();
             spareStore.setPrice(model.getInitialValue());
-            spareStore.setNum(model.getInitStock() );
-            spareStore.setInitNum(model.getInitStock() );
+            spareStore.setNum(model.getInitStock());
+            spareStore.setInitNum(model.getInitStock());
             spareStore.setInitPrice(model.getInitialValue());
             spareStore.setInitPurchasePrice(model.getInitialValue());
             spareStore.setCreatedTime(time);
@@ -365,8 +494,8 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
 
         // 插入设备关联
         List<SbModelSpareBomDTO> detailList = model.getDetailList();
-        if(!CollectionUtils.isEmpty(detailList)){
-            for(SbModelSpareBomDTO detail:detailList) {
+        if (!CollectionUtils.isEmpty(detailList)) {
+            for (SbModelSpareBomDTO detail : detailList) {
                 detail.setSpareId(model.getId());
                 detail.setId(IdGeneratorUtils.getObjectId());
             }
@@ -375,6 +504,54 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         return super.saveModelHaveCreateInfo(model);
     }
 
+    public void setSpareNo(SparePartInfoDTO model) {
+        String prefix = "";
+        SpareType spareType = spareTypeMapper.selectByPrimaryKey(model.getTypeId());
+        if (StringUtils.isNotBlank(spareType.getParentId())) {
+            SpareType spareType1 = spareTypeMapper.selectByPrimaryKey(spareType.getParentId());
+            prefix += spareType1.getNo() + "-";
+        }
+        prefix += spareType.getNo() + "-";
+        String selectMaxNo = mapper.selectMaxNo(model.getTypeId());
+        if (StringUtils.isBlank(selectMaxNo)) {
+            model.setNo(prefix + "00001");
+        } else {
+            String newStr = selectMaxNo.substring(selectMaxNo.length() - 5).replaceFirst("^0*", "");
+            int count = Integer.valueOf(newStr) + 1;
+            String str1 = String.format("%05d", count);
+            model.setNo(prefix + str1);
+        }
+    }
+
+    @Override
+    public void updateSpareNo(SparePartInfo model) {
+        String prefix = "";
+        SpareType spareType = spareTypeMapper.selectByPrimaryKey(model.getTypeId());
+        if(spareType == null){
+            throw new BusinessException("备件类别不存在:type_id=" + model.getTypeId());
+        }
+        if (StringUtils.isNotBlank(spareType.getParentId())) {
+            SpareType spareType1 = spareTypeMapper.selectByPrimaryKey(spareType.getParentId());
+            prefix += spareType1.getNo() + "-";
+        }
+        prefix += spareType.getNo() + "-";
+        String selectMaxNo = mapper.selectMaxNo(model.getTypeId());
+        if (StringUtils.isBlank(selectMaxNo)) {
+            model.setNo(prefix + "00001");
+        } else {
+            log.info("selectMaxNo: " + selectMaxNo);
+            String newStr = selectMaxNo.substring(selectMaxNo.length() - 5).replaceFirst("^0*", "");
+            int count = Integer.valueOf(newStr) + 1;
+            String str1 = String.format("%05d", count);
+            model.setNo(prefix + str1);
+        }
+        SparePartInfo sparePartInfo = new SparePartInfo();
+        sparePartInfo.setId(model.getId());
+        sparePartInfo.setNo(model.getNo());
+        mapper.updateByPrimaryKeySelective(sparePartInfo);
+
+    }
+
     @Override
     public void modModelByDTO(SparePartInfoDTO model) {
         UserInfo userInfo = SecurityUtils.getUserInfo();
@@ -384,29 +561,29 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         SpareType middleType = spareTypeMapper.selectByPrimaryKey(model.getMiddleTypeId());
         String parentTypeNo = "";
         String middleTypeNo = "";
-        if(parentType !=null){
+        if (parentType != null) {
             parentTypeNo = parentType.getNo();
             model.setParentNo(parentTypeNo);
         }
-        if(middleType != null){
+        if (middleType != null) {
             middleTypeNo = middleType.getNo();
             model.setMiddleNo(middleTypeNo);
         }
         String nameNo = model.getNameNo();
         String ggNo = model.getGgNo();
         String childTypeNo = null;
-        if(StringUtils.isNotBlank(model.getChildTypeId())){
+        if (StringUtils.isNotBlank(model.getChildTypeId())) {
             SpareType childType = spareTypeMapper.selectByPrimaryKey(model.getChildTypeId());
             childTypeNo = childType.getNo();
             model.setChildNo(childTypeNo);
             model.setTypeId(model.getChildTypeId());
             model.setUniteNo(parentTypeNo + "-" + middleTypeNo + "-" + childTypeNo + "-" + nameNo + "-" + ggNo);
-        }else{
+        } else {
             model.setTypeId(model.getMiddleTypeId());
-            if(StringUtils.isNotBlank(middleTypeNo)){
+            if (StringUtils.isNotBlank(middleTypeNo)) {
                 model.setTypeId(model.getMiddleTypeId());
                 model.setUniteNo(parentTypeNo + "-" + middleTypeNo);
-            }else{
+            } else {
                 model.setTypeId(model.getParentTypeId());
                 model.setUniteNo(parentTypeNo);
             }
@@ -415,7 +592,7 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         Weekend<SparePartInfo> weekend = new Weekend<>(SparePartInfo.class);
         weekend.weekendCriteria().andEqualTo(SparePartInfo::getName, model.getName()).andEqualTo(SparePartInfo::getGgxh, model.getGgxh());
         int count = mapper.selectCountByExample(weekend);
-        if(count > 1){
+        if (count > 1) {
             throw new BusinessException("同名称同规格的备件已存在,请重新设置名称或者规格");
         }
 
@@ -428,46 +605,48 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         Weekend<SbModelSpareBom> detailWeekend = new Weekend<>(SbModelSpareBom.class);
         List<String> ids = detailList.stream().map(SbModelSpareBomDTO::getId).collect(Collectors.toList());
         ids = ids.stream().filter(item -> StringUtils.isNotBlank(item)).collect(Collectors.toList());
-        if(!CollectionUtils.isEmpty(ids) && ids.size()>0) {
+        if (!CollectionUtils.isEmpty(ids) && ids.size() > 0) {
             detailWeekend.weekendCriteria().andNotIn(SbModelSpareBom::getId, ids);
             sbModelSpareBomMapper.deleteByExample(detailWeekend);
-        }else{
+        } else {
             // 全部刪除:说明id为空,全部删除了
             detailWeekend.weekendCriteria().andEqualTo(SbModelSpareBom::getSpareId, model.getId());
             sbModelSpareBomMapper.deleteByExample(detailWeekend);
         }
         // 新增与更新
-        if(!CollectionUtils.isEmpty(detailList)){
-            for(SbModelSpareBomDTO detail:detailList) {
-                if(StringUtils.isBlank(detail.getId())){
+        if (!CollectionUtils.isEmpty(detailList)) {
+            for (SbModelSpareBomDTO detail : detailList) {
+                if (StringUtils.isBlank(detail.getId())) {
                     detail.setSpareId(model.getId());
                     detail.setId(IdGeneratorUtils.getObjectId());
                     addList.add(detail);
-                }else{
+                } else {
                     updateList.add(detail);
                 }
             }
-            if(!CollectionUtils.isEmpty(addList)){
+            if (!CollectionUtils.isEmpty(addList)) {
                 sbModelSpareBomMapper.insertListforComplex(BeanConverterUtil.copyListProperties(addList, SbModelSpareBom.class));
             }
-            if(!CollectionUtils.isEmpty(updateList)){
+            if (!CollectionUtils.isEmpty(updateList)) {
                 sbModelSpareBomMapper.updateBatchAll(BeanConverterUtil.copyListProperties(updateList, SbModelSpareBom.class));
             }
         }
         this.saveFile(model);
         super.modModelByDTO(model);
     }
+
     private void saveFile(SparePartInfoDTO model) {
         if (CollectionUtil.isNotEmpty(model.getApplicationFileList())) {
             Weekend<SysFile> weekend = new Weekend<>(SysFile.class);
             weekend.weekendCriteria().andEqualTo(SysFile::getType, SysFileTypeEnum.SPARE_IMGS.getValue()).andEqualTo(SysFile::getTargetId, model.getId());
             sysFileMapper.deleteByExample(weekend);
-            List<SysFile> list = SysFileUtils.changeFileList(model.getApplicationFileList(), model.getId(),  SysFileTypeEnum.SPARE_IMGS.getValue());
+            List<SysFile> list = SysFileUtils.changeFileList(model.getApplicationFileList(), model.getId(), SysFileTypeEnum.SPARE_IMGS.getValue());
             if (CollectionUtil.isNotEmpty(list)) {
                 sysFileMapper.insertListforComplex(list);
             }
         }
     }
+
     /**
      * 导入备件基础信息
      *
@@ -496,29 +675,29 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                 List<SbModel> addSbModelItems = new ArrayList<SbModel>();
                 for (SparePartInfoVO item : items) {
                     System.out.println("正在处理:" + item.getName() + ",编号" + item.getNo());
-                    boolean  isExist = false;
+                    boolean isExist = false;
                     for (SparePartInfo old : vos) {
                         // System.out.println("正在对比:" + old.getName() + ", 规格" + old.getGgxh() + ", 原厂编号" + old.getInitNo());
-                        if(item.getGgxh() == null){
-                            if(old.getName().equals(item.getName()) && old.getGgxh() == null){
+                        if (item.getGgxh() == null) {
+                            if (old.getName().equals(item.getName()) && old.getGgxh() == null) {
                                 isExist = true;
                                 item.setId(old.getId());
                                 item.setNo(old.getNo());
                                 item.setInitNo(old.getInitNo());
-                                if(!modelExist.contains(item.getName() + ",规格" + item.getGgxh())){
+                                if (!modelExist.contains(item.getName() + ",规格" + item.getGgxh())) {
                                     modelExist.add(item.getName() + ",规格" + item.getGgxh());
                                 }
                             }
-                        }else{
-                            if(old.getGgxh() == null){
+                        } else {
+                            if (old.getGgxh() == null) {
 
-                            }else{
-                                if(old.getName().equals(item.getName()) && old.getGgxh().equals(item.getGgxh())){
+                            } else {
+                                if (old.getName().equals(item.getName()) && old.getGgxh().equals(item.getGgxh())) {
                                     isExist = true;
                                     item.setId(old.getId());
                                     item.setNo(old.getNo());
                                     item.setInitNo(old.getInitNo());
-                                    if(!modelExist.contains(item.getName() + ",规格" + item.getGgxh())){
+                                    if (!modelExist.contains(item.getName() + ",规格" + item.getGgxh())) {
                                         modelExist.add(item.getName() + ",规格" + item.getGgxh());
                                     }
                                 }
@@ -527,54 +706,54 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                     }
                     // 如果已经存在,则跳过去下一个,不行,需要获取id,因为要入库。需要备件信息
                     System.out.println("处理到这");
-                    if(isExist){
+                    if (isExist) {
 
-                    }else{
+                    } else {
                         // 新增的,需要设置id和类别
                         item.setId(IdGeneratorUtils.getObjectId());
                         // 设置类型转换
                         for (SpareType type : typeList) {
-                            if(type.getName().equals(item.getParentName())){
+                            if (type.getName().equals(item.getParentName())) {
                                 item.setParentTypeId(type.getId());
                                 item.setParentNo(type.getNo());
                             }
-                            if(type.getName().equals(item.getMiddleName())){
+                            if (type.getName().equals(item.getMiddleName())) {
                                 item.setMiddleTypeId(type.getId());
                                 item.setMiddleNo(type.getNo());
                             }
-                            if(type.getName().equals(item.getChildName())){
+                            if (type.getName().equals(item.getChildName())) {
                                 item.setChildTypeId(type.getId());
                                 item.setChildNo(type.getNo());
                             }
                         }
-                        if(StringUtils.isNotBlank(item.getChildTypeId())){
+                        if (StringUtils.isNotBlank(item.getChildTypeId())) {
                             item.setTypeId(item.getChildTypeId());
-                        }else{
+                        } else {
                             item.setTypeId(item.getMiddleTypeId());
                         }
                     }
 
                     // 设置型号bom
                     boolean findModel = false;
-                    if(StringUtils.isNotBlank(item.getSbModel())){
+                    if (StringUtils.isNotBlank(item.getSbModel())) {
                         SbModelSpareBom bom = new SbModelSpareBom();
                         bom.setSpareId(item.getId());
                         for (SbModel model : modelList) {
-                            if(model.getModel().equals(item.getSbModel())){
+                            if (model.getModel().equals(item.getSbModel())) {
                                 findModel = true;
                                 // 判断该model是否已经有bom,如果有,则不导入,需要验证后重新导入。
                                 boolean withBoms = false;
                                 for (String modelIdWithBom : modelIdsWithBom) {
-                                    if(model.getId().equals(modelIdWithBom)){
+                                    if (model.getId().equals(modelIdWithBom)) {
                                         withBoms = true;
-                                        if(!modelWarn.contains(item.getSbName() + ",型号" + item.getSbModel())){
+                                        if (!modelWarn.contains(item.getSbName() + ",型号" + item.getSbModel())) {
                                             modelWarn.add(item.getSbName() + ",型号" + item.getSbModel());
                                         }
                                         break;
                                     }
                                 }
 
-                                if(withBoms){
+                                if (withBoms) {
                                     break;
                                 }
                                 bom.setId(IdGeneratorUtils.getObjectId());
@@ -587,8 +766,8 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                                 break;
                             }
                         }
-                        if(!findModel){
-                            if(!modelError.contains(item.getSbName() + ",型号" + item.getSbModel())){
+                        if (!findModel) {
+                            if (!modelError.contains(item.getSbName() + ",型号" + item.getSbModel())) {
                                 modelError.add(item.getSbName() + ",型号" + item.getSbModel());
                             }
                             SbModel model = new SbModel();
@@ -610,12 +789,12 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                             model.setId(IdGeneratorUtils.getObjectId());
                             boolean withModelBoms = false;
                             for (SbModel modelIs : addSbModelItems) {
-                                if(modelIs.getName().equals(model.getName()) && modelIs.getModel().equals(model.getModel())){
+                                if (modelIs.getName().equals(model.getName()) && modelIs.getModel().equals(model.getModel())) {
                                     withModelBoms = true;
                                     break;
                                 }
                             }
-                            if(!withModelBoms){
+                            if (!withModelBoms) {
                                 addSbModelItems.add(model);
                             }
                             bom.setId(IdGeneratorUtils.getObjectId());
@@ -626,7 +805,7 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                             bom.setUpdateTime(now);
                             bom.setUpdateUserId("1");
                             bomList.add(bom);
-                        }else{
+                        } else {
                             bomList.add(bom);
                         }
                     }
@@ -646,29 +825,29 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                     spareStore.setUpdateTime(now);
                     spareStore.setUpdateUserId("1");
                     spareStoreList.add(spareStore);
-                    if(!isExist) {
+                    if (!isExist) {
                         addItems.add(item);
                     }
                 }
 
-                if(modelWarn.size()>0){
+                if (modelWarn.size() > 0) {
                     System.out.println("如下型号已经存在bom,该备件没有导入,后期可以自行导入: " + modelWarn.toString());
                 }
-                if(!CollectionUtils.isEmpty(addItems)){
-                    addItemsReal = BeanConverterUtil.copyListProperties(addItems,SparePartInfo.class);
+                if (!CollectionUtils.isEmpty(addItems)) {
+                    addItemsReal = BeanConverterUtil.copyListProperties(addItems, SparePartInfo.class);
                     mapper.insertListforComplex(addItemsReal);
                 }
-                if(!CollectionUtils.isEmpty(addSbModelItems)){
+                if (!CollectionUtils.isEmpty(addSbModelItems)) {
                     sbModelMapper.insertListforComplex(addSbModelItems);
                 }
-                if(!CollectionUtils.isEmpty(bomList)){
+                if (!CollectionUtils.isEmpty(bomList)) {
                     sbModelSpareBomMapper.insertListforComplex(bomList);
                 }
-                if(!CollectionUtils.isEmpty(spareStoreList)){
+                if (!CollectionUtils.isEmpty(spareStoreList)) {
                     spareStoreMapper.insertListforComplex(spareStoreList);
                 }
             }
-            return "总计新增导入:"+ (addItems.size()) + "已存在未导入数量:"  + modelExist.size() + ",找不到如下型号,已经添加:" + modelError.toString();
+            return "总计新增导入:" + (addItems.size()) + "已存在未导入数量:" + modelExist.size() + ",找不到如下型号,已经添加:" + modelError.toString();
         } catch (Exception e) {
             throw new BusinessException(e.getMessage());
         }
@@ -700,22 +879,22 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                     item.setId(IdGeneratorUtils.getObjectId());
                     // 设置类型转换
                     for (SpareType type : typeList) {
-                        if(type.getName().equals(item.getParentName())){
+                        if (type.getName().equals(item.getParentName())) {
                             item.setParentTypeId(type.getId());
                             item.setParentNo(type.getNo());
                         }
-                        if(type.getName().equals(item.getMiddleName())){
+                        if (type.getName().equals(item.getMiddleName())) {
                             item.setMiddleTypeId(type.getId());
                             item.setMiddleNo(type.getNo());
                         }
-                        if(type.getName().equals(item.getChildName())){
+                        if (type.getName().equals(item.getChildName())) {
                             item.setChildTypeId(type.getId());
                             item.setChildNo(type.getNo());
                         }
                     }
-                    if(StringUtils.isNotBlank(item.getChildTypeId())){
+                    if (StringUtils.isNotBlank(item.getChildTypeId())) {
                         item.setTypeId(item.getChildTypeId());
-                    }else{
+                    } else {
                         item.setTypeId(item.getMiddleTypeId());
                     }
 
@@ -801,8 +980,8 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                     addItems.add(item);
 
                 }
-                if(!CollectionUtils.isEmpty(addItems)){
-                    addItemsReal = BeanConverterUtil.copyListProperties(addItems,SparePartInfo.class);
+                if (!CollectionUtils.isEmpty(addItems)) {
+                    addItemsReal = BeanConverterUtil.copyListProperties(addItems, SparePartInfo.class);
                     mapper.insertListforComplex(addItemsReal);
                 }
                /* if(!CollectionUtils.isEmpty(addSbModelItems)){
@@ -811,11 +990,11 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
                 if(!CollectionUtils.isEmpty(bomList)){
                     sbModelSpareBomMapper.insertListforComplex(bomList);
                 }*/
-                if(!CollectionUtils.isEmpty(spareStoreList)){
+                if (!CollectionUtils.isEmpty(spareStoreList)) {
                     spareStoreMapper.insertListforComplex(spareStoreList);
                 }
             }
-            return "总计新增导入:"+ (addItems.size()) ;
+            return "总计新增导入:" + (addItems.size());
         } catch (Exception e) {
             throw new BusinessException(e.getMessage());
         }
@@ -827,35 +1006,36 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         List<SparePartInfoVO> addItems = new ArrayList<SparePartInfoVO>();
         LocalDateTime now = LocalDateTime.now();
         try {
-            List<SparePartInfoVO> items = CustomExcelImportUtil.importSparePartInfoListForUpdate(now, file.getInputStream());
+            List<SparePartInfoVO> items = CustomExcelImportUtil.importSparePartInfoListForUpdate(file.getInputStream());
             if (!CollectionUtils.isEmpty(items)) {
                 List<SpareType> typeList = spareTypeMapper.selectAll();
                 for (SparePartInfoVO item : items) {
                     // 设置类型转换
                     for (SpareType type : typeList) {
-                        if(type.getName().equals(item.getParentName())){
+                        if (type.getName().equals(item.getTypeName())) {
                             item.setParentTypeId(type.getId());
                             item.setParentNo(type.getNo());
                             item.setTypeId(type.getId());
                         }
-                        if(type.getName().equals(item.getMiddleName()) && StringUtils.isNotBlank(type.getParentId()) && type.getParentId().equals(item.getParentTypeId())){
+                        /*if (type.getName().equals(item.getMiddleName()) && StringUtils.isNotBlank(type.getParentId()) && type.getParentId().equals(item.getParentTypeId())) {
                             item.setMiddleTypeId(type.getId());
                             item.setMiddleNo(type.getNo());
                             item.setTypeId(type.getId());
                         }
-                        if(type.getName().equals(item.getChildName()) && StringUtils.isNotBlank(type.getParentId()) && type.getParentId().equals(item.getMiddleTypeId())){
+                        if (type.getName().equals(item.getChildName()) && StringUtils.isNotBlank(type.getParentId()) && type.getParentId().equals(item.getMiddleTypeId())) {
                             item.setChildTypeId(type.getId());
                             item.setChildNo(type.getNo());
                             item.setTypeId(type.getId());
-                        }
+                        }*/
                     }
+                    mapper.updateByPrimaryKeySelective(BeanConverterUtil.copyObjectProperties(item, SparePartInfo.class));
                     addItems.add(item);
                 }
             }
-            if(!CollectionUtils.isEmpty(addItems)){
-                mapper.updateBatch(addItems);
+            if (!CollectionUtils.isEmpty(addItems)) {
+                // mapper.updateBatch(addItems);
             }
-            return "总计修改:"+ addItems.size();
+            return "总计修改:" + addItems.size();
         } catch (Exception e) {
             throw new BusinessException(e.getMessage());
         }
@@ -867,11 +1047,11 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         WeekendCriteria<SpareStore, Object> weekendCriteria = weekend.weekendCriteria();
         weekendCriteria.andIn(SpareStore::getSpareId, ids);
         List<SpareStore> list = spareStoreMapper.selectByExample(weekend);
-        list.forEach(item->{
+        list.forEach(item -> {
             item.setSpareId(spareId);
         });
         List<SpareStore> newlist = new ArrayList<SpareStore>();
-        for(SpareStore spareStore:list){
+        for (SpareStore spareStore : list) {
             SpareStore spare = new SpareStore();
             spare.setId(spareStore.getId());
             spare.setSpareId(spareId);
@@ -883,11 +1063,11 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         WeekendCriteria<SbModelSpareBom, Object> weekendCriteria2 = weekend2.weekendCriteria();
         weekendCriteria2.andIn(SbModelSpareBom::getSpareId, ids);
         List<SbModelSpareBom> sbModelSpareBomList = sbModelSpareBomMapper.selectByExample(weekend2);
-        sbModelSpareBomList.forEach(item->{
+        sbModelSpareBomList.forEach(item -> {
             item.setSpareId(spareId);
         });
         List<SbModelSpareBom> newSbModelSpareBomList = new ArrayList<SbModelSpareBom>();
-        for(SbModelSpareBom spareStore:sbModelSpareBomList){
+        for (SbModelSpareBom spareStore : sbModelSpareBomList) {
             SbModelSpareBom spare = new SbModelSpareBom();
             spare.setId(spareStore.getId());
             spare.setSpareId(spareId);
@@ -897,6 +1077,17 @@ public class SparePartInfoServiceImpl extends BaseServiceImpl<SparePartInfoMappe
         this.batchDelete(ids);
     }
 
+    @Override
+    public void updateSpareWarnStatus(String id, Integer type, Integer warnStatus) {
+        SparePartInfo sparePartInfo = mapper.selectById(id);
+        if (type == 1) {
+            sparePartInfo.setWarnStatus(warnStatus);
+        } else {
+            sparePartInfo.setForecastStatus(warnStatus);
+        }
+        mapper.updateByPrimaryKey(sparePartInfo);
+    }
+
     @Override
     public void updateQrCode(SparePartInfoDTO model) {
         SparePartInfo sbInfo = new SparePartInfo();

+ 24 - 9
platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SpareTypeServiceImpl.java

@@ -2,6 +2,7 @@ package com.platform.service.sqarepartmanage.impl;
 
 import com.github.pagehelper.PageHelper;
 import com.platform.common.bean.AbstractPageResultBean;
+import com.platform.common.exception.BusinessException;
 import com.platform.common.util.IdGeneratorUtils;
 import com.platform.common.util.StringUtils;
 import com.platform.dao.bean.MyPage;
@@ -12,8 +13,10 @@ import com.platform.dao.dto.sqarepartmanage.SpareTypeDTO;
 import com.platform.dao.entity.maintain.MaintainJob;
 import com.platform.dao.entity.sb.SbModel;
 import com.platform.dao.entity.sb.SbType;
+import com.platform.dao.entity.sqarepartmanage.SparePartInfo;
 import com.platform.dao.entity.sqarepartmanage.SpareType;
 import com.platform.dao.entity.sqarepartmanage.SpareType;
+import com.platform.dao.mapper.sqarepartmanage.SparePartInfoMapper;
 import com.platform.dao.mapper.sqarepartmanage.SpareTypeMapper;
 import com.platform.dao.vo.sb.SbInfoVO;
 import com.platform.dao.vo.sb.SbModelVO;
@@ -44,23 +47,35 @@ import java.util.List;
 public class SpareTypeServiceImpl extends BaseServiceImpl<SpareTypeMapper, SpareType, SpareTypeDTO> implements SpareTypeService {
     private final SbTypeService sbTypeService;
     private final SbModelService sbModelService;
-
+    private final SparePartInfoMapper sparePartInfoMapper;
     @Override
     public int batchDelete(List<String> ids) {
+        ids.forEach(id -> {
+            deleteByPrimaryKey(id);
+        });
+        return 1;
+    }
 
-        // 删除该类
-        Weekend<SpareType> weekend = new Weekend<>(SpareType.class);
-        WeekendCriteria<SpareType, Object> weekendCriteria = weekend.weekendCriteria();
-        weekendCriteria.andIn(SpareType::getId, ids);
-        mapper.deleteByExample(weekend);
+    @Override
+    public void deleteByPrimaryKey(String id) {
+        // 检查是否有备件引用该类,如有,则不能删除
+        // 删除对应的子类
+        Weekend<SparePartInfo> sparePartInfoWeekend = new Weekend<>(SparePartInfo.class);
+        WeekendCriteria<SparePartInfo, Object> sparePartInfoObjectWeekendCriteria = sparePartInfoWeekend.weekendCriteria();
+        sparePartInfoObjectWeekendCriteria.andEqualTo(SparePartInfo::getTypeId, id);
+        List<SparePartInfo> sparePartInfos = sparePartInfoMapper.selectByExample(sparePartInfoWeekend);
+        if(!CollectionUtils.isEmpty(sparePartInfos)){
+            throw new BusinessException("有备件引用,无法删除");
+        }
+
+        // 删除对应的子类
+        super.deleteByPrimaryKey(id);
 
         // 删除对应的子类
         Weekend<SpareType> weekendChild = new Weekend<>(SpareType.class);
         WeekendCriteria<SpareType, Object> weekendCriteriaChild = weekendChild.weekendCriteria();
-        weekendCriteriaChild.andIn(SpareType::getParentId, ids);
+        weekendCriteriaChild.andEqualTo(SpareType::getParentId, id);
         mapper.deleteByExample(weekendChild);
-
-        return 1;
     }
 
     @Override