OfflineController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. package com.ywt.mg.web.controllers;
  2. import com.ywt.mg.core.MGRight;
  3. import com.ywt.mg.core.MGRightTypeDef;
  4. import com.ywt.mg.core.PagedList;
  5. import com.ywt.mg.core.utils.AsyncUtil;
  6. import com.ywt.mg.core.utils.Checker;
  7. import com.ywt.mg.core.utils.CollectionUtil;
  8. import com.ywt.mg.core.utils.FormatUtil;
  9. import com.ywt.mg.core.utils.serializers.JsonSerializer;
  10. import com.ywt.mg.domain.entities.*;
  11. import com.ywt.mg.domain.models.ConstantDef;
  12. import com.ywt.mg.domain.models.ExcelDataMap;
  13. import com.ywt.mg.domain.models.ExcelStyleMap;
  14. import com.ywt.mg.domain.models.enums.DownloadRecordStatusEnum;
  15. import com.ywt.mg.domain.models.enums.OfflineConsultationSourceEnum;
  16. import com.ywt.mg.domain.models.enums.PaymentStatusEnum;
  17. import com.ywt.mg.domain.models.enums.RefundStatusEnum;
  18. import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
  19. import com.ywt.mg.params.offline.DownloadOfflineListNewRequest;
  20. import com.ywt.mg.services.*;
  21. import com.ywt.mg.web.BaseResponse;
  22. import com.ywt.mg.web.DataResponse;
  23. import com.ywt.mg.web.PageDataResponse;
  24. import com.ywt.mg.web.common.ExcelDownloadSrv;
  25. import com.ywt.mg.web.common.FileSrv;
  26. import jxl.Workbook;
  27. import jxl.format.Alignment;
  28. import jxl.format.Border;
  29. import jxl.format.BorderLineStyle;
  30. import jxl.format.Colour;
  31. import jxl.format.*;
  32. import jxl.format.VerticalAlignment;
  33. import jxl.write.*;
  34. import org.slf4j.Logger;
  35. import org.slf4j.LoggerFactory;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.web.bind.annotation.RequestBody;
  38. import org.springframework.web.bind.annotation.RequestMapping;
  39. import org.springframework.web.bind.annotation.RequestParam;
  40. import org.springframework.web.bind.annotation.RestController;
  41. import org.springframework.web.context.request.RequestContextHolder;
  42. import org.springframework.web.context.request.ServletRequestAttributes;
  43. import javax.servlet.http.HttpServletRequest;
  44. import javax.servlet.http.HttpServletResponse;
  45. import java.io.OutputStream;
  46. import java.util.*;
  47. /**
  48. * 线下就诊相关方法类(公司后台查询所有的,通过hospital_id来区分,公司后台hospital_id = -1)
  49. */
  50. @RestController("/offline")
  51. @RequestMapping({"/offline"})
  52. @MGRight
  53. public class OfflineController {
  54. private static Logger logger = LoggerFactory.getLogger(OfflineController.class);
  55. @Autowired
  56. private AuthService authService;
  57. @Autowired
  58. private OfflineNewService offlineNewService;
  59. @Autowired
  60. private IdGenerator idGenerator;
  61. @Autowired
  62. private DownloadRecordService downloadRecordService;
  63. /**
  64. * 查询线下就诊列表
  65. *
  66. * @param orderNo 订单号
  67. * @param patientName 患者姓名
  68. * @param patientMobile 患者手机号
  69. * @param paymentStatus 支付状态 {@link PaymentStatusEnum}
  70. * @param status 订单状态
  71. * @param doctorName 医生姓名
  72. * @param searchHospitalId 搜索的医院id
  73. * @param payTimeStart 支付查询开始时间
  74. * @param payTimeEnd 支付查询结束时间
  75. */
  76. /*
  77. @RequestMapping({"/downloadOfflineList"})
  78. public void downloadOfflineList(@RequestParam(name = "orderNo", defaultValue = "") String orderNo,
  79. @RequestParam(name = "patientName", defaultValue = "") String patientName,
  80. @RequestParam(name = "patientMobile", defaultValue = "") String patientMobile,
  81. @RequestParam(name = "paymentStatus", defaultValue = "") String paymentStatus,
  82. @RequestParam(name = "status", defaultValue = "") String status,
  83. @RequestParam(name = "doctorName", defaultValue = "") String doctorName,
  84. @RequestParam(name = "hospitalId", defaultValue = "-1") int searchHospitalId,
  85. @RequestParam(name = "hisClinicCode", defaultValue = "") String hisClinicCode,
  86. @RequestParam(name = "payTimeStart", defaultValue = "") String payTimeStart,
  87. @RequestParam(name = "payTimeEnd", defaultValue = "") String payTimeEnd,
  88. @RequestParam(name = "refundTimeStart", defaultValue = "") String refundTimeStart,
  89. @RequestParam(name = "refundTimeEnd", defaultValue = "") String refundTimeEnd,
  90. @RequestParam(name = "source", defaultValue = "") String source,
  91. HttpServletResponse httpServletResponse) {
  92. downloadOfflineListCommon(orderNo, patientName, patientMobile, paymentStatus, status,
  93. doctorName, searchHospitalId, hisClinicCode, payTimeStart, payTimeEnd, refundTimeStart,
  94. refundTimeEnd, source, httpServletResponse);
  95. }
  96. public void downloadOfflineListCommon(String orderNo, String patientName, String patientMobile, String paymentStatus, String status,
  97. String doctorName, int searchHospitalId, String hisClinicCode, String payTimeStart, String payTimeEnd,
  98. String refundTimeStart, String refundTimeEnd, String source, HttpServletResponse httpServletResponse) {
  99. OutputStream out = null;
  100. String filename = "线下就诊记录.xls";
  101. try {
  102. httpServletResponse.setHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes(), "iso-8859-1"));
  103. httpServletResponse.setContentType("application/vnd.ms-excel;charset=UTF-8");
  104. httpServletResponse.setHeader("Pragma", "no-cache");
  105. httpServletResponse.setHeader("Cache-Control", "no-cache");
  106. httpServletResponse.setDateHeader("Expires", 0);
  107. out = httpServletResponse.getOutputStream();
  108. // 创建写工作簿对象
  109. WritableWorkbook workbook = Workbook.createWorkbook(out);
  110. // 工作表
  111. WritableSheet sheet = workbook.createSheet("线下就诊记录", 0);
  112. //设置字体;
  113. WritableFont font = new WritableFont(WritableFont.ARIAL, 14, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
  114. WritableCellFormat cellFormat = new WritableCellFormat(font);
  115. //设置背景颜色;
  116. cellFormat.setBackground(Colour.WHITE);
  117. //设置边框;
  118. cellFormat.setBorder(Border.ALL, BorderLineStyle.DASH_DOT);
  119. //设置自动换行;
  120. cellFormat.setWrap(true);
  121. //设置文字居中对齐方式;
  122. cellFormat.setAlignment(Alignment.CENTRE);
  123. //设置垂直居中;
  124. cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
  125. //分别给1,5,9,15列设置不同的宽度;
  126. sheet.setColumnView(0, 40);
  127. sheet.setColumnView(1, 40);
  128. sheet.setColumnView(4, 40);
  129. sheet.setColumnView(8, 40);
  130. sheet.setColumnView(12, 30);
  131. sheet.setColumnView(13, 30);
  132. sheet.setColumnView(14, 30);
  133. //给sheet电子版中所有的列设置默认的列的宽度;
  134. sheet.getSettings().setDefaultColumnWidth(20);
  135. sheet.getSettings().setDefaultRowHeight(30 * 20);
  136. // 单元格
  137. Label label0 = new Label(0, 0, "订单号", cellFormat);
  138. Label label1 = new Label(1, 0, "支付流水号", cellFormat);
  139. Label label2 = new Label(2, 0, "患者姓名", cellFormat);
  140. Label label3 = new Label(3, 0, "患者手机号", cellFormat);
  141. Label label4 = new Label(4, 0, "身份证号", cellFormat);
  142. Label label5 = new Label(5, 0, "医院流水号", cellFormat);
  143. Label label6 = new Label(6, 0, "医生姓名", cellFormat);
  144. Label label7 = new Label(7, 0, "科室", cellFormat);
  145. Label label8 = new Label(8, 0, "医院", cellFormat);
  146. Label label9 = new Label(9, 0, "诊查费", cellFormat);
  147. Label label10 = new Label(10, 0, "状态", cellFormat);
  148. Label label11 = new Label(11, 0, "支付状态", cellFormat);
  149. Label label12 = new Label(12, 0, "支付时间", cellFormat);
  150. Label label13 = new Label(13, 0, "退款时间", cellFormat);
  151. Label label14 = new Label(14, 0, "备注", cellFormat);
  152. Label label15 = new Label(15, 0, "来源", cellFormat);
  153. sheet.addCell(label0);
  154. sheet.addCell(label1);
  155. sheet.addCell(label2);
  156. sheet.addCell(label3);
  157. sheet.addCell(label4);
  158. sheet.addCell(label5);
  159. sheet.addCell(label6);
  160. sheet.addCell(label7);
  161. sheet.addCell(label8);
  162. sheet.addCell(label9);
  163. sheet.addCell(label10);
  164. sheet.addCell(label11);
  165. sheet.addCell(label12);
  166. sheet.addCell(label13);
  167. sheet.addCell(label14);
  168. sheet.addCell(label15);
  169. //上面是产生表头
  170. //得到里面的数据
  171. int n = 1;
  172. //给第二行设置背景、字体颜色、对齐方式等等;
  173. WritableFont font2 = new WritableFont(WritableFont.ARIAL, 14, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
  174. WritableCellFormat cellFormat2 = new WritableCellFormat(font2);
  175. //设置文字居中对齐方式;
  176. cellFormat2.setAlignment(Alignment.CENTRE);
  177. //设置垂直居中;
  178. cellFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
  179. cellFormat2.setBackground(Colour.WHITE);
  180. cellFormat2.setBorder(Border.ALL, BorderLineStyle.THIN);
  181. cellFormat2.setWrap(true);
  182. // 按条件查找记录
  183. int hospitalId = -1;
  184. List<OfflineConsultation> offlineList = hospOfflineService.queryDownloadOfflineList(orderNo, patientName, patientMobile,
  185. paymentStatus, status, doctorName, searchHospitalId, hisClinicCode,
  186. payTimeStart, payTimeEnd, refundTimeStart, refundTimeEnd, hospitalId, source);
  187. int payTotal = 0, refundTotal = 0;
  188. if (!Checker.isNone(offlineList)) {
  189. // 遍历
  190. for (OfflineConsultation v : offlineList) {
  191. String orderNoStr = Checker.getStringValue(v.getOrderNo());
  192. Label valuel0 = new Label(0, n, orderNoStr, cellFormat);
  193. String paymentNoStr = Checker.getStringValue(v.getPaymentNo());
  194. Label valuel1 = new Label(1, n, paymentNoStr, cellFormat);
  195. String patientNameNoStr = Checker.getStringValue(v.getRealName());
  196. Label valuel2 = new Label(2, n, patientNameNoStr, cellFormat);
  197. String patientMobileStr = Checker.getStringValue(v.getMobile());
  198. Label valuel3 = new Label(3, n, patientMobileStr, cellFormat);
  199. String idNoStr = Checker.getStringValue(v.getIdNo());
  200. Label valuel4 = new Label(4, n, idNoStr, cellFormat);
  201. String hisClinicCodeStr = Checker.getStringValue(v.getHisClinicCode() + "");
  202. Label valuel5 = new Label(5, n, hisClinicCodeStr, cellFormat);
  203. String doctorNameStr = Checker.getStringValue(v.getDoctorName());
  204. Label valuel6 = new Label(6, n, doctorNameStr, cellFormat);
  205. String deptNameStr = Checker.getStringValue(v.getDeptName());
  206. Label valuel7 = new Label(7, n, deptNameStr, cellFormat);
  207. String hospitalNameStr = hospitalCacheService.getCacheHospitalNameByHospitalId(Checker.getIntegerValue(v.getHospitalId()));
  208. Label valuel8 = new Label(8, n, hospitalNameStr, cellFormat);
  209. String totalStr = FormatUtil.intShrink100ToStr(v.getTotal());
  210. Label valuel9 = new Label(9, n, totalStr, cellFormat);
  211. String orderStatusStr = hospOfflineService.getOfflineStatusStr(v);
  212. Label valuel10 = new Label(10, n, orderStatusStr, cellFormat);
  213. String paymentStatusStr = PaymentStatusEnum.getPaymentStatus(Checker.getIntegerValue(v.getPaymentStatus())).getDisplayName();
  214. Label valuel11 = new Label(11, n, paymentStatusStr, cellFormat);
  215. String payTimeStr = FormatUtil.createTimeFormatList(v.getPayTime());
  216. Label valuel12 = new Label(12, n, payTimeStr, cellFormat);
  217. String refundTimeStr = FormatUtil.createTimeFormatList(v.getRefundTime());
  218. Label valuel13 = new Label(13, n, refundTimeStr, cellFormat);
  219. String remarkStr = Checker.getStringValue(v.getRefundRemark());
  220. Label valuel14 = new Label(14, n, remarkStr, cellFormat);
  221. String sourceStr = OfflineConsultationSourceEnum.getDisplayName(Checker.getIntegerValue(v.getSource()));
  222. Label value15 = new Label(15, n, sourceStr, cellFormat);
  223. if (Checker.getIntegerValue(v.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
  224. payTotal += Checker.getIntegerValue(v.getTotal());
  225. }
  226. if (Checker.getIntegerValue(v.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()){
  227. refundTotal += Checker.getIntegerValue(v.getTotal());
  228. }
  229. sheet.addCell(valuel0);
  230. sheet.addCell(valuel1);
  231. sheet.addCell(valuel2);
  232. sheet.addCell(valuel3);
  233. sheet.addCell(valuel4);
  234. sheet.addCell(valuel5);
  235. sheet.addCell(valuel6);
  236. sheet.addCell(valuel7);
  237. sheet.addCell(valuel8);
  238. sheet.addCell(valuel9);
  239. sheet.addCell(valuel10);
  240. sheet.addCell(valuel11);
  241. sheet.addCell(valuel12);
  242. sheet.addCell(valuel13);
  243. sheet.addCell(valuel14);
  244. sheet.addCell(value15);
  245. n++;
  246. }
  247. }
  248. n = n + 2;
  249. Label valuel3 = new Label(3, n, "支付总额", cellFormat);
  250. Label valuel4 = new Label(4, n, FormatUtil.intShrink100ToStr(payTotal), cellFormat);
  251. Label valuel5 = new Label(5, n, "退款总额", cellFormat);
  252. Label valuel6 = new Label(6, n, FormatUtil.intShrink100ToStr(refundTotal), cellFormat);
  253. Label valuel7 = new Label(7, n, "实际支付金额", cellFormat);
  254. Label valuel8 = new Label(8, n, FormatUtil.intShrink100ToStr(payTotal-refundTotal), cellFormat);
  255. sheet.addCell(valuel3);
  256. sheet.addCell(valuel4);
  257. sheet.addCell(valuel5);
  258. sheet.addCell(valuel6);
  259. sheet.addCell(valuel7);
  260. sheet.addCell(valuel8);
  261. //开始执行写入操作
  262. workbook.write();
  263. //关闭流
  264. workbook.close();
  265. } catch (Exception e) {
  266. logger.error("/offline/downloadOfflineList(): {}", e.getMessage(), e);
  267. e.printStackTrace();
  268. }
  269. }
  270. */
  271. @RequestMapping({"/downloadOfflineList"})
  272. public BaseResponse downloadOfflineList(@RequestBody DownloadOfflineListNewRequest request) {
  273. int currentAdminId = Checker.getIntegerValue(authService.getCurrentAdminId());
  274. request.setCurrentAdminId(currentAdminId);
  275. // 插入记录
  276. int downloadRecordId = idGenerator.genDownloadRecordId();
  277. String name = "线下就诊";
  278. String fileName = "线下就诊";
  279. String excelSuffixFormat = ConstantDef.EXCEL_SUFFIX_FORMAT;
  280. String paramUrl = "/offline/downloadOfflineList";
  281. String paramJson = JsonSerializer.toJson(request);
  282. downloadRecordService.getOrInsertDownloadRecord(downloadRecordId, name, fileName + excelSuffixFormat, paramUrl, paramJson);
  283. Thread t = new Thread() {
  284. @Override
  285. public void run() {
  286. offlineNewService.downloadOfflineListCommon(downloadRecordId, fileName, request);
  287. }
  288. };
  289. t.start();
  290. return new BaseResponse().succeed("后台下载中...");
  291. }
  292. }