package com.ssm.controller;

import com.ssm.core.bean.GenericResponse;
import com.ssm.core.util.SessionHelp;
import com.ssm.manage.extendEntity.NegativeDayStatistic;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmNegativeCardService;
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.ArrayList;
import java.util.List;

@Api(value="负卡金统计controller",tags={"负卡金统计controller相关接口"})
@RequestMapping("/demay/ssm/negativeCard")
@RestController
@Slf4j
public class SsmNegativeCardController {

    @Autowired
    private SsmNegativeCardService ssmNegativeCardService;

    @ApiOperation(value = "当日负卡金记录查询", notes = "门店统计报表-当日负卡金记录查询", response = GenericResponse.class)
    @RequestMapping(path="/dayStatistic", method= RequestMethod.POST)
    public GenericResponse dayStatistic(@RequestBody NegativeDayStatistic negativeDayStatistic) {
        GenericResponse<NegativeDayStatistic> genericResponse = new GenericResponse<>();
        List<NegativeDayStatistic> list = new ArrayList<>();
//        Long storeId = SessionHelp.getStoreId(session);
        try{
            list = ssmNegativeCardService.selectDayList(negativeDayStatistic.getStoreId(), negativeDayStatistic.getDate());
        }catch (Exception e){
            log.error("SsmNegativeCardController.dayStatistic:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }

        genericResponse.setRows(list);
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        return genericResponse;
    }


    @ApiOperation(value = "选择日期进行负卡金记录添加", notes = "平台端-选择日期进行负卡金记录添加", response = GenericResponse.class)
    @RequestMapping(path="/saveNegative", method= RequestMethod.POST)
    public GenericResponse saveNegative(@RequestBody NegativeDayStatistic negativeDayStatistic) {
        GenericResponse genericResponse = new GenericResponse<>();
        int i = 0;
//        Long storeId = SessionHelp.getStoreId(session);
        try{
            i = ssmNegativeCardService.saveNegativeRecord(negativeDayStatistic.getDate());
        }catch (Exception e){
            log.error("SsmNegativeCardController.saveNegative:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }
}
