package com.sckw.system.service;

import com.sckw.core.common.enums.enums.DictEnum;
import com.sckw.core.exception.SystemException;
import com.sckw.core.model.constant.Global;
import com.sckw.core.model.enums.ApprovalEnum;
import com.sckw.core.model.enums.SystemTypeEnum;
import com.sckw.core.utils.*;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.context.LoginUserHolder;
import com.sckw.excel.utils.ExcelUtil;
import com.sckw.redis.constant.RedisConstant;
import com.sckw.redis.utils.RedissonUtils;
import com.sckw.system.api.RemoteUserService;
import com.sckw.system.api.model.dto.req.RegisterReqDto;
import com.sckw.system.api.model.dto.req.UpdatePasswordReqDto;
import com.sckw.system.api.model.dto.res.AreaTreeFrontResDto;
import com.sckw.system.api.model.dto.res.KwsUserResDto;
import com.sckw.system.api.model.dto.res.RegisterResDto;
import com.sckw.system.api.model.dto.res.SysDictResDto;
import com.sckw.system.dao.*;
import com.sckw.system.dubbo.RemoteSystemServiceImpl;
import com.sckw.system.model.*;
import com.sckw.system.model.report.KwsUserExcel;
import com.sckw.system.model.vo.req.*;
import com.sckw.system.model.vo.res.KwsUserResVo;
import com.sckw.transport.api.dubbo.TransportStatisticsService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 用户service接口
 *
 * @author zk
 * @date 2023-05-31
 */
@Slf4j
@Service
public class KwsUserService {

    @Autowired
    KwsUserDao kwsUserDao;

    @Autowired
    KwsUserDeptDao kwsUserDeptDao;

    @Autowired
    KwsEntCheckTrackDao kwsEntCheckTrackDao;

    @Autowired
    KwsRoleService kwsRoleService;

    @Autowired
    KwsUserRoleDao kwsUserRoleDao;

    @Autowired
    KwsDeptService kwsDeptService;

    @Autowired
    KwsEnterpriseDao kwsEnterpriseDao;

    @Autowired
    KwsMenuService kwsMenuService;

    @Autowired
    private RemoteSystemServiceImpl remoteSystemService;
    @Autowired
    private RemoteUserService remoteUserService;

    @Autowired
    private CommonService commonService;

    @DubboReference(version = "1.0.0", group = "design", check = false)
    private TransportStatisticsService transportStatisticsService;

    /**
     * @param reqVo 入参
     * @desc: 新增
     * @author: czh
     * @date: 2023/7/7
     */
    @Transactional(rollbackFor = {})
    public void add(UserAddReqVo reqVo) {
        commonService.checkPhone(reqVo.getAccount());
        KwsUser kwsUser = new KwsUser();
        BeanUtils.copyProperties(reqVo, kwsUser);
        kwsUser.setPhone(kwsUser.getAccount());
        kwsUser.setIsMain(Global.NO);
        kwsUser.setSystemType(kwsUser.getSystemType());

        /*1、数据校验*/
        checkAccountValid(kwsUser.getAccount(), kwsUser.getSystemType());

        /*2、填充密码*/
        fillPassword(kwsUser);
        synchronized (this) {
            //再次校验数据
            checkAccountValid(kwsUser.getAccount(), kwsUser.getSystemType());
            /*3、存库*/
            long userId = new IdWorker(1).nextId();
            kwsUser.setId(userId);
            if (kwsUserDao.insert(kwsUser) <= 0) {
                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
            }

            /*4、填充用户角色*/
            fillUserRole(reqVo.getRoleIds(), userId, reqVo.getSystemType());

            /*5、用户机构关系*/
            fillUserDept(kwsUser.getId(), reqVo.getDeptId());
        }

    }

