|
@@ -0,0 +1,208 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package com.fjhx.subscribe.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.flow.entity.Flow;
|
|
|
+import com.fjhx.flow.entity.FlowParam;
|
|
|
+import com.fjhx.myapp.application.feign.IFlowApi;
|
|
|
+import com.fjhx.subscribe.entity.ApplyPurchase;
|
|
|
+import com.fjhx.subscribe.entity.ApplyPurchasedetail;
|
|
|
+import com.fjhx.subscribe.enums.ApplyPurchaseStatusEnum;
|
|
|
+import com.fjhx.subscribe.mapper.ApplyPurchaseMapper;
|
|
|
+import com.fjhx.subscribe.service.IApplyPurchaseFlowService;
|
|
|
+import com.fjhx.subscribe.service.IApplyPurchaseService;
|
|
|
+import com.fjhx.subscribe.service.IApplyPurchasedetailService;
|
|
|
+import com.fjhx.supplier.entity.Supplier;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springblade.common.utils.CodeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 申购单流程 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2022-07-26
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ApplyPurchaseFlowServiceImpl extends ServiceImpl<ApplyPurchaseMapper, ApplyPurchase> implements IApplyPurchaseFlowService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFlowApi flowApi;
|
|
|
+ @Autowired
|
|
|
+ private IUserClient userClient;
|
|
|
+ @Autowired
|
|
|
+ private IApplyPurchasedetailService iApplyPurchasedetailService;
|
|
|
+ /**
|
|
|
+ * 发起流程
|
|
|
+ * @param applyPurchase
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void start(ApplyPurchase applyPurchase) {
|
|
|
+ //状态=审批中
|
|
|
+ applyPurchase.setApproveBillState(ApplyPurchaseStatusEnum.APPLY_PURCHASE_STATUS_1.getKey());
|
|
|
+ User user = userClient.infoUser(AuthUtil.getUserIdStr());
|
|
|
+ if(StringUtils.isEmpty(applyPurchase.getApplyBillNo())){
|
|
|
+ //生成code
|
|
|
+ ApplyPurchase sCode = getOne(Wrappers.<ApplyPurchase>query().lambda().orderByDesc(ApplyPurchase::getApplyBillNo).last("limit 1"));
|
|
|
+ String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
|
|
+ String code = "PR-"+date+"-0001";
|
|
|
+ if(ObjectUtil.isEmpty(sCode)){
|
|
|
+ applyPurchase.setApplyBillNo(code);
|
|
|
+ }else{
|
|
|
+ applyPurchase.setApplyBillNo(sCode.getApplyBillNo()==null?code: CodeUtil.generateSubscribeCode(sCode.getApplyBillNo()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //发起审批
|
|
|
+ String title = user.getName() + " 在" + LocalDate.now() + "日发起了 申购单审批流程(单号" + applyPurchase.getApplyBillNo() + ")";
|
|
|
+ if (StringUtils.isBlank(applyPurchase.getId())) {
|
|
|
+ saveApplyPurchase(applyPurchase);
|
|
|
+ }else{
|
|
|
+ updateApplyPurchase(applyPurchase);
|
|
|
+ }
|
|
|
+ //发起流程
|
|
|
+ FlowParam param = setValue(title,null,null,"subscribe",null);
|
|
|
+ try {
|
|
|
+ flowApi.startFlow(param);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new ServiceException("流程异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批
|
|
|
+ * @param condition
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void examine(FlowParam condition) {
|
|
|
+ if (StringUtils.isAnyBlank(condition.getBusinessId(), condition.getProInstantsId())) {
|
|
|
+ throw new ServiceException("参数缺失");
|
|
|
+ }
|
|
|
+ //查询申购单信息
|
|
|
+ ApplyPurchase applyPurchase = this.getById(condition.getBusinessId());
|
|
|
+ if (applyPurchase == null) {
|
|
|
+ throw new ServiceException("申购单不存在");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Boolean flowResult = flowApi.examineFlow(condition);
|
|
|
+ if(flowResult){//流程结束
|
|
|
+ ApplyPurchase update = new ApplyPurchase();
|
|
|
+ update.setId(condition.getBusinessId());
|
|
|
+ update.setApprovalTime(new Date());
|
|
|
+ update.setApproveBillState(ApplyPurchaseStatusEnum.APPLY_PURCHASE_STATUS_2.getKey());
|
|
|
+ this.updateById(update);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new ServiceException("流程异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 驳回
|
|
|
+ * @param condition
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void reject(FlowParam condition) {
|
|
|
+ if (StringUtils.isAnyBlank(condition.getBusinessId(), condition.getProInstantsId())) {
|
|
|
+ throw new ServiceException("参数缺失");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Boolean flowResult = flowApi.rejectFlow(condition);//驳回完后判断流程是否结束。还是转交到上一个节点
|
|
|
+ if(flowResult){//流程结束
|
|
|
+ ApplyPurchase update = new ApplyPurchase();
|
|
|
+ update.setId(condition.getBusinessId());
|
|
|
+ update.setApproveBillState(ApplyPurchaseStatusEnum.APPLY_PURCHASE_STATUS_3.getKey());
|
|
|
+ this.updateById(update);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new ServiceException("流程异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置流程属性
|
|
|
+ * @param title
|
|
|
+ * @param common
|
|
|
+ * @param businessId
|
|
|
+ * @param flowIdentifying
|
|
|
+ * @param proInstantsId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private FlowParam setValue(String title,String common,String businessId,String flowIdentifying,String proInstantsId){
|
|
|
+ FlowParam param = new FlowParam();
|
|
|
+ param.setCommon(common);
|
|
|
+ param.setBusinessId(businessId);
|
|
|
+ param.setFlowIdentifying(flowIdentifying);
|
|
|
+ param.setTitle(title);
|
|
|
+ return param;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ * @param applyPurchase
|
|
|
+ */
|
|
|
+ private void saveApplyPurchase(ApplyPurchase applyPurchase){
|
|
|
+ applyPurchase.setCreate();
|
|
|
+ save(applyPurchase);
|
|
|
+ //申购明细保存
|
|
|
+ List<ApplyPurchasedetail> applyPurchasedetailList = applyPurchase.getPurchasedetailList();
|
|
|
+ if(CollectionUtils.isNotEmpty(applyPurchasedetailList)){
|
|
|
+ for(ApplyPurchasedetail d:applyPurchasedetailList){
|
|
|
+ d.setCreate();
|
|
|
+ d.setApplyPurchaseId(applyPurchase.getId());
|
|
|
+ }
|
|
|
+ iApplyPurchasedetailService.saveBatch(applyPurchasedetailList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ * @param applyPurchase
|
|
|
+ */
|
|
|
+ private void updateApplyPurchase(ApplyPurchase applyPurchase){
|
|
|
+ applyPurchase.setUpdate();
|
|
|
+ updateById(applyPurchase);
|
|
|
+ //申购明细修改
|
|
|
+ List<ApplyPurchasedetail> applyPurchasedetailList = applyPurchase.getPurchasedetailList();
|
|
|
+ if(CollectionUtils.isNotEmpty(applyPurchasedetailList)){
|
|
|
+ //清空申购明细
|
|
|
+ iApplyPurchasedetailService.remove(Wrappers.<ApplyPurchasedetail>query().lambda().eq(ApplyPurchasedetail::getApplyPurchaseId,applyPurchase.getId()));
|
|
|
+ for(ApplyPurchasedetail d:applyPurchasedetailList){
|
|
|
+ d.setCreate();
|
|
|
+ d.setApplyPurchaseId(applyPurchase.getId());
|
|
|
+ }
|
|
|
+ iApplyPurchasedetailService.saveBatch(applyPurchasedetailList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|