CompanyDictServiceImpl.java
5.1 KB
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
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.OperatorsDTO;
import com.subsidy.dto.company.AddCompanyDTO;
import com.subsidy.mapper.AdministerMapper;
import com.subsidy.mapper.DepartmentDictMapper;
import com.subsidy.mapper.RoleAdministerMappingMapper;
import com.subsidy.model.AdministerDO;
import com.subsidy.model.CompanyDictDO;
import com.subsidy.mapper.CompanyDictMapper;
import com.subsidy.model.DepartmentDictDO;
import com.subsidy.model.RoleAdministerMappingDO;
import com.subsidy.service.CompanyDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.administer.OperatorsVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 企业字典表 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-25
*/
@Service
public class CompanyDictServiceImpl extends ServiceImpl<CompanyDictMapper, CompanyDictDO> implements CompanyDictService {
@Autowired
private AdministerMapper administerMapper;
@Autowired
private RoleAdministerMappingMapper roleAdministerMappingMapper;
@Autowired
private DepartmentDictMapper departmentDictMapper;
public IPage<OperatorsVO> operators(OperatorsDTO operatorsDTO) {
Page pager = new Page(operatorsDTO.getPageNum(), operatorsDTO.getPageSize());
//判断该用户的角色
Integer count = roleAdministerMappingMapper.selectCount(new QueryWrapper<RoleAdministerMappingDO>()
.lambda()
.eq(RoleAdministerMappingDO::getAdministerId,operatorsDTO.getId())
.eq(RoleAdministerMappingDO::getRoleId,1));
if (count > 0){
operatorsDTO.setId(null);
}
return this.baseMapper.operators(pager, operatorsDTO.getCompanyName(), operatorsDTO.getId(),operatorsDTO.getUserName(),1);
}
public String addOperator(AddCompanyDTO addCompanyDTO) {
Integer count = this.baseMapper.selectCount(new QueryWrapper<CompanyDictDO>()
.lambda()
.eq(CompanyDictDO::getCompanyName, addCompanyDTO.getAccountName()));
Integer count1 = administerMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, addCompanyDTO.getAccountName()));
if (count > 0 || count1>0) {
throw new HttpException(20002);
}
CompanyDictDO companyDictDO =new CompanyDictDO();
BeanUtils.copyProperties(addCompanyDTO,companyDictDO);
this.baseMapper.insert(companyDictDO);
AdministerDO administerDO = new AdministerDO();
administerDO.setAccountName(addCompanyDTO.getAccountName());
administerDO.setCompanyId(companyDictDO.getId());
administerDO.setPassword("admin123");
administerDO.setStatus("1");
administerDO.setRole(1);
administerMapper.insert(administerDO);
RoleAdministerMappingDO roleAdministerMappingDO = new RoleAdministerMappingDO();
roleAdministerMappingDO.setAdministerId(administerDO.getId());
roleAdministerMappingDO.setRoleId(2L);
roleAdministerMappingMapper.insert(roleAdministerMappingDO);
//添加默认部门 名称为公司名称
DepartmentDictDO departmentDictDO = new DepartmentDictDO();
departmentDictDO.setCompanyId(companyDictDO.getId());
departmentDictDO.setDepartmentName(companyDictDO.getCompanyName());
//departmentDictDO.setParentId(1L);
departmentDictMapper.insert(departmentDictDO);
return ConstantUtils.ADD_SUCCESS;
}
public String deleteAdminister(CompanyDictDO companyDictDO) {
this.baseMapper.deleteById(companyDictDO.getId());
administerMapper.delete(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getCompanyId,companyDictDO.getId()));
return ConstantUtils.DELETE_SUCCESS;
}
public String updateAdminister(AddCompanyDTO addCompanyDTO) {
CompanyDictDO companyDictDO = new CompanyDictDO();
BeanUtils.copyProperties(addCompanyDTO,companyDictDO);
this.baseMapper.updateById(companyDictDO);
//查找企业管理员
AdministerDO administerDO = administerMapper.selectOne(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getCompanyId,addCompanyDTO.getId())
.eq(AdministerDO::getRole,1));
if (StringUtils.isNotBlank(addCompanyDTO.getAccountName())){
administerDO.setAccountName(addCompanyDTO.getAccountName());
}
if (StringUtils.isBlank(addCompanyDTO.getPassword())){
addCompanyDTO.setPassword(addCompanyDTO.getPassword());
}
administerMapper.updateById(administerDO);
return ConstantUtils.SET_SUCCESS;
}
}