|
@@ -1,6 +1,5 @@
|
|
|
package com.jeeplus.psimanage.loss.service;
|
|
package com.jeeplus.psimanage.loss.service;
|
|
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -21,7 +20,6 @@ import com.jeeplus.psimanage.loss.service.dto.PsiLossExportDto;
|
|
|
import com.jeeplus.psimanage.oss.service.dto.WorkAttachmentDto;
|
|
import com.jeeplus.psimanage.oss.service.dto.WorkAttachmentDto;
|
|
|
import com.jeeplus.psimanage.psiWareHouse.domain.PsiWareHouseDetailed;
|
|
import com.jeeplus.psimanage.psiWareHouse.domain.PsiWareHouseDetailed;
|
|
|
import com.jeeplus.psimanage.psiWareHouse.mapper.PsiWareHouseDetailedMapper;
|
|
import com.jeeplus.psimanage.psiWareHouse.mapper.PsiWareHouseDetailedMapper;
|
|
|
-import com.jeeplus.psimanage.psiWareHouse.mapper.PsiWareHouseSummaryMapper;
|
|
|
|
|
import com.jeeplus.psimanage.purchase.service.PsiMaterialService;
|
|
import com.jeeplus.psimanage.purchase.service.PsiMaterialService;
|
|
|
import com.jeeplus.psimanage.serialNumTpl.service.PsiSerialnumTplService;
|
|
import com.jeeplus.psimanage.serialNumTpl.service.PsiSerialnumTplService;
|
|
|
import com.jeeplus.sys.feign.IRoleApi;
|
|
import com.jeeplus.sys.feign.IRoleApi;
|
|
@@ -58,9 +56,6 @@ public class PsiLossService {
|
|
|
private PsiMaterialService psiMaterialService;
|
|
private PsiMaterialService psiMaterialService;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
- private PsiWareHouseSummaryMapper summaryMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
private PsiWareHouseDetailedMapper psiWareHouseDetailedMapper;
|
|
private PsiWareHouseDetailedMapper psiWareHouseDetailedMapper;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
@@ -95,9 +90,6 @@ public class PsiLossService {
|
|
|
|
|
|
|
|
public String add(PsiLossDto dto, UserDTO userDTO) throws Exception {
|
|
public String add(PsiLossDto dto, UserDTO userDTO) throws Exception {
|
|
|
validateDetailInfos(dto.getDetailInfos());
|
|
validateDetailInfos(dto.getDetailInfos());
|
|
|
- PsiLossDetailed detail = dto.getDetailInfos().get(0);
|
|
|
|
|
- prepareDetail(detail, userDTO);
|
|
|
|
|
- fillStockInfo(detail);
|
|
|
|
|
|
|
|
|
|
String id = UUID.randomUUID().toString().replace("-", "");
|
|
String id = UUID.randomUUID().toString().replace("-", "");
|
|
|
PsiLossBasic info = new PsiLossBasic();
|
|
PsiLossBasic info = new PsiLossBasic();
|
|
@@ -112,17 +104,23 @@ public class PsiLossService {
|
|
|
info.setDelFlag(0);
|
|
info.setDelFlag(0);
|
|
|
basicMapper.insert(info);
|
|
basicMapper.insert(info);
|
|
|
|
|
|
|
|
- detail.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
|
- detail.setBasicId(id);
|
|
|
|
|
- detailedMapper.insert(detail);
|
|
|
|
|
- saveDetailFiles(detail, userDTO);
|
|
|
|
|
|
|
+ for (PsiLossDetailed detail : dto.getDetailInfos()) {
|
|
|
|
|
+ prepareDetail(detail, userDTO);
|
|
|
|
|
+ fillStockInfo(detail);
|
|
|
|
|
+ detail.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
|
+ detail.setBasicId(id);
|
|
|
|
|
+ detailedMapper.insert(detail);
|
|
|
|
|
+ saveDetailFiles(detail, userDTO);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(dto.getFiles())) {
|
|
if (CollectionUtils.isNotEmpty(dto.getFiles())) {
|
|
|
psiMaterialService.saveFiles(dto.getFiles(), userDTO, id);
|
|
psiMaterialService.saveFiles(dto.getFiles(), userDTO, id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (isApproved(info.getStatus())) {
|
|
if (isApproved(info.getStatus())) {
|
|
|
- deductInventory(detail);
|
|
|
|
|
|
|
+ for (PsiLossDetailed detail : dto.getDetailInfos()) {
|
|
|
|
|
+ deductInventory(detail);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return id;
|
|
return id;
|
|
|
}
|
|
}
|
|
@@ -144,13 +142,10 @@ public class PsiLossService {
|
|
|
|
|
|
|
|
List<String> dbIds = detailedMapper.getIdByBasicId(dto.getId());
|
|
List<String> dbIds = detailedMapper.getIdByBasicId(dto.getId());
|
|
|
List<String> liveIds = new ArrayList<>();
|
|
List<String> liveIds = new ArrayList<>();
|
|
|
- PsiLossDetailed detail = dto.getDetailInfos().get(0);
|
|
|
|
|
- prepareDetail(detail, userDTO);
|
|
|
|
|
- fillStockInfo(detail);
|
|
|
|
|
- detail.setBasicId(dto.getId());
|
|
|
|
|
-
|
|
|
|
|
- if (StringUtils.isNotBlank(detail.getId())) {
|
|
|
|
|
- liveIds.add(detail.getId());
|
|
|
|
|
|
|
+ for (PsiLossDetailed detail : dto.getDetailInfos()) {
|
|
|
|
|
+ if (StringUtils.isNotBlank(detail.getId())) {
|
|
|
|
|
+ liveIds.add(detail.getId());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(dbIds)) {
|
|
if (CollectionUtils.isNotEmpty(dbIds)) {
|
|
|
dbIds.stream()
|
|
dbIds.stream()
|
|
@@ -161,22 +156,29 @@ public class PsiLossService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (StringUtils.isBlank(detail.getId()) || detailedMapper.selectById(detail.getId()) == null) {
|
|
|
|
|
- detail.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
|
- detail.setCreateById(userDTO.getId());
|
|
|
|
|
- detail.setCreateTime(new Date());
|
|
|
|
|
- detail.setDelFlag(0);
|
|
|
|
|
- detailedMapper.insert(detail);
|
|
|
|
|
- saveDetailFiles(detail, userDTO);
|
|
|
|
|
- } else {
|
|
|
|
|
- detailedMapper.updateById(detail);
|
|
|
|
|
- psiMaterialService.updateFiles(detail.getFileInfoLost(), userDTO, detail.getId());
|
|
|
|
|
|
|
+ for (PsiLossDetailed detail : dto.getDetailInfos()) {
|
|
|
|
|
+ prepareDetail(detail, userDTO);
|
|
|
|
|
+ fillStockInfo(detail);
|
|
|
|
|
+ detail.setBasicId(dto.getId());
|
|
|
|
|
+ if (StringUtils.isBlank(detail.getId()) || detailedMapper.selectById(detail.getId()) == null) {
|
|
|
|
|
+ detail.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
|
+ detail.setCreateById(userDTO.getId());
|
|
|
|
|
+ detail.setCreateTime(new Date());
|
|
|
|
|
+ detail.setDelFlag(0);
|
|
|
|
|
+ detailedMapper.insert(detail);
|
|
|
|
|
+ saveDetailFiles(detail, userDTO);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detailedMapper.updateById(detail);
|
|
|
|
|
+ psiMaterialService.updateFiles(detail.getFileInfoLost(), userDTO, detail.getId());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
psiMaterialService.updateFiles(dto.getFiles(), userDTO, dto.getId());
|
|
psiMaterialService.updateFiles(dto.getFiles(), userDTO, dto.getId());
|
|
|
|
|
|
|
|
if (!isApproved(oldInfo.getStatus()) && isApproved(info.getStatus())) {
|
|
if (!isApproved(oldInfo.getStatus()) && isApproved(info.getStatus())) {
|
|
|
- deductInventory(detail);
|
|
|
|
|
|
|
+ for (PsiLossDetailed detail : dto.getDetailInfos()) {
|
|
|
|
|
+ deductInventory(detail);
|
|
|
|
|
+ }
|
|
|
//通知发起人
|
|
//通知发起人
|
|
|
List<UserDTO> notifiedPartyUsers = new ArrayList<>();
|
|
List<UserDTO> notifiedPartyUsers = new ArrayList<>();
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
@@ -217,7 +219,7 @@ public class PsiLossService {
|
|
|
List<PsiLossDetailed> detailList = detailedMapper.getByBasicId(id);
|
|
List<PsiLossDetailed> detailList = detailedMapper.getByBasicId(id);
|
|
|
if (CollectionUtils.isNotEmpty(detailList)) {
|
|
if (CollectionUtils.isNotEmpty(detailList)) {
|
|
|
detailList.forEach(detail -> {
|
|
detailList.forEach(detail -> {
|
|
|
- detail.setSurplusNumber(formatNumber(getAvailableBottleCount(detail.getGoodsName(), getCollectTypeId(detail))));
|
|
|
|
|
|
|
+ detail.setSurplusNumber(formatNumber(getAvailableBottleCount(detail)));
|
|
|
List<WorkAttachmentDto> fileList = detailedMapper.getByAttachmentId(detail.getId());
|
|
List<WorkAttachmentDto> fileList = detailedMapper.getByAttachmentId(detail.getId());
|
|
|
if (CollectionUtils.isNotEmpty(fileList)) {
|
|
if (CollectionUtils.isNotEmpty(fileList)) {
|
|
|
fileList.forEach(file -> file.setCreateBy(SpringUtil.getBean(IUserApi.class).getById(file.getBy())));
|
|
fileList.forEach(file -> file.setCreateBy(SpringUtil.getBean(IUserApi.class).getById(file.getBy())));
|
|
@@ -300,21 +302,27 @@ public class PsiLossService {
|
|
|
if (CollectionUtils.isEmpty(detailInfos)) {
|
|
if (CollectionUtils.isEmpty(detailInfos)) {
|
|
|
throw new RuntimeException("报损明细不能为空");
|
|
throw new RuntimeException("报损明细不能为空");
|
|
|
}
|
|
}
|
|
|
- if (detailInfos.size() != 1) {
|
|
|
|
|
- throw new RuntimeException("报损单只能保存一条明细");
|
|
|
|
|
- }
|
|
|
|
|
- PsiLossDetailed detail = detailInfos.get(0);
|
|
|
|
|
- if (StringUtils.isBlank(detail.getRecipientAgentId())) {
|
|
|
|
|
- throw new RuntimeException("报损人不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (StringUtils.isBlank(getCollectTypeId(detail))) {
|
|
|
|
|
- throw new RuntimeException("报损类型不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (StringUtils.isBlank(detail.getGoodsName())) {
|
|
|
|
|
- throw new RuntimeException("物品名称不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (StringUtils.isBlank(detail.getLossNumber())) {
|
|
|
|
|
- throw new RuntimeException("报损数量不能为空");
|
|
|
|
|
|
|
+ for (int i = 0; i < detailInfos.size(); i++) {
|
|
|
|
|
+ PsiLossDetailed detail = detailInfos.get(i);
|
|
|
|
|
+ String lineNo = String.valueOf(i + 1);
|
|
|
|
|
+ if (StringUtils.isBlank(detail.getRecipientAgentId())) {
|
|
|
|
|
+ throw new RuntimeException("报损明细第" + lineNo + "行报损人不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(getCollectTypeId(detail))) {
|
|
|
|
|
+ throw new RuntimeException("报损明细第" + lineNo + "行报损类型不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(detail.getGoodsName())) {
|
|
|
|
|
+ throw new RuntimeException("报损明细第" + lineNo + "行物品名称不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(detail.getInventoryId())) {
|
|
|
|
|
+ throw new RuntimeException("报损明细第" + lineNo + "行请选择报损库存批次");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(detail.getLossNumber())) {
|
|
|
|
|
+ throw new RuntimeException("报损明细第" + lineNo + "行报损数量不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(detail.getLossReason())) {
|
|
|
|
|
+ throw new RuntimeException("报损明细第" + lineNo + "行报损原因不能为空");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -337,59 +345,40 @@ public class PsiLossService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void fillStockInfo(PsiLossDetailed detail) {
|
|
private void fillStockInfo(PsiLossDetailed detail) {
|
|
|
- detail.setSurplusNumber(formatNumber(getAvailableBottleCount(detail.getGoodsName(), getCollectTypeId(detail))));
|
|
|
|
|
|
|
+ detail.setSurplusNumber(formatNumber(getAvailableBottleCount(detail)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void deductInventory(PsiLossDetailed detail) {
|
|
private void deductInventory(PsiLossDetailed detail) {
|
|
|
double lossNumber = parseDouble(detail.getLossNumber());
|
|
double lossNumber = parseDouble(detail.getLossNumber());
|
|
|
- double available = getAvailableBottleCount(detail.getGoodsName(), getCollectTypeId(detail));
|
|
|
|
|
|
|
+ PsiWareHouseDetailed inventory = getInventory(detail.getInventoryId());
|
|
|
|
|
+ double spec = parseSpec(inventory.getSpec());
|
|
|
|
|
+ double available = round(parseDouble(inventory.getCurrentInventory()) * spec);
|
|
|
if (lossNumber - available > 0.001D) {
|
|
if (lossNumber - available > 0.001D) {
|
|
|
- throw new RuntimeException("报损数量不能大于当前库存数量");
|
|
|
|
|
- }
|
|
|
|
|
- List<PsiWareHouseDetailed> updateList = batchCalculation(detail);
|
|
|
|
|
- if (CollUtil.isNotEmpty(updateList)) {
|
|
|
|
|
- psiWareHouseDetailedMapper.updateBatchById(updateList);
|
|
|
|
|
|
|
+ throw new RuntimeException("报损数量不能大于当前批次库存数量");
|
|
|
}
|
|
}
|
|
|
|
|
+ PsiWareHouseDetailed update = new PsiWareHouseDetailed();
|
|
|
|
|
+ update.setId(inventory.getId());
|
|
|
|
|
+ update.setCurrentInventory(formatNumber(round((available - lossNumber) / spec)));
|
|
|
|
|
+ psiWareHouseDetailedMapper.updateBatchById(Collections.singletonList(update));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private List<PsiWareHouseDetailed> batchCalculation(PsiLossDetailed detail) {
|
|
|
|
|
- List<PsiWareHouseDetailed> inventoryList = summaryMapper.getInfoByProduceDateDesc(detail.getGoodsName(), getCollectTypeId(detail));
|
|
|
|
|
- List<PsiWareHouseDetailed> updateList = new ArrayList<>();
|
|
|
|
|
- double pending = parseDouble(detail.getLossNumber());
|
|
|
|
|
- for (PsiWareHouseDetailed inventory : inventoryList) {
|
|
|
|
|
- if (pending <= 0.001D) {
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- double currentBox = parseDouble(inventory.getCurrentInventory());
|
|
|
|
|
- double spec = parseSpec(inventory.getSpec());
|
|
|
|
|
- double totalUnit = round(currentBox * spec);
|
|
|
|
|
- if (totalUnit <= 0.001D) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- PsiWareHouseDetailed update = new PsiWareHouseDetailed();
|
|
|
|
|
- update.setId(inventory.getId());
|
|
|
|
|
- if (totalUnit >= pending) {
|
|
|
|
|
- update.setCurrentInventory(formatNumber(round((totalUnit - pending) / spec)));
|
|
|
|
|
- pending = 0D;
|
|
|
|
|
- } else {
|
|
|
|
|
- update.setCurrentInventory("0");
|
|
|
|
|
- pending = round(pending - totalUnit);
|
|
|
|
|
- }
|
|
|
|
|
- updateList.add(update);
|
|
|
|
|
|
|
+ private double getAvailableBottleCount(PsiLossDetailed detail) {
|
|
|
|
|
+ if (detail == null || StringUtils.isBlank(detail.getInventoryId())) {
|
|
|
|
|
+ return 0D;
|
|
|
}
|
|
}
|
|
|
- return updateList;
|
|
|
|
|
|
|
+ PsiWareHouseDetailed inventory = getInventory(detail.getInventoryId());
|
|
|
|
|
+ return round(parseDouble(inventory.getCurrentInventory()) * parseSpec(inventory.getSpec()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private double getAvailableBottleCount(String goodsName, String collectTypeId) {
|
|
|
|
|
- if (StringUtils.isBlank(goodsName) || StringUtils.isBlank(collectTypeId)) {
|
|
|
|
|
- return 0D;
|
|
|
|
|
|
|
+ private PsiWareHouseDetailed getInventory(String inventoryId) {
|
|
|
|
|
+ if (StringUtils.isBlank(inventoryId)) {
|
|
|
|
|
+ throw new RuntimeException("请选择报损库存批次");
|
|
|
}
|
|
}
|
|
|
- List<PsiWareHouseDetailed> inventoryList = summaryMapper.getInfoByProduceDateDesc(goodsName, collectTypeId);
|
|
|
|
|
- double total = 0D;
|
|
|
|
|
- for (PsiWareHouseDetailed inventory : inventoryList) {
|
|
|
|
|
- total += parseDouble(inventory.getCurrentInventory()) * parseSpec(inventory.getSpec());
|
|
|
|
|
|
|
+ PsiWareHouseDetailed inventory = psiWareHouseDetailedMapper.selectById(inventoryId);
|
|
|
|
|
+ if (inventory == null || !"0".equals(String.valueOf(inventory.getDelFlag()))) {
|
|
|
|
|
+ throw new RuntimeException("报损库存批次不存在");
|
|
|
}
|
|
}
|
|
|
- return round(total);
|
|
|
|
|
|
|
+ return inventory;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private String getCollectTypeId(PsiLossDetailed detail) {
|
|
private String getCollectTypeId(PsiLossDetailed detail) {
|
|
@@ -444,12 +433,13 @@ public class PsiLossService {
|
|
|
recordList.forEach(record -> {
|
|
recordList.forEach(record -> {
|
|
|
PsiLossExportDto exportDto = new PsiLossExportDto();
|
|
PsiLossExportDto exportDto = new PsiLossExportDto();
|
|
|
exportDto.setLossNo(item.getLossNo());
|
|
exportDto.setLossNo(item.getLossNo());
|
|
|
- exportDto.setRecipientAgent(record.getRecipientAgent());
|
|
|
|
|
- exportDto.setRecipientOffice(record.getRecipientOffice());
|
|
|
|
|
|
|
+ //exportDto.setRecipientAgent(record.getRecipientAgent());
|
|
|
|
|
+ //exportDto.setRecipientOffice(record.getRecipientOffice());
|
|
|
exportDto.setCollectType(record.getCollectType());
|
|
exportDto.setCollectType(record.getCollectType());
|
|
|
- exportDto.setGoodsName(record.getGoodsName());
|
|
|
|
|
- exportDto.setProduceDate(record.getProduceDate() == null ? "暂无生产日期" : dateFormat.format(record.getProduceDate()));
|
|
|
|
|
|
|
+ //exportDto.setGoodsName(record.getGoodsName());
|
|
|
|
|
+ //exportDto.setProduceDate(record.getProduceDate() == null ? "暂无生产日期" : dateFormat.format(record.getProduceDate()));
|
|
|
exportDto.setLossNumber(record.getLossNumber());
|
|
exportDto.setLossNumber(record.getLossNumber());
|
|
|
|
|
+ exportDto.setLossReason(record.getLossReason());
|
|
|
result.add(exportDto);
|
|
result.add(exportDto);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|