智慧保安后台管理-外网项目备份
guoshilong
2023-12-27 be38921cb7b2807e5e35c983940ee02d83df493b
制证时间批量导入
9 files modified
2 files added
202 ■■■■■ changed files
src/main/java/org/springblade/modules/accreditation/controller/AccreditationRecordsController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/accreditation/entity/AccreditationRecords.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/accreditation/mapper/AccreditationRecordsMapper.xml 3 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/accreditation/service/impl/AccreditationRecordsServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/accreditation/vo/AccreditationRecordsVo.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/controller/UserController.java 40 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/excel/UserCertificateExcel.java 31 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/excel/UserCertificateExcelImporter.java 41 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/IUserService.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java 69 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/accreditation/controller/AccreditationRecordsController.java
@@ -197,7 +197,7 @@
        List<String> list = Arrays.asList(ids.split(","));
        //批量审核
        list.forEach(id->{
            accreditationRecords.setId(Long.parseLong(id));
            accreditationRecords.setId(id);
            accreditationRecords.setAuditTime(new Date());
            accreditationRecordsService.updateById(accreditationRecords);
            //审核通过
src/main/java/org/springblade/modules/accreditation/entity/AccreditationRecords.java
@@ -25,7 +25,7 @@
     * 制证记录主键id,非自增
     */
    @TableId(value = "id",type = IdType.ASSIGN_ID)
    private Long id;
    private String id;
    /**
     * 制证人 user_id
src/main/java/org/springblade/modules/accreditation/mapper/AccreditationRecordsMapper.xml
@@ -16,7 +16,8 @@
            ifnull(DATE_FORMAT(NOW(), '%Y') - SUBSTRING( bu.cardid,7,4),0) age,
            bu1.real_name applyName,
            bt1.dept_name applyUnit,
            bu.user_type userType
            bu.user_type userType,
            bu.paper_time as userPaperTime
        FROM
            sys_accreditation_records sar
        left join
src/main/java/org/springblade/modules/accreditation/service/impl/AccreditationRecordsServiceImpl.java
@@ -232,7 +232,7 @@
        list.forEach(id -> {
            AccreditationRecords records = new AccreditationRecords();
            records.setStatus(2);
            records.setId(Long.parseLong(id));
            records.setId(id);
            //更新
            this.updateById(records);
src/main/java/org/springblade/modules/accreditation/vo/AccreditationRecordsVo.java
@@ -100,4 +100,7 @@
    private Long deptId;
    private String jurisdiction;
    //用户表里的paperTime
    private String userPaperTime;
}
src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -1400,5 +1400,45 @@
        return R.status(result);
    }
    /**
     * 导入保安员制证时间
     */
    @PostMapping("import-security-paperTime")
    @ApiOperationSupport(order = 12)
    @ApiOperation(value = "导入用户", notes = "传入excel")
    public R importSecurityPaperTime(MultipartFile file, Integer isCovered, String deptId) {
        UserCertificateExcelImporter userCertificateExcelImporter = new UserCertificateExcelImporter(userService, false, deptId);
        ExcelUtil.save(file, userCertificateExcelImporter, UserCertificateExcel.class);
        return R.success("操作成功");
    }
    /**
     * 保安员制证时间导出模板
     */
    @GetMapping("export-template-security-paperTime")
    @ApiOperationSupport(order = 14)
    @ApiOperation(value = "导出模板")
    public void exportPaperTimeExcelTemplate(HttpServletResponse response) throws IOException {
        List<UserCertificateExcel> list = new ArrayList<>();
        UserCertificateExcel userCertificateExcel = new UserCertificateExcel();
        userCertificateExcel.setRealName("张三");
        userCertificateExcel.setCardid("360XXX19XXXXXX****");
        userCertificateExcel.setPaperTime("2023-12-26");
        list.add(userCertificateExcel);
        String fileName = null;
        try {
            response.setContentType("application/vnd.ms-excel");
            response.setCharacterEncoding(org.apache.commons.codec.Charsets.UTF_8.name());
            fileName = URLEncoder.encode("发证时间导入数据模板" + DateUtil.time(), Charsets.UTF_8.name());
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
            //修改单元格格式为文本格式
            EasyExcel.write(response.getOutputStream(), UserCertificateExcel.class).sheet("发证时间导入数据表").registerWriteHandler(new RowWriteHandler()).doWrite(list);
        } catch (Throwable var6) {
            throw var6;
        }
    }
}
src/main/java/org/springblade/modules/system/excel/UserCertificateExcel.java
New file
@@ -0,0 +1,31 @@
package org.springblade.modules.system.excel;
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;
@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class UserCertificateExcel implements Serializable {
    private static final long serialVersionUID = 1L;
    @ExcelProperty("姓名")
    private String realName;
    @ExcelProperty("身份证号")
    private String cardid;
    @ExcelProperty("保安员证编号")
    @ColumnWidth(15)
    private String securitynumber;
    @ExcelProperty("发证时间")
    private String paperTime;
}
src/main/java/org/springblade/modules/system/excel/UserCertificateExcelImporter.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 Chill
 */
@RequiredArgsConstructor
public class UserCertificateExcelImporter implements ExcelImporter<UserCertificateExcel> {
    private final IUserService service;
    private final Boolean isCovered;
    private final String deptId;
    @Override
    public void save(List<UserCertificateExcel> data) {
        service.importSecurityPaperTime(data, isCovered,deptId);
    }
}
src/main/java/org/springblade/modules/system/mapper/UserMapper.xml
@@ -425,7 +425,7 @@
    <!--通过 身份证号查询用户信息-->
    <select id="getUserInfoByIdCardNo" resultType="org.springblade.modules.system.entity.User">
        SELECT id, name, real_name RealName,securitynumber
        SELECT id, name, real_name RealName,securitynumber,dept_id
        FROM blade_user
        where 1=1
        and is_deleted = 0
src/main/java/org/springblade/modules/system/service/IUserService.java
@@ -27,10 +27,7 @@
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.entity.UserInfo;
import org.springblade.modules.system.entity.UserOauth;
import org.springblade.modules.system.excel.QrCodeExcel;
import org.springblade.modules.system.excel.SecurityExcel;
import org.springblade.modules.system.excel.SecurityYyExcel;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.*;
import org.springblade.modules.system.node.TreeNode;
import org.springblade.modules.system.vo.UserInfoDetail;
import org.springblade.modules.system.vo.UserVO;
@@ -438,4 +435,6 @@
    UserInfoDetail getUserInfoDetail(String id);
    boolean batchAudit(String ids, String auditStatus);
    void importSecurityPaperTime(List<UserCertificateExcel> data, Boolean isCovered, String deptId);
}
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -60,10 +60,7 @@
import org.springblade.modules.securitypaper.entity.SecurityPaper;
import org.springblade.modules.securitypaper.service.SecurityPaperService;
import org.springblade.modules.system.entity.*;
import org.springblade.modules.system.excel.QrCodeExcel;
import org.springblade.modules.system.excel.SecurityExcel;
import org.springblade.modules.system.excel.SecurityYyExcel;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.*;
import org.springblade.modules.system.mapper.UserMapper;
import org.springblade.modules.system.node.TreeNode;
import org.springblade.modules.system.service.*;
@@ -1936,4 +1933,68 @@
    public boolean batchAudit(String ids, String auditStatus) {
        return baseMapper.batchAudit(ids,auditStatus);
    }
    @Override
    public void importSecurityPaperTime(List<UserCertificateExcel> data, Boolean isCovered, String deptId) {
        //将不能导入的保安员账号存起来
        List<String> errorList = new ArrayList<>();
        //导入状态,默认为true ,如果有一个出现问题则为 false
        AtomicBoolean status = new AtomicBoolean(true);
        AtomicBoolean securityInvalidStatus = new AtomicBoolean(true);
        //遍历
        for (UserCertificateExcel userExcel : data) {
            //身份证校验
            if (null == userExcel.getCardid() || userExcel.getCardid().equals("")) {
                throw new ServiceException("导入失败!身份证号码不能为空!");
            }
            if (null != userExcel.getCardid() && !userExcel.getCardid().equals("")) {
                //去除所有空格
                String cardid = userExcel.getCardid().replaceAll(" ", "");
                //校验
                boolean b = IdCardNoUtil.checkIdCardNo(cardid);
                if (b) {
                    userExcel.setCardid(cardid);
                } else {
                    //forEach 只能使用 return 跳出本次循环
//                    return;
                    continue;
                }
            }
            //根据身份证获取用户
            User userInfoByIdCardNo = baseMapper.getUserInfoByIdCardNo(userExcel.getCardid());
            if (!userInfoByIdCardNo.getSecuritynumber().equals( userExcel.getSecuritynumber())){
                throw new ServiceException("导入失败!保安证编号与系统不匹配!");
            }
            User user = new User();
            user.setId(userInfoByIdCardNo.getId());
            if (!Strings.isBlank(userExcel.getPaperTime())) {
                try {
                    user.setPaperTime(new SimpleDateFormat("yyyy-MM-dd").parse(userExcel.getPaperTime()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            updateById(user);
            //如果所有数据导入有一个异常
            StringBuilder errorBuilder = new StringBuilder();
            if (!status.get()) {
                String errorAccount = StringUtils.join(errorList, "\\\n");
                errorBuilder.append("用户:[" + errorAccount + "]导入失败!已在其他单位存在!");
            }
            //抛出异常
            if (errorBuilder.length() > 0) {
                throw new ServiceException(errorBuilder.toString());
            }
        }
    }
}