瀏覽代碼

维修配件优化

guarantee-lsq 3 年之前
父節點
當前提交
97a96d7315

+ 2 - 0
platform-dao/src/main/java/com/platform/dao/dto/sb/SbModelSpareBomDTO.java

@@ -121,4 +121,6 @@ public class SbModelSpareBomDTO extends BaseDTO implements Serializable {
 
     private String oldSpareId;
 
+    private Integer isSpecial;
+
 }

+ 6 - 0
platform-dao/src/main/java/com/platform/dao/dto/sqarepartmanage/SparePartUsedDTO.java

@@ -141,4 +141,10 @@ public class SparePartUsedDTO extends BaseDTO implements Serializable {
      */
     private Integer usedSource;
 
+    /**
+     * 是否是专用备件
+     * 0 不是 1 是
+     */
+    private Integer isSpecial;
+
 }

+ 8 - 0
platform-dao/src/main/java/com/platform/dao/mapper/sqarepartmanage/SparePartUsedMapper.java

@@ -64,4 +64,12 @@ public interface SparePartUsedMapper extends MyMapper<SparePartUsed> {
      * @return
      */
     SparePartUsedVO selectSpecialOne(SparePartUsedDTO model);
+
+    /**
+     * 查询型号对应的点检标准
+     *
+     * @param sbId
+     * @return
+     */
+    List<SparePartUsedVO> selectSparePartUsedListBySbId(String sbId);
 }

+ 4 - 0
platform-dao/src/main/resources/mapper/sb/SbModelSpareBomMapper.xml

@@ -34,6 +34,7 @@
         from t_sb_model_spare_bom bom
         LEFT JOIN t_sb_info sbInfo ON bom.sb_id = sbInfo.id
         LEFT JOIN t_part_info part on bom.sb_part_id = part.id
+        left join t_spare_part_info partInfo on bom.spare_id = partInfo.id
         <where>
             <if test="spareId != null">
                 and bom.spare_id = #{spareId}
@@ -41,6 +42,9 @@
             <if test="sbId != null">
                 and bom.sb_id = #{sbId}
             </if>
