无关风月
2025-02-14 569961440c33e90f57770f77e2c61e83dcc32139
manage/src/main/java/com/jilongda/manage/controller/TOrderController.java
@@ -2,6 +2,10 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jilongda.common.Ticket.TAddOptometryVO;
import com.jilongda.common.Ticket.TOptometryDetailVO;
import com.jilongda.common.Ticket.TOrderGoodsPrintVO;
import com.jilongda.common.Ticket.TicketUtil;
import com.jilongda.common.basic.ApiResult;
import com.jilongda.common.basic.PageInfo;
import com.jilongda.manage.authority.model.SecUser;
@@ -14,12 +18,10 @@
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;
import com.jilongda.manage.vo.TOrderVO;
import com.jilongda.manage.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -28,6 +30,7 @@
import org.springframework.web.multipart.MultipartFile;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -178,7 +181,10 @@
        return ApiResult.success(tCouponReceives);
    }
    @Autowired
    private TTicketService tTicketService;
    @Autowired
    private TStoreService storeService;
    @ApiOperation(value = "添加订单")
    @PostMapping(value = "/addOrder")
    public ApiResult addOrder(@RequestBody TOrderDTO dto) {
@@ -210,13 +216,16 @@
                String[] split = null;
                if(StringUtils.hasLength(rLens)){
                    split = rLens.split(",");
                    if (split.length == 1){
                    }
                }else {
                    split = orderGood.getLLens().split(",");
                }
                TBrand one1 = brandService.lambdaQuery().eq(TBrand::getName, orderGood.getBrandName())
                TBrand brand = brandService.lambdaQuery().eq(TBrand::getName, orderGood.getBrandName())
                        .eq(TBrand::getType, 2).one();
                TLensSeries lensSeries = lensSeriesService.lambdaQuery().eq(TLensSeries::getName, orderGood.getSeriesName())
                        .eq(TLensSeries::getBrandId, one1.getId()).one();
                        .eq(TLensSeries::getBrandId, brand.getId()).one();
                TLensGoods one = lensGoodsService.lambdaQuery()
                        .eq(StringUtils.hasLength(orderGood.getSeriesName()),TLensGoods::getSeriesId, lensSeries.getId())
                        .eq(StringUtils.hasLength(orderGood.getRefractiveIndex()),TLensGoods::getRefractiveIndex, orderGood.getRefractiveIndex())
@@ -225,44 +234,44 @@
                        .eq(split.length>=2,TLensGoods::getColumnMirror, split[1])
                        .one();
                if (one!=null){
                    if (one.getTotal()-1<0){
                    if (one.getTotal()-1<0 && lensSeries.getType()==1 ){
                        return ApiResult.failed("库存不足");
                    }
                    // 减少对应库存
                    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);
                    // 生成销售订单主表
                    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("商品库存不足");
@@ -325,7 +334,7 @@
                    return ApiResult.failed("优惠券不存在");
                }
                List<TCouponReceive> couponReceives = couponReceiveService.lambdaQuery()
                        .eq(TCouponReceive::getId, dto.getUserId())
                        .eq(TCouponReceive::getUserId, dto.getUserId())
                        .eq(TCouponReceive::getCouponId, couponReceive.getCouponId())
                        .orderByDesc(TCouponReceive::getCreateTime).list();
                if (couponReceives.isEmpty())return ApiResult.failed("优惠券不存在");
@@ -366,6 +375,52 @@
        orderGoodsService.saveBatch(orderGoods);
        lensGoodsService.updateBatchById(tLensGoods);
        frameGoodsService.updateBatchById(tFrameGoods);
        TAddOptometryVO tAddOptometryVO = new TAddOptometryVO();
        TTicket tTicket = tTicketService.lambdaQuery().eq(TTicket::getStoreId, dto.getStoreId())
                .eq(TTicket::getType,1)
                .eq(TTicket::getStatus, 1).list().stream().findFirst().orElse(null);
        if (tTicket==null){
            return ApiResult.failed("当前门店未绑定小票机");
        }
        tAddOptometryVO.setSn(tTicket.getCloudId()+"");
        tAddOptometryVO.setPhone(dto.getPhone());
        List<TOrderGoods> orderGoods1 = dto.getOrderGoods();
        ArrayList<TOrderGoodsPrintVO> tOrderGoodsPrintVOS = new ArrayList<>();
        // 复制
        for (TOrderGoods orderGood : orderGoods1) {
            TOrderGoodsPrintVO tOrderGoodsPrintVO = new TOrderGoodsPrintVO();
            BeanUtils.copyProperties(orderGood,tOrderGoodsPrintVO);
            if (orderGood.getModelId()!=null){
                TModel byId = modelService.getById(orderGood.getModelId());
                if (byId!=null){
                    TMaterial byId1 = materialService.getById(byId.getMaterialId());
                    if (byId1!=null){
                        tOrderGoodsPrintVO.setMaterial(byId1.getName());
                    }
                }
            }
            tOrderGoodsPrintVOS.add(tOrderGoodsPrintVO);
        }
        tAddOptometryVO.setOrderGoods(tOrderGoodsPrintVOS);
        tAddOptometryVO.setRemark(dto.getRemark());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        tAddOptometryVO.setTime(format);
        tAddOptometryVO.setMachiningCode(dto.getMachiningCode());
        List<TOptometryDetailVO> tOptometryDetailVOS = new ArrayList<>();
        for (TOptometryDetail optometryDetail : dto.getOptometryDetails()) {
            TOptometryDetailVO tOptometryDetailVO = new TOptometryDetailVO();
            BeanUtils.copyProperties(optometryDetail,tOptometryDetailVO);
            tOptometryDetailVOS.add(tOptometryDetailVO);
        }
        tAddOptometryVO.setOptometryDetailVOS(tOptometryDetailVOS);
        tAddOptometryVO.setShopName(storeService.getById(dto.getStoreId()).getName());
        System.err.println("加工单数据");
        System.err.println(tAddOptometryVO);
        if (dto.getIsMachining()==1){
            // 打印加工单
            TicketUtil.printMatch(tAddOptometryVO);
        }
        return ApiResult.success(dto.getId());
    }