|
@@ -1,12 +1,15 @@
|
|
package com.management.platform.service.impl;
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.management.platform.entity.Company;
|
|
import com.management.platform.entity.User;
|
|
import com.management.platform.entity.User;
|
|
|
|
+import com.management.platform.mapper.CompanyMapper;
|
|
import com.management.platform.mapper.UserMapper;
|
|
import com.management.platform.mapper.UserMapper;
|
|
import com.management.platform.service.UserService;
|
|
import com.management.platform.service.UserService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.MD5Util;
|
|
import com.management.platform.util.MD5Util;
|
|
|
|
+import com.management.platform.util.SnowFlake;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -25,6 +28,8 @@ import java.util.List;
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
|
@Resource
|
|
@Resource
|
|
private UserMapper userMapper;
|
|
private UserMapper userMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
|
|
|
//管理员登录网页端
|
|
//管理员登录网页端
|
|
@Override
|
|
@Override
|
|
@@ -91,15 +96,110 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
//删除普通用户
|
|
//删除普通用户
|
|
@Override
|
|
@Override
|
|
- public HttpRespMsg deleteUser(String userId) {
|
|
|
|
|
|
+ public HttpRespMsg deleteUser(String userId, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ //删除用户之前首先要验证权限
|
|
|
|
+ User requester = userMapper.selectById(request.getHeader("Token"));
|
|
|
|
+ User target = userMapper.selectById(userId);
|
|
|
|
+ if (target == null) {
|
|
|
|
+ httpRespMsg.setError("未找到用户");
|
|
|
|
+ } else {
|
|
|
|
+ if (!requester.getCompanyId().equals(target.getRole())) {
|
|
|
|
+ httpRespMsg.setError("只能删除同一公司人员的账号");
|
|
|
|
+ } else if (target.getRole() == 2) {
|
|
|
|
+ httpRespMsg.setError("负责人账号不可删除");
|
|
|
|
+ } else if (target.getRole() == 3 && requester.getRole() != 2) {
|
|
|
|
+ httpRespMsg.setError("只有负责人可以删除管理员账号");
|
|
|
|
+ } else {
|
|
|
|
+ userMapper.deleteById(userId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //编辑密码
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg editPassword(String originPassword, String newPassword, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ User requester = userMapper.selectById(request.getHeader("Token"));
|
|
|
|
+ //检验和之前的密码是否一致
|
|
|
|
+ if (MD5Util.getPassword(originPassword).equals(requester.getPassword())) {
|
|
|
|
+ requester.setPassword(MD5Util.getPassword(newPassword));
|
|
|
|
+ if (userMapper.updateById(requester) == 0) {
|
|
|
|
+ httpRespMsg.setError("操作失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //新增公司和负责人
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg createCompany(String companyName, String name, String phone) {
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
- User user = userMapper.selectById(userId);
|
|
|
|
- if (user == null) {
|
|
|
|
- httpRespMsg.setError("未找到用户");
|
|
|
|
- } else if (user.getRole() != 0) {
|
|
|
|
- httpRespMsg.setError("只能删除普通用户");
|
|
|
|
|
|
+ //首先检测用户名是否重复
|
|
|
|
+ if (userMapper.selectList(new QueryWrapper<User>().eq("phone", phone)).size() > 0) {
|
|
|
|
+ httpRespMsg.setError("电话号码重复");
|
|
} else {
|
|
} else {
|
|
- userMapper.deleteById(userId);
|
|
|
|
|
|
+ //首先生成一个新公司
|
|
|
|
+ Company company = new Company().setCompanyName(companyName);
|
|
|
|
+ companyMapper.insert(company);
|
|
|
|
+ //然后生成一个负责人
|
|
|
|
+ Long id = SnowFlake.nextId();
|
|
|
|
+ User user = new User()
|
|
|
|
+ .setName(name)
|
|
|
|
+ .setId(id.toString())
|
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
+ .setPhone(phone)
|
|
|
|
+ .setRole(1)
|
|
|
|
+ .setCompanyId(company.getId());
|
|
|
|
+ if (userMapper.insert(user) == 0) {
|
|
|
|
+ httpRespMsg.setError("操作失败");
|
|
|
|
+ } else {
|
|
|
|
+ httpRespMsg.data = user;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //新增用户
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg insertUser(String name, String phone, Integer role, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ User creator = userMapper.selectById(request.getHeader("Token"));
|
|
|
|
+ //管理员只能新增员工
|
|
|
|
+ if (creator.getRole() == 2 && role != 0) {
|
|
|
|
+ httpRespMsg.setError("管理员只能新增普通员工");
|
|
|
|
+ } else if (role == 3) {
|
|
|
|
+ httpRespMsg.setError("不可新增负责人");
|
|
|
|
+ } else {
|
|
|
|
+ //电话号码列 检测重名
|
|
|
|
+ if (userMapper.selectList(new QueryWrapper<User>().eq("phone", phone)).size() > 0) {
|
|
|
|
+ httpRespMsg.setError("电话号码重复");
|
|
|
|
+ } else {
|
|
|
|
+ Long id = SnowFlake.nextId();
|
|
|
|
+ User user = new User()
|
|
|
|
+ .setName(name)
|
|
|
|
+ .setId(id.toString())
|
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
+ .setPhone(phone)
|
|
|
|
+ .setRole(role)
|
|
|
|
+ .setCompanyId(creator.getCompanyId());
|
|
|
|
+ if (userMapper.insert(user) == 0) {
|
|
|
|
+ httpRespMsg.setError("操作失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
}
|
|
}
|
|
return httpRespMsg;
|
|
return httpRespMsg;
|
|
}
|
|
}
|