+            <if test="isSpecial != null">
+                and partInfo.is_special = #{isSpecial}
+            </if>
             <if test="keyword != null and keyword != ''">
                 and (
                     sbInfo.no like concat('%',#{keyword},'%')

+ 7 - 0
platform-dao/src/main/resources/mapper/sqarepartmanage/SparePartUsedMapper.xml

@@ -149,4 +149,11 @@
         </where>
         order by created_time desc limit 1
     </select>
+
+    <select id="selectSparePartUsedListBySbId" resultType="com.platform.dao.vo.spare.SparePartUsedVO">
+        select used.*, spareInfo.name as spareName
+        from t_spare_part_used used
+        left join t_spare_part_info spareInfo on used.spare_id = spareInfo.id
+        where used.sb_id = #{sbId} and used.status = 1 and spareInfo.is_special = 1
+    </select>
 </mapper>

+ 16 - 18
platform-rest/src/main/java/com/platform/rest/controller/sqarepartmanage/SparePartUsedController.java

@@ -1,24 +1,19 @@
 package com.platform.rest.controller.sqarepartmanage;
 
 import com.platform.common.bean.AbstractPageResultBean;
-import com.platform.common.exception.BusinessException;
 import com.platform.common.util.BeanConverterUtil;
-import com.platform.common.util.IdGeneratorUtils;
 import com.platform.common.util.R;
 import com.platform.common.validation.group.AddGroup;
 import com.platform.common.validation.group.UpdateGroup;
 import com.platform.dao.bean.MyVOPage;
-import com.platform.dao.dto.repair.RepairProjectRelationDTO;
 import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
 import com.platform.dao.entity.sqarepartmanage.SparePartUsed;
 import com.platform.dao.util.ExcelUtil;
 import com.platform.dao.vo.export.sqarepartmanage.ExportSparePartUsedVO;
-import com.platform.dao.vo.repair.RepairProjectVO;
 import com.platform.dao.vo.spare.SparePartUsedVO;
 import com.platform.rest.log.annotation.SysLog;
 import com.platform.service.sqarepartmanage.SparePartUsedService;
 import lombok.AllArgsConstructor;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -71,19 +66,8 @@ public class SparePartUsedController {
     @SysLog("新增维修单-维修项目关联")
     @PostMapping("/batch")
     public R save(@Validated({AddGroup.class}) @RequestBody List<SparePartUsedDTO> sparePartUsedDTOList) throws Exception {
-        /*for(SparePartUsedDTO sparePartUsedDTO:sparePartUsedDTOList ){
-            SparePartUsedDTO d = new SparePartUsedDTO();
-            d.setRepairId(sparePartUsedDTO.getRepairId());
-            d.setSpareId(sparePartUsedDTO.getSpareId());
-            d.setSbId(sparePartUsedDTO.getSbId());
-            int count = sparePartUsedService.getCountByDTO(d);
-            if(count != 0){
-                throw new BusinessException("已经存在该备件,修改即可,无需添加");
-            }
-            sparePartUsedDTO.setId(IdGeneratorUtils.getObjectId());
-        }*/
-        sparePartUsedService.saveModelListByDTO(sparePartUsedDTOList);
-        return new R<>("添加成功");
+        //sparePartUsedService.saveModelListByDTO(sparePartUsedDTOList);
+        return new R<>(sparePartUsedService.saveBatch(sparePartUsedDTOList));
     }
 
     /**
@@ -98,6 +82,13 @@ public class SparePartUsedController {
         List<SparePartUsedVO> list =  sparePartUsedService.selectSparePartUsedListByRepairId(repairId);
         return new R<>(list);
     }
+
+    @SysLog("维修项目bom")
+    @GetMapping("list/{sbId}")
+    public R selectSparePartUsedListBySbId(@PathVariable String sbId) {
+        List<SparePartUsedVO> list =  sparePartUsedService.selectSparePartUsedListBySbId(sbId);
+        return new R<>(list);
+    }
     /**
      * 修改记录
      * 修改仅仅只能修改:状态,更换日期两个参数,其他不能修改,只能通过删除操作
@@ -192,4 +183,11 @@ public class SparePartUsedController {
         return new R<>(sparePartUsedService.statisticsByGroupBySparePage(model, pageNum, pageSize));
     }
 
+    @SysLog("更换备件")
+    @PutMapping("/update/spare")
+    public R updateSpare(@Validated({UpdateGroup.class}) @RequestBody SparePartUsedDTO sparePartUsedDTO) {
+        sparePartUsedService.updateSpare(sparePartUsedDTO);
+        return new R<>();
+    }
+
 }

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

@@ -85,4 +85,19 @@ public interface SparePartUsedService extends IBaseService<SparePartUsed, SpareP
      * @return
      */
     List<SparePartUsedVO> getMonthReportMonth(SparePartUsedDTO sparePartUsedDTO, Integer year, Integer month);
+
+    /**
+     * 批量插入
+     * @param sparePartUsedDTOList
+     * @return
+     */
+    int[] saveBatch(List<SparePartUsedDTO> sparePartUsedDTOList);
+
+    /**
+     * 设备备件更换
+     * @param sparePartUsedDTO
+     */
+    void updateSpare(SparePartUsedDTO sparePartUsedDTO);
+
+    List<SparePartUsedVO> selectSparePartUsedListBySbId(String sbId);
 }

+ 90 - 8
platform-service/src/main/java/com/platform/service/sqarepartmanage/impl/SparePartUsedServiceImpl.java

@@ -2,14 +2,16 @@ package com.platform.service.sqarepartmanage.impl;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.github.pagehelper.PageHelper;
-import com.platform.common.exception.BusinessException;
+import com.platform.common.exception.DeniedException;
 import com.platform.common.model.UserInfo;
 import com.platform.common.util.*;
 import com.platform.dao.bean.MyVOPage;
 import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
+import com.platform.dao.entity.sqarepartmanage.SparePartInfo;
 import com.platform.dao.entity.sqarepartmanage.SparePartUsed;
 import com.platform.dao.entity.store.SpareStore;
 import com.platform.dao.enums.SparePartUsedStatusEnum;
+import com.platform.dao.mapper.sqarepartmanage.SparePartInfoMapper;
 import com.platform.dao.mapper.sqarepartmanage.SparePartUsedMapper;
 import com.platform.dao.mapper.store.SpareStoreMapper;
 import com.platform.dao.mapper.store.SpareStoreSecondMapper;
@@ -41,6 +43,7 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
 
     private SpareStoreSecondMapper spareStoreSecondMapper;
     private SpareStoreMapper spareStoreMapper;
+    private SparePartInfoMapper sparePartInfoMapper;
     @Override
     public int batchDelete(List<String> ids) {
         ids.forEach(id -> {
@@ -67,17 +70,57 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
 
     @Override
     public SparePartUsed saveModelByDTO(SparePartUsedDTO model) {
+        if(model.getIsSpecial() != null && model.getIsSpecial() == 1){
+            // 专用备件,是否初次加入
+            SparePartUsed usedQuery = new SparePartUsed();
+            usedQuery.setSbId(model.getSbId());
+            usedQuery.setSpareId(model.getSpareId());
+            usedQuery.setPartId(model.getPartId());
+            usedQuery.setRemark(model.getRemark() == null ? null : model.getRemark().trim());
+            int count = mapper.selectCount(usedQuery);
+            if(count > 0){
+                throw new DeniedException("配件记录已存在,如需更换,请点击更换");
+            }
+            // 判断到日期是否携带
+            if(model.getChangeDate() == null){
+                throw new DeniedException("预计报废日期不能为空");
+            }
+        }
+        // 是否需要添加BOM关系
         model.setStatus(SparePartUsedStatusEnum.IN_USE.getValue());
         SparePartUsed sparePartUsed = super.saveModelByDTO(model);
-       /* SpareStoreSecond second = spareStoreSecondMapper.selectByPrimaryKey(model.getStoreId());
-        if (ObjectUtil.isNotNull(second)) {
-            second.setTotalNum(second.getTotalNum()-1);
-            second.setUsedNum(second.getUsedNum() + 1);
-            spareStoreSecondMapper.updateByPrimaryKey(second);
-        }*/
         return sparePartUsed;
     }
 
+    /**
+     * 检查并存入
+     * @param model
+     * @return
+     */
+    private SparePartUsed saveAndCheck(SparePartUsedDTO model){
+        if(model.getIsSpecial() != null && model.getIsSpecial() == 1){
+            // 专用备件,是否初次加入
+            SparePartUsed usedQuery = new SparePartUsed();
+            usedQuery.setSbId(model.getSbId());
+            usedQuery.setSpareId(model.getSpareId());
+            usedQuery.setPartId(model.getPartId());
+            usedQuery.setRemark(model.getRemark() == null ? null : model.getRemark().trim());
+            int count = mapper.selectCount(usedQuery);
+            if(count > 0){
+                return null;
+            }
+            // 判断到日期是否携带
+            if(model.getChangeDate() == null){
+               return null;
+            }
+        }else{
+            return null;
+        }
+        // 是否需要添加BOM关系
+        model.setStatus(SparePartUsedStatusEnum.IN_USE.getValue());
+        return super.saveModelByDTO(model);
+    }
+
     /**
      * 刪除需要更新二級庫的庫存
      *
@@ -128,7 +171,7 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
         UserInfo userInfo = SecurityUtils.getUserInfo();
 
         for(SparePartUsedDTO sparePartUsedDTO:models ){
-            setCreateUserInfo(sparePartUsedDTO);
+           setCreateUserInfo(sparePartUsedDTO);
             sparePartUsedDTO.setId(IdGeneratorUtils.getObjectId());
             list.add(BeanConverterUtil.copyObjectProperties(sparePartUsedDTO, getEntityClass()));
             /*// 更新库存信息  该部分功能,放在领用单模块
@@ -217,6 +260,45 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
         return mapper.selectVOList(sparePartUsedDTO);
     }
 
+    @Override
+    public int[] saveBatch(List<SparePartUsedDTO> sparePartUsedDTOList) {
+        int[] array = new int[]{0,0};
+        for(SparePartUsedDTO sparePartUsedDTO : sparePartUsedDTOList){
+            if(saveAndCheck(sparePartUsedDTO) == null){
+                array[1] = array[1] + 1;
+            }else{
+                array[0] = array[0] + 1;
+            }
+        }
+        return array;
+    }
+
+    @Override
+    public void updateSpare(SparePartUsedDTO sparePartUsedDTO) {
+        SparePartUsed usedOld = new SparePartUsed();
+        usedOld.setId(sparePartUsedDTO.getId());
+        // 新配件
+        SparePartInfo sparePartInfo = sparePartInfoMapper.selectByPrimaryKey(sparePartUsedDTO.getSpareId());
+        LocalDate now = LocalDate.now();
+        int periodDay = sparePartInfo.getAgePeriod().multiply(new BigDecimal(30)).intValue();
+        sparePartUsedDTO.setStartDate(now);
+        sparePartUsedDTO.setChangeDate(now.plusDays(periodDay));
+        sparePartUsedDTO.setStatus(SparePartUsedStatusEnum.IN_USE.getValue());
+        this.saveModelByDTO(sparePartUsedDTO);
+        // 修改老配件
+        usedOld.setRealChangeDate(now);
+        usedOld.setUpdateTime(LocalDateTime.now());
+        usedOld.setUpdateUserId(SecurityUtils.getUserInfo().getUserId());
+        usedOld.setUpdateUserName(SecurityUtils.getUserInfo().getUsername());
+        usedOld.setStatus(SparePartUsedStatusEnum.REPLACEMENTED.getValue());
+        mapper.updateByPrimaryKeySelective(usedOld);
+    }
+
+    @Override
+    public List<SparePartUsedVO> selectSparePartUsedListBySbId(String sbId) {
+        return mapper.selectSparePartUsedListBySbId(sbId);
+    }
+
     public static void main(String[] args) {
         LocalDate localDate = LocalDate.now();
         int year = localDate.getYear();

+ 1 - 0
platform-service/src/main/java/com/platform/service/store/impl/SpareStoreServiceImpl.java

@@ -186,6 +186,7 @@ public class SpareStoreServiceImpl extends BaseServiceImpl<SpareStoreMapper, Spa
         if(model.getIsSpecial()!=null&&model.getIsSpecial()==1) {
             SbModelSpareBomDTO sbModelDTO = new SbModelSpareBomDTO();
             sbModelDTO.setSbId(model.getSbId());
+            sbModelDTO.setIsSpecial(1);
             List<SbModelSpareBomVO> modelList = sbModelSpareBomService.selectVOList(sbModelDTO);
             if(modelList != null && modelList.size()==0){
                 return new MyPage<>(null);