package com.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.response.PageResponse;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.core.utils.AESUtils;
import com.ssm.core.utils.QRCodeUtil;
import com.ssm.manage.entity.BaseStore;
import com.ssm.manage.entity.BaseStores;
import com.ssm.manage.entity.SmsException;
import com.ssm.manage.entity.StoreParament;
import com.ssm.manage.query.StoreRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmBaseStoreService;
import com.ssm.manage.service.SsmStoreParaService;
import com.ssm.manage.utils.CommonUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.stream.Collectors;

@Api(value="门店controller",tags={"门店相关接口"})
@RestController
@RequestMapping("/demay/ssm/store")
@Slf4j
public class SsmBaseStoreController {
    @Autowired
    private SsmBaseStoreService ssmBaseStoreService;

    @Autowired
    private SsmStoreParaService ssmStoreParaService;

    @ApiOperation(value = "分页查询门店信息  平台端-门店管理-门店审核-分页查询门店信息",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/pageStoreNew")
    public PageResponse<Map<String,List<BaseStore>>> pageStoreNew(@RequestBody StoreRequest storeRequest){
        PageResponse<Map<String,List<BaseStore>>> pageResponse = new PageResponse<>();
        List<Map<String,List<BaseStore>>> list = new ArrayList<>();
        Map<String,List<BaseStore>> map = new HashMap<>();
        List<String> strings = new ArrayList<>();

        try {
            strings = ssmBaseStoreService.selectGroup();
            List<BaseStore> select = ssmBaseStoreService.select(null);
            for (BaseStore baseStore : select) {
                if(baseStore.getDescription()==null){
                    baseStore.setDescription("无");
                }
            }
            for (String string : strings) {
                List<BaseStore> collect = select.stream().filter(item -> item.getDescription().equals(string)).collect(Collectors.toList());
                map.put(string,collect);
            }
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        list.add(map);
        pageResponse.setData(list);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }
    @ApiOperation(value = "分页查询门店信息  平台端-门店管理-门店审核-分页查询门店信息",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/pageStore")
    public PageResponse<String> pageStore(@RequestBody StoreRequest storeRequest){
        PageResponse<String> pageResponse = new PageResponse<>();
        List<Map<String,List<BaseStore>>> list = new ArrayList<>();
        List<String> strings = new ArrayList<>();

        try {
            strings = ssmBaseStoreService.selectGroup();
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setData(strings);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    @ApiOperation(value = "新店注册 平台端-门店管理-新店注册",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/addStore")
    public GenericResponse<BaseStore> addStore(@RequestBody StoreRequest storeRequest,HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        if (StringUtils.isBlank(storeRequest.getRegistrant())) {
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "注册人");
            return genericResponse;
        }
        if (StringUtils.isBlank(storeRequest.getRegistrantMobilePhone())) {
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "注册人手机");
            return genericResponse;
        }
        if (!CommonUtils.isMobile(storeRequest.getRegistrantMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.NOT_MEET_REQUIREMENTS_S,"注册人手机");
            return genericResponse;
        }
//        if (StringUtils.isBlank(storeRequest.getTelephone())) {
//            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "门店服务电话");
//            return genericResponse;
//        }
//        if (StringUtils.isNotBlank(storeRequest.getTelephone()) && !CommonUtils.isTelephone(storeRequest.getTelephone())){
//            genericResponse.setCodeAndMsg(ResponseCode.NOT_MEET_REQUIREMENTS_S,"门店服务电话");
//            return genericResponse;
//        }
        if (StringUtils.isBlank(storeRequest.getStoreName())) {
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "门店名称");
            return genericResponse;
        }
//        if (StringUtils.isBlank(storeRequest.getRegistrantIdentity())) {
//            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "身份证号");
//            return genericResponse;
//        }
        if (StringUtils.isNotBlank(storeRequest.getRegistrantIdentity()) && !CommonUtils.isIdentityCard(storeRequest.getRegistrantIdentity())) {
            genericResponse.setCodeAndMsg(ResponseCode.NOT_MEET_REQUIREMENTS_S, "身份证号");
            return genericResponse;
        }
        String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.addStore(storeRequest,userNum);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e) {
            log.error("SsmBaseStoreController.addStore", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "分页查询门店信息  平台端-门店管理-门店审核-分页查询门店信息",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/page")
    public PageResponse<StoreRequest> selectPage(@RequestBody StoreRequest storeRequest){
        PageResponse<StoreRequest> pageResponse = new PageResponse<>();
        PageInfo<StoreRequest> pageInfo = new PageInfo<>();
        try {
            pageInfo = ssmBaseStoreService.selectPage(storeRequest);
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setPageInfo(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    @ApiOperation(value = "分页查询门店信息  平台端-门店管理-门店审核-分页查询门店信息",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/selectDescription")
    public GenericResponse<List<String>> selectDescription(){
        GenericResponse<List<String>> pageResponse = new GenericResponse<>();
        List<String> pageInfo = new ArrayList<>();
        try {
            pageInfo = ssmBaseStoreService.selectDescription();
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setData(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    @ApiOperation(value = "门店明细查询  平台端-门店管理-门店审核-门店明细查询",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/one")
    public GenericResponse<BaseStore> selectOne(@RequestBody StoreRequest storeRequest) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
       BaseStore baseStore = new BaseStore();
        try {
            baseStore = ssmBaseStoreService.selectOne(storeRequest);
        } catch (Exception e) {
            log.error("SsmBaseStoreController.selectOne", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setData(baseStore);
        return genericResponse;
    }

    @ApiOperation(value = "门店信息修改  平台端-门店管理-门店审核-门店信息修改",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/updateStore")
    public GenericResponse<BaseStore> updateStore(@RequestBody StoreRequest storeRequest, HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        if (StringUtils.isBlank(storeRequest.getRegistrant())) {
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "注册人");
            return genericResponse;
        }
        if (StringUtils.isBlank(storeRequest.getRegistrantMobilePhone())) {
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "注册人手机");
            return genericResponse;
        }
        if (!CommonUtils.isMobile(storeRequest.getRegistrantMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.NOT_MEET_REQUIREMENTS_S,"注册人手机");
            return genericResponse;
        }
//        if (StringUtils.isBlank(storeRequest.getTelephone())) {
//            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "门店服务电话");
//            return genericResponse;
//        }
//        if (StringUtils.isNotBlank(storeRequest.getTelephone()) && !CommonUtils.isTelephone(storeRequest.getTelephone())){
//            genericResponse.setCodeAndMsg(ResponseCode.NOT_MEET_REQUIREMENTS_S,"门店服务电话");
//            return genericResponse;
//        }
        if (StringUtils.isBlank(storeRequest.getStoreName())) {
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "门店名称");
            return genericResponse;
        }
        if (StringUtils.isBlank(storeRequest.getStoreNum())) {
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "门店编码");
            return genericResponse;
        }
        String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.updateStore(storeRequest, userNum);
        } catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e) {
            log.error("SsmBaseStoreController.updateStore", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "门店审核  平台端-门店管理-门店审核-审核",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/auditStore")
    public GenericResponse<BaseStore> auditStore(@RequestBody StoreRequest storeRequest, HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
       String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.auditStore(storeRequest, userNum);
        } catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e) {
            log.error("SsmBaseStoreController.auditStore", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "门店反审核  平台端-门店管理-门店审核-反审核",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/unauditStore")
    public GenericResponse<BaseStore> unauditStore(@RequestBody StoreRequest storeRequest, HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.unauditStore(storeRequest, userNum);
        } catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        } catch (Exception e) {
            log.error("SsmBaseStoreController.unauditStore", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }


    @ApiOperation(value = "门店启用  平台端-门店管理-门店启用",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/start")
    public GenericResponse<BaseStore> start(@RequestBody StoreRequest storeRequest, HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.start(storeRequest, userNum);
        } catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        } catch (Exception e) {
            log.error("SsmBaseStoreController.start", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "门店停用  平台端-门店管理-门店停用",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/stop")
    public GenericResponse<BaseStore> stop(@RequestBody StoreRequest storeRequest, HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.stop(storeRequest, userNum);
        } catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        } catch (Exception e) {
            log.error("SsmBaseStoreController.stop", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "查询所有门店 平台端-门店管理-查询所有门店",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/list")
    public GenericResponse<BaseStore> list(@RequestBody StoreRequest storeRequest) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        BaseStore baseStore = new BaseStore();
        BeanUtils.copyProperties(storeRequest, baseStore);
        List<BaseStore> list = new ArrayList<>();
        try {
            list = ssmBaseStoreService.select(baseStore);
        } catch (Exception e) {
            log.error("SsmBaseStoreController.list", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setRows(list);
        return genericResponse;
    }

    @ApiOperation(value = "查询所有门店 平台端-门店管理-查询所有门店",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/listAll")
    public GenericResponse<BaseStore> listAll() {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        List<BaseStore> list = new ArrayList<>();
        try {
            list = ssmBaseStoreService.selectAll();
        } catch (Exception e) {
            log.error("SsmBaseStoreController.listAll", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setRows(list);
        return genericResponse;
    }



    @ApiOperation(value = "查询所有门店 平台端-门店管理-查询所有门店",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/lists")
    public GenericResponse<BaseStore> lists(@RequestBody StoreRequest storeRequest) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        BaseStore baseStore = new BaseStore();
        BeanUtils.copyProperties(storeRequest, baseStore);
        baseStore.setRegistrantMobilePhone(AESUtils.encrypt(storeRequest.getRegistrantMobilePhone()));
        List<BaseStore> list = new ArrayList<>();
        try {
            list = ssmBaseStoreService.selects(baseStore);
        } catch (Exception e) {
            log.error("SsmBaseStoreController.list", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setRows(list);
        return genericResponse;
    }

    @ApiOperation(value = "门店添加短信信息  平台端-门店管理-门店审核-门店添加短信信息",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/addSms")
    public GenericResponse<BaseStore> addSms(@RequestBody StoreRequest storeRequest, HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.addSms(storeRequest);
        } catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e) {
            log.error("SsmBaseStoreController.addSms", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "门店审核失败更新状态和原因  平台端-门店管理-门店审核-门店审核失败更新状态和原因",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/auditFiled")
    public GenericResponse<BaseStore> auditFiled(@RequestBody StoreRequest storeRequest, HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.auditFiled(storeRequest, userNum);
        }catch (Exception e) {
            log.error("SsmBaseStoreController.auditFiled", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "门店获取门店信息二维码  平台端-门店管理-门店获取门店信息二维码",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping(value = "/getQrCode", produces = MediaType.IMAGE_PNG_VALUE)
    public byte[] getQrCode(@RequestBody StoreRequest storeRequest, HttpServletResponse response) {
        BaseStore baseStore = new BaseStore();
        byte[] bytes = new byte[0];
        try {
            baseStore = ssmBaseStoreService.selectByPrimaryKey(storeRequest.getId());
            String content = baseStore.getId() + "-" + baseStore.getStoreName();
            bytes = QRCodeUtil.encode(content, null, false, false);
        }catch (Exception e) {
            log.error("SsmBaseStoreController.getQrCode", e);
        }
        return bytes;
    }

    @ApiOperation(value = "分页查询门店信息  平台端-门店管理-门店审核-分页查询门店信息",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/pages")
    public PageResponse<BaseStores> selectPages(@RequestBody StoreRequest storeRequest){
        PageResponse<BaseStores> pageResponse = new PageResponse<>();
        PageInfo<BaseStores> pageInfo = new PageInfo<>();
        try {
            pageInfo = ssmBaseStoreService.selectPages(storeRequest);
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setPageInfo(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    @ApiOperation(value = "分页查询门店信息  平台端-门店管理-门店审核-分页查询门店信息",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/pagesparent")
    public PageResponse<BaseStores> pagesparent(@RequestBody StoreRequest storeRequest){
        PageResponse<BaseStores> pageResponse = new PageResponse<>();
        PageInfo<BaseStores> pageInfo = new PageInfo<>();
        try {
            pageInfo = ssmBaseStoreService.pagesparent(storeRequest);
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setPageInfo(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    @ApiOperation(value = "查询当前门店总店的所有分店",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/organization")
    public GenericResponse<BaseStores> organization(@RequestBody StoreRequest storeRequest, HttpSession session){
        GenericResponse<BaseStores> genericResponse = new GenericResponse<>();
        storeRequest.setId(SessionHelp.getStoreId(session));
        List<BaseStores> pageInfo = new ArrayList<>();
        try {
            pageInfo = ssmBaseStoreService.pagesorganizationim(storeRequest);
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setRows(pageInfo);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "查询当前门店总店的所有分店",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/pagesorganizations")
    public GenericResponse<BaseStores> pagesorganizations(@RequestBody StoreRequest storeRequest, HttpSession session){
        GenericResponse<BaseStores> genericResponse = new GenericResponse<>();
        storeRequest.setId(SessionHelp.getStoreId(session));
        List<BaseStores> pageInfo = new ArrayList<>();
        List<BaseStores> baseStores1 = new ArrayList<>();
        try {
            pageInfo = ssmBaseStoreService.pagesorganizations(storeRequest);
            if(pageInfo==null||pageInfo.size()==0){
                genericResponse.setCodeAndMsg(ResponseCode.MSG,"门店不存在");
                return genericResponse;
            }
            List<String> collect = pageInfo.stream().map(item -> item.getStoreNum()).collect(Collectors.toList());
            String [] objects = collect.toArray(new String[collect.size()]);
            Arrays.sort(objects,String.CASE_INSENSITIVE_ORDER);
            HashSet<String> hashSet = new HashSet<>();

            for (int i = 0; i < objects.length; i++) {
                if(hashSet.add(objects[i])){
                    for (BaseStores baseStore : pageInfo) {
                        if(objects[i].equals(baseStore.getStoreNum())){
                            baseStores1.add(baseStore);
                        }
                    }
                }
            }
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setRows(baseStores1);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "查询当前门店总店的所有分店",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/selectByStore")
    public GenericResponse<BaseStores> selectByStore(@RequestBody StoreRequest storeRequest, HttpSession session){
        GenericResponse<BaseStores> genericResponse = new GenericResponse<>();
        storeRequest.setId(SessionHelp.getStoreId(session));
        List<BaseStores> pageInfo = new ArrayList<>();
        List<BaseStores> baseStores1 = new ArrayList<>();
        try {
            pageInfo = ssmBaseStoreService.selectByStore(storeRequest);
            List<String> collect = pageInfo.stream().map(item -> item.getStoreNum()).collect(Collectors.toList());
            String [] objects = collect.toArray(new String[collect.size()]);
            Arrays.sort(objects,String.CASE_INSENSITIVE_ORDER);
            HashSet<String> hashSet = new HashSet<>();

            for (int i = 0; i < objects.length; i++) {
                if(hashSet.add(objects[i])){
                    for (BaseStores baseStore : pageInfo) {
                        if(objects[i].equals(baseStore.getStoreNum())){
                            baseStores1.add(baseStore);
                        }
                    }
                }
            }
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setRows(baseStores1);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }


    @ApiOperation(value = "查询当前门店的总店",httpMethod = "POST",notes = "",response = PageResponse.class)
    @RequestMapping("/pagesorganizationone")
    public GenericResponse<StoreParament> pagesorganizationone(@RequestBody StoreRequest storeRequest, HttpSession session){
        GenericResponse<StoreParament> genericResponse = new GenericResponse<>();
        storeRequest.setId(SessionHelp.getStoreId(session));
        List<StoreParament> storeParaments=new ArrayList<>();


        try {
            BaseStores pageInfo = ssmBaseStoreService.pagesorganizationone(storeRequest);
            storeParaments = ssmStoreParaService.list1(pageInfo.getId());
        }catch (Exception e){
            log.error("SsmBaseStoreController.selectPage", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setRows(storeParaments);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店短信详细重发  平台端-门店管理-门店审核-门店短信详细重发",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/again")
    public GenericResponse<BaseStore> again(@RequestBody StoreRequest storeRequest, HttpSession session) {
        GenericResponse<BaseStore> genericResponse = new GenericResponse<>();
        String userNum = SessionHelp.getLoginAccount(session);
        int i = 0;
        try {
            i = ssmBaseStoreService.again(storeRequest);
        } catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e) {
            log.error("SsmBaseStoreController.again", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }

    @ApiOperation(value = "查询所有门店 平台端-门店管理-查询所有门店",httpMethod = "POST",notes = "",response = GenericResponse.class)
    @RequestMapping("/listByPage")
    public PageResponse<BaseStore> listByPage(@RequestBody StoreRequest storeRequest) {
        PageResponse<BaseStore> genericResponse = new PageResponse<>();
        PageInfo<BaseStore> list = new PageInfo<>();
        try {
            list = ssmBaseStoreService.PageResponse(storeRequest);
        } catch (Exception e) {
            log.error("SsmBaseStoreController.list", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setPageInfo(list);
        return genericResponse;
    }

}
