futian.liu
2023-12-05 ceecebe477faf5a45b19f3b258f7add8f93b4583
consum-base/src/main/java/com/consum/base/controller/FinSysTenantUserController.java
@@ -1,12 +1,36 @@
package com.consum.base.controller;
import cn.hutool.core.util.ReflectUtil;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.core.utils.MapperUtil;
import com.consum.base.pojo.FinSysTenantUserSearchParam;
import com.consum.base.pojo.FinSysTenantUserUpdParam;
@@ -35,32 +59,12 @@
import com.walker.infrastructure.utils.PhoneNumberUtils;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
import cn.hutool.core.util.ReflectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
 * @Description 系统用户
@@ -78,7 +82,6 @@
    private UserServiceImpl userService;
    private FinSysTenantServiceImpl finSysTenantService;
    private RoleServiceImpl roleService;
@@ -86,16 +89,14 @@
    @Autowired
    private FinSysTenantDepartmentService finSysTenantDepartmentService;
    @Autowired
    public void setUserService(UserServiceImpl userService) {
        this.userService = userService;
    }
    @Autowired
    public FinSysTenantUserController(FinSysTenantServiceImpl finSysTenantService, FinSysTenantUserServiceImpl finSysTenantUserService,
        RoleServiceImpl roleService) {
    public FinSysTenantUserController(FinSysTenantServiceImpl finSysTenantService,
        FinSysTenantUserServiceImpl finSysTenantUserService, RoleServiceImpl roleService) {
        this.finSysTenantUserService = finSysTenantUserService;
        this.finSysTenantService = finSysTenantService;
        this.roleService = roleService;
@@ -107,7 +108,11 @@
     * @Date 2023/7/11 13:59
     */
    @RequestMapping("/select/list")
    public ResponseValue allocatedList(FinSysTenantUserSearchParam param) {
    public ResponseValue allocatedList() {
        FinSysTenantUserSearchParam param = CommonUtil.getObjFromReq(FinSysTenantUserSearchParam.class);
        FinSysTenantUserSearchParam param2 = new FinSysTenantUserSearchParam();
        CommonUtil.copyProperties(param, param2);
        param = param2;
        if (param.getTenantCode() == 0) {
            FinSysTenantUser user = new FinSysTenantUser();
            Long id = this.getCurrentUser().getId();
@@ -176,11 +181,10 @@
            ReflectUtil.setFieldValue(pager, fieldDatas, resultList);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("分页列表查询失败,原因:" + e);
        }
        return ResponseValue.success(pager);
    }
    @ApiOperation(value = "根据机构id查询用户", notes = "根据机构id查询用户")
    @ApiImplicitParam(name = "tenantId", value = "机构id", required = true, dataType = "Long", paramType = "query")
@@ -193,7 +197,6 @@
        return ResponseValue.success(result);
    }
    /**
     * @Description 新增
     * @Author wh
@@ -201,12 +204,17 @@
     */
    @PostMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    public ResponseValue add(@RequestBody FinSysTenantUser user) {
    public ResponseValue add() {
        FinSysTenantUser user = CommonUtil.getObjFromReqBody(FinSysTenantUser.class);
        FinSysTenantUser formInventoryParam = new FinSysTenantUser();
        CommonUtil.copyProperties(user, formInventoryParam);
        user = formInventoryParam;
        if (user == null) {
            return ResponseValue.error("参数为空");
        }
        //根据员工编号查询,如果存在则提示
        if (finSysTenantUserService.getByUserCode(user.getUserCode()) != null && finSysTenantUserService.getByUserCode(user.getUserCode()) > 0) {
        if (finSysTenantUserService.getByUserCode(user.getUserCode()) != null
            && finSysTenantUserService.getByUserCode(user.getUserCode()) > 0) {
            return ResponseValue.error("员工编号重复");
        }
        if (user.getTenantId() == null || "".equals(user.getTenantId()) || new Integer(user.getTenantId()) == 0) {
@@ -290,7 +298,6 @@
        return ResponseValue.success(1);
    }
    public static class ImportUserParam {
        @ExcelProperty("用户姓名")
@@ -371,7 +378,8 @@
     * @Date 2023/10/12 15:56
     */
    @PostMapping("/import")
    public ResponseValue importUser(@RequestParam String tenantId, @RequestParam String tenantCode, MultipartFile file) throws IOException {
    public ResponseValue importUser(@RequestParam String tenantId, @RequestParam String tenantCode, MultipartFile file)
        throws IOException {
        String originalFilename = file.getOriginalFilename();
        if (!"xls".equals(originalFilename.substring(originalFilename.lastIndexOf(".") + 1))) {
            return ResponseValue.error("文件格式有误!");
@@ -391,8 +399,10 @@
        EasyExcel.read(file.getInputStream(), ImportUserParam.class, new AnalysisEventListener<ImportUserParam>() {
            @Override
            public void invoke(ImportUserParam data, AnalysisContext context) {
                if (StringUtils.isEmpty(data.getUserName()) || StringUtils.isEmpty(data.getUserCode()) || StringUtils.isEmpty(data.getUserPhone())
                    || null == data.getSex() || StringUtils.isEmpty(data.getEmail()) || null == data.getSeq() || StringUtils.isEmpty(data.getRoleName())) {
                if (StringUtils.isEmpty(data.getUserName()) || StringUtils.isEmpty(data.getUserCode())
                    || StringUtils.isEmpty(data.getUserPhone()) || null == data.getSex()
                    || StringUtils.isEmpty(data.getEmail()) || null == data.getSeq()
                    || StringUtils.isEmpty(data.getRoleName())) {
                    throw new ImportUserParamVerifyException("单元格不能为空!");
                }
                //根据员工编号查询,如果存在则提示
@@ -412,7 +422,8 @@
                user.setTenantId(tenantId);
                user.setTenantCode(tenantCode);
                //设置角色
                Optional<S_role> sRole = roles.stream().filter(role -> role.getRole_name().equals(data.getRoleName())).findFirst();
                Optional<S_role> sRole =
                    roles.stream().filter(role -> role.getRole_name().equals(data.getRoleName())).findFirst();
                user.setRoleList(Arrays.asList(sRole.orElse(new S_role()).getRole_id()));
                user.setId(NumberGenerator.getLongSequenceNumber());
@@ -446,14 +457,16 @@
                    // 如果是某一个单元格的转换异常 能获取到具体行号 封装时异常
                    if (exception instanceof ExcelDataConvertException) {
                        ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
                        logger.error("第{}行,第{}列解析异常,数据为:{}", excelDataConvertException.getRowIndex(), excelDataConvertException.getColumnIndex() + 1,
                        logger.error("第{}行,第{}列解析异常,数据为:{}", excelDataConvertException.getRowIndex(),
                            excelDataConvertException.getColumnIndex() + 1,
                            excelDataConvertException.getCellData().getStringValue());
                        throw new IllegalStateException(
                            "第" + (excelDataConvertException.getRowIndex() + 1) + "行,第" + (excelDataConvertException.getColumnIndex() + 1) + "列解析异常,异常数据为:[ "
                        throw new IllegalStateException("第" + (excelDataConvertException.getRowIndex() + 1) + "行,第"
                            + (excelDataConvertException.getColumnIndex() + 1) + "列解析异常,异常数据为:[ "
                                + excelDataConvertException.getCellData().getStringValue() + " ]");
                    }
                    if (exception instanceof ImportUserParamVerifyException) {
                        throw new IllegalStateException("第" + context.readSheetHolder().getRowIndex() + "行, 解析错误:[ " + exception.getMessage() + " ]");
                        throw new IllegalStateException("第" + context.readSheetHolder().getRowIndex() + "行, 解析错误:[ "
                            + exception.getMessage() + " ]");
                    }
                    throw exception;
                }
@@ -536,7 +549,6 @@
            super(message);
        }
    }
    /**
     * @Description 编辑
@@ -696,7 +708,8 @@
            }
            // 查询 用户角色 TODO 临时解决 将来放配置文件中
            List<S_role> list = finSysTenantUserService.getByUserId(sysInfo.getSysUserId());  //已有的权限
            // 已有的权限
            List<S_role> list = finSysTenantUserService.getByUserId(sysInfo.getSysUserId());
            for (S_role s_role : list) {
                if (s_role.getRole_id() != null && s_role.getRole_id().equals(1690961420053L)) {
                    sysInfo.setKfStatus(1);
@@ -710,7 +723,8 @@
                if (select != null && select.size() > 0) {
                    FinSysTenant finSysTenant = select.get(0);
                    if (finSysTenant != null && finSysTenant.getParentId() != null) {
                        List<FinSysTenant> parents = finSysTenantService.select(new FinSysTenant(finSysTenant.getParentId()));
                        List<FinSysTenant> parents =
                            finSysTenantService.select(new FinSysTenant(finSysTenant.getParentId()));
                        if (parents != null && parents.size() > 0) {
                            sysInfo.setParentCode(parents.get(0).getCode());
                        }
@@ -721,7 +735,6 @@
        }
        return ResponseValue.success(sysInfo);
    }
    /**
     * 更新角色权限
@@ -747,7 +760,6 @@
        return ResponseValue.success(1);
    }
    /**
     * @Description 新增
     * @Author llb
@@ -765,7 +777,8 @@
            return ResponseValue.error(roleName + "的角色不存在");
        }
        //根据员工编号查询,如果存在则提示
        if (finSysTenantUserService.getByUserCode(user.getUserCode()) != null && finSysTenantUserService.getByUserCode(user.getUserCode()) > 0) {
        if (finSysTenantUserService.getByUserCode(user.getUserCode()) != null
            && finSysTenantUserService.getByUserCode(user.getUserCode()) > 0) {
            return ResponseValue.error("员工编号重复");
        }
        FinSysTenantUser sysInfo = this.getSysInfo();
@@ -843,7 +856,8 @@
        return ResponseValue.success(1);
    }
    private Set<String> picFormatArr = new HashSet<String>() {{
    private Set<String> picFormatArr = new HashSet<String>() {
        {
        add(".pjp");
        add(".svgz");
        add(".jxl");
@@ -860,7 +874,8 @@
        add(".pjpeg");
        add(".bmp");
        add(".webp");
    }};
        }
    };
    @PostMapping("/updatePerson")
    @Transactional(rollbackFor = Exception.class)
@@ -962,8 +977,7 @@
    @ApiOperation(value = "根据机构id查询部门中的用户", notes = "根据机构id查询部门中的用户")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "agencyId", value = "机构id", required = true, dataType = "Long", paramType = "query")
    })
        @ApiImplicitParam(name = "agencyId", value = "机构id", required = true, dataType = "Long", paramType = "query")})
    @GetMapping("/select/department")
    public ResponseValue selectDepartment(Long agencyId) {
        FinSysTenantVO finSysTenantVO = new FinSysTenantVO();
@@ -977,7 +991,8 @@
        // 部门
        FinSysTenantDepartment finSysTenantDepartment = new FinSysTenantDepartment();
        finSysTenantDepartment.setTenantId(agencyId);
        List<FinSysTenantDepartment> tenantDepartmentList = finSysTenantDepartmentService.select(finSysTenantDepartment);
        List<FinSysTenantDepartment> tenantDepartmentList =
            finSysTenantDepartmentService.select(finSysTenantDepartment);
        List<DepartmentVO> departmentVOList = Lists.newArrayList();
        tenantDepartmentList.forEach(department -> {
            DepartmentVO departmentVO = new DepartmentVO();
@@ -987,8 +1002,7 @@
            departmentVO.setName(department.getName());
            departmentVO.setType("department");
            String sql = "SELECT SYS_USER_ID,USER_NAME FROM "
                + "fin_sys_tenant_user "
            String sql = "SELECT SYS_USER_ID,USER_NAME FROM " + "fin_sys_tenant_user "
                + "WHERE SYS_DEPT_ID =:deptId AND SYS_USER_ID NOT IN(SELECT MANAGER_ID FROM base_warehouse_manager)";
            Map<String, Object> param = new HashMap<>();
            param.put("deptId", id);
@@ -1008,6 +1022,5 @@
        return ResponseValue.success(finSysTenantVO);
    }
}