package com.hzs.sale.wares.controller.manage;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hzs.common.core.annotation.AccessPermissions;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.constant.EnumsPrefixConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.CreateNormsCodeUtils;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.sale.classify.BdSpecs;
import com.hzs.common.domain.sale.ext.BdWaresDetailExt;
import com.hzs.common.domain.sale.ext.BdWaresSpecsRelationExt;
import com.hzs.common.domain.sale.ext.BdWaresSpecsSkuExt;
import com.hzs.common.domain.sale.product.BdAreaClassify;
import com.hzs.common.domain.sale.product.BdProduct;
import com.hzs.common.domain.sale.product.BdProductExtend;
import com.hzs.common.domain.sale.wares.*;
import com.hzs.common.domain.system.config.ext.BdRangeExt;
import com.hzs.common.security.service.UserTokenService;
import com.hzs.common.security.utils.SecurityUtils;

import com.hzs.common.service.ITransactionCommonService;
import com.hzs.sale.product.service.IBdAreaClassifyService;
import com.hzs.sale.product.service.IBdProductExtendService;
import com.hzs.sale.product.service.IBdProductService;
import com.hzs.sale.product.service.IBdSpecsService;
import com.hzs.sale.wares.param.WaresDetailParams;
import com.hzs.sale.wares.param.*;
import com.hzs.sale.wares.service.*;
import com.hzs.sale.wares.vo.*;
import com.hzs.system.base.ICurrencyServiceApi;
import com.hzs.system.base.dto.CurrencyDTO;
import com.hzs.system.config.IRangeServiceApi;
import com.hzs.system.sys.dto.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author: yuhui
 * @Time: 2022/9/8 17:04
 * @Classname: BdWaresController
 * @PackageName: com.hzs.sale.wares.controller.manage
 */
@Slf4j
@RestController
@RequestMapping("/manage/wares")
public class BdWaresController extends BaseController {

    @DubboReference
    ICurrencyServiceApi currencyServiceApi;
    @DubboReference
    IRangeServiceApi rangeServiceApi;

    @Autowired
    private IBdWaresAuthorizeService waresAuthorizeService;
    @Autowired
    private IBdWaresAwardsService waresAwardsService;
    @Autowired
    private ITransactionCommonService iTransactionCommonService;
    @Autowired
    private IBdWaresGradeService waresGradeService;
    @Autowired
    private IBdProductExtendService productExtendService;
    @Autowired
    private IBdSpecsService specsService;
    @Autowired
    private IBdWaresRangeService waresRangeService;
    @Autowired
    private IBdProductService productService;
    @Autowired
    private IBdWaresSpecsPackService waresSpecsPackService;
    @Autowired
    private IBdWaresService waresService;
    @Autowired
    private IBdWaresLabelService waresLabelService;
    @Autowired
    private IBdWaresExtendService waresExtendService;
    @Autowired
    private IBdWaresDetailService waresDetailService;
    @Autowired
    private IBdWaresSpecsSkuService waresSpecsSkuService;
    @Autowired
    private IBdWaresSpecsRelationService waresSpecsRelationService;
    @Autowired
    private IBdWaresSpecsService waresSpecsService;
    @Autowired
    private IBdWaresAuthorityService waresAuthorityService;
    @Autowired
    private UserTokenService userTokenService;
    @Autowired
    private IBdAreaClassifyService areaClassifyService;

    /**
     * 查询列表
     *
     * @return
     */
    @AccessPermissions("GoodsList")
    @GetMapping("list")
    @Log(module = EOperationModule.WARES_LIST, business = EOperationBusiness.WARES_LIST, method = EOperationMethod.SELECT)
    public TableDataInfo list(WaresParams waresParams) {
        waresParams.setPkCountry(SecurityUtils.getPkCountry());
        waresParams.setSystemType(SecurityUtils.getSystemType());

        startPage();
        List<WaresVo> resultList = waresService.selectByWaresInfo(waresParams);
        if (CollectionUtil.isNotEmpty(resultList)) {
            R<CurrencyDTO> currencyDto = currencyServiceApi.getCurrency(SecurityUtils.getPkCountry());

            resultList.parallelStream().forEach(waresVo -> {
                WaresAuthorityVo waresAuthorityVo = waresService.getWaresAuthorityFirst(waresVo.getPkWares());
                if (waresAuthorityVo != null) {
                    waresVo.setAuthorityType(waresAuthorityVo.getAuthorityType());
                    waresVo.setAuthorityTypeVal(EWaresPermissionType.getEnumByValue(waresAuthorityVo.getAuthorityType()).getLabel());
                    waresVo.setMemberCode(waresAuthorityVo.getMemberCode());
                    waresVo.setMemberName(waresAuthorityVo.getMemberName());
                }
                List<WaresProductDetailVo> waresDetailList = waresDetailService.selectByList(waresVo.getPkWares());
                waresVo.setWaresDetailList(waresDetailList);
                if (waresVo.getIsMakerGift() != null) {
                    waresVo.setIsMakerGiftVal(EWaresType.getEnumByValue(waresVo.getIsMakerGift()).getLabel());
                }
                if (null != waresVo.getMakerIncome()) {
                    // 处理发起人收益
                    waresVo.setMakerIncome(waresVo.getMakerIncome().multiply(currencyDto.getData().getInExchangeRate()));
                }
            });
        }
        return getDataTable(resultList);
    }

