fuliqi
2024-11-22 0526c88cd7082090fe658fd536562185527ba48a
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
package com.ycl.service.impl;
 
import com.ycl.common.core.text.Convert;
import com.ycl.service.IPurchaseService;
import com.ycl.system.domain.Purchase;
import com.ycl.mapper.PurchaseMapper;
import lombok.RequiredArgsConstructor;
import org.flowable.engine.HistoryService;
import org.flowable.engine.IdentityService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.HashMap;
import java.util.List;
 
/**
 * 采购Service业务层处理
 *
 * @author shenzhanwang
 * @date 2022-05-28
 */
@Service
@Transactional
@RequiredArgsConstructor
public class PurchaseServiceImpl implements IPurchaseService {
 
    private final PurchaseMapper purchaseMapper;
 
    private final RuntimeService runtimeService;
 
    private final TaskService taskService;
 
    private final IdentityService identityService;
 
    private final HistoryService historyService;
 
    /**
     * 查询采购
     *
     * @param id 采购主键
     * @return 采购
     */
    @Override
    public Purchase selectPurchaseById(Long id) {
        return purchaseMapper.selectPurchaseById(id);
    }
 
    /**
     * 查询采购列表
     *
     * @param purchase 采购
     * @return 采购
     */
    @Override
    public List<Purchase> selectPurchaseList(Purchase purchase) {
        return purchaseMapper.selectPurchaseList(purchase);
    }
 
    /**
     * 新增采购
     *
     * @param purchase 采购
     * @return 结果
     */
    @Override
    public int insertPurchase(Purchase purchase) {
        int row = purchaseMapper.insertPurchase(purchase);
        // 启动采购流程
        identityService.setAuthenticatedUserId(purchase.getApplyer());
        HashMap<String, Object> variables = new HashMap<>();
        variables.put("starter", purchase.getApplyer());
        variables.put("purchasemanager", purchase.getPurchasemanager());
        variables.put("financeName", purchase.getFinanceName());
        variables.put("pay", purchase.getPay());
        variables.put("managerName", purchase.getManagerName());
        variables.put("money", Double.parseDouble(purchase.getTotal()));
        runtimeService.startProcessInstanceByKey("purchase", String.valueOf(purchase.getId()), variables);
        return row;
    }
 
    /**
     * 修改采购
     *
     * @param purchase 采购
     * @return 结果
     */
    @Override
    public int updatePurchase(Purchase purchase) {
        return purchaseMapper.updatePurchase(purchase);
    }
 
    /**
     * 批量删除采购
     *
     * @param ids 需要删除的采购主键
     * @return 结果
     */
    @Override
    public int deletePurchaseByIds(String ids) {
        String[] keys = Convert.toStrArray(ids);
        for (String key : keys) {
            ProcessInstance process = runtimeService.createProcessInstanceQuery().processDefinitionKey("purchase").processInstanceBusinessKey(key).singleResult();
            if (process != null) {
                runtimeService.deleteProcessInstance(process.getId(), "删除");
            }
            // 删除历史数据
            HistoricProcessInstance history = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("purchase").processInstanceBusinessKey(key).singleResult();
            if (history != null) {
                historyService.deleteHistoricProcessInstance(history.getId());
            }
            purchaseMapper.deletePurchaseByIds(Convert.toStrArray(ids));
        }
        return keys.length;
    }
 
    /**
     * 删除采购信息
     *
     * @param id 采购主键
     * @return 结果
     */
    @Override
    public int deletePurchaseById(Long id) {
        return purchaseMapper.deletePurchaseById(id);
    }
}