consum-base/src/main/java/com/consum/base/controller/FinSysTenantUserController.java
@@ -1,29 +1,6 @@
package com.consum.base.controller;
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 cn.hutool.core.util.ReflectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
@@ -34,6 +11,7 @@
import com.consum.base.pojo.FinSysTenantUserSearchParam;
import com.consum.base.pojo.FinSysTenantUserUpdParam;
import com.consum.base.pojo.ImportUserParam;
import com.consum.base.pojo.request.FinSysTenantUserParam;
import com.consum.base.pojo.response.DepartmentVO;
import com.consum.base.pojo.response.FinSysTenantUserVO;
import com.consum.base.pojo.response.FinSysTenantVO;
@@ -53,18 +31,22 @@
import com.iplatform.model.po.S_role;
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.infrastructure.utils.NumberGenerator;
import com.walker.infrastructure.utils.PhoneNumberUtils;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.infrastructure.utils.*;
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 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.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.*;
/**
 * @Description 系统用户
@@ -206,68 +188,71 @@
    @Transactional(rollbackFor = Exception.class)
    public ResponseValue add() {
        FinSysTenantUser user = CommonUtil.getObjFromReqBody(FinSysTenantUser.class);
        FinSysTenantUser formInventoryParam = new FinSysTenantUser();
        CommonUtil.copyProperties(user, formInventoryParam);
        user = formInventoryParam;
        if (user == null) {
        FinSysTenantUser tenantUser = new FinSysTenantUser();
        CommonUtil.copyProperties(user, tenantUser);
        if (tenantUser == null) {
            return ResponseValue.error("参数为空");
        }
        // 根据员工编号查询,如果存在则提示
        if (finSysTenantUserService.getByUserCode(user.getUserCode()) != null
            && finSysTenantUserService.getByUserCode(user.getUserCode()) > 0) {
        if (finSysTenantUserService.getByUserCode(tenantUser.getUserCode()) != null
            && finSysTenantUserService.getByUserCode(tenantUser.getUserCode()) > 0) {
            return ResponseValue.error("员工编号重复");
        }
        if (user.getTenantId() == null || "".equals(user.getTenantId()) || new Integer(user.getTenantId()) == 0) {
        if (StringUtils.isEmpty(tenantUser.getTenantId()) || "0".equals(tenantUser.getTenantId())) {
            return ResponseValue.error("添加时请选择区县");
        }
        if (user.getTenantCode() == null || "".equals(user.getTenantCode()) || new Integer(user.getTenantCode()) == 0) {
        if (StringUtils.isEmpty(tenantUser.getTenantCode()) || "0".equals(tenantUser.getTenantCode())) {
            return ResponseValue.error("添加时请选择区县");
        }
        // 插入系统用户
        user.setId(NumberGenerator.getLongSequenceNumber());
        user.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis()));
        user.setCreateBy(this.getCurrentUser().getUser_name());
        user.setUpdateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis()));
        user.setUpdateBy(this.getCurrentUser().getUser_name());
        tenantUser.setId(NumberGenerator.getLongSequenceNumber());
        tenantUser.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis()));
        tenantUser.setCreateBy(this.getCurrentUser().getUser_name());
        tenantUser.setUpdateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis()));
        tenantUser.setUpdateBy(this.getCurrentUser().getUser_name());
        // user.setStatus(1);// 0禁用 1启用
        user.setIsDelete(0);
        user.setSysUserId(NumberGenerator.getLongSequenceNumber());
        tenantUser.setIsDelete(0);
        tenantUser.setSysUserId(NumberGenerator.getLongSequenceNumber());
        // 加密手机号
        String key = PlatformRSAUtils.AES_KEY;
        String encPhone = "";
        if (user.getUserPhone() != null) {
            encPhone = AESUtils.encryptStrAES(user.getUserPhone(), key);
        if (tenantUser.getUserPhone() != null) {
            encPhone = AESUtils.encryptStrAES(tenantUser.getUserPhone(), key);
        }
        user.setUserPhone(encPhone);
        tenantUser.setUserPhone(encPhone);
        // 怎么获取左侧机构树数据
        user.setSysDeptId(3L); // 对应平台机构id 默认为平台管理
        this.finSysTenantUserService.insert(user);
//        tenantUser.setSysDeptId(3L); // 对应平台机构id 默认为平台管理
        this.finSysTenantUserService.insert(tenantUser);
        // 插入平台用户
        S_user_core userCore = new S_user_core();
        userCore.setId(user.getSysUserId());
        userCore.setId(tenantUser.getSysUserId());
        userCore.setDept_id(3L); // 部门id,目前写死
        userCore.setOrg_id(user.getSysDeptId()); // 机构id
        userCore.setOrg_id(tenantUser.getSysDeptId()); // 机构id
        userCore.setOrg_id(1L);
        userCore.setUser_name(user.getUserCode()); // 用户账号
        userCore.setNick_name(user.getUserName());
        userCore.setUser_name(tenantUser.getUserCode()); // 用户账号
        userCore.setNick_name(tenantUser.getUserName());
        // 用户类型 先默认设置为2
        userCore.setUser_type(2);
        userCore.setPhonenumber(encPhone);
        userCore.setSex(user.getSex().toString());
        userCore.setSex(tenantUser.getSex().toString());
        // 初始化密码 123456
        String pws = this.getArgumentVariable(ArgumentsConstants.KEY_SECURITY_PASSWORD_INIT).getStringValue();
        userCore.setPassword(pws);
        // 平台用户表和系统用户 表状态相反
        if (user.getStatus() == 0) {
            user.setStatus(1);
        if (tenantUser.getStatus() == 0) {
            tenantUser.setStatus(1);
        } else {
            user.setStatus(0);
            tenantUser.setStatus(0);
        }
        userCore.setStatus(user.getStatus());
        userCore.setStatus(tenantUser.getStatus());
        userCore.setDel_flag(0);
        userCore.setCreate_by(this.getCurrentUser().getUser_name());
        userCore.setCreate_time(DateUtils.getDateTimeNumber(System.currentTimeMillis()));
        userCore.setRemark(user.getRemark());
        userCore.setRemark(tenantUser.getRemark());
        userCore.setType(1);
        userCore.setBind_client_id("0");
        userCore.setBind_wechat(0);
@@ -291,7 +276,7 @@
        // 少角色id
        List<Long> roleList = user.getRoleList(); // 机构id 多个
        if (!CollectionUtils.isEmpty(roleList)) {
            Long sysUserId = user.getSysUserId(); // 用户id
            Long sysUserId = tenantUser.getSysUserId(); // 用户id
            this.finSysTenantUserService.execInsertRoleUserList(roleList, sysUserId);
        }
        // this.getFinCustomerCache().remove();
@@ -485,21 +470,20 @@
    @Transactional(rollbackFor = Exception.class)
    public ResponseValue update() {
        FinSysTenantUser user = CommonUtil.getObjFromReqBody(FinSysTenantUser.class);
        FinSysTenantUser formInventoryParam = new FinSysTenantUser();
        CommonUtil.copyProperties(user, formInventoryParam);
        user = formInventoryParam;
        FinSysTenantUser tenantUser = new FinSysTenantUser();
        CommonUtil.copyProperties(user, tenantUser);
        if (user == null) {
        if (tenantUser == null) {
            return ResponseValue.error("参数为空");
        }
        String key = PlatformRSAUtils.AES_KEY;
        String encPhone = "";
        if (user.getUserPhone() != null) {
            encPhone = AESUtils.encryptStrAES(user.getUserPhone(), key);
        if (tenantUser.getUserPhone() != null) {
            encPhone = AESUtils.encryptStrAES(tenantUser.getUserPhone(), key);
        }
        user.setUserPhone(encPhone);
        tenantUser.setUserPhone(encPhone);
        // 1.更新系统用户 FIN_SYS_TENANT_USER
        finSysTenantUserService.update(user);
        finSysTenantUserService.update(tenantUser);
        // 2.更新平台用户 S_USER_CORE
        S_user_core userCore = new S_user_core();
        userCore.setId(user.getSysUserId());
@@ -543,15 +527,14 @@
    @PostMapping("/updateStatus")
    @Transactional(rollbackFor = Exception.class)
    public ResponseValue updateStatus() {
        FinSysTenantUser user = CommonUtil.getObjFromReqBody(FinSysTenantUser.class);
        FinSysTenantUser formInventoryParam = new FinSysTenantUser();
        CommonUtil.copyProperties(user, formInventoryParam);
        user = formInventoryParam;
        if (user == null) {
        FinSysTenantUserParam user = CommonUtil.getObjFromReqBody(FinSysTenantUserParam.class);
        FinSysTenantUser tenantUser = new FinSysTenantUser();
        CommonUtil.copyProperties(user, tenantUser);
        if (tenantUser == null) {
            return ResponseValue.error("参数为空");
        }
        // 1.更新系统用户 FIN_SYS_TENANT_USER 应该是查询 然后只改状态
        List<FinSysTenantUser> select = finSysTenantUserService.select(new FinSysTenantUser(user.getId()));
        List<FinSysTenantUser> select = finSysTenantUserService.select(new FinSysTenantUser(tenantUser.getId()));
        if (select == null || select.size() == 0) {
            return ResponseValue.error("用户不存在");
        }
@@ -580,15 +563,20 @@
     * @Date 2023/7/17 14:36
     */
    @PostMapping("/defaultPassword")
    public ResponseValue defaultPassword(@RequestBody FinSysTenantUser finSysTenantUser) {
        if (finSysTenantUser == null) {
    public ResponseValue defaultPassword() {
        FinSysTenantUserParam user = CommonUtil.getObjFromReqBody(FinSysTenantUserParam.class);
        FinSysTenantUserParam tenantUser = new FinSysTenantUserParam();
        CommonUtil.copyProperties(user, tenantUser);
        user = tenantUser;
        if (Objects.isNull(user)) {
            return ResponseValue.error("用户信息不存在");
        }
        // 初始化密码 123456
        String stringValue = this.getArgumentVariable(ArgumentsConstants.KEY_SECURITY_PASSWORD_INIT).getStringValue();// 密文
        // 1. 修改用户表
        // 用户表id
        Long sysUserId = finSysTenantUser.getSysUserId();
        Long sysUserId = user.getSysUserId();
        S_user_core userCore = new S_user_core();
        userCore.setId(sysUserId);
        userCore.setPassword(stringValue);
@@ -679,9 +667,9 @@
    @PostMapping("/updRole")
    public ResponseValue updRole() {
        FinSysTenantUser user = CommonUtil.getObjFromReqBody(FinSysTenantUser.class);
        FinSysTenantUser finSysTenantParam = new FinSysTenantUser();
        CommonUtil.copyProperties(user, finSysTenantParam);
        user = finSysTenantParam;
        FinSysTenantUser tenantUser = new FinSysTenantUser();
        CommonUtil.copyProperties(user, tenantUser);
        user = tenantUser;
        if (user == null) {
            return ResponseValue.error("参数为空");
@@ -707,10 +695,10 @@
    @PostMapping("/addSupplier")
    @Transactional(rollbackFor = Exception.class)
    public ResponseValue addSupplier() {
        FinSysTenantUser user = CommonUtil.getObjFromReqBody(FinSysTenantUser.class);
        FinSysTenantUser finSysTenantParam = new FinSysTenantUser();
        CommonUtil.copyProperties(user, finSysTenantParam);
        user = finSysTenantParam;
        FinSysTenantUserParam userParam = CommonUtil.getObjFromReqBody(FinSysTenantUserParam.class);
        FinSysTenantUser user = new FinSysTenantUser();
        CommonUtil.copyProperties(userParam, user);
        if (user == null) {
            return ResponseValue.error("参数为空");
        }
@@ -823,31 +811,31 @@
    @PostMapping("/updatePerson")
    @Transactional(rollbackFor = Exception.class)
    public ResponseValue updatePerson() {
        FinSysTenantUser user = CommonUtil.getObjFromReqBody(FinSysTenantUser.class);
        FinSysTenantUser finSysTenantParam = new FinSysTenantUser();
        CommonUtil.copyProperties(user, finSysTenantParam);
        user = finSysTenantParam;
        if (user == null) {
        FinSysTenantUserParam userParam = CommonUtil.getObjFromReqBody(FinSysTenantUserParam.class);
        FinSysTenantUserParam tenantUser = new FinSysTenantUserParam();
        CommonUtil.copyProperties(userParam, tenantUser);
        userParam = tenantUser;
        if (userParam == null) {
            return ResponseValue.error("参数为空");
        }
        FinSysTenantUser sysInfo = getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("用户信息不存在");
        }
        String avatar = user.getAvatar();
        String avatar = userParam.getAvatar();
        if (!picFormatArr.contains(avatar.substring(avatar.lastIndexOf(".")))) {
            return ResponseValue.error("头像格式不允许");
        }
        FinSysTenantUser updUser = new FinSysTenantUser();
        updUser.setId(sysInfo.getId());
        updUser.setAvatar(user.getAvatar());
        updUser.setEmail(user.getEmail());
        updUser.setUserName(user.getUserName());
        updUser.setSex(user.getSex());
        updUser.setAvatar(userParam.getAvatar());
        updUser.setEmail(userParam.getEmail());
        updUser.setUserName(userParam.getUserName());
        updUser.setSex(userParam.getSex());
        String encPhone = "";
        if (user.getUserPhone() != null) {
        if (userParam.getUserPhone() != null) {
            String key = PlatformRSAUtils.AES_KEY;
            encPhone = AESUtils.encryptStrAES(user.getUserPhone(), key);
            encPhone = AESUtils.encryptStrAES(userParam.getUserPhone(), key);
        }
        updUser.setUserPhone(encPhone);
        // 1.更新系统用户 FIN_SYS_TENANT_USER