package org.gyk.modules.sz.cxcsssjjldbjcanshusz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.gyk.common.annotation.AutoLog;
import org.gyk.common.api.Result;
import org.gyk.modules.sz.cxcsssjjldbjcanshusz.entity.CxcSssjJldBjCanshuSz;
import org.gyk.modules.sz.cxcsssjjldbjcanshusz.service.ICxcSssjJldBjCanshuSzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

 /**
 * @Description: 计量点报警参数字典
 * @Author: jeecg-boot
 * @Date:   2023-09-25
 * @Version: V1.0
 */
@Api(tags="计量点报警参数字典")
@RestController
@RequestMapping("/cxcsssjjldbjcanshusz/cxcSssjJldBjCanshuSz")
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
public class CxcSssjJldBjCanshuSzController  {
	@Autowired
	private ICxcSssjJldBjCanshuSzService cxcSssjJldBjCanshuSzService;
	
	/**
	 * 分页列表查询
	 *
	 * @param cxcSssjJldBjCanshuSz
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "计量点报警参数字典-分页列表查询")
	@ApiOperation(value="计量点报警参数字典-分页列表查询", notes="计量点报警参数字典-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(CxcSssjJldBjCanshuSz cxcSssjJldBjCanshuSz,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<CxcSssjJldBjCanshuSz> queryWrapper = new QueryWrapper<>();
		Page<CxcSssjJldBjCanshuSz> page = new Page<CxcSssjJldBjCanshuSz>(pageNo, pageSize);
		IPage<CxcSssjJldBjCanshuSz> pageList = cxcSssjJldBjCanshuSzService.page(page, queryWrapper);
		return Result.ok(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param cxcSssjJldBjCanshuSz
	 * @return
	 */
	@AutoLog(value = "计量点报警参数字典-添加")
	@ApiOperation(value="计量点报警参数字典-添加", notes="计量点报警参数字典-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody CxcSssjJldBjCanshuSz cxcSssjJldBjCanshuSz) {
		cxcSssjJldBjCanshuSzService.save(cxcSssjJldBjCanshuSz);
		return Result.ok("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param cxcSssjJldBjCanshuSz
	 * @return
	 */
	@AutoLog(value = "计量点报警参数字典-编辑")
	@ApiOperation(value="计量点报警参数字典-编辑", notes="计量点报警参数字典-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody CxcSssjJldBjCanshuSz cxcSssjJldBjCanshuSz) {
		cxcSssjJldBjCanshuSzService.updateById(cxcSssjJldBjCanshuSz);
		return Result.ok("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "计量点报警参数字典-通过id删除")
	@ApiOperation(value="计量点报警参数字典-通过id删除", notes="计量点报警参数字典-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		cxcSssjJldBjCanshuSzService.removeById(id);
		return Result.ok("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "计量点报警参数字典-批量删除")
	@ApiOperation(value="计量点报警参数字典-批量删除", notes="计量点报警参数字典-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.cxcSssjJldBjCanshuSzService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "计量点报警参数字典-通过id查询")
	@ApiOperation(value="计量点报警参数字典-通过id查询", notes="计量点报警参数字典-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		CxcSssjJldBjCanshuSz cxcSssjJldBjCanshuSz = cxcSssjJldBjCanshuSzService.getById(id);
		if(cxcSssjJldBjCanshuSz==null) {
			return Result.error("未找到对应数据");
		}
		return Result.ok(cxcSssjJldBjCanshuSz);
	}
}
