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

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.constant.EnumsPrefixConstants;
import com.hzs.common.core.constant.SystemFieldConstants;
import com.hzs.common.core.constant.msg.ConfigMsgConstants;
import com.hzs.common.core.constant.msg.WaresMsgConstants;
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.common.core.utils.TransactionUtils;
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.util.WaresSpecialUtil;
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.config.IRangeServiceApi;
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 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
    private 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
     */
    @GetMapping("list")
    @Log(module = EOperationModule.WARES_LIST,business=EOperationBusiness.WARES_LIST, method = EOperationMethod.SELECT)
    public TableDataInfo list(WaresParams waresParams) {
        startPage();
        waresParams.setPkCountry(SecurityUtils.getPkCountry());

        Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(ERecommend.values());
        List<WaresVo> resultList = waresService.selectByWaresInfo(waresParams);
        for (WaresVo waresVo : resultList) {
            if (waresVo.getIsRecommend() ==null){
                waresVo.setIsRecommendVal(transactionMap.get(ERecommend.NOT_RECOMMEND.getKey()));
            }else {
                waresVo.setIsRecommendVal(transactionMap.get(EnumsPrefixConstants.RECOMMEND_TYPE + waresVo.getIsRecommend().intValue()));
            }

        }
        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());
        List<WaresVo> resultList = waresService.selectByWaresInfo(waresParams);
        // 获取需要翻译的枚举翻译
        Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(ESpecialArea.values(),EYesNo.values(),ESupplyWay.values(),EPresaleStatus.values());
        for (WaresVo waresVo : resultList) {
            // 所属专区
            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()));
        }
        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(TransactionUtils.getContent(WaresMsgConstants.WARES_NAME_DOES_NOT_EXIST));
        }
        // 预售状态必传
        if (wares.getPreSaleStatus() == null) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.PRESALE_STATUS_NOT_EXIST));
        }
        if (wares.getWaresPrice() == null) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_PRICE_DOES_NOT_EXIST));
        }
        // 累计消费 和 商品消费 不允许添加商品
        if (wares.getSpecialArea() != null){
            if (wares.getSpecialArea().equals(ESpecialArea.UPGRADE_FORM.getValue()) || wares.getSpecialArea().equals(ESpecialArea.UPGRADE_CONSUMPTION.getValue())){
                return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.CONSUMPTION_NOT_ALLOWED_UPLOAD));
            }
        }

        if (wares.getPkAreaClassify() == null) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_AREA_CLASSIFY_DOES_NOT_EXIST));
        }
        if (wares.getCover1() == null) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_COVER_DUPLICATE));
        }
