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

import cn.hutool.core.util.StrUtil;
import cn.xluobo.business.sc.salary.repo.model.SalaryBase;
import cn.xluobo.business.sc.salary.service.SalaryBaseService;
import cn.xluobo.core.page.RespPage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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("salary")
@AllArgsConstructor
public class SalaryBaseController {

    private final SalaryBaseService salaryBaseService;

    @PostMapping("listAll")
    public AjaxResult listAll(){
        return AjaxResult.success(salaryBaseService.list());
    }

    @PostMapping("list")
    public AjaxResult list(@RequestBody Map<String,Object> params){
        RespPage<SalaryBase> page = new RespPage<>((Integer) params.get("pageNum"), (Integer) params.get("pageSize"));
        LambdaQueryWrapper<SalaryBase> wrapper = Wrappers.<SalaryBase>lambdaQuery()
                    .eq(StrUtil.isNotEmpty((CharSequence) params.get("name")),SalaryBase::getName, params.get("name")
                );
        RespPage<SalaryBase> page1 = salaryBaseService.page(page, wrapper);
        return AjaxResult.success(page1);
    }

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

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