package com.steerinfo.ems.trmcalpointexvalue.controller;

import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.framework.utils.collection.ListUtils;
import com.steerinfo.ems.Utils.DateUtils;
import com.steerinfo.ems.trmcalpointexvalue.model.TRmCalpointExValue;
import com.steerinfo.ems.trmcalpointexvalue.service.ITRmCalpointExValueService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.math.BigDecimal;

/**
 * TRmCalpointExValue RESTful接口：
 * @author generator
 * @version 1.0-SNAPSHORT 2020-10-14 10:18
 * 类描述
 * 修订历史：
 * 日期：2020-10-14
 * 作者：generator
 * 参考：
 * 描述：TRmCalpointExValue RESTful接口
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@RestController
@RequestMapping("/${api.version}/trmcalpointexvalues")
public class TRmCalpointExValueController extends BaseRESTfulController {

    @Autowired
    ITRmCalpointExValueService tRmCalpointExValueService;

    @ApiOperation(value="获取列表", notes="分页查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
        @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("trmcalpointexvalue:view")
    @GetMapping(value = "/")
    public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
        PageList<TRmCalpointExValue> list = tRmCalpointExValueService.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("trmcalpointexvalue:view")
    @GetMapping(value = "/like/")
    public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
        PageList<TRmCalpointExValue> list = tRmCalpointExValueService.queryLikeForPage(parmas, pageNum, pageSize);
        return success(list);
    }
    
    @ApiOperation(value="创建", notes="根据TRmCalpointExValue对象创建")
    @ApiImplicitParam(name = "tRmCalpointExValue", value = "详细实体tRmCalpointExValue", required = true, dataType = "TRmCalpointExValue")
    //@RequiresPermissions("trmcalpointexvalue:create")
    @PostMapping(value = "/")
    public RESTfulResult add(@ModelAttribute TRmCalpointExValue model){
        TRmCalpointExValue tRmCalpointExValue = tRmCalpointExValueService.add(model);
        return success(tRmCalpointExValue);
    }

    @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
    //@RequiresPermissions("trmcalpointexvalue:view")
    @GetMapping(value = "/{id}")
    public RESTfulResult get(@PathVariable String id){
        TRmCalpointExValue tRmCalpointExValue = tRmCalpointExValueService.getById(id);
        return success(tRmCalpointExValue);
    }

    @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象，并根据传过来的tRmCalpointExValue信息来更新详细信息")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
        @ApiImplicitParam(name = "tRmCalpointExValue", value = "详细实体tRmCalpointExValue", required = true, dataType = "TRmCalpointExValue")
    })
    //@RequiresPermissions("trmcalpointexvalue:update")
    @PutMapping(value = "/{id}", produces  = "application/json;charset=UTF-8")
    public RESTfulResult update(@PathVariable String id, @RequestBody TRmCalpointExValue model){
        model.setId(id);
        TRmCalpointExValue tRmCalpointExValue = tRmCalpointExValueService.modify(model);
        return success(tRmCalpointExValue);
    }

    @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
    //@RequiresPermissions("trmcalpointexvalue:delete")
    @DeleteMapping(value = "/{id}")//String
    public RESTfulResult delete(@PathVariable String id){
    	List<String> list = Arrays.asList(id.split(","));
    	if(ListUtils.isNotEmpty(list)) {
	    	List<String> ids = ListUtils.convertList(list);
			  tRmCalpointExValueService.delete(ids);
    	}
      return success();
    }
    @ApiOperation(value="获取详细信息", notes="根据url的parmas来获取详细信息")
    @ApiImplicitParam(name = "parmas", value = "详细实体tRmCalpointExValue的id值", required = true, dataType = "TRmCalpointExValue")
    //@RequiresPermissions("trmcalpointexvalue:view")
    @GetMapping(value = "/getExData")
    public RESTfulResult getExData(@RequestParam HashMap<String, Object>parmas,Integer pageNum,Integer pageSize){
    	//日期范围开头增加0:0:0,结尾增加23:59:59，解决查询无结果bug
    	if(parmas.get("clock") !=null && !parmas.get("clock").toString().isEmpty()){  
    		parmas.replace("clock", parmas.get("clock").toString() + " 00:00:00");
    	}
    	if(parmas.get("itemid") !=null && !parmas.get("itemid").toString().isEmpty()){
    		String itemid = parmas.get("itemid").toString();
    		if (!itemid.startsWith("'")){
                itemid="'"+itemid.replaceAll(",","','").replaceAll("，","','")+"'";
            }
    		parmas.put("itemid",itemid);
    	}
        if(parmas.get("clocke") !=null && !parmas.get("clocke").toString().isEmpty()){
            parmas.replace("clocke", parmas.get("clocke").toString() + " 23:59:59");
        }
        if(parmas.get("energyid") != null && !parmas.get("energyid").toString().isEmpty()){
            String energyid = parmas.get("energyid").toString();
            if(!energyid.startsWith("'")){
                energyid = "'" + energyid.replaceAll(",", "','").replaceAll("，", "','") + "'";
            }
            parmas.put("energyid", energyid);
        }
        if(parmas.get("locateid") != null && !parmas.get("locateid").toString().isEmpty()){
            String locateid = parmas.get("locateid").toString();
            if(!locateid.startsWith("'")){
                locateid = "'" + locateid.replaceAll(",", "','").replaceAll("，", "','") + "'";
            }
            parmas.put("locateid", locateid);
        }
    	//end
        PageList<Map<String,Object>> tRmCalpointExValue = tRmCalpointExValueService.getExData(parmas, pageNum, pageSize);
        return success(tRmCalpointExValue);
    }
    //获取位置
    @ApiOperation(value="获取位置", notes="获取相关位置")
    @ApiImplicitParam(name = "itemid", value = "详细实体tRmCalpointExValue的id值", required = true, dataType = "TRmCalpointExValue")
    //@RequiresPermissions("trmcalpointexvalue:view")
    @GetMapping(value = "/getlocateid")
    public RESTfulResult getlocateid(){
       List<TRmCalpointExValue> locateid = tRmCalpointExValueService.getlocateid();
        return success(locateid);
    }
}
