Commit 11bd027cf2420fef7540074cca7bdcb29b847f48

Authored by zhangchao
1 parent ba62a6706a
Exists in dev

#fix:新增视频分段上传功能

Showing 3 changed files with 209 additions and 66 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PregnantBuildController.java View file @ 11bd027
... ... @@ -643,6 +643,26 @@
643 643 }
644 644  
645 645 /**
  646 + * 视频分片上传
  647 + * @param fileName 文件名称
  648 + * @param file 原文件
  649 + * @param chunk 分片
  650 + * @param chunks 分片总数
  651 + * @return
  652 + */
  653 + @RequestMapping(value = "/uploadVideo", method = RequestMethod.POST)
  654 + @ResponseBody
  655 + public BaseResponse uploadVideo(@RequestParam(value="fileName") String fileName,
  656 + @RequestParam(value="file") MultipartFile file,
  657 + @RequestParam(value="chunk") int chunk,
  658 + @RequestParam(value="chunks") int chunks){
  659 +
  660 + return bookbuildingFacade.uploadVideo(fileName,file,chunk,chunks);
  661 +
  662 + }
  663 +
  664 +
  665 + /**
646 666 * 图片上次
647 667 *
648 668 * @param request
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java View file @ 11bd027
... ... @@ -26,6 +26,7 @@
26 26 import com.lyms.platform.operate.web.result.*;
27 27 import com.lyms.platform.operate.web.service.ITrackDownService;
28 28 import com.lyms.platform.operate.web.utils.CommonsHelper;
  29 +import com.lyms.platform.operate.web.utils.FileUtils;
29 30 import com.lyms.platform.operate.web.utils.JdbcUtil;
30 31 import com.lyms.platform.operate.web.worker.BatchUpdateLymsPatient;
31 32 import com.lyms.platform.permission.dao.master.CouponMapper;
... ... @@ -53,6 +54,7 @@
53 54 import org.springframework.web.client.RestTemplate;
54 55 import org.springframework.web.multipart.MultipartFile;
55 56  
  57 +import javax.servlet.ServletContext;
56 58 import javax.servlet.http.HttpServletRequest;
57 59 import javax.servlet.http.HttpServletResponse;
58 60 import java.io.File;
... ... @@ -479,7 +481,7 @@
479 481 PatientService patientService = new PatientService();
480 482 patientService.setSerInfos(yunRequest.getSerInfos());
481 483 patientService.setPerType(1);
482   - if(userId!=null){
  484 + if (userId != null) {
483 485 patientService.setCreateUser(String.valueOf(userId));
484 486 }
485 487 //开通日期与建档日期一致
... ... @@ -608,7 +610,7 @@
608 610 //根据patient查询是否存在追访信息
609 611 TrackDownRecordQuery downRecordQuery = new TrackDownRecordQuery();
610 612 downRecordQuery.setParentId(patient.getId());
611   - // downRecordQuery.setStatus(3);
  613 + // downRecordQuery.setStatus(3);
612 614 List<TrackDownRecord> records = trackDownRecordService.queryTrackDown(downRecordQuery);
613 615 if (CollectionUtils.isNotEmpty(records)) {//存在则进行修改,只修改基本信息,不修改显示状态和追访类型
614 616 TrackDownRecord trackDownRecord1 = records.get(0);
615 617  
... ... @@ -1296,15 +1298,15 @@
1296 1298 final List<Patients> patientList = patientsService.queryPatient(patientsQuery);
1297 1299  
1298 1300 if (CollectionUtils.isNotEmpty(patientList)) {
1299   - final String date= DateUtil.getyyyy_MM_dd(DateUtil.addDay(new Date(),0));
1300   - final String planTime = date+ " 16:30:00";
  1301 + final String date = DateUtil.getyyyy_MM_dd(DateUtil.addDay(new Date(), 0));
  1302 + final String planTime = date + " 16:30:00";
1301 1303 commonThreadPool.execute(new Runnable() {
1302 1304 @Override
1303 1305 public void run() {
1304 1306 for (Patients patients : patientList) {
1305 1307 //TODO 处理建档短信提醒逻辑
1306 1308 List<MsgRequest> messages = new ArrayList<>();
1307   - final String hospitalId=patients.getHospitalId();
  1309 + final String hospitalId = patients.getHospitalId();
1308 1310 String title = "建档成功提醒短信";
1309 1311 String messageContent = "【" + getHospitalName(hospitalId) + "】" + "您已成功建档!请微信-添加朋友-公众号-搜索“美生孕育”关注;点击开通成功提醒,手机号获取验证码成功登录宝贝孕程小程序。请您经常登录【宝贝孕程】小程序并持续关注【美生孕育】公众号,以便于您享受孕期的私有化服务,会依据您的年龄、孕周、单双胎、高危风险因素给予专题文章、个性指导、产检提醒等,让您了解、掌握和促进健康孕育,让我们携手并进一起迎接小宝宝的降生。";
1310 1312 MsgRequest request = new MsgRequest();
1311 1313  
1312 1314  
1313 1315  
1314 1316  
1315 1317  
1316 1318  
1317 1319  
... ... @@ -1337,32 +1339,32 @@
1337 1339 logger.info("bookbuildingMsg end");
1338 1340 }
1339 1341  
1340   - private static String getHospitalName(String hospitalId){
  1342 + private static String getHospitalName(String hospitalId) {
1341 1343 //TODO 暂时这样处理后期优化
1342   - if ("2100002419".equals(hospitalId)){
1343   - return "大同市第一人民医院";
1344   - }else if ("1000000016".equals(hospitalId)){
  1344 + if ("2100002419".equals(hospitalId)) {
  1345 + return "大同市第一人民医院";
  1346 + } else if ("1000000016".equals(hospitalId)) {
1345 1347 return "秦皇岛市第二医院";
1346   - }else if ("2100002421".equals(hospitalId)){
  1348 + } else if ("2100002421".equals(hospitalId)) {
1347 1349 return "邢台威县人民医院";
1348   - }else if ("1000000115".equals(hospitalId)){
1349   - return "南和区人民医院";
1350   - }else if("2100001296".equals(hospitalId)){
  1350 + } else if ("1000000115".equals(hospitalId)) {
  1351 + return "南和区人民医院";
  1352 + } else if ("2100001296".equals(hospitalId)) {
1351 1353 return "临城县人民医院";
1352   - }else if("2100001306".equals(hospitalId)){
1353   - return "临西县人民医院";
  1354 + } else if ("2100001306".equals(hospitalId)) {
  1355 + return "临西县人民医院";
1354 1356 }
1355   - return "";
  1357 + return "";
1356 1358 }
1357 1359  
1358 1360 /**
1359 1361 * 大同服务内容提醒 上午9点推送
1360 1362 * 开通服务第1天、第7天、第14天、第21天、第28天去推送
1361 1363 */
1362   - public void serviceSync(){
  1364 + public void serviceSync() {
1363 1365 logger.info("serviceSync startup...");
1364 1366 final String hospitalId = "2100002419";
1365   - Date day=DateUtil.getYMDTime();
  1367 + Date day = DateUtil.getYMDTime();
1366 1368 PatientsQuery patientsQuery = new PatientsQuery();
1367 1369 patientsQuery.setHospitalId(hospitalId);
1368 1370 patientsQuery.setExtEnable(false);
... ... @@ -1370,15 +1372,15 @@
1370 1372 patientsQuery.setYn(YnEnums.YES.getId());
1371 1373 patientsQuery.setServiceType(ServiceTypeEnums.ADD_SERVICE.getId());
1372 1374 patientsQuery.setServiceStatus(ServiceStatusEnums.ADD_OPEN.getId());
1373   - Date seven= DateUtil.addDay(day,-7);
1374   - Date fourteen= DateUtil.addDay(day,-14);
1375   - Date twenty=DateUtil.addDay(day,-21);
1376   - Date twentyEight=DateUtil.addDay(day,-28);
1377   - Map<String,Date> params=new HashMap<>();
1378   - params.put("seven",seven);
1379   - params.put("fourteen",fourteen);
1380   - params.put("twenty",twenty);
1381   - params.put("twentyEight",twentyEight);
  1375 + Date seven = DateUtil.addDay(day, -7);
  1376 + Date fourteen = DateUtil.addDay(day, -14);
  1377 + Date twenty = DateUtil.addDay(day, -21);
  1378 + Date twentyEight = DateUtil.addDay(day, -28);
  1379 + Map<String, Date> params = new HashMap<>();
  1380 + params.put("seven", seven);
  1381 + params.put("fourteen", fourteen);
  1382 + params.put("twenty", twenty);
  1383 + params.put("twentyEight", twentyEight);
1382 1384 patientsQuery.setServiceTime("1");
1383 1385 patientsQuery.setMapTime(params);
1384 1386 final List<Patients> patientList = patientsService.queryPatient(patientsQuery);
1385 1387  
... ... @@ -1390,9 +1392,9 @@
1390 1392 for (int i = 0, j = patientList.size(); i < j; i++) {
1391 1393 Patients patients = patientList.get(i);
1392 1394 try {
1393   - patientServiceFacade.sendServiceMsg(patients,SmsServiceEnums.FWKT.getId(),"您好,请点击此处查看开通服务内容详情。","大同市第一人民医院",patients.getType(),null);
  1395 + patientServiceFacade.sendServiceMsg(patients, SmsServiceEnums.FWKT.getId(), "您好,请点击此处查看开通服务内容详情。", "大同市第一人民医院", patients.getType(), null);
1394 1396 } catch (Exception e) {
1395   - logger.error("weekSync InterruptedException," + e.getMessage());
  1397 + logger.error("weekSync InterruptedException," + e.getMessage());
1396 1398 }
1397 1399 }
1398 1400 }
... ... @@ -3461,6 +3463,51 @@
3461 3463 return patientId;
3462 3464 }
3463 3465  
  3466 + public BaseResponse uploadVideo(String fileName,
  3467 + MultipartFile file,
  3468 + int chunk, int chunks) {
  3469 + BaseObjectResponse objectResponse = new BaseObjectResponse();
  3470 + try {
  3471 +
  3472 + //临时路径
  3473 + String tempsDirPath="tempsDir";
  3474 + //创建临时文件储存目录
  3475 + File tempsDir = new File(BASE_IMG_PATH + File.separator + tempsDirPath, fileName);
  3476 + if (!tempsDir.exists()) {
  3477 + tempsDir.mkdirs();
  3478 + }
  3479 + //储存为临时文件
  3480 + File tempFile = new File(tempsDir.getAbsolutePath(), fileName + ".part" + chunk);
  3481 + file.transferTo(tempFile);
  3482 + //检查分片是否下载完成
  3483 + int successChunks = FileUtils.getInstance().successChunks(fileName, chunks);
  3484 +
  3485 + if (successChunks == chunks) {
  3486 + //正式路径
  3487 + String imgPath = DateUtil.getYmd(new Date());
  3488 + //分片下载完成后合并分片为文件
  3489 + FileUtils.getInstance().mergeChunks(tempsDir.getAbsolutePath(),
  3490 + BASE_IMG_PATH + File.separator +imgPath
  3491 + , fileName, chunks);
  3492 + //返回文件地址
  3493 + objectResponse.setData(imgPath + "/" + fileName);
  3494 + objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
  3495 + objectResponse.setErrormsg("成功");
  3496 + } else {
  3497 + objectResponse.setErrorcode(1);
  3498 + objectResponse.setErrormsg("上传中");
  3499 + }
  3500 + return objectResponse;
  3501 + } catch (Exception e) {
  3502 + ExceptionUtils.catchException(e, "上传文件发生异常");
  3503 + objectResponse.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR);
  3504 + objectResponse.setErrormsg(ErrorCodeConstants.SYSTEM_ERROR_DESCRIPTION);
  3505 + return objectResponse;
  3506 + }
  3507 +
  3508 + }
  3509 +
  3510 +
