CheckDetailService.java
4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.huaheng.pc.check.checkDetail.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.check.checkHeader.domain.CheckHeader;
import com.huaheng.pc.check.checkHeader.service.CheckHeaderService;
import com.huaheng.pc.check.checkingRegister.domain.CheckingRegister;
import com.huaheng.pc.check.checkingRegister.service.CheckingRegisterService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.check.checkDetail.mapper.CheckDetailMapper;
import com.huaheng.pc.check.checkDetail.domain.CheckDetail;
import org.springframework.transaction.annotation.Transactional;
@Service
public class CheckDetailService extends ServiceImpl<CheckDetailMapper, CheckDetail> {
@Resource
private CheckHeaderService checkHeaderService;
@Resource
private CheckingRegisterService checkingRegisterService;
@Resource
private ReceiptDetailService receiptDetailService;
/**
* 质检完成
* @param id 质检明细id
* @return AjaxResult
*/
@Transactional
public AjaxResult complete(Integer id){
LambdaQueryWrapper<CheckingRegister> checkingRegisterLambda = Wrappers.lambdaQuery();
checkingRegisterLambda.eq(CheckingRegister::getCheckDetailId, id);
List<CheckingRegister> checkingRegisters = checkingRegisterService.list(checkingRegisterLambda);
int total = 0; //质检登记中的总数量
for (CheckingRegister checkingRegister: checkingRegisters){
total += checkingRegister.getQty();
}
//更新传入明细id为完成质检状态
CheckDetail checkDetail = this.getById(id);
if ( checkDetail.getQty().compareTo(BigDecimal.valueOf(total)) != 0){
return AjaxResult.error("质检登记中总数量不等于质检明细中数量,不能完成质检");
}
checkDetail.setCheckBy(ShiroUtils.getLoginName());
checkDetail.setCheckAt(new Date());
checkDetail.setStatus((QuantityConstant.CHECK_STATUS_COMPLETED).toString());
checkDetail.setLastUpdated(new Date());
checkDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
if (!this.updateById(checkDetail)){
throw new ServiceException("更新质检明细表失败");
}
LambdaQueryWrapper<CheckDetail> lambda = Wrappers.lambdaQuery();
lambda.eq(CheckDetail::getCheckHeaderId, checkDetail.getCheckHeaderId());
List<CheckDetail> checkDetails = this.list(lambda);
//判断头表下所有明细是否全部完成
boolean result = false;
for (CheckDetail checkDetail1 : checkDetails){
if ((QuantityConstant.CHECK_STATUS_COMPLETED).toString().equals(checkDetail1.getStatus())){
result = true;
} else {
result = false;
}
}
if (result){
CheckHeader checkHeader = new CheckHeader();
checkHeader.setId(checkDetail.getCheckHeaderId());
checkHeader.setStatus((QuantityConstant.CHECK_STATUS_COMPLETED).toString());
if ( !checkHeaderService.updateById(checkHeader)){
throw new ServiceException("质检头表更新失败");
}
//更新入库单明细状态
ReceiptDetail receiptDetail = receiptDetailService.queryflow(receiptDetailService.getById(checkDetail.getReceiptDetailId()));
if (!receiptDetailService.updateById(receiptDetail)){
throw new ServiceException("入库单明细更新失败");
}
//更新头表状态
receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
}
return AjaxResult.success("质检完成");
}
}