package cn.xluobo.business.sc.salary.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.xluobo.business.sc.salary.repo.model.ScCommissionPlans;
import cn.xluobo.business.sc.salary.service.ScCommissionPlansService;
import cn.xluobo.core.page.RespPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.AllArgsConstructor;
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;

import java.util.Map;

@RestController
@RequestMapping("commissionPlans")
@AllArgsConstructor
public class ScCommissionPlansController {

    private final ScCommissionPlansService service;

    @PostMapping("list")
    public AjaxResult list(@RequestBody Map<String,Object> params){
        RespPage<ScCommissionPlans> page = new RespPage<>((Integer) params.get("pageNum"), (Integer) params.get("pageSize"));
        RespPage<ScCommissionPlans> page1 = service.page(page, Wrappers.<ScCommissionPlans>lambdaQuery()
                .eq(StrUtil.isNotEmpty((CharSequence) params.get("planName")),
                        ScCommissionPlans::getPlanName, params.get("planName"))
                .eq(ObjectUtil.isNotEmpty(params.get("isActive")), ScCommissionPlans::getIsActive, params.get("isActive"))
        );
        return AjaxResult.success(page1);
    }

    @PostMapping("saveOrEdit")
    public AjaxResult saveOrEdit(@RequestBody ScCommissionPlans salaryBase){
        service.saveOrUpdate(salaryBase);
        return AjaxResult.success();
    }

    @PostMapping("remove")
    public AjaxResult remove(Integer id){
        service.removeById(id);
        return AjaxResult.success();
    }

}
