Commit a8b01ad127d71f561e80980f7d543c171c228083

Authored by litao@lymsh.com
1 parent e895d08404

建档统计导出接口

Showing 4 changed files with 117 additions and 2 deletions

platform-dal/src/main/java/com/lyms/platform/pojo/Patients.java View file @ a8b01ad
... ... @@ -16,6 +16,15 @@
16 16  
17 17 private static final long serialVersionUID = SerialIdEnum.Patients.getCid();
18 18  
  19 + private String shortCode;
  20 +
  21 + public String getShortCode() {
  22 + return shortCode;
  23 + }
  24 +
  25 + public void setShortCode(String shortCode) {
  26 + this.shortCode = shortCode;
  27 + }
19 28  
20 29 // 纠正末次月经 (和末次月经反起存)
21 30 private Date fuckLastMens;
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java View file @ a8b01ad
... ... @@ -46,6 +46,22 @@
46 46 return reportService.patients(provinceId, cityId, aredId, streetId, statistType, ageType, patientType, startDate, endDate, getUserId(request));
47 47 }
48 48  
  49 + /**
  50 + * 建档明细导出
  51 + * @param statistType 统计环比 1=周 2=月 3=季度 4=半年 5=年
  52 + * @param ageType 1=全部年龄 2=20岁以下 3=20-30岁 4=30-40岁 5=40岁以上
  53 + * @param patientType 建档孕周 1=孕早期 2=孕中期 3=孕晚期
  54 + * @return
  55 + */
  56 + @ResponseBody
  57 +// @TokenRequired
  58 + @RequestMapping(value = "/patients/export", method = RequestMethod.GET)
  59 + public void patientsExport(String provinceId, String cityId, String aredId, String streetId, @RequestParam Integer statistType,
  60 + Integer ageType, Integer patientType, Date startDate, Date endDate, HttpServletRequest request, HttpServletResponse response) {
  61 +// reportService.patientsExport(provinceId, cityId, aredId, streetId, statistType, ageType, patientType, startDate, endDate, getUserId(request), response);
  62 + reportService.patientsExport(provinceId, cityId, aredId, streetId, statistType, ageType, patientType, startDate, endDate, 1000000185, response);
  63 + }
  64 +
