package com.hzs.member.storeconfig.controller.manager;/**
 * @Description:
 * @Author: yuhui
 * @Time: 2024/4/3 11:48
 * @Classname: BdStoreMonthCheckConfigController
 * @PackageName: com.hzs.member.storeconfig.controller
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.member.storeconfig.BdStoreMonthCheckConfig;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.member.store.vo.CuStoreVO;
import com.hzs.member.storeconfig.param.StoreMonthCheckConfigParam;
import com.hzs.member.storeconfig.service.IBdStoreMonthCheckConfigService;
import com.hzs.member.storeconfig.vo.StoreMonthCheckConfigVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *@BelongsProject: hzs_java_cloud_africa
 *@BelongsPackage: com.hzs.member.storeconfig.controller
 *@Author: yh
 *@CreateTime: 2024-04-03  11:48
 *@Description: TODO
 *@Version: 1.0
 */
@RestController
@RequestMapping("/manage/store-month")
public class BdStoreMonthCheckConfigController extends BaseController {

    @Autowired
    private IBdStoreMonthCheckConfigService storeMonthCheckConfigService;

    /**
     * 查询列表
     * @return
     */
    @GetMapping("list")
    public TableDataInfo list(StoreMonthCheckConfigParam storeMonthCheckConfigParam){
        startPage();
        storeMonthCheckConfigParam.setPkCountry(SecurityUtils.getPkCountry());
        List<StoreMonthCheckConfigVo> list =  storeMonthCheckConfigService.selectByList(storeMonthCheckConfigParam);
        return getDataTable(list);
    }


    /**
     * 新增 店铺月度考核设置配置表
     * @return
     */
    @PostMapping("save")
    public AjaxResult save(@RequestBody List<BdStoreMonthCheckConfig> storeMonthCheckConfigList){
        for (BdStoreMonthCheckConfig storeMonthCheckConfig : storeMonthCheckConfigList) {
            storeMonthCheckConfig.setCreationTime(DateUtils.currentDateTime());
            storeMonthCheckConfig.setPkCountry(SecurityUtils.getPkCountry());
            storeMonthCheckConfig.setPkCreator(SecurityUtils.getUserId());
        }
        storeMonthCheckConfigService.insertAll(storeMonthCheckConfigList);
        return AjaxResult.success();
    }

    /**
     * 修改 店铺月度考核设置配置表
     * @return
     */
    @PostMapping("update")
    public AjaxResult update(@RequestBody BdStoreMonthCheckConfig storeMonthCheckConfig){
        storeMonthCheckConfigService.updateById(storeMonthCheckConfig);

        return AjaxResult.success();
    }

    /**
     * 查询 店铺月度考核设置配置表 详情
     */
    @GetMapping("detail")
    public AjaxResult detail(Integer pkStoreMonthCheckConfigId){
        BdStoreMonthCheckConfig storeMonthCheckConfig = storeMonthCheckConfigService.getById(pkStoreMonthCheckConfigId);
        return AjaxResult.success(storeMonthCheckConfig);
    }

    /**
     * 删除 店铺月度考核设置配置表
     * @param pkStoreMonthCheckConfigId
     * @return
     */
    @GetMapping("remove")
    public AjaxResult remove(Integer pkStoreMonthCheckConfigId){

        QueryWrapper<BdStoreMonthCheckConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PK_ID",pkStoreMonthCheckConfigId);
        storeMonthCheckConfigService.remove(queryWrapper);
        return AjaxResult.success();
    }

    /**
     * 导出
     * @param storeMonthCheckConfigParam
     */
    @PostMapping("export")
    public void export(StoreMonthCheckConfigParam storeMonthCheckConfigParam, HttpServletResponse response){
        storeMonthCheckConfigParam.setPkCountry(SecurityUtils.getPkCountry());
        List<StoreMonthCheckConfigVo> list =  storeMonthCheckConfigService.selectByList(storeMonthCheckConfigParam);
        ExcelUtil<StoreMonthCheckConfigVo> util = new ExcelUtil<>(StoreMonthCheckConfigVo.class);
        util.exportExcel(response, list, "店铺月度考核设置");
    }
}