//        if (wares.getPkPrefixLabel() == null || wares.getPkCoolLabel() == null ||  wares.getPkGuaranteeLabel() == null || wares.getPkSellingPoint() == null){
//            return AjaxResult.error(WaresMsgConstants.WARES_LABEL_DUPLICATE);
//        }
        // 检测排序重复
        QueryWrapper<BdWares> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("SORT", wares.getSort());
        queryWrapper.eq("PK_COUNTRY",SecurityUtils.getPkCountry());
        if (waresService.count(queryWrapper) > 0) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.HO_SORT_NOT_REPEAT));
        }
        // 是否陆运
        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(TransactionUtils.getContent(WaresMsgConstants.POSTAGE_TEMPLATE_CANNOT_BE_EMPTY));
            }
            // 校验是否可以陆运
            if (wares.getIsLandTrans() != null) {
                if (EYesNo.NO.getIntValue() == isLandTrans && EYesNo.YES.getIntValue() == wares.getIsLandTrans()) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_UNABLE_LAND_CARRIAGE));
                }
            }

            // 校验是否可以空运
            if (wares.getIsAirTrans() != null) {
                if (EYesNo.NO.getIntValue() == isAirTrans && EYesNo.YES.getIntValue() == wares.getIsAirTrans()) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_UNABLE_AIR_TRANSPORT));
                }
            }

            // 校验是否可以海运
            if (wares.getIsOceanTrans() != null) {
                if (isOceanTrans == EYesNo.NO.getIntValue() && EYesNo.YES.getIntValue() == wares.getIsOceanTrans()) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_UNABLE_OCEAN_TRANSPORT));
                }
            }
            // 不免邮必须添加邮费模板
            if (wares.getIsLandTrans() != null && EYesNo.YES.getIntValue() == wares.getIsLandTrans()) {
                if (wares.getPkLandPostage() == null) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.POSTAGE_TEMPLATE_CANNOT_BE_EMPTY));
                }
            }
            // 是否空运
            if (wares.getIsAirTrans() != null && EYesNo.YES.getIntValue() == wares.getIsAirTrans()) {
                if (wares.getPkAirPostage() == null) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.POSTAGE_TEMPLATE_CANNOT_BE_EMPTY));
                }
            }
            // 是否海运
            if (wares.getIsOceanTrans() != null && EYesNo.YES.getIntValue() == wares.getIsOceanTrans()) {
                if (wares.getPkOceanPostage() == null) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.POSTAGE_TEMPLATE_CANNOT_BE_EMPTY));
                }
            }
        }
        if (wares.getSpecialArea() == ESpecialArea.REPURCHASE_AREA.getValue()) {
            if (wares.getWaresRangeList() == null || wares.getWaresRangeList().size() == 0) {
                return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_RANGE_SIZE_NOT_NULL));
            }
        }

        // 产品明细
        if (wares.getWaresDetailList() == null || wares.getWaresDetailList().size() == 0) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_DETAIL_NOT_NULL));
        }
        // 产品规格
        if (wares.getWaresSpecsSkuList() == null || wares.getWaresSpecsSkuList().size() == 0) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_SKU_NOT_NULL));
        }
        Boolean isPutOn = false;
        for (WaresSpecsSkuParams waresSpecsSkuParams : wares.getWaresSpecsSkuList()) {
            if (waresSpecsSkuParams.getIsPutOn().equals(EYesNo.YES.getIntValue())){
                isPutOn = true;
            }
        }
        if (!isPutOn){
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_SKU_PUT_ON));
        }
        // 编号重复
        QueryWrapper<BdWares> qwe = new QueryWrapper<>();
        qwe.eq("WARES_CODE",wares.getWaresCode());
        int count = waresService.count(qwe);
        if (count > 0){
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.CODE_DUPLICATES));
        }

        waresService.saveWares(wares, userTokenService.getLoginUser());
        //   waresService.saveWaresModifyRecord(wares, userTokenService.getLoginUser(),EModifyRecordType.WARES_ADD.getValue());
        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());
        if (StringUtils.isBlank(waresParams.getWaresCode())) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_NUMBER_DOES_NOT_EXIST));
        }
        // 预售状态必传
        if (waresParams.getPreSaleStatus() == null) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.PRESALE_STATUS_NOT_EXIST));
        }
        if (StringUtils.isBlank(waresParams.getWaresName())) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_NAME_DOES_NOT_EXIST));
        }
        if (waresParams.getWaresPrice() == null) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_PRICE_DOES_NOT_EXIST));
        }
        if (waresParams.getPkAreaClassify() == null) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_AREA_CLASSIFY_DOES_NOT_EXIST));
        }
        if (waresParams.getCover1() == null) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_COVER_DUPLICATE));
        }
