ludc
2023-07-14 36d3d9da36c71e65081e38cf9cfbd5e0ff6bfeed
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
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.vci.ubcs.flow.engine.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.flow.core.entity.ProcessTemplate;
import com.vci.ubcs.flow.core.utils.TaskUtil;
import com.vci.ubcs.flow.engine.mapper.ProcessTemplateMapper;
import com.vci.ubcs.flow.engine.service.ProcessTemplateService;
import com.vci.ubcs.starter.web.enumpck.ProcessTemplateTypeEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * 流程模板服务实现类
 *
 * @author wang1
 */
@Slf4j
@Service
@AllArgsConstructor
public class ProcessTemplateServiceImpl extends ServiceImpl<ProcessTemplateMapper, ProcessTemplate> implements ProcessTemplateService {
 
 
    /**
     * 新增/修改流程模板
     * @param processTemplate
     * @return
     */
    public void saveOrUpdateUser(ProcessTemplate processTemplate){
        //校验这个模板下,一类按钮只能有一个模板
        QueryWrapper<ProcessTemplate> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("button_type_key", processTemplate.getButtonTypeKey());
        queryWrapper.eq("template_id", processTemplate.getTemplateId());
        if(StringUtils.isNotEmpty(processTemplate.getId())) {//修改的时候,id为空就是新增
            queryWrapper.ne("id", processTemplate.getId());
        }
        if(baseMapper.selectOne(queryWrapper)!=null){
            throw new ServiceException(processTemplate.getButtonTypeValue()+"功能已经配置了流程!");
        }
        if(StringUtils.isEmpty(processTemplate.getButtonTypeValue())){
            processTemplate.setButtonTypeValue(ProcessTemplateTypeEnum.getTextByValue(processTemplate.getButtonTypeKey()));
        }
        //新增或者修改
        if(StringUtils.isEmpty(processTemplate.getId())){
            processTemplate.setCreated(Calendar.getInstance().getTime());
            processTemplate.setCreatedBy(TaskUtil.getTaskUser());
            processTemplate.setLastUpdated(Calendar.getInstance().getTime());
            processTemplate.setLastUpdatedBy(TaskUtil.getTaskUser());
        }
        this.saveOrUpdate(processTemplate);
 
    }
 
    /**
     * 删除流程模板
     * @param id
     * @return
     */
    public void deleteProcessTemplate(String id){
        baseMapper.deleteById(id);
    }
 
    /**
     * 流程模板用途
     * @return
     */
    public List<Map<String,String>> processTemplateType(){
        ProcessTemplateTypeEnum[] es = ProcessTemplateTypeEnum.values();
        List<Map<String,String>> ll = new ArrayList<>();
        for (ProcessTemplateTypeEnum p:es){
            Map<String,String> mi = new HashMap<>();
            String value = p.getValue();
            String text = p.getText();
            mi.put("codee",value);
            mi.put("namee",text);
            ll.add(mi);
        }
        return ll;
    }
}