yangdamao 2 сар өмнө
parent
commit
d14260ae03

+ 4 - 4
zhongzheng-admin/src/main/java/com/zhongzheng/controller/user/UserSubscribeController.java

@@ -431,10 +431,10 @@ public class UserSubscribeController extends BaseController {
     @GetMapping("/listUserExport")
     public AjaxResult<Map<String,Object>> listUserExport(UserSubscribeQueryBo bo) {
         Map<String,Object> map = iUserSubscribeService.listUserExport(bo);
-        List<UserSubscribeStudentExportVo> list = (List<UserSubscribeStudentExportVo>)map.get("list");
-        ExcelUtil<UserSubscribeStudentExportVo> util = new ExcelUtil<UserSubscribeStudentExportVo>(UserSubscribeStudentExportVo.class);
-        map.put("excel",util.exportExcel(list, "学员信息表"));
-        map.remove("list");
+//        List<UserSubscribeStudentExportVo> list = (List<UserSubscribeStudentExportVo>)map.get("list");
+//        ExcelUtil<UserSubscribeStudentExportVo> util = new ExcelUtil<UserSubscribeStudentExportVo>(UserSubscribeStudentExportVo.class);
+//        map.put("excel",util.exportExcel(list, "学员信息表"));
+//        map.remove("list");
         return AjaxResult.success(map);
     }
 

+ 275 - 54
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserSubscribeServiceImpl.java

@@ -2182,73 +2182,294 @@ public class UserSubscribeServiceImpl extends ServiceImpl<UserSubscribeMapper, U
     public Map<String, Object> listUserExport(UserSubscribeQueryBo bo) {
         Map<String, Object> map = new HashMap<>();
         List<UserVo> list = baseMapper.listUserExport(bo);
-        List<UserSubscribeStudentExportVo> list1 = new ArrayList<>();
-        List<FileBean> fileBeanList = new ArrayList<>(); //图片列表
-        String filename = FileUtils.encodingZipFilename("学员信息数据");
-        String zipFile = FileUtils.getZipAbsoluteFile(filename);
-        try {
-            ZipOutputStream outStream = new ZipOutputStream(new FileOutputStream(zipFile));
-            for (UserVo vo : list) {
-                UserSubscribeStudentExportVo item = BeanUtil.toBean(vo, UserSubscribeStudentExportVo.class);
-                if (Validator.isNotEmpty(vo.getSex())) {
-                    if (vo.getSex() == 1) {
-                        item.setSex("男");
-                    }
-                    if (vo.getSex() == 2) {
-                        item.setSex("女");
-                    }
+        if (CollectionUtils.isEmpty(list)) {
+            return new HashMap<>();
+        }
+
+        String tenantId = ServletUtils.getRequest().getHeader("TenantId");
+        SysTenant sysTenant = iSysTenantService.getById(Long.valueOf(tenantId));
+        String schoolName = ObjectUtils.isNotNull(sysTenant.getSchoolName()) ? sysTenant.getSchoolName() : "广东省祥粤建设职业培训学校";
+        Map<String, List<UserVo>> collect = list.stream().collect(Collectors.groupingBy(UserVo::getJob));
+        String zhiyuan = System.getProperty("user.dir");
+        String destDirPath = zhiyuan + "/zhongzheng-admin/src/main/resources/"
+                + String.format("%s预约考试%s", DateUtils.timestampToDateFormat(bo.getApplySiteExamTime(), "yyyy-MM-dd"), DateUtils.getNowTime());
+        List<UserExamApplyExport> examApplyExports = new ArrayList<>();
+
+        collect.forEach((k, v) -> {
+            String majorPath = destDirPath + "/" + k;
+            File dirw = new File(majorPath);
+            if (!dirw.exists()) {
+                dirw.mkdirs();
+            }
+            String photoPath = majorPath + "/" + schoolName;
+            File dirw2 = new File(photoPath);
+            if (!dirw2.exists()) {
+                dirw2.mkdirs();
+            }
+            List<UserSubApplyExport> applyExports = new ArrayList<>();
+            //学员头像
+            v.forEach(item -> {
+                User user = iUserService.getByIdNoTenant(item.getUserId());
+                //报考资料
+                UserProfile profile = iUserProfileService.getByOrderGoodsIdNoTenant(item.getOrderGoodsId());
+                if (ObjectUtils.isNull(profile)) {
+                    return;
                 }
-                if (ObjectUtils.isNotNull(vo.getApplySiteExamTime())) {
-                    String format = String.format("%s %s-%s", DateUtils.timestampToDateFormat(vo.getApplySiteExamTime(), "yyyy-MM-dd"), vo.getApplySiteStartTime(), vo.getApplySiteEndTime());
-                    item.setApplyTime(format);
+                UserSubApplyExport applyExport = new UserSubApplyExport();
+                applyExport.setUserName(user.getRealname());
+                applyExport.setIdCard(EncryptHandler.decrypt(user.getIdCard()));
+                applyExport.setPhone(EncryptHandler.decrypt(user.getTelphone()));
+
+                String keyValue = profile.getKeyValue();
+                applyExport.setSex(getUserProfileValue(keyValue, "sex"));
+                String education = getUserProfileValue(keyValue, "education");
+                if(education.equals("小学")||education.equals("中学")||education.equals("高中")||education.equals("中职(含技工学校)")){
+                    applyExport.setEducation("中职(含技工学校)");
+                }
+                else if(education.equals("本科")||education.equals("硕士研究生")||education.equals("博士研究生")||education.equals("本科及以上")){
+                    applyExport.setEducation("本科及以上");
+                }
+                else{
+                    applyExport.setEducation("专科(含高职和技师学院)");
                 }
-                if (ObjectUtils.isNotNull(vo.getSubscribeId())) {
-                    UserSubscribe subscribe = getById(vo.getSubscribeId());
-                    Goods goods = iGoodsService.getById(subscribe.getGoodsId());
-                    if (ObjectUtils.isNotNull(goods.getMajorId())) {
-                        Major major = iMajorService.getById(goods.getMajorId());
-                        item.setMajorName(major.getCategoryName());
+                applyExport.setCompanyName(getUserProfileValue(keyValue, "work_unit"));
+                applyExport.setPostName(getUserProfileValue(keyValue, "apply_post"));
+                applyExport.setMajorName(getUserProfileValue(keyValue, "major"));
+                applyExport.setAge(getUserProfileValue(keyValue, "working_years"));
+                applyExport.setGraduateTime(getUserProfileValue(keyValue, "graduation_time"));
+                applyExports.add(applyExport);
+
+                //个人近照
+                try {
+                    String idCardPath = photoPath + "/个人照";
+                    File dirw3 = new File(idCardPath);
+                    if (!dirw3.exists()) {
+                        dirw3.mkdirs();
                     }
+                    InputStream inputStream = ossService.getStreamByObject(user.getOneInchPhotos());
+                    //写入本地文件
+                    String inchPath = idCardPath + "/" + String.format("%s$头像.jpg", EncryptHandler.decrypt(user.getRealname()));
+                    FileOutputStream fileOutputStream = new FileOutputStream(inchPath);
+                    byte[] buffer = new byte[1024];
+                    int len = 0;
+                    while ((len = inputStream.read(buffer)) != -1) {
+                        fileOutputStream.write(buffer, 0, len);
+                    }
+                    inputStream.close();
+                    fileOutputStream.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
                 }
-                list1.add(item);
 
-                if (Validator.isNotEmpty(vo.getIdCardImg1())) {
-                    FileBean f1 = new FileBean();
-                    String idCardImg1 = vo.getIdCardImg1();
-                    f1.setPath(idCardImg1);
-                    f1.setFileName("身份证/" + vo.getIdCard() + "_0$身份证.jpg");
-                    FileBean f2 = new FileBean();
-                    String idCardImg2 = vo.getIdCardImg2();
-                    f2.setPath(idCardImg2);
-                    f2.setFileName("身份证/" + vo.getIdCard() + "_1$身份证.jpg");
-                    fileBeanList.add(f1);
-                    fileBeanList.add(f2);
+                //身份证
+                try {
+                    String idCardPath = photoPath + "/身份证";
+                    File dirw3 = new File(idCardPath);
+                    if (!dirw3.exists()) {
+                        dirw3.mkdirs();
+                    }
+
+                    InputStream inputStream = ossService.getStreamByObject(user.getIdCardImg1());
+                    //写入本地文件
+                    String inchPath = idCardPath + "/" + String.format("%s$身份证正面.jpg", EncryptHandler.decrypt(user.getRealname()));
+                    FileOutputStream fileOutputStream = new FileOutputStream(inchPath);
+                    byte[] buffer = new byte[1024];
+                    int len = 0;
+                    while ((len = inputStream.read(buffer)) != -1) {
+                        fileOutputStream.write(buffer, 0, len);
+                    }
+                    inputStream.close();
+                    fileOutputStream.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
                 }
 
+                try {
+                    String idCardPath = photoPath + "/身份证";
+                    File dirw3 = new File(idCardPath);
+                    if (!dirw3.exists()) {
+                        dirw3.mkdirs();
+                    }
 
-                if (Validator.isNotEmpty(vo.getOneInchPhotos())) {
-                    FileBean f3 = new FileBean();
-                    String oneInchPhotos = vo.getOneInchPhotos();
-                    f3.setPath(oneInchPhotos);
-                    f3.setFileName("证件照/" + vo.getIdCard() + "$头像.jpg");
-                    fileBeanList.add(f3);
+                    InputStream inputStream = ossService.getStreamByObject(user.getIdCardImg2());
+                    //写入本地文件
+                    String inchPath = idCardPath + "/" + String.format("%s$身份证背面.jpg", EncryptHandler.decrypt(user.getRealname()));
+                    FileOutputStream fileOutputStream = new FileOutputStream(inchPath);
+                    byte[] buffer = new byte[1024];
+                    int len = 0;
+                    while ((len = inputStream.read(buffer)) != -1) {
+                        fileOutputStream.write(buffer, 0, len);
+                    }
+                    inputStream.close();
+                    fileOutputStream.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
                 }
 
-                if (Validator.isNotEmpty(vo.getKeyValue())) {
-                    Map<String, String> maps = JSONObject.parseObject(vo.getKeyValue(), Map.class);
-                    String commitment_seal = JSONObject.parseObject(String.valueOf(maps.get("commitment_seal")), UserProfileFit.class).getValue();
-                    FileBean f4 = new FileBean();
-                    f4.setPath(commitment_seal);
-                    f4.setFileName("承诺书/" + vo.getIdCard() + "$承诺书.jpg");
-                    fileBeanList.add(f4);
+                try {
+                    String idCardPath = photoPath + "/承诺书";
+                    File dirw3 = new File(idCardPath);
+                    if (!dirw3.exists()) {
+                        dirw3.mkdirs();
+                    }
+                    String commitmentSeal = getUserProfileValue(keyValue, "commitment_seal");
+                    InputStream inputStream = ossService.getStreamByObject(commitmentSeal);
+                    //写入本地文件
+                    String inchPath = idCardPath + "/" + String.format("%s$承诺书.jpg", EncryptHandler.decrypt(user.getRealname()));
+                    FileOutputStream fileOutputStream = new FileOutputStream(inchPath);
+                    byte[] buffer = new byte[1024];
+                    int len = 0;
+                    while ((len = inputStream.read(buffer)) != -1) {
+                        fileOutputStream.write(buffer, 0, len);
+                    }
+                    inputStream.close();
+                    fileOutputStream.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
                 }
+
+                //测试计划
+                UserExamApplyExport export = new UserExamApplyExport();
+                export.setUserName(user.getRealname());
+                export.setIdCard(EncryptHandler.decrypt(user.getIdCard()));
+                export.setPhone(EncryptHandler.decrypt(user.getTelphone()));
+                export.setPostName(getUserProfileValue(keyValue, "apply_post"));
+                export.setApplyName(
+                        String.format("%s测试%s-%s", DateUtils.timestampToDateFormat(item.getApplySiteExamTime(), "yyyy.MM.dd")
+                                , applyTimeTransition(item.getApplySiteStartTime()), applyTimeTransition(item.getApplySiteEndTime())));
+                examApplyExports.add(export);
+            });
+            //打包zip
+            String zipPath = majorPath + "/" + String.format("%s.zip",schoolName);
+            FileUtils.toZip(zipPath, photoPath, true);
+            //删除本地资源
+            Path pathStr = Paths.get(photoPath);
+            try (Stream<Path> walk = Files.walk(pathStr)) {
+                walk.sorted(Comparator.reverseOrder())
+                        .forEach(FileUtils::deleteDirectoryStream);
+            } catch (IOException e) {
+                log.error("删除本地资源失败:" + DateUtils.getNowTime());
             }
-            ossService.zipWisdomDownload(fileBeanList, outStream);
-            outStream.close();
-        } catch (IOException e) {
+            //报考资料
+            if (CollectionUtils.isNotEmpty(applyExports)) {
+                ExcelUtil<UserSubApplyExport> util = new ExcelUtil<UserSubApplyExport>(UserSubApplyExport.class);
+                String path = majorPath + "/" + String.format("%s报名信息表", k) + ".xlsx";
+                util.exportEasyExcelStudy(util.exportEasyData(applyExports), path);
+            }
+        });
+
+        //测试计划
+        if (CollectionUtils.isNotEmpty(examApplyExports)) {
+            ExcelUtil<UserExamApplyExport> util = new ExcelUtil<UserExamApplyExport>(UserExamApplyExport.class);
+            String path = destDirPath + "/测试计划.xlsx";
+            util.exportEasyExcelStudy(util.exportEasyData(examApplyExports), path);
         }
-        map.put("list", list1);
-        map.put("zip", AjaxResult.success(filename));
+
+        //打包zip 上传oss
+        String zipPath = zhiyuan + "/zhongzheng-admin/src/main/resources/"
+                + String.format("%s预约考试%s.zip", DateUtils.timestampToDateFormat(bo.getApplySiteExamTime(), "yyyy-MM-dd"), DateUtils.getNowTime());
+        FileUtils.toZip(zipPath, destDirPath, true);
+        //上传oss
+        OssRequest ossRequest = new OssRequest();
+        ossRequest.setGradeId(0L);
+        ossRequest.setUserId(0L);
+        ossRequest.setImageStatus(7);
+        File file1 = new File(zipPath);
+        ossRequest.setFile(FileUtils.getMultipartFile(file1));
+        try {
+            String upload = ossService.upload(ossRequest);
+            //删除本地资源
+            Path pathStr = Paths.get(destDirPath);
+            try (Stream<Path> walk = Files.walk(pathStr)) {
+                walk.sorted(Comparator.reverseOrder())
+                        .forEach(FileUtils::deleteDirectoryStream);
+            } catch (IOException e) {
+                log.error("删除本地资源失败:" + DateUtils.getNowTime());
+            }
+
+            Path zipStr = Paths.get(zipPath);
+            try (Stream<Path> walk = Files.walk(zipStr)) {
+                walk.sorted(Comparator.reverseOrder())
+                        .forEach(FileUtils::deleteDirectoryStream);
+            } catch (IOException e) {
+                log.error("删除本地资源失败:" + DateUtils.getNowTime());
+            }
+            map.put("zip", AjaxResult.success(upload));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+//        collect.forEach((k,v ) ->{
+//
+//
+//        });
+//        List<UserSubscribeStudentExportVo> list1 = new ArrayList<>();
+//        List<FileBean> fileBeanList = new ArrayList<>(); //图片列表
+//        String filename = FileUtils.encodingZipFilename("学员信息数据");
+//        String zipFile = FileUtils.getZipAbsoluteFile(filename);
+//        try {
+//            ZipOutputStream outStream = new ZipOutputStream(new FileOutputStream(zipFile));
+//            for (UserVo vo : list) {
+//                UserSubscribeStudentExportVo item = BeanUtil.toBean(vo, UserSubscribeStudentExportVo.class);
+//                if (Validator.isNotEmpty(vo.getSex())) {
+//                    if (vo.getSex() == 1) {
+//                        item.setSex("男");
+//                    }
+//                    if (vo.getSex() == 2) {
+//                        item.setSex("女");
+//                    }
+//                }
+//                if (ObjectUtils.isNotNull(vo.getApplySiteExamTime())) {
+//                    String format = String.format("%s %s-%s", DateUtils.timestampToDateFormat(vo.getApplySiteExamTime(), "yyyy-MM-dd"), vo.getApplySiteStartTime(), vo.getApplySiteEndTime());
+//                    item.setApplyTime(format);
+//                }
+//                if (ObjectUtils.isNotNull(vo.getSubscribeId())) {
+//                    UserSubscribe subscribe = getById(vo.getSubscribeId());
+//                    Goods goods = iGoodsService.getById(subscribe.getGoodsId());
+//                    if (ObjectUtils.isNotNull(goods.getMajorId())) {
+//                        Major major = iMajorService.getById(goods.getMajorId());
+//                        item.setMajorName(major.getCategoryName());
+//                    }
+//                }
+//                list1.add(item);
+//
+//                if (Validator.isNotEmpty(vo.getIdCardImg1())) {
+//                    FileBean f1 = new FileBean();
+//                    String idCardImg1 = vo.getIdCardImg1();
+//                    f1.setPath(idCardImg1);
+//                    f1.setFileName("身份证/" + vo.getIdCard() + "_0$身份证.jpg");
+//                    FileBean f2 = new FileBean();
+//                    String idCardImg2 = vo.getIdCardImg2();
+//                    f2.setPath(idCardImg2);
+//                    f2.setFileName("身份证/" + vo.getIdCard() + "_1$身份证.jpg");
+//                    fileBeanList.add(f1);
+//                    fileBeanList.add(f2);
+//                }
+//
+//
+//                if (Validator.isNotEmpty(vo.getOneInchPhotos())) {
+//                    FileBean f3 = new FileBean();
+//                    String oneInchPhotos = vo.getOneInchPhotos();
+//                    f3.setPath(oneInchPhotos);
+//                    f3.setFileName("证件照/" + vo.getIdCard() + "$头像.jpg");
+//                    fileBeanList.add(f3);
+//                }
+//
+//                if (Validator.isNotEmpty(vo.getKeyValue())) {
+//                    Map<String, String> maps = JSONObject.parseObject(vo.getKeyValue(), Map.class);
+//                    String commitment_seal = JSONObject.parseObject(String.valueOf(maps.get("commitment_seal")), UserProfileFit.class).getValue();
+//                    FileBean f4 = new FileBean();
+//                    f4.setPath(commitment_seal);
+//                    f4.setFileName("承诺书/" + vo.getIdCard() + "$承诺书.jpg");
+//                    fileBeanList.add(f4);
+//                }
+//            }
+//            ossService.zipWisdomDownload(fileBeanList, outStream);
+//            outStream.close();
+//        } catch (IOException e) {
+//        }
+//        map.put("list", list1);
+//        map.put("zip", AjaxResult.success(filename));
         return map;
     }
 

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/vo/UserVo.java

@@ -323,6 +323,9 @@ public class UserVo {
 	private Integer studentRestudy;
 	@ApiModelProperty("是否需要修改密碼: 1是 0否")
 	private Integer pwdSign;
+
+	private Long orderGoodsId;
+
 	public void setNull(){
 		this.setOpenId(null);
 /*		this.setIdCardImg1(null);

+ 4 - 1
zhongzheng-system/src/main/resources/mapper/modules/user/UserSubscribeMapper.xml

@@ -505,10 +505,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="listUserExport" parameterType="com.zhongzheng.modules.user.bo.UserSubscribeQueryBo" resultMap="UserVoResult">
         SELECT
-            us.*,u.company_name,u.job,u.edu_level,u.realname,u.telphone,u.id_card,u.sex,u.id_card_img1,u.id_card_img2,u.one_inch_photos,up.key_value
+            us.*,u.company_name,m.category_name AS job,u.edu_level,u.realname,u.telphone,u.id_card,u.sex,u.id_card_img1,u.id_card_img2,u.one_inch_photos,up.key_value
         FROM
             user_subscribe us
         LEFT JOIN `user` u on u.user_id =us.user_id
+        LEFT JOIN order_goods og ON us.order_goods_id = og.order_goods_id
+        LEFT JOIN goods g ON og.goods_id = g.goods_id
+        LEFT JOIN major m ON g.major_id = m.id
         LEFT JOIN user_profile up on us.order_goods_id =up.order_goods_id and up.current_status = 1
         and up.type_status = 1
         WHERE