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

import cn.hutool.core.util.StrUtil;
import cn.xluobo.business.sc.salary.repo.model.StaffSalaryBase;
import cn.xluobo.business.sc.salary.service.StaffSalaryBaseService;
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("staffSalaryBase")
@AllArgsConstructor
public class StaffSalaryBaseController {

    private final StaffSalaryBaseService baseService;

    @PostMapping("list")
    public AjaxResult list(@RequestBody Map<String,Object> params){
        RespPage<StaffSalaryBase> page = new RespPage<>((Integer) params.get("pageNum"), (Integer) params.get("pageSize"));
        RespPage<StaffSalaryBase> result = baseService.page(page, Wrappers.<StaffSalaryBase>lambdaQuery()
                .eq(StrUtil.isNotEmpty((CharSequence) params.get("salaryBaseName")), StaffSalaryBase::getSalaryBaseName, params.get("salaryBaseName"))
                .eq(StrUtil.isNotEmpty((CharSequence) params.get("staffName")), StaffSalaryBase::getStaffName, params.get("staffName"))
        );
        return AjaxResult.success(result);
    }

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

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