Commit 585dd4a89dc6ca75fed3aaa395d7ab2dbbd54884

Authored by litao
1 parent 1731d1dd8e

优惠券报表详情和导出接口

Showing 4 changed files with 202 additions and 13 deletions

platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml View file @ 585dd4a
... ... @@ -223,10 +223,14 @@
223 223 </select>
224 224  
225 225 <select id="findCouponInfo" parameterType="map" resultType="map">
226   - select c.type, a.sequence_id, d.name, e.name as send_hospital, a.use_date
  226 + select c.type, a.sequence_id, d.name, e.name as send_hospital, a.use_date, a.used_id, b.coupon_order
227 227 from coupon_info a, coupon_template b, coupon_type c, users d, organization e, hospital_coupon_template_group f
228 228 where a.coupon_template_id = b.id and b.type_id = c.id and a.user_id = d.id and a.status=2 and a.create_hospital_id = e.id
229   - and a.used_hospital_id = #{hospitalId} and f.hospital_id = a.used_hospital_id and c.type in
  229 + and a.used_hospital_id in
  230 + <foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
  231 + #{hid}
  232 + </foreach>
  233 + and f.hospital_id = a.used_hospital_id and c.type in
230 234 <foreach collection="couponType" open="(" close=")" separator="," item="type">
231 235 #{type}
232 236 </foreach>
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java View file @ 585dd4a
... ... @@ -236,11 +236,40 @@
236 236 String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType,
237 237 Integer page, Integer limit) {
238 238 /* Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate,
239   - "endDate", endDate, "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type,
  239 + "endDate", endDate, "hospitalId", CollectionUtils.asList(hospitalId), "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type,
240 240 "tempId", tempId, "couponType", CollectionUtils.asList(couponType), "currentPage", page, "pageSize", limit);*/
241   - Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "hospitalId", "216", "type", type,
  241 + Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "hospitalId", CollectionUtils.asList("216"), "type", type,
242 242 "tempId", tempId, "couponType", CollectionUtils.asList("1,2,3,4,5,6,7,8"), "currentPage", page, "pageSize", limit);
243 243 return reportService.couponInfo(param);
  244 + }
  245 +
  246 + /**
  247 + * @param request
  248 + * @param startDate
  249 + * @param endDate
  250 + * @param type 1 = 孕期优惠券使用统计, 2 = 产后优惠券使用统计, 3 = 儿童优惠券使用统计
  251 + * @param response
  252 + * @param provinceId
  253 + * @param cityId
  254 + * @param areaId
  255 + * @param hospitalId
  256 + * @param tempId
  257 + * @param couponType
  258 + * @param page
  259 + * @param limit
  260 + */
  261 + @ResponseBody
  262 +// @TokenRequired
  263 + @RequestMapping(value = "/coupon/info/export", method = RequestMethod.GET)
  264 + public void couponInfoExport(HttpServletRequest request, Date startDate, Date endDate, Integer type, HttpServletResponse response,
  265 + String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType,
  266 + Integer page, Integer limit) {
  267 + /* Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate,
  268 + "endDate", endDate, "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type,
  269 + "tempId", tempId, "couponType", CollectionUtils.asList(couponType), "currentPage", page, "pageSize", limit);*/
  270 + Map<String, Object> param = CollectionUtils.createMap("userId", "1000000185", "hospitalId", CollectionUtils.asList("216"), "type", type,
  271 + "tempId", tempId, "couponType", CollectionUtils.asList("1,2,3,4,5,6,7,8"), "currentPage", page, "pageSize", limit);
  272 + reportService.exportCouponInfo(param, response);
244 273 }
245 274  
246 275 @ResponseBody
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java View file @ 585dd4a
... ... @@ -72,5 +72,7 @@
72 72 BaseObjectResponse couponInit(Map<String, Object> userId);
73 73  
74 74 BaseObjectResponse couponInfo(Map<String, Object> param);
  75 +
  76 + void exportCouponInfo(Map<String, Object> param, HttpServletResponse response);
