package com.zcxk.controller;

import com.zcxk.model.AjaxMessage;
import com.zcxk.model.ResultStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import org.springframework.web.bind.annotation.*;
import com.zcxk.entity.ThingyearSettingEntity;
import com.zcxk.service.ThingyearSettingService;

/**
 * 物品年代设置页面控制器
 * @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
    public AjaxMessage<List<ThingyearSettingEntity>> findList(@ApiParam(value = "物品类型(1管网 2窨井 3阀门 4消防栓)", required = true)@RequestParam Integer thingType) {
        ThingyearSettingEntity thingyearSettingEntity = new ThingyearSettingEntity();
        thingyearSettingEntity.setThingType(thingType);
        List<ThingyearSettingEntity> thingyearSettingEntities = thingyearSettingService.findList(thingyearSettingEntity);
        return new AjaxMessage<>(ResultStatus.OK, thingyearSettingEntities);
    }

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

    /**
     * 修改
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public AjaxMessage<ThingyearSettingEntity> selectById(@ApiParam(value = "id", required = true) @RequestParam Long id){
        ThingyearSettingEntity thingyearSetting = thingyearSettingService.findThingyearSettingById(id);
        return  new AjaxMessage<>(ResultStatus.OK, thingyearSetting);
    }

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

    /**
     * 删除
     */
    @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 new AjaxMessage<>(ResultStatus.OK, result);
    }
}
