智慧保安后台管理-外网项目备份
Administrator
2021-09-11 afd1817037c8e28838066aa89fcc480cabee255e
新增考试缴费凭证批量上传
11 files modified
256 ■■■■■ changed files
src/main/java/org/springblade/modules/apply/controller/ApplyController.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/controller/ExamPaymentController.java 12 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/entity/ExamPayment.java 12 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/mapper/ExamPaymentMapper.xml 16 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/vo/ExamPaymentVO.java 20 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/mapper/ExamPaperMapper.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/mapper/ExamPaperMapper.xml 33 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/service/ExamPaperService.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/service/impl/ExamPaperServiceImpl.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/vo/ExamPaperVO.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java 128 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/controller/ApplyController.java
@@ -370,6 +370,12 @@
     */
    @PostMapping("/remove")
    public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
        List<String> list = Arrays.asList(ids.split(","));
        list.forEach(id -> {
            //内网同步
            String s1 = "delete from sys_apply where id = " + "'" + id + "'";
            FtpUtil.sqlFileUpload(s1);
        });
        return R.status(applyService.removeByIds(Func.toLongList(ids)));
    }
src/main/java/org/springblade/modules/apply/controller/ExamPaymentController.java
@@ -9,10 +9,14 @@
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.apply.entity.ExamPayment;
import org.springblade.modules.apply.service.ExamPaymentService;
import org.springblade.modules.apply.vo.ExamPaymentVO;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
 * @author zhongrj
@@ -72,7 +76,6 @@
     */
    @PostMapping("/submit")
    public R submit(@RequestBody ExamPayment examPayment) throws Exception {
        //arg.test01(arg.url+"/examPayment/submit",examPayment);
        return R.status(examPaymentService.saveOrUpdate(examPayment));
    }
@@ -83,7 +86,12 @@
     */
    @PostMapping("/remove")
    public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
        //arg.sendPostRemoveByIds(arg.url+"/examPayment/remove",ids);
        List<String> list = Arrays.asList(ids.split(","));
        list.forEach(id -> {
            //内网同步
            String s1 = "delete from sys_exam_payment where id = " + "'" + id + "'";
            FtpUtil.sqlFileUpload(s1);
        });
        return R.status(examPaymentService.removeByIds(Func.toLongList(ids)));
    }
src/main/java/org/springblade/modules/apply/entity/ExamPayment.java
@@ -45,7 +45,7 @@
    /**
     * 缴费类型  1:公司缴费  2:个人缴费
     */
    private Long type;
    private Integer type;
    /**
@@ -57,7 +57,7 @@
    private Date paymentTime;
    /**
     * 缴费人/公司deptId
     * 缴费人id
     */
    @TableField("worker_id")
    private String workerId;
@@ -77,8 +77,14 @@
    /**
     * 报名编号
     * 报名id
     */
    @TableField("apply_code")
    private String applyCode;
    /**
     * 缴费凭证 url
     */
    @TableField("certificate_url")
    private String certificateUrl;
}
src/main/java/org/springblade/modules/apply/mapper/ExamPaymentMapper.xml
@@ -2,17 +2,22 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.apply.mapper.ExamPaymentMapper">
    <!--考试报名分页信息-->
    <!--缴费分页信息-->
    <select id="selectExamPaymentPage" resultType="org.springblade.modules.apply.vo.ExamPaymentVO">
        SELECT
            se.*,
            bu.real_name realName,bu.cardid idCardNo,bu.sex,bu.phone,
            bd.dept_name deptName
        FROM
            sys_exam_payment se
        left join
            blade_user bu
        on
            bu.id = se.worker_id
        left join
            blade_dept bd
        on
            bd.id = se.worker_id
            bd.id = bu.dept_id
        WHERE
            type = 1
        <if test="examPayment.workerId!=null and  examPayment.workerId!=''">
