|
@@ -2,14 +2,16 @@ package com.platform.service.sqarepartmanage.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.github.pagehelper.PageHelper;
|
|
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.model.UserInfo;
|
|
import com.platform.common.util.*;
|
|
import com.platform.common.util.*;
|
|
import com.platform.dao.bean.MyVOPage;
|
|
import com.platform.dao.bean.MyVOPage;
|
|
import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
|
|
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.sqarepartmanage.SparePartUsed;
|
|
import com.platform.dao.entity.store.SpareStore;
|
|
import com.platform.dao.entity.store.SpareStore;
|
|
import com.platform.dao.enums.SparePartUsedStatusEnum;
|
|
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.sqarepartmanage.SparePartUsedMapper;
|
|
import com.platform.dao.mapper.store.SpareStoreMapper;
|
|
import com.platform.dao.mapper.store.SpareStoreMapper;
|
|
import com.platform.dao.mapper.store.SpareStoreSecondMapper;
|
|
import com.platform.dao.mapper.store.SpareStoreSecondMapper;
|
|
@@ -41,6 +43,7 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
|
|
|
private SpareStoreSecondMapper spareStoreSecondMapper;
|
|
private SpareStoreSecondMapper spareStoreSecondMapper;
|
|
private SpareStoreMapper spareStoreMapper;
|
|
private SpareStoreMapper spareStoreMapper;
|
|
|
|
+ private SparePartInfoMapper sparePartInfoMapper;
|
|
@Override
|
|
@Override
|
|
public int batchDelete(List<String> ids) {
|
|
public int batchDelete(List<String> ids) {
|
|
ids.forEach(id -> {
|
|
ids.forEach(id -> {
|
|
@@ -67,17 +70,57 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public SparePartUsed saveModelByDTO(SparePartUsedDTO model) {
|
|
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());
|
|
model.setStatus(SparePartUsedStatusEnum.IN_USE.getValue());
|
|
SparePartUsed sparePartUsed = super.saveModelByDTO(model);
|
|
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;
|
|
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();
|
|
UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
|
|
|
for(SparePartUsedDTO sparePartUsedDTO:models ){
|
|
for(SparePartUsedDTO sparePartUsedDTO:models ){
|
|
- setCreateUserInfo(sparePartUsedDTO);
|
|
|
|
|
|
+ setCreateUserInfo(sparePartUsedDTO);
|
|
sparePartUsedDTO.setId(IdGeneratorUtils.getObjectId());
|
|
sparePartUsedDTO.setId(IdGeneratorUtils.getObjectId());
|
|
list.add(BeanConverterUtil.copyObjectProperties(sparePartUsedDTO, getEntityClass()));
|
|
list.add(BeanConverterUtil.copyObjectProperties(sparePartUsedDTO, getEntityClass()));
|
|
/*// 更新库存信息 该部分功能,放在领用单模块
|
|
/*// 更新库存信息 该部分功能,放在领用单模块
|
|
@@ -217,6 +260,45 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
return mapper.selectVOList(sparePartUsedDTO);
|
|
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) {
|
|
public static void main(String[] args) {
|
|
LocalDate localDate = LocalDate.now();
|
|
LocalDate localDate = LocalDate.now();
|
|
int year = localDate.getYear();
|
|
int year = localDate.getYear();
|