    /**
     * @param reqDto 入参
     * @return RegisterResDto
     * @desc: 注册
     * @author: czh
     * @date: 2023/7/7
     */
    @Transactional(rollbackFor = {})
    public RegisterResDto register(RegisterReqDto reqDto) {
        commonService.checkEntRepeat(reqDto.getEntName(), reqDto.getPhone());
        /*1、数据校验*/
        checkAccountValid(reqDto.getPhone(), reqDto.getSystemType());

        /*存用户表、企业表，暂时不处理角色关系，需要认证*/
        KwsUser kwsUser = new KwsUser();
        long userId = new IdWorker(1).nextId();
        Long createBy = userId;
        if (Objects.nonNull(LoginUserHolder.getUserId()) && LoginUserHolder.getUserId().compareTo(1L) != 0) {
            createBy = LoginUserHolder.getUserId();
        }

        kwsUser.setSystemType(reqDto.getSystemType());
        kwsUser.setAccount(reqDto.getPhone());
        kwsUser.setPassword(reqDto.getPassword());
        kwsUser.setName(reqDto.getName());
        kwsUser.setPhone(reqDto.getPhone());
        kwsUser.setIsMain(reqDto.getIsMain());
        kwsUser.setId(userId);
        kwsUser.setCreateBy(createBy);
        kwsUser.setUpdateBy(createBy);
        //填充密码、入库
        fillPassword(kwsUser);
        if (kwsUserDao.insert(kwsUser) <= 0) {
            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
        }

        //组装返参
        RegisterResDto registerResDto = new RegisterResDto();
        registerResDto.setUserId(userId);

        /*存企业机构等*/
        //目前注册接口只有企业管理员进来
        if (reqDto.getIsMain() == Global.YES && !reqDto.getSystemType().equals(SystemTypeEnum.MANAGE.getCode())) {
            KwsEnterprise kwsEnterprise = new KwsEnterprise();
            long entId = new IdWorker(1L).nextId();
            kwsEnterprise.setId(entId);
            kwsEnterprise.setCode("");
            kwsEnterprise.setFirmName(reqDto.getEntName());
            kwsEnterprise.setApproval(ApprovalEnum.NO.getCode());
            kwsEnterprise.setContacts(reqDto.getName());
            kwsEnterprise.setPhone(reqDto.getPhone());
            kwsEnterprise.setCreateBy(createBy);
            kwsEnterprise.setUpdateBy(createBy);

            if (kwsEnterpriseDao.insert(kwsEnterprise) <= 0) {
                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
            }

            registerResDto.setEntId(entId);
            /*1、新增管理员机构*/
            KwsDept kwsDept = new KwsDept();
            Integer systemType = SystemTypeEnum.COMPANY.getCode();
            kwsDept.setEntId(entId);
            kwsDept.setName(reqDto.getEntName());
            kwsDept.setSystemType(systemType);
            kwsDept.setCompany(Global.NO);
            kwsDept.setUpdateBy(createBy);
            kwsDept.setCreateBy(createBy);
            kwsDeptService.add(kwsDept);

            /*3、绑定用户机构关系*/
            fillUserDept(userId, kwsDept.getId());

            /*2、新增管理员角色*/
            EditRoleReqVo editRoleReqVo = new EditRoleReqVo();
            List<KwsMenu> kwsMenus = kwsMenuService.selectAll();
            if (CollectionUtils.isEmpty(kwsMenus)) {
                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.MENU_NOT_EXISTS);
            }
            kwsMenus = kwsMenus.stream().filter(item -> item.getClientType().equals(Global.NUMERICAL_TWO)).collect(Collectors.toList());
            editRoleReqVo.setName(Global.MANAGE_NAME);
            editRoleReqVo.setCurrentUnitId(kwsDept.getId());
            editRoleReqVo.setMenuIds(String.join(Global.COMMA, kwsMenus.stream().map(KwsMenu::getId).map(String::valueOf).toList()));
            editRoleReqVo.setVisiblePersonal(false);
            editRoleReqVo.setIsManage(true);
            kwsRoleService.add(editRoleReqVo);
        }

