智慧保安后台管理-外网
Administrator
2021-12-16 5f5ad9cb069f7bf0aadf821b07a7cf6d8509eb38
1. 保安员查询修改
2. 保安员导入优化
4 files modified
320 ■■■■ changed files
src/main/java/org/springblade/modules/system/mapper/UserMapper.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml 59 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java 240 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/vo/UserVO.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserMapper.java
@@ -23,6 +23,7 @@
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.dispatcher.vo.DispatcherVO;
import org.springblade.modules.experience.entity.Experience;
import org.springblade.modules.system.excel.SecurityExcel;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.entity.User;
@@ -234,4 +235,16 @@
     * @return
     */
    DispatcherVO getUserDispatcherInfo(Long id);
    /**
     * 用户批量导入
     * @param userList
     */
    void batchUserList(@Param("list") List<User> userList);
    /**
     * 从业记录批量导入
     * @param experienceList
     */
    void batchExperienceList(@Param("list") List<Experience> experienceList);
}
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml
@@ -149,6 +149,18 @@
                and bu.dispatch = #{user.dispatch}
            </if>
        </if>
        <if test="user.isAvatar==1">
            and bu.avatar is not null and bu.avatar!=""
        </if>
        <if test="user.isAvatar==2">
            and (bu.avatar is null or bu.avatar="")
        </if>
        <if test="user.isFingerprint==1">
            and bu.fingerprint is not null and bu.fingerprint!=""
        </if>
        <if test="user.isFingerprint==2">
            and (bu.fingerprint is null or bu.fingerprint="")
        </if>
        <if test="user.userType!=null and user.userType != ''">
            and bu.user_type = #{user.userType}
        </if>
@@ -729,6 +741,18 @@
                and bu.examination_type = #{user.examinationType}
            </if>
        </if>
        <if test="user.isAvatar==1">
            and bu.avatar is not null and bu.avatar!=""
        </if>
        <if test="user.isAvatar==2">
            and (bu.avatar is null or bu.avatar="")
        </if>
        <if test="user.isFingerprint==1">
            and bu.fingerprint is not null and bu.fingerprint!=""
        </if>
        <if test="user.isFingerprint==2">
            and (bu.fingerprint is null or bu.fingerprint="")
        </if>
        <if test="user.account!=null and user.account != ''">
            and bu.account like concat('%', #{user.account},'%')
        </if>
@@ -829,4 +853,39 @@
        and bu.dispatch = 0
        and bu.id = #{id}
    </select>
    <!-- 批量插入时将主键值设置到参数user的userId字段上 -->
    <insert id="batchUserList" useGeneratedKeys="true" keyProperty="id">
        insert into blade_user
        (id,
        tenant_id,account,password,name,real_name,avatar,email,phone,sex,
        role_id,dept_id,cardid,nativePlace,nation,fingerprint,education,
        politicaloutlook,healstats,height,address,registered,securitynumber,
        hold,jurisdiction,examination_type,status,is_deleted,dispatch,create_time
        )
        values
        <foreach collection="list" item="user" separator=",">
            (#{user.id},
            #{user.tenantId},#{user.account},#{user.password},#{user.name},#{user.realName},#{user.avatar},#{user.email},#{user.phone},#{user.sex},
            #{user.roleId},#{user.deptId},#{user.cardid},#{user.nativeplace},#{user.nation},#{user.fingerprint},#{user.education},
            #{user.politicaloutlook},#{user.healstats},#{user.height},#{user.address},#{user.registered},#{user.securitynumber},
            #{user.hold},#{user.jurisdiction},#{user.examinationType},#{user.status},#{user.isDeleted},#{user.dispatch},#{user.createTime}
            )
        </foreach>
    </insert>
    <!-- 批量插入时将主键值设置到参数user的userId字段上 -->
    <insert id="batchExperienceList" useGeneratedKeys="true" keyProperty="id">
        insert into sys_experience
        (
        name,post,entryTime,cardId,companyname,securityId
        )
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.name},#{item.post},#{item.entrytime},#{item.cardid},#{item.companyname},#{item.securityid}
            )
        </foreach>
    </insert>