    /**
     * 导出
     */
    @PostMapping("export")
    @Log(module = EOperationModule.WARES_LIST, business = EOperationBusiness.WARES_LIST, method = EOperationMethod.EXPORT)
    public void export(WaresParams waresParams, HttpServletResponse response) {
        waresParams.setPkCountry(SecurityUtils.getPkCountry());
        waresParams.setSystemType(SecurityUtils.getSystemType());

        List<WaresVo> resultList = waresService.selectByWaresInfo(waresParams);
        if (CollectionUtil.isNotEmpty(resultList)) {
            R<CurrencyDTO> currencyDto = currencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
            // 获取需要翻译的枚举翻译
            Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(ESpecialArea.values(), EYesNo.values(), ESupplyWay.values(), EPresaleStatus.values());

            resultList.parallelStream().forEach(waresVo -> {
                // 所属专区
                waresVo.setSpecialAreaVal(transactionMap.get(EnumsPrefixConstants.SPECIAL_AREA + waresVo.getSpecialArea()));
                // 供应方式
                waresVo.setOperateScopeVal(transactionMap.get(EnumsPrefixConstants.SUPPLY_WAY + waresVo.getOperateScope()));
                // 预售状态
                waresVo.setPreSaleStatusVal(transactionMap.get(EnumsPrefixConstants.PRESALE_STATUS + waresVo.getPreSaleStatus()));

                WaresAuthorityVo waresAuthorityVo = waresService.getWaresAuthorityFirst(waresVo.getPkWares());
                if (waresAuthorityVo != null) {
                    waresVo.setAuthorityType(waresAuthorityVo.getAuthorityType());
                    waresVo.setAuthorityTypeVal(EWaresPermissionType.getEnumByValue(waresAuthorityVo.getAuthorityType()).getLabel());
                    waresVo.setMemberCode(waresAuthorityVo.getMemberCode());
                    waresVo.setMemberName(waresAuthorityVo.getMemberName());
                }
                List<WaresProductDetailVo> waresDetailList = waresDetailService.selectByList(waresVo.getPkWares());
                waresVo.setWaresDetailList(waresDetailList);
                if (waresDetailList.size() > 0) {
                    StringBuilder productNames = new StringBuilder();
                    StringBuilder productCodes = new StringBuilder();
                    StringBuilder productQuantitys = new StringBuilder();
                    for (WaresProductDetailVo waresProductDetailVo : waresDetailList) {
                        productNames.append(waresProductDetailVo.getProductName()).append(",");
                        productCodes.append(waresProductDetailVo.getProductCode()).append(",");
                        productQuantitys.append(waresProductDetailVo.getProductQuantity()).append(",");
                    }
                    waresVo.setProductNames(productNames.toString());
                    waresVo.setProductCodes(productCodes.toString());
                    waresVo.setProductQuantitys(productQuantitys.toString());
                    if (waresVo.getIsMakerGift() != null) {
                        waresVo.setIsMakerGiftVal(EWaresType.getEnumByValue(waresVo.getIsMakerGift()).getLabel());
                    }
                }
                if (null != waresVo.getMakerIncome()) {
                    // 处理发起人收益
                    waresVo.setMakerIncome(waresVo.getMakerIncome().multiply(currencyDto.getData().getInExchangeRate()));
                }
            });
        }
        ExcelUtil<WaresVo> util = new ExcelUtil<>(WaresVo.class);
        util.exportExcel(response, resultList, "商品信息导出");
    }

    /**
     * 新增商品信息
     *
     * @return
     */
    @PostMapping("/save")
    @Log(module = EOperationModule.WARES_LIST, business = EOperationBusiness.WARES_LIST, method = EOperationMethod.INSERT)
    public AjaxResult save(@RequestBody WaresParams wares) {
        if (StringUtils.isBlank(wares.getWaresName())) {
            return AjaxResult.error("商品名称不存在");
        }
        // 预售状态必传
        if (wares.getPreSaleStatus() == null) {
            return AjaxResult.error("预售状态必传");
        }
        if (wares.getWaresPrice() == null) {
            return AjaxResult.error("商品价格必填");
        }
        if (StringUtils.isNotBlank(wares.getWaresCode())) {
            LambdaQueryWrapper<BdWares> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(BdWares::getWaresCode, wares.getWaresCode());
            queryWrapper.eq(BdWares::getSpecialArea, wares.getSpecialArea());
            if (waresService.count(queryWrapper) > 0) {
                return AjaxResult.error("商品编号重复");
            }
        }
        if (wares.getPkAreaClassify() == null) {
            return AjaxResult.error("商品分类不能为空");
        }
        if (wares.getCover1() == null) {
            return AjaxResult.error("商品图片必传");
        }
        // 是否陆运
        int isLandTrans = 1;
        // 是否空运
        int isAirTrans = 1;
        // 是否海运
        int isOceanTrans = 1;
        if (wares.getWaresDetailList().size() > 0) {
            for (WaresDetailParams waresDetailParams : wares.getWaresDetailList()) {
                BdProductExtend productExtend = productExtendService.getProductExtend(waresDetailParams.getPkProduct());
                // 是否陆运
                if (productExtend.getIsLandTrans() == EYesNo.YES.getIntValue()) {
                    isLandTrans = EYesNo.YES.getIntValue();
                }
                // 是否空运
                if (productExtend.getIsAirTrans() == EYesNo.YES.getIntValue()) {
                    isAirTrans = EYesNo.YES.getIntValue();
                }
                // 是否海运
                if (productExtend.getIsOceanTrans() == EYesNo.YES.getIntValue()) {
                    isOceanTrans = EYesNo.YES.getIntValue();
                }
            }
        }

        // 校验不免邮必须配置邮费默认
        if (EYesNo.NO.getIntValue() == wares.getIsFreeMail()) {
            if (wares.getIsLandTrans() == null && wares.getIsAirTrans() == null && wares.getIsOceanTrans() == null) {
                return AjaxResult.error("邮费模板必传");
            }
            // 校验是否可以陆运
            if (wares.getIsLandTrans() != null) {
                if (EYesNo.NO.getIntValue() == isLandTrans && EYesNo.YES.getIntValue() == wares.getIsLandTrans()) {
                    return AjaxResult.error("该商品无法使用陆运");
                }
            }
            // 校验是否可以空运
            if (wares.getIsAirTrans() != null) {
                if (EYesNo.NO.getIntValue() == isAirTrans && EYesNo.YES.getIntValue() == wares.getIsAirTrans()) {
                    return AjaxResult.error("该商品无法使用空运");
                }
            }
            // 校验是否可以海运
            if (wares.getIsOceanTrans() != null) {
                if (isOceanTrans == EYesNo.NO.getIntValue() && EYesNo.YES.getIntValue() == wares.getIsOceanTrans()) {
                    return AjaxResult.error("该商品无法使用海运");
                }
            }
            // 不免邮必须添加邮费模板
            if (wares.getIsLandTrans() != null && EYesNo.YES.getIntValue() == wares.getIsLandTrans()) {
                if (wares.getPkLandPostage() == null) {
                    return AjaxResult.error("邮费模板必传");
                }
            }
            // 是否空运
            if (wares.getIsAirTrans() != null && EYesNo.YES.getIntValue() == wares.getIsAirTrans()) {
                if (wares.getPkAirPostage() == null) {
                    return AjaxResult.error("邮费模板必传");
                }
            }
            // 是否海运
            if (wares.getIsOceanTrans() != null && EYesNo.YES.getIntValue() == wares.getIsOceanTrans()) {
                if (wares.getPkOceanPostage() == null) {
                    return AjaxResult.error("邮费模板必传");
                }
            }
        }
        if (wares.getSpecialArea() == ESpecialArea.REPURCHASE_AREA.getValue()) {
            if (wares.getWaresRangeList() == null || wares.getWaresRangeList().size() == 0) {
                return AjaxResult.error("极差明细不能为空");
            }
        }

        // 产品明细
        if (wares.getWaresDetailList() == null || wares.getWaresDetailList().size() == 0) {
            return AjaxResult.error("产品明细不能为空");
        }
        // 产品规格
        if (wares.getWaresSpecsSkuList() == null || wares.getWaresSpecsSkuList().size() == 0) {
            return AjaxResult.error("产品规格不能为空");
        }
        boolean isPutOn = false;
        for (WaresSpecsSkuParams waresSpecsSkuParams : wares.getWaresSpecsSkuList()) {
            if (waresSpecsSkuParams.getIsPutOn().equals(EYesNo.YES.getIntValue())) {
                isPutOn = true;
                break;
            }
        }
        if (!isPutOn) {
            return AjaxResult.error("产品规格至少有一个上架");
        }
//        wares.setSort(0);
        waresService.saveWares(wares, userTokenService.getLoginUser());
        return AjaxResult.success(wares.getWaresCode());
    }

