Houjie
2025-05-23 c5daf9399f292e5b21deff9d5a8ac60fb4c377ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package org.jeecg.modules.tms.service.impl;
 
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
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.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
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.ToolsLossBound;
import org.jeecg.modules.tms.entity.ToolsLossBoundDetail;
import org.jeecg.modules.tms.enums.OutBillStatus;
import org.jeecg.modules.tms.mapper.ToolsLossBoundDetailMapper;
import org.jeecg.modules.tms.mapper.ToolsLossBoundMapper;
import org.jeecg.modules.tms.service.IToolsLossBoundDetailService;
import org.jeecg.modules.tms.service.IToolsLossBoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.*;
 
/**
 * @Description: 损耗单
 * @Author: jeecg-boot
 * @Date: 2025-05-21
 * @Version: V1.0
 */
@Service("IToolsLossBoundService")
public class ToolsLossBoundServiceImpl extends ServiceImpl<ToolsLossBoundMapper, ToolsLossBound> implements IToolsLossBoundService, FlowCallBackServiceI {
 
    @Autowired
    private ToolsLossBoundMapper baseMapper;
 
    @Autowired
    private ToolsLossBoundDetailMapper baseDetailMapper;
    @Autowired
    private IToolsLossBoundDetailService toolsLossBoundDetailService;
    @Resource
    private FlowCommonService flowCommonService;
    @Resource
    private IFlowDefinitionService flowDefinitionService;
    @Autowired
    private IFlowTaskService flowTaskService;
    @Autowired
    private ISysBusinessCodeRuleService businessCodeRuleService;
 
 
    @Override
    public void delMain(String id) {
        baseDetailMapper.deleteByMainId(id);
        baseMapper.deleteById(id);
    }
 
    @Override
    public void delBatchMain(Collection<? extends Serializable> idList) {
        for (Serializable id : idList) {
            baseDetailMapper.deleteByMainId(id.toString());
            baseMapper.deleteById(id);
        }
    }
 
    @Override
    public void addTotal(ToolsLossBound toolsLossBound) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         if (loginUser != null){
             toolsLossBound.setHandler(loginUser.getId());
         }
        toolsLossBound.setOrderCode(businessCodeRuleService.generateBusinessCodeSeq("LossBound"));
        toolsLossBound.setOrderStatus(OutBillStatus.DRAFT.getValue());
        save(toolsLossBound);
 
        List<ToolsLossBoundDetail> detailList = toolsLossBound.getToolsLossBoundDetailList();
        List<ToolsLossBoundDetail> newDetailList = new ArrayList<>();
 
        if (CollectionUtils.isNotEmpty(detailList)) {
            detailList.forEach(item -> {
                item.setLossBoundId(toolsLossBound.getId());
                newDetailList.add(item);
            });
 
            toolsLossBoundDetailService.saveBatch(newDetailList);
        }
    }
 
 
    @Override
    public IPage<ToolsLossBound> queryPageList(Page<ToolsLossBound> page, Map<String, String[]> parameterMap) {
        QueryWrapper<ToolsLossBound> queryWrapper = Wrappers.query();
        String[] orderCode = parameterMap.get("orderCode");
        if (orderCode != null && orderCode.length > 0) {
            queryWrapper.like("t.order_code", orderCode[0]);
        }
        String[] statuses = parameterMap.get("orderStatus");
        if (statuses != null && statuses.length > 0) {
            queryWrapper.eq("t.order_status", statuses[0]);
        }
        return this.baseMapper.queryPageList(page, queryWrapper);
    }
 
    @Override
    public void editTotal(ToolsLossBound toolsLossBound) {
        //删除所有明细
        toolsLossBoundDetailService.remove(new LambdaQueryWrapper<ToolsLossBoundDetail>()
                .eq(ToolsLossBoundDetail::getLossBoundId, toolsLossBound.getId()));
        ToolsLossBound toolsLossBound1 = BeanUtil.copyProperties(toolsLossBound, ToolsLossBound.class);
        this.baseMapper.updateById(toolsLossBound1);
        List<ToolsLossBoundDetail> detailList = CollectionUtil.newArrayList();
        toolsLossBound.getToolsLossBoundDetailList().forEach(item -> {
            item.setLossBoundId(toolsLossBound1.getId());
            detailList.add(item);
        });
        toolsLossBoundDetailService.saveBatch(detailList);
 
    }
 
    @Override
    public boolean submintOrder(String id) {
 
        ToolsLossBound toolsLossBound = this.getById(id);
        if (toolsLossBound == null) {
            return false;
        } else {
            toolsLossBound.setReviewer(toolsLossBound.getReviewer());
 
            flowCommonService.initActBusiness("报损单号:" + toolsLossBound.getOrderCode() + ";报损人: " + toolsLossBound.getLosser() + ";进行报损",
                    toolsLossBound.getId(), "IToolsStocktakingBoundService", "tools_Loss_Approval", null);
            Map<String, Object> variables = new HashMap<>();
            variables.put("dataId", toolsLossBound.getId());
            if (StrUtil.isEmpty(toolsLossBound.getReviewer())) {
                variables.put("organization", "新增工具报损单默认启动流程");
                variables.put("comment", "新增工具报损单默认启动流程");
            } else {
                variables.put("organization", toolsLossBound.getLossReason());
                variables.put("comment", toolsLossBound.getLossReason());
            }
            variables.put("proofreading", true);
            List<String> usernames = new ArrayList<>();
            usernames.add(toolsLossBound.getReviewer());
            variables.put("NextAssignee", usernames);
            Result result = flowDefinitionService.startProcessInstanceByKey("tools_Loss_Approval", variables);
            if (result != null) {
                toolsLossBound.setLossTime(new Date());
                toolsLossBound.setOrderStatus(OutBillStatus.SUBMITTED.getValue());
                //保存工单
                baseMapper.updateById(toolsLossBound);
                return result.isSuccess();
            }
            return true;
        }
    }
 
    @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 null;
    }
 
    @Override
    public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
        Object object = values.get("NextAssignee");
        return (List<String>) object;
    }
}