75 77 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ 585dd4a
... ... @@ -14,10 +14,7 @@
14 14 import com.lyms.platform.operate.web.service.IReportService;
15 15 import com.lyms.platform.operate.web.utils.*;
16 16 import com.lyms.platform.permission.dao.master.CouponMapper;
17   -import com.lyms.platform.pojo.AntExChuModel;
18   -import com.lyms.platform.pojo.AntenatalExaminationModel;
19   -import com.lyms.platform.pojo.BasicConfig;
20   -import com.lyms.platform.pojo.Patients;
  17 +import com.lyms.platform.pojo.*;
21 18 import com.lymsh.platform.reportdata.model.echarts.Series;
22 19 import org.apache.commons.lang.StringUtils;
23 20 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -25,6 +22,7 @@
25 22 import org.springframework.data.mongodb.core.query.Criteria;
26 23 import org.springframework.data.mongodb.core.query.Query;
27 24 import org.springframework.stereotype.Service;
  25 +import scala.annotation.target.param;
28 26  
29 27 import javax.servlet.http.HttpServletResponse;
30 28 import java.sql.PreparedStatement;
... ... @@ -72,6 +70,11 @@
72 70 */
73 71 private static final Map<String, Object> couponReportMap = new HashMap<>();
74 72  
  73 + /**
  74 + * 优惠券类型描述map
  75 + */
  76 + private static final Map<Integer, String> couponDescMap = new HashMap<>();
  77 +
75 78 @Autowired
76 79 private SystemDataSource db;
77 80  
... ... @@ -108,6 +111,16 @@
108 111 couponReportMap.put("6_2", "<div class='ag-double-line'>产后复查券(一)<div>使用人次</div></div>");
109 112 couponReportMap.put("6_3", "<div class='ag-double-line'>产后复查券(二)<div>使用人次</div></div>");
110 113 couponReportMap.put("6_4", "<div class='ag-double-line'>产后复查券(三)<div>使用人次</div></div>");
  114 +
  115 + /** 1=孕妇建档 2=孕妇产检 3=产妇建档 4=产妇分娩 5=产妇出院小结 6=产妇产后复查 7=儿童建档 8=儿童保健 */
  116 + couponDescMap.put(1, "孕妇建档券");
  117 + couponDescMap.put(2, "孕妇产检券");
  118 + couponDescMap.put(3, "产妇建档券");
  119 + couponDescMap.put(4, "产妇分娩券");
  120 + couponDescMap.put(5, "产妇出院小结券");
  121 + couponDescMap.put(6, "产妇产后复查券");
  122 + couponDescMap.put(7, "儿童建档券");
  123 + couponDescMap.put(8, "儿童保健券");
