forked from gzzfw/backEnd/gz-dyh

liyj
2024-08-24 981634fa893b787f2991d99ebf60276eee8d28c7
dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/controller/web/CtUserWebController.java
@@ -1,39 +1,23 @@
package cn.huge.module.ctuser.controller.web;
import cn.huge.base.common.dto.SelectTermDTO;
import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.base.common.utils.ReturnFailUtils;
import cn.huge.base.common.utils.ReturnSucUtils;
import cn.huge.base.common.utils.SelectTermUtils;
import cn.huge.base.config.CurrentUser;
import cn.huge.module.ctrole.domain.po.CtRole;
import cn.huge.module.ctrole.service.CtRoleService;
import cn.huge.module.ctuser.domain.po.*;
import cn.huge.module.ctuser.dto.CtUserSaveDTO;
import cn.huge.module.ctuser.service.*;
import cn.huge.module.cust.constant.RoleBaseEnum;
import cn.huge.module.cust.constant.UserBaseConsts;
import cn.huge.module.cust.dto.CtUserDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
 * @title: 客户用户表接口api
 * @description: 客户用户表接口api
 * @title: 客户用户表接口api-web端
 * @description: 客户用户表接口api-web端
 * @company: hugeinfo
 * @author: liyj
 * @time: 2024-08-19 20:04:19