@@ -20,6 +25,12 @@
        </if>
        <if test="examPayment.deptName!=null and  examPayment.deptName!=''">
            and bd.dept_name like concat('%', #{examPayment.deptName},'%')
        </if>
        <if test="examPayment.realName!=null and  examPayment.realName!=''">
            and bu.real_name like concat('%', #{examPayment.realName},'%')
        </if>
        <if test="examPayment.idCardNo!=null and  examPayment.idCardNo!=''">
            and bu.cardid like concat('%', #{examPayment.idCardNo},'%')
        </if>
    </select>
@@ -33,6 +44,5 @@
        <if test="examPayment.id!=null and examPayment.id!=''">
            and id = #{examPayment.id}
        </if>
    </select>
</mapper>
src/main/java/org/springblade/modules/apply/vo/ExamPaymentVO.java
@@ -44,5 +44,25 @@
     */
    private Integer num;
    /**
     * 保安员姓名
     */
    private String realName;
    /**
     * 身份证号
     */
    private String idCardNo;
    /**
     * 性别  1男  2女
     */
    private Integer sex;
    /**
     * 联系电话
     */
    private String phone;
}
src/main/java/org/springblade/modules/exam/mapper/ExamPaperMapper.java
@@ -19,6 +19,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.apply.entity.Apply;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.entity.ExamSubjectChoices;
import org.springblade.modules.exam.vo.ExamPaperSubjectVO;
@@ -102,4 +103,11 @@
     * @return
     */
    Integer getTrainNumber(@Param("examPaper")ExamPaperVO examPaperVO1);
    /**
     * 根据用户id查询报名信息
     * @param userId 用户id
     * @return
     */
    List<Apply> getApplyDetail(@Param("userId")String userId);
}
src/main/java/org/springblade/modules/exam/mapper/ExamPaperMapper.xml
@@ -249,4 +249,37 @@
        and cancel = 1
    </select>
    <!--根据用户id查询报名信息-->
    <select id="getApplyDetail" resultType="org.springblade.modules.apply.entity.Apply">
        (select
            sa.id as id
        from
            sys_apply sa
        left join
            blade_user bu
        on
            bu.id = sa.user_id
        where sa.user_id = #{userId}
        and is_apply = 1
        and is_exam = 1
        and sa.apply_status = 2
        )
        union all
        (select
            str.id as id
        from
            sys_training_registration str
        left join
            blade_user bu
        on
            bu.id = str.user_id
        where str.user_id = #{userId}
        and bu.is_train = 1
        and is_exam = 1
        and str.cancel = 1
        )
    </select>
</mapper>
src/main/java/org/springblade/modules/exam/service/ExamPaperService.java
@@ -18,6 +18,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.modules.apply.entity.Apply;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.entity.ExamSubjectChoices;
import org.springblade.modules.exam.vo.ExamPaperSubjectVO;
@@ -96,4 +97,11 @@
     * @return
     */
    ExamPaper getExamInfoByExamName(String examName);
    /**
     * 根据用户id查询报名信息
     * @param userId 用户id
     * @return
     */
    List<Apply> getApplyDetail(String userId);
}
src/main/java/org/springblade/modules/exam/service/impl/ExamPaperServiceImpl.java
@@ -18,6 +18,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.apply.entity.Apply;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.entity.ExamSubjectChoices;
import org.springblade.modules.exam.mapper.ExamPaperMapper;
@@ -142,4 +143,14 @@
    public ExamPaper getExamInfoByExamName(String examName) {
        return baseMapper.getExamInfoByExamName(examName);
    }
    /**
     * 根据用户id查询报名信息
     * @param userId 用户id
     * @return
     */
    @Override
    public List<Apply> getApplyDetail(String userId) {
        return baseMapper.getApplyDetail(userId);
    }
}
src/main/java/org/springblade/modules/exam/vo/ExamPaperVO.java
@@ -33,7 +33,7 @@
    private Integer sex;
    /**
     * 考试 id
     * 报名 id
     */
    private Long applyId;
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -34,6 +34,11 @@
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.apply.entity.Apply;
import org.springblade.modules.apply.entity.ExamPayment;
import org.springblade.modules.apply.service.ExamPaymentService;
import org.springblade.modules.exam.service.ExamPaperService;
import org.springblade.modules.exam.vo.ExamPaperVO;
import org.springblade.modules.resource.builder.oss.OssBuilder;
import org.springblade.modules.resource.entity.Attach;
import org.springblade.modules.resource.service.IAttachService;
@@ -77,6 +82,11 @@
    private final IUserService userService;
    private final ExamPaperService examPaperService;
    private final ExamPaymentService examPaymentService;
    /**
     * 创建存储桶
@@ -373,7 +383,123 @@
    /**
     * 文件上传,自定义上传
     * 文件上传,zip , 缴费凭证
     *
     * @param file 图片对象
     */
    @PostMapping("put-file-exam-payment-zip")
    public R putFileExamPaymentZip(@RequestParam MultipartFile file) throws Exception {
        Map<String, Object> map = new HashMap<>(1);
        //填写你文件上传的地址以及相应信息
        String url = "http://223.82.109.183:2081";
        String access = "zhbaadmin";
        String secret = "zhbapassword";
        String bucket = "zhba";
        MinioClient minioClient =
            MinioClient.builder()
                .endpoint(url)
                .credentials(access, secret)
                .build();
        // 检查存储桶是否已经存在
        boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
        if (!isExist) {
            // 创建一个名为zip的存储桶,用于zip文件。
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
            minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
        }
        String fileName = file.getOriginalFilename();
        String namePath = fileName.substring(0,fileName.lastIndexOf("."));
        String fileType = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(Locale.US);
        //判断文件是不是zip类型
        if(!fileType.equals("zip")){
            map.put("data","上传文件类型不符!");
            return R.data(map);
        }
        //FileConfig.localtion是配置文件和config类生产的,测试demo可以直接把FileConfig.localtion替换成D:/test
        String uuid = UUID.randomUUID().toString();
        String desPath = FileConfig.localtion + File.separator + uuid.replaceAll("-", "");
        //遗漏了这个代码,在本地测试环境不会出问题,在服务器上一定会报没有找到文件的错误
        String savePath = FileConfig.localtion + File.separator;
        FileUtil fileUtil = new FileUtil();
        //解压zip文件
        FileUtil.unZip(file, desPath,savePath);
        List<MultipartFile> fileList = new ArrayList<>();
        //获取图片文件
        fileList = fileUtil.getSubFiles(desPath+File.separator+namePath,fileList);
        for (MultipartFile multipartFile : fileList){
            if(multipartFile.getName().toLowerCase().endsWith(".png") || multipartFile.getName().toLowerCase().endsWith(".jpg")) {
                String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "") + multipartFile.getName().substring(multipartFile.getName().lastIndexOf("."));
                InputStream in = multipartFile.getInputStream();
                String[] split = newName.split("/");
                //创建头部信息
                Map<String, String> headers = new HashMap<>(1 << 2);
                //添加自定义内容类型
                headers.put("Content-Type", "application/octet-stream");
                //上传
                minioClient.putObject(
                    PutObjectArgs.builder().bucket(bucket).object(newName).stream(
                        in, in.available(), -1)
                        .headers(headers)
                        .build());
                String urls = "http://223.82.109.183:2081/zhba/" + newName;
                //内网
                String inUrl = ip + newName;
                //取出身份证号,查询用户信息,更新用户信息
                String pictrueName = multipartFile.getName().substring(0, multipartFile.getName().lastIndexOf("."));
//                String regex ="([1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx])|([1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3})";
                String regex ="[\u4e00-\u9fa5]";
                Pattern compile = Pattern.compile(regex);
                String idCardNo = compile.matcher(pictrueName).replaceAll("");
                User user = userService.getUserInfoByIdCardNo(idCardNo);
                //设置用户头像url
                if (null!=user){
                    ExamPayment examPayment = new ExamPayment();
                    examPayment.setWorkerId(user.getId().toString());
                    examPayment.setCertificateUrl(urls);
                    examPayment.setType(1);
                    examPayment.setPaymentTime(new Date());
                    //查询当前人员的报名信息
                    List<Apply> applyList = examPaperService.getApplyDetail(user.getId().toString());
                    //有且只有一条信息
                    if (applyList.size()==1){
                        examPayment.setApplyCode(applyList.get(0).getId().toString());
                    }
                    //新增
                    examPaymentService.save(examPayment);
                    //数据推送
                    String formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(examPayment.getPaymentTime());
                    String s = "insert into sys_apply(id,type,payment_time,worker_id,apply_code,certificate_url) " +
                        "values(" + "'" + examPayment.getId() + "'" +
                        "," + "'" + examPayment.getType() + "'" +
                        "," + "'" + formatStr + "'" +
                        "," + "'" + examPayment.getWorkerId() + "'" +
                        "," + "'" + examPayment.getApplyCode() + "'" +
                        "," +"'" + examPayment.getCertificateUrl() + "'" + ")";
                    FtpUtil.sqlFileUpload(s);
                    //文件推送
                    InputStream inputStream = multipartFile.getInputStream();
                    FtpUtil.uploadFile(ftpHost_dev, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", split[2], inputStream);
                    in.close();
                }
            }
        }
        //最后要删除文件
        FileUtil.clearFiles(FileConfig.localtion + File.separator + file.getOriginalFilename());
        FileUtil.clearFiles(desPath);
        //数据封装
        map.put("data", "上传成功!");
        //返回
        return R.data(map);
    }
    /**
     * 文件上传,个人头像上传
     *
     * @param file 图片对象
     */