package com.ltkj.web.controller.system; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.swing.plaf.basic.BasicScrollPaneUI; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ltkj.common.core.redis.RedisCache; import com.ltkj.framework.config.MatchUtils; import com.ltkj.hosp.domain.TbTransition; import com.ltkj.hosp.domain.TjCustomer; import com.ltkj.hosp.domain.TjProject; import com.ltkj.hosp.service.ITjCustomerService; import com.ltkj.hosp.service.ITjProjectService; import com.ltkj.hosp.service.TjAsyncService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.aspectj.weaver.AjAttribute; 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.hosp.domain.TjSampling; import com.ltkj.hosp.service.ITjSamplingService; import com.ltkj.common.utils.poi.ExcelUtil; import com.ltkj.common.core.page.TableDataInfo; /** * 体检采样管理Controller * * @author ltkj_赵佳豪&李格 * @date 2023-04-11 */ @RestController @RequestMapping("/sampling/sampling") @Api(tags = "体检采样管理") public class TjSamplingController extends BaseController { @Resource private ITjSamplingService tjSamplingService; @Resource private ITjCustomerService customerService; @Resource private ITjProjectService projectService; @Resource private TjAsyncService asyncService; @Resource private RedisCache redisCache; /** * 查询体检采样管理列表 */ //@PreAuthorize("@ss.hasPermi('sampling:sampling:list')") @GetMapping("/list") @ApiOperation(value = "查询体检采样管理列表(自带默认)") public TableDataInfo list(TjSampling tjSampling) { startPage(); List list = tjSamplingService.selectTjSamplingList(tjSampling); if (null != list && list.size() > 0) { for (TjSampling sampling : list) { TjCustomer customer = customerService.getById(sampling.getCusId()); if (null != customer) { sampling.setCustomer(customer); } } } return getDataTable(list); } @GetMapping("/getList") @ApiOperation(value = "查询采样未签收列表()") public AjaxResult getList(@RequestParam @ApiParam(value = "0是1否") Integer isSignFor, @RequestParam(required = false) @ApiParam(value = "体检号") String tjNum, @RequestParam(required = false) @ApiParam(value = "客户姓名") String name, @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer pageNum, @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize, @ApiParam(value = "开始时间") @RequestParam(required = false) String beginTime, @ApiParam(value = "结束时间") @RequestParam(required = false) String endTime) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); List> arrayList = new ArrayList<>(); wq.orderByDesc(TjSampling::getApplicationTime); if (null != beginTime && !"".equals(beginTime) && null != endTime && !"".equals(endTime)) wq.between(TjSampling::getApplicationTime, beginTime, endTime); if (null != tjNum) { wq.eq(TjSampling::getTjNum, tjNum); wq.eq(TjSampling::getIsSignFor, isSignFor); List list = tjSamplingService.list(wq); List> extracted = extracted(arrayList, list, pageNum, pageSize); //________________________解决搜索数据不对 Map map = new HashMap<>(); map.put("list", extracted); map.put("total", arrayList.size()); return AjaxResult.success(map); //________________________解决搜索数据不对 } if (null != name) { wq.like(TjSampling::getCusName, name); wq.eq(TjSampling::getIsSignFor, isSignFor); List list = tjSamplingService.list(wq); List> extracted = extracted(arrayList, list, pageNum, pageSize); //________________________解决搜索数据不对 Map map = new HashMap<>(); map.put("list", extracted); map.put("total", arrayList.size()); return AjaxResult.success(map); //________________________解决搜索数据不对 } List> cacheMapValue = null; if (isSignFor == 0) { cacheMapValue = redisCache.getCacheMapValue("sampling", "yqs"); } if (isSignFor == 1) { cacheMapValue = redisCache.getCacheMapValue("sampling", "wqs"); } asyncService.saveSampling(); List> collect = null; Map map = new HashMap<>(); if (null == cacheMapValue || cacheMapValue.size() == 0) { wq.eq(TjSampling::getIsSignFor, isSignFor); List list = tjSamplingService.list(wq); collect = extracted(arrayList, list, pageNum, pageSize); map.put("total", arrayList.size()); } else { collect = cacheMapValue.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); map.put("total", cacheMapValue.size()); } map.put("list", collect); return AjaxResult.success(map); } private List> extracted(List> arrayList, List list, Integer pageNum, Integer pageSize) { if (null != list && list.size() > 0) { Map> stringListMap = list.stream().collect(Collectors.groupingBy(TjSampling::getCusId)); for (Map.Entry> entry : stringListMap.entrySet()) { Map map = new HashMap<>(); TjCustomer customer = customerService.getById(entry.getKey()); if (customer == null) { continue; } customer.setCusName(MatchUtils.hideCusName(customer.getCusName())); customer.setCusPhone(MatchUtils.hidePhoneNum(customer.getCusPhone())); customer.setCusIdcard(MatchUtils.hideIdCardNum(customer.getCusIdcard())); customer.setTjNumber(entry.getValue().get(0).getTjNum()); customer.setApplicationTime(entry.getValue().get(0).getApplicationTime()); List samplings = entry.getValue(); if (null != samplings && samplings.size() > 0) { List projectList = new ArrayList<>(); for (TjSampling sampling : samplings) { sampling.setCusName(MatchUtils.hideCusName(sampling.getCusName())); TjProject project = projectService.getById(sampling.getProId()); if (null != project && project.getProParentId() == 0) { projectList.add(sampling); } } map.put("list", projectList); } map.put("customer", customer); arrayList.add(map); } } List> collect = null; if (null != arrayList && arrayList.size() > 0) { collect = arrayList.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); } return collect; } /** * 导出体检采样管理列表 */ //@PreAuthorize("@ss.hasPermi('sampling:sampling:export')") @Log(title = "体检采样管理", businessType = BusinessType.EXPORT) @PostMapping("/export") @ApiOperation(value = "导出体检采样管理列表") public void export(HttpServletResponse response, TjSampling tjSampling) { List list = tjSamplingService.selectTjSamplingList(tjSampling); ExcelUtil util = new ExcelUtil(TjSampling.class); util.exportExcel(response, list, "体检采样管理数据"); } /** * 获取体检采样管理详细信息 */ //@PreAuthorize("@ss.hasPermi('sampling:sampling:query')") @GetMapping(value = "/{id}") @ApiOperation(value = "获取体检采样管理详细信息") public AjaxResult getInfo(@PathVariable("id") String id) { return success(tjSamplingService.selectTjSamplingById(id)); } /** * 新增体检采样管理 */ //@PreAuthorize("@ss.hasPermi('sampling:sampling:add')") @Log(title = "体检采样管理", businessType = BusinessType.INSERT) @PostMapping @ApiOperation(value = "新增体检采样管理") public AjaxResult add(@RequestBody TjSampling tjSampling) { return toAjax(tjSamplingService.insertTjSampling(tjSampling)); } /** * 修改体检采样管理 */ //@PreAuthorize("@ss.hasPermi('sampling:sampling:edit')") @Log(title = "体检采样管理", businessType = BusinessType.UPDATE) @PutMapping @ApiOperation(value = "修改体检采样管理") public AjaxResult edit(@RequestBody TjSampling tjSampling) { return toAjax(tjSamplingService.updateById(tjSampling)); } /** * 删除体检采样管理 */ //@PreAuthorize("@ss.hasPermi('sampling:sampling:remove')") @Log(title = "体检采样管理", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") @ApiOperation(value = "删除体检采样管理") public AjaxResult remove(@PathVariable String[] ids) { return toAjax(tjSamplingService.deleteTjSamplingByIds(ids)); } /** * 确认采样接口 */ @PostMapping("/confirmSampling") @ApiOperation(value = "确认采样接口") public AjaxResult confirmSampling(@RequestBody List ids) { if (null == ids || ids.size() == 0) { return AjaxResult.error("请选择要确认项"); } for (String id : ids) { TjSampling sampling = tjSamplingService.getById(id); if (null != sampling) { sampling.setIsSignFor("0"); LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjProject::getProParentId, sampling.getProId()); List projectList = projectService.list(wq); List collect = new ArrayList<>(); for (TjProject project : projectList) { Long proId = project.getProId(); collect.add(String.valueOf(proId)); } LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjSampling::getTjNum, sampling.getTjNum()); wq1.in(TjSampling::getProId, collect); List samplingList = tjSamplingService.list(wq1); if (null != samplingList && samplingList.size() > 0) { for (TjSampling tjSampling : samplingList) { tjSampling.setIsSignFor("0"); tjSamplingService.updateById(tjSampling); } } } tjSamplingService.updateById(sampling); } return AjaxResult.success("操作成功"); } }