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);
|
}
|
}
|