he2802 3 лет назад
Родитель
Сommit
be7ab3faa0

+ 7 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/schedule/ScheduleController.java

@@ -293,4 +293,11 @@ public class ScheduleController extends BaseController {
         iScheduleService.wisdomExamSite(bo);
         return AjaxResult.success();
     }
+
+    @ApiOperation("批量同步考试计划用户")
+    @GetMapping("/syncApplyUserInfo")
+    public AjaxResult syncApplyUserInfo(UserQueryBo bo){
+        iScheduleService.syncApplyUserInfo(bo);
+        return AjaxResult.success();
+    }
 }

+ 13 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/user/UserSubscribeController.java

@@ -63,5 +63,18 @@ public class UserSubscribeController extends BaseController {
         return AjaxResult.success(userExamGoodsVo);
     }
 
+    /**
+     * 查询用户预约考试列表
+     */
+    @ApiOperation("查询预约列表")
+    @PreAuthorize("@ss.hasPermi('system:subscribe:list')")
+    @GetMapping("/listSubscribe")
+    public AjaxResult<List<UserSubscribeVo>> listSubscribeList(UserSubscribeQueryBo bo) {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        bo.setUserId(loginUser.getUser().getUserId());
+        List<UserSubscribeVo> list = iUserSubscribeService.listSubscribe(bo);
+        return AjaxResult.success(list);
+    }
+
 
 }

+ 26 - 1
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/ToolsUtils.java

@@ -5,11 +5,13 @@ import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
 import com.aliyun.teaopenapi.models.Config;
 import io.micrometer.core.lang.NonNull;
 
-import java.io.UnsupportedEncodingException;
+import java.io.*;
 import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 public class ToolsUtils {
 
@@ -236,4 +238,27 @@ public class ToolsUtils {
         return str;
     }
 
+    /**
+     * 将文件转换成Byte数组
+     */
+    public static byte[] getBytesByFile(String pathStr) {
+        File file = new File(pathStr);
+        try {
+            FileInputStream fis = new FileInputStream(file);
+            ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
+            byte[] b = new byte[1000];
+            int n;
+            while ((n = fis.read(b)) != -1) {
+                bos.write(b, 0, n);
+            }
+            fis.close();
+            byte[] data = bos.toByteArray();
+            bos.close();
+            return data;
+        } catch (IOException e) {
+        }
+        return null;
+    }
+
+
 }

+ 41 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/http/HttpUtils.java

@@ -168,6 +168,47 @@ public class HttpUtils
         return null;
     }
 