    /**
     * 编辑商品信息
     *
     * @param waresParams
     * @return
     */
    @PostMapping("/update")
    @Log(module = EOperationModule.WARES_LIST, business = EOperationBusiness.WARES_LIST, method = EOperationMethod.UPDATE)
    public AjaxResult update(@RequestBody WaresParams waresParams) {
        waresParams.setPkCountry(SecurityUtils.getPkCountry());
        waresParams.setSystemType(SecurityUtils.getSystemType());
        if (StringUtils.isBlank(waresParams.getWaresCode())) {
            return AjaxResult.error("商品编号不存在");
        }
        // 预售状态必传
        if (waresParams.getPreSaleStatus() == null) {
            return AjaxResult.error("预售状态必传");
        }
        // 商品编号 重复
        if (StringUtils.isNotBlank(waresParams.getWaresCode())) {
            LambdaQueryWrapper<BdWares> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(BdWares::getWaresCode, waresParams.getWaresCode());
            queryWrapper.eq(BdWares::getSpecialArea, waresParams.getSpecialArea());
            queryWrapper.notIn(BdWares::getPkId, waresParams.getWaresId());
            if (waresService.count(queryWrapper) > 0) {
                return AjaxResult.error("商品编号重复");
            }
        }
        if (StringUtils.isBlank(waresParams.getWaresName())) {
            return AjaxResult.error("商品名称不存在");
        }
        if (waresParams.getWaresPrice() == null) {
            return AjaxResult.error("商品价格必填");
        }
        if (waresParams.getPkAreaClassify() == null) {
            return AjaxResult.error("商品分类不能为空");
        }
        if (waresParams.getCover1() == null) {
            return AjaxResult.error("商品图片必传");
        }

        // 是否陆运
        int isLandTrans = 1;
        // 是否空运
        int isAirTrans = 1;
        // 是否海运
        int isOceanTrans = 1;
        if (waresParams.getWaresDetailList().size() > 0) {
            for (WaresDetailParams waresDetailParams : waresParams.getWaresDetailList()) {
                BdProductExtend productExtend = productExtendService.getProductExtend(waresDetailParams.getPkProduct());
                // 是否陆运
                if (productExtend.getIsLandTrans() == EYesNo.YES.getIntValue()) {
                    isLandTrans = EYesNo.YES.getIntValue();
                }
                // 是否空运
                if (productExtend.getIsAirTrans() == EYesNo.YES.getIntValue()) {
                    isAirTrans = EYesNo.YES.getIntValue();
                }
                // 是否海运
                if (productExtend.getIsOceanTrans() == EYesNo.YES.getIntValue()) {
                    isOceanTrans = EYesNo.YES.getIntValue();
                }
            }
        }

        // 校验不免邮必须配置邮费默认
        if (EYesNo.NO.getIntValue() == waresParams.getIsFreeMail()) {
            if (waresParams.getIsLandTrans() == null && waresParams.getIsAirTrans() == null && waresParams.getIsOceanTrans() == null) {
                return AjaxResult.error("邮费模板必传");
            }
            // 校验是否可以陆运
            if (waresParams.getIsLandTrans() != null) {
                if (EYesNo.NO.getIntValue() == isLandTrans && EYesNo.YES.getIntValue() == waresParams.getIsLandTrans()) {
                    return AjaxResult.error("该商品无法使用陆运");
                }
            }
            // 校验是否可以空运
            if (waresParams.getIsAirTrans() != null) {
                if (EYesNo.NO.getIntValue() == isAirTrans && EYesNo.YES.getIntValue() == waresParams.getIsAirTrans()) {
                    return AjaxResult.error("该商品无法使用空运");
                }
            }
            // 校验是否可以海运
            if (waresParams.getIsOceanTrans() != null) {
                if (isOceanTrans == EYesNo.NO.getIntValue() && EYesNo.YES.getIntValue() == waresParams.getIsOceanTrans()) {
                    return AjaxResult.error("该商品无法使用海运");
                }
            }
            // 不免邮必须添加邮费模板
            if (waresParams.getIsLandTrans() != null && EYesNo.YES.getIntValue() == waresParams.getIsLandTrans()) {
                if (waresParams.getPkLandPostage() == null) {
                    return AjaxResult.error("邮费模板必传");
                }
            }
            // 是否空运
            if (waresParams.getIsAirTrans() != null && EYesNo.YES.getIntValue() == waresParams.getIsAirTrans()) {
                if (waresParams.getPkAirPostage() == null) {
                    return AjaxResult.error("邮费模板必传");
                }
            }
            // 是否海运
            if (waresParams.getIsOceanTrans() != null && EYesNo.YES.getIntValue() == waresParams.getIsOceanTrans()) {
                if (waresParams.getPkOceanPostage() == null) {
                    return AjaxResult.error("邮费模板必传");
                }
            }
        }
        if (waresParams.getSpecialArea() == ESpecialArea.REPURCHASE_AREA.getValue()) {
            if (waresParams.getWaresRangeList() == null || waresParams.getWaresRangeList().size() == 0) {
                return AjaxResult.error("极差明细不能为空");
            }
        }
        // 产品明细
        if (waresParams.getWaresDetailList() == null || waresParams.getWaresDetailList().size() == 0) {
            return AjaxResult.error("产品明细不能为空");
        }
        // 产品规格
        if (waresParams.getWaresSpecsSkuList() == null || waresParams.getWaresSpecsSkuList().size() == 0) {
            return AjaxResult.error("产品规格不能为空");
        }
        for (WaresSpecsSkuParams waresSpecsSkuParams : waresParams.getWaresSpecsSkuList()) {
            if (StringUtils.isBlank(waresSpecsSkuParams.getSpecCover())) {
                return AjaxResult.error("规格图片必传");
            }
        }

//        waresParams.setSort(0);
        waresService.updateWares(waresParams, userTokenService.getLoginUser());
        return AjaxResult.success(waresParams.getWaresCode());
    }

