cuilei
2025-05-23 98e4c499221c0069af9632c4fd08f096fb8006d6
工具管理-工具出库流程启动、审批
已添加2个文件
已修改3个文件
285 ■■■■■ 文件已修改
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/OutboundOrderController.java 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/entity/dto/OutBoundOrderFlowDto.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/enums/OutBoundStatusEnum.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IOutboundOrderService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java 187 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/OutboundOrderController.java
@@ -1,5 +1,9 @@
package org.jeecg.modules.tms.controller;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jeecg.common.system.query.QueryGenerator;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -7,6 +11,8 @@
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.TranslateDictTextUtils;
import org.jeecg.modules.tms.entity.dto.OutBoundOrderFlowDto;
import org.jeecg.modules.tms.entity.dto.OutboundOrderAndDetailDto;
import org.jeecg.modules.tms.entity.vo.OutboundDetailVo;
import org.jeecg.modules.tms.enums.OutBillStatus;
@@ -56,6 +62,13 @@
    @Autowired
    private IOutboundDetailService outboundDetailService;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private TranslateDictTextUtils translateDictTextUtils;
    /*---------------------------------主表处理-begin-------------------------------------*/
@@ -79,6 +92,28 @@
        Page<OutboundOrder> page = new Page<OutboundOrder>(pageNo, pageSize);
        IPage<OutboundOrder> pageList = outboundOrderService.queryPageList(page, parameterMap);
        return Result.OK(pageList);
    }
    @ApiOperation(value="tms_outbound_order-通过id查询", notes="tms_outbound_order-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam("id") String id) {
        OutboundOrder outboundOrder = outboundOrderService.getById(id);
        if (outboundOrder == null) {
            return Result.error("未找到对应数据");
        }
        try {
            String jsonStr = objectMapper.writeValueAsString(outboundOrder);
            JSONObject item = JSONObject.parseObject(jsonStr, Feature.OrderedField);
            translateDictTextUtils.translateField("outStorehouseType", outboundOrder.getOutStorehouseType(), item, "out_storehouse_type");
            translateDictTextUtils.translateField("handler", outboundOrder.getHandler(), item, "sys_user,realname,id");
            translateDictTextUtils.translateField("orderStatus", outboundOrder.getOrderStatus(), item, "out_bill_status");
            translateDictTextUtils.translateField("outStatus", outboundOrder.getOutStatus(), item, "out_storehouse_status");
            translateDictTextUtils.translateField("createBy", outboundOrder.getCreateBy(), item, "sys_user,realname,username");
            translateDictTextUtils.translateField("updateBy", outboundOrder.getUpdateBy(), item, "sys_user,realname,username");
            return Result.OK(item);
        } catch (JsonProcessingException e) {
            return Result.error("数据转译失败!");
        }
    }
    /**
@@ -130,14 +165,18 @@
    @ApiOperation(value="tms_outbound_order-提交出库申请单", notes="tms_outbound_order-提交出库申请单")
    @GetMapping(value = "/submit")
    public Result<String> submit(@RequestParam(name="id") String id) {
        OutboundOrder order = new OutboundOrder();
        order.setId(id);
        order.setOrderStatus(OutBillStatus.SUBMITTED.getValue());
        outboundOrderService.updateById(order);
        //开启流程
        outboundOrderService.submit(id);
        return Result.OK("提交成功!");
    }
     @AutoLog(value = "审批流程")
     @ApiOperation(value = "出库申请单-审批流程", notes = "出库申请单-审批流程")
     @PostMapping("/approval")
     public Result<?> approval(@RequestBody OutBoundOrderFlowDto outBoundOrderFlowDto) {
        outboundOrderService.approvalProcess(outBoundOrderFlowDto);
        return Result.OK("操作成功");
     }
    /**
     * é€šè¿‡id删除
     * @param id
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/entity/dto/OutBoundOrderFlowDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,12 @@
package org.jeecg.modules.tms.entity.dto;
import lombok.Data;
import org.jeecg.modules.flowable.domain.vo.FlowTaskVo;
@Data
public class OutBoundOrderFlowDto extends FlowTaskVo {
    //审批状态
    private String status;
    //审批意见
    private String approvalOpinion;
}
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/enums/OutBoundStatusEnum.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,32 @@
package org.jeecg.modules.tms.enums;
import lombok.Getter;
/**
 * å‡ºåº“状态枚举
 */
