package com.zcxk.charge.web.controller;

import com.zcxk.charge.core.entity.ThingyearSettingEntity;
import com.zcxk.charge.web.service.ThingyearSettingService;
import com.zcxk.core.common.pojo.AjaxMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物品年代设置页面控制器
 * @author WYY
 * @date 2020-12-28 15:18
 */
@RestController
@RequestMapping("/thingyearsetting")
@Api(tags = "物品年代设置")
public class ThingyearSettingController {

    @Autowired
    private ThingyearSettingService thingyearSettingService;

    @RequestMapping(value = "/findList",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询集合")
    public AjaxMessage findList(@ApiParam(value = "物品类型(1管网 2窨井 3阀门 4消防栓)", required = true)@RequestParam Integer thingType) {
        ThingyearSettingEntity thingyearSettingEntity = new ThingyearSettingEntity();
        thingyearSettingEntity.setThingType(thingType);
        return AjaxMessage.success(thingyearSettingService.findList(thingyearSettingEntity));
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "新增")
    public  AjaxMessage<Integer> addThingyearSetting(@ApiParam(value = "物品年代统计设置", required = true) @RequestBody ThingyearSettingEntity thingyearSetting){
        // 校验参数
        int result =  thingyearSettingService.addThingyearSetting(thingyearSetting)? 1: 0;
        return AjaxMessage.success(result);
    }

    @ApiOperation(value = "查询单个")
    @ResponseBody
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public AjaxMessage selectById(@ApiParam(value = "id", required = true) @RequestParam Long id){
        return AjaxMessage.success(thingyearSettingService.findThingyearSettingById(id));
    }

    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改保存物品年代设置")
    public AjaxMessage<Integer>  editThingyearSetting(@ApiParam(value = "物品年代统计设置", required = true) @RequestBody ThingyearSettingEntity thingyearSetting){
        int result = thingyearSettingService.updateThingyearSettingById(thingyearSetting)? 1 : 0;
        return AjaxMessage.success( result);
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    @ResponseBody
    public AjaxMessage<Integer> del(@ApiParam(value = "ids", required = true) @RequestBody Long[] ids) {
        int result = thingyearSettingService.delThingyearSettingByIds(ids) ? 1 : 0;
        return AjaxMessage.success( result);
    }
}
