package com.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.manage.response.PageResponse;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.entity.PromotionMember;
import com.ssm.manage.query.PromotionListRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmPromotionMemberService;
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.RestController;

import javax.servlet.http.HttpSession;

@Api(value = "促销活动指定会员Controller",tags = {"促销活动指定会员相关接口"})
@RestController
@RequestMapping("/demay/ssm/promotionMem")
@Slf4j
public class SsmPromotionMemberController {
    @Autowired
    private SsmPromotionMemberService ssmPromotionMemberService;

    @ApiOperation(value = "分页查询  门店端-促销活动-分页查询促销活动指定会员数据", httpMethod = "POST", response = PageResponse.class)
    @RequestMapping("/page")
    public PageResponse selectPage(@RequestBody PromotionListRequest promotionListRequest, HttpSession session) {
        PageResponse<PromotionMember> pageResponse = new PageResponse<>();
        PageInfo<PromotionMember> pageInfo = new PageInfo<>();
        promotionListRequest.setStoreId(SessionHelp.getStoreId(session));
        try {
            pageInfo = ssmPromotionMemberService.selectPage(promotionListRequest);
        } catch (Exception e) {
            log.error("SsmPromotionMemberController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }
}