</mapper>
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -801,16 +801,22 @@
     */
    @Override
    public void importSecurity(List<SecurityExcel> data, Boolean isCovered, String deptId) {
        long time = System.currentTimeMillis();
        //将不能导入的保安员账号存起来
        List<String> errorList = new ArrayList<>();
        //年龄不符的保安员信息存入集合
        List<String> ageErrorList = new ArrayList<>();
        //将需要更新的保安员信息存入集合
        List<User> updateList = new ArrayList<>();
        //需要新增的保安员集合
        List<User> userList = new ArrayList<>();
        //需要新增的从业记录集合
        List<Experience> experienceList = new ArrayList<>();
        //导入状态,默认为true ,如果有一个出现问题则为 false
        AtomicBoolean status = new AtomicBoolean(true);
        AtomicBoolean agetStatus = new AtomicBoolean(true);
        data.forEach(userExcel -> {
        //遍历
        for (SecurityExcel userExcel : data) {
            User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class));
            //设置部门id
            String deptIds = userDeptService.selectIn(user.getDeptId());
@@ -846,7 +852,8 @@
                    ageErrorList.add(user.getCardid());
//                    throw new ServiceException("导入失败!身份证号码[ "+user.getCardid()+" ]不正确,请核对!");
                    //forEach 只能使用 return 跳出本次循环
                    return;
//                    return;
                    continue;
                }
            }
            //判断当前用户是否已在本单位,如果是的更新数据
@@ -873,100 +880,51 @@
                }
                //判断年龄,超过60岁的不入
