package com.ssm.controller;

import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.entity.DocPromotionProject;
import com.ssm.manage.query.DocPromotionRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmDocPromotionProjectService;
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;
import java.util.ArrayList;
import java.util.List;

@Api(value = "促销活动单据项目controller", tags = {"促销活动单据项目相关接口"})
@RestController
@RequestMapping("/demay/ssm/docPromotionPro")
@Slf4j
public class SsmDocPromotionProController {
    @Autowired
    private SsmDocPromotionProjectService ssmDocPromotionProjectService;

    @ApiOperation(value = "查询促销活动项目  门店端-促销活动-查询促销活动项目", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/list")
    public GenericResponse list(@RequestBody DocPromotionRequest docPromotionRequest, HttpSession session) {
        GenericResponse pageResponse = new GenericResponse();
        docPromotionRequest.setStoreId(SessionHelp.getStoreId(session));
        List<DocPromotionProject> list = new ArrayList<>();
        try {
            list = ssmDocPromotionProjectService.selectList(docPromotionRequest);
        } catch (Exception e) {
            log.error("SsmDocPromotionProController.list", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setRows(list);
        return pageResponse;
    }

    @ApiOperation(value = "查询促销活动项目  门店端-促销活动-查询促销活动项目", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/listNew")
    public GenericResponse listNew(@RequestBody DocPromotionRequest docPromotionRequest, HttpSession session) {
        GenericResponse pageResponse = new GenericResponse();
//        docPromotionRequest.setStoreId(SessionHelp.getStoreId(session));
        List<DocPromotionProject> list = new ArrayList<>();
        try {
            list = ssmDocPromotionProjectService.selectList(docPromotionRequest);
        } catch (Exception e) {
            log.error("SsmDocPromotionProController.list", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setRows(list);
        return pageResponse;
    }
}