@Getter
public enum OutBoundStatusEnum {
    /**
     * æœªå‡ºåº“
     */
    NOT_OUTBOUND("1", "未出库"),
    /**
     * éƒ¨åˆ†å‡ºåº“
     */
    PARTIAL_OUTBOUND("2", "部分出库"),
    /**
     * å‡ºåº“完成
     */
    COMPLETED("3", "出库完成");
    private final String value;
    private final String description;
    OutBoundStatusEnum(String value, String description) {
        this.value = value;
        this.description = description;
    }
}
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IOutboundOrderService.java
@@ -5,6 +5,7 @@
import org.jeecg.modules.tms.entity.OutboundDetail;
import org.jeecg.modules.tms.entity.OutboundOrder;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.tms.entity.dto.OutBoundOrderFlowDto;
import org.jeecg.modules.tms.entity.dto.OutboundOrderAndDetailDto;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.Serializable;
@@ -40,4 +41,8 @@
    IPage<OutboundOrder> queryPageList(Page<OutboundOrder> page, Map<String, String[]> parameterMap);
    void editTotal(OutboundOrderAndDetailDto outboundOrder);
    void submit(String id);
    void approvalProcess(OutBoundOrderFlowDto outBoundOrderFlowDto);
}
lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java
@@ -2,19 +2,36 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
import org.jeecg.modules.flowable.apithird.business.service.impl.FlowMyBusinessServiceImpl;
import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
import org.jeecg.modules.flowable.apithird.service.FlowCommonService;
import org.jeecg.modules.flowable.service.IFlowDefinitionService;
import org.jeecg.modules.flowable.service.IFlowTaskService;
import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
import org.jeecg.modules.tms.entity.OutboundOrder;
import org.jeecg.modules.tms.entity.OutboundDetail;
import org.jeecg.modules.tms.entity.dto.OutBoundOrderFlowDto;
import org.jeecg.modules.tms.entity.dto.OutboundOrderAndDetailDto;
import org.jeecg.modules.tms.enums.OutBillStatus;
import org.jeecg.modules.tms.enums.OutBoundStatusEnum;
import org.jeecg.modules.tms.mapper.OutboundDetailMapper;
import org.jeecg.modules.tms.mapper.OutboundOrderMapper;
import org.jeecg.modules.tms.service.IOutboundDetailService;
@@ -24,10 +41,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.*;
/**
 * @Description: tms_outbound_order
@@ -35,13 +49,24 @@
 * @Date:   2025-05-16
 * @Version: V1.0
 */
