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.Permission; import com.example.demo.mapper.AdminMapper; import com.example.demo.mapper.PermissionMapper; import com.example.demo.service.PermissionService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.util.List; /** * @program: GOLD * @ClassName PermissionServiceImpl * @description: * @author: huangqizhen * @create: 2025−06-26 13:20 * @Version 1.0 **/ @Service public class PermissionServiceImpl implements PermissionService { @Autowired private PermissionMapper permissionMapper; @Autowired private AdminMapper adminMapper; @Override public List getposition(String token) { return permissionMapper.getposition(token); } @Override public List getmarket(String token) { return permissionMapper.getmarket(token); } @Override public PageInfo getpermission(Integer pageNum, Integer pageSize, Permission permission) { PageHelper.startPage(pageNum, pageSize); List list= permissionMapper.getPermission(permission); return new PageInfo<>(list); } @Override @Transactional public Integer addpermission(Admin admin) throws Exception { if(!ObjectUtils.isEmpty(adminMapper.getAdmin(admin.getAccount()))){ throw new Exception("账号已存在"); } if(ObjectUtils.isEmpty(admin.getAccount())){ throw new Exception("账号为空!"); } if(ObjectUtils.isEmpty( admin.getMarket())){ throw new Exception("地区为空!"); } if(ObjectUtils.isEmpty( admin.getPostiton())){ throw new Exception("职位为空!"); } if (ObjectUtils.isEmpty( admin.getRoleId())){ throw new Exception("权限类别为空!"); } if(ObjectUtils.isEmpty( admin.getAdminName())){ throw new Exception("用户名为空!"); } if(ObjectUtils.isEmpty( admin.getMachineId())){ throw new Exception("机器编号为空!"); } if (admin.getMachineId().contains(",")) { throw new Exception("机器编号格式错误"); } else { BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); admin.setPassword(passwordEncoder.encode(("123456"))); permissionMapper.addPermission(admin); AdminRole adminRole = new AdminRole(); adminRole.setAdminId(admin.getId()); adminRole.setRoleId(admin.getRoleId()); return permissionMapper.addadminRole(adminRole); } } @Override public List getRole(String token) { return permissionMapper.getRole(token); } @Override @Transactional public Integer deleteAdmin(Integer id) { if (id == null){ return -1; } permissionMapper.deleteAdminRole(id); return permissionMapper.deleteAdmin(id); } @Override public Integer updateAdminRole(AdminRole adminRole) { return permissionMapper.updateAdminRole(adminRole); } //修改管理员状态(启用 不启用) @Override public Integer upadatePermission(Admin admin) throws Exception { return permissionMapper.updatePermission(admin); } @Override public Object updateAdmin(Admin admin)throws Exception { if(ObjectUtils.isEmpty(admin.getAccount())){ throw new Exception("账号为空!"); } if(ObjectUtils.isEmpty( admin.getMarket())){ throw new Exception("地区为空!"); } if(ObjectUtils.isEmpty( admin.getPostiton())){ throw new Exception("职位为空!"); } if(ObjectUtils.isEmpty( admin.getAdminName())){ throw new Exception("用户名为空!"); } if(ObjectUtils.isEmpty( admin.getMachineId())){ throw new Exception("机器编号为空!"); } if (admin.getMachineId().contains(",")) { throw new Exception("机器编号格式错误"); } else { return permissionMapper.updateAdmin(admin); } } }