|
@@ -17,6 +17,7 @@ import com.zhongzheng.common.type.EncryptHandler;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.common.utils.JavaMailUtils;
|
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.common.utils.file.FileUploadUtils;
|
|
|
import com.zhongzheng.common.utils.file.FileUtils;
|
|
|
import com.zhongzheng.common.utils.http.HttpUtils;
|
|
|
import com.zhongzheng.common.utils.poi.EasyPoiUtil;
|
|
@@ -30,6 +31,12 @@ import com.zhongzheng.modules.bank.domain.Exam;
|
|
|
import com.zhongzheng.modules.bank.domain.QuestionBusiness;
|
|
|
import com.zhongzheng.modules.bank.service.IExamService;
|
|
|
import com.zhongzheng.modules.bank.service.IQuestionBusinessService;
|
|
|
+import com.zhongzheng.modules.base.bo.UserProfileQueryBo;
|
|
|
+import com.zhongzheng.modules.base.domain.UserProfile;
|
|
|
+import com.zhongzheng.modules.base.service.IUserProfileService;
|
|
|
+import com.zhongzheng.modules.base.vo.UserProfileVo;
|
|
|
+import com.zhongzheng.modules.course.domain.Major;
|
|
|
+import com.zhongzheng.modules.course.service.IMajorService;
|
|
|
import com.zhongzheng.modules.exam.bo.*;
|
|
|
import com.zhongzheng.modules.exam.domain.*;
|
|
|
import com.zhongzheng.modules.exam.mapper.ExamApplyMapper;
|
|
@@ -47,6 +54,7 @@ import com.zhongzheng.modules.user.domain.UserSubscribe;
|
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
|
import com.zhongzheng.modules.user.service.IUserSubscribeService;
|
|
|
import com.zhongzheng.modules.user.vo.UserStudyRecordExport;
|
|
|
+import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -90,6 +98,8 @@ public class ExamApplyServiceImpl extends ServiceImpl<ExamApplyMapper, ExamApply
|
|
|
@Autowired
|
|
|
private IGoodsService iGoodsService;
|
|
|
@Autowired
|
|
|
+ private IMajorService iMajorService;
|
|
|
+ @Autowired
|
|
|
private IUserService iUserService;
|
|
|
@Autowired
|
|
|
private ISysTenantService sysTenantService;
|
|
@@ -105,6 +115,8 @@ public class ExamApplyServiceImpl extends ServiceImpl<ExamApplyMapper, ExamApply
|
|
|
private OssService ossService;
|
|
|
@Autowired
|
|
|
private ISysConfigService iSysConfigService;
|
|
|
+ @Autowired
|
|
|
+ private IUserProfileService iUserProfileService;
|
|
|
@Value("${exam.applyDelete}")
|
|
|
private String EXAM_APPLY_DELETE;
|
|
|
|
|
@@ -1008,7 +1020,217 @@ public class ExamApplyServiceImpl extends ServiceImpl<ExamApplyMapper, ExamApply
|
|
|
e.printStackTrace();
|
|
|
throw new CustomException("文件解压错误");
|
|
|
}
|
|
|
+ // 路径
|
|
|
+ try (Stream<Path> paths = Files.walk(Paths.get(path))){
|
|
|
+ List<Path> fileNames = paths
|
|
|
+ .filter(Files::isRegularFile)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(fileNames)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, List<Path>> map = fileNames.stream().collect(Collectors.groupingBy(item -> {
|
|
|
+ Path name = item.getFileName();
|
|
|
+ List<String> sign = Arrays.stream(name.toString().split("\\$")).collect(Collectors.toList());
|
|
|
+ //身份证号
|
|
|
+ String idCard = sign.get(0);
|
|
|
+ return idCard;
|
|
|
+ }));
|
|
|
+ map.forEach((k,v) ->{
|
|
|
+ //身份证号
|
|
|
+ String idCard = k;
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
+ .eq(User::getIdCard, EncryptHandler.encrypt(idCard)));
|
|
|
+ if (ObjectUtils.isNull(user)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (Path item : v) {
|
|
|
+ List<String> sign = Arrays.stream(item.getFileName().toString().split("\\$")).collect(Collectors.toList());
|
|
|
+ String promise = sign.get(1);
|
|
|
+ String post = Arrays.stream(sign.get(sign.size() - 1).split("\\.")).findFirst().orElse("");
|
|
|
+ String content1 = item.toString();
|
|
|
+ File userFile = new File(content1);
|
|
|
+ MultipartFile multipartFile = FileUtils.getMultipartFile(userFile);
|
|
|
+ if (!promise.contains("承诺书")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //查询学员资料填写情况
|
|
|
+ List<UserProfile> profiles = baseMapper.getUserProfileList(idCard,"考前培训施工现场专业人员",post);
|
|
|
+ profiles.forEach(userItem -> {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(userItem.getKeyValue());
|
|
|
+ Map<String, Object> userMap = new HashMap<>();
|
|
|
+ for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
|
|
|
+ userMap.put(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ String key = "commitment_seal";
|
|
|
+ String fieldName = "承诺书盖章";
|
|
|
+ OssRequest ossRequest = new OssRequest();
|
|
|
+ ossRequest.setUserId(user.getUserId());
|
|
|
+ ossRequest.setFile(multipartFile);
|
|
|
+ ossRequest.setImageStatus(0);
|
|
|
+ try {
|
|
|
+ String upload = ossService.upload(ossRequest);
|
|
|
+ JSONObject recentJson = JSONObject.parseObject(userMap.get(key).toString());
|
|
|
+ Map<String, Object> recentMap = new HashMap<>();
|
|
|
+ for (Map.Entry<String, Object> entry : recentJson.entrySet()) {
|
|
|
+ recentMap.put(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(recentMap)){
|
|
|
+ recentMap.put("value",upload);
|
|
|
+ }else {
|
|
|
+ recentMap.put("fieldKey",key);
|
|
|
+ recentMap.put("value",upload);
|
|
|
+ recentMap.put("fieldName",fieldName);
|
|
|
+ recentMap.put("status",0);
|
|
|
+ }
|
|
|
+ userMap.put(key,recentMap);
|
|
|
+ }catch (Exception e) {
|
|
|
+ throw new CustomException(fieldName+"上传oss失败");
|
|
|
+ }
|
|
|
+ String content = JSONObject.toJSONString(userMap);
|
|
|
+ userItem.setKeyValue(content);
|
|
|
+ });
|
|
|
+ iUserProfileService.updateBatchById(profiles);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //删除本地文件
|
|
|
+ FileUtils.deleteFilePackage(path);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("学员资料有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String examUserProfileExport(UserProfileQueryBo bo) {
|
|
|
+ List<UserProfileVo> userProfileVos = iUserProfileService.queryList(bo);
|
|
|
+ if (CollectionUtils.isEmpty(userProfileVos)){
|
|
|
+ throw new CustomException("请勿导出空数据");
|
|
|
+ }
|
|
|
+ //根据公司分组
|
|
|
+ Map< String, List<UserProfileVo>> map = userProfileVos.stream().collect(Collectors.groupingBy(x -> {
|
|
|
+ User user = iUserService.getById(x.getUserId());
|
|
|
+ return StringUtils.isNotBlank(user.getCompanyName())?user.getCompanyName():"没有填写公司名称的学员";
|
|
|
+ }));
|
|
|
+ //写入文件
|
|
|
+ String path = System.getProperty("user.dir") + "/zhongzheng-admin/src/main/resources/profile";
|
|
|
+
|
|
|
+ map.forEach((k,v) -> {
|
|
|
+ String toPath = path+"/"+k;
|
|
|
+ File file = new File(toPath);
|
|
|
+ if (!file.exists()){
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ //学员分组
|
|
|
+ Map<Long, List<UserProfileVo>> userMap = v.stream().collect(Collectors.groupingBy(UserProfileVo::getUserId));
|
|
|
+ userMap.forEach((m,j) -> {
|
|
|
+ User user = iUserService.getById(m);
|
|
|
+ if (ObjectUtils.isNull(user)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String idCard = EncryptHandler.decrypt(user.getIdCard());
|
|
|
+ //学员资料
|
|
|
+ String keyValue = j.get(0).getKeyValue();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(keyValue);
|
|
|
+ //头像
|
|
|
+ JSONObject recentPhotos = JSONObject.parseObject(JSONObject.toJSONString(jsonObject.get("recent_photos")));
|
|
|
+ if (ObjectUtils.isNotNull(recentPhotos)){
|
|
|
+ handleFile(recentPhotos,idCard,toPath,"recent_photos","");
|
|
|
+ }
|
|
|
+ //身份证正面
|
|
|
+ JSONObject facePhoto = JSONObject.parseObject(JSONObject.toJSONString(jsonObject.get("idcard_face_photo")));
|
|
|
+ if (ObjectUtils.isNotNull(facePhoto)){
|
|
|
+ handleFile(facePhoto,idCard,toPath,"idcard_face_photo","");
|
|
|
+ }
|
|
|
+ //身份证反面
|
|
|
+ JSONObject nationalPhotos = JSONObject.parseObject(JSONObject.toJSONString(jsonObject.get("idcard_national_photo")));
|
|
|
+ if (ObjectUtils.isNotNull(nationalPhotos)){
|
|
|
+ handleFile(nationalPhotos,idCard,toPath,"idcard_national_photo","");
|
|
|
+ }
|
|
|
+
|
|
|
+ //承诺书
|
|
|
+ for (UserProfileVo userProfile : j) {
|
|
|
+ Goods goods = iGoodsService.getById(userProfile.getGoodsId());
|
|
|
+ Major major = iMajorService.getById(goods.getMajorId());
|
|
|
+ if (ObjectUtils.isNotNull(major)){
|
|
|
+ JSONObject json = JSONObject.parseObject(userProfile.getKeyValue());
|
|
|
+ //头像
|
|
|
+ JSONObject sign = JSONObject.parseObject(JSONObject.toJSONString(json.get("commitment_electr_signature")));
|
|
|
+ handleFile(sign,idCard,toPath,"commitment_electr_signature",major.getCategoryName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ //打成压缩包
|
|
|
+ String zipPath = System.getProperty("user.dir") + "/zhongzheng-admin/src/main/resources/profile-zip/七大员资料.zip";
|
|
|
+ try {
|
|
|
+ File file = new File(zipPath);
|
|
|
+ if (!file.exists()){
|
|
|
+ //先得到文件的上级目录,并创建上级目录,在创建文件
|
|
|
+ file.getParentFile().mkdir();
|
|
|
+ file.createNewFile();
|
|
|
+ }
|
|
|
+ FileUtils.zipFolder(path,zipPath);
|
|
|
+ //删除本地资源
|
|
|
+ FileUtils.deleteFilePackage(path);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("文件压缩zip包失败!");
|
|
|
+ }
|
|
|
+ ExcelUtil<UserProfile> util = new ExcelUtil<>(UserProfile.class);
|
|
|
+ String content = util.userProfileExport(zipPath, "七大员资料.zip");
|
|
|
|
|
|
+ //删除本地资源
|
|
|
+ FileUtils.deleteFilePackage(System.getProperty("user.dir") + "/zhongzheng-admin/src/main/resources/profile-zip");
|
|
|
+ return content;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleFile(JSONObject recentPhotos,String idCard,String toPath,String key,String major){
|
|
|
+ try {
|
|
|
+ if (ObjectUtils.isNotNull(recentPhotos.get("value"))){
|
|
|
+ String content = recentPhotos.get("value").toString();
|
|
|
+ InputStream photos = ossService.getStreamByObject(content);
|
|
|
+ //文件名称
|
|
|
+ String keyName = "";
|
|
|
+ if ("recent_photos".equals(key)){
|
|
|
+ keyName = "头像";
|
|
|
+ }else if ("idcard_face_photo".equals(key)){
|
|
|
+ keyName = "身份证正面";
|
|
|
+ }else if ("idcard_national_photo".equals(key)){
|
|
|
+ keyName = "身份证反面";
|
|
|
+ }else if ("commitment_electr_signature".equals(key)){
|
|
|
+ keyName = "承诺书";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(keyName)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String fileName = idCard+"$"+keyName;
|
|
|
+ if (StringUtils.isNotBlank(major)){
|
|
|
+ fileName = fileName+"$"+major;
|
|
|
+ }
|
|
|
+ if (content.contains(".")){
|
|
|
+ List<String> names = Arrays.stream(content.split("\\.")).collect(Collectors.toList());
|
|
|
+ fileName = fileName + "." + names.get(names.size() -1);
|
|
|
+ }else {
|
|
|
+ fileName = fileName +".jpg";
|
|
|
+ }
|
|
|
+ String filePath = toPath+"/"+fileName;
|
|
|
+ //写入本地文件
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(filePath);
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ while ((len = photos.read(buffer)) != -1) {
|
|
|
+ fileOutputStream.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ photos.close();
|
|
|
+ fileOutputStream.close();
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("获取学员资料文件失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|