|
|
@ -3,9 +3,13 @@ package com.example.demo.serviceImpl; |
|
|
|
import com.example.demo.domain.entity.Admin; |
|
|
|
import com.example.demo.domain.entity.AdminRole; |
|
|
|
import com.example.demo.domain.entity.Role; |
|
|
|
import com.example.demo.domain.vo.AdminVo; |
|
|
|
import com.example.demo.domain.vo.Password; |
|
|
|
import com.example.demo.domain.vo.Permission; |
|
|
|
import com.example.demo.domain.vo.Result; |
|
|
|
import com.example.demo.mapper.AdminMapper; |
|
|
|
import com.example.demo.mapper.PermissionMapper; |
|
|
|
import com.example.demo.service.AdminService; |
|
|
|
import com.example.demo.service.PermissionService; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
@ -32,6 +36,9 @@ public class PermissionServiceImpl implements PermissionService { |
|
|
|
private PermissionMapper permissionMapper; |
|
|
|
@Autowired |
|
|
|
private AdminMapper adminMapper; |
|
|
|
@Autowired |
|
|
|
private AdminService adminService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<String> getposition(String token) { |
|
|
|
return permissionMapper.getposition(token); |
|
|
@ -45,7 +52,7 @@ public class PermissionServiceImpl implements PermissionService { |
|
|
|
@Override |
|
|
|
public PageInfo<Permission> getpermission(Integer pageNum, Integer pageSize, Permission permission) { |
|
|
|
PageHelper.startPage(pageNum, pageSize); |
|
|
|
List<Permission> list= permissionMapper.getPermission(permission); |
|
|
|
List<Permission> list = permissionMapper.getPermission(permission); |
|
|
|
return new PageInfo<>(list); |
|
|
|
} |
|
|
|
|
|
|
@ -53,31 +60,30 @@ public class PermissionServiceImpl implements PermissionService { |
|
|
|
@Transactional |
|
|
|
public Integer addpermission(Admin admin) throws Exception { |
|
|
|
|
|
|
|
if(!ObjectUtils.isEmpty(adminMapper.getAdmin(admin.getAccount()))){ |
|
|
|
if (!ObjectUtils.isEmpty(adminMapper.getAdmin(admin.getAccount()))) { |
|
|
|
throw new Exception("账号已存在"); |
|
|
|
} |
|
|
|
if(ObjectUtils.isEmpty(admin.getAccount())){ |
|
|
|
if (ObjectUtils.isEmpty(admin.getAccount())) { |
|
|
|
throw new Exception("账号为空!"); |
|
|
|
} |
|
|
|
if(ObjectUtils.isEmpty( admin.getMarket())){ |
|
|
|
if (ObjectUtils.isEmpty(admin.getMarket())) { |
|
|
|
throw new Exception("地区为空!"); |
|
|
|
} |
|
|
|
if(ObjectUtils.isEmpty( admin.getPostiton())){ |
|
|
|
if (ObjectUtils.isEmpty(admin.getPostiton())) { |
|
|
|
throw new Exception("职位为空!"); |
|
|
|
} |
|
|
|
if (ObjectUtils.isEmpty( admin.getRoleId())){ |
|
|
|
if (ObjectUtils.isEmpty(admin.getRoleId())) { |
|
|
|
throw new Exception("权限类别为空!"); |
|
|
|
} |
|
|
|
if(ObjectUtils.isEmpty( admin.getAdminName())){ |
|
|
|
if (ObjectUtils.isEmpty(admin.getAdminName())) { |
|
|
|
throw new Exception("用户名为空!"); |
|
|
|
} |
|
|
|
if(ObjectUtils.isEmpty( admin.getMachineId())){ |
|
|
|
if (ObjectUtils.isEmpty(admin.getMachineId())) { |
|
|
|
throw new Exception("机器编号为空!"); |
|
|
|
} |
|
|
|
if (admin.getMachineId().contains(",")) { |
|
|
|
throw new Exception("机器编号格式错误"); |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); |
|
|
|
admin.setPassword(passwordEncoder.encode(("123456"))); |
|
|
|
permissionMapper.addPermission(admin); |
|
|
@ -96,7 +102,7 @@ public class PermissionServiceImpl implements PermissionService { |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer deleteAdmin(Integer id) { |
|
|
|
if (id == null){ |
|
|
|
if (id == null) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
@ -115,32 +121,47 @@ public class PermissionServiceImpl implements PermissionService { |
|
|
|
return permissionMapper.updatePermission(admin); |
|
|
|
} |
|
|
|
|
|
|
|
//更新管理员信息 |
|
|
|
@Override |
|
|
|
public Object updateAdmin(Admin admin)throws Exception { |
|
|
|
|
|
|
|
if(ObjectUtils.isEmpty(admin.getAccount())){ |
|
|
|
public Result updateAdmin(AdminVo adminVo) throws Exception { |
|
|
|
// 校验账号是否为空(账号是唯一标识,必须存在) |
|
|
|
if (ObjectUtils.isEmpty(adminVo.getAccount())) { |
|
|
|
throw new Exception("账号为空!"); |
|
|
|
} |
|
|
|
if(ObjectUtils.isEmpty( admin.getMarket())){ |
|
|
|
// 校验用户名是否为空(管理员姓名为必填项) |
|
|
|
if (ObjectUtils.isEmpty(adminVo.getAdminName())) { |
|
|
|
throw new Exception("用户名为空!"); |
|
|
|
} |
|
|
|
// 校验地区是否为空(管理员所属地区为必填项) |
|
|
|
if (ObjectUtils.isEmpty(adminVo.getMarket())) { |
|
|
|
throw new Exception("地区为空!"); |
|
|
|
} |
|
|
|
if(ObjectUtils.isEmpty( admin.getPostiton())){ |
|
|
|
// 校验职位是否为空(管理员职位为必填项) |
|
|
|
if (ObjectUtils.isEmpty(adminVo.getPostiton())) { |
|
|
|
throw new Exception("职位为空!"); |
|
|
|
} |
|
|
|
|
|
|
|
if(ObjectUtils.isEmpty( admin.getAdminName())){ |
|
|
|
throw new Exception("用户名为空!"); |
|
|
|
} |
|
|
|
if(ObjectUtils.isEmpty( admin.getMachineId())){ |
|
|
|
// 校验机器编号是否为空(机器编号为必填项) |
|
|
|
if (ObjectUtils.isEmpty(adminVo.getMachineId())) { |
|
|
|
throw new Exception("机器编号为空!"); |
|
|
|
} |
|
|
|
if (admin.getMachineId().contains(",")) { |
|
|
|
// 校验机器编号格式(不允许包含逗号,避免与后续拼接逻辑冲突 |
|
|
|
if (adminVo.getMachineId().contains(",")) { |
|
|
|
throw new Exception("机器编号格式错误"); |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
|
|
|
|
return permissionMapper.updateAdmin(admin); |
|
|
|
} else { |
|
|
|
Admin admin = new Admin(); |
|
|
|
admin.setAccount(adminVo.getAccount()); |
|
|
|
admin.setAdminName(adminVo.getAdminName()); |
|
|
|
admin.setMarket(adminVo.getMarket()); |
|
|
|
admin.setPostiton(adminVo.getPostiton()); |
|
|
|
// 处理机器编号:若存在额外机器编号(machineIds),则与原编号拼接(用逗号分隔) |
|
|
|
if (adminVo.getMachineIds() == null) { |
|
|
|
admin.setMachineId(adminVo.getMachineId()); |
|
|
|
} else { |
|
|
|
admin.setMachineId(adminVo.getMachineId() + "," + adminVo.getMachineIds()); |
|
|
|
} |
|
|
|
admin.setRemark(adminVo.getRemark()); |
|
|
|
permissionMapper.updateAdmin(admin); |
|
|
|
return Result.success("成功"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|