洪城义警-正式版后台
钟日健
2022-02-21 e7484f262cfb05b0ed7260c468ce4c78998b05f2
新增保安员批量导入接口
3 files modified
2 files added
209 ■■■■■ changed files
src/main/java/org/springblade/modules/system/controller/UserController.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/excel/UserExcels.java 102 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/excel/UserImporters.java 41 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/IUserService.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java 44 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -48,7 +48,9 @@
import org.springblade.modules.system.entity.Role;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.UserExcels;
import org.springblade.modules.system.excel.UserImporter;
import org.springblade.modules.system.excel.UserImporters;
import org.springblade.modules.system.service.IRoleService;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.system.vo.UserVO;
@@ -349,6 +351,17 @@
    }
    /**
     * 导入用户(保安员)
     */
    @PostMapping("import-users")
    @ApiOperation(value = "导入用户", notes = "传入excel")
    public R importUsers(MultipartFile file, Integer isCovered) {
        UserImporters userImporter = new UserImporters(userService, isCovered == 1);
        ExcelUtil.save(file, userImporter, UserExcels.class);
        return R.success("操作成功");
    }
    /**
     * 导出用户
     */
    @GetMapping("export-user")
src/main/java/org/springblade/modules/system/excel/UserExcels.java
New file
@@ -0,0 +1,102 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.system.excel;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
 * UserExcel
 *
 * @author Chill
 */
@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class UserExcels implements Serializable {
    private static final long serialVersionUID = 1L;
    @ColumnWidth(15)
    @ExcelProperty("账户")
    private String account;
    /**
     * 密码
     */
    @ColumnWidth(20)
    @ExcelProperty("密码")
    private String password;
    @ColumnWidth(10)
    @ExcelProperty("姓名")
    private String realName;
    @ColumnWidth(20)
    @ExcelProperty("头像")
    private String avatar;
    @ExcelProperty("邮箱")
    private String email;
    @ColumnWidth(15)
    @ExcelProperty("手机")
    private String phone;
    @ColumnWidth(10)
    @ExcelProperty("性别")
    private Integer sex;
    @ColumnWidth(20)
    @ExcelProperty("角色ID")
    private String roleId;
    @ColumnWidth(10)
    @ExcelProperty("是否在职")
    private Integer status;
    @ColumnWidth(10)
    @ExcelProperty("是否删除")
    private Integer isDeleted;
    @ColumnWidth(10)
    @ExcelProperty("审查状态")
    private String examinationType;
    @ColumnWidth(15)
    @ExcelProperty("审查明细")
    private String examinationMx;
    @ColumnWidth(15)
    @ExcelProperty("辖区ID")
    private String jurisdiction;
    @ColumnWidth(20)
    @ExcelProperty("身份证号码")
    private String cardid;
}
src/main/java/org/springblade/modules/system/excel/UserImporters.java
New file
@@ -0,0 +1,41 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.system.excel;
import lombok.RequiredArgsConstructor;
import org.springblade.core.excel.support.ExcelImporter;
import org.springblade.modules.system.service.IUserService;
import java.util.List;
/**
 * 用户数据导入类(保安员导入)
 *
 * @author zhongrj
 * @since 2022-2-21
 */
@RequiredArgsConstructor
public class UserImporters implements ExcelImporter<UserExcels> {
    private final IUserService service;
    private final Boolean isCovered;
    @Override
    public void save(List<UserExcels> data) {
        service.importUsers(data, isCovered);
    }
}
src/main/java/org/springblade/modules/system/service/IUserService.java
@@ -28,6 +28,7 @@
import org.springblade.modules.system.entity.UserInfo;
import org.springblade.modules.system.entity.UserOauth;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.UserExcels;
import org.springblade.modules.system.vo.UserDistrictStatisVO;
import org.springblade.modules.system.vo.UserRegisterStatisVO;
import org.springblade.modules.system.vo.UserVO;
@@ -285,4 +286,12 @@
    Integer selectCount(String account);
    void updateAcc(String stype,String account);
    void delete(String account);
    /**
     * 保安员导入
     * @param data
     * @param isCovered
     */
    void importUsers(List<UserExcels> data, Boolean isCovered);
}
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -43,6 +43,7 @@
import org.springblade.modules.auth.enums.UserEnum;
import org.springblade.modules.system.entity.*;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.UserExcels;
import org.springblade.modules.system.mapper.UserMapper;
import org.springblade.modules.system.service.IRoleService;
import org.springblade.modules.system.service.IUserDeptService;
@@ -537,4 +538,47 @@
        baseMapper.delete(account);
    }
    /**
     * 用户导入(保安员导入)
     * @param data
     * @param isCovered
     */
    @Override
//    @Transactional(rollbackFor = Exception.class)
    public void importUsers(List<UserExcels> data, Boolean isCovered) {
        data.forEach(userExcel -> {
            User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class));
            // 设置租户ID
            user.setTenantId("000000");
            //查询身份证号是否有重复的,有的话只更新
            User user1 = new User();
            user1.setCardid(user.getCardid());
            user1.setStatus(1);
            user1.setIsDeleted(0);
            List<User> list = this.list(Condition.getQueryWrapper(user1));
            if (list.size()>0){
                //更新
                user.setId(list.get(0).getId());
                this.updateById(user);
            }else {
                String tenantId = user.getTenantId();
                Tenant tenant = SysCache.getTenant(tenantId);
                if (Func.isNotEmpty(tenant)) {
                    Integer accountNumber = tenant.getAccountNumber();
                    if (tenantProperties.getLicense()) {
                        String licenseKey = tenant.getLicenseKey();
                        String decrypt = DesUtil.decryptFormHex(licenseKey, TenantConstant.DES_KEY);
                        accountNumber = JsonUtil.parse(decrypt, Tenant.class).getAccountNumber();
                    }
                    Integer tenantCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId));
                    if (accountNumber != null && accountNumber > 0 && accountNumber <= tenantCount) {
                        throw new ServiceException("当前租户已到最大账号额度!");
                    }
                }
                //新增
                this.save(user);
            }
        });
    }
}