|
@@ -1,19 +1,34 @@
|
|
|
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.model.UserInfo;
|
|
|
+import com.platform.common.util.BeanConverterUtil;
|
|
|
+import com.platform.common.util.BigDecimalUtil;
|
|
|
+import com.platform.common.util.IdGeneratorUtils;
|
|
|
+import com.platform.common.util.SecurityUtils;
|
|
|
import com.platform.dao.bean.MyVOPage;
|
|
|
import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
|
|
|
import com.platform.dao.dto.store.OutStoreFormDTO;
|
|
|
import com.platform.dao.entity.sqarepartmanage.SparePartUsed;
|
|
|
+import com.platform.dao.entity.store.SpareStore;
|
|
|
+import com.platform.dao.enums.DelFlagEnum;
|
|
|
import com.platform.dao.enums.SparePartUsedStatusEnum;
|
|
|
import com.platform.dao.mapper.sqarepartmanage.SparePartUsedMapper;
|
|
|
+import com.platform.dao.mapper.store.SpareStoreMapper;
|
|
|
import com.platform.dao.mapper.store.SpareStoreSecondMapper;
|
|
|
import com.platform.dao.vo.spare.SparePartUsedVO;
|
|
|
import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
import com.platform.service.sqarepartmanage.SparePartUsedService;
|
|
|
+import com.platform.service.store.SpareStoreService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import tk.mybatis.mapper.weekend.Weekend;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -27,7 +42,7 @@ import java.util.List;
|
|
|
public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMapper, SparePartUsed, SparePartUsedDTO> implements SparePartUsedService {
|
|
|
|
|
|
private SpareStoreSecondMapper spareStoreSecondMapper;
|
|
|
-
|
|
|
+ private SpareStoreMapper spareStoreMapper;
|
|
|
@Override
|
|
|
public int batchDelete(List<String> ids) {
|
|
|
ids.forEach(id -> {
|
|
@@ -36,6 +51,22 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void updateModelByDTO(SparePartUsedDTO model) {
|
|
|
+ SparePartUsedVO sparePartUsed = mapper.selectById(model.getId());
|
|
|
+ // 更新库存信息
|
|
|
+ Weekend<SpareStore> spareStoreWeekend = new Weekend<>(SpareStore.class);
|
|
|
+ spareStoreWeekend.weekendCriteria().andEqualTo(SpareStore::getSpareId, sparePartUsed.getSpareId())
|
|
|
+ .andEqualTo(SpareStore::getStoreId, sparePartUsed.getStoreId());
|
|
|
+ SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
|
|
|
+ if (ObjectUtil.isNotNull(spareStore)) {
|
|
|
+ spareStore.setNum(BigDecimalUtil.sub(BigDecimalUtil.add(spareStore.getNum(), sparePartUsed.getNum()), model.getNum()));
|
|
|
+ spareStoreMapper.updateByPrimaryKeySelective(spareStore);
|
|
|
+ }
|
|
|
+ // 还原出库数量
|
|
|
+ super.modModelByDTO(model);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public SparePartUsed saveModelByDTO(SparePartUsedDTO model) {
|
|
|
model.setStatus(SparePartUsedStatusEnum.IN_USE.getValue());
|
|
@@ -49,11 +80,6 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
return sparePartUsed;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void updateModelByDTO(OutStoreFormDTO model) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 刪除需要更新二級庫的庫存
|
|
|
*
|
|
@@ -63,14 +89,16 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
@Override
|
|
|
public boolean cascadingDeleteByKey(String id) {
|
|
|
|
|
|
- /*SparePartUsed sparePartUsed = mapper.selectById(id);
|
|
|
- SpareStoreSecond second = spareStoreSecondMapper.selectByPrimaryKey(sparePartUsed.getStoreId());
|
|
|
- if (ObjectUtil.isNotNull(second)) {
|
|
|
- second.setTotalNum(second.getTotalNum()+1);
|
|
|
- second.setUsedNum(second.getUsedNum() - 1);
|
|
|
- spareStoreSecondMapper.updateByPrimaryKey(second);
|
|
|
- }*/
|
|
|
- // 刪除出库单
|
|
|
+ SparePartUsedVO sparePartUsed = mapper.selectById(id);
|
|
|
+ // 更新库存信息
|
|
|
+ Weekend<SpareStore> spareStoreWeekend = new Weekend<>(SpareStore.class);
|
|
|
+ spareStoreWeekend.weekendCriteria().andEqualTo(SpareStore::getSpareId, sparePartUsed.getSpareId())
|
|
|
+ .andEqualTo(SpareStore::getStoreId, sparePartUsed.getStoreId());
|
|
|
+ SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
|
|
|
+ if (ObjectUtil.isNotNull(spareStore)) {
|
|
|
+ spareStore.setNum(BigDecimalUtil.add(spareStore.getNum(), sparePartUsed.getNum()));
|
|
|
+ spareStoreMapper.updateByPrimaryKey(spareStore);
|
|
|
+ }
|
|
|
int result = mapper.deleteByPrimaryKey(id);
|
|
|
return true;
|
|
|
}
|
|
@@ -92,6 +120,37 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
return new MyVOPage<>(mapper.statisticsByGroupBySpare(model));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void saveModelListByDTO(List<SparePartUsedDTO> models) {
|
|
|
+ if (CollectionUtils.isEmpty(models)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<SparePartUsed> list = new ArrayList<>(10);
|
|
|
+ // 入库单详情
|
|
|
+ UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
+
|
|
|
+ for(SparePartUsedDTO sparePartUsedDTO:models ){
|
|
|
+ setCreateUserInfo(sparePartUsedDTO);
|
|
|
+ sparePartUsedDTO.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ list.add(BeanConverterUtil.copyObjectProperties(sparePartUsedDTO, getEntityClass()));
|
|
|
+ // 更新库存信息
|
|
|
+ Weekend<SpareStore> spareStoreWeekend = new Weekend<>(SpareStore.class);
|
|
|
+ spareStoreWeekend.weekendCriteria().andEqualTo(SpareStore::getSpareId, sparePartUsedDTO.getSpareId())
|
|
|
+ .andEqualTo(SpareStore::getStoreId, sparePartUsedDTO.getStoreId());
|
|
|
+ SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
|
|
|
+ if (ObjectUtil.isNull(spareStore)) {
|
|
|
+ throw new BusinessException("仓库找不到备件,请重新选择");
|
|
|
+ }
|
|
|
+ // 重新计算商品库存价格
|
|
|
+ spareStore.setUpdateTime(LocalDateTime.now());
|
|
|
+ spareStore.setUpdateUserId(userInfo.getUserId());
|
|
|
+ spareStore.setUpdateUserName(userInfo.getRealName());
|
|
|
+ spareStore.setNum(BigDecimalUtil.sub(spareStore.getNum(), sparePartUsedDTO.getNum()));
|
|
|
+ spareStoreMapper.updateByPrimaryKeySelective(spareStore);
|
|
|
+ }
|
|
|
+ mapper.insertListforComplex(list);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<SparePartUsedVO> selectSparePartUsedListByRepairId(String repairId) {
|
|
|
return mapper.selectSparePartUsedListByRepairId(repairId);
|