package com.gkhy.safePlatform.account.controller; import com.alibaba.fastjson.JSONObject; import com.gkhy.safePlatform.account.model.annotation.CommonLogEnable; import com.gkhy.safePlatform.account.model.dto.req.AccountAddReqDTO; import com.gkhy.safePlatform.account.model.dto.req.AccountModReqDTO; import com.gkhy.safePlatform.account.model.dto.req.AccountPwdForgetReqDTO; import com.gkhy.safePlatform.account.model.dto.resp.*; import com.gkhy.safePlatform.account.model.query.AccountQuery; import com.gkhy.safePlatform.account.model.query.UserScheduleQuery; import com.gkhy.safePlatform.account.service.AccountService; import com.gkhy.safePlatform.account.service.baseService.GroupStrategyUserTimeTableInfoService; import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.Module; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.query.PageQuery; import com.gkhy.safePlatform.commons.utils.PageUtils; import com.gkhy.safePlatform.commons.vo.ResultVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.security.Principal; import java.time.LocalDate; import java.util.List; /** * @Description: 用户模块 */ @RestController @RequestMapping("/account") public class UserController { @Autowired private AccountService accountService; @Autowired private GroupStrategyUserTimeTableInfoService groupStrategyUserTimeTableInfoService; /** * @Description: 用户列表 */ @RequestMapping(value = "/page/list", method = RequestMethod.POST) public ResultVO> getAccountPage(Authentication authentication, @RequestBody PageQuery pageQuery) { // 校验页信息 PageUtils.checkCheck(pageQuery); ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); return accountService.listAccountByPage(currentUser.getUid(), pageQuery); } /** * @Description: 个人信息 */ @RequestMapping(value = "/personal", method = RequestMethod.GET) public ResultVO getPersonal(Authentication authentication) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); PersonalDetailRespDTO personAccount = accountService.getPersonalAccountByUserId(currentUser.getUid()); return new ResultVO<>(ResultCodes.OK, personAccount); } /** * @Description: 新增用户信息 当前统一为员工 */ @RequestMapping(value = "/add", method = RequestMethod.POST) @PreAuthorize("hasRole('ROLE_admin')") @CommonLogEnable(module = Module.ACCOUNT,content = "新增用户") public ResultVO addUser(Authentication authentication, @RequestBody AccountAddReqDTO accountAddDto) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); accountService.addAccount(currentUser, accountAddDto); return new ResultVO<>(ResultCodes.OK); } /** * @Description: 修改用户信息 */ @RequestMapping(value = "/mod", method = RequestMethod.POST) @PreAuthorize("hasRole('ROLE_admin')") @CommonLogEnable(module = Module.ACCOUNT,content = "修改用户") public ResultVO modUser(Authentication authentication, @RequestBody AccountModReqDTO accountModDto) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); accountService.modAccount(currentUser, accountModDto); return new ResultVO<>(ResultCodes.OK); } /** * @Description: 删除用户信息 */ @RequestMapping(value = "/del", method = RequestMethod.POST) @PreAuthorize("hasRole('ROLE_admin')") @CommonLogEnable(module = Module.ACCOUNT,content = "删除用户") public ResultVO delUser(Authentication authentication, @RequestBody JSONObject json) { Long uid = json.getLong("uid"); ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); accountService.delAccount(currentUser, uid); return new ResultVO<>(ResultCodes.OK); } /** * @Description: 获取部门下的用户列表 */ @RequestMapping(value = "/dep/list", method = RequestMethod.GET) public ResultVO> depUserList(Authentication authentication,Long depId) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); List data = accountService.getDepUserList(currentUser.getUid(), depId); return new ResultVO<>(ResultCodes.OK,data); } /** * @Description: 获取部门下的用户列表 */ @RequestMapping(value = "/list", method = RequestMethod.GET) public ResultVO> list(Authentication authentication) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); List data = accountService.getUserList(currentUser.getUid()); return new ResultVO<>(ResultCodes.OK,data); } /** * @Description: 系统普通人员自行修改 */ @RequestMapping(value = "/pwd/forget", method = RequestMethod.POST) public ResultVO pwdForget(Authentication authentication, @RequestBody AccountPwdForgetReqDTO reqDTO) { accountService.pwdForget(reqDTO); return new ResultVO<>(ResultCodes.OK); } /** * @Description: 用户排班 */ @RequestMapping(value = "/schedule", method = RequestMethod.POST) public ResultVO> shiftDetail(Authentication authentication,@RequestBody UserScheduleQuery userScheduleQuery) { ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); List userShift = accountService.getUserScheduleInfo(currentUser, userScheduleQuery); return new ResultVO<>(ResultCodes.OK,userShift); } }