/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/28
 */
package org.springblade.modules.business.rtu.data.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.constant.BusinessConstant;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.business.rtu.data.dto.RtuDataRiverDTO;
import org.springblade.modules.business.rtu.data.service.IRtuDataRiverService;
import org.springblade.modules.business.rtu.data.vo.RtuDataRainVO;
import org.springblade.modules.business.rtu.data.vo.RtuDataRiverVO;
import org.springblade.modules.business.rtu.data.wrapper.RtuDataRainWrapper;
import org.springblade.modules.business.rtu.data.wrapper.RtuDataRiverWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/***
 * Date:2022/8/28
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@RestController
@RequestMapping("galaxy-business/rtu/data/river")
@AllArgsConstructor
@Api(value = "河道水情实时数据管理", tags = "测站实时数据管理")
public class RtuDataRiverController extends BladeController {
	private final IRtuDataRiverService dataRiverService;
	/**
	 * 分页
	 */
	@GetMapping("/page")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rtuName", value = "测站名称", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "adCode", value = "行政区划编码", paramType = "query", dataType = "string"),
	})
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页")
	public R<IPage<RtuDataRiverVO>> page(@ApiIgnore RtuDataRiverDTO rtuDataRiverDTO, Query query) {
		BladeUser user = AuthUtil.getUser();
		if (BusinessConstant.ROLE_ORG_ADMIN.equals(user.getRoleName()) || BusinessConstant.ROLE_ORG_SERVICE_PERSON.equals(user.getRoleName())) {
			rtuDataRiverDTO.setOrgId(Func.toLong(user.getDeptId()));
		} else {
			rtuDataRiverDTO.setOrgId(null);
		}
		IPage<RtuDataRiverVO> pages = dataRiverService.selectPage(Condition.getPage(query),rtuDataRiverDTO);
		List<RtuDataRiverVO> list = pages.getRecords();
		for (RtuDataRiverVO rtuInfoVO : list) {
			RtuDataRiverWrapper.build().appendInfo(rtuInfoVO);
		}
		return R.data(pages);
	}
}
