package com.ltkj.web.controller.system;/* * @作者 zjh * @时间 2024-06-26 9:44 * */ import cn.hutool.extra.pinyin.PinyinUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.*; import com.ltkj.hosp.dto.QianDaoDto; import com.ltkj.hosp.service.ITjProjectService; import com.ltkj.hosp.service.TjZhxmService; import com.ltkj.hosp.service.TjZhxmglproService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @RestController @RequestMapping("/system/zhxm") @Api(tags = "PC端组合项目相关接口") @Slf4j public class TjZhxmController extends BaseController { @Autowired private TjZhxmglproService tjZhxmglproService; @Autowired private TjZhxmService zhxmService; @Resource private ITjProjectService tjProjectService; @GetMapping("/getZhList") @ApiOperation(value = "查询组合集合") public AjaxResult getZhList(@ApiParam(value = "体检组合名称或拼音码") @RequestParam(required = false) String zhmc) { LambdaQueryWrapper wq2=new LambdaQueryWrapper<>(); if (zhmc != null) wq2.like(TjZhxm::getZhmc,zhmc).or().like(TjZhxm::getPym,zhmc); List lists = zhxmService.list(wq2); if (null != lists && lists.size()>0) { for (TjZhxm zhxm : lists) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjZhxmglpro::getZhId, zhxm.getId()); List list = tjZhxmglproService.list(wq); StringBuilder allName = new StringBuilder(); if (null != list && list.size() > 0) { List projectList = new ArrayList<>(); BigDecimal money = new BigDecimal("0.00"); for (TjZhxmglpro zhxmglpro : list) { TjProject project = tjProjectService.getById(zhxmglpro.getProId()); if (null != project) { projectList.add(project); allName.append(project.getProName()).append(";"); money=money.add(project.getProPrice()); } } zhxm.setPrice(money); zhxm.setAllProName(allName.toString()); zhxm.setZhxmglpros(list); zhxm.setTjProjectList(projectList); } } return AjaxResult.success(lists); } return AjaxResult.success("暂时没有数据"); } @Log(title = "体检组合项目", businessType = BusinessType.INSERT) @PostMapping @ApiOperation(value = "新增体检组合") @Transactional public AjaxResult add(@RequestBody @ApiParam(value = "体检组合对象") TjZhxm zhxm) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjZhxm::getZhmc, zhxm.getZhmc()); TjZhxm one = zhxmService.getOne(wq); if (null != one) { return AjaxResult.error("该组合已存在,不可重复添加!"); } zhxm.setPym(PinyinUtil.getFirstLetter(zhxm.getZhmc(), "")); if (zhxmService.save(zhxm)) { List zhxmglpros = zhxm.getZhxmglpros(); if (null != zhxmglpros && !zhxmglpros.isEmpty()) { for (TjZhxmglpro zhxmglpro : zhxmglpros) { TjZhxmglpro pro = new TjZhxmglpro(); pro.setZhId(zhxm.getId()); pro.setProId(zhxmglpro.getProId()); tjZhxmglproService.save(pro); } } return AjaxResult.success(); } return AjaxResult.error("新增失败"); } /** * 修改体检组合 */ @Log(title = "体检组合", businessType = BusinessType.UPDATE) @PutMapping @ApiOperation(value = "修改体检组合") @Transactional public AjaxResult edit(@RequestBody @ApiParam(value = "体检组合对象") TjZhxm zhxm) { zhxm.setPym(PinyinUtil.getFirstLetter(zhxm.getZhmc(), "")); if (zhxmService.updateById(zhxm)) { List zhxmglpros = zhxm.getZhxmglpros(); if (null != zhxmglpros && !zhxmglpros.isEmpty()) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjZhxmglpro::getZhId, zhxm.getId()); tjZhxmglproService.remove(wq); for (TjZhxmglpro zhxmglpro : zhxmglpros) { TjZhxmglpro pro = new TjZhxmglpro(); pro.setZhId(zhxm.getId()); pro.setProId(zhxmglpro.getProId()); tjZhxmglproService.save(pro); } } return AjaxResult.success(); } return AjaxResult.error(); } @GetMapping("/listByZhId") @ApiOperation(value = "根据组合id获取体检组合详细信息") public AjaxResult listByZhId(@ApiParam(value = "体检组合id") @RequestParam Long zhId) { if (zhId != null) { TjZhxm zhxm = zhxmService.getById(zhId); if (null != zhxm) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjZhxmglpro::getZhId, zhxm.getId()); List list = tjZhxmglproService.list(wq); StringBuilder allName = new StringBuilder(); // StringBuilder allSonName = new StringBuilder(); if (null != list && !list.isEmpty()) { List projectList = new ArrayList<>(); BigDecimal money = new BigDecimal("0.00"); for (TjZhxmglpro zhxmglpro : list) { TjProject project = tjProjectService.getById(zhxmglpro.getProId()); if (null != project) { projectList.add(project); allName.append(project.getProName()).append(";"); money=money.add(project.getProPrice()); } } zhxm.setAllProName(allName.toString()); zhxm.setPrice(money); zhxm.setZhxmglpros(list); zhxm.setTjProjectList(projectList); return AjaxResult.success(zhxm); } } return success("暂时没有数据"); } return error("组合ID不能为空"); } @DeleteMapping("/{zhIds}") @ApiOperation(value = "删除体检组合") public AjaxResult remove(@PathVariable Long[] zhIds) { if (null != zhIds && zhIds.length > 0) { for (Long zhId : zhIds) { TjZhxm byId = zhxmService.getById(zhId); if (zhxmService.removeById(byId)) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjZhxmglpro::getZhId,zhId); tjZhxmglproService.remove(wq); } } return AjaxResult.success("删除成功"); } return AjaxResult.error("请选择要删除的组合"); } }