    /**
     * 删除商品
     *
     * @param pkId
     * @return
     */
    @DeleteMapping("/{pkId}")
    @Log(module = EOperationModule.WARES_LIST, business = EOperationBusiness.THIRD_WARES_LIST, method = EOperationMethod.DELETE)
    public AjaxResult remove(@PathVariable Integer pkId) {
        waresService.removeWares(pkId, userTokenService.getLoginUser());
        return AjaxResult.success();
    }

    /**
     * 查询商品详情
     *
     * @param pkId
     * @return
     */
    @GetMapping("/detail")
    public AjaxResult detail(Long pkId) {
        R<List<BdRangeExt>> rangeDto = rangeServiceApi.queryRange(SecurityUtils.getPkCountry());
        List<BdRangeExt> rsList = rangeDto.getData();
        Map<Integer, BdRangeExt> rangeMap = rsList.stream().collect(Collectors.toMap(BdRangeExt::getPkId, Function.identity()));

        BdWares wares = waresService.getById(pkId);
        LambdaQueryWrapper<BdWaresExtend> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BdWaresExtend::getPkWares, pkId);
        BdWaresExtend waresExtend = waresExtendService.getOne(queryWrapper);
        WaresParams waresParams = new WaresParams();
        waresParams.setWaresId(wares.getPkId());
        waresParams.setIsPreSale(wares.getIsPreSale());
        waresParams.setPreSaleQuantity(wares.getPreSaleQuantity());
        waresParams.setWaresCode(wares.getWaresCode());
        waresParams.setWaresName(wares.getWaresName());
        waresParams.setWaresPrice(wares.getWaresPrice());
        waresParams.setWaresAchieve(wares.getWaresAchieve());
        waresParams.setPkAreaClassify(wares.getPkAreaClassify());
        waresParams.setCover(wares.getCover());
        waresParams.setVideoUrl(wares.getVideoUrl());
        waresParams.setCover1(wares.getCover1());
        waresParams.setCover2(wares.getCover2());
        waresParams.setCover3(wares.getCover3());
        waresParams.setCover4(wares.getCover4());
        waresParams.setCover5(wares.getCover5());
        waresParams.setCover6(wares.getCover6());
        waresParams.setDetails(wares.getDetails());
        waresParams.setSort(wares.getSort());
        waresParams.setSpecialArea(wares.getSpecialArea());
        waresParams.setIsSingle(wares.getIsSingle());
        waresParams.setDetails(wares.getDetails());
        waresParams.setIsPutOn(waresExtend.getIsPutOn());
        waresParams.setPreSaleStatus(waresExtend.getPreSaleStatus());
        waresParams.setPutOnTime(waresExtend.getPutOnTime());
        waresParams.setPutOffTime(waresExtend.getPutOffTime());
        waresParams.setOperateScope(waresExtend.getOperateScope());
        waresParams.setPrefixLabel(waresExtend.getPrefixLabel());
        waresParams.setCoolLabel(waresExtend.getCoolLabel());
        waresParams.setSLabel(waresExtend.getSLabel());
        waresParams.setIsFreeMail(wares.getIsFreeMail());
        waresParams.setSales(waresExtend.getSales());
        waresParams.setIsSale(waresExtend.getIsSale());
        waresParams.setPkAgreement(waresExtend.getPkAgreement());
        waresParams.setArrivalTime(waresExtend.getArrivalTime());
        waresParams.setWarnMessage(waresExtend.getWarnMessage());
        waresParams.setSellingPoints(waresExtend.getSellingPoints());
        waresParams.setIsOceanTrans(waresExtend.getIsOceanTrans());
        waresParams.setPkOceanPostage(waresExtend.getPkOceanPostage());
        waresParams.setIsLandTrans(waresExtend.getIsLandTrans());
        waresParams.setPkLandPostage(waresExtend.getPkLandPostage());
        waresParams.setIsAirTrans(waresExtend.getIsAirTrans());
        waresParams.setPkAirPostage(waresExtend.getPkAirPostage());
        waresParams.setAfterGuarantee(wares.getAfterGuarantee());
        waresParams.setIsRecommend(wares.getIsRecommend());
        waresParams.setIsMakerGift(waresExtend.getIsMakerGift());
        waresParams.setPkSpecialCurrency(waresExtend.getPkSpecialCurrency());
        waresParams.setSortStatus(wares.getSortStatus());
        waresParams.setSystemType(waresExtend.getSystemType());
        waresParams.setAreaIncome(wares.getAreaIncome());
        if (waresExtend.getMakerIncome() != null) {
            R<CurrencyDTO> currencyDto = currencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
            waresParams.setMakerIncome(waresExtend.getMakerIncome().multiply(currencyDto.getData().getInExchangeRate()));
        }

