lyfO_o
2022-08-26 57b39bca1c6a2b6e5d2b9acc2b0238c4ad5d6005
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/UserController.java
@@ -9,12 +9,14 @@
import com.gkhy.safePlatform.account.rpc.apimodel.model.req.query.AccountRPCQuery;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepUserRPCRespDTO;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.PersonalDetailRPCRespDTO;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
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;
@@ -33,8 +35,9 @@
    @RequestMapping("/page/list")
    public Object getUserPage(Principal principal, PageQuery<AccountRPCQuery> rpcQueryPageQuery) {
        return accountUserService.getAccountPage(Long.valueOf(principal.getName()), rpcQueryPageQuery);
    public Object getUserPage(Authentication authentication, PageQuery<AccountRPCQuery> rpcQueryPageQuery) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return accountUserService.getAccountPage(currentUser.getUid(), rpcQueryPageQuery);
    }
@@ -42,18 +45,18 @@
     * @Description: 获取部门下的用户列表
     */
    @RequestMapping(value = "/dep/list", method = RequestMethod.GET)
    public ResultVO<List<DepUserRPCRespDTO>> depUserList(Principal principal, Long depId) {
        String userId = principal.getName();
        return accountUserService.getDepList(Long.valueOf(userId), depId);
    public ResultVO<List<DepUserRPCRespDTO>> depUserList(Authentication authentication, Long depId) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return accountUserService.getDepList(currentUser.getUid(), depId);
    }
    /**
     * @Description: 个人信息
     */
    @RequestMapping(value = "/personal", method = RequestMethod.GET)
    public ResultVO<PersonalDetailRPCRespDTO> getPersonal(Principal principal) {
        String userId = principal.getName();
        return accountUserService.getPersonalAccountDetail(Long.valueOf(userId));
    public ResultVO<PersonalDetailRPCRespDTO> getPersonal(Authentication authentication) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return accountUserService.getPersonalAccountDetail(currentUser.getUid());
    }
@@ -62,9 +65,9 @@
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    public ResultVO<String> addUser(Principal principal, @RequestBody AccountAddRPCReqDTO accountAddRPCReqDTO) {
        String userId = principal.getName();
        return  accountUserService.addAccount(Long.valueOf(userId), accountAddRPCReqDTO);
    public ResultVO<String> addUser(Authentication authentication, @RequestBody AccountAddRPCReqDTO accountAddRPCReqDTO) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return  accountUserService.addAccount(currentUser, accountAddRPCReqDTO);
    }
@@ -74,9 +77,9 @@
    @RequestMapping(value = "/mod", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    public ResultVO<String> modUser(Principal principal, @RequestBody AccountModRPCReqDTO accountModRPCReqDTO) {
        String userId = principal.getName();
        return accountUserService.modAccount(Long.valueOf(userId), accountModRPCReqDTO);
    public ResultVO<String> modUser(Authentication authentication, @RequestBody AccountModRPCReqDTO accountModRPCReqDTO) {
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return accountUserService.modAccount(currentUser, accountModRPCReqDTO);
    }
@@ -85,9 +88,9 @@
     */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @PreAuthorize("hasRole('ROLE_admin')")
    public ResultVO<String> delUser(Principal principal, @RequestBody JSONObject json) {
    public ResultVO<String> delUser(Authentication authentication, @RequestBody JSONObject json) {
        Long uid = json.getLong("uid");
        String userId = principal.getName();
        return accountUserService.delAccount(Long.valueOf(userId), uid);
        ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal();
        return accountUserService.delAccount(currentUser, uid);
    }
}