新购代码优化
This commit is contained in:
parent
6d85856207
commit
8b627bf00b
|
|
@ -68,7 +68,9 @@ public class BpmPurchaseBindController extends BaseController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 二维码生成下载
|
||||
* 二维码生成下载一体操作
|
||||
* @param response
|
||||
* @param purchaseDto
|
||||
*/
|
||||
@PostMapping(value = "/downloadQrCode")
|
||||
@RequiresPermissions("purchase:bpmPurchaseInfo:query")
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public class BpmPurchaseAcceptServiceImpl implements BpmPurchaseAcceptService {
|
|||
|
||||
/**
|
||||
* 查询采购单
|
||||
*
|
||||
* @param purchaseDto
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -47,6 +48,7 @@ public class BpmPurchaseAcceptServiceImpl implements BpmPurchaseAcceptService {
|
|||
|
||||
/**
|
||||
* 查询采购单详情
|
||||
*
|
||||
* @param purchaseDto
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -57,129 +59,164 @@ public class BpmPurchaseAcceptServiceImpl implements BpmPurchaseAcceptService {
|
|||
|
||||
/**
|
||||
* 批量验收合格
|
||||
*
|
||||
* @param purchaseDto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult updateTask(PurchaseDto purchaseDto) {
|
||||
//只有任务状态为待验收时,方可批量验收合格
|
||||
if (purchaseDto.getId() != null) {
|
||||
String[] split = purchaseDto.getId().split(",");
|
||||
List<Integer> taskIdList = new ArrayList<>();
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
taskIdList.add(Integer.parseInt(split[i]));
|
||||
}
|
||||
purchaseDto.setTaskIds(taskIdList);
|
||||
List<Integer> statusList = mapper.selectStatus(purchaseDto);
|
||||
if (CollectionUtils.isNotEmpty(statusList)) {
|
||||
for (Integer status : statusList) {
|
||||
if (!status.equals(Constants.PENDING_ACCEPTANCE)) {
|
||||
return AjaxResult.warn("存在非待验收任务,无法批量验收合格");
|
||||
}
|
||||
}
|
||||
}
|
||||
int result = 0;
|
||||
try {
|
||||
//根据任务id查询详情表
|
||||
for (Integer taskId : taskIdList) {
|
||||
purchaseDto.setId(String.valueOf(taskId));
|
||||
List<PurchaseAcceptVo> details = mapper.getDetails(purchaseDto);
|
||||
//根据查询的采购数量,更新验收数量
|
||||
for (PurchaseAcceptVo purchaseVo : details) {
|
||||
result += mapper.updateCheckNum(purchaseVo.getPurchaseId(), purchaseVo.getPurchaseNum());
|
||||
if ("0".equals(purchaseVo.getManageType())) {
|
||||
result += bpmPurchaseInfoMapper.updateStatusById(Constants.PENDING_BINDING, Integer.parseInt(purchaseVo.getPurchaseId()));
|
||||
} else if ("1".equals(purchaseVo.getManageType())) {
|
||||
result += bpmPurchaseInfoMapper.updateStatusById(Constants.PENDING_INVENTORY, Integer.parseInt(purchaseVo.getPurchaseId()));
|
||||
}
|
||||
}
|
||||
// 提取 PurchaseId
|
||||
List<String> idList = details.stream().map(PurchaseAcceptVo::getPurchaseId).collect(Collectors.toList());
|
||||
//根据详情id查询详情状态,更新任务表状态
|
||||
List<PurchaseAcceptVo> idStatusList = mapper.select(idList);
|
||||
// 使用流 API 按 id 分组,并提取 status
|
||||
Map<Integer, List<Integer>> groupedByIdStatus = idStatusList.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
PurchaseAcceptVo::getId,
|
||||
Collectors.mapping(PurchaseAcceptVo::getStatus, Collectors.toList())
|
||||
));
|
||||
for (Map.Entry<Integer, List<Integer>> entry : groupedByIdStatus.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
List<Integer> statusList1 = entry.getValue();
|
||||
if (statusList1.contains(Constants.PENDING_BINDING)) {
|
||||
//如果详情状态包含待绑定,则外部任务状态为待绑定
|
||||
result += bpmTaskMapper.updateStatusById(Constants.PENDING_BINDING, id);
|
||||
} else if (!statusList1.contains(Constants.PENDING_BINDING) && statusList1.contains(Constants.PENDING_INVENTORY)) {
|
||||
result += bpmTaskMapper.updateStatusById(Constants.PENDING_INVENTORY, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("批量验收合格成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//外层验收合格
|
||||
return processBatchAcceptById(purchaseDto);
|
||||
} else if (purchaseDto.getPurchaseId() != null) {
|
||||
String[] split = purchaseDto.getPurchaseId().split(",");
|
||||
purchaseDto.setStatus(Constants.PENDING_BINDING);
|
||||
int result = 0;
|
||||
try {
|
||||
//根据采购单id查询详情id
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
purchaseDto.setPurchaseId(split[i]);
|
||||
List<PurchaseAcceptVo> details = mapper.getDetails(purchaseDto);
|
||||
if (CollectionUtils.isNotEmpty(details)) {
|
||||
if ("0".equals(details.get(0).getManageType())) {
|
||||
bpmPurchaseInfoMapper.updateStatusById(Constants.PENDING_BINDING, Integer.parseInt(split[i]));
|
||||
} else if ("1".equals(details.get(0).getManageType())) {
|
||||
bpmPurchaseInfoMapper.updateStatusById(Constants.PENDING_INVENTORY, Integer.parseInt(split[i]));
|
||||
}
|
||||
}
|
||||
result = mapper.updateCheckNum(details.get(0).getPurchaseId(), details.get(0).getPurchaseNum());
|
||||
}
|
||||
//根据详情id查询详情状态,更新任务表状态
|
||||
List<PurchaseAcceptVo> statusList = mapper.select(Arrays.asList(split));
|
||||
// 使用流 API 按 id 分组,并提取 status
|
||||
Map<Integer, List<Integer>> groupedByIdStatus = statusList.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
PurchaseAcceptVo::getId,
|
||||
Collectors.mapping(PurchaseAcceptVo::getStatus, Collectors.toList())
|
||||
));
|
||||
result = getResult(result, groupedByIdStatus);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("批量验收合格成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//内层验收合格
|
||||
return processBatchAcceptByPurchaseId(purchaseDto);
|
||||
}
|
||||
return AjaxResult.error("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量合格方法抽取
|
||||
* @param result
|
||||
* @param groupedByIdStatus
|
||||
* 外层验收合格
|
||||
* @param purchaseDto
|
||||
* @return
|
||||
*/
|
||||
private int getResult(int result, Map<Integer, List<Integer>> groupedByIdStatus) {
|
||||
for (Map.Entry<Integer, List<Integer>> entry : groupedByIdStatus.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
List<Integer> statusList1 = entry.getValue();
|
||||
if (statusList1.contains(Constants.PENDING_BINDING)) {
|
||||
//如果详情状态包含待绑定,则外部任务状态为待绑定
|
||||
result += bpmTaskMapper.updateStatusById(Constants.PENDING_BINDING, id);
|
||||
} else if (!statusList1.contains(Constants.PENDING_BINDING) && statusList1.contains(Constants.PENDING_INVENTORY)) {
|
||||
result += bpmTaskMapper.updateStatusById(Constants.PENDING_INVENTORY, id);
|
||||
private AjaxResult processBatchAcceptById(PurchaseDto purchaseDto) {
|
||||
List<Integer> taskIdList = parseIds(purchaseDto.getId());
|
||||
purchaseDto.setTaskIds(taskIdList);
|
||||
List<Integer> statusList = mapper.selectStatus(purchaseDto);
|
||||
if (!areAllStatusesPendingAcceptance(statusList)) {
|
||||
return AjaxResult.warn("存在非待验收任务,无法批量验收合格");
|
||||
}
|
||||
int result = 0;
|
||||
try {
|
||||
for (Integer taskId : taskIdList) {
|
||||
purchaseDto.setId(String.valueOf(taskId));
|
||||
List<PurchaseAcceptVo> details = mapper.getDetails(purchaseDto);
|
||||
result += updateCheckNumAndStatus(details);
|
||||
result += updateTaskStatus(details);
|
||||
}
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("批量验收合格成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return AjaxResult.error("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 内层验收合格
|
||||
* @param purchaseDto
|
||||
* @return
|
||||
*/
|
||||
private AjaxResult processBatchAcceptByPurchaseId(PurchaseDto purchaseDto) {
|
||||
List<String> purchaseIdList = Arrays.asList(purchaseDto.getPurchaseId().split(","));
|
||||
purchaseDto.setStatus(Constants.PENDING_BINDING);
|
||||
int result = 0;
|
||||
try {
|
||||
for (String purchaseId : purchaseIdList) {
|
||||
purchaseDto.setPurchaseId(purchaseId);
|
||||
List<PurchaseAcceptVo> details = mapper.getDetails(purchaseDto);
|
||||
if (CollectionUtils.isNotEmpty(details)) {
|
||||
//状态改变
|
||||
result += updatePurchaseInfoStatus(details.get(0), Integer.parseInt(purchaseId));
|
||||
//验收数量同步,当前默认全部验收
|
||||
result += mapper.updateCheckNum(details.get(0).getPurchaseId(), details.get(0).getPurchaseNum());
|
||||
}
|
||||
}
|
||||
List<PurchaseAcceptVo> statusList = mapper.select(purchaseIdList);
|
||||
result += updateTaskStatus(statusList);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("批量验收合格成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return AjaxResult.error("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转换为Integer列表
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
private List<Integer> parseIds(String ids) {
|
||||
return Arrays.stream(ids.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否全部待验收
|
||||
* @param statusList
|
||||
* @return
|
||||
*/
|
||||
private boolean areAllStatusesPendingAcceptance(List<Integer> statusList) {
|
||||
return CollectionUtils.isNotEmpty(statusList) && statusList.stream().allMatch(status -> status.equals(Constants.PENDING_ACCEPTANCE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 外层验收状态改变
|
||||
* @param details
|
||||
* @return
|
||||
*/
|
||||
private int updateCheckNumAndStatus(List<PurchaseAcceptVo> details) {
|
||||
return details.stream()
|
||||
.mapToInt(detail -> {
|
||||
int result = mapper.updateCheckNum(detail.getPurchaseId(), detail.getPurchaseNum());
|
||||
if ("0".equals(detail.getManageType())) {
|
||||
result += bpmPurchaseInfoMapper.updateStatusById(Constants.PENDING_BINDING, Integer.parseInt(detail.getPurchaseId()));
|
||||
} else if ("1".equals(detail.getManageType())) {
|
||||
result += bpmPurchaseInfoMapper.updateStatusById(Constants.PENDING_INVENTORY, Integer.parseInt(detail.getPurchaseId()));
|
||||
}
|
||||
return result;
|
||||
}).sum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务表状态改变
|
||||
* @param details
|
||||
* @return
|
||||
*/
|
||||
private int updateTaskStatus(List<PurchaseAcceptVo> details) {
|
||||
Map<Integer, List<Integer>> groupedByIdStatus = details.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
PurchaseAcceptVo::getId,
|
||||
Collectors.mapping(PurchaseAcceptVo::getStatus, Collectors.toList())
|
||||
));
|
||||
|
||||
return groupedByIdStatus.entrySet().stream()
|
||||
.mapToInt(entry -> {
|
||||
Integer id = entry.getKey();
|
||||
List<Integer> statusList = entry.getValue();
|
||||
if (statusList.contains(Constants.PENDING_BINDING)) {
|
||||
return bpmTaskMapper.updateStatusById(Constants.PENDING_BINDING, id);
|
||||
} else if (!statusList.contains(Constants.PENDING_BINDING) && statusList.contains(Constants.PENDING_INVENTORY)) {
|
||||
return bpmTaskMapper.updateStatusById(Constants.PENDING_INVENTORY, id);
|
||||
}
|
||||
return 0;
|
||||
}).sum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ManageType的值,调整状态
|
||||
* @param detail
|
||||
* @param purchaseId
|
||||
* @return
|
||||
*/
|
||||
private int updatePurchaseInfoStatus(PurchaseAcceptVo detail, int purchaseId) {
|
||||
if ("0".equals(detail.getManageType())) {
|
||||
return bpmPurchaseInfoMapper.updateStatusById(Constants.PENDING_BINDING, purchaseId);
|
||||
} else if ("1".equals(detail.getManageType())) {
|
||||
return bpmPurchaseInfoMapper.updateStatusById(Constants.PENDING_INVENTORY, purchaseId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二级批量审批不合格
|
||||
*
|
||||
* @param purchaseDto
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -214,6 +251,7 @@ public class BpmPurchaseAcceptServiceImpl implements BpmPurchaseAcceptService {
|
|||
|
||||
/**
|
||||
* 批量不合格方法抽取
|
||||
*
|
||||
* @param result
|
||||
* @param groupedByIdStatus
|
||||
* @return
|
||||
|
|
|
|||
|
|
@ -60,106 +60,138 @@ public class BpmPurchaseStorageServiceImpl implements BpmPurchaseStorageService
|
|||
@Override
|
||||
public AjaxResult warehouse(PurchaseDto purchaseDto) {
|
||||
if (purchaseDto.getId() != null) {
|
||||
String[] split = purchaseDto.getId().split(",");
|
||||
List<Integer> taskIdList = new ArrayList<>();
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
taskIdList.add(Integer.parseInt(split[i]));
|
||||
}
|
||||
System.out.println(taskIdList);
|
||||
purchaseDto.setTaskIds(taskIdList);
|
||||
int result = 0;
|
||||
try {
|
||||
//根据任务id查询详情表
|
||||
for (Integer taskId : taskIdList) {
|
||||
purchaseDto.setId(String.valueOf(taskId));
|
||||
List<PurchaseAcceptVo> details = mapper.getDetails(purchaseDto);
|
||||
//根据查询的采购数量,更新验收数量
|
||||
for (PurchaseAcceptVo purchaseVo : details) {
|
||||
result += mapper.updateNum(purchaseVo.getPurchaseId(), purchaseVo.getBindNum());
|
||||
result += bpmPurchaseInfoMapper.updateStatusById(Constants.PURCHASE_PASSED, Integer.parseInt(purchaseVo.getPurchaseId()));
|
||||
if ("0".equals(purchaseVo.getManageType())) {
|
||||
result += bpmPurchaseStorageMapper.insertmaMachine(purchaseVo);
|
||||
} else if ("1".equals(purchaseVo.getManageType())) {
|
||||
result += bpmPurchaseStorageMapper.updateStorageNum(purchaseVo.getBindNum(), purchaseVo.getTypeId());
|
||||
}
|
||||
}
|
||||
// 提取 PurchaseId
|
||||
List<String> idList = details.stream().map(PurchaseAcceptVo::getPurchaseId).collect(Collectors.toList());
|
||||
//根据详情id查询详情状态,更新任务表状态
|
||||
List<PurchaseAcceptVo> idStatusList = mapper.select(idList);
|
||||
// 使用流 API 按 id 分组,并提取 status
|
||||
Map<Integer, List<Integer>> groupedByIdStatus = idStatusList.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
PurchaseAcceptVo::getId,
|
||||
Collectors.mapping(PurchaseAcceptVo::getStatus, Collectors.toList())
|
||||
));
|
||||
for (Map.Entry<Integer, List<Integer>> entry : groupedByIdStatus.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
List<Integer> statusList1 = entry.getValue();
|
||||
if (statusList1.contains(Constants.PENDING_INVENTORY)) {
|
||||
//如果详情状态包含待绑定,则外部任务状态为待绑定
|
||||
result += bpmTaskMapper.updateStatusById(Constants.PENDING_INVENTORY, id);
|
||||
} else if (!statusList1.contains(Constants.PENDING_INVENTORY) && statusList1.contains(Constants.PURCHASE_PASSED)) {
|
||||
result += bpmTaskMapper.updateStatusById(Constants.PURCHASE_PASSED, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("批量入库成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//外层入库
|
||||
return processByTaskIds(purchaseDto);
|
||||
} else if (purchaseDto.getPurchaseId() != null) {
|
||||
String[] split = purchaseDto.getPurchaseId().split(",");
|
||||
purchaseDto.setStatus(Constants.PURCHASE_PASSED);
|
||||
int result = 0;
|
||||
try {
|
||||
//根据采购单id查询详情id
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
purchaseDto.setPurchaseId(split[i]);
|
||||
List<PurchaseAcceptVo> details = mapper.getDetails(purchaseDto);
|
||||
if (CollectionUtils.isNotEmpty(details)) {
|
||||
result += bpmPurchaseInfoMapper.updateStatusById(Constants.PURCHASE_PASSED, Integer.parseInt(details.get(0).getPurchaseId()));
|
||||
if ("0".equals(details.get(0).getManageType())) {
|
||||
result += bpmPurchaseStorageMapper.insertmaMachine(details.get(0));
|
||||
} else if ("1".equals(details.get(0).getManageType())) {
|
||||
result += bpmPurchaseStorageMapper.updateStorageNum(details.get(0).getBindNum(), details.get(0).getTypeId());
|
||||
}
|
||||
}
|
||||
result = mapper.updateNum(details.get(0).getPurchaseId(), details.get(0).getBindNum());
|
||||
}
|
||||
//根据详情id查询详情状态,更新任务表状态
|
||||
List<PurchaseAcceptVo> statusList = mapper.select(Arrays.asList(split));
|
||||
// 使用流 API 按 id 分组,并提取 status
|
||||
Map<Integer, List<Integer>> groupedByIdStatus = statusList.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
PurchaseAcceptVo::getId,
|
||||
Collectors.mapping(PurchaseAcceptVo::getStatus, Collectors.toList())
|
||||
));
|
||||
result = getResult(result, groupedByIdStatus);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("批量入库成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//内层入库
|
||||
return processByPurchaseIds(purchaseDto);
|
||||
}
|
||||
return AjaxResult.error("操作失败");
|
||||
}
|
||||
|
||||
private int getResult(int result, Map<Integer, List<Integer>> groupedByIdStatus) {
|
||||
for (Map.Entry<Integer, List<Integer>> entry : groupedByIdStatus.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
List<Integer> statusList1 = entry.getValue();
|
||||
if (statusList1.contains(Constants.PENDING_INVENTORY)) {
|
||||
//如果详情状态包含待绑定,则外部任务状态为待绑定
|
||||
result += bpmTaskMapper.updateStatusById(Constants.PENDING_INVENTORY, id);
|
||||
} else if (!statusList1.contains(Constants.PENDING_INVENTORY) && statusList1.contains(Constants.PURCHASE_PASSED)) {
|
||||
result += bpmTaskMapper.updateStatusById(Constants.PURCHASE_PASSED, id);
|
||||
/**
|
||||
* 外层入库
|
||||
* @param purchaseDto
|
||||
* @return
|
||||
*/
|
||||
private AjaxResult processByTaskIds(PurchaseDto purchaseDto) {
|
||||
List<Integer> taskIdList = parseIds(purchaseDto.getId());
|
||||
purchaseDto.setTaskIds(taskIdList);
|
||||
int result = 0;
|
||||
try {
|
||||
for (Integer taskId : taskIdList) {
|
||||
purchaseDto.setId(String.valueOf(taskId));
|
||||
List<PurchaseAcceptVo> details = mapper.getDetails(purchaseDto);
|
||||
result += updateDetailsAndStatus(details);
|
||||
result += updateTaskStatus(details);
|
||||
}
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("批量入库成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return AjaxResult.error("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 内层入库
|
||||
* @param purchaseDto
|
||||
* @return
|
||||
*/
|
||||
private AjaxResult processByPurchaseIds(PurchaseDto purchaseDto) {
|
||||
List<String> purchaseIdList = Arrays.asList(purchaseDto.getPurchaseId().split(","));
|
||||
purchaseDto.setStatus(Constants.PURCHASE_PASSED);
|
||||
int result = 0;
|
||||
try {
|
||||
for (String purchaseId : purchaseIdList) {
|
||||
purchaseDto.setPurchaseId(purchaseId);
|
||||
List<PurchaseAcceptVo> details = mapper.getDetails(purchaseDto);
|
||||
if (CollectionUtils.isNotEmpty(details)) {
|
||||
result += updatePurchaseInfoAndDetails(details.get(0), Integer.parseInt(purchaseId));
|
||||
}
|
||||
}
|
||||
List<PurchaseAcceptVo> statusList = mapper.select(purchaseIdList);
|
||||
result += updateTaskStatus(statusList);
|
||||
|
||||
if (result > 0) {
|
||||
return AjaxResult.success("批量入库成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return AjaxResult.error("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转换为Integer集合
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
private List<Integer> parseIds(String ids) {
|
||||
return Arrays.stream(ids.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新采购单和采购明细状态
|
||||
* @param details
|
||||
* @return
|
||||
*/
|
||||
private int updateDetailsAndStatus(List<PurchaseAcceptVo> details) {
|
||||
return details.stream()
|
||||
.mapToInt(detail -> {
|
||||
int result = mapper.updateNum(detail.getPurchaseId(), detail.getBindNum());
|
||||
result += bpmPurchaseInfoMapper.updateStatusById(Constants.PURCHASE_PASSED, Integer.parseInt(detail.getPurchaseId()));
|
||||
if ("0".equals(detail.getManageType())) {
|
||||
result += bpmPurchaseStorageMapper.insertmaMachine(detail);
|
||||
} else if ("1".equals(detail.getManageType())) {
|
||||
result += bpmPurchaseStorageMapper.updateStorageNum(detail.getBindNum(), detail.getTypeId());
|
||||
}
|
||||
return result;
|
||||
}).sum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务状态
|
||||
* @param details
|
||||
* @return
|
||||
*/
|
||||
private int updateTaskStatus(List<PurchaseAcceptVo> details) {
|
||||
Map<Integer, List<Integer>> groupedByIdStatus = details.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
PurchaseAcceptVo::getId,
|
||||
Collectors.mapping(PurchaseAcceptVo::getStatus, Collectors.toList())
|
||||
));
|
||||
|
||||
return groupedByIdStatus.entrySet().stream()
|
||||
.mapToInt(entry -> {
|
||||
Integer id = entry.getKey();
|
||||
List<Integer> statusList = entry.getValue();
|
||||
if (statusList.contains(Constants.PENDING_INVENTORY)) {
|
||||
return bpmTaskMapper.updateStatusById(Constants.PENDING_INVENTORY, id);
|
||||
} else if (!statusList.contains(Constants.PENDING_INVENTORY) && statusList.contains(Constants.PURCHASE_PASSED)) {
|
||||
return bpmTaskMapper.updateStatusById(Constants.PURCHASE_PASSED, id);
|
||||
}
|
||||
return 0;
|
||||
}).sum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新采购单和采购明细
|
||||
* @param detail
|
||||
* @param purchaseId
|
||||
* @return
|
||||
*/
|
||||
private int updatePurchaseInfoAndDetails(PurchaseAcceptVo detail, int purchaseId) {
|
||||
int result = bpmPurchaseInfoMapper.updateStatusById(Constants.PURCHASE_PASSED, purchaseId);
|
||||
if ("0".equals(detail.getManageType())) {
|
||||
result += bpmPurchaseStorageMapper.insertmaMachine(detail);
|
||||
} else if ("1".equals(detail.getManageType())) {
|
||||
result += bpmPurchaseStorageMapper.updateStorageNum(detail.getBindNum(), detail.getTypeId());
|
||||
}
|
||||
return result + mapper.updateNum(detail.getPurchaseId(), detail.getBindNum());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue