rk
2025-12-16 2cfceadff437135a255990ab9698788a48adb636
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package com.doumee.service.business.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CreationApplyMapper;
import com.doumee.dao.business.CreationApplyPlatMapper;
import com.doumee.dao.business.CreationMapper;
import com.doumee.dao.business.CreationPlatMapper;
import com.doumee.dao.business.join.CreationApplyJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.web.dto.CreateSystemUserDTO;
import com.doumee.dao.web.dto.CreationApplyDTO;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.system.model.SystemUserRole;
import com.doumee.service.business.CreationApplyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.service.system.SystemUserRoleService;
import com.doumee.service.system.SystemUserService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 创作中心申请表Service实现
 *
 * @author 江蹄蹄
 * @date 2023/03/21 15:48
 */
@Service
public class CreationApplyServiceImpl implements CreationApplyService {
 
    @Autowired
    private CreationApplyMapper creationApplyMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Autowired
    private CreationApplyJoinMapper creationApplyJoinMapper;
    @Autowired
    private CreationApplyPlatMapper creationApplyPlatMapper;
 
    @Autowired
    private CreationMapper creationMapper;
    @Autowired
    private CreationPlatMapper creationPlatMapper;
 
    @Autowired
    private SystemUserService systemUserService;
 
    @Autowired
    private SystemUserRoleService systemUserRoleService;
 
 
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    @Override
    public Integer create(CreationApplyDTO creationApplyDTO) {
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
 
        CreationApply  creationApply = new CreationApply();
 
        creationApply.setCreator(loginUserInfo.getId());
        creationApply.setEditor(loginUserInfo.getId());
        creationApply.setRemark(creationApplyDTO.getRemark());
        creationApply.setRealname(creationApplyDTO.getRealname());
        creationApply.setSex(creationApplyDTO.getSex() != null ? creationApplyDTO.getSex() : 2);
        creationApply.setEmail(creationApplyDTO.getEmail());
        creationApply.setPhone(creationApplyDTO.getPhone());
        creationApply.setBirthday(creationApplyDTO.getBirthday());
        creationApply.setIdcard(creationApplyDTO.getIdcard());
        creationApply.setIdcardImg(creationApplyDTO.getIdcardImg());
        creationApply.setIdcardImgBack(creationApplyDTO.getIdcardImgBack());
        creationApply.setStatus(Constants.ZERO);
        creationApply.setAreaId(creationApplyDTO.getAreaId());
        creationApply.setAddr(creationApplyDTO.getAddr());
        creationApply.setInfo(creationApplyDTO.getInfo());
        creationApply.setOrigin(creationApplyDTO.getOrigin());
        creationApply.setMemberId(creationApplyDTO.getMemberId());
//        creationApply.setCheckInfo(creationApplyDTO.getCheckInfo());
//        creationApply.setCheckDate(creationApplyDTO.getCheckDate());
        creationApplyMapper.insert(creationApply);
        List<CreationApplyDTO.CreationApplyPlatDTO> applyPlatList = creationApplyDTO.getApplyPlatList();
        applyPlatList.forEach(s->{
            CreationApplyPlat plat = new CreationApplyPlat();
            plat.setCreator(loginUserInfo.getId());
            plat.setEditor(loginUserInfo.getId());
            plat.setRemark(s.getRemark());
            plat.setName(s.getName());
            plat.setNickname(s.getNickname());
            plat.setFans(s.getFans());
            plat.setStatus(Constants.ZERO);
            plat.setObjId(creationApply.getId());
            creationApplyPlatMapper.insert(plat);
        });
        return creationApply.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        creationApplyMapper.deleteById(id);
    }
 
    @Override
    public void delete(CreationApply creationApply) {
        UpdateWrapper<CreationApply> deleteWrapper = new UpdateWrapper<>(creationApply);
        creationApplyMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        creationApplyMapper.deleteBatchIds(ids);
    }
 