3464 3511 public BaseResponse uploadImg(MultipartFile file) {
3465 3512 //如果文件不为空,写入上传路径
3466 3513 BaseObjectResponse objectResponse = new BaseObjectResponse();
... ... @@ -4477,7 +4524,7 @@
4477 4524 serInfos.add(params);
4478 4525 patientService.setSerInfos(serInfos);
4479 4526 patientService.setPerType(1);
4480   - if (StringUtils.isNotEmpty(patient.getFirstCheckId())){
  4527 + if (StringUtils.isNotEmpty(patient.getFirstCheckId())) {
4481 4528 patientService.setCreateUser(patient.getFirstCheckId());
4482 4529 }
4483 4530  
... ... @@ -4942,7 +4989,7 @@
4942 4989 patientsQuery.setType(1);
4943 4990 boolean b = false;
4944 4991 Patients patient = null;
4945   - Integer num=1;
  4992 + Integer num = 1;
4946 4993 if (StringUtils.isNotEmpty(map.get("cardNo"))) {
4947 4994 patientsQuery.setCardNo(map.get("cardNo").trim());
4948 4995 //判断该身份证号码是否有孕妇建档 在该医院
... ... @@ -4950,8 +4997,8 @@
4950 4997 if (CollectionUtils.isNotEmpty(patients)) {
4951 4998 b = true;
4952 4999 patient = patients.get(0);
4953   - if (patient.getNextCheckTime()!=null&&patient.getNextCheckTime().compareTo(DateUtil.parseYMD(map.get("nextCheckTime")))<0){
4954   - num=2;
  5000 + if (patient.getNextCheckTime() != null && patient.getNextCheckTime().compareTo(DateUtil.parseYMD(map.get("nextCheckTime"))) < 0) {
  5001 + num = 2;
4955 5002 }
4956 5003 } else {
4957 5004 patient = new Patients();
4958 5005  
... ... @@ -4973,9 +5020,9 @@
4973 5020 patient.setLastReportDoctorName(users.get(0).getName());
4974 5021 }
4975 5022 }
4976   - if (StringUtils.isEmpty(map.get("lastMenses"))){
  5023 + if (StringUtils.isEmpty(map.get("lastMenses"))) {
4977 5024 patient.setLastMenses(DateUtil.getCurrentDueDate(map.get("currentDueDate"), map.get("bookbuildingDate")));
4978   - }else {
  5025 + } else {
4979 5026 patient.setLastMenses(DateUtil.parseYMD(map.get("lastMenses")));
4980 5027 }
4981 5028 Integer type = 1; //1孕妇 2儿童 3产妇
4982 5029  
... ... @@ -5024,17 +5071,17 @@
5024 5071 patient.setAge(Integer.valueOf(map.get("age")));
5025 5072 patient.setBirth(DateUtil.parseYMD(map.get("birth")));
5026 5073  
5027   - // patient.setAddressRegister(map.get("xian") + map.get("xiang") + map.get("cun"));
  5074 + // patient.setAddressRegister(map.get("xian") + map.get("xiang") + map.get("cun"));
5028 5075 patient.setPhone(map.get("phone").trim());
5029 5076 patient.setFirstCheckId(String.valueOf(patient.getOperator()));
5030 5077 patient.setFirstCheckTime(patient.getBookbuildingDate());
5031 5078 if (patient.getLastMenses() != null) {
5032 5079 patient.setBuildDays(DateUtil.getDays(patient.getLastMenses(), new Date()));
5033   - String dueDate=null;
5034   - if (StringUtils.isNotEmpty(map.get("dueDate"))){
5035   - dueDate= map.get("dueDate");
5036   - }else {
5037   - dueDate=DateUtil.getyyyy_MM_dd(DateUtil.addDay(patient.getLastMenses(), 42 * 7));
  5080 + String dueDate = null;
  5081 + if (StringUtils.isNotEmpty(map.get("dueDate"))) {
  5082 + dueDate = map.get("dueDate");
  5083 + } else {
  5084 + dueDate = DateUtil.getyyyy_MM_dd(DateUtil.addDay(patient.getLastMenses(), 42 * 7));
5038 5085 }
5039 5086 patient.setDueDate(DateUtil.parseYMD(dueDate));
5040 5087 }
... ... @@ -5100,11 +5147,11 @@
5100 5147 patient.setNextCheckTime(DateUtil.parseYMD(map.get("nextCheckTime")));
5101 5148 if (patient.getDueDate() != null) {
5102 5149 } else {
5103   - String dueDate=null;
5104   - if (StringUtils.isNotEmpty(map.get("dueDate"))){
5105   - dueDate= map.get("dueDate");
5106   - }else {
5107   - dueDate=DateUtil.getyyyy_MM_dd(DateUtil.addDay(patient.getLastMenses(), 42 * 7));
  5150 + String dueDate = null;
  5151 + if (StringUtils.isNotEmpty(map.get("dueDate"))) {
  5152 + dueDate = map.get("dueDate");
  5153 + } else {
  5154 + dueDate = DateUtil.getyyyy_MM_dd(DateUtil.addDay(patient.getLastMenses(), 42 * 7));
5108 5155 }
5109 5156 patient.setDueDate(DateUtil.parseYMD(dueDate));
5110 5157  
... ... @@ -5127,7 +5174,7 @@
5127 5174 }
5128 5175  
5129 5176  
5130   - // Integer num = Integer.valueOf(map.get("num"));
  5177 + // Integer num = Integer.valueOf(map.get("num"));
5131 5178 AntExRecordModel antExRecordModel = new AntExRecordModel();
5132 5179 AntExChuModel antExChuModel = new AntExChuModel();
5133 5180 String riskFactor = map.get("name");
... ... @@ -5213,7 +5260,7 @@
5213 5260 antExChuModel.setProdDoctor(String.valueOf(patient.getOperator()));
5214 5261  
5215 5262  
5216   - antExChuModel= antenatalExaminationService.addOneAntEx(antExChuModel);
  5263 + antExChuModel = antenatalExaminationService.addOneAntEx(antExChuModel);
5217 5264 antExRecordModel.setfId(antExChuModel.getId());
5218 5265 antExRecordService.addOneRecord(antExRecordModel);
5219 5266 //初诊是添加追访记录
5220 5267  
... ... @@ -5222,26 +5269,26 @@
5222 5269  
5223 5270  
5224 5271 if (num > 1) {
5225   - antExRecordModel.setId(null);
5226   - antExRecordModel.setType(2);
5227   - AntenatalExaminationModel antenatalExaminationModel = new AntenatalExaminationModel();
5228   - antenatalExaminationModel.setYn(1);
5229   - antenatalExaminationModel.setParentId(patient.getId());
5230   - antenatalExaminationModel.setPid(patient.getPid());
5231   - antenatalExaminationModel.setCheckDoctor(String.valueOf(patient.getOperator()));
5232   - antenatalExaminationModel.setHospitalId("2100001504");
5233   - antenatalExaminationModel.setName(map.get("username"));
5234   - antenatalExaminationModel.setRiskScore(antExChuModel.getHighriskSocre());
5235   - antenatalExaminationModel.setRiskFactor(antExChuModel.getHighrisk());
5236   - antenatalExaminationModel.setLastMenses(patient.getLastMenses());
5237   - antenatalExaminationModel.setNextCheckTime(DateUtil.parseYMD(map.get("nextCheckTime")));
5238   - antenatalExaminationModel.setCurrentDueDate(map.get("currentDueDate"));
5239   - antenatalExaminationModel.setCheckDate(DateUtil.parseYMD(map.get("checkDate")));
5240   - antenatalExaminationModel=antenatalExaminationService.addOneBabyAnt(antenatalExaminationModel);
  5272 + antExRecordModel.setId(null);
  5273 + antExRecordModel.setType(2);
  5274 + AntenatalExaminationModel antenatalExaminationModel = new AntenatalExaminationModel();
  5275 + antenatalExaminationModel.setYn(1);
  5276 + antenatalExaminationModel.setParentId(patient.getId());
  5277 + antenatalExaminationModel.setPid(patient.getPid());
  5278 + antenatalExaminationModel.setCheckDoctor(String.valueOf(patient.getOperator()));
  5279 + antenatalExaminationModel.setHospitalId("2100001504");
  5280 + antenatalExaminationModel.setName(map.get("username"));
  5281 + antenatalExaminationModel.setRiskScore(antExChuModel.getHighriskSocre());
  5282 + antenatalExaminationModel.setRiskFactor(antExChuModel.getHighrisk());
  5283 + antenatalExaminationModel.setLastMenses(patient.getLastMenses());
  5284 + antenatalExaminationModel.setNextCheckTime(DateUtil.parseYMD(map.get("nextCheckTime")));
  5285 + antenatalExaminationModel.setCurrentDueDate(map.get("currentDueDate"));
  5286 + antenatalExaminationModel.setCheckDate(DateUtil.parseYMD(map.get("checkDate")));
  5287 + antenatalExaminationModel = antenatalExaminationService.addOneBabyAnt(antenatalExaminationModel);
5241 5288 antExRecordModel.setfId(antenatalExaminationModel.getId());
5242 5289 antExRecordService.addOneRecord(antExRecordModel);
5243   - //添加复诊时添加追访信息
5244   - antenatalExaminationFacade.addTrackDownInfo(patient.getOperator(), patient, map.get("nextCheckTime"));
  5290 + //添加复诊时添加追访信息
  5291 + antenatalExaminationFacade.addTrackDownInfo(patient.getOperator(), patient, map.get("nextCheckTime"));
5245 5292 }
5246 5293 }
5247 5294 });
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/FileUtils.java View file @ 11bd027
  1 +package com.lyms.platform.operate.web.utils;
  2 +
  3 +import java.io.*;
  4 +import java.util.concurrent.ConcurrentHashMap;
  5 +
  6 +public class FileUtils {
  7 + //记录已经上传成功的分片文件数量,线程安全
  8 + private static ConcurrentHashMap<String,Integer> successChunksCount = new ConcurrentHashMap<>();
  9 + private static FileUtils instance = new FileUtils();
  10 +
  11 + public static FileUtils getInstance(){
  12 + return instance;
  13 + }
  14 +
  15 + /**
  16 + * 每上传成功一个文件的分片,就在文件名对应的值加1
  17 + * 对比分片总数,如果上传成功分片数等于分片总数则调用合并文件方法
  18 + * @param fileName
  19 + * @param chunks
  20 + * @return
  21 + */
  22 + public int successChunks(String fileName,int chunks){
  23 + int chunksNow = successChunksCount.get(fileName)==null ? 0 : successChunksCount.get(fileName);
  24 + chunksNow ++;
  25 + if(chunks==chunksNow){
  26 + successChunksCount.remove(fileName);
  27 + }else{
  28 + successChunksCount.put(fileName, chunksNow);
  29 + }
  30 + return chunksNow;
  31 + }
  32 +
  33 + /**
  34 + * 上传完成后合并分片文件
  35 + * @param sourceDirPath 分片的目录地址
  36 + * @param destDirPath 合成后存放的目录地址
  37 + * @param fileName 文件名
  38 + * @param chunks 分片总数
  39 + * @return
  40 + * @throws FileNotFoundException
  41 + */
  42 + public boolean mergeChunks(String sourceDirPath,
  43 + String destDirPath,String fileName,int chunks) throws Exception{
  44 + //创建目标目录
  45 + File destDir = new File(destDirPath);
  46 + if(!destDir.exists()){
  47 + destDir.mkdirs();
  48 + }
  49 + //创建目标文件流
  50 + BufferedOutputStream destOutputStream =
  51 + new BufferedOutputStream(new FileOutputStream(destDir+"/"+fileName));
  52 +
  53 + //循环将每个分片的数据写入目标文件
  54 + byte[] fileBuffer = new byte[1024];//文件读写缓存
  55 + int readBytesLength = 0;//每次读取字节数
  56 + System.out.println(("开始合并文件="+fileName));
  57 + for(int i=0; i<chunks; i++){
  58 + File sourceFile = new File(sourceDirPath+"/"+fileName+".part"+i);
  59 + BufferedInputStream sourceInputStream =
  60 + new BufferedInputStream(new FileInputStream(sourceFile));
  61 + while((readBytesLength=sourceInputStream.read(fileBuffer))!=-1){
  62 + destOutputStream.write(fileBuffer, 0, readBytesLength);
  63 + }
  64 + sourceInputStream.close();
  65 + //分片用完后删除
  66 + sourceFile.delete();
  67 + }
  68 + //文件合并完成后删除临时文件夹
  69 + File sourceDir = new File(sourceDirPath);
  70 + sourceDir.delete();
  71 + destOutputStream.flush();
  72 + destOutputStream.close();
  73 + System.out.println(("上传文件完成"));
  74 + return false;
  75 + }
  76 +}