|
@@ -18,6 +18,7 @@ import com.platform.dao.mapper.store.*;
|
|
|
import com.platform.dao.util.MessageTemplateUtil;
|
|
|
import com.platform.dao.vo.query.store.*;
|
|
|
import com.platform.service.event.WorkplaceBacklogEvent;
|
|
|
+import com.platform.service.store.InStoreFormService;
|
|
|
import com.platform.service.store.OutStoreFormService;
|
|
|
import com.platform.service.store.StoreService;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -53,6 +54,8 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
|
|
|
private SparePickFormMapper sparePickFormMapper;
|
|
|
private SparePickDetailMapper sparePickDetailMapper;
|
|
|
+ private InStoreFormServiceImpl inStoreFormServiceImpl;
|
|
|
+
|
|
|
@Override
|
|
|
public int batchDelete(List<String> ids) {
|
|
|
//Weekend<OutStoreForm> weekend = new Weekend<>(OutStoreForm.class);
|
|
@@ -80,9 +83,9 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
public OutStoreFormVO getDetail(Object id) {
|
|
|
OutStoreForm outStoreForm = this.getModelById(id);
|
|
|
OutStoreFormVO outStoreFormVO = new OutStoreFormVO();
|
|
|
- BeanConverterUtil.copyObjectProperties(outStoreForm,outStoreFormVO);
|
|
|
+ BeanConverterUtil.copyObjectProperties(outStoreForm, outStoreFormVO);
|
|
|
// 详情列表
|
|
|
- if(StringUtils.isNotBlank(outStoreForm.getStoreId())){
|
|
|
+ if (StringUtils.isNotBlank(outStoreForm.getStoreId())) {
|
|
|
Store store = storeService.getModelById(outStoreForm.getStoreId());
|
|
|
outStoreFormVO.setStoreName(store.getName());
|
|
|
}
|
|
@@ -107,6 +110,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
|
|
|
/**
|
|
|
* 只有未出库状态才可以删除,不需要回滚
|
|
|
+ *
|
|
|
* @param id :
|
|
|
* @return
|
|
|
*/
|
|
@@ -114,7 +118,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean cascadingDeleteByKey(String id) {
|
|
|
OutStoreForm form = mapper.selectByPrimaryKey(id);
|
|
|
- if( form.getStatus()!=null && (form.getStatus().intValue() == OutStoreStatusEnum.EXECUTING.getValue())){
|
|
|
+ if (form.getStatus() != null && (form.getStatus().intValue() == OutStoreStatusEnum.EXECUTING.getValue())) {
|
|
|
throw new BusinessException("已出库的不可以删除,出库单id:" + form.getId());
|
|
|
}
|
|
|
// 刪除出库单
|
|
@@ -122,7 +126,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
|
|
|
// 刪除详情,更新详情涉及的库存
|
|
|
- if(result == 1){
|
|
|
+ if (result == 1) {
|
|
|
Weekend<OutStoreDetail> detailWeekend = new Weekend<>(OutStoreDetail.class);
|
|
|
detailWeekend.weekendCriteria().andEqualTo(OutStoreDetail::getOutId, id);
|
|
|
List<OutStoreDetail> detailList = detailMapper.selectByExample(detailWeekend);
|
|
@@ -159,24 +163,24 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
BigDecimal totalPrice = new BigDecimal(0);
|
|
|
|
|
|
// 判断备件是否在该仓库里面,出库单已经勾选了仓库。这个不允许了,pc和移动端都不允许
|
|
|
- for(OutStoreDetailDTO detail:detailList) {
|
|
|
+ for (OutStoreDetailDTO detail : detailList) {
|
|
|
SpareStore spareStore = new SpareStore();
|
|
|
- if(StringUtils.isNotBlank(model.getStoreId())){
|
|
|
+ if (StringUtils.isNotBlank(model.getStoreId())) {
|
|
|
spareStore.setStoreId(model.getStoreId());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
spareStore.setStoreId(detail.getStoreId());
|
|
|
}
|
|
|
spareStore.setSpareId(detail.getSpareId());
|
|
|
List<SpareStore> spareStoreList = spareStoreMapper.select(spareStore);
|
|
|
- if(spareStoreList == null || spareStoreList.size() == 0){
|
|
|
+ if (spareStoreList == null || spareStoreList.size() == 0) {
|
|
|
throw new BusinessException("该仓库中没有此备件,请检查");
|
|
|
}
|
|
|
}
|
|
|
// 插
|
|
|
- for(OutStoreDetailDTO detail:detailList) {
|
|
|
+ for (OutStoreDetailDTO detail : detailList) {
|
|
|
detail.setUserInfo(userInfo);
|
|
|
detail.setOutId(outStoreForm.getId());
|
|
|
- if(StringUtils.isNotBlank(model.getStoreId())){
|
|
|
+ if (StringUtils.isNotBlank(model.getStoreId())) {
|
|
|
detail.setStoreId(model.getStoreId());
|
|
|
}
|
|
|
// detail.setStoreId(outStoreForm.getStoreId());
|
|
@@ -190,7 +194,8 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
storeDetail.setId(IdGeneratorUtils.getObjectId());
|
|
|
detailMapper.insertSelective(storeDetail);
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
+ ;
|
|
|
outStoreForm.setTotalPrice(totalPrice);
|
|
|
mapper.updateByPrimaryKey(outStoreForm);
|
|
|
updateStore(outStoreForm.getId());
|
|
@@ -208,7 +213,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
public void updateStore(String outStoreFormId) {
|
|
|
|
|
|
OutStoreForm outStoreForm = this.getModelById(outStoreFormId);
|
|
|
- outStoreForm.setStatus(OutStoreStatusEnum.NOT_EXECUTE.getValue());
|
|
|
+ outStoreForm.setStatus(OutStoreStatusEnum.EXECUTING.getValue());
|
|
|
mapper.updateByPrimaryKey(outStoreForm);
|
|
|
|
|
|
Weekend<OutStoreDetail> detailWeekend = new Weekend<>(OutStoreDetail.class);
|
|
@@ -217,13 +222,12 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
|
|
|
// 更新领用单状态
|
|
|
- if( outStoreForm.getPickId() != null && outStoreForm.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue()) ){
|
|
|
+ if (outStoreForm.getPickId() != null && outStoreForm.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())) {
|
|
|
SparePickForm sparePickForm = sparePickFormMapper.selectByPrimaryKey(outStoreForm.getPickId());
|
|
|
sparePickForm.setStatus(SparePickFormStatusEnum.FINISHED.getValue());
|
|
|
sparePickFormMapper.updateByPrimaryKeySelective(sparePickForm);
|
|
|
-
|
|
|
// 发送通知给领用人
|
|
|
- SpringContextHolder.publishEvent(new WorkplaceBacklogEvent( WorkplaceBacklogTypeEnum.SPARE_PICK.getValue(), WorkplaceBacklogDetailTypeEnum.SPARE_PICK.getValue(),
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.SPARE_PICK.getValue(), WorkplaceBacklogDetailTypeEnum.SPARE_PICK.getValue(),
|
|
|
sparePickForm.getId(), MessageTemplateUtil.getSparePickFinish(sparePickForm.getId()),
|
|
|
sparePickForm.getId(), ListUtils.newArrayList(sparePickForm.getPickUserId())));
|
|
|
}
|
|
@@ -237,7 +241,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
.andEqualTo(SpareStore::getStoreId, storeDetail.getStoreId());
|
|
|
SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
|
|
|
if (ObjectUtil.isNull(spareStore)) {
|
|
|
- throw new BusinessException("找不到该备件仓库!,备件ID:"+storeDetail.getSpareId()+",仓库ID:"+storeDetail.getStoreId());
|
|
|
+ throw new BusinessException("找不到该备件仓库!,备件ID:" + storeDetail.getSpareId() + ",仓库ID:" + storeDetail.getStoreId());
|
|
|
} else {
|
|
|
BigDecimal rest = spareStore.getNum().subtract(storeDetail.getNum());
|
|
|
if (rest.compareTo(new BigDecimal(0)) < 0) {
|
|
@@ -265,13 +269,13 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
|
|
|
// 获取领用单详情
|
|
|
SparePickForm sparePickForm = null;
|
|
|
- if(model.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())){
|
|
|
+ if (model.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())) {
|
|
|
sparePickForm = sparePickFormMapper.selectByPrimaryKey(model.getPickId());
|
|
|
}
|
|
|
BigDecimal totalPrice = new BigDecimal(0);
|
|
|
|
|
|
// 插
|
|
|
- for(OutStoreDetailDTO detail:detailList) {
|
|
|
+ for (OutStoreDetailDTO detail : detailList) {
|
|
|
model.setCreatedUserId("1");
|
|
|
detail.setOutId(outStoreForm.getId());
|
|
|
detail.setStoreId(outStoreForm.getStoreId());
|
|
@@ -284,7 +288,8 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
storeDetail.setId(IdGeneratorUtils.getObjectId());
|
|
|
detailMapper.insertSelective(storeDetail);
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
+ ;
|
|
|
// 更新库存
|
|
|
updateStore(outStoreForm.getId());
|
|
|
}
|
|
@@ -302,16 +307,16 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
List<OutStoreDetailDTO> detailList = model.getDetailList();
|
|
|
|
|
|
// 判断备件是否在该仓库里面,出库单已经勾选了仓库。这个不允许了,pc和移动端都不允许
|
|
|
- for(OutStoreDetailDTO detail:detailList) {
|
|
|
+ for (OutStoreDetailDTO detail : detailList) {
|
|
|
SpareStore spareStore = new SpareStore();
|
|
|
- if(StringUtils.isNotBlank(model.getStoreId())){
|
|
|
+ if (StringUtils.isNotBlank(model.getStoreId())) {
|
|
|
spareStore.setStoreId(model.getStoreId());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
spareStore.setStoreId(detail.getStoreId());
|
|
|
}
|
|
|
spareStore.setSpareId(detail.getSpareId());
|
|
|
List<SpareStore> spareStoreList = spareStoreMapper.select(spareStore);
|
|
|
- if(spareStoreList == null || spareStoreList.size() == 0){
|
|
|
+ if (spareStoreList == null || spareStoreList.size() == 0) {
|
|
|
throw new BusinessException("该仓库中没有此备件,请检查");
|
|
|
}
|
|
|
}
|
|
@@ -327,19 +332,19 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
List<OutStoreDetail> addDetailList = new ArrayList<OutStoreDetail>();
|
|
|
// 详情
|
|
|
SparePickForm sparePickForm = null;
|
|
|
- if(model.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())){
|
|
|
+ if (model.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())) {
|
|
|
sparePickForm = sparePickFormMapper.selectByPrimaryKey(model.getPickId());
|
|
|
}
|
|
|
SparePickForm finalSparePickForm = sparePickForm;
|
|
|
|
|
|
BigDecimal totalPrice = new BigDecimal(0);
|
|
|
// 新增
|
|
|
- for(OutStoreDetailDTO detail:detailList) {
|
|
|
+ for (OutStoreDetailDTO detail : detailList) {
|
|
|
OutStoreDetail realDetail = detailMapper.selectByPrimaryKey(detail.getId());
|
|
|
- if(ObjectUtil.isNull(realDetail)){
|
|
|
+ if (ObjectUtil.isNull(realDetail)) {
|
|
|
detail.setUserInfo(userInfo);
|
|
|
detail.setOutId(model.getId());
|
|
|
- if(StringUtils.isNotBlank(model.getStoreId())){
|
|
|
+ if (StringUtils.isNotBlank(model.getStoreId())) {
|
|
|
detail.setStoreId(model.getStoreId());
|
|
|
}
|
|
|
//detail.setStoreId(model.getStoreId());
|
|
@@ -350,19 +355,20 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
BeanConverterUtil.copyObjectProperties(detail, storeDetail);
|
|
|
storeDetail.setId(IdGeneratorUtils.getObjectId());
|
|
|
addDetailList.add(storeDetail);
|
|
|
- }else{// 修改数量的
|
|
|
+ } else {// 修改数量的
|
|
|
detail.setTotalPrice(detail.getNum().multiply(detail.getPrice()));
|
|
|
totalPrice = totalPrice.add(detail.getTotalPrice());
|
|
|
OutStoreDetail storeDetail = new OutStoreDetail();
|
|
|
BeanConverterUtil.copyObjectProperties(detail, storeDetail);
|
|
|
updateDetailList.add(storeDetail);
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
+ ;
|
|
|
|
|
|
- if(!CollectionUtils.isEmpty(addDetailList)){
|
|
|
+ if (!CollectionUtils.isEmpty(addDetailList)) {
|
|
|
detailMapper.insertListforComplex(addDetailList);
|
|
|
}
|
|
|
- if(!CollectionUtils.isEmpty(updateDetailList)){
|
|
|
+ if (!CollectionUtils.isEmpty(updateDetailList)) {
|
|
|
detailMapper.updateBatch(updateDetailList);
|
|
|
}
|
|
|
// 更新
|
|
@@ -394,22 +400,22 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
model.setDelFlag(false);
|
|
|
model.setUserInfo(userInfo);
|
|
|
|
|
|
- Store store = storeService.getModelById(sparePickFormDTO.getStoreId());
|
|
|
+ Store store = storeService.getModelById(sparePickFormDTO.getStoreId());
|
|
|
model.setCreatedUserId(store.getUserId());
|
|
|
model.setType(OutStoreTypeEnum.CHUKU_LINGYONG.getValue());
|
|
|
model.setStatus(OutStoreStatusEnum.NOT_EXECUTE.getValue());
|
|
|
model.setRemark(sparePickFormDTO.getRemark());
|
|
|
OutStoreForm form = super.saveModelByDTO(model);
|
|
|
List<OutStoreDetail> detailList = new ArrayList<OutStoreDetail>();
|
|
|
- pickDetailList.forEach(pickDetail->{
|
|
|
+ pickDetailList.forEach(pickDetail -> {
|
|
|
OutStoreDetail detail = new OutStoreDetail();
|
|
|
detail.setId(IdGeneratorUtils.getObjectId());
|
|
|
detail.setCreatedTime(pickDetail.getCreatedTime());
|
|
|
detail.setNum(pickDetail.getNum());
|
|
|
detail.setPrice(pickDetail.getPrice());
|
|
|
- if(pickDetail.getTotalPrice() == null){
|
|
|
- detail.setTotalPrice(BigDecimalUtil.mul(pickDetail.getNum(),pickDetail.getPrice()));
|
|
|
- }else{
|
|
|
+ if (pickDetail.getTotalPrice() == null) {
|
|
|
+ detail.setTotalPrice(BigDecimalUtil.mul(pickDetail.getNum(), pickDetail.getPrice()));
|
|
|
+ } else {
|
|
|
detail.setTotalPrice(pickDetail.getTotalPrice());
|
|
|
}
|
|
|
detail.setSpareId(pickDetail.getSpareId());
|
|
@@ -420,7 +426,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
});
|
|
|
detailMapper.insertListforComplex(detailList);
|
|
|
|
|
|
- SpringContextHolder.publishEvent(new WorkplaceBacklogEvent( WorkplaceBacklogTypeEnum.OUT_STORE.getValue(), WorkplaceBacklogDetailTypeEnum.OUT_STORE_FOR_PICK.getValue(),
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.OUT_STORE.getValue(), WorkplaceBacklogDetailTypeEnum.OUT_STORE_FOR_PICK.getValue(),
|
|
|
form.getId(), MessageTemplateUtil.getOutStoreForSparePick(form.getId()),
|
|
|
form.getId(), ListUtils.newArrayList(store.getUserId())));
|
|
|
return form;
|
|
@@ -436,7 +442,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
public void saveModelBySbOil(List<SbOil> sbOils) {
|
|
|
UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
List<OutStoreDetail> detailList = new ArrayList<OutStoreDetail>();
|
|
|
- for(SbOil oil:sbOils){
|
|
|
+ for (SbOil oil : sbOils) {
|
|
|
// 出库单
|
|
|
Weekend<OutStoreForm> weekend = new Weekend<>(OutStoreForm.class);
|
|
|
weekend.weekendCriteria().andIsNotNull(OutStoreForm::getId);
|
|
@@ -445,11 +451,11 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
model.setPickId(oil.getId());
|
|
|
model.setStoreId(oil.getStoreId());
|
|
|
SpareStore spareStore = spareStoreMapper.selectByPrimaryKey(oil.getSpareStoreId());
|
|
|
- if(spareStore == null){
|
|
|
+ if (spareStore == null) {
|
|
|
throw new BusinessException("找不到仓库备件,spareStoreId:" + oil.getSpareStoreId());
|
|
|
}
|
|
|
model.setCreatedTime(oil.getCreatedTime());
|
|
|
- model.setTotalPrice(BigDecimalUtil.mul(spareStore.getPrice()== null?new BigDecimal(0):spareStore.getPrice(), oil.getRealOil()));
|
|
|
+ model.setTotalPrice(BigDecimalUtil.mul(spareStore.getPrice() == null ? new BigDecimal(0) : spareStore.getPrice(), oil.getRealOil()));
|
|
|
model.setOutNo(IdGeneratorUtils.getOutStoreNo(++count));
|
|
|
model.setDelFlag(false);
|
|
|
model.setUserInfo(userInfo);
|
|
@@ -483,7 +489,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
.andEqualTo(SpareStore::getStoreId, storeDetail.getStoreId());
|
|
|
SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
|
|
|
if (ObjectUtil.isNull(spareStore)) {
|
|
|
- throw new BusinessException("找不到该备件仓库!,备件ID:"+storeDetail.getSpareId()+",仓库ID:"+storeDetail.getStoreId());
|
|
|
+ throw new BusinessException("找不到该备件仓库!,备件ID:" + storeDetail.getSpareId() + ",仓库ID:" + storeDetail.getStoreId());
|
|
|
} else {
|
|
|
BigDecimal rest = spareStore.getNum().subtract(storeDetail.getNum());
|
|
|
if (rest.compareTo(new BigDecimal(0)) < 0) {
|
|
@@ -510,7 +516,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
List<OutStoreDetail> detailList = new ArrayList<OutStoreDetail>();
|
|
|
List<OutStoreForm> formList = new ArrayList<OutStoreForm>();
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
- for(StoreCheckJobVO job:jobs){
|
|
|
+ for (StoreCheckJobVO job : jobs) {
|
|
|
// 出库单
|
|
|
Weekend<OutStoreForm> weekend = new Weekend<>(OutStoreForm.class);
|
|
|
weekend.weekendCriteria().andIsNotNull(OutStoreForm::getId);
|
|
@@ -519,11 +525,11 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
model.setPickId(job.getId());
|
|
|
model.setStoreId(job.getStoreId());
|
|
|
SpareStore spareStore = spareStoreMapper.selectByPrimaryKey(job.getSpareStoreId());
|
|
|
- if(spareStore == null){
|
|
|
+ if (spareStore == null) {
|
|
|
throw new BusinessException("找不到仓库备件,spareStoreId:" + job.getSpareStoreId());
|
|
|
}
|
|
|
model.setCreatedTime(now);
|
|
|
- BigDecimal adjustNum = BigDecimalUtil.div(job.getCheckNum(),job.getRealNum());
|
|
|
+ BigDecimal adjustNum = BigDecimalUtil.div(job.getCheckNum(), job.getRealNum());
|
|
|
model.setTotalPrice(job.getProfitPrice());
|
|
|
model.setOutNo(IdGeneratorUtils.getOutStoreNo(++count));
|
|
|
model.setDelFlag(false);
|
|
@@ -549,8 +555,8 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
formList.add(form);
|
|
|
}
|
|
|
detailMapper.insertListforComplex(detailList);
|
|
|
- if(!CollectionUtils.isEmpty(formList)){
|
|
|
- for(OutStoreForm form: formList){
|
|
|
+ if (!CollectionUtils.isEmpty(formList)) {
|
|
|
+ for (OutStoreForm form : formList) {
|
|
|
updateStore(form.getId());
|
|
|
}
|
|
|
}
|
|
@@ -577,4 +583,67 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
|
|
|
}
|
|
|
});*/
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void pasteOutStore(String id) {
|
|
|
+ OutStoreForm outStoreForm = this.getModelById(id);
|
|
|
+ outStoreForm.setStatus(OutStoreStatusEnum.NOT_EXECUTE.getValue());
|
|
|
+ mapper.updateByPrimaryKey(outStoreForm);
|
|
|
+
|
|
|
+ Weekend<OutStoreDetail> detailWeekend = new Weekend<>(OutStoreDetail.class);
|
|
|
+ detailWeekend.weekendCriteria().andEqualTo(OutStoreDetail::getOutId, id);
|
|
|
+ List<OutStoreDetail> detailList = detailMapper.selectByExample(detailWeekend);
|
|
|
+ UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
+
|
|
|
+ // 更新领用单状态
|
|
|
+ if (outStoreForm.getPickId() != null && outStoreForm.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())) {
|
|
|
+ SparePickForm sparePickForm = sparePickFormMapper.selectByPrimaryKey(outStoreForm.getPickId());
|
|
|
+ sparePickForm.setStatus(SparePickFormStatusEnum.NOT_EXECUTE.getValue());
|
|
|
+ sparePickFormMapper.updateByPrimaryKeySelective(sparePickForm);
|
|
|
+ // 发送通知给领用人
|
|
|
+ SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.BACK_STORE.getValue(), WorkplaceBacklogDetailTypeEnum.BACK_STORE.getValue(),
|
|
|
+ sparePickForm.getId(), MessageTemplateUtil.getSparePickFinish(sparePickForm.getId()),
|
|
|
+ sparePickForm.getId(), ListUtils.newArrayList(sparePickForm.getPickUserId())));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (OutStoreDetail detail : detailList) {
|
|
|
+ // 更新库存信息
|
|
|
+ Weekend<SpareStore> spareStoreWeekend = new Weekend<>(SpareStore.class);
|
|
|
+ spareStoreWeekend.weekendCriteria().andEqualTo(SpareStore::getSpareId, detail.getSpareId())
|
|
|
+ .andEqualTo(SpareStore::getStoreId, detail.getStoreId());
|
|
|
+ SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
|
|
|
+ if (ObjectUtil.isNull(spareStore)) {
|
|
|
+ spareStore = new SpareStore();
|
|
|
+ spareStore.setCreatedUserId(userInfo.getUserId());
|
|
|
+ spareStore.setCreatedUserName(userInfo.getRealName());
|
|
|
+ spareStore.setCreatedTime(LocalDateTime.now());
|
|
|
+ spareStore.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ spareStore.setNum(detail.getNum());
|
|
|
+ spareStore.setSpareId(detail.getSpareId());
|
|
|
+ spareStore.setDelFlag(DelFlagEnum.NORMAL.getValue());
|
|
|
+ spareStore.setStoreId(detail.getStoreId());
|
|
|
+ spareStore.setPrice(detail.getPrice());
|
|
|
+ spareStore.setInitPrice(detail.getPrice());
|
|
|
+ spareStore.setInitPurchasePrice(detail.getPrice());
|
|
|
+ spareStoreMapper.insertSelective(spareStore);
|
|
|
+ } else {
|
|
|
+ // 重新计算商品库存价格
|
|
|
+ spareStore.setUpdateTime(LocalDateTime.now());
|
|
|
+ spareStore.setUpdateUserId(userInfo.getUserId());
|
|
|
+ spareStore.setUpdateUserName(userInfo.getRealName());
|
|
|
+ spareStore.setPrice(getNewPrice(spareStore, detail));
|
|
|
+ spareStore.setNum(BigDecimalUtil.add(spareStore.getNum(), detail.getNum()));
|
|
|
+ spareStoreMapper.updateByPrimaryKeySelective(spareStore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal getNewPrice(SpareStore spareStore, OutStoreDetail detail) {
|
|
|
+ BigDecimal totalStorePrice = BigDecimalUtil.mul(spareStore.getPrice(), spareStore.getNum());
|
|
|
+ BigDecimal totalInPrice = BigDecimalUtil.mul(detail.getPrice(), detail.getNum());
|
|
|
+ BigDecimal totalPrice = BigDecimalUtil.add(totalStorePrice, totalInPrice);
|
|
|
+ BigDecimal totalNum = BigDecimalUtil.add(spareStore.getNum(), detail.getNum());
|
|
|
+ BigDecimal price = BigDecimalUtil.div(totalPrice, totalNum);
|
|
|
+ return price;
|
|
|
+ }
|
|
|
}
|