//        if (waresParams.getPkPrefixLabel() == null || waresParams.getPkCoolLabel() == null ||  waresParams.getPkGuaranteeLabel() == null || waresParams.getPkSellingPoint() == null){
//            return AjaxResult.error(WaresMsgConstants.WARES_LABEL_DUPLICATE);
//        }
        // 检测排序重复
        QueryWrapper<BdWares> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("SORT", waresParams.getSort());
        queryWrapper.eq("PK_COUNTRY",SecurityUtils.getPkCountry());
        queryWrapper.notIn("PK_ID", waresParams.getWaresId());
        if (waresService.count(queryWrapper) > 0) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.HO_SORT_NOT_REPEAT));
        }

        // 是否陆运
        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(TransactionUtils.getContent(WaresMsgConstants.POSTAGE_TEMPLATE_CANNOT_BE_EMPTY));
            }
            // 校验是否可以陆运
            if (waresParams.getIsLandTrans() != null) {
                if (EYesNo.NO.getIntValue() == isLandTrans && EYesNo.YES.getIntValue() == waresParams.getIsLandTrans()) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_UNABLE_LAND_CARRIAGE));
                }
            }

            // 校验是否可以空运
            if (waresParams.getIsAirTrans() != null) {
                if (EYesNo.NO.getIntValue() == isAirTrans && EYesNo.YES.getIntValue() == waresParams.getIsAirTrans()) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_UNABLE_AIR_TRANSPORT));
                }
            }

            // 校验是否可以海运
            if (waresParams.getIsOceanTrans() != null) {
                if (isOceanTrans == EYesNo.NO.getIntValue() && EYesNo.YES.getIntValue() == waresParams.getIsOceanTrans()) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_UNABLE_OCEAN_TRANSPORT));
                }
            }
            // 不免邮必须添加邮费模板
            if (waresParams.getIsLandTrans() != null && EYesNo.YES.getIntValue() == waresParams.getIsLandTrans()) {
                if (waresParams.getPkLandPostage() == null) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.POSTAGE_TEMPLATE_CANNOT_BE_EMPTY));
                }
            }
            // 是否空运
            if (waresParams.getIsAirTrans() != null && EYesNo.YES.getIntValue() == waresParams.getIsAirTrans()) {
                if (waresParams.getPkAirPostage() == null) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.POSTAGE_TEMPLATE_CANNOT_BE_EMPTY));
                }
            }
            // 是否海运
            if (waresParams.getIsOceanTrans() != null && EYesNo.YES.getIntValue() == waresParams.getIsOceanTrans()) {
                if (waresParams.getPkOceanPostage() == null) {
                    return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.POSTAGE_TEMPLATE_CANNOT_BE_EMPTY));
                }
            }
        }
        if (waresParams.getSpecialArea() == ESpecialArea.REPURCHASE_AREA.getValue()) {
            if (waresParams.getWaresRangeList() == null || waresParams.getWaresRangeList().size() == 0) {
                return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_RANGE_SIZE_NOT_NULL));
            }
        }
        // 产品明细
        if (waresParams.getWaresDetailList() == null || waresParams.getWaresDetailList().size() == 0) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_DETAIL_NOT_NULL));
        }
        // 产品规格
        if (waresParams.getWaresSpecsSkuList() == null || waresParams.getWaresSpecsSkuList().size() == 0) {
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.WARES_SKU_NOT_NULL));
        }
        // 编号重复
        QueryWrapper<BdWares> qwe = new QueryWrapper<>();
        qwe.eq("WARES_CODE",waresParams.getWaresCode());
        qwe.notIn("PK_ID",waresParams.getWaresId());
        int count = waresService.count(qwe);
        if (count > 0){
            return AjaxResult.error(TransactionUtils.getContent(WaresMsgConstants.CODE_DUPLICATES));
        }


        waresService.updateWares(waresParams, userTokenService.getLoginUser());
        //     waresService.saveWaresModifyRecord(waresParams, userTokenService.getLoginUser(),EModifyRecordType.WARES_UPDATE.getValue());
        return AjaxResult.success(waresParams.getWaresCode());
    }


    /**
     * 删除商品
     *
     * @param pkId
     * @return
     */
    @DeleteMapping("/{pkId}")
    @Log(module = EOperationModule.WARES_LIST,business=EOperationBusiness.WARES_LIST, method = EOperationMethod.DELETE)
    public AjaxResult remove(@PathVariable Integer pkId) {
        // TODO 商品被订单引用之后无法删除
        waresService.removeWares(pkId);
        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);
        QueryWrapper<BdWaresExtend> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PK_WARES", pkId);
        BdWaresExtend waresExtend = waresExtendService.getOne(queryWrapper);
        WaresParams waresParams = new WaresParams();
        waresParams.setWaresId(wares.getPkId());
        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());

        BdAreaClassify parentAreaClassify = areaClassifyService.getAreaClassify(wares.getPkAreaClassify());
        if (parentAreaClassify != null) {
            if (parentAreaClassify.getPkParent() == 0) {
                waresParams.setParentPkAreaClassify(null);
            } else {
                waresParams.setParentPkAreaClassify(parentAreaClassify.getPkParent().intValue());
            }
        }
        // 标签
        QueryWrapper<BdWaresLabel> waresLabelWrapper = new QueryWrapper<>();
        waresLabelWrapper.eq("PK_WARES", 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);

        //包装和规格
        QueryWrapper<BdWaresSpecsPack> waresSpecsPackWrapper = new QueryWrapper<>();
        waresSpecsPackWrapper.eq("PK_WARES", 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);

        //产品详情列表
        QueryWrapper<BdWaresDetail> waresDetailWrapper = new QueryWrapper<>();
        waresDetailWrapper.eq("PK_WARES", 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());
                waresDetailParams.setIsGift(bd.getIsGift());
            }
            detailList.add(waresDetailParams);

            // 拼装查询每个产品详情的规格
            QueryWrapper<BdWaresSpecsSku> specsSku = new QueryWrapper<>();
            specsSku.eq("PK_WARES", pkId);
            specsSku.eq("PK_WARES_DETAIL", bd.getPkId());
            List<BdWaresSpecsSku> specsSkuList = waresSpecsSkuService.list(specsSku);
            for (BdWaresSpecsSku bdWaresSpecsSku : specsSkuList) {
                WaresSpecsSkuParams specsSkuParams = new WaresSpecsSkuParams();
                specsSkuParams.setPkWaresSpecsSku(bdWaresSpecsSku.getPkId());
                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.setIsGift(bd.getIsGift());
                // 每个规格的sku键值对
                List<BdWaresSpecs> waresSpecsList = new ArrayList<>();
                QueryWrapper<BdWaresSpecsRelation> waresSpecsRelation = new QueryWrapper<>();
                waresSpecsRelation.eq("PK_WARES_SPECS_SKU", 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());
                    }
                    //     WaresSpecsVo waresSpecsVo =  waresSpecsService.selectByWaresSpecsInfo(bdWaresSpecsRelation.getPkWaresSpecs());
                    waresSpecsList.add(waresSpecs);

                }
                specsSkuParams.setWaresSpecsList(waresSpecsList);
                waresSpecsSkuList.add(specsSkuParams);
            }
        }
        waresParams.setWaresDetailList(detailList);
        waresParams.setWaresSpecsSkuList(waresSpecsSkuList);
        // 团队配置
        QueryWrapper<BdWaresAuthority> authorityWrapper = new QueryWrapper<>();
        authorityWrapper.eq("PK_WARES", 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<>();
//        QueryWrapper<BdWaresRange> waresRangeWrapper = new QueryWrapper<>();
//        waresRangeWrapper.eq("PK_WARES", pkId);
//        List<BdWaresRange> rangeList = waresRangeService.list(waresRangeWrapper);
        List<BdWaresRange> rangeList = waresRangeService.queryWaresList(pkId,SecurityUtils.getPkCountry());
        QueryWrapper<BdWaresRange> waresRangeWrapper = new QueryWrapper<>();
        waresRangeWrapper.eq("PK_WARES", pkId);
        int waresRangeCount = waresRangeService.count(waresRangeWrapper);
        // 查询不存在的极差等级 (部分极差等级可能是后期添加导致商品和极差关联表不存在该极差信息)
//        List<Integer> rangeArrayList = new ArrayList<>();
//        Map<Integer, BdWaresRange> wrMap = rangeList.stream().collect(Collectors.toMap(BdWaresRange::getPkRange, Function.identity()));
//        for (BdRangeExt bdRangeExt : rsList) {
//            BdWaresRange bdWaresRange = wrMap.get(bdRangeExt.getPkId());
//            if (bdWaresRange == null){
//                rangeArrayList.add(bdWaresRange.getPkRange());
//            }
//        }
        List<Integer> rgList = new ArrayList<>();
        for (BdWaresRange bdWaresRange : rangeList) {
            if (bdWaresRange.getPkId() != null){
                if (bdWaresRange.getPkWaresSpecsSku() != null) {
                    WaresRangeParams waresRangeParams = BeanUtil.copyProperties(bdWaresRange, WaresRangeParams.class);
                    // 查询每一个sku 的所有规格
                    List<BdWaresSpecs> waresSpecsList = new ArrayList<>();
                    QueryWrapper<BdWaresSpecsRelation> waresSpecsRelation = new QueryWrapper<>();
                    waresSpecsRelation.eq("PK_WARES_SPECS_SKU", 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());
                        }
                        //     WaresSpecsVo waresSpecsVo =  waresSpecsService.selectByWaresSpecsInfo(bdWaresSpecsRelation.getPkWaresSpecs());
                        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(a -> {
                        return a.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());
                    if (product != null) {
                        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);
                    }
                    QueryWrapper<BdWaresRange> qe = new QueryWrapper<>();
                    qe.eq("PK_WARES",bdWaresDetail.getPkWares());
                    qe.eq("PK_WARES_DETAIL",bdWaresDetail.getPkId());
                    List<BdWaresRange> wrList = waresRangeService.list(qe);
                    // 查询每一个sku 的所有规格
                    List<BdWaresSpecs> waresSpecsList = new ArrayList<>();
                    for (BdWaresRange bdWaresRange : wrList) {
                        QueryWrapper<BdWaresSpecsRelation> waresSpecsRelation = new QueryWrapper<>();
                        waresSpecsRelation.eq("PK_WARES_SPECS_SKU", 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());
                            }
                            //     WaresSpecsVo waresSpecsVo =  waresSpecsService.selectByWaresSpecsInfo(bdWaresSpecsRelation.getPkWaresSpecs());
                            waresSpecsList.add(waresSpecs);

                        }

                    }

                    waresRangeParams.setWaresSpecsList(waresSpecsList);
                    List<String> specsNames = waresSpecsList.stream().map(a -> {
                        return a.getSpecsName();
                    }).collect(Collectors.toList());
                    waresRangeParams.setSpecsNames(StringUtils.join(specsNames.get(0),","));
                    waresRangeList.add(waresRangeParams);
                }
            }
        }

        waresParams.setWaresRangeList(waresRangeList);
        // 查询商品级别
        QueryWrapper<BdWaresGrade> qw = new QueryWrapper<>();
        qw.eq("PK_WARES", pkId);
        List<BdWaresGrade> waresGradeIds = waresGradeService.list(qw);
        List<Integer> ids = waresGradeIds.stream().map(BdWaresGrade::getPkRange).collect(Collectors.toList());
        waresParams.setWaresGradeIds(ids);
        // 查询商品奖衔
        QueryWrapper<BdWaresAwards> qe = new QueryWrapper<>();
        qe.eq("PK_WARES",pkId);
        List<BdWaresAwards> waresAwardsIds = waresAwardsService.list(qe);
        List<Integer> waresAwardsArray = waresAwardsIds.stream().map(a -> {
            return a.getPkAwards();
        }).collect(Collectors.toList());
        waresParams.setWaresAwardsIds(waresAwardsArray);
        // 查询商品权限配置
        QueryWrapper<BdWaresAuthorize> qa = new QueryWrapper<>();
        qa.eq("PK_WARES",pkId);
        List<BdWaresAuthorize> waresAuthoritys = waresAuthorizeService.list(qa);
        List<Integer> waresAuthorizeList = waresAuthoritys.stream().map(a -> {
            return a.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.WARES_LIST, method = EOperationMethod.UP_MOVE)
    public AjaxResult move(Integer waresId, Integer waresMoveType) {
        waresService.waresMove(waresId, waresMoveType);
        return AjaxResult.success();

    }

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


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

    /**
     * 商品序号创建
     *
     * @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) {
        // TODO 需要优化此接口 空单查询
        QueryWrapper<BdWares> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(waresName)) {
            queryWrapper.eq("WARES_NAME", waresName);
        }
        queryWrapper.eq("PK_COUNTRY",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) {
                //   BdProduct product = productService.getProduct(bdWaresDetail.getPkProduct());
                ProductEntnyOrderVo productEntnyOrderVo = new ProductEntnyOrderVo();
                productEntnyOrderVo.setPkProduct(bdWaresDetail.getPkProduct());
                productEntnyOrderVo.setQuantity(bdWaresDetail.getQuantity());
                productEntnyOrderVo.setProductName(bdWaresDetail.getProductName());
                QueryWrapper<BdWaresSpecsSku> qw = new QueryWrapper<>();
                qw.eq("PK_WARES_DETAIL", 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++) {
            //    BdWaresSpecsSku ws = waresSpecsSkuService.getById(emptyOrderWares.getPkWaresSpecsSkus().get(i).getPkWaresSpecsSku());
            BdWaresSpecsSkuExt ws = waresSpecsSkuService.selectByPkWaresSpecsSku(emptyOrderWares.getPkWaresSpecsSkus().get(i).getPkWaresSpecsSku());
            //  BdWares wares = waresService.getById(ws.getPkWares());
            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());
            QueryWrapper<BdWaresSpecsRelation> qer = new QueryWrapper<>();
            qer.eq("PK_WARES_SPECS_SKU", ws.getPkId());
            List<BdWaresSpecsRelation> waresSpecsRelation = waresSpecsRelationService.list(qer);
            List<String> specsList = new ArrayList<>();
            for (BdWaresSpecsRelation bdWaresSpecsRelation : waresSpecsRelation) {
                BdWaresSpecs waresSpecs = waresSpecsService.selectByPkId(bdWaresSpecsRelation.getPkWaresSpecs());
                //    BdWaresSpecs waresSpecs = waresSpecsService.getById(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 ) {
        QueryWrapper<BdWares> queryWrapper = new QueryWrapper<>();
//        if (waresParams.getSpecialArea() != null){
//            queryWrapper.eq("SPECIAL_AREA",waresParams.getSpecialArea());
//        }
        //  累计消费同步报单加盟的商品
        //  商品消费同步特价产品的商品
        if (waresParams.getSpecialArea() != null){
            List<Integer> waresSpecial = WaresSpecialUtil.getWaresSpecial(waresParams.getSpecialArea());
            queryWrapper.in("SPECIAL_AREA",waresSpecial);
        }
        queryWrapper.eq(SystemFieldConstants.PK_COUNTRY, SecurityUtils.getPkCountry());
        List<BdWares> list = waresService.list(queryWrapper);
        return AjaxResult.success(list);
    }

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

}
