|
@@ -0,0 +1,108 @@
|
|
|
+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.constant.StatusConstant;
|
|
|
+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.lend.dto.LendDto;
|
|
|
+import com.sd.business.entity.lend.po.Lend;
|
|
|
+import com.sd.business.entity.lend.po.LendBom;
|
|
|
+import com.sd.business.service.lend.LendBomService;
|
|
|
+import com.sd.business.service.lend.LendService;
|
|
|
+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.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 发起借出流程
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class LendFlow extends FlowDelegate {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LendService lendService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LendBomService lendBomService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFlowKey() {
|
|
|
+ return "apply_buy";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long start(Long flowId, JSONObject submitData) {
|
|
|
+
|
|
|
+ LendDto lendDto = submitData.toJavaObject(LendDto.class);
|
|
|
+ validated(lendDto);
|
|
|
+
|
|
|
+ long lendId = IdWorker.getId();
|
|
|
+
|
|
|
+ lendDto.setId(lendId);
|
|
|
+ lendDto.setCode(CodeEnum.LEND_CODE.getCode());
|
|
|
+ lendDto.setFlowId(flowId);
|
|
|
+ lendDto.setFlowStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
|
+ lendDto.setReturnStatus(StatusConstant.NO);
|
|
|
+
|
|
|
+ List<LendBom> lendBomList = lendDto.getLendBomList();
|
|
|
+ for (LendBom lendBom : lendBomList) {
|
|
|
+ lendBom.setLendId(lendId);
|
|
|
+ }
|
|
|
+
|
|
|
+ lendService.save(lendDto);
|
|
|
+ lendBomService.saveBatch(lendBomList);
|
|
|
+
|
|
|
+ return lendId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
+ lendService.update(q -> q
|
|
|
+ .eq(BaseIdPo::getId, businessId)
|
|
|
+ .set(Lend::getFlowStatus, FlowStatusEnum.PASS.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public void jump() {
|
|
|
+ // 如果是驳回,修改流程状态为驳回
|
|
|
+ if (HandleTypeEnum.REJECT.equals(FlowThreadLocalUtil.getHandleTypeEnum())) {
|
|
|
+ lendService.update(q -> q
|
|
|
+ .eq(BaseIdPo::getId, FlowThreadLocalUtil.getBusinessId())
|
|
|
+ .set(Lend::getFlowStatus, FlowStatusEnum.REJECT.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证数据
|
|
|
+ */
|
|
|
+ private void validated(LendDto lendDto) {
|
|
|
+ Assert.notBlank(lendDto.getLendName(), "借出人不能为空");
|
|
|
+ Assert.notEmpty(lendDto.getLendTime(), "借出时间不能为空");
|
|
|
+ Assert.notEmpty(lendDto.getReturnTime(), "归还时间不能为空");
|
|
|
+
|
|
|
+ List<LendBom> lendBomList = lendDto.getLendBomList();
|
|
|
+ Assert.notEmpty(lendBomList, "借出明细不能为空");
|
|
|
+
|
|
|
+ for (LendBom lendBom : lendBomList) {
|
|
|
+ Assert.notNull(lendBom.getBomSpecId(), "bom规格Id不能为空");
|
|
|
+ Assert.notNull(lendBom.getQuantity(), "借出数量不能为空");
|
|
|
+ Assert.gtZero(lendBom.getQuantity(), "借出数量必须大于0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|