//                if (AgeUtil.idCardToAge(user.getCardid())<60) {
                    //分配保安角色
                    Role role = new Role();
                    role.setRoleAlias("保安");
                    Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
                    user.setRoleId(oneRole.getId().toString());
                //分配保安角色
                Role role = new Role();
                role.setRoleAlias("保安");
                Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
                user.setRoleId(oneRole.getId().toString());
                    //性别
                    if (null != userExcel.getSex()) {
                        if (userExcel.getSex().equals("男")) {
                            user.setSex(1);
                        }
                        if (userExcel.getSex().equals("女")) {
                            user.setSex(2);
                        }
                //性别
                if (null != userExcel.getSex()) {
                    if (userExcel.getSex().equals("男")) {
                        user.setSex(1);
                    }
                    //设置账号
                    user.setAccount(user.getCardid());
                    //获取默认密码配置
                    user.setPassword(user.getCardid().substring(user.getCardid().length() - 6));
                    //加密
                    if (Func.isNotEmpty(user.getPassword())) {
                        user.setPassword(DigestUtil.encrypt(user.getPassword()));
                    if (userExcel.getSex().equals("女")) {
                        user.setSex(2);
                    }
                    Integer userCount = baseMapper.selectCountAccount(user.getAccount());
                    if (userCount > 0 && Func.isEmpty(user.getId())) {
                        throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
                    }
                    user.setCreateTime(new Date());
                    //新增
                    this.save(user);
                }
                //设置账号
                user.setAccount(user.getCardid());
                //获取默认密码配置
                user.setPassword(user.getCardid().substring(user.getCardid().length() - 6));
                //加密
                if (Func.isNotEmpty(user.getPassword())) {
                    user.setPassword(DigestUtil.encrypt(user.getPassword()));
                }
                Integer userCount = baseMapper.selectCountAccount(user.getAccount());
                if (userCount > 0 && Func.isEmpty(user.getId())) {
                    throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
                }
                user.setCreateTime(new Date());
                //新增
//                this.save(user);
                //加入集合
                userList.add(user);
                //从业记录新增
                Experience experience = new Experience();
                experience.setCardid(user.getCardid());
//                experience.setSecurityid(user.getId().toString());
                experience.setCompanyname(userExcel.getDeptId());
                experience.setName(user.getRealName());
                experience.setPost("保安员");
                experience.setEntrytime(new Date());
//                experienceService.save(experience);
                //加入集合
                experienceList.add(experience);
                    //从业记录新增
                    Experience experience = new Experience();
                    experience.setCardid(user.getCardid());
                    experience.setSecurityid(user.getId().toString());
                    experience.setCompanyname(userExcel.getDeptId());
                    experience.setName(user.getRealName());
                    experience.setPost("保安员");
                    experience.setEntrytime(new Date());
                    experienceService.save(experience);
                    //内网同步
                    String s = "insert into blade_user(" +
                        "id,tenant_id,account,password,name,real_name,avatar,email,phone,sex," +
                        "role_id,dept_id,cardid,nativePlace,nation,fingerprint,education," +
                        "politicaloutlook,healstats,height,address,registered," +
                        "securitynumber,hold,jurisdiction,examination_type,status,is_deleted,dispatch,create_time) " +
                        "values(" + "'" + user.getId() + "'" +
                        "," + "'" + user.getTenantId() + "'" +
                        "," + "'" + user.getAccount() + "'" +
                        "," + "'" + user.getPassword() + "'" +
                        "," + "'" + user.getName() + "'" +
                        "," + "'" + user.getRealName() + "'" +
                        "," + "'" + user.getAvatar() + "'" +
                        "," + "'" + user.getEmail() + "'" +
                        "," + "'" + user.getPhone() + "'" +
                        "," + "'" + user.getSex() + "'" +
                        "," + "'" + user.getRoleId() + "'" +
                        "," + "'" + user.getDeptId() + "'" +
                        "," + "'" + user.getCardid() + "'" +
                        "," + "'" + user.getNativeplace() + "'" +
                        "," + "'" + user.getNation() + "'" +
                        "," + "'" + user.getFingerprint() + "'" +
                        "," + "'" + user.getEducation() + "'" +
                        "," + "'" + user.getPoliticaloutlook() + "'" +
                        "," + "'" + user.getHealstats() + "'" +
                        "," + "'" + user.getHeight() + "'" +
                        "," + "'" + user.getAddress() + "'" +
                        "," + "'" + user.getRegistered() + "'" +
                        "," + "'" + user.getSecuritynumber() + "'" +
                        "," + "'" + user.getHold() + "'" +
                        "," + "'" + user.getJurisdiction() + "'" +
                        "," + "'" + user.getExaminationType() + "'" +
                        "," + "'" + user.getStatus() + "'" +
                        "," + "'" + user.getIsDeleted() + "'" +
                        "," + "'" + user.getDispatch() + "'" +
                        "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getCreateTime()) + "'" + ");"+
                    "insert into sys_experience(id,name,post,entryTime," +
                        "cardId,companyname,securityId) " +
                        "values(" + "'" + experience.getId() + "'" + "," +
                        "'" + experience.getName() + "'" + "," +
                        "'" + experience.getPost() + "'" + "," +
                        "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getEntrytime()) + "'" +
                        "," + "'" + experience.getCardid() + "'" +
                        "," + "'" + experience.getCompanyname() + "'" +
                        "," + "'" + experience.getSecurityid() + "'"
                        + ")";
                    FtpUtil.sqlFileUpload(s);
//                }else {
//                    agetStatus.set(false);
//                    ageErrorList.add(user.getCardid());
//                }
            }else {
                //匹配组织机构是否一致,如果不一致
                if(!user2.getDeptId().equals(user.getDeptId())){
@@ -1007,7 +965,8 @@
                        //加入集合
                        errorList.add(user.getCardid());
                        //forEach 只能使用 return 跳出本次循环
                        return;
//                        return;
                        continue;
                    }
                }else {
                    //如果是一致,则更新用户数据
@@ -1039,7 +998,102 @@
                    FtpUtil.sqlFileUpload(s1);
                }
            }
        });
        }
        //批量插入
        //用户批量插入
        if (userList.size()>0) {
            baseMapper.batchUserList(userList);
            //sql 拼接
            StringBuilder builder = new StringBuilder();
            StringBuilder builder1 = new StringBuilder();
            //遍历
            for (User user : userList) {
                //内网同步,sql 拼接
                String sql = "insert into blade_user(" +
                    "id,tenant_id,account,password,name,real_name,avatar,email,phone,sex," +
                    "role_id,dept_id,cardid,nativePlace,nation,fingerprint,education," +
                    "politicaloutlook,healstats,height,address,registered," +
                    "securitynumber,hold,jurisdiction,examination_type,status,is_deleted,dispatch,create_time) " +
                    "values(" + "'" + user.getId() + "'" +
                    "," + "'" + user.getTenantId() + "'" +
                    "," + "'" + user.getAccount() + "'" +
                    "," + "'" + user.getPassword() + "'" +
                    "," + "'" + user.getName() + "'" +
                    "," + "'" + user.getRealName() + "'" +
                    "," + "'" + user.getAvatar() + "'" +
                    "," + "'" + user.getEmail() + "'" +
                    "," + "'" + user.getPhone() + "'" +
                    "," + "'" + user.getSex() + "'" +
                    "," + "'" + user.getRoleId() + "'" +
                    "," + "'" + user.getDeptId() + "'" +
                    "," + "'" + user.getCardid() + "'" +
                    "," + "'" + user.getNativeplace() + "'" +
                    "," + "'" + user.getNation() + "'" +
                    "," + "'" + user.getFingerprint() + "'" +
                    "," + "'" + user.getEducation() + "'" +
                    "," + "'" + user.getPoliticaloutlook() + "'" +
                    "," + "'" + user.getHealstats() + "'" +
                    "," + "'" + user.getHeight() + "'" +
                    "," + "'" + user.getAddress() + "'" +
                    "," + "'" + user.getRegistered() + "'" +
                    "," + "'" + user.getSecuritynumber() + "'" +
                    "," + "'" + user.getHold() + "'" +
                    "," + "'" + user.getJurisdiction() + "'" +
                    "," + "'" + user.getExaminationType() + "'" +
                    "," + "'" + user.getStatus() + "'" +
                    "," + "'" + user.getIsDeleted() + "'" +
                    "," + "'" + user.getDispatch() + "'" +
                    "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getCreateTime()) + "'" + ")";
                //拼接
                builder  = builder.append(sql).append(";");
                List<String> list = Arrays.asList(builder.toString().split(";"));
                //判断list.size 大小
                if (list.size()==1000){
                    //执行
                    FtpUtil.sqlFileUpload(builder.toString());
                    //清空
                    builder.delete(0,builder.length());
                }
            }
            //装换成map
            Map<String, User> userMap = userList.stream().collect(Collectors.toMap(user -> user.getCardid(), user -> user));
            //匹配
            experienceList = experienceList.stream().map(experience -> {
                if (experience.getCardid().equals(userMap.get(experience.getCardid()).getCardid())) {
                    experience.setSecurityid(userMap.get(experience.getCardid()).getId().toString());
                }
                return experience;
            }).collect(Collectors.toList());
            //批量插入从业记录
            baseMapper.batchExperienceList(experienceList);
            //遍历,拼接sql ,同步数据到内网
            for (Experience experience : experienceList) {
                String sql1  = "insert into sys_experience(id,name,post,entryTime,cardId,companyname,securityId) " +
                    "values(" + "'" + experience.getId() + "'" + "," +
                    "'" + experience.getName() + "'" + "," +
                    "'" + experience.getPost() + "'" + "," +
                    "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getEntrytime()) + "'" +
                    "," + "'" + experience.getCardid() + "'" +
                    "," + "'" + experience.getCompanyname() + "'" +
                    "," + "'" + experience.getSecurityid() + "'" + ")";
                //拼接
                builder1  = builder1.append(sql1).append(";");
                String[] split1 = builder.toString().split(";");
                //判断list.size 大小
                if (split1.length==1000){
                    //执行
                    FtpUtil.sqlFileUpload(builder1.toString());
                    //清空
                    builder1.delete(0,builder1.length());
                }
            }
            //剩余的继续执行
            FtpUtil.sqlFileUpload(builder.toString());
            FtpUtil.sqlFileUpload(builder1.toString());
        }
//        System.out.println("导入时间: = " + (System.currentTimeMillis()-time));
        //如果所有数据导入有一个异常
        if (!status.get() || !agetStatus.get()){
            if (!status.get() && agetStatus.get()) {
src/main/java/org/springblade/modules/system/vo/UserVO.java
@@ -150,6 +150,14 @@
    private String dispatchEndTime;
    /**
     * 是否有头像  1:有  2:没有上传
     */
    private Integer isAvatar;
    /**
     * 是否有指纹  1:有  2:没有上传
     */
    private Integer isFingerprint;
}