懒羊羊
2023-11-14 8286c62256f23bc2367a6729c0f46f84215e380b
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
package cn.stylefeng.guns.workflow.modular.service.impl;
 
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.workflow.modular.entity.Task;
import cn.stylefeng.guns.workflow.modular.mapper.TaskWaitingMapper;
import cn.stylefeng.guns.workflow.modular.model.params.TaskParam;
import cn.stylefeng.guns.workflow.modular.model.result.TaskResult;
import cn.stylefeng.guns.workflow.modular.service.TaskWaitingService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
 
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author fengshuonan
 * @since 2019-08-19
 */
@Service
public class TaskWaitingServiceImpl extends ServiceImpl<TaskWaitingMapper, Task> implements TaskWaitingService {
 
    @Override
    public void add(TaskParam param) {
        Task entity = getEntity(param);
        this.save(entity);
    }
 
    @Override
    public String getUserRoleString() {
        String account = LoginContextHolder.getContext().getUser().getAccount();
        String userRoleString = this.baseMapper.getUserRoleString(account);
        StringBuilder result = new StringBuilder("(");
 
        if (ToolUtil.isEmpty(userRoleString)) {
            return String.valueOf(result.append("''").append(")"));
        }
 
        if (userRoleString.contains(",")) {
            String[] split = userRoleString.trim().split(",");
            for (int i = 0; i < split.length; i++) {
                if (i < split.length - 1) {
                    result.append("'").append(split[i]).append("'").append(",");
                } else {
                    result.append("'").append(split[i]).append("'").append(")");
                }
            }
            return String.valueOf(result);
        } else if (ToolUtil.isNotEmpty(userRoleString)) {
            return String.valueOf(result.append("'").append(userRoleString).append("'").append(")"));
        }
        return "('')";
    }
 
    @Override
    public void delete(TaskParam param) {
        this.removeById(getKey(param));
    }
 
    @Override
    public void update(TaskParam param) {
        Task oldEntity = getOldEntity(param);
        Task newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }
 
    @Override
    public TaskResult findBySpec(TaskParam param) {
        return null;
    }
 
    @Override
    public List<TaskResult> findListBySpec(TaskParam param) {
        return null;
    }
 
    @Override
    public LayuiPageInfo findPageBySpec(TaskParam param) {
 
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("keywords", param.getKeywords());
        paramMap.put("lastStart", param.getLastStart());
        paramMap.put("lastEnd", param.getLastEnd());
 
        paramMap.put("USERNAME", LoginContextHolder.getContext().getUser().getAccount());
        String userRoleString = this.getUserRoleString();
        paramMap.put("RNUMBERS", userRoleString);
 
        Page pageContext = getPageContext();
        List<Map<String, Object>> maps = this.baseMapper.datalistPage(pageContext, paramMap);
        pageContext.setRecords(maps);
 
        return LayuiPageFactory.createPageInfo(pageContext);
    }
 
    private Serializable getKey(TaskParam param) {
        return param.getId();
    }
 
    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }
 
    private Task getOldEntity(TaskParam param) {
        return this.getById(getKey(param));
    }
 
    private Task getEntity(TaskParam param) {
        Task entity = new Task();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
 
}