111 124 }
112 125  
113 126 @Override
114 127  
115 128  
116 129  
117 130  
118 131  
... ... @@ -490,20 +503,145 @@
490 503 @Override
491 504 public BaseObjectResponse couponInfo(Map<String, Object> param) {
492 505 PageUtil.setPageInfo(param);
493   - if(StringUtils.isEmpty((String) param.get("hospitalId"))) {
  506 + if(StringUtils.isEmpty(param.get("hospitalId") + "")) {
494 507 param.put("hospitalId", accessPermissionFacade.getCurrentUserHospPermissions(Integer.parseInt(param.get("userId") + ""))); /** 根据登陆人id 查询出来的医院 */
495 508 }
496   - Map<String, Object> hospitalName = couponMapper.findHospitalName(param);
497 509 List<Map<String, Object>> couponInfos = couponMapper.findCouponInfo(param);
498 510 for (Map<String, Object> couponInfo : couponInfos) {
  511 + String desc = (String) couponReportMap.get(couponInfo.get("type") + "_" + couponInfo.get("coupon_order"));
  512 + if(StringUtils.isNotBlank(desc)) {
  513 + /** <div class='ag-double-line'>儿童保健券(五)<div>使用人次</div></div> */
  514 + String s = desc.replace("使用人次", "")
  515 + .replace("<div class='ag-double-line'>", "")
  516 + .replace("<div>", "")
  517 + .replace("</div>", "");
  518 + couponInfo.put("type_desc", s);
  519 + }
  520 +
499 521 setAntexInfo(couponInfo);
500 522 }
501   - hospitalName.put("couponInfos", couponInfos);
502 523 int count = couponMapper.findCouponInfoCount(param);
503   - PageResult pageResult = new PageResult(count, (Integer) param.get("currentPage") ,(Integer) param.get("pageSize"), hospitalName);
  524 + PageResult pageResult = new PageResult(count, (Integer) param.get("currentPage") ,(Integer) param.get("pageSize"), CollectionUtils.createMap("couponInfos", couponInfos));
504 525 return RespBuilder.buildSuccess(pageResult);
505 526 }
506 527  
  528 + @Override
  529 + public void exportCouponInfo(Map<String, Object> param, HttpServletResponse response) {
  530 + BaseObjectResponse resp = couponInfo(param);
  531 + PageResult pageResult = (PageResult) resp.getData();
  532 + Map<String,Object> map = (Map<String, Object>) pageResult.getGrid();
  533 + List<Map<String, Object>> couponInfos = (List<Map<String, Object>>) map.get("couponInfos");
  534 +
  535 + Integer type = (Integer) param.get("type");
  536 + if(type == 1) { /** 孕期 */
  537 + exportPregnancy(couponInfos, response);
  538 + } else if(type == 2 || type == 3) { /** 产后和儿童类似 */
  539 + exportPostpartum(couponInfos, response);
  540 + } /*else if(type == 3) { *//** 儿童 *//*
  541 + exportChild(couponInfos, response);
  542 + }*/
  543 +
  544 + }
  545 +
  546 + private void exportChild(List<Map<String, Object>> couponInfos, HttpServletResponse response) {
  547 + Map<String, String> cnames = new LinkedHashMap<>();
  548 + cnames.put("id", "#");
  549 + cnames.put("checkDate", "产检日期");
  550 + cnames.put("username", "姓名");
  551 + cnames.put("patient_week", "建档孕周");
  552 + cnames.put("patient_org_name", "建档机构");
  553 + cnames.put("patient_docker_name", "建档医生");
  554 + cnames.put("address", "居住地");
  555 + cnames.put("census_register", "户籍地");
  556 + cnames.put("phone", "联系电话");
  557 +
  558 + List<Map<String,Object>> results = new ArrayList<>();
  559 + int i = 0;
  560 + for (Map<String, Object> m : couponInfos) {
  561 + Map<String, Object> result = new LinkedHashMap<>();
  562 + result.put("id", ++i);
  563 + result.put("checkDate", DateUtil.getyyyy_MM_dd((Date) m.get("checkDate")));
  564 + result.put("username", m.get("username"));
  565 + result.put("use_day", m.get("use_day"));
  566 + result.put("type", couponDescMap.get(m.get("type")));
  567 + result.put("coupon_desc", couponReportMap.get(m.get("type") + "_" + m.get("coupon_order")));
  568 + result.put("sequence_id", m.get("sequence_id"));
  569 + result.put("operatorOrgName", m.get("operatorOrgName"));
  570 + result.put("doctorName", m.get("doctorName"));
  571 + result.put("send_hospital", m.get("send_hospital"));
  572 + result.put("phone", m.get("phone"));
  573 + results.add(result);
  574 + }
  575 + ResponseUtil.responseExcel(cnames, results, response);
  576 + }
  577 +
  578 + private void exportPostpartum(List<Map<String, Object>> couponInfos, HttpServletResponse response) {
  579 + Map<String, String> cnames = new LinkedHashMap<>();
  580 + cnames.put("id", "#");
  581 + cnames.put("checkDate", "产检日期");
  582 + cnames.put("username", "姓名");
  583 + cnames.put("use_day", "使用时间");
  584 + cnames.put("type", "产检券类型");
  585 + cnames.put("coupon_desc", "优惠券");
  586 + cnames.put("sequence_id", "优惠券号");
  587 + cnames.put("operatorOrgName", "使用机构");
  588 + cnames.put("doctorName", "使用医生");
  589 + cnames.put("send_hospital", "优惠券发放机构");
  590 + cnames.put("phone", "联系电话");
  591 +
  592 + List<Map<String,Object>> results = new ArrayList<>();
  593 + int i = 0;
  594 + for (Map<String, Object> m : couponInfos) {
  595 + Map<String, Object> result = new LinkedHashMap<>();
  596 + result.put("id", ++i);
  597 + result.put("checkDate", DateUtil.getyyyy_MM_dd((Date) m.get("checkDate")));
  598 + result.put("username", m.get("username"));
  599 + result.put("use_day", m.get("use_day"));
  600 + result.put("type", couponDescMap.get(m.get("type")));
  601 + result.put("coupon_desc", couponReportMap.get(m.get("type") + "_" + m.get("coupon_order")));
  602 + result.put("sequence_id", m.get("sequence_id"));
  603 + result.put("operatorOrgName", m.get("operatorOrgName"));
  604 + result.put("doctorName", m.get("doctorName"));
  605 + result.put("send_hospital", m.get("send_hospital"));
  606 + result.put("phone", m.get("phone"));
  607 + results.add(result);
  608 + }
  609 + ResponseUtil.responseExcel(cnames, results, response);
  610 + }
  611 +
  612 + private void exportPregnancy(List<Map<String, Object>> couponInfos, HttpServletResponse response) {
  613 + Map<String, String> cnames = new LinkedHashMap<>();
  614 + cnames.put("id", "#");
  615 + cnames.put("checkDate", "产检日期");
  616 + cnames.put("username", "姓名");
  617 + cnames.put("week", "产检孕周");
  618 + cnames.put("number", "产检第次");
  619 + cnames.put("type", "产检券类型");
  620 + cnames.put("sequence_id", "产检券号");
  621 + cnames.put("operatorOrgName", "产检机构");
  622 + cnames.put("doctorName", "产检医生");
  623 + cnames.put("send_hospital", "产检券发放机构");
  624 + cnames.put("phone", "联系电话");
  625 +
  626 + List<Map<String,Object>> results = new ArrayList<>();
  627 + int i = 0;
  628 + for (Map<String, Object> m : couponInfos) {
  629 + Map<String, Object> result = new LinkedHashMap<>();
  630 + result.put("id", ++i);
  631 + result.put("checkDate", DateUtil.getyyyy_MM_dd((Date) m.get("checkDate")));
  632 + result.put("username", m.get("username"));
  633 + result.put("week", m.get("week"));
  634 + result.put("number", m.get("number"));
  635 + result.put("sequence_id", m.get("sequence_id"));
  636 + result.put("operatorOrgName", m.get("operatorOrgName"));
  637 + result.put("doctorName", m.get("doctorName"));
  638 + result.put("send_hospital", m.get("send_hospital"));
  639 + result.put("phone", m.get("phone"));
  640 + results.add(result);
  641 + }
  642 + ResponseUtil.responseExcel(cnames, results, response);
  643 + }
  644 +
507 645 private void setAntexInfo(Map<String, Object> map) {
508 646 String sequenceId = (String) map.get("sequence_id");
509 647 if(StringUtils.isEmpty(sequenceId)) return;
... ... @@ -518,7 +656,12 @@
518 656 map.put("number", antexc.getProdTime()); /** 产检第几次 */
519 657 map.put("doctorName", couponMapper.findUserName(antexc.getProdDoctor())); /** 产检医生 */
520 658 map.put("operatorOrgName", couponMapper.findUserName(antexc.getOperator() + "")); /** 产检机构 */
521   - map.put("phone", couponMapper.findPhone(antexc.getOperator() + ""));
  659 + PersonModel personModel = mongoTemplate.findById(map.get("user_id"), PersonModel.class);
  660 + if(personModel != null) {
  661 + map.put("phone", personModel.getPhone());
  662 + } else {
  663 + map.put("phone", null);
  664 + }
522 665 } else {
523 666 AntenatalExaminationModel antenatal = mongoTemplate.findOne(Query.query(Criteria.where("barCode").is(sequenceId)), AntenatalExaminationModel.class);
524 667 if(antenatal != null) {
... ... @@ -534,6 +677,17 @@
534 677 map.put("phone", couponMapper.findPhone(antenatal.getOperator() + ""));
535 678 }
536 679 }
  680 +
  681 + Date useDate = (Date) map.get("use_date");
  682 + String usedId = (String) map.get("used_id");
  683 + if(StringUtils.isNotBlank(usedId)) {
  684 + BabyModel babyModel = mongoTemplate.findById(usedId, BabyModel.class);
  685 + if (babyModel != null) {
  686 + Date birth = babyModel.getBirth();
  687 + Integer day = DateUtil.getDays(birth, useDate);
  688 + map.put("use_day", "产后" + day + "天");
  689 + }
  690 + }
537 691 }
538 692  
539 693 private String findName(Object id) {