|
|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.jzg.commons.constants.Constants;
|
|
|
import com.jzg.commons.constants.ReturnInformation;
|
|
|
+import com.jzg.commons.core.base.StateResult;
|
|
|
import com.jzg.commons.core.page.HttpResult;
|
|
|
import com.jzg.commons.entity.dto.CostAgreementParam;
|
|
|
import com.jzg.commons.entity.dto.PtlAgreementCostAdd;
|
|
|
@@ -16,13 +17,20 @@ import com.jzg.commons.entity.po.PtlAgreementCostType;
|
|
|
import com.jzg.commons.entity.po.RuleConditionsVerify;
|
|
|
import com.jzg.commons.entity.vo.PtlAgreementCostRuleVo;
|
|
|
import com.jzg.commons.entity.vo.PtlAgreementCostVo;
|
|
|
+import com.jzg.commons.exception.SystemException;
|
|
|
import com.jzg.commons.util.ListUtils;
|
|
|
import com.jzg.organization.mapper.PtlAgreementCostMapper;
|
|
|
import com.jzg.organization.service.PtlAgreementCostRuleService;
|
|
|
import com.jzg.organization.service.PtlAgreementCostService;
|
|
|
import com.jzg.organization.service.PtlAgreementCostTypeService;
|
|
|
+import com.jzg.organization.state.CostState;
|
|
|
+import com.jzg.organization.state.UserState;
|
|
|
+import com.jzg.organization.state.listener.CostStateListener;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.statemachine.StateMachine;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@@ -44,6 +52,15 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
@Resource
|
|
|
private PtlAgreementCostMapper ptlAgreementCostMapper;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("costStateMachine")
|
|
|
+ private StateMachine<CostState.CostStateEnum, CostState.CostStateEvent> costStateMachine;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CostStateListener costStateListener;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HttpResult save(List<PtlAgreementCostAdd> costAddList) {
|
|
|
@@ -156,5 +173,56 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
|
|
|
baseMapper.update(ptlAgreementCost,new LambdaQueryWrapper<>(PtlAgreementCost.class).in(PtlAgreementCost::getId,ids));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean auditSuccess(List<String> ids) {
|
|
|
+ for (String id : ids) {
|
|
|
+ PtlAgreementCost ptlAgreementCost = baseMapper.selectById(id);
|
|
|
+ if (ObjectUtil.isNull(ptlAgreementCost)) {
|
|
|
+ throw new SystemException("该条费用不存在,请检查");
|
|
|
+ }
|
|
|
+ if (ptlAgreementCost.getApproved() == 1) {
|
|
|
+ throw new SystemException("该条费用已审核通过,请勿重复操作");
|
|
|
+ }
|
|
|
+ if (ptlAgreementCost.getApproved() == 2) {
|
|
|
+ throw new SystemException("该条费用已审核不通过,请勿重复操作");
|
|
|
+ }
|
|
|
+ if (ptlAgreementCost.getApproved() == 0) {
|
|
|
+ StateResult stateResult = costStateListener.auditSuccess(ptlAgreementCost);
|
|
|
+ if (stateResult.isResult()) {
|
|
|
+ ptlAgreementCost.setApproved(stateResult.getCurrentState());
|
|
|
+ baseMapper.updateById(ptlAgreementCost);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean auditFailed(List<String> ids, String reason) {
|
|
|
+ for (String id : ids) {
|
|
|
+ PtlAgreementCost ptlAgreementCost = baseMapper.selectById(id);
|
|
|
+ if (ObjectUtil.isNull(ptlAgreementCost)) {
|
|
|
+ throw new SystemException("该条费用不存在,请检查");
|
|
|
+ }
|
|
|
+ if (ptlAgreementCost.getApproved() == 1) {
|
|
|
+ throw new SystemException("该条费用已审核通过,请勿重复操作");
|
|
|
+ }
|
|
|
+ if (ptlAgreementCost.getApproved() == 2) {
|
|
|
+ throw new SystemException("该条费用已审核不通过,请勿重复操作");
|
|
|
+ }
|
|
|
+ if (ptlAgreementCost.getApproved() == 0) {
|
|
|
+ StateResult stateResult = costStateListener.auditFailed(ptlAgreementCost);
|
|
|
+ if (stateResult.isResult()) {
|
|
|
+ ptlAgreementCost.setApproved(stateResult.getCurrentState());
|
|
|
+ ptlAgreementCost.setReviewDescription(reason);
|
|
|
+ baseMapper.updateById(ptlAgreementCost);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|