管道基础大数据平台系统开发-【后端】-Server
13693261870
2022-12-25 52288b740a2f767c0b29f84860a07f0bde634860
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
package com.lf.server.service.show;
 
import com.lf.server.entity.ctrl.DownloadReqEntity;
import com.lf.server.entity.show.ApplyEntity;
import com.lf.server.entity.show.FlowEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.Md5Helper;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.show.ApplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 数据申请
 * @author WWW
 */
@Service
public class ApplyService implements ApplyMapper {
    @Autowired
    ApplyMapper applyMapper;
 
    @Autowired
    FlowService flowService;
 
    @Override
    public Integer selectCount(String uname, Integer status, Timestamp start, Timestamp end) {
        uname = StringHelper.getLikeStr(uname);
 
        return applyMapper.selectCount(uname, status, start, end);
    }
 
    @Override
    public List<ApplyEntity> selectByPage(Integer userid, String uname, Integer status, Timestamp start, Timestamp end, Integer limit, Integer offset) {
        uname = StringHelper.getLikeStr(uname);
 
        return applyMapper.selectByPage(userid, uname, status, start, end, limit, offset);
    }
 
    @Override
    public List<ApplyEntity> selectAll() {
        return applyMapper.selectAll();
    }
 
    @Override
    public ApplyEntity selectById(int id) {
        return applyMapper.selectById(id);
    }
 
    @Override
    public UserEntity selectUserByDepid(Integer depid) {
        return applyMapper.selectUserByDepid(depid);
    }
 
    @Override
    public Integer selectSubmits(Integer userid) {
        return applyMapper.selectSubmits(userid);
    }
 
    @Override
    public List<FlowEntity> selectFlows(Integer applyid) {
        return applyMapper.selectFlows(applyid);
    }
 
    @Override
    public Integer insert(ApplyEntity entity) {
        return applyMapper.insert(entity);
    }
 
    @Override
    public Integer inserts(List<ApplyEntity> list) {
        return applyMapper.inserts(list);
    }
 
    @Override
    public Integer delete(int id) {
        return applyMapper.delete(id);
    }
 
    @Override
    public Integer deletes(List<Integer> ids) {
        return applyMapper.deletes(ids);
    }
 
    @Override
    public Integer update(ApplyEntity entity) {
        return applyMapper.update(entity);
    }
 
    @Override
    public Integer updates(List<ApplyEntity> list) {
        return applyMapper.updates(list);
    }
 
    @Override
    public Integer updateForDiscard(Integer id) {
        return applyMapper.updateForDiscard(id);
    }
 
    @Override
    public Integer updateForResubmit(Integer id) {
        return applyMapper.updateForResubmit(id);
    }
 
    @Override
    public Integer updateForReject(Integer applyid, Integer flowId) {
        return applyMapper.updateForReject(applyid, flowId);
    }
 
    /**
     * 插入数据申请
     */
    public Integer insertApply(UserEntity ue, DownloadReqEntity dr) {
        ApplyEntity apply = getApplyEntity(ue, dr);
        int rows = applyMapper.insert(apply);
        if (0 == rows) {
            return 0;
        }
 
        List<FlowEntity> list = getFlowEntities(apply.getId(), ue, dr);
        rows = flowService.inserts(list);
 
        return rows;
    }
 
    /**
     * 获取数据申请实体类
     */
    private ApplyEntity getApplyEntity(UserEntity ue, DownloadReqEntity dr) {
        String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd()));
 
        ApplyEntity apply = new ApplyEntity();
        apply.setUserid(ue.getId());
        apply.setDepids(StringHelper.join(dr.getIds(), ","));
        apply.setTabs(StringHelper.join(dr.getTabs(), ","));
        apply.setEntities(StringHelper.join(dr.getEntities(), ","));
        apply.setWkt(dr.getWkt());
        apply.setPwd(dbPwd);
        apply.setStatus(0);
        apply.setCount(dr.getIds().size());
        apply.setDescr(dr.getDescr());
        apply.setCreateUser(ue.getId());
 
        return apply;
    }
 
    /**
     * 获取申请流程实体类集合
     */
    private List<FlowEntity> getFlowEntities(Integer applyId, UserEntity ue, DownloadReqEntity dr) {
        List<FlowEntity> list = new ArrayList<>();
        for (Integer depid : dr.getIds()) {
            UserEntity user = selectUserByDepid(depid);
            if (null == user) {
                continue;
            }
 
            FlowEntity flow = new FlowEntity();
            flow.setApplyid(applyId);
            flow.setDepid(depid);
            flow.setUserid(user.getId());
            flow.setStatus(0);
            flow.setDescr(null);
            flow.setCreateUser(ue.getId());
 
            list.add(flow);
        }
 
        return list;
    }
}