package cn.com.usky.iot.EfAnalysis.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.usky.iot.entity.YtiotTEfAnalysis;
import cn.com.usky.iot.entity.YtiotTWaterAnalysis;
import cn.com.usky.iot.EfAnalysis.dao.YtiotTEfAnalysisDao;
import cn.com.usky.utils.DaoResult;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class YtiotTEfAnalysisServicesImpl implements YtiotTEfAnalysisService {
	private YtiotTEfAnalysisDao ytiotTEfAnalysisDao;

	public YtiotTEfAnalysisDao getYtiotTEfAnalysisDao() {
		return ytiotTEfAnalysisDao;
	}

	public void setYtiotTEfAnalysisDao(YtiotTEfAnalysisDao ytiotTEfAnalysisDao) {
		this.ytiotTEfAnalysisDao = ytiotTEfAnalysisDao;
	}

	public boolean chk_string_param(String param) {
		if(param==null)
			return true;
		if(param.indexOf("=")>=0)
			return false;
		if(param.indexOf("\'")>=0)
			return false;
		if(param.indexOf("\"")>=0)
			return false;
		return true;
	}
	
	public String chkhw(String hqlwhere){
		if(hqlwhere==null)
			return " where ";
		else
			return hqlwhere+" and ";
	}
	public String fieldname(String field){
		if(field.equals("company_code"))
			return "companyCode";
		if(field.equals("generation_time"))
			return "generationTime";
		if(field.equals("I_ORDER_IDX"))
			return "IOrderIdx";
		if(field.equals("UQ_PARENT_ID"))
			return "uqParentId";
		if(field.equals("UQ_PARENT_COMPANY_ID"))
			return "uqParentCompanyId";
		if(field.equals("V_COMPANY_NAME"))
			return "VCompanyName";
		if(field.equals("V_COMPANY_ADDRESS_0"))
			return "VCompanyAddress0";
		if(field.equals("V_COMPANY_ADDRESS_1"))
			return "VCompanyAddress1";
		if(field.equals("V_COMPANY_ADDRESS_2"))
			return "VCompanyAddress2";
		if(field.equals("E_STATUS"))
			return "EStatus";
		if(field.equals("UQ_ADMIN_ID"))
			return "uqAdminId";
		if(field.equals("I_VERSION"))
			return "IVersion";
		if(field.equals("D_STORETIME"))
			return "DStoretime";
		if(field.equals("V_COMMENT"))
			return "VComment";
		return null;
	}

	@Override
	public String getEfAnalysisList(String queryJson, String page, String start, String limit, String sort) throws Exception {
		// TODO Auto-generated method stub
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");	
		String generation_time = null;
		
		String V_COMPANY_NAME=null;//单位名称
		String V_COMPANY_ADDRESS_0=null;//单位地址_1
		String I_VERSION=null;//当前记录版本
		String D_STORETIME=null;//记录存储时间
		String UQ_ADMIN_ID=null;//信息录入人ID\
		String E_STATUS=null;//当前状态，0为待开通服务，1为已开通服务，2为服务锁定，3为已注销，4、5留用
		String V_COMMENT  = null;//注册/修改说明
		String company_code  = null;//单位编号
		String Page = null;
		String Start = null;
		JSONArray Sort = null;
		String Limit = null;
		
		String hqlwhere = null;
		String order = null;
		String dir = null;		
		String order_str = null;
		JSONObject q_json = null;		
		JSONArray jSONArray = new JSONArray();
		JSONObject json = new JSONObject();
		json.put("action", "getEfAnalysisList");
		if(queryJson!=null) {
			q_json = JSONObject.fromObject(queryJson);
			company_code= q_json.has("company_code")?q_json.getString("company_code"):null;
			generation_time = q_json.has("generation_time")?q_json.getString("generation_time"):null;
			
			order = q_json.has("order")?q_json.getString("order"):null;
			dir = q_json.has("dir")?q_json.getString("dir"):null;
			Start = q_json.has("start")?q_json.getString("start"):(start!=null)?start:"0";
			Limit = q_json.has("limit")?q_json.getString("limit"):(limit!=null)?limit:null;
			Page = q_json.has("page")?q_json.getString("page"):(page!=null)?page:"0";
		}
//		System.out.println();
		if(sort!=null) {
