package com.zhgd.xmgl.modules.basicdata.controller.project;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.util.PageUtil;
import com.zhgd.xmgl.modules.basicdata.entity.DustNoiseData;
import com.zhgd.xmgl.modules.basicdata.service.IDustNoiseDataService;
import com.zhgd.xmgl.security.SecurityUser;
import com.zhgd.xmgl.security.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
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;


 /**
 * @Title: Controller
 * @Description: 扬尘实时数据管理
 * @author： pds
 * @date：   2023-03-01
 * @version： V1.0
 */
@RestController
@RequestMapping("/project/dustNoiseData")
@Slf4j
@Api(tags = "扬尘实时数据")
public class DustNoiseDataController {
	@Autowired
	private IDustNoiseDataService dustNoiseDataService;
	
	/**
	  * 分页列表查询
	 * @return
	 */
	@OperLog(operModul = "扬尘实时数据管理", operType = "分页查询", operDesc = "分页列表查询扬尘实时数据管理信息")
	@ApiOperation(value = " 分页列表查询扬尘实时数据管理信息", notes = "分页列表查询扬尘实时数据管理信息", httpMethod="POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "name", value = "扬尘名称", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "pageNo", value = "页数", paramType = "query", required = true, defaultValue = "1", dataType = "Integer"),
			@ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", required = true, defaultValue = "10", dataType = "Integer")
	})
	@PostMapping(value = "/page")
	public Result<IPage<DustNoiseData>> queryPageList(@RequestBody Map<String, Object> map) {
		String name = MapUtils.getString(map, "name");
		QueryWrapper<DustNoiseData> wrapper = Wrappers.<DustNoiseData>query();
		SecurityUser user = SecurityUtil.getUser();
		if (StringUtils.isNotBlank(user.getEngineeringSn())) {
			wrapper.eq("ed.engineering_sn", user.getSn());
		} else {
			wrapper.eq("ed.project_sn", user.getSn());
		}
		if (StringUtils.isNotBlank(name)) {
			wrapper.like("ed.name", name);
		}
		Page<DustNoiseData> page = PageUtil.getPage(map);
		IPage<DustNoiseData> pageList = dustNoiseDataService.pageList(page, wrapper);
		return Result.success(pageList);
	}
}
