From 1e2d55b9f92cebfc9909e83e09478c864fa11ca0 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期四, 09 一月 2025 11:47:13 +0800 Subject: [PATCH] bug修改 --- manage/src/main/java/com/jilongda/manage/controller/TOrderController.java | 145 +++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 131 insertions(+), 14 deletions(-) diff --git a/manage/src/main/java/com/jilongda/manage/controller/TOrderController.java b/manage/src/main/java/com/jilongda/manage/controller/TOrderController.java index 0f8c184..f17d8e8 100644 --- a/manage/src/main/java/com/jilongda/manage/controller/TOrderController.java +++ b/manage/src/main/java/com/jilongda/manage/controller/TOrderController.java @@ -13,6 +13,7 @@ import com.jilongda.manage.query.TOrderQuery; import com.jilongda.manage.service.*; import com.jilongda.manage.utils.LoginInfoUtil; +import com.jilongda.manage.utils.OssUploadUtil; import com.jilongda.manage.vo.TModelVO; import com.jilongda.manage.vo.TOptometryVO; import com.jilongda.manage.vo.TOrderListVO; @@ -24,8 +25,10 @@ import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -68,6 +71,32 @@ private TBrandService brandService; @Autowired private TOptometryService optometryService; + @Autowired + private TWarehousingService warehousingService; + @Autowired + private TLensWarehousingDetailService lensWarehousingDetailService; + @Autowired + private TFrameWarehousingDetailService frameWarehousingDetailService; + @Autowired + private TSupplierService supplierService; + @Autowired + private TMaterialService materialService; + + @PostMapping("/obs-upload") + @ApiOperation(value = "文件上传",tags = "管理后台-文件上传") + public ApiResult<String> uploadOSS(@RequestPart("file") MultipartFile file) { + try { + // 上传并返回访问地址 + String fileName = file.getOriginalFilename(); + String prefix = fileName.substring(fileName.lastIndexOf(".")); + long fileSize = file.getSize(); + String url = OssUploadUtil.ossUpload("eyes/",file); + return ApiResult.success(url); + } catch (Exception e) { + System.err.println("上传文件失败"+e); + return ApiResult.failed(e.getMessage()); + } + } @ApiOperation(value = "销售订单分页列表") @PostMapping(value = "/pageList") public ApiResult<PageInfo<TOrderListVO>> pageList(@RequestBody TOrderQuery query) { @@ -87,7 +116,7 @@ List<Integer> collect1 = orderGoodsService.lambdaQuery() .eq(StringUtils.hasLength(query.getBrandLens()), TOrderGoods::getBrandName, query.getBrandLens()) .eq(StringUtils.hasLength(query.getSeries()), TOrderGoods::getSeriesName, query.getSeries()) - .eq((query.getType() != null), TOrderGoods::getType, query.getType()) + .eq(query.getType() != null, TOrderGoods::getType, query.getType()) .eq(StringUtils.hasLength(query.getRefractiveIndex()), TOrderGoods::getRefractiveIndex, query.getRefractiveIndex()).list() .stream().map(TOrderGoods::getOrderId).collect(Collectors.toList()); if (StringUtils.hasLength(query.getBrandLens())||StringUtils.hasLength(query.getSeries())||query.getType() != null|| @@ -157,16 +186,14 @@ if(Objects.nonNull(user)){ dto.setStoreId(user.getStoreId()); } + if (dto.getUserId()!=null){ + TAppUser byId = tAppUserService.getById(dto.getUserId()); + dto.setName(byId.getName()); + dto.setPhone(byId.getPhone()); + } orderService.save(dto); - List<TOptometryDetail> optometryDetails = dto.getOptometryDetails(); - if (!CollectionUtils.isEmpty(optometryDetails)){ - for (TOptometryDetail optometryDetail : optometryDetails) { - optometryDetail.setOrderId(dto.getId()); - } - optometryDetailService.saveBatch(optometryDetails); - } List<TOrderGoods> orderGoods = dto.getOrderGoods(); List<TLensGoods> tLensGoods = new ArrayList<>(); @@ -175,14 +202,21 @@ orderGood.setOrderId(dto.getId()); if (StringUtils.hasLength(orderGood.getSeriesName())){ // 镜片 + orderGood.setRLens(orderGood.getRightLens()); + orderGood.setLLens(orderGood.getLeftLens()); String rLens = orderGood.getRLens(); - String[] split = rLens.split(","); + String[] split = null; + if(StringUtils.hasLength(rLens)){ + split = rLens.split(","); + }else { + split = orderGood.getLLens().split(","); + } TBrand one1 = brandService.lambdaQuery().eq(TBrand::getName, orderGood.getBrandName()) .eq(TBrand::getType, 2).one(); - TLensSeries one2 = lensSeriesService.lambdaQuery().eq(TLensSeries::getName, orderGood.getSeriesName()) + TLensSeries lensSeries = lensSeriesService.lambdaQuery().eq(TLensSeries::getName, orderGood.getSeriesName()) .eq(TLensSeries::getBrandId, one1.getId()).one(); TLensGoods one = lensGoodsService.lambdaQuery() - .eq(StringUtils.hasLength(orderGood.getSeriesName()),TLensGoods::getSeriesId, one2.getId()) + .eq(StringUtils.hasLength(orderGood.getSeriesName()),TLensGoods::getSeriesId, lensSeries.getId()) .eq(StringUtils.hasLength(orderGood.getRefractiveIndex()),TLensGoods::getRefractiveIndex, orderGood.getRefractiveIndex()) .eq(orderGood.getType()!=null,TLensGoods::getLensType, orderGood.getType()) .eq(split.length>0,TLensGoods::getBallMirror, split[0]) @@ -195,8 +229,41 @@ // 减少对应库存 one.setTotal(one.getTotal()-1); tLensGoods.add(one); + // 生成销售订单主表 + + TWarehousing tWarehousing = new TWarehousing(); + tWarehousing.setStatus(5); + tWarehousing.setType(2); + tWarehousing.setStoreId(dto.getStoreId()); + tWarehousing.setRemark("销售订单-镜片"); + tWarehousing.setOrderNum(dto.getId()+""); + warehousingService.save(tWarehousing); + // 生成明细记录 + TLensWarehousingDetail tLensWarehousingDetail = new TLensWarehousingDetail(); + tLensWarehousingDetail.setBrand(orderGood.getBrandName()); + TSupplier supplier = supplierService.getById(lensSeries.getSupplierId()); + if (supplier!=null){ + tLensWarehousingDetail.setSupplier(supplier.getName()); + } + tLensWarehousingDetail.setSeries(lensSeries.getName()); + tLensWarehousingDetail.setRefractiveIndex(orderGood.getRefractiveIndex()); + if (StringUtils.hasLength(orderGood.getLLens())){ + tLensWarehousingDetail.setBallMirror(orderGood.getLLens().split(",")[0]); + tLensWarehousingDetail.setColumnMirror(orderGood.getLLens().split(",")[0]); + } + if (StringUtils.hasLength(orderGood.getRLens())){ + tLensWarehousingDetail.setBallMirror(orderGood.getRLens().split(",")[0]); + tLensWarehousingDetail.setColumnMirror(orderGood.getRLens().split(",")[0]); + } + tLensWarehousingDetail.setType(orderGood.getType()); + tLensWarehousingDetail.setTotal(1); + tLensWarehousingDetail.setSeriesId(lensSeries.getId()); + tLensWarehousingDetail.setWarehousingId(tWarehousing.getId()); + tLensWarehousingDetail.setOrderId(dto.getId()); + lensWarehousingDetailService.save(tLensWarehousingDetail); + }else { - return ApiResult.failed("商品不存在"); + return ApiResult.failed("商品库存不足"); } }else{ TModel one1 = modelService.lambdaQuery().eq(TModel::getName, orderGood.getModelName()) @@ -213,15 +280,65 @@ // 增加对应库存 one.setTotal(one.getTotal()-1); tFrameGoods.add(one); + // 生成销售订单主表 + TWarehousing tWarehousing = new TWarehousing(); + tWarehousing.setStatus(5); + tWarehousing.setType(1); + tWarehousing.setStoreId(dto.getStoreId()); + tWarehousing.setRemark("销售订单-镜架"); + tWarehousing.setOrderNum(dto.getId()+""); + warehousingService.save(tWarehousing); + // 生成明细记录 + TBrand brand = brandService.getById(one1.getBrandId()); + + TFrameWarehousingDetail tFrameWarehousingDetail = new TFrameWarehousingDetail(); + tFrameWarehousingDetail.setWarehousingId(tWarehousing.getId()); + if (brand!=null){ + tFrameWarehousingDetail.setBrand(brand.getName()); + } + TSupplier supplier = supplierService.getById(one1.getSupplierId()); + if (supplier!=null){ + tFrameWarehousingDetail.setSupplier(supplier.getName()); + } + TMaterial material = materialService.getById(one1.getMaterialId()); + if (material!=null){ + tFrameWarehousingDetail.setMaterial(material.getName()); + } + tFrameWarehousingDetail.setTotal(1); + tFrameWarehousingDetail.setColor(orderGood.getColor()); + tFrameWarehousingDetail.setModel(one1.getName()); + tFrameWarehousingDetail.setModelId(one1.getId()); + tFrameWarehousingDetail.setOrderId(dto.getId()); + frameWarehousingDetailService.save(tFrameWarehousingDetail); + }else{ - return ApiResult.failed("商品不存在"); + return ApiResult.failed("商品库存不足"); } } + } + if (dto.getUserId()!=null){ + if (dto.getCouponId()!=null){ + List<TCouponReceive> couponReceives = couponReceiveService.lambdaQuery().eq(TCouponReceive::getUserId, dto.getUserId()) + .eq(TCouponReceive::getCouponId, dto.getCouponId()) + .orderByDesc(TCouponReceive::getCreateTime).list(); + if (couponReceives.isEmpty())return ApiResult.failed("优惠券不存在"); + TCouponReceive tCouponReceive = couponReceives.get(0); + tCouponReceive.setStatus(2); + tCouponReceive.setUseTime(LocalDateTime.now()); + couponReceiveService.updateById(tCouponReceive); + } + } + List<TOptometryDetail> optometryDetails = dto.getOptometryDetails(); + if (!CollectionUtils.isEmpty(optometryDetails)){ + for (TOptometryDetail optometryDetail : optometryDetails) { + optometryDetail.setOrderId(dto.getId()); + } + optometryDetailService.saveBatch(optometryDetails); } orderGoodsService.saveBatch(orderGoods); lensGoodsService.updateBatchById(tLensGoods); frameGoodsService.updateBatchById(tFrameGoods); - return ApiResult.success(); + return ApiResult.success(dto.getId()); } @ApiOperation(value = "销售订单详情") -- Gitblit v1.7.1