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

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Calendar;
import java.text.NumberFormat;
import cn.com.usky.iot.admin.dao.YtiotTAdminDao;
import cn.com.usky.iot.admin.dao.YtiotVUserCompanyDao;
import cn.com.usky.iot.company.dao.YtiotVCompanyDao;
import cn.com.usky.iot.entity.YtiotTAdmin;
import cn.com.usky.iot.entity.YtiotTInspectors;
import cn.com.usky.iot.entity.YtiotVCompany;
import cn.com.usky.iot.entity.YtiotVCompanyId;
import cn.com.usky.iot.entity.YtiotVUsercompany;
import cn.com.usky.iot.entity.YtiotVUsercompanyId;
import cn.com.usky.iot.entity.YtiotTProjectDetails;
import cn.com.usky.iot.entity.YtiotTProjectDevice;
import cn.com.usky.iot.entity.YtiotTProjectMonitor;
import cn.com.usky.iot.entity.YtiotVEfire;
import cn.com.usky.iot.entity.YtiotVEfireId;
import cn.com.usky.iot.entity.YtiotVHj;
import cn.com.usky.iot.entity.YtiotVHjId;
import cn.com.usky.iot.entity.YtiotVRtu;
import cn.com.usky.iot.entity.YtiotVRtuId;
import cn.com.usky.iot.entity.YtiotVSj;
import cn.com.usky.iot.entity.YtiotVSjId;
import cn.com.usky.iot.alarm.dao.YtiotVAlarmDao;
import cn.com.usky.iot.data.dao.YtiotVDataDao;
import cn.com.usky.iot.entity.YtiotVEfire;
import cn.com.usky.iot.entity.YtiotVEfireId;
import cn.com.usky.iot.entity.YtiotVHj;
import cn.com.usky.iot.entity.YtiotVHjId;
import cn.com.usky.iot.entity.YtiotVRtu;
import cn.com.usky.iot.entity.YtiotVRtuId;
import cn.com.usky.iot.entity.YtiotVSj;
import cn.com.usky.iot.entity.YtiotVSjId;
import cn.com.usky.utils.MD5Util;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class YtiotVCompanyServiceImpl implements YtiotVCompanyService {
	private YtiotVCompanyDao ytiotVCompanyDao;
	private YtiotTAdminDao ytiotTAdminDao;
	private YtiotVUserCompanyDao ytiotVUserCompanyDao;
	private YtiotVAlarmDao ytiotVAlarmDao;
	private YtiotVDataDao ytiotVDataDao;

	public YtiotVDataDao getYtiotVDataDao() {
		return ytiotVDataDao;
	}

	public void setYtiotVDataDao(YtiotVDataDao ytiotVDataDao) {
		this.ytiotVDataDao = ytiotVDataDao;
	}
	
	public YtiotVAlarmDao getYtiotVAlarmDao() {
		return ytiotVAlarmDao;
	}

	public void setYtiotVAlarmDao(YtiotVAlarmDao ytiotVAlarmDao) {
		this.ytiotVAlarmDao = ytiotVAlarmDao;
	}
	
	public YtiotVUserCompanyDao getYtiotVUserCompanyDao() {
		return ytiotVUserCompanyDao;
	}

	public void setYtiotVUserCompanyDao(YtiotVUserCompanyDao ytiotVUserCompanyDao) {
		this.ytiotVUserCompanyDao = ytiotVUserCompanyDao;
	}
	public YtiotVCompanyDao getYtiotVCompanyDao() {
		return ytiotVCompanyDao;
	}

	public void setYtiotVCompanyDao(YtiotVCompanyDao ytiotVCompanyDao) {
		this.ytiotVCompanyDao = ytiotVCompanyDao;
	}

	public YtiotTAdminDao getYtiotTAdminDao() {
		return ytiotTAdminDao;
	}

	public void setYtiotTAdminDao(YtiotTAdminDao ytiotTAdminDao) {
		this.ytiotTAdminDao = ytiotTAdminDao;
	}

	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("building_id"))
			return "buildingId";
		if(field.equals("building_name"))
			return "buildingName";
		if(field.equals("create_man"))
			return "createMan";
		if(field.equals("create_time"))
			return "createTime";
		if(field.equals("owner_address"))
			return "ownerAddress";
		if(field.equals("owner_id"))
			return "ownerId";
		if(field.equals("owner_man"))
			return "ownerMan";
		if(field.equals("owner_name"))
			return "ownerName";
		if(field.equals("owner_office"))
			return "ownerOffice";
		if(field.equals("company_code"))
			return "companyCode";
		return field;
	}
	@Override
	public String getVCompanyList(String queryJson, String page, String start, String limit, String sort)
			throws Exception {
		// TODO Auto-generated method stub
		String addr1=null, addr2=null, addr3=null;
		String addr1list=null, addr2list=null, addr3list=null;
		String address=null, building_id=null, building_name=null, create_man=null;
		String data1=null, data2=null, data3=null, fulladdress=null;
		String h5=null, hls=null, id=null, owner_address=null;
		String owner_id=null, owner_man=null, owner_name=null;
		String owner_id_list=null, building_id_list=null;
		String owner_office=null, rtmp=null, xmlx=null, xmlx_list=null;
		String hqlwhere = null;
		String order = null;
		String dir = null;
		String Start = null;
		String Limit = null;
		String Page = null;
		String order_str = null;
		JSONObject q_json = null;
		JSONArray Sort = null;
		JSONArray jSONArray = new JSONArray();
		JSONObject json = new JSONObject();
		json.put("action", "getVCompanyList");
		if(queryJson!=null) {
			q_json = JSONObject.fromObject(queryJson);
			if(q_json.has("addr1")) {
				if(((JSONObject) q_json.get("addr1")).isArray())
				{
					JSONArray j_tmp = q_json.getJSONArray("addr1");
					for(int i=0;i<j_tmp.size();i++)
					{