        BdAreaClassify parentAreaClassify = areaClassifyService.getAreaClassify(wares.getPkAreaClassify());
        if (parentAreaClassify != null) {
            if (parentAreaClassify.getPkParent() == 0) {
                waresParams.setParentPkAreaClassify(null);
            } else {
                waresParams.setParentPkAreaClassify(parentAreaClassify.getPkParent().intValue());
            }
        }
        // 标签
        LambdaQueryWrapper<BdWaresLabel> waresLabelWrapper = new LambdaQueryWrapper<>();
        waresLabelWrapper.eq(BdWaresLabel::getPkWares, pkId);
        List<BdWaresLabel> labelList = waresLabelService.list(waresLabelWrapper);
        // 保证标签
        List<Integer> pkGuaranteeLabel = new ArrayList<>();
        // 卖点标签
        List<Integer> pkSellingPoint = new ArrayList<>();
        for (BdWaresLabel bdWaresLabel : labelList) {
            // 前缀标签
            if (bdWaresLabel.getLabelType() == ELabelType.PREFIX.getValue()) {
                waresParams.setPkPrefixLabel(bdWaresLabel.getPkLable());
            }
            // 酷炫标签
            if (bdWaresLabel.getLabelType() == ELabelType.COOL.getValue()) {
                waresParams.setPkCoolLabel(bdWaresLabel.getPkLable());
            }
            // 保证标签
            if (bdWaresLabel.getLabelType() == ELabelType.ENSURE.getValue()) {
                pkGuaranteeLabel.add(bdWaresLabel.getPkLable());
            }
            // 卖点标签
            if (bdWaresLabel.getLabelType() == ELabelType.SELLING.getValue()) {
                pkSellingPoint.add(bdWaresLabel.getPkLable());
            }
        }
        waresParams.setPkGuaranteeLabel(pkGuaranteeLabel);
        waresParams.setPkSellingPoint(pkSellingPoint);

        //包装和规格
        LambdaQueryWrapper<BdWaresSpecsPack> waresSpecsPackWrapper = new LambdaQueryWrapper<>();
        waresSpecsPackWrapper.eq(BdWaresSpecsPack::getPkWares, pkId);
        List<BdWaresSpecsPack> list = waresSpecsPackService.list(waresSpecsPackWrapper);
        List<WaresSpecsPackParams> waresSpecsPackList = new ArrayList<>();
        for (BdWaresSpecsPack bdWaresSpecsPack : list) {
            WaresSpecsPackParams waresSpecsPackParams = BeanUtil.copyProperties(bdWaresSpecsPack, WaresSpecsPackParams.class);
            waresSpecsPackList.add(waresSpecsPackParams);
        }
        waresParams.setWaresSpecsPackList(waresSpecsPackList);

