郑永安
2023-06-19 59e91a4e9ddaf23cebb12993c774aa899ab22d16
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
package com.gk.firework.Service.ServiceImpl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.firework.Config.Oauth2.IRedisService;
import com.gk.firework.Domain.Enterprise;
import com.gk.firework.Domain.EnterpriseLicense;
import com.gk.firework.Domain.EnterpriseResource;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Domain.Utils.Constants;
import com.gk.firework.Domain.Utils.Properties;
import com.gk.firework.Domain.Utils.StringUtils;
import com.gk.firework.Domain.Utils.UploadUtil;
import com.gk.firework.Domain.Vo.EnterpriseLicenseVo;
import com.gk.firework.Mapper.EnterpriseLicenseMapper;
import com.gk.firework.Service.EnterpriseLicenseService;
import com.gk.firework.Service.EnterpriseResourceService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.*;
 
@Service("enterpriseLicenseService")
public class EnterpriseLicenseServiceImpl extends ServiceImpl<EnterpriseLicenseMapper, EnterpriseLicense> implements EnterpriseLicenseService {
 
    @Autowired
    private EnterpriseLicenseMapper enterpriseLicenseMapper;
    @Autowired
    private EnterpriseResourceService enterpriseResourceService;
 
 
    /**
     * @Description: 根据创建时间排序,分页
     * @date 2021/3/24 14:57
     */
    @Override
    public IPage<EnterpriseLicense> selectPage(Long id, Page<EnterpriseLicense> page) {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("tabletype", Constants.LICENSE);
        List<EnterpriseLicense> list = enterpriseLicenseMapper.selectPages(page,params);
        page.setRecords(list);
        return page;
 
    }
 
 
    /**
    * @Description: 新增许可证信息
    * @date 2021/3/24 14:09
    */
    @Override
    @Transactional
    public void addEnterpriseLicense(EnterpriseLicenseVo enterpriseLicenseVo, UserInfo user) throws Exception {
        //新增信息
        EnterpriseLicense el = new EnterpriseLicense();
        el.setLicensenumber(enterpriseLicenseVo.getLicensenumber());
        el.setLicensename(enterpriseLicenseVo.getLicensename());
        el.setRanges(enterpriseLicenseVo.getRanges());
        el.setValidstarttime(enterpriseLicenseVo.getValidstarttime());
        el.setValidendtime(enterpriseLicenseVo.getValidendtime());
        el.setEnterpriseid(enterpriseLicenseVo.getEnterpriseid());
        el.setAuthority(enterpriseLicenseVo.getAuthority());
        el.setCreateby(user.getId());
        el.setCreatebyname(user.getUsername());
        el.setCreatetime(new Date());
        el.setValidflag(true);
        this.save(el);
 
        //新增资源
        List<EnterpriseResource> adds = null;
        if (enterpriseLicenseVo.getFile() != null && enterpriseLicenseVo.getFile().length > 0) {
            adds = new ArrayList<>();
            Date now = new Date();
            for (MultipartFile file : enterpriseLicenseVo.getFile()) {
                String name = UploadUtil.uploadFile(file, Properties.enterprisePath);
                EnterpriseResource er = new EnterpriseResource();
                er.setTabletype(Constants.LICENSE);
                er.setFilename(file.getOriginalFilename());
                er.setUrl(Properties.enterprise + name);
                er.setCreatetime(now);
                er.setCreateby(user.getId());
                er.setCreatebyname(user.getUsername());
                er.setBelongid(el.getId());
                er.setValidflag(true);
                adds.add(er);
            }
            //执行
            enterpriseResourceService.saveBatch(adds);
        }
 
    }
 
 
    /**
    * @Description: 修改许可证信息
    * @date 2021/3/24 14:35
    */
    @Override
    @Transactional
    public void modEnterpriseLicense(EnterpriseLicenseVo enterpriseLicenseVo, UserInfo user) throws Exception {
        //修改
        EnterpriseLicense el = new EnterpriseLicense();
        el.setId(enterpriseLicenseVo.getId());
        el.setLicensenumber(enterpriseLicenseVo.getLicensenumber());
        el.setLicensename(enterpriseLicenseVo.getLicensename());
        el.setRanges(enterpriseLicenseVo.getRanges());
        el.setAuthority(enterpriseLicenseVo.getAuthority());
        el.setValidstarttime(enterpriseLicenseVo.getValidstarttime());
        el.setValidendtime(enterpriseLicenseVo.getValidendtime());
        el.setEnterpriseid(enterpriseLicenseVo.getEnterpriseid());
        el.setAuthority(enterpriseLicenseVo.getAuthority());
        el.setValidflag(true);
        el.setUpdateby(user.getId());
        el.setUpdatebyname(user.getUsername());
        el.setUpdatetime(new Date());
        this.updateById(el);
        //删除资源
        List<Long> ids = enterpriseLicenseVo.getImgids();
 
        List<EnterpriseResource> dels = null;
        if (ids != null && ids.size() > 0) {
            dels = new ArrayList<>();
            Date now = new Date();
            for (Long id:ids) {
                EnterpriseResource er = new EnterpriseResource();
                er.setId(id);
                er.setValidflag(false);
                er.setUpdateby(user.getId());
                er.setUpdatebyname(user.getUsername());
                er.setUpdatetime(now);
                dels.add(er);
            }
            //删除
            enterpriseResourceService.updateBatchById(dels);
        }
 
        //2.新增
        List<EnterpriseResource> adds = null;
        if (enterpriseLicenseVo.getFile() !=null && enterpriseLicenseVo.getFile().length > 0) {
            adds = new ArrayList<>();
            Date now = new Date();
            for (MultipartFile file : enterpriseLicenseVo.getFile()) {
                String name = UploadUtil.uploadFile(file, Properties.enterprisePath);
                EnterpriseResource er = new EnterpriseResource();
                er.setTabletype(Constants.LICENSE);
                er.setFilename(file.getOriginalFilename());
                er.setUrl(Properties.enterprise + name);
                er.setCreatetime(now);
                er.setCreateby(user.getId());
                er.setCreatebyname(user.getUsername());
                er.setBelongid(enterpriseLicenseVo.getId());
                er.setValidflag(true);
                adds.add(er);
            }
 
            //执行
            enterpriseResourceService.saveBatch(adds);
        }
    }
 