        return registerResDto;
    }

    /**
     * @param userId 用户id，deptId 机构id
     * @desc: 填充用户机构
     * @author: czh
     * @date: 2023/7/11
     */
    private void fillUserDept(long userId, long deptId) {
        KwsUserDept kwsUserDept = new KwsUserDept();
        kwsUserDept.setUserId(userId);
        kwsUserDept.setDeptId(deptId);
        kwsUserDept.setId(new IdWorker(1).nextId());
        kwsUserDept.setRemark("");
        kwsUserDept.setStatus(Global.NO);
        kwsUserDept.setDelFlag(Global.NO);
        if (kwsUserDeptDao.insert(kwsUserDept) <= 0) {
            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
        }
    }

    /**
     * @param roleIds 角色ids，userId用户id，systemType系统类型
     * @desc: 填充用户角色
     * @author: czh
     * @date: 2023/7/7
     */
    public void fillUserRole(String roleIds, long userId, Integer systemType) {
        UserBindRoleReqVo userBindRoleReqVo = new UserBindRoleReqVo();
        userBindRoleReqVo.setUserId(userId);
        userBindRoleReqVo.setRoleIds(roleIds);
        userBindRoleReqVo.setSystemType(systemType);
        kwsRoleService.userBindRole(userBindRoleReqVo);
    }

    /**
     * @param kwsUser 实体类
     * @desc: 填充密码
     * @author: czh
     * @date: 2023/7/7
     */
    private void fillPassword(KwsUser kwsUser) {
        //密码为空时，以登录名作为密码
        String password;
        if (StringUtils.isBlank(kwsUser.getPassword())) {
            password = PasswordUtils.entryptPassword(PasswordUtils.md5(kwsUser.getAccount()));
            kwsUser.setPassword(password);
        } else {
            password = PasswordUtils.entryptPassword(kwsUser.getPassword());
            kwsUser.setPassword(password);
        }
        kwsUser.setSalt(PasswordUtils.getSaltSubPwd(password));
    }

    /**
     * 删除记录-根据主键
     */
    @Transactional(rollbackFor = {})
    public void deleteByKey(String ids) {
        /*1.数据校验*/
        if (StringUtils.isBlank(ids)) {
            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_MISSING);
        }

        String[] idArray = ids.split(",");
        for (String id : idArray) {
            if (id.equals(String.valueOf(LoginUserHolder.getUserId()))) {
                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.MSG_025);
            }
            KwsUser kwsUser = kwsUserDao.selectByKey(Long.parseLong(id));
            if (null != kwsUser) {
                kwsUser.setDelFlag(Global.YES);
                if (kwsUserDao.update(kwsUser) <= 0) {
                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.DELETE_FAIL);
                }
            }
        }
    }

    /**
     * 更新记录
     *
     * @param params KwsUser
     */
    @Transactional(rollbackFor = {})
    public void update(UserAddReqVo params) {
        commonService.checkPhone(params.getAccount());
        KwsUser kwsUser = kwsUserDao.selectByKey(params.getId());
        if (Objects.isNull(kwsUser)) {
            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_NOT_EXISTS);
        }
        //更换账号后账号唯一性校验
