package com.hzs.system.config.controller.manage;


import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.config.service.IBdNoticeConfigService;
import com.hzs.system.config.vo.BdNoticeConfigSecondCategoryVO;
import com.hzs.system.config.vo.BdNoticeConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 公告配置表 前端控制器
 * </p>
 *
 * @author hzs
 * @since 2023-02-02
 */
@RestController
@RequestMapping("/manage/notice-config")
public class BdNoticeConfigController extends BaseController {

    @Autowired
    IBdNoticeConfigService bdNoticeConfigService;


    /**
     * 新增前台配置信息
     *
     * @param bdNoticeConfigVO 配置信息
     * @return AjaxResult
     */
    @PostMapping("save")
    @Log(module = EOperationModule.NOTICE_CONFIG, method = EOperationMethod.INSERT, remark = "保存公告前台配置信息")
    public AjaxResult memberSave(@RequestBody BdNoticeConfigVO bdNoticeConfigVO) {
        bdNoticeConfigVO.setPkCountry(SecurityUtils.getPkCountry());
        bdNoticeConfigVO.setPkMember(SecurityUtils.getUserId());
        return toAjax(bdNoticeConfigService.saveNoticeConfig(bdNoticeConfigVO));
    }


    /**
     * 公告后台配置页面初始化
     *
     * @return AjaxResult
     */
    @GetMapping("show-admin")
    @Log(module = EOperationModule.NOTICE_CONFIG, method = EOperationMethod.SELECT, remark = "公告后台配置页面显示")
    public AjaxResult showAdminList() {
        Integer pkCountry = SecurityUtils.getPkCountry();
        return AjaxResult.success(bdNoticeConfigService.showAdminList(pkCountry));
    }

    /**
     * 新增后台配置信息
     *
     * @param secondCategoryVOList 配置信息
     * @return AjaxResult
     */
    @PostMapping("admin-save")
    @Log(module = EOperationModule.NOTICE_CONFIG, method = EOperationMethod.INSERT, remark = "保存公告后台配置信息")
    public AjaxResult adminSave(@RequestBody List<BdNoticeConfigSecondCategoryVO> secondCategoryVOList) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        Long pkMember = SecurityUtils.getUserId();
        return toAjax(bdNoticeConfigService.saveAdminNoticeConfig(secondCategoryVOList, pkCountry, pkMember));
    }

    /**
     * 前台公告显示
     *
     * @param bdNoticeConfigVO 配置信息
     * @return AjaxResult
     */
    @PostMapping("list")
    @Log(module = EOperationModule.NOTICE_CONFIG, method = EOperationMethod.SELECT)
    public AjaxResult memberList(@RequestBody BdNoticeConfigVO bdNoticeConfigVO) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        bdNoticeConfigVO.setPkCountry(pkCountry);
        return AjaxResult.success(bdNoticeConfigService.getNoticeConfig(bdNoticeConfigVO));
    }


    /**
     * 后台公告显示
     *
     * @return AjaxResult
     */
    @GetMapping("admin-list")
    @Log(module = EOperationModule.NOTICE_CONFIG, method = EOperationMethod.SELECT)
    public AjaxResult adminList() {
        Integer pkCountry = SecurityUtils.getPkCountry();
        return AjaxResult.success(bdNoticeConfigService.getAdminNoticeConfig(pkCountry));
    }

    /**
     * 更新公告前台配置信息
     *
     * @param bdNoticeConfigVO 公告配置信息
     * @return AjaxResult
     */
    @PostMapping("member-update")
    @Log(module = EOperationModule.NOTICE_CONFIG, method = EOperationMethod.INSERT, remark = "更新公告前台配置信息")
    public AjaxResult memberUpdate(@RequestBody BdNoticeConfigVO bdNoticeConfigVO) {
        bdNoticeConfigVO.setPkCountry(SecurityUtils.getPkCountry());
        bdNoticeConfigVO.setPkMember(SecurityUtils.getUserId());
        return toAjax(bdNoticeConfigService.updateMemberNoticeConfig(bdNoticeConfigVO));
    }

    /**
     * 更新公告后台配置信息
     *
     * @param secondCategoryVOList 公告配置信息
     * @return AjaxResult
     */
    @PostMapping("admin-update")
    @Log(module = EOperationModule.NOTICE_CONFIG, method = EOperationMethod.INSERT, remark = "更新公告后台配置信息")
    public AjaxResult adminUpdate(@RequestBody List<BdNoticeConfigSecondCategoryVO> secondCategoryVOList) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        Long pkMember = SecurityUtils.getUserId();
        return toAjax(bdNoticeConfigService.updateAdminNoticeConfig(secondCategoryVOList, pkCountry, pkMember));
    }

    @PostMapping("test")
    @Log(module = EOperationModule.NOTICE_CONFIG, method = EOperationMethod.SELECT)
    public AjaxResult test(@RequestBody BdNoticeConfigVO bdNoticeConfigVO) {
        Integer pkCountry = SecurityUtils.getPkCountry();
        bdNoticeConfigVO.setPkCountry(pkCountry);
        bdNoticeConfigVO.setPkMember(SecurityUtils.getUserId());
        List<Long> list = new ArrayList<>();
        list.add(2L);
        bdNoticeConfigVO.setRoleIds(list);
        bdNoticeConfigVO.setUserId(2L);
        return AjaxResult.success(bdNoticeConfigService.updateNoticeConfigByContent(bdNoticeConfigVO));
    }
}