    @Override
    @Transactional(rollbackFor = {BusinessException.class, Exception.class})
    public void updateById(CreationApply creationApply) {
 
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        creationApply.setEditor(user.getId());
        creationApply.setEditDate(new Date());
 
        CreationApplyPlat creationApplyPlat = new CreationApplyPlat();
        creationApplyPlat.setIsdeleted(Constants.ZERO);
        creationApplyPlat.setObjId(creationApply.getId());
        List<CreationApplyPlat> list = creationApplyPlatMapper.selectList(new QueryWrapper<>(creationApplyPlat));
 
        CreationApply result=creationApplyMapper.selectById(creationApply.getId());
        if(Objects.isNull(result)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), ResponseStatus.DATA_EMPTY.getMessage());
        }
        if(!Constants.equalsInteger(result.getStatus(),Constants.ZERO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "已审核,禁止操作");
        }
        CreateSystemUserDTO createSystemUserDTO=new CreateSystemUserDTO();
        if (Constants.equalsInteger(creationApply.getStatus(), Constants.ONE)) {
            //审核通过
            createSystemUserDTO=  createSystemUser(result,user);
            approved(creationApply, user,list,createSystemUserDTO.getId());
            //生成systemuser数据
        }
        creationApplyMapper.updateById(creationApply);
 
      /*  list.stream().forEach(s->{
            s.setEditDate(new Date());
            s.setEditor(user.getId());
            s.setStatus(Constants.ZERO);
            creationApplyPlatMapper.updateById(s);
        });*/
    }
 
 
    /**
     * 审核通过,往主表中添加数据,
     * @param creationApply
     * @param user
     * @param list
     */
    public void approved(CreationApply creationApply, LoginUserInfo user, List<CreationApplyPlat> list,Integer userid) {
        Creation query = new Creation();
        query.setIsdeleted(Constants.ZERO);
        query.setApplyId(creationApply.getId());
        Creation result = creationMapper.selectOne(new QueryWrapper<>(query));
        Creation creation = new Creation();
        BeanUtils.copyProperties(creation, creationApply);
        if (Objects.nonNull(result)) {
            //存在不作任何操作
          /*  creation.setId(result.getId());
            creation.setStatus(Constants.ZERO);
            creation.setEditDate(new Date());
            creation.setEditor(user.getId());
            creationMapper.updateById(creation);
 
            CreationPlat creationPlat=new CreationPlat();
            CreationPlat updateplat=new CreationPlat();
            list.stream().forEach(s->{
                BeanUtils.copyProperties(creationPlat, s);
                creationPlat.setId(null);
                creationPlat.setStatus(Constants.ZERO);
                creationPlat.setEditDate(new Date());
                creationPlat.setEditor(user.getId());
                creationPlatMapper.update(creationPlat,new UpdateWrapper<>(updateplat)
                .lambda().eq(CreationPlat::getObjId,creation.getId())
                );
            });*/
 
        } else {
            creation.setId(null);
            creation.setStatus(Constants.ZERO);
            creation.setCreateDate(new Date());
            creation.setCreator(user.getId());
            creation.setUserId(userid);
            creation.setStatus(Constants.ZERO);
            creationMapper.insert(creation);
 
             CreationPlat creationPlat=new CreationPlat();
             list.stream().forEach(s->{
                BeanUtils.copyProperties(creationPlat, s);
                creationPlat.setId(null);
                creationPlat.setStatus(Constants.ZERO);
                creationPlat.setCreateDate(new Date());
                creationPlat.setCreator(user.getId());
                creationPlat.setObjId(creation.getId());
                creationPlatMapper.insert(creationPlat);
            });
        }
    }
 
 
    public CreateSystemUserDTO createSystemUser( CreationApply result,  LoginUserInfo user ) {
        CreateSystemUserDTO  systemUser=new CreateSystemUserDTO();
        systemUser.setMemberId(result.getMemberId());
        systemUser.setUsername(result.getPhone());
        // 验证用户名
        SystemUser queryUserDto = new SystemUser();
        queryUserDto.setUsername(systemUser.getUsername());
        queryUserDto.setDeleted(Boolean.FALSE);
        SystemUser queryuser = systemUserService.findOne(queryUserDto);
        if (queryuser != null) {
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "用户名已存在");
        }
        //初始密码
        String initialPassword = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.INITIAL_PASSWORD).getCode() ;
        // 生成密码盐
        String salt = RandomStringUtils.randomAlphabetic(6);
        // 生成密码
        systemUser.setPassword(Utils.Secure.encryptPassword(initialPassword, salt));
        systemUser.setSalt(salt);
        // 创建用户记录
        systemUser.setRealname(result.getRealname());
        systemUser.setBirthday(result.getBirthday());
        systemUser.setSex(result.getSex()+"");
        systemUser.setEmail(result.getEmail());
        systemUser.setMobile(result.getPhone());
        systemUser.setCreateUser(user.getId());
        systemUser.setCreateTime(new Date());
        Integer userId = systemUserService.create(systemUser);
 
        String initialRoles= systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.INITIAL_ROLE).getCode() ;
        // 新增新的角色
        SystemUserRole newUserRole = new SystemUserRole();
        newUserRole.setUserId(userId);
        newUserRole.setRoleId(Integer.valueOf(initialRoles));
        systemUserRoleService.create(newUserRole);
        return systemUser;
 
    }
 
    @Override
    public void updateByIdInBatch(List<CreationApply> creationApplys) {
        if (CollectionUtils.isEmpty(creationApplys)) {
            return;
        }
        for (CreationApply creationApply : creationApplys) {
            this.updateById(creationApply);
        }
    }
 
    @Override
    public CreationApply findById(Integer id) {
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.ACTIVITY_FILE).getCode();
        MPJLambdaWrapper<CreationApply> queryWrapper = new MPJLambdaWrapper<>();
 
        queryWrapper.selectAll(CreationApply.class);
        queryWrapper.selectAs(Member::getNickname,CreationApply::getNikeName);
        queryWrapper.eq(CreationApply::getId,id);
        queryWrapper.leftJoin(Member.class,Member::getId,CreationApply::getMemberId);
        CreationApply creationApply=  creationApplyJoinMapper.selectJoinOne(CreationApply.class,queryWrapper);
        creationApply.setResourcePath(path);
        CreationApplyPlat creationApplyPlat=new CreationApplyPlat();
        creationApplyPlat.setIsdeleted(Constants.ZERO);
        creationApplyPlat.setObjId(id);
        List<CreationApplyPlat> list=creationApplyPlatMapper.selectList(new QueryWrapper<>(creationApplyPlat));
        creationApply.setApplyPlatList(list);
        return creationApply;
    }
 
    @Override
    public CreationApply findByMemberId(Integer memberIdId) {
 
        LambdaQueryWrapper<CreationApply> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CreationApply::getMemberId,memberIdId);
        queryWrapper.orderByDesc(CreationApply::getCreateDate).last("limit 1");
        return creationApplyMapper.selectOne(queryWrapper);
    }
 
    @Override
    public CreationApply findOne(CreationApply creationApply) {
        QueryWrapper<CreationApply> wrapper = new QueryWrapper<>(creationApply);
        return creationApplyMapper.selectOne(wrapper);
    }
 
    @Override
    public List<CreationApply> findList(CreationApply creationApply) {
        QueryWrapper<CreationApply> wrapper = new QueryWrapper<>(creationApply);
        return creationApplyMapper.selectList(wrapper);
    }
 
    @Override
    public PageData<CreationApply> findPage(PageWrap<CreationApply> pageWrap) {
        IPage<CreationApply> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<CreationApply> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
 
        queryWrapper.selectAll(CreationApply.class);
        queryWrapper.selectAs(Member::getNickname, CreationApply::getNikeName);
 
        queryWrapper.leftJoin(Member.class, Member::getId, CreationApply::getMemberId);
 
        queryWrapper.eq(pageWrap.getModel().getStatus() != null, CreationApply::getStatus, pageWrap.getModel().getStatus());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getRealname()), CreationApply::getRealname, pageWrap.getModel().getRealname());
        queryWrapper.eq(CreationApply::getIsdeleted, Constants.ZERO);
        queryWrapper.orderByDesc(CreationApply::getCreateDate);
 
        IPage<CreationApply> result = creationApplyJoinMapper.selectJoinPage(page, CreationApply.class, queryWrapper);
        return PageData.from(result);
    }
 
    @Override
    public long count(CreationApply creationApply) {
        QueryWrapper<CreationApply> wrapper = new QueryWrapper<>(creationApply);
        return creationApplyMapper.selectCount(wrapper);
    }
}