package cn.api.atv.app;

import java.util.Map;
import cn.pojo.atv.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import cn.facade.abs.IService;
import cn.common.annotation.Log;
import cn.common.enums.BizOpType;
import cn.common.enums.ResultCode;
import cn.common.page.response.Result;
import cn.orm.sqltoy.model.Page;
import cn.orm.sqltoy.plus.Wrappers;
import cn.orm.sqltoy.plus.query.QueryWrapper;
import cn.util.core.IsKit;

@RestController
@RequestMapping("/app")
public class QueryListCtrl extends IService
{

	@GetMapping(value = "/atvCountry/list")
	public Result<?> countryQueryPageList(@RequestParam Map<String,Object> pageMap)
	{
		QueryWrapper<AtvCountry> queryWrapper = Wrappers.wrapper(AtvCountry.class);
		Page<?> page = daoService. getPage(pageMap);
		Page<?> pageResult = daoService.findPage(queryWrapper,page);
		if(IsKit.isNullOrEmpty(pageResult)) {
			return Result.warnMsg(ResultCode.SQL_RUN.getMsg());
		}
		return Result.ok_ePlusList(pageResult.getRecordCount(),pageResult.getRows());
	}



	@GetMapping(value = "/atvLine/list")
	public Result<?> lineQueryPageList(@RequestParam Map<String,Object> pageMap)
	{
		QueryWrapper<AtvLine> queryWrapper = Wrappers.wrapper(AtvLine.class);
		Page<?> page = daoService. getPage(pageMap);
		Page<?> pageResult = daoService.findPage(queryWrapper,page);
		if(IsKit.isNullOrEmpty(pageResult)) {
			return Result.warnMsg(ResultCode.SQL_RUN.getMsg());
		}
		return Result.ok_ePlusList(pageResult.getRecordCount(),pageResult.getRows());
	}
	@GetMapping(value = "/atvTrain/list")
	public Result<?> trainQueryPageList(@RequestParam Map<String,Object> pageMap)
	{
		QueryWrapper<AtvTrain> queryWrapper = Wrappers.wrapper(AtvTrain.class);
		Page<?> page = daoService. getPage(pageMap);
		Page<?> pageResult = daoService.findPage(queryWrapper,page);
		if(IsKit.isNullOrEmpty(pageResult)) {
			return Result.warnMsg(ResultCode.SQL_RUN.getMsg());
		}
		return Result.ok_ePlusList(pageResult.getRecordCount(),pageResult.getRows());
	}

	@GetMapping(value = "/atvArea/list")
	public Result<?> areaQueryPageList(@RequestParam Map<String,Object> pageMap)
	{
		QueryWrapper<AtvArea> queryWrapper = Wrappers.wrapper(AtvArea.class);
		Page<?> page = daoService. getPage(pageMap);
		Page<?> pageResult = daoService.findPage(queryWrapper,page);
		if(IsKit.isNullOrEmpty(pageResult)) {
			return Result.warnMsg(ResultCode.SQL_RUN.getMsg());
		}
		return Result.ok_ePlusList(pageResult.getRecordCount(),pageResult.getRows());
	}


	/**获取车厢:已知trainId*/
	@GetMapping(value = "/atvCarriage/list")
	@Log(title = "车厢表-分页列表查询", businessType = BizOpType.DELETE)
	public Result<?> carriageQueryPageList(	@RequestParam Map<String,Object> paraMap)
	{
		QueryWrapper<AtvCarriage> queryWrapper = Wrappers.wrapper(AtvCarriage.class)
				.eq("trainId",paraMap.get("trainId"));
		Page<?> page = daoService. getPage(paraMap);
		Page<?> pageResult = daoService.findPage(queryWrapper,page);
		if(IsKit.isNullOrEmpty(pageResult)) {
			return Result.warnMsg(ResultCode.SQL_RUN.getMsg());
		}
		return Result.ok_ePlusList(pageResult.getRecordCount(),pageResult.getRows());
	}
	/**获取设备:已知carriageId*/
	@GetMapping(value = "/atvEquipment/list")
	@Log(title = "设备表-分页列表查询", businessType = BizOpType.DELETE)
	public Result<?> equipQueryPageList(@RequestParam Map<String,Object> paraMap)
	{
		QueryWrapper<AtvEquipment> queryWrapper = Wrappers.wrapper(AtvEquipment.class)
				.eq("carriageId",paraMap.get("carriageId"));
		Page<?> page = daoService. getPage(paraMap);
		Page<?> pageResult = daoService.findPage(queryWrapper,page);
		if(IsKit.isNullOrEmpty(pageResult)) {
			return Result.warnMsg(ResultCode.SQL_RUN.getMsg());
		}
		return Result.ok_ePlusList(pageResult.getRecordCount(),pageResult.getRows());
	}
	/**获取板卡；已知equipmentId.引入字段缓存翻译*/
	@GetMapping(value = "/atvBoardCard/list")
	@Log(title = "板卡表-分页列表查询", businessType = BizOpType.DELETE)
	public Result<?> boardCardQueryPageList(@RequestParam Map<String,Object> paramMap)
	{
		Page<?> page = daoService.getPage(paramMap);
        Page<?> pageResult = daoService.findPageBySql(page,"atv_boardCardListApp",paramMap,Map.class);
		if(IsKit.isNullOrEmpty(pageResult)) {
			return Result.warnMsg(ResultCode.SQL_RUN.getMsg());
		}
		return Result.ok_ePlusList(pageResult.getRecordCount(),pageResult.getRows());
	}
}
