ludc
2025-01-16 5203081b68e3a8dc139d1807b2f8774e4a00a82a
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
package com.vci.web.service.impl;
 
import com.vci.corba.common.PLException;
import com.vci.corba.wf.data.ProcessCategoryInfo;
import com.vci.corba.wf.data.ProcessDefinitionInfo;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.util.Lcm.Func;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.web.dao.WebProcessDaoI;
import com.vci.web.service.WebFlowServiceI;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 流程服务
 * @author ludc
 * @date 2025/1/14 17:28
 */
@Service
public class WebFlowServiceImpl implements WebFlowServiceI {
 
    /**
     * 平台调用客户端
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    @Autowired
    private WebProcessDaoI webProcessDaoI;
 
    /**
     * 流程分类全查询
     * @param parentId
     * @return
     * @throws PLException
     */
    @Override
    public List<ProcessCategoryInfo> getProcessCategories(String parentId) throws PLException {
        VciBaseUtil.alertNotNull(parentId,"流程分类父主键");
        ProcessCategoryInfo[] processCategories = platformClientUtil.getWFService().getProcessCategories(parentId);
        List<ProcessCategoryInfo> processCategoryInfoList = Arrays.asList(processCategories).stream().sorted((Comparator.comparing(o -> o.id))).collect(Collectors.toList());
        return processCategoryInfoList;
    }
 
    /**
     * 流程分类分页查询
     * @param baseQueryObject
     * @return
     */
    @Override
    public DataGrid<ProcessCategoryInfo> getProcessCategoriesByPage(BaseQueryObject baseQueryObject) throws PLException {
        String parentId = baseQueryObject.getConditionMap().get("parentId");
        VciBaseUtil.alertNotNull(parentId,"流程分类父主键");
        int page = baseQueryObject.getPage();
        int limit = baseQueryObject.getLimit();
        ProcessCategoryInfo[] processCategories = platformClientUtil.getWFService().getProcessCategoriesByPage(parentId,limit,page);
        List<ProcessCategoryInfo> processCategoryInfoList = Arrays.asList(processCategories).stream().sorted((Comparator.comparing(o -> o.id))).collect(Collectors.toList());
        DataGrid<ProcessCategoryInfo> dataGrid = new DataGrid<>();
        dataGrid.setData(processCategoryInfoList);
        dataGrid.setPage(page);
        dataGrid.setLimit(limit);
        //dataGrid.setTotal();
        return dataGrid;
    }
 
    /**
     * 保存流程分类
     * @param category
     * @return 返回主键
     */
    @Override
    public String saveProcessCategory(ProcessCategoryInfo category) throws PLException {
        VciBaseUtil.alertNotNull(category,"流程分类对象",category.name,"流程分类名称");
        this.checkNameExisted(category);
        if(Func.isBlank(category.parentId)){
            category.parentId = "root";
        }
        long time = new Date().getTime();
        String userId = WebUtil.getCurrentUserId();
        category.createTime = time;
        category.modifyTime = time;
        category.creator = userId;
        category.modifer = userId;
        return platformClientUtil.getWFService().saveProcessCategory(category);
    }
 
    /**
     * 修改流程分类
     * @param category
     * @return
     */
    @Override
    public boolean updateProcessCategory(ProcessCategoryInfo category) throws PLException {
        VciBaseUtil.alertNotNull(category,"流程分类对象",category.name,"流程分类名称");
        if(Func.isBlank(category.parentId)){
            category.parentId = "root";
        }
        this.checkNameExisted(category);
        category.modifyTime = new Date().getTime();
        category.modifer = WebUtil.getCurrentUserId();
        return platformClientUtil.getWFService().updateProcessCategory(category);
    }
 
    /**
     * 删除流程分类
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public boolean deleteProcessCategory(String id) throws Exception {
        VciBaseUtil.alertNotNull(id,"待删除流程分类的主键");
        ProcessDefinitionInfo[] processDefinitions = platformClientUtil.getWFService().getProcessDefinitions(id);
        if(processDefinitions.length>0){
            new VciBaseException( "分类下有模板,请先删除模版!");
        }
        return platformClientUtil.getWFService().deleteProcessCategory(id);
    }
 
    /**
     * 根据主键和名称查询流程分类是否存在
     * @param category
     * @return
     */
    private void checkNameExisted(ProcessCategoryInfo category) throws PLException{
        //判断是否存在相同名称的模板分类
        if(platformClientUtil.getWFService().existProcessCategory(category.id, category.name)){
            throw new VciBaseException("模板分类的名称不能重复!");
        }
    }
 
}