package org.gyk.modules.lssj.jldls.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.lssj.jldls.entity.CxcSssjLssjJldlsRsj;
import org.gyk.modules.lssj.jldls.service.ICxcSssjLssjJldlsRsjService;
import org.gyk.modules.sssj.controller.GykController;
import org.gyk.modules.sssj.entity.CxcRsjQijing;
import org.gyk.modules.sssj.entity.Rishuju;
import org.gyk.modules.sssj.service.ICxcRsjQijingService;
import org.gyk.modules.sssj.service.IRishujuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;


/**
 * @Description: 计量点日数据
 * @Author: jeecg-boot
 * @Date:   2021-08-16
 * @Version: V1.0
 */
@Api(tags="计量点日数据")
@RestController
@RequestMapping("/jldlsrsj/cxcSssjLssjJldlsRsj")
@Slf4j
public class CxcSssjLssjJldlsRsjController extends GykController{
	@Autowired
	private ICxcSssjLssjJldlsRsjService cxcSssjLssjJldlsRsjService;

	@Autowired
	private IRishujuService rishujuService;
	@Autowired
	private ICxcRsjQijingService qijingService;


	/**
	 *   添加
	 *
	 * @param cxcSssjLssjJldlsRsj
	 * @return
	 */
	@AutoLog(value = "计量点日数据-添加")
	@ApiOperation(value="计量点日数据-添加", notes="计量点日数据-添加")
	@PostMapping(value = "/add")

	public Result<?> add(@RequestBody CxcSssjLssjJldlsRsj cxcSssjLssjJldlsRsj) {
		cxcSssjLssjJldlsRsjService.save(cxcSssjLssjJldlsRsj);
		return Result.ok("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param cxcSssjLssjJldlsRsj
	 * @return
	 */
//	@AutoLog(value = "计量点日数据-编辑")
//	@ApiOperation(value="计量点日数据-编辑", notes="计量点日数据-编辑")
//	@PutMapping(value = "/edit")
//	public Result<?> edit(@RequestBody CxcSssjLssjJldlsRsj cxcSssjLssjJldlsRsj) {
//		cxcSssjLssjJldlsRsjService.updateById(cxcSssjLssjJldlsRsj);
//		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) {
//		cxcSssjLssjJldlsRsjService.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.cxcSssjLssjJldlsRsjService.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) {
		CxcSssjLssjJldlsRsj cxcSssjLssjJldlsRsj = cxcSssjLssjJldlsRsjService.getById(id);
		if(cxcSssjLssjJldlsRsj==null) {
			return Result.error("未找到对应数据");
		}
		return Result.ok(cxcSssjLssjJldlsRsj);
	}

	 /**
	  * 通过jldId查询年数据
	  *
	  * @param jh
	  * @return
	  */
	 @AutoLog(value = "计量点日数据-通过jldId查询")
	 @ApiOperation(value="计量点日数据-通过jldId查询", notes="计量点日数据-通过jldId查询")
	 @GetMapping(value = "/queryYByJldid")

	 public Result<?> queryYearByJldid(@RequestParam(name="jh",required=true) String jh) {

		 List<Map<String,Object>> RsjQjlist = qijingService.getYMDataByjh(jh);
//		 for (Map<String,Object>map :RsjQjlist){
//
//			 System.out.println(map.get("qilMData"));
//		 }


//		 List<Map<String,Object>> Rsj = qijingService.getYMDataByjldIds(jh);
//		 	for (int i = 0 ; i<Rsj.size() ; i++){
//		 		String res = (String)Rsj.get(i).get("yData");
//				System.out.println(res);
//			}

//		 rishujuService.save((Rishuju) Rsj);

		 return Result.ok(RsjQjlist);
	 }
}
