ShareholderCardService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package thyyxxk.webserver.service.outpatient.thmz;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.convert.Convert;
  4. import cn.hutool.core.util.NumberUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.web.client.RestTemplate;
  13. import thyyxxk.webserver.config.exception.BizException;
  14. import thyyxxk.webserver.config.exception.ExceptionEnum;
  15. import thyyxxk.webserver.dao.his.outpatient.thmz.ShareholderCardDao;
  16. import thyyxxk.webserver.dao.his.outpatient.thmz.ZdDiscountDetailDao;
  17. import thyyxxk.webserver.dao.his.outpatient.thmz.ZdVisitTypeNewDao;
  18. import thyyxxk.webserver.entity.ResultVo;
  19. import thyyxxk.webserver.entity.executeItem.ZdChargeItem;
  20. import thyyxxk.webserver.entity.outpatient.thmz.DiscountEnum;
  21. import thyyxxk.webserver.utils.AssertUtil;
  22. import thyyxxk.webserver.utils.CommonUtil;
  23. import thyyxxk.webserver.utils.ResultVoUtil;
  24. import javax.annotation.Resource;
  25. import java.util.ArrayList;
  26. import java.util.Date;
  27. import java.util.HashMap;
  28. import java.util.List;
  29. import java.util.Map;
  30. /**
  31. * @Description:
  32. * @Author:lihong
  33. * @Date: 2024/1/12
  34. */
  35. @Service
  36. @Slf4j
  37. public class ShareholderCardService {
  38. @Resource
  39. private ShareholderCardDao dao;
  40. @Resource
  41. private ZdVisitTypeNewDao zdVisitTypeNewDao;
  42. @Resource
  43. private ZdDiscountDetailDao zdDiscountDetailDao;
  44. @Value("${thmz-api-url}")
  45. private String thmzUrl;
  46. public List<Map<String, Object>> queryDiscountClass() {
  47. return DiscountEnum.listDiscount();
  48. }
  49. /**
  50. * @description: 查询身份
  51. * @author: lihong
  52. * @date: 2024/1/12 9:44
  53. * @return: java.util.List<thyyxxk.webserver.service.mz.ZdVisitTypeNew>
  54. **/
  55. public List<ZdVisitTypeNew> queryZdVisitTypeNew(ZdVisitTypeNew zdVisitTypeNew) {
  56. QueryWrapper queryWrapper = new QueryWrapper();
  57. queryWrapper.eq(zdVisitTypeNew.getDelFlag() !=null,"del_flag", zdVisitTypeNew.getDelFlag());
  58. return zdVisitTypeNewDao.selectList(queryWrapper);
  59. }
  60. public void insertZdVisitTypeNew(ZdVisitTypeNew param) {
  61. AssertUtil.isnotBlank(param.getStartDate(), "有效开始时间不能为空");
  62. AssertUtil.isnotBlank(param.getEndDate(), "有效截止时间不能为空");
  63. AssertUtil.isnotBlank(param.getName(), "身份名称不能为空");
  64. zdVisitTypeNewDao.insert(param);
  65. }
  66. public void updateZdVisitTypeNew(ZdVisitTypeNew param) {
  67. AssertUtil.isnotBlank(param.getId(), "id不能为空");
  68. AssertUtil.isnotBlank(param.getStartDate(), "有效开始时间不能为空");
  69. AssertUtil.isnotBlank(param.getEndDate(), "有效截止时间不能为空");
  70. AssertUtil.isnotBlank(param.getName(), "身份名称不能为空");
  71. zdVisitTypeNewDao.updateById(param);
  72. }
  73. public void delZdVisitTypeNew(ZdVisitTypeNew param) {
  74. AssertUtil.isnotBlank(param.getId(), "id不能为空");
  75. AssertUtil.isnotBlank(param.getDelFlag(), "删除标识不能为空");
  76. zdVisitTypeNewDao.updateById(param);
  77. }
  78. public IPage queryPatientInfo(Page page, String keyWard, Integer id) {
  79. List<Map<String, Object>> list = dao.selectPatientInfo(page, keyWard, id);
  80. if (CollUtil.isNotEmpty(list)) {
  81. CommonUtil.BeanTrim(list);
  82. list.forEach(item -> {
  83. ZdVisitTypeNew zdVisitTypeNew = dao.selectByPatientId(Convert.toStr(item.get("patientId"), "").trim());
  84. item.put("visitName", zdVisitTypeNew == null || StrUtil.isBlank(zdVisitTypeNew.getName()) ? "" : zdVisitTypeNew.getName());
  85. item.put("visitId", zdVisitTypeNew == null || zdVisitTypeNew.getId() == null ? null : zdVisitTypeNew.getId());
  86. });
  87. }
  88. page.setRecords(list);
  89. return page;
  90. }
  91. /**
  92. * @description: 保存身份关系表
  93. * @author: lihong
  94. * @date: 2024/1/12 16:21
  95. * @param: params
  96. **/
  97. public void saveZdVisitTypeUser(ZdVisitTypeNew params) {
  98. AssertUtil.isnotBlank(params.getPatientId(), "门诊号不能为空");
  99. AssertUtil.isnotBlank(params.getId(), "病人身份id不能为空");
  100. params.setPatientId(params.getPatientId().trim());
  101. Integer count = dao.selectZdVisitTypeUserBypatienId(params.getPatientId());
  102. params.setOpDate(new Date());
  103. if (count == null) {
  104. List<ZdVisitTypeNew> list = new ArrayList<>();
  105. list.add(params);
  106. dao.insertZdVisitTypeUser(list);
  107. } else {
  108. dao.updateZdVisitTypeUserBypatienId(params);
  109. }
  110. }
  111. public void delZdVisitTypeUser(ZdVisitTypeNew params) {
  112. AssertUtil.isnotBlank(params.getPatientId(), "门诊号不能为空");
  113. dao.delZdVisitTypeUser(params.getPatientId());
  114. }
  115. public IPage queryZdDiscountDetail(ZdDiscountDetail params) {
  116. IPage<ZdDiscountDetail> page = new Page<>(params.getCurrentPage(), params.getPageSize());
  117. QueryWrapper queryWrapper = new QueryWrapper();
  118. queryWrapper.eq(Convert.toInt(params.getVisitType(), 0) != 0, "visit_type", params.getVisitType());
  119. queryWrapper.eq(StrUtil.isNotBlank(params.getDiscountClass()) && !"all".equals(params.getDiscountClass()), "discount_class", params.getDiscountClass());
  120. return zdDiscountDetailDao.selectPage(page, queryWrapper);
  121. }
  122. public int updateZdDiscountDetailDelFlag(ZdDiscountDetail params) {
  123. AssertUtil.isnotBlank(params.getId(),"id不能为空");
  124. AssertUtil.isnotBlank(params.getDelFlag(),"启用状态不能为空");
  125. params.setOpDate(new Date());
  126. return zdDiscountDetailDao.updateById(params);
  127. }
  128. public int saveZdDiscountDetail(ZdDiscountDetail params) {
  129. AssertUtil.isnotBlank(params.getVisitType(),"身份不能为空");
  130. AssertUtil.isnotBlank(params.getDiscountClass(),"优惠类型不能为空");
  131. AssertUtil.isnotBlank(params.getDiscountType(),"折扣方式不能为空");
  132. AssertUtil.isnotBlank(params.getDiscount(),"折扣不能为空");
  133. AssertUtil.isnotBlank(NumberUtil.isNumber(params.getDiscount()),"折扣只能为数字,请输入折扣或具体的收费金额(如0.8或500)");
  134. AssertUtil.isnotBlank(params.getStartDate(), "有效开始时间不能为空");
  135. AssertUtil.isnotBlank(params.getEndDate(), "有效截止时间不能为空");
  136. AssertUtil.isnotBlank(params.getChargeItem(), "项目编码不能为空");
  137. params.setOpDate(new Date());
  138. if (params.getId() == null) {
  139. checkData(params);
  140. return zdDiscountDetailDao.insert(params);
  141. } else {
  142. ZdDiscountDetail zdDiscountDetail = zdDiscountDetailDao.selectById(params.getId());
  143. if(!params.getVisitType().equals(zdDiscountDetail.getVisitType()) || !params.getDiscountClass().equals(zdDiscountDetail.getDiscountClass()) || !params.getChargeItem().equals(zdDiscountDetail.getChargeItem())){
  144. checkData(params);
  145. }
  146. return zdDiscountDetailDao.updateById(params);
  147. }
  148. }
  149. public void checkData(ZdDiscountDetail params) {
  150. QueryWrapper queryWrapper = new QueryWrapper();
  151. queryWrapper.eq("visit_type", params.getVisitType());
  152. queryWrapper.eq("discount_class", params.getDiscountClass());
  153. queryWrapper.eq("charge_item", params.getChargeItem());
  154. Integer count = zdDiscountDetailDao.selectCount(queryWrapper);
  155. if(count > 0){
  156. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "该项目已经存在,请不要重复!");
  157. }
  158. }
  159. public List<ZdChargeItem> queryItemList(String discountClass,String keyWard){
  160. AssertUtil.isnotBlank(discountClass,"优惠类型不能为空!");
  161. List<ZdChargeItem> list;
  162. if(DiscountEnum.AUDIT_CODE.getCode().equals(discountClass)){
  163. list = dao.selectZyAuditItem(keyWard);
  164. }else if(DiscountEnum.CHARGE_CODE.getCode().equals(discountClass)){
  165. list = dao.selcetZdChargeItem(keyWard);
  166. }
  167. else if(DiscountEnum.JY_JC_CODE.getCode().equals(discountClass)){
  168. if(StrUtil.isBlank(keyWard)){
  169. keyWard = null;
  170. }else {
  171. keyWard = "%" + keyWard + "%";
  172. }
  173. list = dao.selectJcJyItemByCommonParams(keyWard,40);
  174. }
  175. else {
  176. list = dao.selectMzTc(keyWard);
  177. }
  178. return list;
  179. }
  180. public ResultVo<List<Map<String,Object>>> queryAllTemplate(){
  181. ResultVo response = new RestTemplate().getForObject(thmzUrl+"/queryAllTemplate", ResultVo.class);
  182. if(response == null){
  183. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "查询组合套餐失败");
  184. }
  185. if(response.getCode() == -1){
  186. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "查询组合套餐失败,原因:"+response.getMessage());
  187. }
  188. return ResultVoUtil.success((List<Map<String,Object>>)response.getData());
  189. }
  190. public List<Map<String,Object>> queryTemplateDetails(Long templateId){
  191. Map<String,Object> params = new HashMap<String,Object>(5);
  192. params.put("templateId", templateId);
  193. ResultVo response = new RestTemplate().postForObject(thmzUrl + "/queryTemplateDetails", params, ResultVo.class);
  194. if(response == null){
  195. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "查询组合套餐明细失败");
  196. }
  197. if(response.getCode() == -1){
  198. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "查询组合套餐明细失败,原因:"+response.getMessage());
  199. }
  200. return (List<Map<String,Object>>)response.getData();
  201. }
  202. public List<Map<String,Object>> queryMzChargeType() {
  203. ResultVo response = new RestTemplate().getForObject(thmzUrl+"/queryMzChargeType", ResultVo.class);
  204. if(response == null){
  205. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "查询号别失败");
  206. }
  207. if(response.getCode() == -1){
  208. throw new BizException(ExceptionEnum.LOGICAL_ERROR, "查询号别失败,原因:"+response.getMessage());
  209. }
  210. return (List<Map<String,Object>>)response.getData();
  211. }
  212. public List<ZdChargeItem> queryItemDetail(ZdDiscountDetail params) {
  213. AssertUtil.isnotBlank(params.getChargeItem(),"编码不能为空");
  214. AssertUtil.isnotBlank(params.getDiscountClass(),"类型不能不能为空");
  215. List<ZdChargeItem> list;
  216. if(DiscountEnum.AUDIT_CODE.getCode().equals(params.getDiscountClass())){
  217. list = dao.selcetZdChargeItemByCode(params.getChargeItem());
  218. }
  219. else if(DiscountEnum.JY_JC_CODE.getCode().equals(params.getDiscountClass())){
  220. list = dao.selectJcJyZdChargeItemByCode(params.getChargeItem(), params.getJyjcType());
  221. }
  222. else {
  223. // tc_no
  224. list = dao.selectTcDeatil(params.getChargeItem());
  225. }
  226. return list;
  227. }
  228. }