        //产品详情列表
        LambdaQueryWrapper<BdWaresDetail> waresDetailWrapper = new LambdaQueryWrapper<>();
        waresDetailWrapper.eq(BdWaresDetail::getPkWares, pkId);
        List<BdWaresDetail> waresDetailList = waresDetailService.list(waresDetailWrapper);
        // 商品详情
        List<WaresDetailParams> detailList = new ArrayList<>();
        // 商品sku
        List<WaresSpecsSkuParams> waresSpecsSkuList = new ArrayList<>();
        for (BdWaresDetail bd : waresDetailList) {
            WaresDetailParams waresDetailParams = BeanUtil.copyProperties(bd, WaresDetailParams.class);
            BdProduct product = productService.getProduct(bd.getPkProduct());
            if (product != null) {
                waresDetailParams.setProductCode(product.getProductCode());
                waresDetailParams.setProductName(product.getProductName());
                waresDetailParams.setCover(product.getCover());
            }
            detailList.add(waresDetailParams);

            // 拼装查询每个产品详情的规格
            LambdaQueryWrapper<BdWaresSpecsSku> specsSku = new LambdaQueryWrapper<>();
            specsSku.eq(BdWaresSpecsSku::getPkWares, pkId);
            specsSku.eq(BdWaresSpecsSku::getPkWaresDetail, bd.getPkId());
            List<BdWaresSpecsSku> specsSkuList = waresSpecsSkuService.list(specsSku);
            for (BdWaresSpecsSku bdWaresSpecsSku : specsSkuList) {
                WaresSpecsSkuParams specsSkuParams = new WaresSpecsSkuParams();
                specsSkuParams.setPkWaresSpecsSku(bdWaresSpecsSku.getPkId());
                specsSkuParams.setIsGift(bd.getIsGift());
                specsSkuParams.setPkProduct(bd.getPkProduct());
                specsSkuParams.setAssAchieve(bdWaresSpecsSku.getAssAchieve());
                specsSkuParams.setProductPrice(bdWaresSpecsSku.getPrice());
                specsSkuParams.setProductAchieve(bdWaresSpecsSku.getAchieve());
                specsSkuParams.setSpecCover(bdWaresSpecsSku.getSpecCover());
                specsSkuParams.setIsPutOn(bdWaresSpecsSku.getIsPutOn());
                specsSkuParams.setVipPrice(bdWaresSpecsSku.getVipPrice());
                specsSkuParams.setRetailPrice(bdWaresSpecsSku.getRetailPrice());
                // 每个规格的sku键值对
                List<BdWaresSpecs> waresSpecsList = new ArrayList<>();
                LambdaQueryWrapper<BdWaresSpecsRelation> waresSpecsRelation = new LambdaQueryWrapper<>();
                waresSpecsRelation.eq(BdWaresSpecsRelation::getPkWaresSpecsSku, bdWaresSpecsSku.getPkId());
                List<BdWaresSpecsRelation> rslist = waresSpecsRelationService.list(waresSpecsRelation);
                for (BdWaresSpecsRelation bdWaresSpecsRelation : rslist) {
                    BdWaresSpecs waresSpecs = waresSpecsService.getById(bdWaresSpecsRelation.getPkWaresSpecs());
                    BdSpecs specs = specsService.getSpecs(waresSpecs.getPkSpecs());
                    if (specs != null) {
                        waresSpecs.setSpecsName(specs.getSpecsName());
                    }
                    waresSpecsList.add(waresSpecs);
                }
                specsSkuParams.setWaresSpecsList(waresSpecsList);
                waresSpecsSkuList.add(specsSkuParams);
            }
        }
        waresParams.setWaresDetailList(detailList);
        waresParams.setWaresSpecsSkuList(waresSpecsSkuList);
        // 团队配置
        LambdaQueryWrapper<BdWaresAuthority> authorityWrapper = new LambdaQueryWrapper<>();
        authorityWrapper.eq(BdWaresAuthority::getPkWares, pkId);
        List<BdWaresAuthority> authList = waresAuthorityService.list(authorityWrapper);
        List<WaresAuthorityParam> waresAuthorityList = new ArrayList<>();
        for (BdWaresAuthority bdWaresAuthority : authList) {
            WaresAuthorityParam waresAuthorityParam = BeanUtil.copyProperties(bdWaresAuthority, WaresAuthorityParam.class);
            waresAuthorityList.add(waresAuthorityParam);
        }
        waresParams.setWaresAuthorityList(waresAuthorityList);
        // 极差
        List<WaresRangeParams> waresRangeList = new ArrayList<>();
        List<BdWaresRange> rangeList = waresRangeService.queryWaresList(pkId, SecurityUtils.getPkCountry());
        LambdaQueryWrapper<BdWaresRange> waresRangeWrapper = new LambdaQueryWrapper<>();
        waresRangeWrapper.eq(BdWaresRange::getPkWares, pkId);
        int waresRangeCount = waresRangeService.count(waresRangeWrapper);
        List<Integer> rgList = new ArrayList<>();
        for (BdWaresRange bdWaresRange : rangeList) {
            if (bdWaresRange.getPkId() != null) {
                if (bdWaresRange.getPkWaresSpecsSku() != null) {
                    WaresRangeParams waresRangeParams = BeanUtil.copyProperties(bdWaresRange, WaresRangeParams.class);
                    waresRangeParams.setIsGift(bdWaresRange.getIsGift());
                    // 查询每一个sku 的所有规格
                    List<BdWaresSpecs> waresSpecsList = new ArrayList<>();
                    LambdaQueryWrapper<BdWaresSpecsRelation> waresSpecsRelation = new LambdaQueryWrapper<>();
                    waresSpecsRelation.eq(BdWaresSpecsRelation::getPkWaresSpecsSku, bdWaresRange.getPkWaresSpecsSku());
                    List<BdWaresSpecsRelation> rslist = waresSpecsRelationService.list(waresSpecsRelation);
                    for (BdWaresSpecsRelation bdWaresSpecsRelation : rslist) {
                        BdWaresSpecs waresSpecs = waresSpecsService.getById(bdWaresSpecsRelation.getPkWaresSpecs());
                        BdSpecs specs = specsService.getSpecs(waresSpecs.getPkSpecs());
                        if (specs != null) {
                            waresSpecs.setSpecsName(specs.getSpecsName());
                        }
                        waresSpecsList.add(waresSpecs);
                    }
                    waresRangeParams.setWaresSpecsList(waresSpecsList);
                    // 冗余
                    if (rangeMap.get(bdWaresRange.getPkRange()) != null) {
                        waresRangeParams.setRangeName(rangeMap.get(bdWaresRange.getPkRange()).getRangeName());
                    } else {
                        waresRangeParams.setRangeName(null);
                    }
                    BdProduct product = productService.getProduct(bdWaresRange.getPkProduct());
                    waresRangeParams.setProductCode(product.getProductCode());
                    waresRangeParams.setProductName(product.getProductName());
                    waresRangeParams.setProductCover(product.getCover());
                    List<String> specsNames = waresSpecsList.stream().map(BdWaresSpecs::getSpecsName).collect(Collectors.toList());
                    waresRangeParams.setSpecsNames(StringUtils.join(specsNames, ","));
                    waresRangeList.add(waresRangeParams);
                }
            } else {
                if (waresRangeCount > 0) {
                    rgList.add(bdWaresRange.getPkRange());
                }
            }
        }
        if (rgList.size() > 0) {
            // 查询不存在的极差等级 (部分极差等级可能是后期添加导致商品和极差关联表不存在该极差信息)
            for (Integer rg : rgList) {
                for (BdWaresDetail bdWaresDetail : waresDetailList) {
                    WaresRangeParams waresRangeParams = new WaresRangeParams();
                    waresRangeParams.setPkRange(rg);
                    BdProduct product = productService.getProduct(bdWaresDetail.getPkProduct());
                    waresRangeParams.setPkProduct(product.getPkId());
                    waresRangeParams.setProductCode(product.getProductCode());
                    waresRangeParams.setProductName(product.getProductName());
                    waresRangeParams.setProductCover(product.getCover());
                    // 冗余
                    if (rangeMap.get(rg) != null) {
                        waresRangeParams.setRangeName(rangeMap.get(rg).getRangeName());
                    } else {
                        waresRangeParams.setRangeName(null);
                    }
                    LambdaQueryWrapper<BdWaresRange> qe = new LambdaQueryWrapper<>();
                    qe.eq(BdWaresRange::getPkWares, bdWaresDetail.getPkWares());
                    qe.eq(BdWaresRange::getPkWaresDetail, bdWaresDetail.getPkId());
                    List<BdWaresRange> wrList = waresRangeService.list(qe);
                    // 查询每一个sku 的所有规格
                    List<BdWaresSpecs> waresSpecsList = new ArrayList<>();
                    for (BdWaresRange bdWaresRange : wrList) {
                        LambdaQueryWrapper<BdWaresSpecsRelation> waresSpecsRelation = new LambdaQueryWrapper<>();
                        waresSpecsRelation.eq(BdWaresSpecsRelation::getPkWaresSpecsSku, bdWaresRange.getPkWaresSpecsSku());
                        List<BdWaresSpecsRelation> rslist = waresSpecsRelationService.list(waresSpecsRelation);
                        for (BdWaresSpecsRelation bdWaresSpecsRelation : rslist) {
                            BdWaresSpecs waresSpecs = waresSpecsService.getById(bdWaresSpecsRelation.getPkWaresSpecs());
                            BdSpecs specs = specsService.getSpecs(waresSpecs.getPkSpecs());
                            if (specs != null) {
                                waresSpecs.setSpecsName(specs.getSpecsName());
                            }
                            waresSpecsList.add(waresSpecs);

                        }
                    }

                    waresRangeParams.setWaresSpecsList(waresSpecsList);
                    List<String> specsNames = waresSpecsList.stream().map(BdWaresSpecs::getSpecsName).collect(Collectors.toList());
                    waresRangeParams.setSpecsNames(StringUtils.join(specsNames.get(0), ","));
                    waresRangeList.add(waresRangeParams);
                }
            }
        }
        waresParams.setWaresRangeList(waresRangeList);