49 65  
50 66 /**
51 67 * 未发放优惠券统计
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java View file @ a8b01ad
... ... @@ -99,5 +99,7 @@
99 99 BaseObjectResponse unUsedPeopleInfo(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId);
100 100  
101 101 BaseObjectResponse patients(String provinceId, String cityId, String aredId, String streetId, Integer statistType, Integer ageType, Integer patientType, Date startDate, Date endDate, Integer userId);
  102 +
  103 + void patientsExport(String provinceId, String cityId, String aredId, String streetId, Integer statistType, Integer ageType, Integer patientType, Date startDate, Date endDate, Integer userId, HttpServletResponse response);
102 104 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ a8b01ad
... ... @@ -9,6 +9,7 @@
9 9 import com.lyms.platform.common.result.RespBuilder;
10 10 import com.lyms.platform.common.utils.DateUtil;
11 11 import com.lyms.platform.common.utils.EnumUtil;
  12 +import com.lyms.platform.common.utils.PingYinUtil;
12 13 import com.lyms.platform.operate.web.dao.IReportDao;
13 14 import com.lyms.platform.operate.web.facade.AccessPermissionFacade;
14 15 import com.lyms.platform.operate.web.facade.AutoMatchFacade;
... ... @@ -177,6 +178,7 @@
177 178 couponDescMap.put(8, "儿童保健券");
178 179 }
179 180  
  181 +
180 182 /**
181 183 * 建档统计
182 184 * @param statistType 统计环比 1=周 2=月 3=季度 4=半年 5=年
... ... @@ -187,6 +189,92 @@
187 189 @Override
188 190 public BaseObjectResponse patients(String provinceId, String cityId, String aredId, String streetId,
189 191 Integer statistType, Integer ageType, Integer patientType, Date startDate, Date endDate, Integer userId) {
  192 + List<Patients> patients = getPatients(provinceId, cityId, aredId, streetId, ageType, patientType, startDate, endDate, userId);
  193 + return null;
  194 + }
  195 +
  196 + @Override
  197 + public void patientsExport(String provinceId, String cityId, String aredId, String streetId, Integer statistType, Integer ageType, Integer patientType, Date startDate, Date endDate, Integer userId, HttpServletResponse response) {
  198 + List<Patients> patients = getPatients(provinceId, cityId, aredId, streetId, ageType, patientType, startDate, endDate, userId);
  199 +
  200 + Map<String, String> codeCache = new HashMap<>();
  201 + Map<String, String> hNameCache = new HashMap<>();
  202 + Map<String, String> userNameCache = new HashMap<>();
  203 + for (Patients patient : patients) {
  204 + if(!userNameCache.containsKey(patient.getBookbuildingDoctor())) {
  205 + userNameCache.put(patient.getBookbuildingDoctor(), couponMapper.findUserName(patient.getBookbuildingDoctor()));
  206 + }
  207 + if(codeCache.containsKey(patient.getHospitalId())) {
  208 + patient.setShortCode(codeCache.get(patient.getHospitalId()));
  209 + } else {
  210 + String name = couponMapper.findHospitalNameById(patient.getHospitalId());
  211 + String code = PingYinUtil.getFirstSpell(name);
  212 + patient.setShortCode(code);
  213 + codeCache.put(patient.getHospitalId(), code);
  214 + hNameCache.put(patient.getHospitalId(), name);
  215 + }
  216 + }
  217 +
  218 + Collections.sort(patients, new Comparator<Patients>() {
  219 + @Override
  220 + public int compare(Patients patients1, Patients patients2) {
  221 + if(StringUtils.isEmpty(patients1.getShortCode()) || StringUtils.isEmpty(patients2.getShortCode())) {
  222 + return 0;
  223 + }
  224 + return patients1.getShortCode().compareTo(patients2.getShortCode());
  225 + }
  226 + });
  227 +
  228 + Map<String, String> cnames = new LinkedHashMap<>();
  229 + cnames.put("id", "#");
  230 + cnames.put("hospitalName", "医院名称");
  231 + cnames.put("vcCardNo", "就诊卡号");
  232 + cnames.put("username", "姓名");
  233 + cnames.put("birth", "出生日期");
  234 + cnames.put("phone", "手机号");
  235 + cnames.put("cardNo", "证件号");
  236 + cnames.put("age", "年龄");
  237 + cnames.put("huji", "户籍地");
  238 + cnames.put("juzhu", "居住地");
  239 + cnames.put("week", "建档孕周");
  240 + cnames.put("lastMens", "末次月经");
  241 + cnames.put("dueDate", "预产期");
  242 + cnames.put("bookbuildingDate", "建档日期");
  243 + cnames.put("doctorName", "建档医生");
  244 +
  245 +
  246 + List<Map<String,Object>> results = new ArrayList<>();
  247 + if(org.apache.commons.collections.CollectionUtils.isNotEmpty(patients)) {
  248 + int i = 0;
  249 + for (Patients p : patients) {
  250 + Map<String, Object> result = new LinkedHashMap<>();
  251 + result.put("id", ++i);
  252 + result.put("hospitalName", hNameCache.get(p.getHospitalId()));
  253 + result.put("vcCardNo", p.getVcCardNo());
  254 + result.put("username", p.getUsername());
  255 + result.put("birth", DateUtil.getyyyy_MM_dd(p.getBirth()));
  256 + result.put("phone", com.lyms.platform.common.utils.StringUtils.encryPhone(p.getPhone()));
  257 + result.put("cardNo", com.lyms.platform.common.utils.StringUtils.encryCardNo(p.getCardNo()));
  258 + result.put("age", DateUtil.getAge(p.getBirth()));
  259 + String residenceAddress = findName(p.getProvinceRegisterId()) + findName(p.getCityRegisterId()) + findName(p.getAreaRegisterId()) + findName(p.getStreetRegisterId()) + p.getAddressRegister();
  260 + result.put("juzhu", residenceAddress.replace("null", ""));
  261 + String householdAddress = findName(p.getProvinceId()) + findName(p.getCityId()) + findName(p.getAreaId()) + findName(p.getStreetId()) + p.getAddress();
  262 + result.put("huji", householdAddress.replace("null", ""));
  263 +
  264 + result.put("week", DateUtil.getWeekDesc(p.getLastMenses(), p.getBookbuildingDate()));
  265 + result.put("lastMens", DateUtil.getyyyy_MM_dd(p.getLastMenses()));
  266 + result.put("dueDate", DateUtil.getyyyy_MM_dd(p.getDueDate()));
  267 + result.put("bookbuildingDate", DateUtil.getyyyy_MM_dd(p.getBookbuildingDate()));
  268 + result.put("doctorName", userNameCache.get(p.getBookbuildingDoctor()));
  269 + results.add(result);
  270 + }
  271 + }
  272 +
  273 + ResponseUtil.responseExcel(cnames, results, response);
  274 + }
  275 +
  276 + private List<Patients> getPatients(String provinceId, String cityId, String aredId, String streetId,
  277 + Integer ageType, Integer patientType, Date startDate, Date endDate, Integer userId) {
190 278 List<Map<String, Object>> hospitalInfos = mongoUtil.getHospitals(userId, provinceId, cityId, aredId, streetId);
191 279 List<String> hospitalIds = CollectionUtils.getListByKey(hospitalInfos, "id");
192 280 Criteria c = new Criteria();
... ... @@ -195,8 +283,8 @@
195 283 c.and("bookbuildingDate").gte(startDate).lt(DateUtil.addDay(endDate, 1));
196 284 }
197 285 List<Patients> patients = mongoTemplate.find(Query.query(c), Patients.class);
198   -
199   - return null;
  286 + doFilter(patients, ageType, patientType);
  287 + return patients;
200 288 }
201 289  
202 290 private void doFilter(List<Patients> patients, Integer ageType, Integer patientType) {