package com.ltkj.web.controller.system; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ltkj.framework.config.MatchUtils; import com.ltkj.hosp.domain.*; import com.ltkj.hosp.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.ltkj.common.annotation.Log; import com.ltkj.common.core.controller.BaseController; import com.ltkj.common.core.domain.AjaxResult; import com.ltkj.common.enums.BusinessType; import com.ltkj.common.utils.poi.ExcelUtil; import com.ltkj.common.core.page.TableDataInfo; /** * 规则+病种Controller * * @author ltkj_赵佳豪&李格 * @date 2023-08-30 */ @RestController @RequestMapping("/hosp/rules") @Api(tags = "规则+病种接口") public class TjRulesController extends BaseController { @Autowired private ITjRulesService tjRulesService; @Autowired private ITjRuleAdviceService tjRuleAdviceService; @Resource private ITjOrderService orderService; @Resource private ITjCustomerService customerService; @Autowired private ITjGroupingProService groupingProService; @Resource private ITjProjectService projectService; @Resource private TjProGzjyService proGzjyService; /** * 查询规则+病种列表 */ //@PreAuthorize("@ss.hasPermi('hosp:rules:list')") @GetMapping("/list") @ApiOperation(value = "查询规则+病种列表") public AjaxResult list(TjRules tjRules) { Page page=new Page<>(tjRules.getPageNum(),tjRules.getPageSize()); LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); if (tjRules.getProId() != null) { List projects = projectService.getTjProjectListBySoneId(tjRules.getProId()); if(null !=projects && !projects.isEmpty()){ wq.and(w-> w.eq(TjRules::getProId, tjRules.getProId()) .or().in(TjRules::getProId,projects.stream().map(TjProject::getProId).collect(Collectors.toList()))); }else { wq.eq(TjRules::getProId, tjRules.getProId()); } } if (tjRules.getProName() != null) { wq.like(TjRules::getProName, tjRules.getProName()); } if (tjRules.getRuleType() != null) { wq.eq(TjRules::getRuleType, tjRules.getRuleType()); } if (tjRules.getRuleStr() != null) { wq.like(TjRules::getRuleStr, tjRules.getRuleStr()); } if (tjRules.getBingzhong() != null) { wq.like(TjRules::getBingzhong, tjRules.getBingzhong()); } if (tjRules.getBzPinyin() != null) { wq.like(TjRules::getBzPinyin, tjRules.getBzPinyin()); } if (tjRules.getSex() != null) { wq.eq(TjRules::getSex, tjRules.getSex()); } wq.orderByAsc(TjRules::getSort); // List list = tjRulesService.list(wq); Page page1 = tjRulesService.page(page, wq); Mapmap=new HashMap<>(); map.put("rows",page1.getRecords()); map.put("total",page1.getTotal()); return AjaxResult.success(map); } /** * 查询规则+病种列表 */ @GetMapping("/listByRuleStr") @ApiOperation(value = "查询规则+病种列表") public TableDataInfo listByRuleStr(@ApiParam(value = "项目id") @RequestParam String proId, @ApiParam(value = "体检号") @RequestParam String tjNumber, @ApiParam(value = "体检号") @RequestParam String ruleStr) { TjOrder one = orderService.getOrderByTjNum(tjNumber); TjCustomer customer = customerService.getById(one.getUserId()); LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); if (proId != null) { wq.eq(TjRules::getProId, proId); } if (ruleStr != null) { wq.like(TjRules::getRuleStr, ruleStr); } if (customer.getCusSex() != null) { wq.eq(TjRules::getSex, customer.getCusSex()); } wq.orderByAsc(TjRules::getSort); List list = tjRulesService.list(wq); if (list != null) { for (TjRules rules : list) { LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjRuleAdvice::getBz, rules.getAid()); final List list1 = tjRuleAdviceService.list(wq1); rules.setRuleAdvices(list1); } } return getDataTable(list); } /** * 导出规则+病种列表 */ //@PreAuthorize("@ss.hasPermi('hosp:rules:export')") @Log(title = "规则+病种", businessType = BusinessType.EXPORT) @PostMapping("/export") @ApiOperation(value = "导出规则+病种列表") public void export(HttpServletResponse response, TjRules tjRules) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); if (tjRules.getProName() != null) { wq.like(TjRules::getProName, tjRules.getProName()); } if (tjRules.getRuleType() != null) { wq.eq(TjRules::getRuleType, tjRules.getRuleType()); } if (tjRules.getBingzhong() != null) { wq.like(TjRules::getBingzhong, tjRules.getBingzhong()); } if (tjRules.getBzPinyin() != null) { wq.like(TjRules::getBzPinyin, tjRules.getBzPinyin()); } if (tjRules.getSex() != null) { wq.eq(TjRules::getSex, tjRules.getSex()); } List list = tjRulesService.list(wq); ExcelUtil util = new ExcelUtil(TjRules.class); util.exportExcel(response, list, "规则+病种数据"); } /** * 获取规则+病种详细信息 */ //@PreAuthorize("@ss.hasPermi('hosp:rules:query')") @GetMapping(value = "/{aid}") @ApiOperation(value = "获取规则+病种详细信息") public AjaxResult getInfo(@PathVariable("aid") String aid) { return success(tjRulesService.getById(aid)); } /** * 新增规则+病种 */ // @PreAuthorize("@ss.hasPermi('hosp:rules:add')") @Log(title = "规则+病种", businessType = BusinessType.INSERT) @PostMapping @ApiOperation(value = "新增规则+病种") public AjaxResult add(@RequestBody TjRules tjRules) { return toAjax(tjRulesService.save(tjRules)); } /** * 修改规则+病种 */ //@PreAuthorize("@ss.hasPermi('hosp:rules:edit')") @Log(title = "规则+病种", businessType = BusinessType.UPDATE) @PutMapping @ApiOperation(value = "修改规则+病种") public AjaxResult edit(@RequestBody TjRules tjRules) { return toAjax(tjRulesService.saveOrUpdate(tjRules)); } /** * 删除规则+病种 */ //@PreAuthorize("@ss.hasPermi('hosp:rules:remove')") @Log(title = "规则+病种", businessType = BusinessType.DELETE) @DeleteMapping("/{aids}") @ApiOperation(value = "删除规则+病种") public AjaxResult remove(@PathVariable String[] aids) { for (String aid : aids) { tjRulesService.removeById(aid); } return toAjax(true); } /** * 规则自动计算 */ @GetMapping("/AutoGetRule") @ApiOperation(value = "规则自动计算") public AjaxResult AutoGetRule(@ApiParam(value = "项目") @RequestParam String proId, @ApiParam(value = "客户") @RequestParam(required = false) String cusId, @ApiParam(value = "体检号")@RequestParam String tjNum, @ApiParam(value = "关键字") @RequestParam(required = false) String keyWord, @ApiParam(value = "结果值") @RequestParam(required = false) String keyNum) { TjProject project = projectService.getById(proId); TjOrder order = orderService.getOrderByTjNum(tjNum); if(null !=project && null !=order){ TjProject pproject = projectService.getById(project.getProParentId()); List> tjproGzJy = projectService.getTjproGzJy(tjNum, proId, keyNum, 0); if(null !=tjproGzJy && !tjproGzJy.isEmpty()){ // proGzjyService.remove(new LambdaQueryWrapper().eq(TjProGzjy::getProId,proId).eq(TjProGzjy::getTjNumber,tjNum)); proGzjyService.deletedByTjNumAndProId(proId,tjNum); for (Map map : tjproGzJy) { Object bz = map.get("bz"); Object bt = map.get("bt"); Object nr = map.get("nr"); TjProGzjy proGzjy=new TjProGzjy(); proGzjy.setTjNumber(tjNum); proGzjy.setOrderId(order.getOrderId()); proGzjy.setProId(Long.valueOf(proId)); proGzjy.setProName(project.getProName()); proGzjy.setProPrentId(project.getProParentId()); proGzjy.setProPrentName(pproject.getProName()); proGzjy.setProJgz(keyNum); if(null !=bz)proGzjy.setBz(bz.toString()); if(null !=bt)proGzjy.setBt(bt.toString()); if(null !=nr)proGzjy.setJy(nr.toString()); proGzjyService.save(proGzjy); } } return AjaxResult.success(tjproGzJy); } return AjaxResult.success(); } //之前规则算法方法 private AjaxResult getAjaxResult(String proId, String cusId, String keyWord, BigDecimal keyNum) { List res = new ArrayList<>(); if (proId ==null){ return AjaxResult.success(res); } if (cusId ==null){ return AjaxResult.success(res); } TjCustomer byId = customerService.getById(cusId); if(byId==null){ return AjaxResult.success(res); } LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjRules::getProId, proId); wq.lt(TjRules::getAgeLt, MatchUtils.getAgeByIdCard(byId.getCusIdcard())); wq.gt(TjRules::getAgeGt, MatchUtils.getAgeByIdCard(byId.getCusIdcard())); // wq.in(TjRules::getSex, 0, byId.getCusSex()); final List list = tjRulesService.list(wq); if (list==null){ return AjaxResult.success(res); } for (TjRules tjRules : list) { //判断规则类型:数值/文字 if ("2".equals(tjRules.getRuleType())) { if (new BigDecimal(0).equals(tjRules.getRuleLt()) && new BigDecimal(0).equals(tjRules.getRuleGt())) { res.add(tjRules); } else { if (keyNum != null) { if (tjRules.getRuleLt().compareTo(keyNum) < 0 && tjRules.getRuleGt().compareTo(keyNum) > 0) { res.add(tjRules); } } } } else if ("1".equals(tjRules.getRuleType())) { if (keyWord !=null){ if (tjRules.getRuleStr().contains(keyWord)) { res.add(tjRules); } } } } if (!res.isEmpty()) { //建议赋值 for (TjRules re : res) { LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjRuleAdvice::getBz, re.getAid()); final List list1 = tjRuleAdviceService.list(wq1); re.setRuleAdvices(list1); } } return AjaxResult.success(res); } }