package com.kiisoo.ic.store.controller;

import com.github.pagehelper.PageInfo;
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.store.entity.StorePromotionDataDO;
import com.kiisoo.ic.store.service.StoreEmployeeService;
import com.kiisoo.ic.store.service.StorePromotionDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author yunjie.jiang
 * @date 2020/4/10 10:49
 * @company kiisoo
 * @details 门店推广数据controller
 */
@Controller
@RequestMapping("/store/promotion/data")
@Slf4j
public class StorePromotionDataController extends BaseController {

    /**
     * 推广数据数据
     */
    @Autowired
    private StorePromotionDataService storePromotionDataService;

    /**
     * 查询门店推广数据列表
     * @param userId
     * @param storeId
     * @param regionId
     * @param sellerId
     * @param startDate
     * @param endDate
     * @param type 页面类型 "region".区域, "store".门店, "seller".导购
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> listStorePromotionData(@RequestParam("userId") Long userId,
                                                     @RequestParam(value = "storeId", required = false) Long storeId,
                                                     @RequestParam(value = "regionId", required = false) Long regionId,
                                                     @RequestParam(value = "sellerId", required = false) Long sellerId,
                                                     @RequestParam(value = "startDate", required = false) Date startDate,
                                                     @RequestParam(value = "endDate", required = false) Date endDate,
                                                     @RequestParam("type") String type,
                                                     @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                                                     @RequestParam(value = "pageSize", required = false, defaultValue = "15") int pageSize){
        try {
            PageInfo<StorePromotionDataDO> storePromotionDataDOS = storePromotionDataService.listStorePromotionData(userId, storeId,
                    regionId, sellerId, startDate, endDate, type, pageNum, pageSize);
            return data(storePromotionDataDOS);
        }catch (Exception e){
            log.error("查询门店推广数据列表",e);
            return fail();
        }
    }

    /**
     * 查询门店推广数据列表 手机端
     * @param userId
     * @param roleCode
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping(value = "list/wx",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> listStorePromotionDataWx(@RequestParam("userId") Long userId,
                                                       @RequestParam("roleCode") String roleCode,
                                                     @RequestParam(value = "startDate", required = false) Date startDate,
                                                     @RequestParam(value = "endDate", required = false) Date endDate,
                                                     @RequestParam(value = "lastStartDate", required = false) Date lastStartDate,
                                                     @RequestParam(value = "lastEndDate", required = false) Date lastEndDate){
        try {
            StorePromotionDataDO storePromotionDataDOS = storePromotionDataService.listStorePromotionDataWx(userId, roleCode, startDate, endDate, lastStartDate,
                    lastEndDate);
            return data(storePromotionDataDOS);
        }catch (Exception e){
            log.error("查询门店推广数据列表",e);
            return fail();
        }
    }
}
