package com.ssm.controller;

import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.entity.*;
import com.ssm.manage.query.MemberRequest;
import com.ssm.manage.query.StaffRequest;
import com.ssm.manage.query.StoreRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.response.StaffResponse;
import com.ssm.manage.service.SsmBaseStoreService;
import com.ssm.manage.service.SsmStaffLoginService;
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.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Api(value = "门店员工登录controller",tags = {"门店员工登录相关接口"})
@RequestMapping("/demay/ssm/staffLogin")
@RestController
@Slf4j
public class SsmStaffLoginController extends SsmSysBaseController{

    public static final int MAX_INACTIVE_INTERVAL = 60 * 60 * 24;
    @Autowired
    public SsmStaffLoginService ssmStaffLoginService;

    @Autowired
    private SsmBaseStoreService ssmBaseStoreService;


/*    @ApiOperation(value = "门店员工账户登陆获取token接口", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/accountLogin", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> accountLogin(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        try{
            staffResponse = ssmStaffLoginService.accountLogin(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.accountLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmLoginController.accountLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        SessionHelp.setToken(session,staffResponse.getToken());
        SessionHelp.setLoginAccount(session,staffResponse.getStaffNum());
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }*/


    @ApiOperation(value = "门店员工手机验证码登陆获取token接口", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phoneLogin", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> phoneLogin(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        if (StringUtils.isBlank(staffRequest.getPassCode())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"验证码");
            return genericResponse;
        }
        try{
            staffResponse = ssmStaffLoginService.phoneLogin(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phoneLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phoneLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        SessionHelp.setToken(session,staffResponse.getToken());
        SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
        SessionHelp.setStoreId(session,staffResponse.getStoreId());
        SessionHelp.setStoreName(session,staffRequest.getStoreName());
        session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
        StoreRequest storeRequest = new StoreRequest();
        List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
        List<Long> objects = new ArrayList<>();
        for (BaseStores pagesorganization : pagesorganizations) {
            objects.add(pagesorganization.getId());
        }
        SessionHelp.setStoreIds(objects);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店员工获取手机短信验证码接口", notes = "用户获取手机短信验证码接口", response = GenericResponse.class)
    @RequestMapping(path="/getSmsCode", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> getSmsCode(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
//        staffRequest.setStoreId(SessionHelp.getStoreId(session));
        try{
            staffResponse = ssmStaffLoginService.getSmsCode(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.getSmsCode:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.getSmsCode:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        //genericResponse.setData(staffResponse);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店修改支付密码获取手机短信验证码接口", notes = "用户修改支付密码获取手机短信验证码接口", response = GenericResponse.class)
    @RequestMapping(path="/getCode", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> getCode(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        staffRequest.setStoreId(SessionHelp.getStoreId(session));
        try{
            staffResponse = ssmStaffLoginService.getCode(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.getSmsCode:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.getSmsCode:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        //genericResponse.setData(staffResponse);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }


    @ApiOperation(value = "门店员工修改密码接口", notes = "用户修改密码接口", response = String.class)
    @RequestMapping(path="/changePassword", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> changePassword(@RequestBody StaffRequest staffRequest,HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        String phone = SessionHelp.getLoginAccount(session);
        SessionHelp.getLoginAccount(session);
        staffRequest.setMobilePhone(phone);
        SessionHelp.getLoginAccount(session);
        int i = 0;
        try{
            i = ssmStaffLoginService.changePassword(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.changePassword:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.changePassword:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店获取员工登录密码短信", notes = "员工获取登录密码接口", response = GenericResponse.class)
    @RequestMapping(path="/getPsw", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> getPsw(StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        staffRequest.setStoreId(SessionHelp.getStoreId(session));
        staffRequest.setMobilePhone(SessionHelp.getLoginAccount(session));
        int i=0 ;
        try{
            i = ssmStaffLoginService.getPsw(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.getSmsCode:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.getSmsCode:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (i <= 0){
            genericResponse.setCodeAndMsg(ResponseCode.MSG,"获取密码失败");
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }



    @ApiOperation(value = "门店员工手机密码登陆获取token接口", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phonePassLogin", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> phonePassLogin(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        if (StringUtils.isBlank(staffRequest.getPassword())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"密码");
            return genericResponse;
        }
        try{
            staffResponse = ssmStaffLoginService.phonePassLogin(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        SessionHelp.setToken(session,staffResponse.getToken());
        SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
        SessionHelp.setStoreId(session,staffResponse.getStoreId());
        SessionHelp.setStoreName(session,staffResponse.getStoreName());
        session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }



    @ApiOperation(value = "退出登录",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/logout")
    public GenericResponse logout (HttpSession session){
        GenericResponse genericResponse = new GenericResponse();
        StaffRequest staffRequest = new StaffRequest();
        staffRequest.setMobilePhone(SessionHelp.getLoginAccount(session));
        try {
            ssmStaffLoginService.logout(staffRequest,session);
        }catch (Exception e){
            log.error("SsmStaffLoginController.logout",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }


    @ApiOperation(value = "通过手机号查询员工所属门店",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/list")
    public GenericResponse list (@RequestBody StaffRequest staffRequest){
        GenericResponse genericResponse = new GenericResponse();
        List<BaseStaff> list = new ArrayList<>();
        try {
            list = ssmStaffLoginService.list(staffRequest);
        }catch (Exception e){
            log.error("SsmStaffLoginController.list",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setRows(list);
        return genericResponse;
    }

    @ApiOperation(value = "通过手机号查询登录员工所属门店",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/lists")
    public GenericResponse lists(@RequestBody StaffRequest staffRequest){
        GenericResponse genericResponse = new GenericResponse();
        List<StaffRequest> list = new ArrayList<>();
        try {
            list = ssmStaffLoginService.listlogin(staffRequest);
        }catch (Exception e){
            log.error("SsmStaffLoginController.list",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setRows(list);
        return genericResponse;
    }

    @ApiOperation(value = "门店员工手机短信获取密码接口", notes = "用户获取手机短信密码接口", response = GenericResponse.class)
    @RequestMapping(path="/getSmsCodesPassword", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> getSmsCodesPassword(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
//        staffRequest.setStoreId(SessionHelp.getStoreId(session));
        try{
            staffResponse = ssmStaffLoginService.getSmsCodepassword(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.getSmsCode:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.getSmsCode:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "总店登录查询门店",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/selectHeadOffice")
    public GenericResponse<BaseStores> selectHeadOffice(@RequestBody StaffRequest staffRequest){
        GenericResponse<BaseStores> pageResponse = new GenericResponse<>();
        List<StaffRequest> list = new ArrayList<>();
        try {
            list = ssmStaffLoginService.listlogin(staffRequest);
        }catch (Exception e){
            log.error("SsmStaffLoginController.list",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        boolean ifzd=true;
        //总店ID
        List<Long> strotId = new ArrayList<>();
        if(list.size()>0){
            for (StaffRequest request : list) {
                if(null == request.getParentId()){
                    ifzd=false;
                    //获取总店ID
                    strotId.add(request.getStoreId());
                }
            }
        }
        List<BaseStores> pagesorganization = new ArrayList<>();
        if(ifzd){
            pageResponse.setCodeAndMsg(ResponseCode.FAILEDZD);
            return pageResponse;
        }else{
            for (Long stores : strotId) {
                StoreRequest storeRequest = new StoreRequest();
                storeRequest.setId(stores);
                try {
                    List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
                    for (BaseStores baseStores : pagesorganizations) {
                        pagesorganization.add(baseStores);
                    }
//                    for (BaseStores baseStores : pagesorganization) {
//                        baseStores.setReason(String.valueOf(strotId));
//                    }
                }catch (Exception e){
                    log.error("SsmBaseStoreController.selectPage", e);
                    pageResponse.setCodeAndMsg(ResponseCode.FAILED);
                    return pageResponse;
                }
            }
        }
        pageResponse.setRows(pagesorganization);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    @ApiOperation(value = "总店登录手机密码登陆获取token接口", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phonePassLoginzd", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> phonePassLoginZD(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        if (StringUtils.isBlank(staffRequest.getPassword())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"密码");
            return genericResponse;
        }
        try{
            staffResponse = ssmStaffLoginService.phonePassLoginzd(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        SessionHelp.setToken(session,staffResponse.getToken());
        SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
        SessionHelp.setStoreId(session,staffResponse.getStoreId());
        SessionHelp.setStoreName(session,staffResponse.getStoreName());
        session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店员工手机密码登陆获取token接口(新的登录)", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phonePassLoginNew", method= RequestMethod.POST)
    //todo
    public GenericResponse<StaffResponse> phonePassLoginNew(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        if (StringUtils.isBlank(staffRequest.getPassword())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"密码");
            return genericResponse;
        }
        try{
            staffResponse = ssmStaffLoginService.phonePassLoginNew(staffRequest);

        }catch (SmsException e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        if(staffResponse.getStoreType()==2){
            SessionHelp.setToken(session,staffResponse.getToken());
            SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
            SessionHelp.setStoreId(session,staffResponse.getStoreId());
            SessionHelp.setStoreName(session,staffResponse.getStoreName());
            session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店员工手机密码登陆获取token接口（总店登录，选择完门店）(新的登录)", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phonePassLoginNews", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> phonePassLoginNews(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        if (StringUtils.isBlank(staffRequest.getPassword())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"密码");
            return genericResponse;
        }
        try{
            staffResponse = ssmStaffLoginService.phonePassLoginNews(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        if(staffResponse.getStoreType()==2){
            SessionHelp.setToken(session,staffResponse.getToken());
            SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
            SessionHelp.setStoreId(session,staffResponse.getStoreId());
            SessionHelp.setStoreName(session,staffResponse.getStoreName());
            session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }


    @ApiOperation(value = "登录门店获得门店信息  登录门店端-选择登录门店-获取门店信息",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/storeList")
    public GenericResponse storeList(@RequestBody BaseStore baseStore){
        GenericResponse genericResponse = new GenericResponse();
        BaseStore baseStore1=new BaseStore();
        try {
            baseStore1 = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());
        }catch (Exception e){
            log.error("SsmStoreParaController.list",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setData(baseStore1);
        return genericResponse;
    }

    @ApiOperation(value = "门店登录获取动态密码", notes = "用户修改支付密码获取手机短信验证码接口", response = GenericResponse.class)
    @RequestMapping(path="/getDynamicPsw", method= RequestMethod.POST)
    public GenericResponse getDynamicPsw(@RequestBody BaseStore baseStore ) {
        GenericResponse genericResponse = new GenericResponse<>();
        int i=0;
        try{
            i = ssmStaffLoginService.getDynamicPsw(baseStore);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.getDynamicPsw:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.getDynamicPsw:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (i == 0){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店员工动态密码登录获取token接口（总店登录，选择完门店）(新的登录)", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/DynamicLoginNews", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> DynamicLoginNews(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        boolean check=false;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        if (StringUtils.isBlank(staffRequest.getDynamicPsw())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"动态密码");
            return genericResponse;
        }
        try{
            check = ssmStaffLoginService.DynamicphonePassLoginNews(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (check == false){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }



    @ApiOperation(value = "门店员工手机密码登陆获取token接口（总店登录，选择完门店）(新的登录)", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phonePassLogindzz", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> phonePassLogindzz(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        if (StringUtils.isBlank(staffRequest.getPassword())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"密码");
            return genericResponse;
        }
        try{
            staffResponse = ssmStaffLoginService.phonePassLogindzz(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phonePassLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if(staffResponse.getStoreType()==2){
            SessionHelp.setToken(session,staffResponse.getToken());
            SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
            SessionHelp.setStoreId(session,staffResponse.getStoreId());
            SessionHelp.setStoreName(session,staffResponse.getStoreName());
            session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
        }
        genericResponse.setData(staffResponse);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店员工手机验证码登陆获取token接口(新登录)", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phoneLoginNew", method= RequestMethod.POST)
    // todo
    public GenericResponse<StaffResponse> phoneLoginNew(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        if (StringUtils.isBlank(staffRequest.getPassCode())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"验证码");
            return genericResponse;
        }
        try{

            staffResponse = ssmStaffLoginService.phoneLoginNew(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phoneLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phoneLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        if (staffResponse.getStoreType() != null)
        if(staffResponse.getStoreType()==2){
            SessionHelp.setToken(session,staffResponse.getToken());
            SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
            SessionHelp.setStoreId(session,staffResponse.getStoreId());
            SessionHelp.setStoreName(session,staffResponse.getStoreName());
            session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
        }

//        StoreRequest storeRequest = new StoreRequest();
//        List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
//        List<Long> objects = new ArrayList<>();
//        for (BaseStores pagesorganization : pagesorganizations) {
//            objects.add(pagesorganization.getId());
//        }
//        SessionHelp.setStoreIds(objects);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店员工手机验证码登陆获取token接口,多组织选择组织(新登录)", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phoneLoginNewzz", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> phoneLoginNewzz(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        try{
            staffResponse = ssmStaffLoginService.phoneLoginNewzz(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phoneLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phoneLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        SessionHelp.setToken(session,staffResponse.getToken());
        SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
        SessionHelp.setStoreId(session,staffResponse.getStoreId());
        SessionHelp.setStoreName(session,staffRequest.getStoreName());
        session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);

//        StoreRequest storeRequest = new StoreRequest();
//        List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
//        List<Long> objects = new ArrayList<>();
//        for (BaseStores pagesorganization : pagesorganizations) {
//            objects.add(pagesorganization.getId());
//        }
//        SessionHelp.setStoreIds(objects);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }

    @ApiOperation(value = "门店员工手机验证码登陆获取token接口,多组织选择组织(新登录)", notes = "获取登录接口生成的token 使用接口前必须获取一次。作为参数传入", response = GenericResponse.class)
    @RequestMapping(path="/phoneLoginNews", method= RequestMethod.POST)
    public GenericResponse<StaffResponse> phoneLoginNews(@RequestBody StaffRequest staffRequest, HttpSession session) {
        GenericResponse<StaffResponse> genericResponse = new GenericResponse<>();
        StaffResponse staffResponse = null;
        if (StringUtils.isBlank(staffRequest.getMobilePhone())){
            genericResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S,"手机号");
            return genericResponse;
        }
        try{
            staffResponse = ssmStaffLoginService.phoneLoginNews(staffRequest);
        }catch (SmsException e){
            log.error("SsmStaffLoginController.phoneLogin:", e);
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.phoneLogin:", e);
            genericResponse.setCodeAndMsg(ResponseCode.UNKNOWN_SYSTEM_EXCEPTION);
            return genericResponse;
        }
        if (staffResponse == null){
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setData(staffResponse);
        SessionHelp.setToken(session,staffResponse.getToken());
        SessionHelp.setLoginAccount(session,staffRequest.getMobilePhone());
        SessionHelp.setStoreId(session,staffResponse.getStoreId());
        SessionHelp.setStoreName(session,staffRequest.getStoreName());
        session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);

//        StoreRequest storeRequest = new StoreRequest();
//        List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
//        List<Long> objects = new ArrayList<>();
//        for (BaseStores pagesorganization : pagesorganizations) {
//            objects.add(pagesorganization.getId());
//        }
//        SessionHelp.setStoreIds(objects);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }


    @ApiOperation(value = "门店会员支付密码修改验证  会员端-门店会员支付密码修改验证",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/chekeMsg")
    public GenericResponse chekeMsg(@RequestBody MemberRequest memberRequest, HttpSession session){
        GenericResponse<StoreMemberList> genericResponse = new GenericResponse<>();
        memberRequest.setStoreId(SessionHelp.getStoreId(session));
        boolean i=false;
        try {
             i = ssmStaffLoginService.chekeMsg(memberRequest);
        }catch (SmsException e){
            genericResponse.setCodeAndMsg(e);
            return genericResponse;
        }catch (Exception e){
            log.error("SsmStaffLoginController.chekeMsg:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i==true) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }


}