        // 查询商品级别
        LambdaQueryWrapper<BdWaresGrade> qw = new LambdaQueryWrapper<>();
        qw.eq(BdWaresGrade::getPkWares, pkId);
        List<BdWaresGrade> waresGradeIds = waresGradeService.list(qw);
        List<Integer> ids = waresGradeIds.stream().map(BdWaresGrade::getPkRange).collect(Collectors.toList());
        waresParams.setWaresGradeIds(ids);
        // 查询商品奖衔
        LambdaQueryWrapper<BdWaresAwards> qe = new LambdaQueryWrapper<>();
        qe.eq(BdWaresAwards::getPkWares, pkId);
        List<BdWaresAwards> waresAwardsIds = waresAwardsService.list(qe);
        List<Integer> waresAwardsArray = waresAwardsIds.stream().map(BdWaresAwards::getPkAwards).collect(Collectors.toList());
        waresParams.setWaresAwardsIds(waresAwardsArray);
        // 查询商品权限配置
        LambdaQueryWrapper<BdWaresAuthorize> qa = new LambdaQueryWrapper<>();
        qa.eq(BdWaresAuthorize::getPkWares, pkId);
        List<BdWaresAuthorize> waresAuthoritys = waresAuthorizeService.list(qa);
        List<Integer> waresAuthorizeList = waresAuthoritys.stream().map(BdWaresAuthorize::getValue).collect(Collectors.toList());
        waresParams.setWaresMemberAuthorizeList(waresAuthorizeList);
        return AjaxResult.success(waresParams);
    }

    /**
     * 商品移动（上移/下移）
     *
     * @param waresId       产品id
     * @param waresMoveType 商品移动类型 0 上移 1 下移
     * @return
     */
    @GetMapping("/move")
    @Log(module = EOperationModule.WARES_LIST, business = EOperationBusiness.THIRD_WARES_LIST, method = EOperationMethod.UP_MOVE)
    public AjaxResult move(Integer waresId, Integer waresMoveType, Integer specialArea) {
        LoginUser loginUser = userTokenService.getLoginUser();
        waresService.waresMove(waresId, waresMoveType, loginUser, specialArea);
        return AjaxResult.success();

    }

    /**
     * 置顶
     *
     * @param waresId
     * @return
     */
    @GetMapping("/floating-roof")
    @Log(module = EOperationModule.WARES_LIST, business = EOperationBusiness.THIRD_WARES_LIST, method = EOperationMethod.TOP)
    public AjaxResult floatingRoof(Integer waresId) {
        LoginUser loginUser = userTokenService.getLoginUser();
        waresService.floatingRoof(waresId, loginUser);
        return AjaxResult.success();
    }

    /**
     * 置底
     *
     * @return
     */
    @GetMapping("/botton-up")
    public AjaxResult bottomUp(Integer waresId) {
        LoginUser loginUser = userTokenService.getLoginUser();
        waresService.bottomUp(waresId, loginUser);
        return AjaxResult.success();
    }

    /**
     * 创建商品编号
     *
     * @return
     */
    @GetMapping("/create-wares-code")
    public AjaxResult createWaresCode() {
        String waresCode = CreateNormsCodeUtils.createWaresCode(waresService.getLastWaresCode());
        return AjaxResult.success(waresCode);
    }
    @GetMapping("/getMaxSortNum")
    public AjaxResult getMaxSortNum() {
        return AjaxResult.success("请求成功!", iBdWaresService.getMaxSortNum());
    }

    /**
     * 商品序号创建
     *
     * @return
     */
    @GetMapping("/create-wares-sort")
    public AjaxResult createWaresSort() {
        Integer pkCountry = SecurityUtils.getPkCountry();
        Integer maxSort = waresService.getMaxSort(pkCountry);
        if (maxSort == null) {
            maxSort = 0;
        }
        return AjaxResult.success(maxSort + 1);
    }

    /**
     * 查询商品
     */
    @GetMapping("/get-wares-list")
    public AjaxResult getWares(String waresName) {
        LambdaQueryWrapper<BdWares> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(waresName)) {
            queryWrapper.eq(BdWares::getWaresName, waresName);
        }
        queryWrapper.eq(BdWares::getPkCountry, SecurityUtils.getPkCountry());
        List<BdWares> list = waresService.list(queryWrapper);
        List<WaresEntnyOrderVo> resultList = new ArrayList<>();
        for (BdWares bdWares : list) {
            WaresEntnyOrderVo waresEntnyOrderVo = new WaresEntnyOrderVo();
            waresEntnyOrderVo.setWaresName(bdWares.getWaresName());
            waresEntnyOrderVo.setWaresImg(bdWares.getCover1());
            waresEntnyOrderVo.setPkWares(bdWares.getPkId());
            waresEntnyOrderVo.setWaresCode(bdWares.getWaresCode());
            waresEntnyOrderVo.setWaresPrice(bdWares.getWaresPrice());
            waresEntnyOrderVo.setWaresAchieve(bdWares.getWaresAchieve());

            List<BdWaresDetailExt> waresDetailList = waresDetailService.selectByPkWares(bdWares.getPkId());
            List<ProductEntnyOrderVo> productEntnyOrderList = new ArrayList<>();
            for (BdWaresDetailExt bdWaresDetail : waresDetailList) {
                ProductEntnyOrderVo productEntnyOrderVo = new ProductEntnyOrderVo();
                productEntnyOrderVo.setPkProduct(bdWaresDetail.getPkProduct());
                productEntnyOrderVo.setQuantity(bdWaresDetail.getQuantity());
                productEntnyOrderVo.setProductName(bdWaresDetail.getProductName());
                LambdaQueryWrapper<BdWaresSpecsSku> qw = new LambdaQueryWrapper<>();
                qw.eq(BdWaresSpecsSku::getPkWaresDetail, bdWaresDetail.getPkId());
                List<BdWaresSpecsSku> waresSpecsSkuList = waresSpecsSkuService.list(qw);
                List<WaresSpecsEntnyOrterVo> waresSpecsEntnyOrterVoList = new ArrayList<>();
                for (BdWaresSpecsSku bdWaresSpecsSku : waresSpecsSkuList) {
                    WaresSpecsEntnyOrterVo waresSpecsEntnyOrterVo = new WaresSpecsEntnyOrterVo();

                    List<BdWaresSpecsRelationExt> waresSpecsRelation = waresSpecsRelationService.selectByWaresSpecsSku(bdWaresSpecsSku.getPkId());
                    List<String> specsList = new ArrayList<>();
                    List<Integer> specsIds = new ArrayList<>();
                    for (BdWaresSpecsRelationExt bdWaresSpecsRelation : waresSpecsRelation) {
                        specsList.add(bdWaresSpecsRelation.getSpecsName());
                        specsIds.add(bdWaresSpecsRelation.getPkSpecs());
                    }
                    waresSpecsEntnyOrterVo.setPkWaresSpecsSku(bdWaresSpecsSku.getPkId());
                    waresSpecsEntnyOrterVo.setSpecsName(StringUtils.join(specsList, ","));
                    waresSpecsEntnyOrterVo.setSpecsIds(StringUtils.join(specsIds, ","));
                    waresSpecsEntnyOrterVoList.add(waresSpecsEntnyOrterVo);
                }
                productEntnyOrderVo.setWaresSpecsEntnyOrterVo(waresSpecsEntnyOrterVoList);
                productEntnyOrderList.add(productEntnyOrderVo);
            }
            waresEntnyOrderVo.setProductEntnyOrderVoList(productEntnyOrderList);
            resultList.add(waresEntnyOrderVo);
        }
        return AjaxResult.success(resultList);
    }

    /**
     * 空单注册 商品展示
     *
     * @return
     */
    @PostMapping("/get-empty-order-wares")
    public AjaxResult getEmptyOrderWares(@RequestBody EmptyOrderWares emptyOrderWares) {
        List<EmptyOrderWares> resultList = new ArrayList<>();
        for (int i = 0; i < emptyOrderWares.getPkWaresSpecsSkus().size(); i++) {
            BdWaresSpecsSkuExt ws = waresSpecsSkuService.selectByPkWaresSpecsSku(emptyOrderWares.getPkWaresSpecsSkus().get(i).getPkWaresSpecsSku());
            EmptyOrderWares eo = new EmptyOrderWares();
            eo.setSort(i + 1);
            eo.setPkWares(ws.getPkWares());
            eo.setPkWaresSpecsSku(ws.getPkId());
            eo.setPkProduct(ws.getPkProduct());
            eo.setCover(ws.getCover1());
            eo.setWaresName(ws.getWaresName());
            eo.setWaresCode(ws.getWaresCode());
            eo.setWaresPv(ws.getAchieve());
            eo.setQuantity(emptyOrderWares.getPkWaresSpecsSkus().get(i).getQuantity());
            eo.setWaresPrice(ws.getWaresPrice());
            eo.setAmountPrice(eo.getWaresPrice().multiply(new BigDecimal(eo.getQuantity())));
            eo.setSpecialArea(ws.getSpecialArea());
            eo.setSpecialAreaStr(ESpecialArea.getESpecialArea(ws.getSpecialArea()));
            eo.setIsSingle(ws.getIsSingle());
            eo.setProductName(ws.getProductName());
            LambdaQueryWrapper<BdWaresSpecsRelation> qer = new LambdaQueryWrapper<>();
            qer.eq(BdWaresSpecsRelation::getPkWaresSpecsSku, ws.getPkId());
            List<BdWaresSpecsRelation> waresSpecsRelation = waresSpecsRelationService.list(qer);
            List<String> specsList = new ArrayList<>();
            for (BdWaresSpecsRelation bdWaresSpecsRelation : waresSpecsRelation) {
                BdWaresSpecs waresSpecs = waresSpecsService.selectByPkId(bdWaresSpecsRelation.getPkWaresSpecs());
                specsList.add(waresSpecs.getSpecsName());
            }
            eo.setSpecsName(StringUtils.join(specsList, ","));
            resultList.add(eo);
        }
        return AjaxResult.success(resultList);
    }

    /**
     * 查询商品列表全部数据
     *
     * @return
     */
    @GetMapping("/find-all")
    public AjaxResult findAll(WaresParams waresParams) {
        LambdaQueryWrapper<BdWares> queryWrapper = new LambdaQueryWrapper<>();
        if (waresParams.getSpecialArea() != null) {
            queryWrapper.eq(BdWares::getSpecialArea, waresParams.getSpecialArea());
        }
        if (StringUtils.isNotBlank(waresParams.getQueryName())) {
            queryWrapper.like(BdWares::getWaresName, waresParams.getQueryName()).or().like(BdWares::getWaresCode, waresParams.getQueryName());
        }
        queryWrapper.eq(BdWares::getPkCountry, SecurityUtils.getPkCountry());
        queryWrapper.eq(BdWares::getSystemType, SecurityUtils.getSystemType());
        List<BdWares> list = waresService.list(queryWrapper);
        return AjaxResult.success(list);
    }

    /**
     * 计算商品业绩
     */
    @PostMapping("/compute-wares-price")
    public AjaxResult computeWaresPrice(@RequestBody ComputhParams computhParams) {
        for (ComputeWaresPrice computeWaresPrice : computhParams.getComputeWaresPriceList()) {
            computeWaresPrice.setPkWares(computhParams.getPkWares());
        }
        return AjaxResult.success(waresService.computeWaresPrice(computhParams.getComputeWaresPriceList(), computhParams.getSpecialArea()));
    }

    /**
     * 商品审批
     *
     * @param param 请求参数
     * @return
     */
    @Log(module = EOperationModule.WARES_LIST, business = EOperationBusiness.WARES_LIST, method = EOperationMethod.APPROVAL, remark = "商品新増审批")
    @PostMapping("/wares-approve")
    public AjaxResult waresApprove(@Valid @RequestBody WaresApproveParam param) {
        waresService.update(Wrappers.<BdWares>lambdaUpdate()
                .eq(BdWares::getPkId, param.getPkWares())
                .eq(BdWares::getWaresStatus, EApproveStatus.ALREADY_SUBMIT.getValue())
                .set(BdWares::getWaresStatus, EApproveStatus.FINISH.getValue())
                .set(BdWares::getWaresApprover, SecurityUtils.getUserId())
                .set(BdWares::getWaresApprovalTime, new Date()));
        return AjaxResult.success();
    }

}
