package com.goafanti.expenseAccount.controller;

import com.goafanti.common.bo.Result;
import com.goafanti.common.controller.CertifyApiController;
import com.goafanti.common.model.ExpenseConfigDetails;
import com.goafanti.common.utils.ParamUtils;
import com.goafanti.expenseAccount.service.ExpenseConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/admin/expenseConfig")
public class ExpenseConfigController extends CertifyApiController {

    @Autowired
    private ExpenseConfigService expenseConfigService;

    /**
     * 新增报销配置人员
     * @param details
     * @return
     */
    @RequestMapping(value = "/addDeTails",method= RequestMethod.POST)
    public Result add(@Validated ExpenseConfigDetails details, BindingResult bindingResult){
        Result res =new Result();
        if (bindingResult.hasErrors()) {
            res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
                    ParamUtils.getParamName(details,bindingResult.getFieldError().getField())));
            return res;
        }
        return  res.data(expenseConfigService.addDeTails(details));
    }

    /**
     *  删除报销配置人员
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteDeTails",method= RequestMethod.POST)
    public Result deleteDeTails(Integer id){
        Result res =new Result();
        return res.data(expenseConfigService.deleteDeTails(id));
    }


}
