package com.steerinfo.ems.tcm0318.controller;

import com.steerinfo.ems.Utils.DateUtils;
import com.steerinfo.ems.ifmesemswatermonitor.service.IIfMesEmsWatermonitorService;
import com.steerinfo.ems.tcm0318.model.TCm0318;
import com.steerinfo.ems.tcm0318.service.ITCm0318Service;
import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageList;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TCm0318 RESTful接口：
 * @author 王金涛
 * @version 1.0-SNAPSHORT 2019-10-16 11:40
 * 类描述
 * 修订历史：
 * 日期：2019-10-16
 * 作者：王金涛
 * 参考：
 * 描述：TCm0318 RESTful接口
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@RestController
@RequestMapping("/${api.version}/tcm0318s")
public class TCm0318Controller extends BaseRESTfulController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TCm0318Controller.class);

    @Autowired
    ITCm0318Service tCm0318Service;

    @ApiOperation(value="获取列表", notes="分页查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
        @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("tcm0318:view")
    @GetMapping(value = "/")
    public RESTfulResult list(@RequestParam HashMap<String, Object> parmas,Integer pageNum, Integer pageSize){
        PageList<TCm0318> list = tCm0318Service.queryForPage(parmas, pageNum, pageSize);
        return success(list);
    }

    @ApiOperation(value="水质监测数据查询界面查询", notes="分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("tcm0318:view")
    @GetMapping(value = "/dataquery/")
    public RESTfulResult list2(@RequestParam HashMap<String, Object> parmas,Integer pageNum, Integer pageSize){
        if(parmas.get("monitordate") != null && parmas.get("monitordatee") != null && parmas.get("monitordate").toString().compareTo(parmas.get("monitordatee").toString()) > 0){
            return failed(null, "检测日期出现错误，开始时间不能大于结束时间");
        }
        else{
            PageList<TCm0318> list = tCm0318Service.dataQuery(parmas, pageNum, pageSize);
            return success(list);
        }
    }

    @ApiOperation(value="水质历史数据对比分析界面查询", notes="分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("tcm0318:view")
    @GetMapping(value = "/datacomparison/")
    public RESTfulResult list3(@RequestParam HashMap<String, Object> params,Integer pageNum, Integer pageSize){
    	if(params.get("monitordate") == null || params.get("monitordate").toString().isEmpty()){
            return failed(null, "对比日期不能为空！");
        } else if(params.get("monitordatee") == null || params.get("monitordatee").toString().isEmpty()){
            return failed(null, "被对比日期不能为空！");
        }
        else {
            List<Map<String, Object>> list = tCm0318Service.datacomparison(params);
            return success(list);
        }
    }

    @ApiOperation(value="水质质量考核指标统计界面查询", notes="分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("tcm0318:view")
    @GetMapping(value = "/qualityassessment/")
    public RESTfulResult list4(@RequestParam HashMap<String, Object> parmas,Integer pageNum, Integer pageSize){
        PageList<TCm0318> list = tCm0318Service.qualityassessment(parmas, pageNum, pageSize);
        return success(list);
    }

    @ApiOperation(value="水质页面修改", notes="修改")
    @PutMapping(value = "/")
    public RESTfulResult updateByparams(@RequestBody TCm0318[] models){
        for (TCm0318 model : models) {
            tCm0318Service.updateByparams(model);
        }
        return success();
    }

//    @ApiOperation(value="水质监测数据录入", notes="根据url的id来指定更新对象，并根据传过来的tCm0318信息来更新详细信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "tCm0318", value = "详细实体tCm0318", required = true, dataType = "TCm0318")
//    })
//    //@RequiresPermissions("tcm0318:update")
//    @PutMapping(value = "/{id}", produces  = "application/json;charset=UTF-8")
//    public RESTfulResult update(@PathVariable String id, @RequestBody TCm0318 model) {
//        if(tCm0318Service.getById(id) == null){
//            return failed(null, "对应检测数据不存在！");
//        }
//        if(model.getTimegranid() == null || "".equals(model.getTimegranid())){
//            return failed(null, "时间粒度不能为空！");
//        }
//        if(model.getMonitordate() == null || "".equals(model.getMonitordate())){
//            model.setMonitordate(DateUtils.getCurrentTime("yyyy-MM-dd"));
//        }
//        if(model.getDatadate() == null || "".equals(model.getDatadate())){
//            model.setDatadate(DateUtils.getCurrentTime("HH:mm:ss"));
//        }
//        if("DAY".equals(model.getTimegranid()) && !model.getMonitordate().substring(0,10).equals(tCm0318Service.getById(id).getMonitordate())){
//            return failed(null, "检测日期错误！");
//        }
//        if("MONTH".equals(model.getTimegranid()) && !model.getMonitordate().substring(0,7).equals(tCm0318Service.getById(id).getMonitordate().substring(0,7))){
//            return failed(null, "检测日期错误！");
//        }
//        LOGGER.info("水质监测数据录入表修改前的数据是" + tCm0318Service.getById(id).toString());
//        model.setRecordid(id);
//        TCm0318 tCm0318 = tCm0318Service.modify(model);
//        LOGGER.info("水质监测数据录入表修改后的数据是" + tCm0318.toString());
//        return success(tCm0318);
//    }



}
