许鹏程
2023-05-24 de8e6ce8799342f58f80a5a0ad0b92d218cfbe87
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
package com.product.administration.service;
 
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
import com.product.admin.service.UserService;
import com.product.administration.config.CmnConst;
import com.product.administration.service.ide.ICooperatesService;
import com.product.common.lang.StringUtils;
import com.product.core.config.CoreConst;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldMetaEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import com.product.core.websocket.service.WebsocketMesssageServiceThread;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import com.product.tool.flow.service.FlowCoordinationService;
 
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * Copyright LX
 *
 * @Title: CooperatesService
 * @Project: product-server
 * @date: 2021年03月23日 14:51
 * @author: ZhouJie
 * @Description: 协同办公
 */
@Component
@Service
public class CooperatesService extends AbstractBaseService implements ICooperatesService {
    @Autowired
    public BaseDao baseDao;
    @Autowired
    public FlowCoordinationService flowCoordinationService;
    @Autowired
    PermissionService permissionService;
    @Autowired
    QueryFilterService queryFilterService;
    @Autowired
    @Qualifier("userOperService")
    UserService userService;
 
    /**
     * @Date: 2020-03-23 18:10
     * @Author: ZhouJie
     * @Description: 协同办公列表
     */
    public DataTableEntity getCooperateList(FieldSetEntity fs) throws BaseException {
        String queryFilter = BaseUtil.ifNull(BaseUtil.ifNotNull(queryFilterService.getQueryFilter(fs), (value) -> value + " and "), "");
 
        String filter = queryFilter + " created_by = ? ";
        int user_id = SpringMVCContextHolder.getCurrentUser().getUser_id();
        String sta = fs.getString("status");
        String[] status = sta.split(",");
        if (!StringUtils.isEmpty(sta)) {
            filter += " and " + BaseUtil.buildQuestionMarkFilter("status", status.length, true);
        }
        List<Object> params = new ArrayList<Object>();
        params.add(user_id);
        params.addAll(Arrays.asList(status));
        DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_OA_COOPERATES, filter, params.toArray(), null, CmnConst.CREATED_UTC_DATETIME + " DESC", fs.getInteger(CmnConst.PAGESIZE), fs.getInteger(CmnConst.CPAGE));
        baseDao.loadPromptData(dt);
        return dt;
    }
 
    /**
     * @Date: 2020-03-23 17:52
     * @Author: ZhouJie
     * @Description: 协同办公详情
     */
    public String getCooperateInfo(FieldSetEntity fs) throws BaseException {
        FieldSetEntity fse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_COOPERATES, fs.getString(CmnConst.UUID), true);
        DataTableEntity copsub = fse.getSubDataTable(CmnConst.PRODUCT_OA_COOPERATE_SUB);
        baseDao.loadPromptData(copsub);
 
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(" select ifnull(concat(tricode,'-',receiver) ,receiver) code,uuid,title,cooperate_uuid,grade,receiver as id,receiver,sender, ");
        stringBuilder.append(" receiver_name,(select user_name FROM product_sys_users where user_id=receiver) label,sender_name,status, ");
        stringBuilder.append(" tricode,opinion,handle_time,type,attachments from product_oa_cooperate_flow_node where cooperate_uuid=? ORDER BY tricode ");
        DataTableEntity dt = baseDao.listTable(stringBuilder.toString(), new Object[]{fs.getString("uuid")});
        JSONArray json = null;
        if (dt != null && dt.getRows() > 0) {
            DataTableEntity subData = baseDao.listTable(CmnConst.PRODUCT_OA_COOPERATE_FLOW_REPLY, BaseUtil.buildQuestionMarkFilter("parent_uuid", dt.getRows(), true), dt.getUuids());
            baseDao.loadPromptData(subData);
            Map<String, DataTableEntity> subMaps = new HashMap<>();
            for (int i = 0; i < subData.getRows(); i++) {
                FieldSetEntity ff = subData.getFieldSetEntity(i);
                String parent_uuid = ff.getString("parent_uuid");
                if (subMaps.get(parent_uuid) == null) {
                    subMaps.put(parent_uuid, new DataTableEntity());
                }
                subMaps.get(parent_uuid).addFieldSetEntity(ff);
            }
            dt.getMeta().setTableName(new Object[]{"product_oa_cooperate_flow_node"});
            DataTableEntity dd = dt.clones();
            for (int i = 0; i < dt.getRows(); i++) {
                String userId = dt.getString(i, "id");
                String userAvatar = userService.getUserAvatar(userId);
                if (!StringUtils.isEmpty(userAvatar)) {
                    if (i == 0) {
                        dt.setFieldValue(i, "avatar", userAvatar);
                    }
                    dd.setFieldValue(i, "avatar", userAvatar);
                }
                dd.getFieldSetEntity(i).addSubDataTable(subMaps.get(dt.getFieldSetEntity(i).getUUID()));
            }
            fse.addSubDataTable(dd);
            json = BaseUtil.dataTableToTreeData(dt, "code", "tricode", null, false);
        }
        String sql = " select count(*) sum from product_oa_cooperate_flow_node where cooperate_uuid =?  and status =? ";
        String sql1 = " select count(*) sum from product_oa_cooperate_flow_node where cooperate_uuid =? ";
        String sql0 = " select count(*) sum from product_oa_cooperate_flow_node where cooperate_uuid =?  and (status =? or status is null) ";
        FieldSetEntity fss = baseDao.getFieldSetEntityBySQL(sql1, new Object[]{fs.getString(CmnConst.UUID)}, true);
        FieldSetEntity fs0 = baseDao.getFieldSetEntityBySQL(sql0, new Object[]{fs.getString(CmnConst.UUID), 0}, true);
        FieldSetEntity fs1 = baseDao.getFieldSetEntityBySQL(sql, new Object[]{fs.getString(CmnConst.UUID), 1}, true);
        FieldSetEntity fs2 = baseDao.getFieldSetEntityBySQL(sql, new Object[]{fs.getString(CmnConst.UUID), 2}, true);
        if (fss.getInteger("sum") == null) {
            fse.setValue("totals", 0);//流程共有人数
        } else {
            fse.setValue("totals", fss.getInteger("sum") - 1);
        }
        if (fs0.getInteger("sum") == null) {
            fse.setValue("uncollectd", 0);//未收未办人数
        } else {
            fse.setValue("uncollectd", fs0.getInteger("sum"));
        }
        if (fs1.getInteger("sum") == null) {
            fse.setValue("received", 0);//已收未办人数
        } else {
            fse.setValue("received", fs1.getInteger("sum"));
        }
        if (fs2.getInteger("sum") == null) {
            fse.setValue("done", 0);//已收已办人数
        } else {
            fse.setValue("done", fs2.getInteger("sum") - 1);
        }
        int a = fse.getInteger("totals") - fse.getInteger("uncollectd") - fse.getInteger("received") - fse.getInteger("done");
        fse.setValue("not_yet", a);//未到环节人数
        if (fse.getString("attachment") == null || "".equals(fse.getString("attachment"))) {
            fse.setValue("attachment_number", 0);//附件数量
        } else {
            int b = 0;
            String str = fse.getString("attachment");
            String[] array = str.split(",");
            b = array.length;//存在符号的个数
            fse.setValue("attachment_number", b);
        }
        if ("1".equals(fs.getString("countersign_type"))) {
            fse.setValue("countersign_type", 1);
        }
        String emergency_degree = fse.getString("emergency_degree");
        baseDao.loadPromptData(fse);
        Map map = new HashMap();
        map.put("document_process", json);
        fse.setValue(CoreConst.API_RETURN_KEY_STATUS, fse.getString("status_save_value"));
