package com.ltkj.web.controller.system; import java.security.Security; import java.util.Date; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ltkj.common.core.domain.entity.SysUser; import com.ltkj.common.utils.SecurityUtils; import com.ltkj.hosp.domain.TjCustomer; import com.ltkj.hosp.domain.TjOrder; import com.ltkj.hosp.service.ITjCustomerService; import com.ltkj.hosp.service.ITjOrderService; import com.ltkj.system.service.ISysUserService; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; 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.system.domain.TjDjdDyjl; import com.ltkj.system.service.ITjDjdDyjlService; import com.ltkj.common.utils.poi.ExcelUtil; import com.ltkj.common.core.page.TableDataInfo; /** * 体检导检单打印记录Controller * * @author ltkj * @date 2024-10-25 */ @RestController @RequestMapping("/system/dyjl") @Api(tags = "B-体检导检单打印记录接口") @Slf4j public class TjDjdDyjlController extends BaseController { @Autowired private ITjDjdDyjlService tjDjdDyjlService; @Resource private ITjOrderService orderService; @Resource private ITjCustomerService customerService; @Autowired private ISysUserService userService; /** * 查询体检导检单打印记录列表 */ @PreAuthorize("@ss.hasPermi('system:dyjl:list')") @GetMapping("/list") public TableDataInfo list(TjDjdDyjl tjDjdDyjl) { startPage(); List list = tjDjdDyjlService.selectTjDjdDyjlList(tjDjdDyjl); return getDataTable(list); } /** * 导出体检导检单打印记录列表 */ @PreAuthorize("@ss.hasPermi('system:dyjl:export')") @Log(title = "体检导检单打印记录", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, TjDjdDyjl tjDjdDyjl) { List list = tjDjdDyjlService.selectTjDjdDyjlList(tjDjdDyjl); ExcelUtil util = new ExcelUtil(TjDjdDyjl. class); util.exportExcel(response, list, "体检导检单打印记录数据"); } /** * 获取体检导检单打印记录详细信息 */ @PreAuthorize("@ss.hasPermi('system:dyjl:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(tjDjdDyjlService.selectTjDjdDyjlById(id)); } /** * 新增体检导检单打印记录 */ @PreAuthorize("@ss.hasPermi('system:dyjl:add')") @Log(title = "体检导检单打印记录", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody TjDjdDyjl tjDjdDyjl) { return toAjax(tjDjdDyjlService.insertTjDjdDyjl(tjDjdDyjl)); } /** * 修改体检导检单打印记录 */ @PreAuthorize("@ss.hasPermi('system:dyjl:edit')") @Log(title = "体检导检单打印记录", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody TjDjdDyjl tjDjdDyjl) { return toAjax(tjDjdDyjlService.updateTjDjdDyjl(tjDjdDyjl)); } /** * 删除体检导检单打印记录 */ @PreAuthorize("@ss.hasPermi('system:dyjl:remove')") @Log(title = "体检导检单打印记录", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(tjDjdDyjlService.deleteTjDjdDyjlByIds(ids)); } @PostMapping("/saveGjddyjl") public AjaxResult saveGjddyjl(@RequestBody JSONObject json) { log.info("===================记录打印===================="); log.info(json.toJSONString()); String tjNumber = json.getString("tjNumber"); String dqdlr = json.getString("dqdlr"); SysUser user = userService.getById(dqdlr); TjOrder order = orderService.getOrderByTjNum(tjNumber); if(null !=order){ TjCustomer customer = customerService.getById(order.getUserId()); // String nickName = SecurityUtils.getLoginUser().getUser().getNickName(); Date date=new Date(); LambdaQueryWrapperwq=new LambdaQueryWrapper<>(); wq.eq(TjDjdDyjl::getTjNum,tjNumber); wq.eq(TjDjdDyjl::getDylx,"0"); TjDjdDyjl dyjl = tjDjdDyjlService.getOne(wq); if(null !=dyjl){ Long dycs = dyjl.getDycs(); dycs+=1; dyjl.setDycs(dycs); dyjl.setDysj(date); dyjl.setCreateBy(user.getNickName()); dyjl.setUpdateTime(date); tjDjdDyjlService.updateById(dyjl); return AjaxResult.success(); } TjDjdDyjl djdDyjl=new TjDjdDyjl(); djdDyjl.setTjNum(tjNumber); djdDyjl.setDylx("0"); djdDyjl.setCardId(order.getCardId()); djdDyjl.setHzxm(customer.getCusName()); djdDyjl.setCreateBy(user.getNickName()); djdDyjl.setCreateTime(date); djdDyjl.setDysj(date); tjDjdDyjlService.save(djdDyjl); return AjaxResult.success(); } return AjaxResult.error(); } @PostMapping("/saveBlGjddyjl") public AjaxResult saveBlGjddyjl(@RequestBody JSONObject json) { log.info("===================记录打印===================="); log.info(json.toJSONString()); String tjNumber = json.getString("tjNumber"); String dqdlr = json.getString("dqdlr"); SysUser user = userService.getById(dqdlr); TjOrder order = orderService.getOrderByTjNum(tjNumber); if(null !=order){ TjCustomer customer = customerService.getById(order.getUserId()); // String nickName = SecurityUtils.getLoginUser().getUser().getNickName(); Date date=new Date(); LambdaQueryWrapperwq=new LambdaQueryWrapper<>(); wq.eq(TjDjdDyjl::getTjNum,tjNumber); wq.eq(TjDjdDyjl::getDylx,"1"); TjDjdDyjl dyjl = tjDjdDyjlService.getOne(wq); if(null !=dyjl){ Long dycs = dyjl.getDycs(); dycs+=1; dyjl.setDycs(dycs); dyjl.setDysj(date); dyjl.setCreateBy(user.getNickName()); dyjl.setUpdateTime(date); tjDjdDyjlService.updateById(dyjl); return AjaxResult.success(); } TjDjdDyjl djdDyjl=new TjDjdDyjl(); djdDyjl.setTjNum(tjNumber); djdDyjl.setDylx("1"); djdDyjl.setCardId(order.getCardId()); djdDyjl.setHzxm(customer.getCusName()); djdDyjl.setCreateBy(user.getNickName()); djdDyjl.setCreateTime(date); djdDyjl.setDysj(date); tjDjdDyjlService.save(djdDyjl); return AjaxResult.success(); } return AjaxResult.error(); } }