|
@@ -0,0 +1,112 @@
|
|
|
+package com.sd.business.flow;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.fjhx.flow.core.FlowDelegate;
|
|
|
+import com.fjhx.flow.core.FlowThreadLocalUtil;
|
|
|
+import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
+import com.fjhx.flow.enums.HandleTypeEnum;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
+import com.ruoyi.common.core.domain.BasePo;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.sd.business.entity.apply.dto.ApplyBuyDto;
|
|
|
+import com.sd.business.entity.apply.po.ApplyBuy;
|
|
|
+import com.sd.business.entity.apply.po.ApplyBuyBom;
|
|
|
+import com.sd.business.service.apply.ApplyBuyBomService;
|
|
|
+import com.sd.business.service.apply.ApplyBuyService;
|
|
|
+import com.sd.business.util.CodeEnum;
|
|
|
+import com.sd.framework.util.Assert;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 发起申购流程
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ApplyFlow extends FlowDelegate {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplyBuyService applyBuyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplyBuyBomService applyBuyBomService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFlowKey() {
|
|
|
+ return "apply_buy";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long start(Long flowId, JSONObject submitData) {
|
|
|
+ ApplyBuyDto applyBuyDto = submitData.toJavaObject(ApplyBuyDto.class);
|
|
|
+ validated(applyBuyDto);
|
|
|
+
|
|
|
+ Long applyBuyId = IdWorker.getId();
|
|
|
+
|
|
|
+ applyBuyDto.setId(applyBuyId);
|
|
|
+ applyBuyDto.setCode(CodeEnum.APPLY_BUY_CODE.getCode());
|
|
|
+ applyBuyDto.setFlowId(flowId);
|
|
|
+ applyBuyDto.setFlowStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
+
|
|
|
+ List<ApplyBuyBom> applyBuyBomList = applyBuyDto.getApplyBuyBomList();
|
|
|
+ for (ApplyBuyBom applyBuyBom : applyBuyBomList) {
|
|
|
+ applyBuyBom.setApplyBuyId(applyBuyId);
|
|
|
+ applyBuyBom.setPurchaseQuantity(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ applyBuyService.save(applyBuyDto);
|
|
|
+ applyBuyBomService.saveBatch(applyBuyBomList);
|
|
|
+
|
|
|
+ return applyBuyId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
+
|
|
|
+ applyBuyService.update(q -> q
|
|
|
+ .eq(BaseIdPo::getId, businessId)
|
|
|
+ .set(ApplyBuy::getFlowStatus, FlowStatusEnum.PASS.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void jump() {
|
|
|
+
|
|
|
+ // 如果是驳回,修改状态为驳回
|
|
|
+ if (HandleTypeEnum.REJECT.equals(FlowThreadLocalUtil.getHandleTypeEnum())) {
|
|
|
+ applyBuyService.update(q -> q
|
|
|
+ .eq(BaseIdPo::getId, FlowThreadLocalUtil.getBusinessId())
|
|
|
+ .set(ApplyBuy::getFlowStatus, FlowStatusEnum.REJECT.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证数据
|
|
|
+ */
|
|
|
+ private void validated(ApplyBuyDto applyBuyDto) {
|
|
|
+
|
|
|
+ Assert.notBlank(applyBuyDto.getApplyName(), "申购人不能为空");
|
|
|
+ Assert.notEmpty(applyBuyDto.getApplyTime(), "申购时间不能为空");
|
|
|
+
|
|
|
+ List<ApplyBuyBom> applyBuyBomList = applyBuyDto.getApplyBuyBomList();
|
|
|
+ Assert.notEmpty(applyBuyBomList, "申购清单不能为空");
|
|
|
+
|
|
|
+ for (ApplyBuyBom applyBuyBom : applyBuyBomList) {
|
|
|
+ Assert.notNull(applyBuyBom.getBomSpecId(), "bomId不能为空");
|
|
|
+ Assert.notNull(applyBuyBom.getQuantity(), "申购数量不能为空");
|
|
|
+ Assert.gtZero(applyBuyBom.getQuantity(), "申购数量必须大于0");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|