+    public static String sendPostJsonHeader(String url, String json, Map<String, String> headersMap)
+    {
+        System.out.println(json);
+        HttpClient client = HttpClients.createDefault();
+        HttpPost post = new HttpPost(url);
+        try {
+            //此处应设定参数的编码格式,不然中文会变乱码
+            StringEntity s = new StringEntity(json, "UTF-8");
+            s.setContentEncoding("UTF-8");
+            s.setContentType("application/json");
+            post.setEntity(s);
+            post.addHeader("content-type", "application/json");
+            headersMap.forEach(post::setHeader);
+            HttpResponse res = client.execute(post);
+            if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                if (res.getEntity().getContentType().getValue().equalsIgnoreCase("image/jpeg")) {
+                    InputStream inputStream = res.getEntity().getContent();
+                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+                    byte[] buffer = new byte[1024];
+                    int len = 0;
+                    while ((len = inputStream.read(buffer)) != -1){
+                        outputStream.write(buffer, 0, len);
+                    }
+                    inputStream.close();
+                    java.util.Base64.Encoder encoder1 = java.util.Base64.getEncoder();
+                    String encoder = "data:image/jpeg;base64,"
+                            + encoder1.encodeToString(outputStream.toByteArray());
+                    return encoder;
+                }
+                String result = EntityUtils.toString(res.getEntity());// 返回json格式
+                System.out.println("推送成功" + result);
+                return result;
+            } else {
+                System.out.println("推送失败");
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return null;
+    }
+
     public static String sendPostHeader(String url, JSONObject param, Map<String, String> headersMap)
     {
         HttpClient client = HttpClients.createDefault();

+ 19 - 14
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/wisdom/SignatureUtil.java

@@ -83,20 +83,25 @@ public class SignatureUtil {
         }
         return buffer.substring(1);
     }
-    public static void main(String[] args) throws Exception {
-        //参数
+
+
+    /**
+     * 创建签名字符串
+     *
+     * @param paramMapList
+     * @param key
+     * @return
+     * @throws SignatureException
+     */
+    public static String createSignature(List<Map<String, Object>> paramMapList, String key) throws
+            SignatureException {
+        Map<String, Object> paramMap = getMap(paramMapList, key);
+        return createSignature(paramMap, key);
+    }
+
+    private static Map<String, Object> getMap(List<Map<String, Object>> paramMapList, String key){
         Map<String, Object> paramMap = new HashMap<>();
-        //appid
-        String key = "12563";
-        paramMap.put("a", 10);
-        paramMap.put("z", "30");
-        //服务端返回的签名
-        String signature = createSignature(paramMap, key);
-        System.out.println("sign:"+ signature);
-        boolean signatureValid = isSignatureValid(paramMap, key, signature);
-        System.out.println("valid:"+ signatureValid);
-        paramMap.put("l", "30");
-        boolean signatureValid1 = isSignatureValid(paramMap, key, signature);
-        System.out.println("valid1:"+ signatureValid1);
+        paramMap.put(key, paramMapList);
+        return paramMap;
     }
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/alioss/service/OssService.java

@@ -3,6 +3,7 @@ package com.zhongzheng.modules.alioss.service;
 
 
 import com.zhongzheng.modules.alioss.bo.OssRequest;
+import com.zhongzheng.modules.alioss.vo.FileBean;
 import com.zhongzheng.modules.alioss.vo.ResultBean;
 import com.zhongzheng.modules.grade.vo.ClassPeriodStudentExportVo;
 import org.springframework.web.multipart.MultipartFile;
@@ -30,4 +31,6 @@ public interface OssService {
     void zipPeopleDownload(ClassPeriodStudentExportVo vo, ZipOutputStream outStream);
 
     void zipCommonDownload(List<String> fileList, ZipOutputStream zipOut, String dir);
+
+    void zipWisdomDownload(List<FileBean> list, ZipOutputStream outStream);
 }

+ 30 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/alioss/service/impl/OssServiceImpl.java

@@ -15,6 +15,7 @@ import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.modules.alioss.bo.OssCallbackParam;
 import com.zhongzheng.modules.alioss.bo.OssRequest;
 import com.zhongzheng.modules.alioss.service.OssService;
+import com.zhongzheng.modules.alioss.vo.FileBean;
 import com.zhongzheng.modules.alioss.vo.ResultBean;
 import com.zhongzheng.modules.grade.vo.ClassPeriodStudentExportVo;
 import com.zhongzheng.modules.user.service.IUserStudyRecordPhotoService;
@@ -363,6 +364,30 @@ public class OssServiceImpl implements OssService {
         }
     }
 
+    public void zipFile(List<FileBean> fileList, ZipOutputStream zipOut) {
+        if (CollectionUtils.isEmpty(fileList)) {
+            return;
+        }
+        for (FileBean file : fileList) {
+            if(Validator.isEmpty(file)){
+                continue;
+            }
+            String filePath = file.getPath();
+
+            try (InputStream in = getStreamByObject(filePath)) {
+                zipOut.putNextEntry(new ZipEntry(file.getFileName()));
+                byte[] bytes = new byte[1024];
+                int len;
+                while ((len = in.read(bytes)) != -1) {
+                    zipOut.write(bytes, 0, len);
+                }
+                zipOut.closeEntry();
+            }catch (Exception e){
+                System.out.println(e.getMessage()+"压缩错误");
+            }
+        }
+    }
+
     private String getFileName(String filePath,String dir) {
         String filename = filePath.substring(filePath.lastIndexOf("/") + 1)+".jpg";
         if(Validator.isNotEmpty(dir)){
@@ -395,4 +420,9 @@ public class OssServiceImpl implements OssService {
         zipFile(fileList, zipOut,dir);
     }
 
+    @Override
+    public void zipWisdomDownload(List<FileBean> list, ZipOutputStream outStream) {
+        zipFile(list, outStream);
+    }
+
 }

+ 14 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/alioss/vo/FileBean.java

@@ -0,0 +1,14 @@
+package com.zhongzheng.modules.alioss.vo;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+@Data
+@ApiModel("【oss】视图对象")
+public class FileBean {
+
+    private String path;
+
+    private String fileName;
+
+}

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/schedule/service/IScheduleService.java

@@ -72,4 +72,6 @@ public interface IScheduleService extends IService<PolyvVideo> {
     void longNotReadToTeacher(UserQueryBo bo);
 
     void wisdomExamSite(UserQueryBo bo);
+
+    void syncApplyUserInfo(UserQueryBo bo);
 }

+ 5 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/schedule/service/impl/ScheduleServiceImpl.java

@@ -2112,6 +2112,11 @@ public class ScheduleServiceImpl extends ServiceImpl<PolyvVideoMapper, PolyvVide
         iWisdomService.SiteList(1);
     }
 
+    @Override
+    public void syncApplyUserInfo(UserQueryBo bo) {
+        iWisdomService.syncApplyUserInfo(192L);
+    }
+
     private Long formatTime(Long startTime, String addTime) throws ParseException{
         Long times = startTime*1000;//时间戳
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

+ 63 - 3
zhongzheng-system/src/main/java/com/zhongzheng/modules/wisdom/service/impl/WisdomServiceImpl.java

@@ -14,8 +14,12 @@ import com.zhongzheng.common.core.domain.entity.SysUser;
 import com.zhongzheng.common.core.redis.RedisCache;
 import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.common.utils.ToolsUtils;
+import com.zhongzheng.common.utils.file.FileUtils;
 import com.zhongzheng.common.utils.http.HttpUtils;
 import com.zhongzheng.common.utils.wisdom.SignatureUtil;
+import com.zhongzheng.modules.alioss.service.OssService;
+import com.zhongzheng.modules.alioss.vo.FileBean;
 import com.zhongzheng.modules.alisms.vo.ResultBean;
 import com.zhongzheng.modules.base.service.IProfileTpService;
 import com.zhongzheng.modules.base.vo.ProfileTpVo;
@@ -107,11 +111,14 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
+import java.util.zip.ZipOutputStream;
 
 
 @Service
@@ -133,6 +140,8 @@ public class WisdomServiceImpl  implements IWisdomService {
 
     private String getCentersListUrl = "/exam/api/centers";
 
+    private String batchUserUrl = "/exam/api/examinees";
+
     @Autowired
     private RedisCache redisCache;
 
@@ -142,6 +151,9 @@ public class WisdomServiceImpl  implements IWisdomService {
     @Autowired
     private IUserSubscribeService iUserSubscribeService;
 
+    @Autowired
+    private OssService ossService;
+
     @Override
     public String authorization() {
         String key = "WISDOM_AUTH_CODE";
@@ -206,7 +218,6 @@ public class WisdomServiceImpl  implements IWisdomService {
 
     @Override
     public void syncApplyUserInfo(Long applyId) {
-
         List<UserSubscribeVo> list = iUserSubscribeService.selectApplyUserList(applyId);
         Map<Long,CenterVo> cMap = new HashMap<>();
         List<CenterVo> cList = new ArrayList<>();
@@ -235,6 +246,7 @@ public class WisdomServiceImpl  implements IWisdomService {
                 centerVo.setExaminees(examinees);
                 centerVo.setCenterId(vo.getCenterId());
                 centerVo.setExamCode(vo.getSiteCode());
+                centerVo.setZipFileName(vo.getApplyName()+"考生证件照");
                 cMap.put(vo.getCenterId(),centerVo);
             }
         }
@@ -242,11 +254,59 @@ public class WisdomServiceImpl  implements IWisdomService {
         while (iterator.hasNext()) {
             Long key = iterator.next();
             CenterVo vo = cMap.get(key);
-            for(ExamineesVo userVo : vo.getExaminees()){
-
+            String filename = FileUtils.encodingZipFilename(vo.getZipFileName());
+            String zipFile = FileUtils.getZipAbsoluteFile(filename);
+            System.out.println(zipFile);
+            try {
+                ZipOutputStream outStream = new ZipOutputStream(new FileOutputStream(zipFile));
+                List<FileBean> fileBeanList = new ArrayList<>();
+                for(ExamineesVo userVo : vo.getExaminees()){
+                    FileBean f1 = new FileBean();
+                    f1.setPath(userVo.getIdCardImg1());
+                    f1.setFileName(userVo.getExamineeCode()+"_0.jpg");
+                    FileBean f2 = new FileBean();
+                    f2.setPath(userVo.getIdCardImg2());
+                    f2.setFileName(userVo.getExamineeCode()+"_1.jpg");
+                    fileBeanList.add(f1);
+                    fileBeanList.add(f2);
+                }
+                System.out.println(fileBeanList);
+                ossService.zipWisdomDownload(fileBeanList,outStream);
+                outStream.close();
+                byte[] dataByte = ToolsUtils.getBytesByFile(zipFile);
+   //             vo.setExamineeZipFiles();
+            } catch (IOException e) {
+                System.out.println(e.getMessage() + "压缩");
             }
             cList.add(vo);
         }
+        String url = host + batchUserUrl;
+        String auth_code = authorization();
+        List<Map<String, Object>> paramMapList = new ArrayList<>();
+        for(CenterVo vo : cList){
+            Map<String, Object> map = new HashMap<>();
+            map.put("centerId",vo.getCenterId());
+            map.put("examCode",vo.getExamCode());
+            map.put("examinees",vo.getExaminees());
+            map.put("zipFileName",vo.getZipFileName());
+    //        map.put("examineeZipFiles",vo.getExamineeZipFiles());
+            paramMapList.add(map);
+        }
+        try{
+            String signature = SignatureUtil.createSignature(paramMapList, appid);
+            /*JSONObject obj = new JSONObject();
+            JSONArray jsonArray = new JSONArray();
+            jsonArray.add(paramMapList);*/
+            Map<String, String> hearders = new HashMap<>();
+            hearders.put("auth_code", auth_code);
+            hearders.put("appid", appid);
+            hearders.put("sign", signature);
+            System.out.println(signature);
+            String result = HttpUtils.sendPostJsonHeader(url,JSON.toJSONString(paramMapList),hearders);
+
+        }catch (Exception e){
+
+        }
 
     }
 }

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

@@ -380,10 +380,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                u.id_card_img1,
                u.id_card_img2,
                es.center_id,
-               es.code as site_code
+               es.code as site_code,
+               ea.apply_name
         FROM
             user_subscribe us
                 LEFT JOIN `user` u on u.user_id =us.user_id
+                LEFT JOIN exam_apply ea on us.apply_id = ea.apply_id
                 LEFT JOIN exam_site es on us.site_id = es.site_id
         WHERE 1=1
           and us.subscribe_status =1