ConsumablesStatisticsService.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package thyyxxk.webserver.service.querydata;
  2. import com.alibaba.fastjson.JSON;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import thyyxxk.webserver.config.exception.ExceptionEnum;
  7. import thyyxxk.webserver.dao.his.querydata.ConsumablesStatisticsDao;
  8. import thyyxxk.webserver.entity.ResultVo;
  9. import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
  10. import thyyxxk.webserver.entity.querydata.ConsumablesStatistics;
  11. import thyyxxk.webserver.utils.ExcelUtil;
  12. import thyyxxk.webserver.utils.ResultVoUtil;
  13. import javax.servlet.http.HttpServletResponse;
  14. import java.util.List;
  15. /**
  16. * <p>
  17. * 描述
  18. * </p>
  19. *
  20. * @author xc
  21. * @date 2021-04-06 14:35
  22. */
  23. @Service
  24. @Slf4j
  25. public class ConsumablesStatisticsService {
  26. private final ConsumablesStatisticsDao dao;
  27. @Autowired
  28. public ConsumablesStatisticsService(ConsumablesStatisticsDao dao) {
  29. this.dao = dao;
  30. }
  31. /**
  32. * 查询耗材使用统计 根据条件动态查询 这个sql语句太复杂了 mybatis-plus查询很慢
  33. *
  34. * @param param 条件 分页
  35. * @return 指定数据
  36. */
  37. public ResultVo<List<ConsumablesStatistics>> query(ConsumablesStatistics param) {
  38. List<ConsumablesStatistics> list = dao.query(param);
  39. if (list.size() > 0) {
  40. return ResultVoUtil.success(list);
  41. }
  42. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
  43. }
  44. /**
  45. * @param response 固定
  46. * @param param 查询条件
  47. */
  48. public void exportExcel(HttpServletResponse response, ConsumablesStatistics param) {
  49. log.info("导出耗材使用统计excel --> {}", JSON.toJSONString(param));
  50. List<ConsumablesStatistics> list = dao.query(param);
  51. String[] title = {"项目编码", "项目名称", "产地品牌", "耗材院内编码", "来源", "数量", "金额"};
  52. String[][] content = new String[list.size()][];
  53. for (int i = 0; i < list.size(); i++) {
  54. content[i] = new String[title.length];
  55. ConsumablesStatistics pojo = list.get(i);
  56. content[i][0] = pojo.getProjectCode();
  57. content[i][1] = pojo.getEntryName();
  58. content[i][2] = pojo.getOriginBrand();
  59. content[i][3] = pojo.getHospitalCode();
  60. content[i][4] = pojo.getSource();
  61. content[i][5] = String.valueOf(pojo.getNumber());
  62. content[i][6] = String.valueOf(pojo.getAmountOfMoney());
  63. }
  64. //传三个参数 一个是 固定的 response ,excel的头部信息,excel的内容
  65. ExcelUtil.exportExcel(response, title, content);
  66. }
  67. /**
  68. * 获取费用类型
  69. */
  70. public ResultVo<List<GetDropdownBox>> getDropdownBox() {
  71. return ResultVoUtil.success(dao.chargeClassName());
  72. }
  73. }