package com.hzs.member.store.controller.manager;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
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.msg.ConfigMsgConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.RandomNumberGenerator;
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.member.base.CuMember;
import com.hzs.common.domain.member.store.CuStore;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.core.utils.TransactionUtils;
import com.hzs.common.service.ITransactionCommonService;
import com.hzs.member.base.service.ICuMemberService;
import com.hzs.member.store.service.ICuStoreService;
import com.hzs.member.store.vo.CuStoreVO;
import com.hzs.system.base.IAreaServiceApi;
import com.hzs.system.base.ICountryServiceApi;
import com.hzs.system.base.ICurrencyServiceApi;
import com.hzs.system.base.dto.CountryDTO;
import com.hzs.system.base.dto.CurrencyDTO;
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.util.*;
import java.util.stream.Collectors;

/**
 * 店铺设置 前端控制器
 *
 * @author hzs
 * @since 2023-05-04
 */
@RestController
@RequestMapping("/manage/store")
public class CuStoreController extends BaseController {

    @Autowired
    private ICuStoreService storeService;
    @Autowired
    private ICuMemberService cuMemberService;
    @Autowired
    private ITransactionCommonService iTransactionCommonService;

    @DubboReference
    private ICurrencyServiceApi currencyServiceApi;
    @DubboReference
    private IAreaServiceApi areaServiceApi;
    @DubboReference
    private ICountryServiceApi iCountryServiceApi;


