package com.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.core.bean.GenericResponse;
import com.ssm.core.bean.PageResponse;
import com.ssm.core.util.SessionHelp;
import com.ssm.manage.entity.BaseStore;
import com.ssm.manage.entity.SmsException;
import com.ssm.manage.query.StoreRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmBaseStoreService;
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.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

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



    @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("/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;
    }
}
