|
@@ -3,6 +3,7 @@ package com.platform.service.sqarepartmanage.impl;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.platform.common.exception.DeniedException;
|
|
|
+import com.platform.common.model.OauthUser;
|
|
|
import com.platform.common.model.UserInfo;
|
|
|
import com.platform.common.util.*;
|
|
|
import com.platform.dao.bean.MyVOPage;
|
|
@@ -76,10 +77,11 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
usedQuery.setSbId(model.getSbId());
|
|
|
usedQuery.setSpareId(model.getSpareId());
|
|
|
usedQuery.setPartId(model.getPartId());
|
|
|
+ usedQuery.setStatus(SparePartUsedStatusEnum.IN_USE.getValue());
|
|
|
usedQuery.setRemark(model.getRemark() == null ? null : model.getRemark().trim());
|
|
|
int count = mapper.selectCount(usedQuery);
|
|
|
if(count > 0){
|
|
|
- throw new DeniedException("配件记录已存在,如需更换,请点击更换");
|
|
|
+ throw new DeniedException("配件记录已存在,如需更换,请在维修中点击更换");
|
|
|
}
|
|
|
// 判断到日期是否携带
|
|
|
if(model.getChangeDate() == null){
|
|
@@ -104,6 +106,7 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
usedQuery.setSbId(model.getSbId());
|
|
|
usedQuery.setSpareId(model.getSpareId());
|
|
|
usedQuery.setPartId(model.getPartId());
|
|
|
+ usedQuery.setStatus(SparePartUsedStatusEnum.IN_USE.getValue());
|
|
|
usedQuery.setRemark(model.getRemark() == null ? null : model.getRemark().trim());
|
|
|
int count = mapper.selectCount(usedQuery);
|
|
|
if(count > 0){
|
|
@@ -261,37 +264,49 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int[] saveBatch(List<SparePartUsedDTO> sparePartUsedDTOList) {
|
|
|
- int[] array = new int[]{0,0};
|
|
|
+ public void saveBatch(List<SparePartUsedDTO> sparePartUsedDTOList) {
|
|
|
+ List<SparePartUsed> list = new ArrayList<>();
|
|
|
+ // 这里是新增常用备件
|
|
|
for(SparePartUsedDTO sparePartUsedDTO : sparePartUsedDTOList){
|
|
|
- if(saveAndCheck(sparePartUsedDTO) == null){
|
|
|
- array[1] = array[1] + 1;
|
|
|
- }else{
|
|
|
- array[0] = array[0] + 1;
|
|
|
+ if(sparePartUsedDTO.getIsSpecial() == null || sparePartUsedDTO.getIsSpecial() == 0){
|
|
|
+ SparePartUsed entity = BeanConverterUtil.copyObjectProperties(sparePartUsedDTO, SparePartUsed.class);
|
|
|
+ entity.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ entity.setCreatedTime(LocalDateTime.now());
|
|
|
+ OauthUser user = SecurityUtils.getUser();
|
|
|
+ if (user != null) {
|
|
|
+ UserInfo userInfo = user.getUserInfo();
|
|
|
+ entity.setCreatedUserId(userInfo.getUserId());
|
|
|
+ entity.setCreatedUserName(userInfo.getRealName());
|
|
|
+ }
|
|
|
+ list.add(entity);
|
|
|
}
|
|
|
}
|
|
|
- return array;
|
|
|
+ if(list.size() > 0){
|
|
|
+ mapper.insertListforComplex(list);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@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);
|
|
|
+ public synchronized void updateSpare(List<SparePartUsedDTO> records) {
|
|
|
+ for(SparePartUsedDTO sparePartUsedDTO : records){
|
|
|
+ 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());
|
|
|
+ super.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
|
|
@@ -299,6 +314,30 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
return mapper.selectSparePartUsedListBySbId(sbId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void saveInitialized(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.setStatus(SparePartUsedStatusEnum.IN_USE.getValue());
|
|
|
+ //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());
|
|
|
+ super.saveModelByDTO(model);
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
LocalDate localDate = LocalDate.now();
|
|
|
int year = localDate.getYear();
|