    /**
     * @description: 查询店铺配置列表
     * @author: zhang jing
     * @date: 2022/8/30 10:20
     * @param: [custoreVO]
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(CuStoreVO custoreVO) {
        startPage();
        custoreVO.setPkCountry(SecurityUtils.getPkCountry());
        List<CuStoreVO> list = storeService.queryStoreList(custoreVO);
        return getDataTable(list);
    }

    /**
     * @description: 导出店铺信息
     * @author: zhang jing
     * @date: 2023/3/9 16:08
     * @param: [response, custoreVO]
     * @return: void
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.SELECT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CuStoreVO custoreVO) {
        custoreVO.setPkCountry(SecurityUtils.getPkCountry());
        List<CuStoreVO> list = storeService.queryStoreList(custoreVO);
        if (CollectionUtil.isNotEmpty(list)) {
            Map<Integer, String> transactionMap = iTransactionCommonService.exportEnumTransactionByDB(EnumsPrefixConstants.KEY_STORE_LEVEL);
            list.forEach(itm -> {
                itm.setPkTransactionVal(transactionMap.get(itm.getPkTransaction()));
            });
        }
        ExcelUtil<CuStoreVO> util = new ExcelUtil<>(CuStoreVO.class);
        util.exportExcel(response, list, "店铺信息");
    }

    /**
     * @description: 生成店铺编号
     * @author: zhang jing
     * @date: 2023/5/5 10:41
     * @param: []
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.SELECT)
    @GetMapping("/getCode")
    public AjaxResult getCode() {
        List<CuStore> cuStore = storeService.selectMaxList(SecurityUtils.getPkCountry());
        String code = "";
        if (CollectionUtil.isNotEmpty(cuStore)) {
            code = RandomNumberGenerator.getNextNumber(cuStore.get(0).getStoreCode(), 2);
        } else {
            code = RandomNumberGenerator.getNextNumber("SH001", 2);
        }
        return AjaxResult.success(code);
    }

    /**
     * @description: 新增店铺配置
     * @author: zhang jing
     * @date: 2022/8/30 10:21
     * @param: [custoreVO]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody CuStoreVO custoreVO) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        if (StringUtils.isEmpty(custoreVO.getStoreCode())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_CODE_NOT_NULL));
        }
        if (StringUtils.isEmpty(custoreVO.getMemberCode())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_MEMBER_CODE_NOT_NULL));
        }
        CuMember member = cuMemberService.getMember(custoreVO.getMemberCode());
        if (StringUtils.isNull(member)) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.MEMBER_NOT_VALID));
        }
        custoreVO.setPkMember(member.getPkId());

        if (StringUtils.isEmpty(custoreVO.getStoreName())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_NAME_NOT_NULL));
        }

        if (StringUtils.isNull(custoreVO.getProvince())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.GLO_PROVINCE_NOT_NULL));
        }
//        if (StringUtils.isNull(custoreVO.getCity())) {
//            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.GLO_CITY_NOT_NULL));
//        }

        if (StringUtils.isEmpty(custoreVO.getShopowner())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.SHOPOWNER_NOT_NULL));
        }
        if (StringUtils.isNull(custoreVO.getPkStoreLevel())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.PKSTORELEVEL_NOT_NULL));
        }
        if (StringUtils.isEmpty(custoreVO.getAddress())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.HO_ADDRESS_NOT_NULL));
        }
        QueryWrapper<CuStore> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("STORE_CODE", custoreVO.getStoreCode());
        List<CuStore> list = storeService.list(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_CODE_REPEAT));
        }
        QueryWrapper<CuStore> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("PK_MEMBER", custoreVO.getPkMember());
        queryWrapper1.eq("PK_COUNTRY", pkCountry);
        list = storeService.list(queryWrapper1);
        if (CollectionUtil.isNotEmpty(list)) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_REPEAT));
        }
        custoreVO.setPkCountry(pkCountry);
        custoreVO.setPkCreator(SecurityUtils.getUserId());
        custoreVO.setCreationTime(new Date());
        CuStore cuStore = BeanUtil.copyProperties(custoreVO, CuStore.class);
        R<CurrencyDTO> currency = currencyServiceApi.getCurrency(SecurityUtils.getPkCountry());
        return AjaxResult.success(storeService.saveStore(cuStore, currency, member));
    }


    /**
     * @description: 店铺配置确认接口
     * @author: zhang jing
     * @date: 2024/4/3 17:02
     * @param: [custoreVO]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.SUBMIT)
    @PostMapping("/affirm")
    public AjaxResult affirm(@RequestBody CuStoreVO custoreVO) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        CuMember member = cuMemberService.getMember(custoreVO.getMemberCode());
        if (StringUtils.isNull(member)) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.MEMBER_NOT_VALID));
        }
        if (StringUtils.isNull(custoreVO.getControlType())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.CU_STORE_CONTROL_TYPE));
        }
        custoreVO.setPkMember(member.getPkId());

        if (StringUtils.isEmpty(custoreVO.getStoreName())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_NAME_NOT_NULL));
        }
        if (StringUtils.isNull(custoreVO.getProvince())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.GLO_PROVINCE_NOT_NULL));
        }
//        if (StringUtils.isNull(custoreVO.getCity())) {
//            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.GLO_CITY_NOT_NULL));
//        }

        if (StringUtils.isEmpty(custoreVO.getShopowner())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.SHOPOWNER_NOT_NULL));
        }
        if (StringUtils.isNull(custoreVO.getPkStoreLevel())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.PKSTORELEVEL_NOT_NULL));
        }

        if (StringUtils.isEmpty(custoreVO.getAddress())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.HO_ADDRESS_NOT_NULL));
        }
        //根据店铺等级id查询店铺等级值
        custoreVO.setPkCountry(pkCountry);
        CuStoreVO storeLevel = storeService.queryStoreLevelById(custoreVO);
        custoreVO.setPkTransaction(storeLevel.getPkTransaction());
        if (custoreVO.getControlType() == EControlType.SAVE.getValue()||
                custoreVO.getControlType() == EControlType.MODIFY.getValue()) {
            if (StringUtils.isEmpty(custoreVO.getStorePerson())) {
                return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_PERSON_NOT_NULL));
            }
            if (StringUtils.isEmpty(custoreVO.getStorePhone())) {
                return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_PHONE_NOT_NULL));
            }
            if ((storeLevel.getLevelValue() == ELevelValue.COPPER_DRILL.getValue() ||
                    storeLevel.getLevelValue() == ELevelValue.SILVER_DRILL.getValue()) && custoreVO.getBindingProvince() == null) {
                return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_BINDING_PROVINCE_NOT_NULL));
            }
            if (storeLevel.getLevelValue() == ELevelValue.GOLD_DRILL.getValue()) {
                custoreVO.setBindingCountry(pkCountry);
            }

            //校验一个会员只绑定一个店铺
            QueryWrapper<CuStore> queryWrapper1 = new QueryWrapper<>();
            if(custoreVO.getControlType() == EControlType.MODIFY.getValue()){
                queryWrapper1.ne("PK_ID", custoreVO.getPkId());
            }
            queryWrapper1.eq("PK_MEMBER", custoreVO.getPkMember());
            queryWrapper1.eq("PK_COUNTRY", pkCountry);
            List<CuStore> list = storeService.list(queryWrapper1);
            if (CollectionUtil.isNotEmpty(list)) {
                return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_REPEAT));
            }
            //校验绑定省
            if (storeLevel.getLevelValue() == ELevelValue.SILVER_DRILL.getValue()) {
                QueryWrapper<CuStore> queryWrapper3 = new QueryWrapper<>();
                if(custoreVO.getControlType() == EControlType.MODIFY.getValue()){
                    queryWrapper3.ne("PK_ID", custoreVO.getPkId());
                }
                queryWrapper3.eq("BINDING_PROVINCE", custoreVO.getBindingProvince());
                queryWrapper3.eq("PK_STORE_LEVEL", custoreVO.getPkStoreLevel());
                list = storeService.list(queryWrapper3);
                if (CollectionUtil.isNotEmpty(list)) {
                    return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_BINDING_PROVINCE_REPEAT));
                }
            }
            //校验绑定国家
            if (storeLevel.getLevelValue() == ELevelValue.GOLD_DRILL.getValue()) {
                QueryWrapper<CuStore> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.eq("PK_COUNTRY", pkCountry);
                queryWrapper2.eq("BINDING_COUNTRY", custoreVO.getBindingCountry());
                queryWrapper2.eq("PK_STORE_LEVEL", custoreVO.getPkStoreLevel());
                list = storeService.list(queryWrapper2);
                if (CollectionUtil.isNotEmpty(list)) {
                    return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_BINDING_COUNTRY_REPEAT));
                }
            }

        }
        custoreVO.setPkCountry(pkCountry);
        custoreVO.setPkCreator(SecurityUtils.getUserId());
        custoreVO.setCreationTime(new Date());
        Integer count = cuMemberService.checkmsLogCount(custoreVO.getPkMember(), EControlType.getStoreBusiness(custoreVO.getControlType()).getValue());
        if (StringUtils.isNotNull(count) && count > 0) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.MEMBER_UPDATE_CODE_REPEAT));
        }
        return AjaxResult.success(custoreVO);
    }

    /**
     * @description: 店铺配置发起签呈
     * @author: zhang jing
     * @date: 2024/4/3 10:34
     * @param: [custoreVO]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.SUBMIT)
    @PostMapping("/petition")
    public AjaxResult petition(@RequestBody CuStoreVO custoreVO) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        custoreVO.setPkCountry(pkCountry);
        CuMember member = cuMemberService.getMember(custoreVO.getMemberCode());
        if (StringUtils.isNull(member)) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.MEMBER_NOT_VALID));
        }
        if (StringUtils.isNull(custoreVO.getControlType())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.CU_STORE_CONTROL_TYPE));
        }
        custoreVO.setPkMember(member.getPkId());

        if (StringUtils.isEmpty(custoreVO.getStoreName())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_NAME_NOT_NULL));
        }
        if (StringUtils.isNull(custoreVO.getProvince())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.GLO_PROVINCE_NOT_NULL));
        }
//        if (StringUtils.isNull(custoreVO.getCity())) {
//            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.GLO_CITY_NOT_NULL));
//        }

        if (StringUtils.isEmpty(custoreVO.getShopowner())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.SHOPOWNER_NOT_NULL));
        }
        if (StringUtils.isNull(custoreVO.getPkStoreLevel())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.PKSTORELEVEL_NOT_NULL));
        }

        if (StringUtils.isEmpty(custoreVO.getAddress())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.HO_ADDRESS_NOT_NULL));
        }
        if (custoreVO.getControlType() == EControlType.SAVE.getValue()||
                custoreVO.getControlType() == EControlType.MODIFY.getValue()) {
            //根据店铺等级id查询店铺等级值
            custoreVO.setPkCountry(pkCountry);
            CuStoreVO storeLevel = storeService.queryStoreLevelById(custoreVO);
            if (StringUtils.isEmpty(custoreVO.getStorePerson())) {
                return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_PERSON_NOT_NULL));
            }
            if (StringUtils.isEmpty(custoreVO.getStorePhone())) {
                return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_PHONE_NOT_NULL));
            }
            if ((storeLevel.getLevelValue() == ELevelValue.COPPER_DRILL.getValue() ||
                    storeLevel.getLevelValue() == ELevelValue.SILVER_DRILL.getValue()) && custoreVO.getBindingProvince() == null) {
                return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_BINDING_PROVINCE_NOT_NULL));
            }
            if (storeLevel.getLevelValue() == ELevelValue.GOLD_DRILL.getValue()) {
                custoreVO.setBindingCountry(pkCountry);
            }

            //校验一个会员只绑定一个店铺
            QueryWrapper<CuStore> queryWrapper1 = new QueryWrapper<>();
            if(custoreVO.getControlType() == EControlType.MODIFY.getValue()){
                queryWrapper1.ne("PK_ID", custoreVO.getPkId());
            }
            queryWrapper1.eq("PK_MEMBER", custoreVO.getPkMember());
            queryWrapper1.eq("PK_COUNTRY", pkCountry);
            List<CuStore> list = storeService.list(queryWrapper1);
            if (CollectionUtil.isNotEmpty(list)) {
                return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_REPEAT));
            }
            //校验绑定省
            if (storeLevel.getLevelValue() == ELevelValue.SILVER_DRILL.getValue()) {
                QueryWrapper<CuStore> queryWrapper3 = new QueryWrapper<>();
                if(custoreVO.getControlType() == EControlType.MODIFY.getValue()){
                    queryWrapper3.ne("PK_ID", custoreVO.getPkId());
                }
                queryWrapper3.eq("BINDING_PROVINCE", custoreVO.getBindingProvince());
                queryWrapper3.eq("PK_STORE_LEVEL", custoreVO.getPkStoreLevel());
                list = storeService.list(queryWrapper3);
                if (CollectionUtil.isNotEmpty(list)) {
                    return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_BINDING_PROVINCE_REPEAT));
                }
            }
            //校验绑定国家
            if (storeLevel.getLevelValue() == ELevelValue.GOLD_DRILL.getValue()) {
                QueryWrapper<CuStore> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.eq("PK_COUNTRY", pkCountry);
                queryWrapper2.eq("BINDING_COUNTRY", custoreVO.getBindingCountry());
                queryWrapper2.eq("PK_STORE_LEVEL", custoreVO.getPkStoreLevel());
                list = storeService.list(queryWrapper2);
                if (CollectionUtil.isNotEmpty(list)) {
                    return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_BINDING_COUNTRY_REPEAT));
                }
            }

        }
        Map<Integer, String> areaDate = areaServiceApi.getAreaMap(custoreVO.getPkCountry()).getData();
        if (StringUtils.isNotNull(custoreVO.getProvince())) {
            custoreVO.setProvinceVal(areaDate.get(custoreVO.getProvince()));
        }
        if (StringUtils.isNotNull(custoreVO.getCity())) {
            custoreVO.setCityVal(areaDate.get(custoreVO.getCity()));
        }
        if (StringUtils.isNotNull(custoreVO.getBindingProvince())) {
            custoreVO.setBindingProvinceName(areaDate.get(custoreVO.getBindingProvince()));
        }
        if (StringUtils.isNotNull(custoreVO.getBindingCountry())) {
            R<CountryDTO> country = iCountryServiceApi.getCountry(custoreVO.getBindingCountry());
            custoreVO.setBindingCountryName(country.getData().getShortName());
        }
        custoreVO.setPkCreator(SecurityUtils.getUserId());
        custoreVO.setCreationTime(new Date());
        Integer count = cuMemberService.checkmsLogCount(custoreVO.getPkMember(), EControlType.getStoreBusiness(custoreVO.getControlType()).getValue());
        if (StringUtils.isNotNull(count) && count > 0) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.MEMBER_UPDATE_CODE_REPEAT));
        }
        return AjaxResult.success(storeService.petition(custoreVO));
    }

    /**
     * @description: 修改店铺配置
     * @author: zhang jing
     * @date: 2022/8/30 10:21
     * @param: [custoreVO]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody CuStoreVO custoreVO) {

        if (StringUtils.isEmpty(custoreVO.getStoreName())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.STORE_NAME_NOT_NULL));
        }

        if (StringUtils.isNull(custoreVO.getProvince())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.LEVEL_VALUE_NOT_NULL));
        }
        if (StringUtils.isNull(custoreVO.getCity())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.LEVEL_VALUE_NOT_NULL));
        }

        if (StringUtils.isEmpty(custoreVO.getShopowner())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.SHOPOWNER_NOT_NULL));
        }
        if (StringUtils.isNull(custoreVO.getPkStoreLevel())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.PKSTORELEVEL_NOT_NULL));
        }
        if (StringUtils.isEmpty(custoreVO.getAddress())) {
            return AjaxResult.error(TransactionUtils.getContent(ConfigMsgConstants.HO_ADDRESS_NOT_NULL));
        }
        custoreVO.setPkModified(SecurityUtils.getUserId());
        custoreVO.setModifiedTime(new Date());
        CuStore cuStore = BeanUtil.copyProperties(custoreVO, CuStore.class);
        return toAjax(storeService.updateById(cuStore));
    }


    /**
     * @description: 查询单条店铺配置
     * @author: zhang jing
     * @date: 2022/8/30 10:21
     * @param: [pkId]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.SELECT)
    @GetMapping("/getOne/{pkId}")
    public AjaxResult getOne(@PathVariable Integer pkId) {
        CuStoreVO custoreVO = new CuStoreVO();
        custoreVO.setPkId(pkId);
        List<CuStoreVO> list = storeService.queryStoreList(custoreVO);
        if (CollectionUtil.isNotEmpty(list)) {
            custoreVO = list.get(0);
        } else {
            custoreVO = null;
        }
        return AjaxResult.success(custoreVO);
    }


    /**
     * @description: 删除店铺配置
     * @author: zhang jing
     * @date: 2022/8/30 10:21
     * @param: [pkId]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.DELETE)
    @GetMapping("/batchDelete")
    public AjaxResult batchDelete(String pkId) {
        List<CuStoreVO> errorList = new ArrayList<>();
        Integer pkkCountry = SecurityUtils.getPkCountry();
        if (StringUtils.isEmpty(pkId)) {
            return AjaxResult.success();
        } else {
            List<Integer> pkIdList = Arrays.stream(pkId.split(","))
                    .map(Integer::parseInt)
                    .collect(Collectors.toList());
            for (Integer id : pkIdList) {
                CuStoreVO storeVO = new CuStoreVO();
                storeVO.setPkId(id);
                storeVO.setPkCountry(pkkCountry);
                CuStoreVO cs = storeService.checkOrder(storeVO);
                if (cs != null) {
                    storeVO.setStoreCode(cs.getStoreCode());
                    storeVO.setStoreName(cs.getStoreName());
                    storeVO.setErrorMsg(TransactionUtils.getContent(ConfigMsgConstants.DEL_STORE_ORDER));
                    errorList.add(storeVO);
                }
            }
            if (CollectionUtil.isNotEmpty(errorList)) {
                return AjaxResult.error(504, TransactionUtils.getContent(ConfigMsgConstants.MEMBER_DATA_ERROR), errorList);
            }
            return AjaxResult.success(storeService.batchDelete(pkId));
        }
    }

    /**
     * @description: 查询店铺配置列表
     * @author: yuhui
     * @date: 2022/8/30 10:20
     * @param: [custoreVO]
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @Log(module = EOperationModule.CU_STORE, business = EOperationBusiness.CU_STORE, method = EOperationMethod.SELECT)
    @GetMapping("/findall")
    public AjaxResult findall() {
        QueryWrapper<CuStore> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PK_COUNTRY", SecurityUtils.getPkCountry());
        queryWrapper.orderByDesc("STORE_CODE");
        List<CuStore> storeList = storeService.list(queryWrapper);
        return AjaxResult.success(storeList);
    }
}