@@ -279,10 +263,10 @@
     * @throws Exception
     */
    @PostMapping("/saveCtUser")
    public Object saveCtUser(@RequestBody CtUser ctUser, @CurrentUser String userId) {
    public Object saveCtUser(@RequestBody CtUserSaveDTO ctUserSaveDTO, @CurrentUser String userId) {
        try {
            // 保存更新用户信息
            service.webSaveCtUser(ctUser, userId);
            service.webSaveCtUser(ctUserSaveDTO, userId);
            return ReturnSucUtils.getRepInfo();
        } catch (Exception e) {
            return ReturnFailUtils.getRepInfo();
@@ -299,69 +283,15 @@
    @GetMapping("/listSelectTerm")
    public Object listSelectTerm(@CurrentUser String userId) {
        try {
            Map<String, Object> result = Maps.newHashMap();
            // 获取当前登录用户
            CtUser loginUser = service.getById(userId);
            // 组织条件
            QueryWrapper<CtUnit> ctUnitQueryWrapper = new QueryWrapper<>();
            ctUnitQueryWrapper.eq("cust_id", loginUser.getCustId());
            List<CtUnit> ctUnits = ctUnitService.list(ctUnitQueryWrapper);
            List<SelectTermDTO> unitSelectTerms = new ArrayList<>();
            for (CtUnit ctUnit: ctUnits) {
                SelectTermDTO unitSelectTerm = new SelectTermDTO();
                unitSelectTerm.setValue(ctUnit.getId());
                unitSelectTerm.setLabel(ctUnit.getUnitName());
                unitSelectTerm.setParentId(ctUnit.getParentId());
                unitSelectTerms.add(unitSelectTerm);
                // 部门条件
                QueryWrapper<CtDept> ctDeptQueryWrapper = new QueryWrapper<>();
                ctDeptQueryWrapper.eq("unit_id", ctUnit.getId());
                List<CtDept> ctDepts = ctDeptService.list(ctDeptQueryWrapper);
                if (CollectionUtils.isNotEmpty(ctDepts)) {
                    List<SelectTermDTO> deptSelectTerms = new ArrayList<>();
                    for (CtDept ctDept : ctDepts) {
                        SelectTermDTO deptSelectTerm = new SelectTermDTO();
                        deptSelectTerm.setValue(ctDept.getId());
                        deptSelectTerm.setLabel(ctDept.getName());
                        deptSelectTerm.setParentId(ctDept.getParentId());
                        deptSelectTerms.add(deptSelectTerm);
                    }
                    List<SelectTermDTO> depts = SelectTermUtils.createTreeByRoot(deptSelectTerms);
                    unitSelectTerm.setChainList(depts);
                }
            }
            result.put("units", SelectTermUtils.createTreeByFirst(unitSelectTerms, loginUser.getUnitId()));
            // 角色条件
            QueryWrapper<CtRole> ctRoleQueryWrapper = new QueryWrapper<>();
            ctRoleQueryWrapper.eq("unit_id", loginUser.getUnitId());
            //判断是否为村居(村居不应该有调委会管理员角色)
            QueryWrapper<CtUnit> ctUnitQueryWrapper1 = new QueryWrapper<>();
            ctUnitQueryWrapper1.eq("id", loginUser.getUnitId()).eq("cust_id", loginUser.getCustId())
                    .select("unit_type");
            CtUnit ctUnit = ctUnitService.getOne(ctUnitQueryWrapper1);
            if(UserBaseConsts.UNIT_TYPE_4.equals(ctUnit.getUnitType())){
                ctRoleQueryWrapper.ne("role_code", RoleBaseEnum.ROLE_9.getIndex());
            }
            List<CtRole> ctRoleList = ctRoleService.list(ctRoleQueryWrapper);
            List<SelectTermDTO> roleSelectTerms = new ArrayList<>();
            for (CtRole ctRole: ctRoleList){
                SelectTermDTO selectTerm = new SelectTermDTO();
                selectTerm.setValue(ctRole.getRoleCode());
                selectTerm.setLabel(ctRole.getName());
                roleSelectTerms.add(selectTerm);
            }
            result.put("roles", roleSelectTerms);
            return ReturnSucUtils.getRepInfo( "查询成功", result);
            Map<String, Object> result = service.webListSelectTerm(userId);
            return ReturnSucUtils.getRepInfo(result);
        } catch (Exception e) {
            log.error("Controller接口[CtUserController.listSelectTerm]请求异常:"+e, e);
            return ReturnFailUtils.getRepInfo("查询失败", null);
            return ReturnFailUtils.getRepInfo();
        }
    }
    /**
     * 条件分页查询人员信息
     * web端-人员信息管理-人员列表
     * @url {ctx}/api/v1/ctUser/pageQuery
     * @param page 页码
     * @param size 每页数量
@@ -371,79 +301,11 @@
    public Object pageQuery(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size,
                            @CurrentUser String userId) {
        try {
            // 获取当前登录用户
            CtUserDTO loginUser = service.clientGetUserAll(userId);
            Map<String, Object> result = Maps.newHashMap();
            Map<String, Object> terms = getParameter();
            if (RoleBaseEnum.checkAdminPower(loginUser)){
                terms.put("custId", loginUser.getCustId());
            }else if (RoleBaseEnum.checkCourtOrUnitPower(loginUser.getRoleCodes())){
                terms.put("custId", loginUser.getCustId());
                String unitId = (String) terms.get("unitId");
                if (StringUtils.isEmpty(unitId)){
                    terms.put("unitId", loginUser.getUnitId());
                }
            }else {
                terms.put("custId", loginUser.getCustId());
                terms.put("id", loginUser.getId());
            }
            Sort sort = Sort.by(Sort.Direction.DESC, "t1.create_time");
            PageRequest pageRequest = PageRequest.of(page-1, size, sort);
            Page<CtUser> ctUserPage = service.pageUserAndRole(pageRequest, terms);
            QueryWrapper<CtAccount> accountQueryWrapper = new QueryWrapper<>();
            QueryWrapper<CtUserole> ctUseroleQueryWrapper = new QueryWrapper<>();
            QueryWrapper<CtUsepost> ctUsepostQueryWrapper = new QueryWrapper<>();
            for (CtUser ctUser: ctUserPage){
                accountQueryWrapper.clear();
                // 密码
                accountQueryWrapper.eq("acc_type", UserBaseConsts.ACC_TYPE_1);
                accountQueryWrapper.eq("user_id", ctUser.getId());
                CtAccount ctAccount = ctAccountService.getOne(accountQueryWrapper);
                if (ObjectUtils.isNotEmpty(ctAccount)){
                    ctUser.setAcc(ctAccount.getAcc());
                    ctUser.setCipher(ctAccount.getCipherOpen());
                }
                // 角色
                ctUseroleQueryWrapper.clear();
                ctUseroleQueryWrapper.eq("user_id", ctUser.getId());
                List<CtUserole> ctUseroleList = ctUseroleService.list(ctUseroleQueryWrapper);
                if (ObjectUtils.isNotEmpty(ctUseroleList)){
                    for (CtUserole ctUserole: ctUseroleList){
                        ctUserole.setRoleId(ctUserole.getRoleCode());
                    }
                    ctUser.setCtUseroleList(ctUseroleList);
                }
                // 岗位
                ctUsepostQueryWrapper.clear();
                ctUsepostQueryWrapper.eq("user_id", ctUser.getId());
                List<CtUsepost> ctUsepostList = ctUsepostService.list(ctUsepostQueryWrapper);
                if (ObjectUtils.isNotEmpty(ctUsepostList)) {
                    ctUser.setCtUsepostList(ctUsepostList);
                }
            }
            result.put("ctUserPage", ctUserPage);
            terms = Maps.newHashMap();
            // 生效名额
            terms.put("status", UserBaseConsts.USER_STATUS_1);
            terms.put("custId", loginUser.getCustId());
            if (RoleBaseEnum.checkAdminPower(loginUser)){
                terms.put("custId", loginUser.getCustId());
            }else if (RoleBaseEnum.checkCourtOrUnitPower(loginUser.getRoleCodes())){
                terms.put("custId", loginUser.getCustId());
                String unitId = (String) terms.get("unitId");
                if (StringUtils.isEmpty(unitId)){
                    terms.put("unitId", loginUser.getUnitId());
                }
            }else {
                terms.put("custId", loginUser.getCustId());
                terms.put("id", loginUser.getId());
            }
            long countZzStatus = service.countTerms(terms);
            result.put("countZzStatus", countZzStatus);
            return ReturnSucUtils.getRepInfo( "处理成功", result);
            Map<String, Object> result = service.webPageQuery(page, size, terms, userId);
            return ReturnSucUtils.getRepInfo(result);
        } catch (Exception e) {
            log.error("Controller接口[CtUserController.pageQuery]请求异常:"+e, e);
            return ReturnFailUtils.getRepInfo(e.getMessage(), null);
            return ReturnFailUtils.getRepInfo();
        }
    }
}