package com.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.manage.response.PageResponse;
import com.ssm.core.util.StrComparatorUtils;
import com.ssm.manage.entity.SysRoleStore;
import com.ssm.manage.query.SysRoleStoreRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmSysRoleStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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.Collections;

@Api(value="1.门店角色关联门店表（新登录）controller",tags={"1.门店角色关联门店（新登录）相关接口"})
@RestController
@Slf4j
@RequestMapping("/demay/ssm/SysRoleStore")
public class SsmSysRoleStoreController {

    @Autowired
    private SsmSysRoleStoreService ssmSysRoleStoreService;

    @ApiOperation(value = "分页获取角色信息  门店端-角色-分页获取角色信息", httpMethod = "POST", response = PageResponse.class, notes = "分页获取菜单信息")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public PageResponse<SysRoleStore> selectByPage(@RequestBody SysRoleStoreRequest sysStoreRole, HttpSession session) {
        PageResponse<SysRoleStore> pageResponse = new PageResponse<>();
        PageInfo<SysRoleStore> pageInfo;
        if (null == sysStoreRole.getRoleId()) {
            pageResponse.setCodeAndMsg(ResponseCode.PARAMETER_NOT_EXIST_S, "角色Id");
            return pageResponse;
        }
        try {
            pageInfo = ssmSysRoleStoreService.selectPage(sysStoreRole);
            Collections.sort(pageInfo.getList(),new StrComparatorUtils<>("storeNum",false));
        } catch (Exception e) {
            log.error("SsmSysRoleController.selectPage:", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }


}