//        String s = String.copyValueOf(emergency_degree.toCharArray(), 0, emergency_degree.length());
        fse.setValue("emergency_degree_show_value", fse.getString("emergency_degree"));
        fse.setValue("emergency_degree", emergency_degree);
        return BaseUtil.success(fse, map);
    }
 
    /**
     * @Date: 2020-03-23 14:56
     * @Author: ZhouJie
     * @Description: 新增协同办公
     */
    @Transactional
    public String addCooperate(FieldSetEntity fs) throws BaseException {
        fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
        fs.setValue("created_utc_datetime", new Date());
        String uuid = baseDao.add(fs);
        flowCoordinationService.saveCoordinationStartFlow(fs);
        return uuid;
    }
 
    /**
     * @Date: 2020-03-23 17:03
     * @Author: ZhouJie
     * @Description: 修改协同办公
     */
    @Transactional
    public boolean updateCooperate(FieldSetEntity fs) throws BaseException {
        fs.setValue("updated_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
        fs.setValue("updated_utc_datetime", new Date());
        fs.setValue("type", 0);
        Boolean flag = baseDao.update(fs);
        flowCoordinationService.saveCoordinationStartFlow(fs);
        return flag;
    }
 
    /**
     * @Date: 2020-03-23 17:30
     * @Author: ZhouJie
     * @Description: 删除协同办公
     */
    @Transactional
    public boolean deleteCooperate(FieldSetEntity fs) throws BaseException {
        String uuid = fs.getUUID();
        String[] uuids = uuid.split(",");
        return baseDao.delete(CmnConst.PRODUCT_OA_COOPERATES, BaseUtil.buildQuestionMarkFilter(CmnConst.UUID, uuids.length, true), uuids);
    }
 
    /**
     * @Date: 2020-04-01 16:30
     * @Author: ZhouJie
     * @Description: 协同办公送办
     */
    public void sendCooperate(FieldSetEntity fs) throws BaseException {
        DataTableEntity dt = fs.getSubDataTable("document_process");
        if (dt != null && dt.getRows() > 0) {
            for (int i = 0; i < dt.getRows(); i++) {
                FieldSetEntity fss = dt.getFieldSetEntity(i);
                if (fs.getString("flow_node_uuid") == null) {
                    if (fss.getString("sender_name") == null) {
                        fss.setValue("status", 2);
                    }
                }
            }
        }
        if (fs.getUUID() == null) {
            fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
            fs.setValue("created_utc_datetime", new Date());
            fs.setValue("start_time", new Date());//发起时间
            baseDao.add(fs);
        } else {
            fs.setValue("updated_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
            fs.setValue("updated_utc_datetime", new Date());
            fs.setValue("start_time", new Date());//发起时间
            if (fs.getInteger("type") == 4) {
                baseDao.update(fs);
            }
        }
        flowCoordinationService.saveCoordinationStartFlow(fs);
    }
 
    /**
     * @description: 暂存待办
     * @author: ZhouJie
     * @date: 2021-05-26 16:53
     */
    public void saveTodo(FieldSetEntity fs) throws BaseException {
        fs.setValue("status", 1);
        baseDao.update(fs);
    }
 
    /**
     * @description: 协同补充正文
     * @author: ZhouJie
     * @date: 2021-05-28 14:54
     */
    @Transactional
    public String addSupplyText(FieldSetEntity fs) {
        fs.setValue("cooperate_uuid", fs.getString("cooperate_uuid"));
        fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
        fs.setValue("created_utc_datetime", new Date());
        return baseDao.add(fs);
    }
 
    /**
     * @description: 协同办公催办
     * @author: ZhouJie
     * @date: 2021-06-03 17:20
     */
    public void urging(FieldSetEntity fse) {
        FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_COOPERATES, fse.getString("cooperate_uuid"), false);
        WebsocketMesssageServiceThread.getInstance().appendMessage(
                fse.getString("receiver"),
                "协同《" + fs.getString("title") + "》" + fse.getString("content"),
                "催办:",
                SpringMVCContextHolder.getCurrentUser().getUser_id(),
                CoreConst.SYSTEM_MESSAGE_TYPE_DEALT + "",
                CmnConst.PRODUCT_OA_COOPERATE_URL + "?" + CmnConst.UUID + "=" + fs.getString(CoreConst.UUID) + "&" + CmnConst.FIELD_COOPERATE_FLOW_NODE_UUID + "=" + fse.getUUID(),
                CmnConst.PRODUCT_OA_COOPERATES,
                fs.getUUID(),
                fs.getInteger(CoreConst.CREATED_BY),
                0,
                0
        );
    }
 
    /**
     * @description: 消息状态改为“已收未办”
     * @author: ZhouJie
     * @date: 2021-06-11 11:00
     */
    public boolean modifyState(String node_uuid) {
        String sql = " update product_oa_cooperate_flow_node set status=1 where status=0 and  uuid=?";
        return baseDao.executeUpdate(sql, new Object[]{node_uuid});
    }
 
    /**
     * @description: 消息处理列表
     * @author: ZhouJie
     * @date: 2021-06-16 11:34
     */
    public DataTableEntity getNowUserList(FieldSetEntity fs) {
        int user_id = SpringMVCContextHolder.getCurrentUser().getUser_id();
        String queryFilter = queryFilterService.getQueryFilter(fs);
        StringBuffer str = new StringBuffer();
        str.append("SELECT * FROM ( ");
        str.append(" select lc.*,lcn.uuid flow_node_uuid from product_oa_cooperate_flow_node as lcn LEFT JOIN product_oa_cooperates as lc ");
        str.append(" on lc.uuid=lcn.cooperate_uuid where lcn.receiver=? and lcn.status=? and sender_name is not null ");
        str.append(" ) a");
        if (!StringUtils.isEmpty(queryFilter)) {
            str.append(" where  ").append(queryFilter);
        }
        DataTableEntity dt = baseDao.listTable(str.toString(), new Object[]{user_id, 2}, fs.getInteger(CmnConst.PAGESIZE), fs.getInteger(CmnConst.CPAGE));
        dt.getMeta().addAliasTable("product_oa_cooperates", "lc");
        dt.getMeta().addAliasTable("product_oa_cooperate_flow_node", "lcn");
        baseDao.loadPromptData(dt);
        return dt;
    }
 
 
}