    @Override
    public void delEnterpriseLicense(Long id, UserInfo user) {
        LambdaUpdateWrapper<EnterpriseLicense> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(EnterpriseLicense::getUpdatebyname, new Date())
                .set(EnterpriseLicense::getUpdateby, user.getId())
                .set(EnterpriseLicense::getUpdatebyname, user.getUsername())
                .set(EnterpriseLicense::getValidflag, false)
                .eq(EnterpriseLicense::getId, id);
        this.update(updateWrapper);
    }
 
    /**
    * @Description: 证书新增校验
    * @date 2021/4/6 14:41
    */
    @Override
    public void checkEnterpriseLicense(EnterpriseLicenseVo enterpriseLicenseVo) {
 
        if (StringUtils.isBlank(enterpriseLicenseVo.getLicensenumber())) {
            throw new BusinessException("许可证号不能为空");
        }
 
        if (StringUtils.isBlank(enterpriseLicenseVo.getLicensename())) {
            throw new BusinessException("许可证名称不能为空");
        }
 
        if (StringUtils.isBlank(enterpriseLicenseVo.getAuthority())) {
            throw new BusinessException("发证机关不能为空");
        }
 
        if (StringUtils.isBlank(enterpriseLicenseVo.getRanges())) {
            throw new BusinessException("许可范围不能为空");
        }
 
        if (enterpriseLicenseVo.getValidstarttime() == null || enterpriseLicenseVo.getValidendtime() == null) {
            throw new BusinessException("许可证有效期不能为空");
        }
    }
 
    @Override
    public void deleteByLicenseNumber(String licensecode) {
        if (StringUtils.isBlank(licensecode)) {
            throw new BusinessException("许可证编号为空");
        }
        LambdaUpdateWrapper<EnterpriseLicense> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(EnterpriseLicense::getValidflag, false)
                .eq(EnterpriseLicense::getLicensenumber, licensecode)
                .eq(EnterpriseLicense::getValidflag, true);
        this.update(updateWrapper);
 
    }
 
 
}