//        if (StringUtils.isNotBlank(params.getAccount())) {
//            //用户信息
//            KwsUser userByAccount = getUserByAccount(params.getAccount(), params.getSystemType());
//            if (Objects.isNull(userByAccount)) {
//                throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.ACCOUNT_EXISTS);
//            }
//        }

        //以前的关联数据先删除再新增
        List<KwsUserDept> kwsUserDepts = kwsUserDeptDao.findAllByUserId(params.getId());
        if (CollectionUtils.isNotEmpty(kwsUserDepts)) {
            for (KwsUserDept kwsUserDept : kwsUserDepts) {
                kwsUserDept.setDelFlag(Global.YES);
                if (kwsUserDeptDao.update(kwsUserDept) <= 0) {
                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
                }
            }
        }

        List<KwsUserRole> kwsUserRoles = kwsUserRoleDao.findAllByUserId(params.getId());
        if (CollectionUtils.isNotEmpty(kwsUserRoles)) {
            for (KwsUserRole kwsUserRole : kwsUserRoles) {
                kwsUserRole.setDelFlag(Global.YES);
                if (kwsUserRoleDao.update(kwsUserRole) <= 0) {
                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
                }
            }
        }

        kwsUser.setRemark(params.getRemark());
        kwsUser.setName(params.getName());
        kwsUserDao.update(kwsUser);

        /*填充用户角色*/
        fillUserRole(params.getRoleIds(), kwsUser.getId(), kwsUser.getSystemType());

        /*用户机构关系*/
        fillUserDept(kwsUser.getId(), params.getDeptId());
    }

    /**
     * @param id 主键ID
     * @desc 重置密码
     * @author zk
     * @date 2023/06/02
     **/
    public void resetPassword(Long id) {
        //查用户信息
        KwsUser kwsUser = checkUserBase(id);

        //重置密码
        updatePwd(PasswordUtils.md5(kwsUser.getAccount()), kwsUser);
    }

    /**
     * 根据主键查询
     */
    public KwsUser selectByKey(Long key) {
        return kwsUserDao.selectByKey(key);
    }

    /**
     * 根据主键查询
     */
    public List<KwsUser> selectByKeys(List<Long> key) {
        return kwsUserDao.selectByKeys(key);
    }

    /**
     * 分页查询
     */
    public List<KwsUserResVo> findPage(Map<String, Object> params) {
        params.put("entId", LoginUserHolder.getEntId());
        params.put("isMain", Global.NO);
        return kwsUserDao.findPage(params);
    }

    /**
     * 查询
     */
    public List<KwsUserResVo> findList(Map<String, Object> params) {
        return kwsUserDao.findList(params);
    }

    /**
     * 根据用户名查用户信息
     */
    public KwsUser getUserByAccount(String username, int systemType) {
        Map<String, Object> params = new HashMap<>(Global.NUMERICAL_SIXTEEN){{
            put("account", username);
            put("systemType", systemType);
        }};
        List<KwsUserResVo> list = kwsUserDao.findList(params);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        KwsUser kwsUser = new KwsUser();
        KwsUserResVo kwsUserResVo = list.get(0);
        BeanUtils.copyProperties(kwsUserResVo, kwsUser);
        return kwsUser;
    }

    /**
     * @param reqVo 修改密码入参
     * @desc: 修改密码
     * @author: czh
     * @date: 2023/7/3
     */
    public void updatePassword(UpdatePasswordReqDto reqVo) {
        //查用户信息
        KwsUser kwsUser = checkUserBase(reqVo.getId());

        //密码校验
        String password = reqVo.getPassword();
        String currentPwd = kwsUser.getPassword();
        checkPassword(password, currentPwd);

        //校验新密码是否可用
        String newPassword = reqVo.getNewPassword();
        if (PasswordUtils.validatePassword(newPassword, currentPwd)) {
            throw new SystemException(HttpStatus.CODE_10301, HttpStatus.PASSWD_REPEAT);
        }

        //修改密码
        updatePwd(newPassword, kwsUser);
    }

    private void updatePwd(String newPassword, KwsUser kwsUser) {
        kwsUser.setPassword(PasswordUtils.entryptPassword(newPassword));
        kwsUser.setSalt(PasswordUtils.getSaltSubPwd(kwsUser.getPassword()));
        if (kwsUserDao.update(kwsUser) <= 0) {
            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
        }
    }

    /**
     * 忘记密码
     */
    public void forgetPassword(ForgetPasswordReqVo reqVo) {
        //查用户信息
        KwsUser kwsUser = checkUserBase(reqVo.getAccount(), reqVo.getSystemType());

        //从缓存中取出验证码,校验
        String key = StringUtils.format(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, DictEnum.SMS_UPDATE_PASSWORD.getValue(), reqVo.getAccount());
        String sms = RedissonUtils.getString(key);
        if (!reqVo.getCaptcha().equals(sms)) {
            throw new SystemException(HttpStatus.CODE_10301, HttpStatus.CAPTCHA_ERROR);
        }

        //修改密码
        updatePwd(reqVo.getPassword(), kwsUser);
    }

    /**
     * @param account 账号 systemType 系统类型
     * @return KwsUser
     * @desc: 根据登录名校验，为空抛异常用户信息不存在或已失效
     * @author: czh
     * @date: 2023/6/16
     */
    public KwsUser checkUserBase(String account, int systemType) {
        KwsUser kwsUser = getUserByAccount(account, systemType);
        if (Objects.isNull(kwsUser) || kwsUser.getStatus().equals(Global.YES)) {
            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_NOT_EXISTS);
        }
        return kwsUser;
    }

    /**
     * 根据id校验
     */
    public KwsUser checkUserBase(long id) {
        KwsUser kwsUser = kwsUserDao.selectByKey(id);
        if (Objects.isNull(kwsUser) || kwsUser.getDelFlag() != Global.NO) {
            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_NOT_EXISTS);
        }
        return kwsUser;
    }

    /**
     * 校验密码
     *
     * @param password   入参传的密码
     * @param currentPwd 当前用户的密码
     */
    public void checkPassword(String password, String currentPwd) {
        if (!PasswordUtils.validatePassword(password, currentPwd)) {
            throw new SystemException(HttpStatus.CODE_10301, HttpStatus.PASSWD_ERROR);
        }
    }

    /**
     * @param userId 用户id
     * @return KwsUserDept
     * @desc: 根据用户id查用户机构关联关系
     * @author: czh
     * @date: 2023/7/7
     */
    public List<KwsUserDept> queryUserDeptByUserId(Long userId) {
        return kwsUserDao.queryUserDeptByUserId(userId);
    }

    /**
     * @param list 机构主键
     * @return KwsDept
     * @desc: 批量查机构
     * @author: czh
     * @date: 2023/7/7
     */
    public List<KwsDept> queryDeptByIds(List<Long> list) {
        return kwsUserDao.queryDeptByIds(list);
    }

    /**
     * @param account 账号 systemType系统类型
     * @desc: 校验账号有效性, 存在抛异常用户账号已存在
     * @author: czh
     * @date: 2023/6/16
     */
    public void checkAccountValid(String account, Integer systemType) {
        if (Objects.nonNull(getUserByAccount(account, systemType))) {
            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_EXISTS);
        }
    }

    /**
     * @param entId 企业id
     * @return KwsUser
     * @desc: 根据企业id查用户
     * @author: czh
     * @date: 2023/6/26
     */
    public List<KwsUser> selectByEntId(Long entId) {
        return kwsUserDao.selectByEntId(entId);
    }

    /**
     * @param id 用户id
     * @desc: 注销
     * @author: czh
     * @date: 2023/7/3
     */
    public void closeAccount(Long id) {
        KwsUser kwsUser = new KwsUser();
        kwsUser.setId(id);
        kwsUser.setDelFlag(Global.YES);
        if (kwsUserDao.update(kwsUser) <= 0) {
            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.DELETE_FAIL);
        }
    }


    /**
     * @param ids 主键
     * @desc: 冻结
     * @author: czh
     * @date: 2023/7/12
     */
    public void freeze(String ids) {
        if (StringUtils.isBlank(ids)) {
            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ID_MISSING);
        }

        String[] split = ids.split(Global.COMMA);
        for (String id : split) {
            KwsUser kwsUser = kwsUserDao.selectByKey(Long.parseLong(id));
            if (Objects.isNull(kwsUser) || !kwsUser.getStatus().equals(Global.NO)) {
                throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_FREEZE);
            }

            kwsUser.setStatus(Global.YES);
            if (kwsUserDao.update(kwsUser) <= 0) {
                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
            }
            RedissonUtils.remove(Global.getFullUserLoginKey(kwsUser.getSystemType(), kwsUser.getId()));
        }
    }


    /**
     * @param ids 主键
     * @desc: 解冻
     * @author: czh
     * @date: 2023/7/12
     */
    public void unFreeze(String ids) {
        if (StringUtils.isBlank(ids)) {
            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ID_MISSING);
        }

        String[] split = ids.split(Global.COMMA);
        for (String id : split) {
            KwsUser kwsUser = kwsUserDao.selectByKey(Long.parseLong(id));
            if (Objects.isNull(kwsUser) || !kwsUser.getStatus().equals(Global.YES)) {
                throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_UNFREEZE);
            }

            kwsUser.setStatus(Global.NO);
            if (kwsUserDao.update(kwsUser) <= 0) {
                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
            }
        }
    }

    /**
     * @param reqVo 入参
     * @desc: 重置密码
     * @author: czh
     * @date: 2023/7/14
     */
    @Transactional(rollbackFor = {})
    public void resetPasswordByMain(ResetPasswordReqVo reqVo) {
        //查用户信息
        KwsUser kwsUser = checkUserBase(reqVo.getId());

        //重置密码
        updatePwd(reqVo.getNewPassword(), kwsUser);
    }

    public List<AreaTreeFrontResDto> test(List<Integer> list) {
        List<SysDictResDto> sysDictResDtos = remoteSystemService.queryDictFrontAll("product_name_type", "2");
        return null;
    }

    /**
     * 根据用户姓名模糊查用户信息
     *
     * @param name 用户姓名
     * @return list
     */
    public List<KwsUserResDto> getUserByName(String name) {
        List<KwsUser> list = kwsUserDao.getUserByName(name);
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyList();
        }
        return BeanUtils.copyToList(list, KwsUserResDto.class);
    }

    /**
     * @param deptIds 机构id
     * @return KwsUser
     * @desc: 查机构下的用户
     * @author: czh
     * @date: 2023/9/4
     */
    public List<KwsUser> queryUserByDeptIds(List<Long> deptIds) {
        return kwsUserDao.selectByDeptIds(deptIds);
    }


    public void export(HashMap params, HttpServletResponse response) {
        params.put("entId", LoginUserHolder.getEntId());
        String ids = StringUtils.valueOf(params.get("ids"));
        if (StringUtils.isNotBlank(ids)) {
            params.put("idList", StringUtils.splitStrToList(ids, Long.class));
        }
        List<KwsUserResVo> list = kwsUserDao.findPage(params);
        if (CollectionUtils.isEmpty(list)) {
            throw new SystemException(HttpStatus.SUCCESS_CODE, "暂无数据，请确认！");
        }

        List<KwsUserExcel> result = new ArrayList<>();
        list.forEach(item -> {
            KwsUserExcel kwsUserExce = new KwsUserExcel();
            BeanUtils.copyProperties(item, kwsUserExce);
            kwsUserExce.setStatus(item.getStatus().equals(Global.NO) ? "正常" : "冻结");
            result.add(kwsUserExce);
        });
        ExcelUtil.downData(response, KwsUserExcel.class, result);
    }

}