package com.glxp.api.controller.inout; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.controller.BaseController; import com.glxp.api.dao.inout.IoOrderDao; import com.glxp.api.entity.alihealth.YcFileCodeUploadVo; import com.glxp.api.entity.inout.IoCodeEntity; import com.glxp.api.entity.inout.IoOrderEntity; import com.glxp.api.exception.JsonException; import com.glxp.api.req.inout.FilterCodeRequest; import com.glxp.api.req.inout.FilterOrderDetailBizRequest; import com.glxp.api.req.inout.YcFileCodeUploadRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.inout.IoCodeResponse; import com.glxp.api.res.inout.IoOrderDetailBizResponse; import com.glxp.api.service.inout.IoOrderDetailBizService; import com.glxp.api.service.inout.IoOrderService; import com.glxp.api.service.inout.impl.IoCodeService; import com.glxp.api.util.Excel.ExcelHandler; import com.glxp.api.util.Excel.ExcelTemplateEnum; import com.glxp.api.util.Excel.Exception.RenException; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 单据正式码表接口 */ @RestController public class IoCodeController extends BaseController { @Resource private IoCodeService ioCodeService; @Resource private IoOrderService ioOrderService; @Resource private IoOrderDetailBizService ioOrderDetailBizService; /** * 查询单据正式码表数据 * * @param filterCodeRequest * @return */ @GetMapping("/udiwms/inout/code/filterList") public BaseResponse filterList(FilterCodeRequest filterCodeRequest) { List list = ioCodeService.filterList(filterCodeRequest); PageInfo pageInfo = new PageInfo<>(list); return ResultVOUtils.page(pageInfo); } @GetMapping("/udiwms/inout/code/drug/filterList") public BaseResponse filterDrugList(FilterCodeRequest filterCodeRequest) { List list = ioCodeService.filterDrugList(filterCodeRequest); PageInfo pageInfo = new PageInfo<>(list); return ResultVOUtils.page(pageInfo); } /** * 根据单据号查询正式码表数据 * * @return */ @GetMapping("/udiwms/inout/code/findByOrderId") public BaseResponse findAllByOrderId(FilterCodeRequest filterCodeRequest) { List list = ioCodeService.filterList(filterCodeRequest); PageInfo pageInfo = new PageInfo<>(list); return ResultVOUtils.success(pageInfo); } /** * 单据复核,获取单据对应条码 */ @AuthRuleAnnotation("") @GetMapping("spms/inout/dlcode/findByOrderId") public BaseResponse downloadCodesByOrderId(String orderId) { List codeEntityList = ioCodeService.findByOrderId(orderId); PageInfo pageInfo; pageInfo = new PageInfo<>(codeEntityList); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(codeEntityList); return ResultVOUtils.success(pageSimpleResponse); } /** * 单据编辑,+ * * @param filterCodeRequest * @return */ @GetMapping("/udiwms/inout/code/getCodeListForEdit") public BaseResponse getCodeListForEdit(FilterCodeRequest filterCodeRequest) { List list = ioCodeService.getCodeListForEdit(filterCodeRequest); PageInfo pageInfo = new PageInfo<>(list); return ResultVOUtils.page(pageInfo); } @Resource ExcelHandler excelHandler; @GetMapping("/udiwms/inout/code/filterList/excelExport") public void excelExport(YcFileCodeUploadRequest ycFileCodeUploadRequest, HttpServletResponse response) { String billNo = ycFileCodeUploadRequest.getBillNo(); if (StrUtil.isEmpty(billNo)) { throw new JsonException("单据编号不能为空!"); } //获取订单的详情 IoOrderEntity ioOrderEntity = ioOrderService.findByBillNo(billNo); if (ioOrderEntity == null) { throw new JsonException("单据未找到!"); } //获取biz表 FilterOrderDetailBizRequest orderDetailBizRequest = new FilterOrderDetailBizRequest(); orderDetailBizRequest.setOrderIdFk(billNo); List ioOrderDetailBizResponses = ioOrderDetailBizService.filterList(orderDetailBizRequest); if (CollUtil.isEmpty(ioOrderDetailBizResponses)) { throw new JsonException("单据业务明细未找到!"); } FilterCodeRequest filterCodeRequest = new FilterCodeRequest(); List exportExcelList = new ArrayList<>(); String ycBillNo = ioOrderEntity.getYcBillNo(); filterCodeRequest.setYcBillNo(ycBillNo); //遍历biz获取codeList for (int i = 0; i < ioOrderDetailBizResponses.size(); i++) { IoOrderDetailBizResponse ioOrderDetailBizResponse = ioOrderDetailBizResponses.get(i); filterCodeRequest.setYcBizNo(ioOrderDetailBizResponse.getYcBizNo()); filterCodeRequest.setRelId(String.valueOf(ioOrderDetailBizResponse.getBindRlFk())); filterCodeRequest.setBatchNo(ioOrderDetailBizResponse.getBatchNo()); List list = ioCodeService.filterListexcelExport(filterCodeRequest); if (CollUtil.isNotEmpty(list)) { exportExcelList.addAll(list); } } try { excelHandler.exportExcel(response, exportExcelList, YcFileCodeUploadVo.class, "UDI_"+billNo+"追溯码导出", "追溯码"); } catch (Exception e) { throw new RenException("导出失败"); } } }