入库审批流引入
This commit is contained in:
parent
72b6d2ace7
commit
ecf9db93bd
|
|
@ -351,13 +351,22 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|||
*/
|
||||
private void executeCallback(ApprovalInstance instance, String status) {
|
||||
try {
|
||||
log.info("开始执行审批回调,业务类型:{},审批状态:{}", instance.getBusinessType(), status);
|
||||
log.info("当前注册的回调处理器:{}", callbackMap.keySet());
|
||||
|
||||
IApprovalCallback callback = callbackMap.get(instance.getBusinessType());
|
||||
if (callback != null) {
|
||||
log.info("找到回调处理器,开始执行,业务类型:{}", instance.getBusinessType());
|
||||
if (ApprovalStatusEnum.APPROVED.getCode().equals(status)) {
|
||||
log.info("执行审批通过回调");
|
||||
callback.onApproved(instance);
|
||||
} else if (ApprovalStatusEnum.REJECTED.getCode().equals(status)) {
|
||||
log.info("执行审批驳回回调");
|
||||
callback.onRejected(instance);
|
||||
}
|
||||
log.info("审批回调执行成功,业务类型:{}", instance.getBusinessType());
|
||||
} else {
|
||||
log.warn("未找到业务类型[{}]的回调处理器", instance.getBusinessType());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("执行审批回调失败,实例编号:{},业务类型:{}", instance.getInstanceCode(), instance.getBusinessType(), e);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
package com.bonus.material.approval.strategy.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bonus.material.approval.domain.ApprovalInstance;
|
||||
import com.bonus.material.approval.strategy.IApprovalCallback;
|
||||
import com.bonus.material.toolProcess.domain.ToolApplyDetailsEntity;
|
||||
import com.bonus.material.toolProcess.service.ToolApplyService;
|
||||
import com.bonus.material.warehousing.domain.WarehousingEntity;
|
||||
import com.bonus.material.warehousing.mapper.WarehousingMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 入库审批回调
|
||||
*
|
||||
* @author syruan
|
||||
*/
|
||||
@Component("EQUIPMENT_PUT")
|
||||
public class WarehousingApprovalCallback implements IApprovalCallback {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WarehousingApprovalCallback.class);
|
||||
|
||||
@Resource
|
||||
private WarehousingMapper warehousingMapper;
|
||||
|
||||
@Resource
|
||||
private ToolApplyService toolApplyService;
|
||||
|
||||
/**
|
||||
* 审批通过回调
|
||||
* 执行入库业务逻辑:更新入库状态、更新工具申请状态等
|
||||
*/
|
||||
@Override
|
||||
public void onApproved(ApprovalInstance instance) {
|
||||
try {
|
||||
log.info("入库审批通过,开始执行入库业务逻辑,业务ID:{}", instance.getBusinessId());
|
||||
|
||||
// 1. 获取入库ID
|
||||
Integer warehousingId = Integer.valueOf(instance.getBusinessId());
|
||||
|
||||
// 2. 查询入库记录
|
||||
WarehousingEntity entity = warehousingMapper.selectById(warehousingId);
|
||||
if (entity == null) {
|
||||
log.error("入库审批通过,但未找到入库记录,业务ID:{}", instance.getBusinessId());
|
||||
throw new RuntimeException("未找到入库记录");
|
||||
}
|
||||
|
||||
// 3. 更新入库状态为已通过(状态2)
|
||||
entity.setStatus("2");
|
||||
warehousingMapper.updateById(entity);
|
||||
|
||||
// 4. 如果有关联的工具申请,更新工具申请详情状态
|
||||
if (entity.getApplyId() != null && !entity.getApplyId().isEmpty()) {
|
||||
ToolApplyDetailsEntity toolApplyDetailsEntity = new ToolApplyDetailsEntity();
|
||||
toolApplyDetailsEntity.setApplyId(Long.valueOf(entity.getApplyId()));
|
||||
toolApplyDetailsEntity.setStatus("2");
|
||||
toolApplyService.updateAllDetail(toolApplyDetailsEntity);
|
||||
log.info("入库审批通过,已更新工具申请详情状态,申请ID:{}", entity.getApplyId());
|
||||
}
|
||||
|
||||
log.info("入库审批通过,业务逻辑执行成功,业务ID:{}", instance.getBusinessId());
|
||||
} catch (Exception e) {
|
||||
log.error("入库审批通过回调失败", e);
|
||||
throw new RuntimeException("入库审批通过回调失败:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批驳回回调
|
||||
* 更新入库状态为"已驳回"
|
||||
*/
|
||||
@Override
|
||||
public void onRejected(ApprovalInstance instance) {
|
||||
try {
|
||||
log.info("入库审批驳回,开始执行入库业务驳回逻辑,业务ID:{}", instance.getBusinessId());
|
||||
|
||||
// 1. 获取入库ID
|
||||
Integer warehousingId = Integer.valueOf(instance.getBusinessId());
|
||||
|
||||
// 2. 查询入库记录
|
||||
WarehousingEntity entity = warehousingMapper.selectById(warehousingId);
|
||||
if (entity == null) {
|
||||
log.error("入库审批驳回,但未找到入库记录,业务ID:{}", instance.getBusinessId());
|
||||
throw new RuntimeException("未找到入库记录");
|
||||
}
|
||||
|
||||
// 3. 更新入库状态为已驳回(状态3)
|
||||
entity.setStatus("3");
|
||||
warehousingMapper.updateById(entity);
|
||||
|
||||
log.info("入库审批驳回,业务逻辑执行成功,业务ID:{}", instance.getBusinessId());
|
||||
} catch (Exception e) {
|
||||
log.error("入库审批驳回回调失败", e);
|
||||
throw new RuntimeException("入库审批驳回回调失败:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ public class Project {
|
|||
int sequence;
|
||||
|
||||
//工程id 主键
|
||||
private Integer id;
|
||||
private String id;
|
||||
|
||||
//工程编号
|
||||
@Excel(name = "项目编号", width = 25, sort = 2)
|
||||
|
|
|
|||
|
|
@ -62,5 +62,5 @@ public interface ProjectMapper {
|
|||
|
||||
int countByProjectCode(String proCode);
|
||||
|
||||
int countByProjectNameById(@Param("proName")String proName, @Param("id") Integer id);
|
||||
int countByProjectNameById(@Param("proName")String proName, @Param("id") String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import com.bonus.common.core.web.domain.AjaxResult;
|
|||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.common.log.annotation.SysLog;
|
||||
import com.bonus.common.log.enums.OperaType;
|
||||
import com.bonus.material.approval.domain.ApprovalInstance;
|
||||
import com.bonus.material.approval.mapper.ApprovalInstanceMapper;
|
||||
import com.bonus.material.approval.service.IApprovalEngineService;
|
||||
import com.bonus.material.warehousing.domain.WarehousingEntity;
|
||||
import com.bonus.material.warehousing.service.WarehousingService;
|
||||
import io.swagger.annotations.Api;
|
||||
|
|
@ -22,6 +25,12 @@ public class WarehousingController extends BaseController {
|
|||
@Resource
|
||||
private WarehousingService service;
|
||||
|
||||
@Resource
|
||||
private IApprovalEngineService approvalEngineService;
|
||||
|
||||
@Resource
|
||||
private ApprovalInstanceMapper approvalInstanceMapper;
|
||||
|
||||
/**
|
||||
* 工具类型表格
|
||||
*
|
||||
|
|
@ -98,25 +107,75 @@ public class WarehousingController extends BaseController {
|
|||
|
||||
|
||||
/**
|
||||
* 批量提交
|
||||
* 批量审批通过
|
||||
* 通过审批引擎处理审批操作
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
* @param ids 入库ID列表
|
||||
* @return 审批结果
|
||||
*/
|
||||
@PostMapping("/batchApproval/{ids}")
|
||||
public AjaxResult batchApproval(@PathVariable("ids") Integer[] ids) {
|
||||
return service.batchApproval(ids);
|
||||
try {
|
||||
if (ids == null || ids.length == 0) {
|
||||
return AjaxResult.error("未选择数据");
|
||||
}
|
||||
|
||||
// 对每个入库ID进行审批
|
||||
for (Integer id : ids) {
|
||||
// 查询该入库对应的审批实例
|
||||
ApprovalInstance instance = approvalInstanceMapper.selectInstanceByBusiness("EQUIPMENT_PUT", String.valueOf(id));
|
||||
if (instance == null) {
|
||||
return AjaxResult.error("入库ID:" + id + " 对应的审批实例不存在");
|
||||
}
|
||||
|
||||
// 调用审批引擎进行审批通过(1表示通过)
|
||||
AjaxResult result = approvalEngineService.doApprove(instance.getId(), "1", "");
|
||||
if (!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return AjaxResult.success("审批通过");
|
||||
} catch (Exception e) {
|
||||
logger.error("批量审批失败", e);
|
||||
return AjaxResult.error("批量审批失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量提交
|
||||
* 批量审批驳回
|
||||
* 通过审批引擎处理驳回操作
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
* @param ids 入库ID列表
|
||||
* @return 驳回结果
|
||||
*/
|
||||
@PostMapping("/batchRejection/{ids}")
|
||||
public AjaxResult batchRejection(@PathVariable("ids") Integer[] ids) {
|
||||
return service.batchRejection(ids);
|
||||
try {
|
||||
if (ids == null || ids.length == 0) {
|
||||
return AjaxResult.error("未选择数据");
|
||||
}
|
||||
|
||||
// 对每个入库ID进行驳回
|
||||
for (Integer id : ids) {
|
||||
// 查询该入库对应的审批实例
|
||||
ApprovalInstance instance = approvalInstanceMapper.selectInstanceByBusiness("EQUIPMENT_PUT", String.valueOf(id));
|
||||
if (instance == null) {
|
||||
return AjaxResult.error("入库ID:" + id + " 对应的审批实例不存在");
|
||||
}
|
||||
|
||||
// 调用审批引擎进行驳回(2表示驳回)
|
||||
AjaxResult result = approvalEngineService.doApprove(instance.getId(), "2", "");
|
||||
if (!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return AjaxResult.success("审批驳回");
|
||||
} catch (Exception e) {
|
||||
logger.error("批量驳回失败", e);
|
||||
return AjaxResult.error("批量驳回失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.bonus.material.warehousing.service.Impl;
|
|||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.approval.annotation.ApprovalRequired;
|
||||
import com.bonus.material.devchange.domain.MapBean;
|
||||
import com.bonus.material.device.domain.vo.DevMergeVo;
|
||||
import com.bonus.material.device.service.DevMergeService;
|
||||
|
|
@ -120,7 +121,7 @@ public class WarehousingServiceImpl implements WarehousingService {
|
|||
// warehousing.setCompanyId(deptId);
|
||||
// }
|
||||
if(ADMIN_ID.equals(userId)){
|
||||
warehousing.setCompanyId(1L);
|
||||
warehousing.setCompanyId(null);
|
||||
}else{
|
||||
warehousing.setCompanyId(deptId);
|
||||
}
|
||||
|
|
@ -128,17 +129,19 @@ public class WarehousingServiceImpl implements WarehousingService {
|
|||
return ObjectUtils.isNotEmpty(warehousingEntities) ? warehousingEntities : new ArrayList<WarehousingEntity>();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return new ArrayList<WarehousingEntity>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量提交
|
||||
* 提交后会自动创建审批流实例
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@ApprovalRequired(businessType = "EQUIPMENT_PUT", businessIdExpr = "#ids[0]", businessDataExpr = "#ids")
|
||||
public AjaxResult batchSubmission(Integer[] ids) {
|
||||
try {
|
||||
// 1. 空值/空数组校验:提前终止无效请求
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.material.toolLedger.mapper.ToolLedgerMapper">
|
||||
<insert id="add" parameterType="com.bonus.material.toolLedger.domain.ToolLedgerEntity"
|
||||
useGeneratedKeys="true" keyProperty="id" keyColumn="id">
|
||||
<insert id="add" parameterType="com.bonus.material.toolLedger.domain.ToolLedgerEntity" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
|
||||
INSERT INTO tool_ledger
|
||||
<!--
|
||||
trim 标签核心作用:
|
||||
|
|
@ -27,8 +26,8 @@
|
|||
<if test="productionDate != null">production_date,</if>
|
||||
<if test="lastCheckDate != null">last_check_date,</if>
|
||||
<if test="nextCheckDate != null">next_check_date,</if>
|
||||
<if test="status != null and status != ''">status,</if>
|
||||
'1',
|
||||
<if test="status != null and status != ''">`status`,</if>
|
||||
up_down_status,
|
||||
<if test="companyId != null">company_id,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
|
||||
|
|
@ -53,7 +52,7 @@
|
|||
<if test="lastCheckDate != null">#{lastCheckDate},</if>
|
||||
<if test="nextCheckDate != null">#{nextCheckDate},</if>
|
||||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="upDownStatus != null and upDownStatus != ''">#{upDownStatus},</if>
|
||||
'1',
|
||||
<if test="companyId != null">#{companyId},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<!-- 对应上面的兜底字段,确保参数列表和字段列表数量一致 -->
|
||||
|
|
|
|||
Loading…
Reference in New Issue