| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package com.template.controller;
- import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
- import com.template.annotation.AWelcomeLevelLog;
- import com.template.annotation.AWelcomeLog;
- import com.template.annotation.AWelcomeLogMode;
- import com.template.annotation.AWelcomeTypeLog;
- import com.template.api.WelcomeAccountControllerAPI;
- import com.template.common.utils.AesUtils;
- import com.template.model.pojo.WelcomeAccount;
- import com.template.model.pojo.WelcomeOrg;
- import com.template.model.pojo.WelcomeRole;
- import com.template.model.result.CommonResult;
- import com.template.model.result.PageUtils;
- import com.template.model.vo.AccountAuthorityVo;
- import com.template.model.vo.WelcomeAccountVo;
- import com.template.services.WelcomeAccountService;
- import com.template.services.WelcomeOrgService;
- import com.template.services.WelcomeRoleService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author ceshi
- * @since 2025-06-13
- */
- @RestController
- public class WelcomeAccountController implements WelcomeAccountControllerAPI {
- @Autowired
- WelcomeAccountService welcomeAccountService;
- @Autowired
- WelcomeOrgService welcomeOrgService;
- @Autowired
- WelcomeRoleService welcomeRoleService;
- @Override
- @AWelcomeLog("新增用户管理")
- @AWelcomeTypeLog("新增")
- @AWelcomeLogMode("用户管理")
- @AWelcomeLevelLog("信息")
- public CommonResult saveAccount(WelcomeAccount welcomeAccount) {
- String account = welcomeAccount.getAccount();
- // 将密码加密
- String password = welcomeAccount.getPassword();
- String encPassword = AesUtils.encrypt(password);
- welcomeAccount.setPassword(encPassword);
- WelcomeAccount dataByAccount = welcomeAccountService.getDataByAccount(account);
- if (ObjectUtils.isNotEmpty(dataByAccount)) {
- return CommonResult.fail("已存在该账号");
- }
- welcomeAccountService.insertWelcomeAccount(welcomeAccount);
- return CommonResult.ok();
- }
- @Override
- @AWelcomeLog("删除用户管理")
- @AWelcomeTypeLog("删除")
- @AWelcomeLogMode("用户管理")
- @AWelcomeLevelLog("警告")
- public CommonResult deleteAccount(Integer accountId) {
- boolean result = welcomeAccountService.removeById(accountId);
- return result ? CommonResult.ok() : CommonResult.fail();
- }
- @Override
- @AWelcomeLog("编辑用户管理")
- @AWelcomeTypeLog("编辑")
- @AWelcomeLogMode("用户管理")
- @AWelcomeLevelLog("信息")
- public CommonResult updateAccount(WelcomeAccount welcomeAccount) {
- String account = welcomeAccount.getAccount();
- // 将密码加密
- String password = welcomeAccount.getPassword();
- String encPassword = AesUtils.encrypt(password);
- welcomeAccount.setPassword(encPassword);
- WelcomeAccount dataByAccount = welcomeAccountService.getDataByAccount(account);
- if (ObjectUtils.isNotEmpty(dataByAccount)) {
- Integer id = dataByAccount.getId();
- Integer id1 = welcomeAccount.getId();
- if (!id.equals(id1)) {
- return CommonResult.fail("已存在该账号");
- }
- }
- welcomeAccountService.updateWelcomeAccount(welcomeAccount);
- return CommonResult.ok();
- }
- @Override
- public CommonResult listAccount(int currentPage, int pageCount,Integer status,String keyWord,String startTime,String endTime) {
- PageUtils<WelcomeAccountVo> pageUtils= welcomeAccountService.listAccount(currentPage,pageCount,status,keyWord,startTime,endTime);
- List<WelcomeAccountVo> list = pageUtils.getList();
- for (WelcomeAccountVo record : list) {
- String collegeId = record.getCollegeId();
- List<WelcomeOrg> checkOrgList= new ArrayList<>();
- if (ObjectUtils.isNotEmpty(collegeId)) {
- List<String> checkOrg= Arrays.asList(collegeId.split(","));
- for(int i=0;i<checkOrg.size();i++){
- WelcomeOrg welcomeOrg= welcomeOrgService.getById(checkOrg.get(i));
- if (welcomeOrg!=null){
- checkOrgList.add(welcomeOrg);
- }
- }
- record.setWelcomeOrgList(checkOrgList);
- }
- if (ObjectUtils.isNotEmpty(record.getRoleId())) {
- WelcomeRole byId = welcomeRoleService.getById(record.getRoleId());
- record.setWelcomeRole(byId);
- }
- String password = record.getPassword();
- String decrypt = AesUtils.decrypt(password);
- record.setPassword(decrypt);
- }
- return CommonResult.ok(pageUtils);
- }
- @Override
- public CommonResult getAccountAuthority(Integer accountId) {
- WelcomeAccount welcomeAccount = welcomeAccountService.getById(accountId);
- if (ObjectUtils.isEmpty(welcomeAccount)) {
- return CommonResult.fail("无该账号");
- }
- Integer roleId = welcomeAccount.getRoleId();
- if (ObjectUtils.isEmpty(roleId)) {
- return CommonResult.fail("无角色权限");
- }
- String collegeId = welcomeAccount.getCollegeId();
- if (ObjectUtils.isEmpty(collegeId)) {
- return CommonResult.fail("无管理部门");
- }
- WelcomeRole welcomeRole = welcomeRoleService.getById(roleId);
- if (ObjectUtils.isEmpty(welcomeRole)) {
- return CommonResult.fail("无该角色");
- }
- List<String> checkOrg= Arrays.asList(collegeId.split(","));
- List<WelcomeOrg> checkOrgList= new ArrayList<>();
- for(int i=0;i<checkOrg.size();i++){
- WelcomeOrg welcomeOrg= welcomeOrgService.getById(checkOrg.get(i));
- if (welcomeOrg!=null){
- checkOrgList.add(welcomeOrg);
- }
- }
- AccountAuthorityVo vo = new AccountAuthorityVo();
- vo.setWelcomeRole(welcomeRole);
- vo.setWelcomeOrgList(checkOrgList);
- return CommonResult.ok(vo);
- }
- }
|