@Slf4j
@Service
public class OutboundOrderServiceImpl extends ServiceImpl<OutboundOrderMapper, OutboundOrder> implements IOutboundOrderService {
public class OutboundOrderServiceImpl extends ServiceImpl<OutboundOrderMapper, OutboundOrder> implements IOutboundOrderService, FlowCallBackServiceI {
    @Autowired
    private IOutboundDetailService outboundDetailService;
    @Autowired
    private ISysBusinessCodeRuleService businessCodeRuleService;
    @Autowired
    private IFlowDefinitionService flowDefinitionService;
    @Autowired
    private IFlowMyBusinessService flowMyBusinessService;
    @Autowired
    private IFlowTaskService flowTaskService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private FlowCommonService flowCommonService;
    @Autowired
    private OutboundOrderMapper outboundOrderMapper;
    @Autowired
@@ -73,6 +98,7 @@
        save(order);
        List<OutboundDetail> detailList = CollectionUtil.newArrayList();
        outboundOrder.getOutboundDetailList().forEach(item->{
            item.setId(null);
            item.setOutStorehouseId(order.getId());
            detailList.add(item);
        });
@@ -122,7 +148,96 @@
        outboundDetailService.saveBatch(detailList);
    }
    private LoginUser getCurrentUser() {
    @Override
    public void submit(String id) {
        OutboundOrder outboundOrder = getById(id);
        if (outboundOrder == null) {
            throw new JeecgBootException("出库单申请单不存在,无法提交!");
        }
        if (!Objects.equals(outboundOrder.getOrderStatus(), OutBillStatus.DRAFT.getValue())) {
            throw new JeecgBootException("无法提交非草稿状态的出库申请单!");
        }
        //启动流程
        if (triggerProcess(outboundOrder)) {
            outboundOrder.setOrderStatus(OutBillStatus.SUBMITTED.getValue());
        }
        updateById(outboundOrder);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void approvalProcess(OutBoundOrderFlowDto outBoundOrderFlowDto) {
        if (StrUtil.isBlank(outBoundOrderFlowDto.getTaskId()) || StrUtil.isBlank(outBoundOrderFlowDto.getDataId())) {
            throw new JeecgBootException("非法参数!");
        }
        // èŽ·å–å½“å‰ç™»å½•ç”¨æˆ·
        LoginUser user = getCurrentUser();
        if (user == null || StrUtil.isBlank(user.getId())) {
            throw new JeecgBootException("账号不存在");
        }
        //获取出库申请单信息
        OutboundOrder outboundOrder = getById(outBoundOrderFlowDto.getDataId());
        if (outboundOrder == null) {
            throw new JeecgBootException("未找到对应的出库申请单!");
        }
        //获取流程业务记录
        FlowMyBusiness flowMyBusiness = getFlowMyBusiness(outBoundOrderFlowDto.getInstanceId());
        if (flowMyBusiness == null) {
            throw new JeecgBootException("流程记录不存在");
        }
        // æ£€æŸ¥ç”¨æˆ·æ˜¯å¦æœ‰æƒé™æ“ä½œä»»åŠ¡
        if (!isUserAuthorized(flowMyBusiness, user)) {
            throw new JeecgBootException("用户无权操作此任务");
        }
        // è®¤é¢†ä»»åŠ¡
        if (!claimTask(flowMyBusiness.getTaskId(), user)) {
            throw new JeecgBootException("任务不存在、已完成或已被他人认领");
        }
        //设置流程变量
        setupProcessVariables(outBoundOrderFlowDto, outboundOrder, user);
        //完成流程任务
        Result result = flowTaskService.complete(outBoundOrderFlowDto);
        //根据任务完成结果更新申请单状态
        if (result.isSuccess()) {
            outboundOrder.setOrderStatus(outBoundOrderFlowDto.getStatus());
            if (OutBillStatus.APPROVED.getValue().equals(outBoundOrderFlowDto.getStatus())) {
                outboundOrder.setOutStatus(OutBoundStatusEnum.NOT_OUTBOUND.getValue());
            }
            outboundOrder.setAuditDate(new Date());
            outboundOrder.setApprovalOpinion(outBoundOrderFlowDto.getApprovalOpinion());
            updateById(outboundOrder);
        }
    }
    public boolean triggerProcess(OutboundOrder outboundOrder) {
        flowCommonService.initActBusiness("单号为:" + outboundOrder.getOutNum() + " çš„出库申请,开始进行审批",
                outboundOrder.getId(), "outboundOrderServiceImpl", "tool_out_storage", null);
        Map<String, Object> variables = new HashMap<>();
        variables.put("dataId", outboundOrder.getId());
        if (StrUtil.isEmpty(outboundOrder.getRemark())) {
            variables.put("organization", "新增出库申请单默认启动流程");
            variables.put("comment", "新增出库申请单默认启动流程");
        } else {
            variables.put("organization", outboundOrder.getRemark());
            variables.put("comment", outboundOrder.getRemark());
        }
        variables.put("proofreading", true);
        List<String> usernames = new ArrayList<>();
        usernames.add(outboundOrder.getReviewer());
        variables.put("NextAssignee", usernames);
        Result result = flowDefinitionService.startProcessInstanceByKey("tool_out_storage", variables);
        return result.isSuccess();
    }
    private LoginUser getCurrentUser() {
        // èŽ·å–å½“å‰è®¤è¯çš„ç™»å½•ç”¨æˆ·ä¿¡æ¯
        Subject currentUser = SecurityUtils.getSubject();
        if (currentUser != null && currentUser.isAuthenticated()) {
@@ -133,4 +248,64 @@
        }
        return null;
    }
    private FlowMyBusiness getFlowMyBusiness(String instanceId) {
        List<FlowMyBusiness> businessList = flowMyBusinessService.list(
                new LambdaQueryWrapper<FlowMyBusiness>().eq(FlowMyBusiness::getProcessInstanceId, instanceId));
        return businessList.isEmpty() ? null : businessList.get(0);
    }
    private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) {
        List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class);
        return todoUsers != null && todoUsers.contains(user.getUsername());
    }
    private boolean claimTask(String taskId, LoginUser user) {
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        if (task == null) {
            return false;
        }
        if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) {
            return false;
        }
        taskService.claim(taskId, user.getUsername());
        return true;
    }
    private void setupProcessVariables(OutBoundOrderFlowDto outBoundOrderFlowDto, OutboundOrder outboundOrder, LoginUser user) {
        if (OutBillStatus.SUBMITTED.getValue().equals(outboundOrder.getOrderStatus()) && user.getUsername().equals(outboundOrder.getReviewer())) {
            Map<String, Object> values = new HashMap<>();
            values.put("dataId", outboundOrder.getId());
            values.put("organization", outBoundOrderFlowDto.getApprovalOpinion());
            values.put("comment", outBoundOrderFlowDto.getApprovalOpinion());
            values.put("status", outBoundOrderFlowDto.getStatus());
            values.put("NextAssignee", Collections.singletonList(outboundOrder.getReviewer()));
            outBoundOrderFlowDto.setValues(values);
        }
    }
    @Override
    public void afterFlowHandle(FlowMyBusiness business) {
        business.getTaskNameId();//接下来审批的节点
        business.getValues();//前端传进来的参数
        business.getActStatus();
    }
    @Override
    public Object getBusinessDataById(String dataId) {
        return this.getById(dataId);
    }
    @Override
    public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) {
        return Collections.emptyMap();
    }
    @Override
    public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
        //业务是否干预流程,业务干预,流程干预,指定人员进行处理
        //获取下一步处理人
        Object object = values.get("NextAssignee");
        return (List<String>) object;
    }
}