|  | @ -0,0 +1,131 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.hospital.endpoint.inpatient;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.inpatient.BasePatientFeeDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.inpatient.BasePatientFeeDetailDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.inpatient.dao.BasePatientFeeDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.inpatient.dao.BasePatientFeeDetailDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.inpatient.service.BasePatientFeeService;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.Envelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.MixEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.PageEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
 | 
	
		
			
				|  |  | import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiParam;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.annotation.Resource;
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.HashMap;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by yeshijie on 2022/12/7.
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @RestController
 | 
	
		
			
				|  |  | @RequestMapping(value ="/patient/fee")
 | 
	
		
			
				|  |  | @Api(value = "居民端-费用",  tags = {"居民端-费用"})
 | 
	
		
			
				|  |  | public class PatientFeeEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Resource
 | 
	
		
			
				|  |  |     private BasePatientFeeService patientFeeService;
 | 
	
		
			
				|  |  |     @Resource
 | 
	
		
			
				|  |  |     private BasePatientFeeDao patientFeeDao;
 | 
	
		
			
				|  |  |     @Resource
 | 
	
		
			
				|  |  |     private BasePatientFeeDetailDao patientFeeDetailDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @GetMapping(value = "page")
 | 
	
		
			
				|  |  |     @ApiOperation(value = "获取分页")
 | 
	
		
			
				|  |  |     public PageEnvelop page (
 | 
	
		
			
				|  |  |             @ApiParam(name = "patient", required = true, value = "居民id")
 | 
	
		
			
				|  |  |             @RequestParam(value = "patient") String patient,
 | 
	
		
			
				|  |  |             @ApiParam(name = "status", value = "状态 -1已取消 0待结算 1已结算")
 | 
	
		
			
				|  |  |             @RequestParam(value = "status", required = false) Integer status,
 | 
	
		
			
				|  |  |             @ApiParam(name = "startTime", value = "开始时间")
 | 
	
		
			
				|  |  |             @RequestParam(value = "startTime", required = false) String startTime,
 | 
	
		
			
				|  |  |             @ApiParam(name = "endTime", value = "结束时间")
 | 
	
		
			
				|  |  |             @RequestParam(value = "endTime", required = false) String endTime,
 | 
	
		
			
				|  |  |             @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
 | 
	
		
			
				|  |  |             @RequestParam(value = "page") Integer page,
 | 
	
		
			
				|  |  |             @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
 | 
	
		
			
				|  |  |             @RequestParam(value = "size") Integer size) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             String filters = "patient="+patient;
 | 
	
		
			
				|  |  |             if(status!=null){
 | 
	
		
			
				|  |  |                 filters += ";status="+status;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(StringUtils.isNotBlank(startTime)){
 | 
	
		
			
				|  |  |                 filters+=";createTime>="+startTime;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(StringUtils.isNotBlank(endTime)){
 | 
	
		
			
				|  |  |                 filters+=";createTime<="+endTime+" 23:59:59";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             List<BasePatientFeeDO> list = patientFeeService.search(null, filters, null, page, size);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             Map<Integer,String> map = new HashMap<>();
 | 
	
		
			
				|  |  |             map.put(-1,"已取消");
 | 
	
		
			
				|  |  |             map.put(0,"待结算");
 | 
	
		
			
				|  |  |             map.put(1,"已结算");
 | 
	
		
			
				|  |  |             for (BasePatientFeeDO feeDO:list){
 | 
	
		
			
				|  |  |                 feeDO.setStatusName(map.get(feeDO.getStatus()));
 | 
	
		
			
				|  |  |                 feeDO.setTypeName("费用");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             int count = (int)patientFeeService.getCount(filters);
 | 
	
		
			
				|  |  |             return success(list, count, page, size, BasePatientFeeDO.class);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             return PageEnvelop.getError("查询失败");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @GetMapping(value = "findDetail")
 | 
	
		
			
				|  |  |     @ApiOperation(value = "获取费用清单详情")
 | 
	
		
			
				|  |  |     public Envelop findDetail (
 | 
	
		
			
				|  |  |             @ApiParam(name = "id", required = true, value = "清单id")
 | 
	
		
			
				|  |  |             @RequestParam(value = "id") String id) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             BasePatientFeeDO feeDO = patientFeeDao.findById(id).orElse(null);
 | 
	
		
			
				|  |  |             List<JSONObject> list = new ArrayList<>();
 | 
	
		
			
				|  |  |             if(feeDO!=null){
 | 
	
		
			
				|  |  |                 List<BasePatientFeeDetailDO> detailList = patientFeeDetailDao.findByFeeId(id);
 | 
	
		
			
				|  |  |                 Map<String,List<BasePatientFeeDetailDO>> map = detailList.stream().collect(Collectors.groupingBy(BasePatientFeeDetailDO::getType));
 | 
	
		
			
				|  |  |                 Map<String,String> typeMap = new HashMap<>();
 | 
	
		
			
				|  |  |                 typeMap.put("1","西药");
 | 
	
		
			
				|  |  |                 typeMap.put("2","化验费");
 | 
	
		
			
				|  |  |                 for (String key:map.keySet()) {
 | 
	
		
			
				|  |  |                     JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  |                     json.put("type",key);
 | 
	
		
			
				|  |  |                     json.put("typeName",typeMap.get(key));
 | 
	
		
			
				|  |  |                     json.put("detailList",map.get(key));
 | 
	
		
			
				|  |  |                     list.add(json);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             return MixEnvelop.getSuccess("获取成功",feeDO,list);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             return Envelop.getError("查询失败");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @PostMapping(value = "settlement")
 | 
	
		
			
				|  |  |     @ApiOperation(value = "在线结算")
 | 
	
		
			
				|  |  |     public Envelop settlement (
 | 
	
		
			
				|  |  |             @ApiParam(name = "id", required = true, value = "清单id")
 | 
	
		
			
				|  |  |             @RequestParam(value = "id") String id) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             BasePatientFeeDO feeDO = patientFeeDao.findById(id).orElse(null);
 | 
	
		
			
				|  |  |             if(feeDO!=null){
 | 
	
		
			
				|  |  |                 feeDO.setStatus(1);
 | 
	
		
			
				|  |  |                 patientFeeDao.save(feeDO);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             return success("结算成功");
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             return Envelop.getError("结算失败");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |