package com.glxp.api.controller.inout; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; 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.annotation.Log; import com.glxp.api.annotation.RepeatSubmit; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.BusinessType; import com.glxp.api.constant.Constant; import com.glxp.api.constant.ConstantStatus; import com.glxp.api.controller.BaseController; import com.glxp.api.dao.basic.UdiRelevanceDao; import com.glxp.api.dao.inout.IoOrderDetailBizDao; import com.glxp.api.entity.alihealth.AliYljgBillDetail; import com.glxp.api.entity.alihealth.AliYljgBillDetailDrug; import com.glxp.api.entity.alihealth.AliYljgBillDetailDrugCode; import com.glxp.api.entity.alihealth.AliYljgSearchbill; import com.glxp.api.entity.auth.AuthAdmin; import com.glxp.api.entity.auth.InvWarehouseEntity; import com.glxp.api.entity.basic.*; import com.glxp.api.entity.inout.*; import com.glxp.api.entity.purchase.PurOrderDetailEntity; import com.glxp.api.entity.purchase.PurOrderEntity; import com.glxp.api.entity.purchase.SupCertEntity; import com.glxp.api.entity.purchase.SupProductEntity; import com.glxp.api.entity.system.SystemParamConfigEntity; import com.glxp.api.entity.thrsys.ThrOrderDetailEntity; import com.glxp.api.entity.thrsys.ThrOrderEntity; import com.glxp.api.entity.thrsys.ThrSystemBusApiEntity; import com.glxp.api.req.alihealth.AliYljgSearchbillReqeust; import com.glxp.api.req.basic.FilterUdiRelRequest; import com.glxp.api.req.inout.*; import com.glxp.api.req.inv.FilterInvoiceRequest; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.req.thrsys.FilterThrOrderDetailRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.basic.UdiRelevanceResponse; import com.glxp.api.res.inout.IoOrderDetailBizResponse; import com.glxp.api.res.inout.IoOrderDetailCodeResponse; import com.glxp.api.res.inout.IoOrderDetailResultResponse; import com.glxp.api.res.inout.IoOrderInvoiceResponse; import com.glxp.api.service.alihealth.AlihealthBusService; import com.glxp.api.service.auth.InvWarehouseService; import com.glxp.api.service.basic.*; import com.glxp.api.service.inout.*; import com.glxp.api.service.inout.impl.IoCodeTempService; import com.glxp.api.service.inout.impl.IoOrderInvoiceService; import com.glxp.api.service.purchase.PurOrderDetailService; import com.glxp.api.service.purchase.PurOrderService; import com.glxp.api.service.purchase.SupCertService; import com.glxp.api.service.purchase.SupProductService; import com.glxp.api.service.system.SystemParamConfigService; import com.glxp.api.service.thrsys.ThrOrderDetailService; import com.glxp.api.service.thrsys.ThrOrderService; import com.glxp.api.service.thrsys.ThrSystemBusApiService; import com.glxp.api.util.GennerOrderUtils; import com.glxp.api.util.IntUtil; import com.glxp.api.util.OrderNoTypeBean; import com.glxp.api.util.udi.FilterUdiUtils; import com.glxp.api.util.udi.UdiCalCountUtil; import org.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * 单据业务详情 */ @RestController public class IoOrderDetailBizController extends BaseController { @Resource IoOrderService orderService; @Resource IoOrderDetailBizService orderDetailBizService; @Resource UdiRelevanceService udiRelevanceService; @Resource GennerOrderUtils gennerOrderUtils; @Resource private IBasicBussinessTypeService basicBussinessTypeService; @Resource InvWarehouseService invWarehouseService; @Resource private IoCheckInoutService ioCheckInoutService; @Resource IoOrderDetailCodeService orderDetailCodeService; @Resource ThrOrderService thrOrderService; @Resource ReceiveService receiveService; @Resource ReceivedetailService receivedetailService; @Resource IBasicBusTypeChangeService basicBusTypeChangeService; @Resource IoOrderInvoiceService ioOrderInvoiceService; //获取单据业务详情---临时接口查询 @AuthRuleAnnotation("") @GetMapping("udiwms/inout/order/draft/biz") public BaseResponse getDraftsDetailCode(String orderId) { List orderEntityList = orderDetailBizService.checkOrderList(orderId); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(100l); pageSimpleResponse.setList(orderEntityList); return ResultVOUtils.success(pageSimpleResponse); } @Resource SupProductService supProductService; @Resource SystemParamConfigService systemParamConfigService; @Resource SupCertService supCertService; //录入业务单据详情 @AuthRuleAnnotation("") @PostMapping("/udiwms/inout/order/addBizProduct") @Log(title = "单据管理", businessType = BusinessType.INSERT) public BaseResponse addBizProduct(@RequestBody AddBizProductReqeust addBizProductReqeust) { return orderDetailBizService.addBizProduct(addBizProductReqeust); } //修改业务单据详情 @AuthRuleAnnotation("") @PostMapping("/udiwms/inout/order/updateBizProduct") @Log(title = "单据管理", businessType = BusinessType.UPDATE) public BaseResponse updateBizProduct(@RequestBody IoOrderDetailBizEntity orderDetailBizEntity) { boolean isExit = orderDetailBizService.isExit(orderDetailBizEntity.getBindRlFk(), orderDetailBizEntity.getBatchNo(), orderDetailBizEntity.getId(), orderDetailBizEntity.getOrderIdFk()); if (isExit) { return ResultVOUtils.error(500, "存在相同产品,相同批次号,请检查后保存!"); } return orderDetailBizService.update(orderDetailBizEntity) > 0 ? ResultVOUtils.success("保存成功!") : ResultVOUtils.error(500, "保存失败"); } @Resource ThrOrderDetailService thrOrderDetailService; @Resource ThrSystemBusApiService thrSystemBusApiService; @Resource UdiRlSupService udiRlSupService; //选入第三方单据至业务单据 @AuthRuleAnnotation("") @PostMapping("/udiwms/inout/order/addThrOrder") @Log(title = "单据管理", businessType = BusinessType.INSERT) public BaseResponse addThrOrder(@RequestBody ThrOrderEntity thrOrderRequest) { ThrOrderEntity thrOrderEntity = thrOrderService.findById(thrOrderRequest.getId()); if (thrOrderEntity == null) { return ResultVOUtils.error(ResultEnum.DATA_NOT); } List thrOrderDetailEntities = thrOrderDetailService.selectByBillNo(thrOrderEntity.getBillNo()); //获取单据类型 ThrSystemBusApiEntity thrSystemBusApiEntity = thrSystemBusApiService.selectByThrBus(thrOrderEntity.getBillType(), thrOrderEntity.getThirdSysFk()); if (thrSystemBusApiEntity == null || StrUtil.isEmpty(thrSystemBusApiEntity.getCode())) { return ResultVOUtils.error(500, "单据类型对照有误!"); } BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(thrSystemBusApiEntity.getCode()); AuthAdmin authAdmin = getUser(); //创建单据 IoOrderEntity orderEntity = new IoOrderEntity(); String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd")); orderEntity.setBillNo(orderNo); orderEntity.setCreateUser(authAdmin.getId() + ""); orderEntity.setCreateTime(new Date()); orderEntity.setUpdateUser(authAdmin.getId() + ""); orderEntity.setUpdateTime(new Date()); orderEntity.setCustomerId(authAdmin.getCustomerId() + ""); orderEntity.setCorpOrderId(thrOrderEntity.getBillNo()); orderEntity.setAction(bussinessTypeEntity.getAction()); orderEntity.setMainAction(bussinessTypeEntity.getMainAction()); orderEntity.setFromThrBillNo(thrOrderEntity.getBillNo()); //获取当前部门 if (StrUtil.isNotEmpty(thrOrderEntity.getInvCode())) { InvWarehouseEntity invWarehouseEntity = invWarehouseService.selectByThrCode(thrOrderEntity.getInvCode(), thrOrderEntity.getThirdSysFk()); if (invWarehouseEntity != null) { orderEntity.setDeptCode(invWarehouseEntity.getParentId()); orderEntity.setInvCode(invWarehouseEntity.getCode()); } } else { return ResultVOUtils.error(500, "第三方单据所属仓库不能为空!"); } //获取往来信息 if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_INNOR) {//内部调拨 InvWarehouseEntity invWarehouseEntity = invWarehouseService.selectByThrCode(thrOrderEntity.getCorpId(), thrOrderEntity.getThirdSysFk()); orderEntity.setFromDeptCode(invWarehouseEntity.getParentId()); orderEntity.setFromInvCode(invWarehouseEntity.getCode()); } else if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) { //往来信息 BasicCorpEntity basicCorpEntity = basicCorpService.selectByThirdId(thrOrderEntity.getCorpId(), thrOrderEntity.getThirdSysFk()); orderEntity.setFromCorp(basicCorpEntity.getErpId()); } else { orderEntity.setFromCorp(thrOrderEntity.getCorpId()); } orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE); orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT); orderEntity.setFromType(ConstantStatus.FROM_THRORDER); orderEntity.setOrderType(ConstantStatus.ORDER_TYPE_BIZ); orderEntity.setBusType(bussinessTypeEntity.getBusType()); orderService.insertOrder(orderEntity); for (ThrOrderDetailEntity thrOrderDetailEntity : thrOrderDetailEntities) { thrOrderDetailEntity.getProductId(); List udiRelevanceEntities = udiRelevanceService.selectListByThirdId(thrOrderDetailEntity.getProductId(), thrOrderEntity.getThirdSysFk()); IoOrderDetailBizEntity ioOrderDetailBizEntity = new IoOrderDetailBizEntity(); UdiRelevanceResponse udiRelevanceResponse = null; if (udiRelevanceEntities.size() == 1) { udiRelevanceResponse = udiRelevanceEntities.get(0); ioOrderDetailBizEntity.setBindRlFk(udiRelevanceResponse.getId()); ioOrderDetailBizEntity.setUuidFk(udiRelevanceResponse.getUuid()); ioOrderDetailBizEntity.setNameCode(udiRelevanceResponse.getNameCode()); ioOrderDetailBizEntity.setCoName(udiRelevanceResponse.getCpmctymc()); ioOrderDetailBizEntity.setCertCode(udiRelevanceResponse.getZczbhhzbapzbh()); ioOrderDetailBizEntity.setYlqxzcrbarmc(udiRelevanceResponse.getYlqxzcrbarmc()); ioOrderDetailBizEntity.setManufacturer(udiRelevanceResponse.getManufactory()); ioOrderDetailBizEntity.setMeasname(udiRelevanceResponse.getMeasname()); ioOrderDetailBizEntity.setSpec(udiRelevanceResponse.getGgxh()); ioOrderDetailBizEntity.setPrice(udiRelevanceResponse.getPrice()); } else { ioOrderDetailBizEntity.setCoName(thrOrderDetailEntity.getCorpName()); ioOrderDetailBizEntity.setCertCode(thrOrderDetailEntity.getZczbhhzbapzbh()); ioOrderDetailBizEntity.setYlqxzcrbarmc(thrOrderDetailEntity.getYlqxzcrbarmc()); ioOrderDetailBizEntity.setManufacturer(thrOrderDetailEntity.getManufactory()); ioOrderDetailBizEntity.setSpec(thrOrderDetailEntity.getSpec()); ioOrderDetailBizEntity.setPrice(thrOrderDetailEntity.getPrice()); if (udiRelevanceEntities.size() > 1) { String bindRlIds = ""; for (UdiRelevanceResponse temp : udiRelevanceEntities) { bindRlIds = bindRlIds + "," + temp.getId(); } ioOrderDetailBizEntity.setBindRlIds(bindRlIds.substring(1)); } } ioOrderDetailBizEntity.setOrderIdFk(orderEntity.getBillNo()); ioOrderDetailBizEntity.setProductDate(thrOrderDetailEntity.getProductDate()); ioOrderDetailBizEntity.setExpireDate(thrOrderDetailEntity.getExpireDate()); ioOrderDetailBizEntity.setBatchNo(thrOrderDetailEntity.getBatchNo()); ioOrderDetailBizEntity.setCount(thrOrderDetailEntity.getCount()); if (StrUtil.isNotEmpty(thrOrderDetailEntity.getSupId())) { BasicCorpEntity basicCorpEntity = basicCorpService.selectByThirdId(thrOrderDetailEntity.getSupId(), thrOrderEntity.getThirdSysFk()); ioOrderDetailBizEntity.setSupId(basicCorpEntity.getErpId()); } else if (udiRelevanceResponse != null) { List udiRlSupEntities = udiRlSupService.findByUdiRlId(udiRelevanceResponse.getId()); if (CollUtil.isNotEmpty(udiRlSupEntities) && udiRlSupEntities.size() == 1) { ioOrderDetailBizEntity.setSupId(udiRlSupEntities.get(0).getCustomerId()); } } orderDetailBizService.insert(ioOrderDetailBizEntity); } thrOrderService.updateThrOrder(thrOrderEntity); return ResultVOUtils.success("选入成功!"); } @Resource BasicCorpService basicCorpService; //选入领用单据至业务单据 @AuthRuleAnnotation("") @PostMapping("/udiwms/inout/order/addReceiveOrder") @Log(title = "单据管理", businessType = BusinessType.INSERT) public BaseResponse addReceiveOrder(@RequestBody PurReceiveEntity purReceiveEntity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } purReceiveEntity = receiveService.selectById(purReceiveEntity.getId()); List purReceiveDetailEntities = receivedetailService.selectByOrderId(purReceiveEntity.getBillNo()); BasicBusTypeChangeEntity basicBusTypeChangeEntity = basicBusTypeChangeService.selectByOriginAction(purReceiveEntity.getBillType()); BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(basicBusTypeChangeEntity.getTargetAction()); AuthAdmin authAdmin = getUser(); //创建单据 IoOrderEntity orderEntity = new IoOrderEntity(); String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd")); orderEntity.setBillNo(orderNo); orderEntity.setCreateUser(authAdmin.getId() + ""); orderEntity.setCreateTime(new Date()); orderEntity.setUpdateUser(authAdmin.getId() + ""); orderEntity.setUpdateTime(new Date()); orderEntity.setCustomerId(authAdmin.getCustomerId() + ""); orderEntity.setCorpOrderId(purReceiveEntity.getBillNo()); orderEntity.setAction(bussinessTypeEntity.getAction()); orderEntity.setMainAction(bussinessTypeEntity.getMainAction()); orderEntity.setDeptCode(purReceiveEntity.getTargetDeptCode()); orderEntity.setInvCode(purReceiveEntity.getTargetInvCode()); orderEntity.setFromReceiveBillNo(purReceiveEntity.getBillNo()); orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE); orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT); orderEntity.setFromType(ConstantStatus.FROM_RECEIVE); orderEntity.setOrderType(ConstantStatus.ORDER_TYPE_BIZ); orderEntity.setFromDeptCode(purReceiveEntity.getDeptCode()); orderEntity.setFromInvCode(purReceiveEntity.getInvCode()); orderEntity.setBusType(bussinessTypeEntity.getBusType()); orderService.insertOrder(orderEntity); for (PurReceiveDetailEntity purReceiveDetailEntity : purReceiveDetailEntities) { IoOrderDetailBizEntity ioOrderDetailBizEntity = new IoOrderDetailBizEntity(); UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectGroupById(purReceiveDetailEntity.getRelIdFk()); ioOrderDetailBizEntity.setOrderIdFk(orderEntity.getBillNo()); ioOrderDetailBizEntity.setBindRlFk(udiRelevanceResponse.getId()); ioOrderDetailBizEntity.setUuidFk(udiRelevanceResponse.getUuid()); ioOrderDetailBizEntity.setNameCode(udiRelevanceResponse.getNameCode()); ioOrderDetailBizEntity.setCoName(udiRelevanceResponse.getCpmctymc()); ioOrderDetailBizEntity.setCertCode(udiRelevanceResponse.getZczbhhzbapzbh()); ioOrderDetailBizEntity.setYlqxzcrbarmc(udiRelevanceResponse.getYlqxzcrbarmc()); ioOrderDetailBizEntity.setManufacturer(udiRelevanceResponse.getManufactory()); ioOrderDetailBizEntity.setMeasname(udiRelevanceResponse.getMeasname()); ioOrderDetailBizEntity.setSpec(udiRelevanceResponse.getGgxh()); ioOrderDetailBizEntity.setPrice(udiRelevanceResponse.getPrice()); ioOrderDetailBizEntity.setProductDate(purReceiveDetailEntity.getProductDate()); ioOrderDetailBizEntity.setExpireDate(purReceiveDetailEntity.getExpireDate()); ioOrderDetailBizEntity.setBatchNo(purReceiveDetailEntity.getBatchNo()); ioOrderDetailBizEntity.setSupId(purReceiveDetailEntity.getSupId()); ioOrderDetailBizEntity.setCount(purReceiveDetailEntity.getCount()); orderDetailBizService.insert(ioOrderDetailBizEntity); } return ResultVOUtils.success("选入成功!"); } @Resource PurOrderService purOrderService; @Resource PurOrderDetailService purOrderDetailService; //选入领用单据至业务单据 @AuthRuleAnnotation("") @PostMapping("/udiwms/inout/order/addPurOrder") @Log(title = "单据管理", businessType = BusinessType.INSERT) public BaseResponse addPurOrder(@RequestBody PurOrderEntity purOrderEntity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } purOrderEntity = purOrderService.selectById(purOrderEntity.getId()); List purOrderDetailEntities = purOrderDetailService.findByOrderId(purOrderEntity.getId() + ""); BasicBusTypeChangeEntity basicBusTypeChangeEntity = basicBusTypeChangeService.selectByOriginAction(purOrderEntity.getBillType()); if (basicBusTypeChangeEntity == null) { return ResultVOUtils.error(500, "采购订单未配置转换单据类型!"); } BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(basicBusTypeChangeEntity.getTargetAction()); AuthAdmin authAdmin = getUser(); //创建单据 IoOrderEntity orderEntity = new IoOrderEntity(); String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd")); orderEntity.setBillNo(orderNo); orderEntity.setCreateUser(authAdmin.getId() + ""); orderEntity.setCreateTime(new Date()); orderEntity.setUpdateUser(authAdmin.getId() + ""); orderEntity.setUpdateTime(new Date()); orderEntity.setCustomerId(authAdmin.getCustomerId() + ""); orderEntity.setCorpOrderId(purOrderEntity.getBillNo()); orderEntity.setAction(bussinessTypeEntity.getAction()); orderEntity.setMainAction(bussinessTypeEntity.getMainAction()); orderEntity.setDeptCode(purOrderEntity.getDeptCode()); orderEntity.setInvCode(purOrderEntity.getInvCode()); orderEntity.setFromReceiveBillNo(purOrderEntity.getBillNo()); orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE); orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT); orderEntity.setFromType(ConstantStatus.FROM_RECEIVE); orderEntity.setOrderType(ConstantStatus.ORDER_TYPE_BIZ); orderEntity.setBusType(bussinessTypeEntity.getBusType()); orderService.insertOrder(orderEntity); for (PurOrderDetailEntity purReceiveDetailEntity : purOrderDetailEntities) { IoOrderDetailBizEntity ioOrderDetailBizEntity = new IoOrderDetailBizEntity(); UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectGroupById(purReceiveDetailEntity.getProductId().longValue()); ioOrderDetailBizEntity.setOrderIdFk(orderEntity.getBillNo()); ioOrderDetailBizEntity.setBindRlFk(udiRelevanceResponse.getId()); ioOrderDetailBizEntity.setUuidFk(udiRelevanceResponse.getUuid()); ioOrderDetailBizEntity.setNameCode(udiRelevanceResponse.getNameCode()); ioOrderDetailBizEntity.setCoName(udiRelevanceResponse.getCpmctymc()); ioOrderDetailBizEntity.setCertCode(udiRelevanceResponse.getZczbhhzbapzbh()); ioOrderDetailBizEntity.setYlqxzcrbarmc(udiRelevanceResponse.getYlqxzcrbarmc()); ioOrderDetailBizEntity.setManufacturer(udiRelevanceResponse.getManufactory()); ioOrderDetailBizEntity.setMeasname(udiRelevanceResponse.getMeasname()); ioOrderDetailBizEntity.setSpec(udiRelevanceResponse.getGgxh()); ioOrderDetailBizEntity.setPrice(udiRelevanceResponse.getPrice()); ioOrderDetailBizEntity.setSupId(purReceiveDetailEntity.getSupId()); ioOrderDetailBizEntity.setCount(purReceiveDetailEntity.getCount()); orderDetailBizService.insert(ioOrderDetailBizEntity); } return ResultVOUtils.success("选入成功!"); } @AuthRuleAnnotation("") @PostMapping("/udiwms/inout/order/delBizProduct") @Log(title = "单据管理", businessType = BusinessType.DELETE) public BaseResponse delBizProduct(@RequestBody DeleteRequest deleteRequest) { IoOrderDetailBizEntity orderDetailBizEntity = orderDetailBizService.selectById(Long.parseLong(deleteRequest.getId())); int result = orderDetailBizService.deleteById(Long.parseLong(deleteRequest.getId())); if (result > 0) { boolean r1 = orderDetailBizService.isExit(orderDetailBizEntity.getOrderIdFk()); boolean r2 = orderDetailCodeService.isExit(orderDetailBizEntity.getOrderIdFk()); if (!r1 && !r2) { orderService.deleteByBillNo(orderDetailBizEntity.getOrderIdFk()); } return ResultVOUtils.success("删除成功!"); } return ResultVOUtils.error(500, "删除失败"); } /** * 查询单据业务详情列表 * * @param orderDetailBizRequest * @return */ @GetMapping("/udiwms/inout/bizDetail/filterList") public BaseResponse filterList(FilterOrderDetailBizRequest orderDetailBizRequest) { List list = orderDetailBizService.filterList(orderDetailBizRequest); String value = systemParamConfigService.selectValueByParamKey("order_detail_visible"); if (IntUtil.value(value) == 1) { list = list.stream() .sorted(Comparator.comparing(IoOrderDetailBizResponse::getNameCode)) .collect(Collectors.toList()); } List orderDetailCodeEntities = orderDetailCodeService.findByOrderId(orderDetailBizRequest.getOrderIdFk()); ioCheckInoutService.bizOrderCheck2(list, orderDetailCodeEntities); PageInfo pageInfo = new PageInfo<>(list); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(list); return ResultVOUtils.success(pageSimpleResponse); } @GetMapping("/udiwms/inout/bizDetail/drug/filterList") public BaseResponse filterDrugList(FilterOrderDetailBizRequest orderDetailBizRequest) { List list = orderDetailBizService.filterDrugList(orderDetailBizRequest); String value = systemParamConfigService.selectValueByParamKey("order_detail_visible"); if (IntUtil.value(value) == 1) { list = list.stream() .sorted(Comparator.comparing(IoOrderDetailBizResponse::getNameCode)) .collect(Collectors.toList()); } List orderDetailCodeEntities = orderDetailCodeService.findByOrderId(orderDetailBizRequest.getOrderIdFk()); ioCheckInoutService.bizOrderCheck2(list, orderDetailCodeEntities); PageInfo pageInfo = new PageInfo<>(list); return ResultVOUtils.page(pageInfo); } // @GetMapping("/udiwms/inout/bizDetail/filterListInv") // public BaseResponse filterListInv(FilterOrderDetailBizRequest orderDetailBizRequest) { // List list = orderDetailBizService.getfilterList(orderDetailBizRequest); // List orderDetailCodeEntities = orderDetailCodeService.findByOrderId(orderDetailBizRequest.getOrderIdFk()); // ioCheckInoutService.bizOrderCheck2(list, orderDetailCodeEntities); // PageInfo pageInfo = new PageInfo<>(list); // return ResultVOUtils.page(pageInfo); // } @GetMapping("/udiwms/inout/bizDetail/filterListInvoice") public BaseResponse filterListInvoice(FilterOrderDetailBizRequest orderDetailBizRequest) { List list = orderDetailBizService.filterListInv(orderDetailBizRequest); PageInfo pageInfo = new PageInfo<>(list); return ResultVOUtils.page(pageInfo); } @AuthRuleAnnotation("") @PostMapping("/udiwms/inout/biz/updateBind") @Log(title = "单据管理", businessType = BusinessType.UPDATE) public BaseResponse updateBindSup(@RequestBody BizBindUpdateRequest bizBindUpdateRequest) { IoOrderDetailBizEntity orderDetailBizEntity = orderDetailBizService.selectById(bizBindUpdateRequest.getId()); if (bizBindUpdateRequest.getBindRlFk() != null) orderDetailBizEntity.setBindRlFk(bizBindUpdateRequest.getBindRlFk()); if (StrUtil.isNotEmpty(bizBindUpdateRequest.getSupId())) { orderDetailBizEntity.setSupId(bizBindUpdateRequest.getSupId()); } orderDetailBizService.update(orderDetailBizEntity); return ResultVOUtils.success("绑定成功"); } /** * 删除发票表 * * @param * @return */ @PostMapping("/udiwms/inout/biz/deleteById") @Log(title = "发票管理", businessType = BusinessType.DELETE) public BaseResponse deleteById(@RequestBody IoOrderInvoiceEntity ioOrderInvoiceEntity) { IoOrderInvoiceResponse ioOrderInvoiceResponse = orderDetailBizService.selectByinvoiceId(ioOrderInvoiceEntity.getId()); //更改 登记状态 IoOrderDetailCodeEntity ioOrderDetailBizEntity = new IoOrderDetailCodeEntity(); FilterOrderDetailBizRequest filterOrderDetailBizRequest = new FilterOrderDetailBizRequest(); FilterOrderDetailBizRequest filterOrderDetailBizRequest1 = new FilterOrderDetailBizRequest(); filterOrderDetailBizRequest1.setOrderIdFk(ioOrderInvoiceEntity.getOrderIdFk()); filterOrderDetailBizRequest1.setBatchNo(ioOrderInvoiceEntity.getBatchNo()); filterOrderDetailBizRequest.setOrderIdFk(ioOrderInvoiceEntity.getOrderIdFk()); filterOrderDetailBizRequest.setBatchNo(ioOrderInvoiceEntity.getBatchNo()); filterOrderDetailBizRequest.setRelId(ioOrderInvoiceEntity.getBizIdFk()); ioOrderDetailBizEntity.setOrderIdFk(ioOrderInvoiceEntity.getOrderIdFk()); ioOrderDetailBizEntity.setBatchNo(ioOrderInvoiceEntity.getBatchNo()); ioOrderDetailBizEntity.setBindRlFk(ioOrderInvoiceEntity.getBizIdFk()); ioOrderDetailBizEntity.setId(ioOrderInvoiceResponse.getBizIdFk().longValue()); ioOrderInvoiceService.deleteByInvId(ioOrderInvoiceEntity.getId() + ""); List list = orderDetailBizService.filterListInv(filterOrderDetailBizRequest); List ioOrderInvoiceResponses = orderDetailBizService.filterListInv(filterOrderDetailBizRequest1); if (list.size() == 0) { ioOrderDetailBizEntity.setRegStatus(false); } else { ioOrderDetailBizEntity.setRegStatus(true); } orderDetailCodeService.updateOrderDetailBiz(ioOrderDetailBizEntity); return ResultVOUtils.success(ioOrderInvoiceResponses); } /** * 修改发票表 * * @param ioOrderInvoiceRequest * @return */ @PostMapping("/udiwms/inout/biz/updateById") @Log(title = "发票管理", businessType = BusinessType.UPDATE) public BaseResponse updateById(@RequestBody IoOrderInvoiceRequest ioOrderInvoiceRequest) { IoOrderEntity orderEntity = orderService.findByBillNo(ioOrderInvoiceRequest.getOrderIdFk()); if (orderEntity != null) { orderEntity.setUpdateTime(new Date()); orderService.update(orderEntity); } return ResultVOUtils.success(ioOrderInvoiceService.updateByInvId(ioOrderInvoiceRequest)); } @PostMapping("/udiwms/inout/bizDetail/updateById") @Log(title = "发票管理", businessType = BusinessType.UPDATE) public BaseResponse updateBizById(@RequestBody IoOrderDetailBizEntity ioOrderDetailBizEntity) { IoOrderEntity orderEntity = orderService.findByBillNo(ioOrderDetailBizEntity.getOrderIdFk()); if (orderEntity != null) { orderEntity.setUpdateTime(new Date()); orderService.update(orderEntity); } ioOrderDetailBizEntity.setCheckFileName(ioOrderDetailBizEntity.getCheckFileName()); ioOrderDetailBizEntity.setCheckColdFileName(ioOrderDetailBizEntity.getCheckColdFileName()); boolean b = orderDetailBizService.updateOrderDetailBiz(ioOrderDetailBizEntity); return ResultVOUtils.success("修改成功!"); } @RepeatSubmit @PostMapping("/udiwms/inout/biz/insertInvoice") @Log(title = "发票管理", businessType = BusinessType.INSERT) public BaseResponse insertInvoice(@RequestBody IoOrderInvoiceEntity ioOrderInvoice) { String billNo = null; for (IoOrderDetailBizEntity ioOrderDetailBizEntity : ioOrderInvoice.getList()) { IoOrderInvoiceEntity ioOrderInvoiceEntity = new IoOrderInvoiceEntity(); ioOrderInvoiceEntity.setOrderIdFk(ioOrderDetailBizEntity.getOrderIdFk()); ioOrderInvoiceEntity.setBindRlFk(ioOrderDetailBizEntity.getBindRlFk() + ""); ioOrderInvoiceEntity.setBatchNo(ioOrderDetailBizEntity.getBatchNo()); ioOrderInvoiceEntity.setProductDate(ioOrderDetailBizEntity.getProductDate()); ioOrderInvoiceEntity.setExpireDate(ioOrderDetailBizEntity.getExpireDate()); ioOrderInvoiceEntity.setBizIdFk(ioOrderDetailBizEntity.getId()); ioOrderInvoiceEntity.setCreateTime(new Date()); ioOrderInvoiceEntity.setUpdateTime(new Date()); ioOrderInvoiceEntity.setId(IdUtil.getSnowflakeNextId()); ioOrderInvoiceEntity.setMachineNo(ioOrderInvoice.getMachineNo()); ioOrderInvoiceEntity.setInvoiceCode(ioOrderInvoice.getInvoiceCode()); ioOrderInvoiceEntity.setInvoiceEncode(ioOrderInvoice.getInvoiceEncode()); ioOrderInvoiceEntity.setInvoiceDate(ioOrderInvoice.getInvoiceDate()); ioOrderInvoiceEntity.setPrice(ioOrderInvoice.getPrice()); ioOrderInvoiceEntity.setRemark(ioOrderInvoice.getRemark()); ioOrderInvoiceEntity.setLicenseUrl(ioOrderInvoice.getLicenseUrl()); boolean b = ioOrderInvoiceService.insertInvoice(ioOrderInvoiceEntity); billNo = ioOrderDetailBizEntity.getOrderIdFk(); } IoOrderEntity orderEntity = orderService.findByBillNo(billNo); orderEntity.setUpdateTime(new Date()); orderService.update(orderEntity); return ResultVOUtils.success("成功"); } @GetMapping("/udiwms/inout/biz/parseInvoice") public BaseResponse parseInvoice(String code) { List list = Arrays.asList(code.split(",")); FilterInvoiceRequest filterInvoiceRequest = new FilterInvoiceRequest(); filterInvoiceRequest.setType(list.get(1)); filterInvoiceRequest.setInvoiceCode(list.get(2)); filterInvoiceRequest.setInvoiceEncode(list.get(3)); filterInvoiceRequest.setPrice(new BigDecimal(list.get(4))); filterInvoiceRequest.setInvoiceDate(DateUtil.formatDateTime(DateUtil.parse(list.get(5), "yyyyMMdd"))); return ResultVOUtils.success(filterInvoiceRequest); } @PostMapping("/udiwms/inout/biz/updateorderBiz") public BaseResponse updateorderBiz(@RequestBody InvoiceRequest invoiceRequest) { String billNo = null; for (IoOrderDetailCodeEntity ioOrderDetailBizEntity : invoiceRequest.getList()) { ioOrderInvoiceService.updateRegStatus(ioOrderDetailBizEntity); billNo = ioOrderDetailBizEntity.getOrderIdFk(); } IoOrderEntity orderEntity = orderService.findByBillNo(billNo); orderEntity.setUpdateTime(new Date()); orderService.update(orderEntity); return ResultVOUtils.success("成功"); } /** * 查询单据业务详情列表 * * @param orderDetailBizRequest * @return */ @GetMapping("/udiwms/inout/bizDetail/filterBizOrderList") public BaseResponse filterBizOrderList(FilterOrderDetailCodeRequest orderDetailBizRequest) { List ioOrderDetailCodeResponses = orderDetailBizService.getfilterOrderList(orderDetailBizRequest); List orderInvoiceEntities = ioOrderInvoiceService.findByBillNo(orderDetailBizRequest.getOrderIdFk()); for (IoOrderDetailResultResponse orderDetailCodeEntity : ioOrderDetailCodeResponses) { if (orderDetailCodeEntity.getReCount() != 0 && orderDetailCodeEntity.getPrice() != null) { orderDetailCodeEntity.setAmount(new BigDecimal(orderDetailCodeEntity.getReCount()).multiply(orderDetailCodeEntity.getPrice())); } String msg = ""; for (IoOrderInvoiceEntity orderInvoiceEntity : orderInvoiceEntities) { if (StrUtil.trimToEmpty(orderInvoiceEntity.getBatchNo()).equals(StrUtil.trimToEmpty(orderDetailCodeEntity.getBatchNo())) && StrUtil.trimToEmpty(orderInvoiceEntity.getBindRlFk()).equals(StrUtil.trimToEmpty(orderDetailCodeEntity.getBindRlFk() + ""))) { orderDetailCodeEntity.setRegStatus(true); if (StrUtil.isNotEmpty(orderInvoiceEntity.getInvoiceEncode())) { msg += "," + orderInvoiceEntity.getInvoiceEncode(); } } } if (msg.length() > 1) { msg = msg.substring(1); } orderDetailCodeEntity.setInvoiceCodes(msg); } PageInfo pageInfo = new PageInfo<>(ioOrderDetailCodeResponses); return ResultVOUtils.page(pageInfo); } @Resource IoCodeTempService ioCodeTempService; @Resource AlihealthBusService alihealthBusService; @Resource UdiRelevanceDao udiRelevanceDao; @Resource IoCodeLostService ioCodeLostService; @Resource UdiCalCountUtil udiCalCountUtil; //录入阿里送货单的业务单据详情 @AuthRuleAnnotation("") @PostMapping("/udiwms/inout/order/addAliBizProduct") @Log(title = "单据管理", businessType = BusinessType.INSERT) @Transactional(rollbackFor = Exception.class) public BaseResponse addAliBizProduct(@RequestBody AddBizProductReqeust addBizProductReqeust) { //先获取阿里的行类 进行转换 AliYljgSearchbill aliData = addBizProductReqeust.getAliData(); if (aliData == null) { return ResultVOUtils.error("请先选择阿里的单据信息"); } String billCode = aliData.getBillCode(); String fromRefUserId = aliData.getFromRefUserId(); //去获取码明细 AliYljgSearchbillReqeust aliYljgSearchbillReqeust = new AliYljgSearchbillReqeust(); aliYljgSearchbillReqeust.setBillCode(billCode); aliYljgSearchbillReqeust.setFromRefUserId(fromRefUserId); AliYljgBillDetail aliYljgBillDetail = alihealthBusService.aliYljgBillDetail(aliYljgSearchbillReqeust); if (aliYljgBillDetail == null) { return ResultVOUtils.error("未找到单据信息!"); } List aliYljgBillDetailDrugList = aliYljgBillDetail.getAliYljgBillDetailDrugList(); if (CollUtil.isEmpty(aliYljgBillDetailDrugList)) { return ResultVOUtils.error("单据明细为空!"); } List tempDrug = aliYljgBillDetailDrugList.get(0).getAliYljgBillDetailDrugCodeList(); if (CollUtil.isEmpty(tempDrug)) { return ResultVOUtils.error("单据码明细为空!"); } IoOrderEntity ioOrderEntity = addBizProductReqeust.getOrderEntity(); addBizProductReqeust.setAliOrderBillNo(billCode); ioOrderEntity.setAliOrderBillNo(billCode); for (int i = 0; i < aliYljgBillDetailDrugList.size(); i++) { AliYljgBillDetailDrug aliYljgBillDetailDrug = aliYljgBillDetailDrugList.get(i); AliYljgBillDetailDrugCode aliYljgBillDetailDrugCode1 = aliYljgBillDetailDrug.getAliYljgBillDetailDrugCodeList().get(0); String code = aliYljgBillDetailDrugCode1.getCode(); if (StrUtil.isEmpty(code)) { return ResultVOUtils.error("单据码为空!"); } UdiEntity drugInfo = FilterUdiUtils.getDrugInfo(code); if (drugInfo == null) { return ResultVOUtils.error("单据码解析药品信息错误!"); } //获取药品信息 String nameCode = drugInfo.getUdi(); if (StrUtil.isEmpty(nameCode)) { return ResultVOUtils.error("单据码解析药品标识错误!"); } FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest(); filterUdiRelRequest.setNameCode(nameCode); List udiRelevanceResponses = udiRelevanceDao.filterUdiRelevance(filterUdiRelRequest); if (CollUtil.isEmpty(udiRelevanceResponses)) { return ResultVOUtils.error("未通过药品标识【"+aliYljgBillDetailDrug.getProdName()+nameCode+"】获取详情信息!"); } UdiRelevanceResponse udiRelevanceResponse = udiRelevanceResponses.get(0); List aliYljgBillDetailDrugCodeList1 = aliYljgBillDetailDrug.getAliYljgBillDetailDrugCodeList(); //1、直接模拟增加biz一行 addBizProductReqeust.setProductId(String.valueOf(udiRelevanceResponse.getProductId())); addBizProductReqeust.setRelId(udiRelevanceResponse.getRelId()); addBizProductReqeust.setZczbhhzbapzbh(udiRelevanceResponse.getZczbhhzbapzbh()); addBizProductReqeust.setSupId(udiRelevanceResponse.getSupId()); addBizProductReqeust.setDatas(null); addBizProductReqeust.setCount(aliYljgBillDetailDrugCodeList1.size() * udiCalCountUtil.getCirActCount(udiRelevanceResponse)); addBizProductReqeust.setBatchNo(aliYljgBillDetailDrug.getProduceBatchNo()); if (StrUtil.isNotEmpty(aliYljgBillDetailDrug.getProduceDate())) { addBizProductReqeust.setProductDate(aliYljgBillDetailDrug.getProduceDate().substring(2).replace(" 00:00:00", "").replace("-", "")); } if (StrUtil.isNotEmpty(aliYljgBillDetailDrug.getValidEndDate())) { addBizProductReqeust.setExpireDate(aliYljgBillDetailDrug.getValidEndDate().substring(2).replace(" 00:00:00", "").replace("-", "")); } if (i == 0) { addBizProductReqeust.setOrderEntity(ioOrderEntity); } addBizProductReqeust.setProductType(udiRelevanceResponse.getProductType()); BaseResponse response = orderDetailBizService.addBizProduct(addBizProductReqeust); if (response.getCode() != 20000) { return response; } if (i == 0) { ioOrderEntity = JSONObject.parseObject(JSONObject.toJSONString(response.getData()), IoOrderEntity.class); addBizProductReqeust.setOrderEntity(ioOrderEntity); } AddOrderRequest addOrderRequest = new AddOrderRequest(); BeanUtils.copyProperties(ioOrderEntity, addOrderRequest); for (int j = 0; j < aliYljgBillDetailDrugCodeList1.size(); j++) { AliYljgBillDetailDrugCode aliYljgBillDetailDrugCode = aliYljgBillDetailDrugCodeList1.get(j); addOrderRequest.setCode(aliYljgBillDetailDrugCode.getCode()); IoCodeLostEntity codeLostEntity = ioCodeLostService.findByCode(aliYljgBillDetailDrugCode.getCode()); if (codeLostEntity == null) { codeLostEntity = new IoCodeLostEntity(); codeLostEntity.setId(IdUtil.getSnowflakeNextId()); codeLostEntity.setNameCode(nameCode); codeLostEntity.setCode(aliYljgBillDetailDrugCode.getCode()); codeLostEntity.setBatchNo(aliYljgBillDetailDrug.getProduceBatchNo()); if (StrUtil.isNotEmpty(aliYljgBillDetailDrug.getProduceDate())) { codeLostEntity.setProduceDate(aliYljgBillDetailDrug.getProduceDate().substring(2).replace(" 00:00:00", "").replace("-", "")); } if (StrUtil.isNotEmpty(aliYljgBillDetailDrug.getValidEndDate())) { codeLostEntity.setExpireDate(aliYljgBillDetailDrug.getValidEndDate().substring(2).replace(" 00:00:00", "").replace("-", "")); } } else { codeLostEntity.setBatchNo(aliYljgBillDetailDrug.getProduceBatchNo()); if (StrUtil.isNotEmpty(aliYljgBillDetailDrug.getProduceDate())) { codeLostEntity.setProduceDate(aliYljgBillDetailDrug.getProduceDate().substring(2).replace(" 00:00:00", "").replace("-", "")); } if (StrUtil.isNotEmpty(aliYljgBillDetailDrug.getValidEndDate())) { codeLostEntity.setExpireDate(aliYljgBillDetailDrug.getValidEndDate().substring(2).replace(" 00:00:00", "").replace("-", "")); } Long id = codeLostEntity.getId(); if (id == null) codeLostEntity.setId(IdUtil.getSnowflakeNextId()); } ioCodeLostService.insertOrUpdate(codeLostEntity); BaseResponse response2 = ioCodeTempService.addDrugOrderWeb(addOrderRequest); if (response2.getCode() != 20000) { return response2; } } } return ResultVOUtils.success(ioOrderEntity); } }