|
|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
package com.nov.KgLowDurable.service.Impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
@ -14,8 +16,10 @@ import lombok.AllArgsConstructor; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.sql.Wrapper; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
@ -43,12 +47,18 @@ public class LdTwoInventoryRecordServiceImpl extends ServiceImpl<LdTwoInventoryR |
|
|
|
|
@Autowired |
|
|
|
|
ILdDurableFormService durableFormService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ILdErstockOutService ldErstockOutService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ILdErstockOutFromService ldErstockOutFromService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public PageInfo<LdTwoInventoryRecord> getTwoInventoryRecordList(Long consumerFormId, String transactionType, Integer pageNum, Integer pageSize) { |
|
|
|
|
|
|
|
|
|
PageHelper.startPage(pageNum,pageSize); |
|
|
|
|
PageHelper.startPage(pageNum, pageSize); |
|
|
|
|
// 查询全部
|
|
|
|
|
List<LdTwoInventoryRecord> ldTwoInventoryRecordList = twoInventoryRecordMapper.selectByConsumerFormId(consumerFormId,transactionType); |
|
|
|
|
List<LdTwoInventoryRecord> ldTwoInventoryRecordList = twoInventoryRecordMapper.selectByConsumerFormId(consumerFormId, transactionType); |
|
|
|
|
// 返回结果
|
|
|
|
|
PageInfo<LdTwoInventoryRecord> pageInfo = new PageInfo<>(ldTwoInventoryRecordList); |
|
|
|
|
return pageInfo; |
|
|
|
|
@ -57,15 +67,17 @@ public class LdTwoInventoryRecordServiceImpl extends ServiceImpl<LdTwoInventoryR |
|
|
|
|
@Override |
|
|
|
|
public boolean approve(ApproveDto approveDto) { |
|
|
|
|
LdTwoOutStorage twoOutStorage = twoOutStorageService.getById(approveDto.getTwoOutStorageId()); |
|
|
|
|
if(null == twoOutStorage){ |
|
|
|
|
throw new CustomerException("未查到二级出库单"); |
|
|
|
|
if (null == twoOutStorage) { |
|
|
|
|
// 若web的二级出库未查到,插下移动端的二级出库ld_erstock_out
|
|
|
|
|
return approveWeb(approveDto); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//更新审批状态
|
|
|
|
|
if(!approveDto.getApproveResult()){ |
|
|
|
|
if (!approveDto.getApproveResult()) { |
|
|
|
|
twoOutStorage.setStatus(BatchConstant.APPROVAL_FAILED); |
|
|
|
|
twoOutStorageService.updateById(twoOutStorage); |
|
|
|
|
return true; |
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
twoOutStorage.setStatus(BatchConstant.APPROVE); |
|
|
|
|
twoOutStorageService.updateById(twoOutStorage); |
|
|
|
|
} |
|
|
|
|
@ -73,13 +85,13 @@ public class LdTwoInventoryRecordServiceImpl extends ServiceImpl<LdTwoInventoryR |
|
|
|
|
//库存入库
|
|
|
|
|
List<LdTwoOutStorageDetail> ldTwoOutStorageDetailList = twoOutStorageDetailService.selectByTwoOutStorageId(approveDto.getTwoOutStorageId()); |
|
|
|
|
for (LdTwoOutStorageDetail twoOutStorageDetail : ldTwoOutStorageDetailList) { |
|
|
|
|
if(BatchConstant.CONSUMER.equals(twoOutStorageDetail.getType())){ |
|
|
|
|
if (BatchConstant.CONSUMER.equals(twoOutStorageDetail.getType())) { |
|
|
|
|
LdConsumerForm consumerForm = consumerFormService.getById(twoOutStorageDetail.getTwoInventoryId()); |
|
|
|
|
//计算差值
|
|
|
|
|
BigDecimal difference = consumerForm.getNum().subtract(twoOutStorageDetail.getNum()); |
|
|
|
|
consumerForm.setNum(difference); |
|
|
|
|
boolean updateConfumerForm = consumerFormService.updateById(consumerForm); |
|
|
|
|
if(!updateConfumerForm){ |
|
|
|
|
if (!updateConfumerForm) { |
|
|
|
|
throw new CustomerException("易耗品更新失败"); |
|
|
|
|
} |
|
|
|
|
//出库记录
|
|
|
|
|
@ -93,15 +105,71 @@ public class LdTwoInventoryRecordServiceImpl extends ServiceImpl<LdTwoInventoryR |
|
|
|
|
.setDepartmentId(approveDto.getDepartmentId()) |
|
|
|
|
.setDepartmentName(approveDto.getDepartmentName()); |
|
|
|
|
int insertTwoInventoryRecord = twoInventoryRecordMapper.insert(ldTwoInventoryRecord); |
|
|
|
|
if(insertTwoInventoryRecord <= 0){ |
|
|
|
|
if (insertTwoInventoryRecord <= 0) { |
|
|
|
|
throw new CustomerException("出库记录保存失败"); |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
LdDurableForm durableForm = durableFormService.getById(twoOutStorageDetail.getTwoInventoryId()); |
|
|
|
|
durableForm.setIsBorrow(BatchConstant.LEND); |
|
|
|
|
durableForm.setNum(new BigDecimal(0)); |
|
|
|
|
boolean updateDurableForm = durableFormService.updateById(durableForm); |
|
|
|
|
if(!updateDurableForm){ |
|
|
|
|
if (!updateDurableForm) { |
|
|
|
|
throw new CustomerException("耐用品更新失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean approveWeb(ApproveDto approveDto) { |
|
|
|
|
LdErstockOut ldErstockOut = ldErstockOutService.getById(approveDto.getTwoOutStorageId()); |
|
|
|
|
if (null == ldErstockOut) { |
|
|
|
|
throw new CustomerException("未查到二级出库单"); |
|
|
|
|
} |
|
|
|
|
// 更新审批状态, ld_erstock_out表出库状态status不一致。审批通过后需要改为1,驳回后需要改为2
|
|
|
|
|
if (!approveDto.getApproveResult()) { |
|
|
|
|
ldErstockOut.setStatus(BatchConstant.SUBMIT); |
|
|
|
|
ldErstockOutService.updateById(ldErstockOut); |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
ldErstockOut.setStatus(BatchConstant.TEMPORARY); |
|
|
|
|
ldErstockOutService.updateById(ldErstockOut); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<LdErstockOutForm> outFormList = ldErstockOutFromService.listByOutId(approveDto.getTwoOutStorageId()); |
|
|
|
|
for (LdErstockOutForm ldErstockOutForm : outFormList) { |
|
|
|
|
// todo 移动端的类存储的是代码(YH)还是汉字(易耗品)
|
|
|
|
|
if (BatchConstant.CONSUMER.equals(ldErstockOutForm.getType())) { |
|
|
|
|
// 获取二级库存
|
|
|
|
|
LdConsumerForm consumerForm = consumerFormService.getById(ldErstockOutForm.getStockId()); |
|
|
|
|
BigDecimal num = new BigDecimal(ldErstockOutForm.getNum()); |
|
|
|
|
//计算差值
|
|
|
|
|
BigDecimal difference = consumerForm.getNum().subtract(num); |
|
|
|
|
consumerForm.setNum(difference); |
|
|
|
|
boolean updateConfumerForm = consumerFormService.updateById(consumerForm); |
|
|
|
|
if (!updateConfumerForm) { |
|
|
|
|
throw new CustomerException("易耗品更新失败"); |
|
|
|
|
} |
|
|
|
|
//出库记录
|
|
|
|
|
LdTwoInventoryRecord ldTwoInventoryRecord = new LdTwoInventoryRecord() |
|
|
|
|
.setConsumerFormId(consumerForm.getId().longValue()) |
|
|
|
|
.setTransactionType(BatchConstant.OUT_WAREHOUSE) |
|
|
|
|
.setQuantity(num) |
|
|
|
|
.setOperatorId(approveDto.getOperatorId()) |
|
|
|
|
.setOperatorName(approveDto.getOperatorName()) |
|
|
|
|
.setOperationTime(approveDto.getOperationTime()) |
|
|
|
|
.setDepartmentId(approveDto.getDepartmentId()) |
|
|
|
|
.setDepartmentName(approveDto.getDepartmentName()); |
|
|
|
|
int insertTwoInventoryRecord = twoInventoryRecordMapper.insert(ldTwoInventoryRecord); |
|
|
|
|
if (insertTwoInventoryRecord <= 0) { |
|
|
|
|
throw new CustomerException("出库记录保存失败"); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
LdDurableForm durableForm = durableFormService.getById(ldErstockOutForm.getStockId()); |
|
|
|
|
durableForm.setIsBorrow(BatchConstant.LEND); |
|
|
|
|
durableForm.setNum(new BigDecimal(0)); |
|
|
|
|
boolean updateDurableForm = durableFormService.updateById(durableForm); |
|
|
|
|
if (!updateDurableForm) { |
|
|
|
|
throw new CustomerException("耐用品更新失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|