package com.hzs.bonus.bonus.controller.manage;


import cn.hutool.core.collection.CollectionUtil;
import com.hzs.bonus.bonus.param.CuMemberShareBonusParam;
import com.hzs.bonus.bonus.service.ICuMemberShareBonusService;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 会员奖金-分红奖金配置 前端控制器
 * </p>
 *
 * @author hzs
 * @since 2023-07-03
 */
@RestController
@RequestMapping("/manage/bonus")
public class CuMemberShareBonusController extends BaseController {

    private ICuMemberShareBonusService cuMemberShareBonusService;

    @Autowired
    public void setCuMemberShareBonusService(ICuMemberShareBonusService cuMemberShareBonusService) {
        this.cuMemberShareBonusService = cuMemberShareBonusService;
    }

    /**
     * 查询某个月的分红配置
     * @return AjaxResult
     */
    @PostMapping("/query-share-bonus")
//    @Log(module = EOperationModule.SPECIAL_BUSINESS, method = EOperationMethod.UPDATE)
    public AjaxResult queryShareBonus(@RequestBody CuMemberShareBonusParam cuMemberShareBonusParam) {
        if(cuMemberShareBonusParam.getSettleMonth() == null){
            return AjaxResult.error("结算月份不能为空");
        }
        return AjaxResult.success(cuMemberShareBonusService.queryCuMemberShareBonus(SecurityUtils.getPkCountry(), cuMemberShareBonusParam.getSettleMonth()));
    }

    /**
     * 查询某个月的分红配置
     * @return AjaxResult
     */
    @PostMapping("/save-share-bonus")
//    @Log(module = EOperationModule.SPECIAL_BUSINESS, method = EOperationMethod.UPDATE)
    public AjaxResult saveShareBonus(@RequestBody CuMemberShareBonusParam cuMemberShareBonusParam) {
        if(cuMemberShareBonusParam.getSettleMonth() == null || CollectionUtil.isEmpty(cuMemberShareBonusParam.getCuMemberShareDetailList())){
            return AjaxResult.error("结算月份不能为空");
        }
        cuMemberShareBonusParam.setPkCountry(SecurityUtils.getPkCountry());
        cuMemberShareBonusParam.setPkCreator(SecurityUtils.getUserId());
        cuMemberShareBonusService.saveMemberShareBonus(cuMemberShareBonusParam);
        return AjaxResult.success();
    }
}
