`
robinrain
  • 浏览: 60721 次
  • 性别: Icon_minigender_1
  • 来自: 威海
社区版块
存档分类
最新评论

按星期执行的温度命令代码

 
阅读更多
package com.whjnkj.TempCmd.boimpl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.whjnkj.TempCmd.bo.TempCmdBO;
import com.whjnkj.build.dao.BuildInfoDAO;
import com.whjnkj.command.dao.CommandDAO;
import com.whjnkj.command.model.Command;
import com.whjnkj.common.exception.BusinessException;
import com.whjnkj.plan.dao.PlanInfoDAO;
import com.whjnkj.plan.dao.PlanModelDAO;
import com.whjnkj.plan.dao.SetPlanDAO;
import com.whjnkj.plan.model.PlanInfo;
import com.whjnkj.plan.model.PlanModel;
import com.whjnkj.unit.dao.UnitInfoDAO;
import com.whjnkj.unit.model.UnitInfo;
import com.whjnkj.user.dao.UserInfoDAO;

public class TempCmdBOImpl implements TempCmdBO {

	private PlanInfoDAO planInfoDAO;
	private PlanModelDAO planModelDAO;
	private SetPlanDAO setPlanDAO;
	private CommandDAO commandDAO;	
	private UserInfoDAO userInfoDAO;
	private UnitInfoDAO unitInfoDAO;
	private BuildInfoDAO buildInfoDAO;

//command:
//	 * ID
//	private Integer cmdId;
//	 * 1,用户;2,首站;3,二级站
//	private Integer objType;
//	 * 命令类型
//	private String cmdType;
//	 * 操作对象ID,-1为全部
//	private String objId;
//	 * 对象DTU编号
//	private String objDtuCode;
//	 * DTU ip
//	private String dtuIp;
//	 * 命令码
//	private String cmdCode;
//	 * 操作人
//	private Integer operEmployeeId;
	
	@SuppressWarnings("deprecation")
	@Override
	public void insertTempCmd() throws BusinessException, ParseException {
		
		//日期转换格式化 数据库中的日期存储都是yyyy-MM-dd的格式
		SimpleDateFormat insdf = new SimpleDateFormat("yyyy-MM-dd");
		
		//获取当前日期 
		Date currentDate = new Date();
		
		//cmdlist 供以后循环插入数据
		List<Command> cmdList = new ArrayList<Command>();
		
		//取得星期数 如果是周日返回0,周一为1 以此类推
		int weekDay = currentDate.getDay();
		
		//一天的毫秒数
		long oneDayMilliSeconds = 86400000;
		
		//当前日期的年月日
		int currYear = currentDate.getYear();
		int currMon = currentDate.getMonth();
		int currDay = currentDate.getDate();
		
		//比较日期 用于和开始结束日期比较 比较日期只留有年月日,时分秒都为00
		Date compareDate = insdf.parse("2010-01-01");
		compareDate.setYear(currYear);
		compareDate.setMonth(currMon);
		compareDate.setDate(currDay);
		
		//修正比较时间,如果为周日就不修正 其他的时间都修正到本周的周日 方便判断
		if(weekDay != 0){
			int cDays = 7-weekDay;
			long time = compareDate.getTime()+(oneDayMilliSeconds*cDays);
			compareDate.setTime(time);
		}
		
		//获取数据库内的所有开始和结束时间
		List<String> startDateAllString = setPlanDAO.selectStartDateAll();
		List<String> endDateAllString = setPlanDAO.selectEndDateAll();

		//保存需要下放命令的 方案ID和住户ID
		List<Integer> planIds =  new ArrayList<Integer>();
		List<Integer> userIds =  new ArrayList<Integer>();
		
		
		//循环判断,确定需要下方命令的 方案ID 和住户ID
		int loopNo = startDateAllString.size();
		Date compareDateNextDay = insdf.parse("2010-01-01");
		long timeNext = compareDate.getTime()+oneDayMilliSeconds;
		//比较日期的下一天 也就是此次命令下放的方案执行开始时间,时间为周一
		compareDateNextDay.setTime(timeNext);
		for(int i = 0 ; i < loopNo ; i++){
			Date startDatePerRow = insdf.parse(startDateAllString.get(i));
			Date endDatePerRow = insdf.parse(endDateAllString.get(i));
			//判断需要执行下方命令的开始时间,以今天的本周的周日作为判断点,满足条件的就是下周需要执行温度计划的方案
			if((startDatePerRow.before(compareDate)&&endDatePerRow.after(compareDate))||(startDatePerRow.equals(compareDateNextDay))){
				//取得符合条件的日期所在的行数 用于取得这行数据的 计划ID
				int start = i;
				int curPlanId = setPlanDAO.selectPlanIdBystart(start);
				PlanInfo planInfoCur =  planInfoDAO.selectPlanInfoByPlanId(curPlanId);
				//一个住户只能在下次的方案执行期执行一个方案 因此在这里 方案ID和住户ID是一一对应的
				int b=0;
				planIds.add(b,curPlanId);
				userIds.add(b,planInfoCur.getUserId());
				b++;
			}
		}
		
		//接下来将所有需要的cmd信息存储起来 供以后插入
		
		int loopNo2 = planIds.size();
		for(int i=0; i<loopNo2;i++){
			Command command = new Command();
			int planIdCur = planIds.get(i);
			
			//obj_type 为1时是住户
			command.setObjType(1);
			
			//command type 为 E1
			command.setCmdType("E1");
			
			int uid = userIds.get(i);
			//obj_id是住户的ctrl_code
			String ctlCode = userInfoDAO.getUserById(uid).getCtrlCode();
			command.setObjId(ctlCode);
			
			//DTU code为住户所属的楼宇的dtu code
			Integer unid = userInfoDAO.getUserById(uid).getUnitId();
			UnitInfo ui = unitInfoDAO.getUnitInfoById(unid);
			Integer bid = ui.getBuildInfo().getId();
			String dtuCode = buildInfoDAO.getBuildInfoById(bid).getDtuCode();
			command.setObjDtuCode(dtuCode);
			
			//DTU ip为住户所属的楼宇的dtu ip
			String dtuIp = buildInfoDAO.getBuildInfoById(bid).getDtuIp();
			command.setDtuIp(dtuIp);
			
			//操作人ID是planInfo的操作人ID
			PlanInfo planInfoCur =  planInfoDAO.selectPlanInfoByPlanId(planIdCur);
			int operEmId = planInfoCur.getOperEmployeeId();
			command.setOperEmployeeId(operEmId);
			
			//接下来是根据PlanId生成7*12=84个温度的命令代码CMD_CODE!!planInfo和PlanModel两个表是一对一的
			PlanModel pmMon = planModelDAO.selectPlanModelByPlanIdAndSeq(planIdCur, 1);
			PlanModel pmTue = planModelDAO.selectPlanModelByPlanIdAndSeq(planIdCur, 2);
			PlanModel pmWen = planModelDAO.selectPlanModelByPlanIdAndSeq(planIdCur, 3);
			PlanModel pmThe = planModelDAO.selectPlanModelByPlanIdAndSeq(planIdCur, 4);
			PlanModel pmFri = planModelDAO.selectPlanModelByPlanIdAndSeq(planIdCur, 5);
			PlanModel pmSat = planModelDAO.selectPlanModelByPlanIdAndSeq(planIdCur, 6);
			PlanModel pmSun = planModelDAO.selectPlanModelByPlanIdAndSeq(planIdCur, 7);
			
			
			//星期一的12个温度 每隔一个小时取一个值 转换为string类型
			String pmMon1 = String.valueOf(pmMon.getTemp01());
			String pmMon2 = String.valueOf(pmMon.getTemp03());
			String pmMon3 = String.valueOf(pmMon.getTemp05());
			String pmMon4 = String.valueOf(pmMon.getTemp07());
			String pmMon5 = String.valueOf(pmMon.getTemp09());
			String pmMon6 = String.valueOf(pmMon.getTemp11());
			String pmMon7 = String.valueOf(pmMon.getTemp13());
			String pmMon8 = String.valueOf(pmMon.getTemp15());
			String pmMon9 = String.valueOf(pmMon.getTemp17());
			String pmMon10 = String.valueOf(pmMon.getTemp19());
			String pmMon11 = String.valueOf(pmMon.getTemp21());
			String pmMon12 = String.valueOf(pmMon.getTemp23());
			//如果温度值是一位数 比如3℃ 在这里转换为03
			if(pmMon1.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon1);
				pmMon1 = sb.toString();
			}
			if(pmMon2.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon2);
				pmMon2 = sb.toString();
			}
			if(pmMon3.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon3);
				pmMon3 = sb.toString();
			}
			if(pmMon4.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon4);
				pmMon4 = sb.toString();
			}
			if(pmMon5.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon5);
				pmMon5 = sb.toString();
			}
			if(pmMon6.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon6);
				pmMon6 = sb.toString();
			}
			if(pmMon7.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon7);
				pmMon7 = sb.toString();
			}
			if(pmMon8.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon8);
				pmMon8 = sb.toString();
			}
			if(pmMon9.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon9);
				pmMon9 = sb.toString();
			}
			if(pmMon10.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon10);
				pmMon10 = sb.toString();
			}
			if(pmMon11.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon11);
				pmMon11 = sb.toString();
			}
			if(pmMon12.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmMon12);
				pmMon12 = sb.toString();
			}
			StringBuffer sb1= new StringBuffer();
			sb1.append(pmMon1);
			sb1.append(pmMon2);
			sb1.append(pmMon3);
			sb1.append(pmMon4);
			sb1.append(pmMon5);
			sb1.append(pmMon6);
			sb1.append(pmMon7);
			sb1.append(pmMon8);
			sb1.append(pmMon9);
			sb1.append(pmMon10);
			sb1.append(pmMon11);
			sb1.append(pmMon12);
			String strMon = sb1.toString(); 
			//星期2的
			String pmTue1 = String.valueOf(pmTue.getTemp01());
			String pmTue2 = String.valueOf(pmTue.getTemp03());
			String pmTue3 = String.valueOf(pmTue.getTemp05());
			String pmTue4 = String.valueOf(pmTue.getTemp07());
			String pmTue5 = String.valueOf(pmTue.getTemp09());
			String pmTue6 = String.valueOf(pmTue.getTemp11());
			String pmTue7 = String.valueOf(pmTue.getTemp13());
			String pmTue8 = String.valueOf(pmTue.getTemp15());
			String pmTue9 = String.valueOf(pmTue.getTemp17());
			String pmTue10 = String.valueOf(pmTue.getTemp19());
			String pmTue11 = String.valueOf(pmTue.getTemp21());
			String pmTue12 = String.valueOf(pmTue.getTemp23());
			//如果温度值是一位数 比如3℃ 在这里转换为03
			if(pmTue1.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue1);
				pmTue1 = sb.toString();
			}
			if(pmTue2.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue2);
				pmTue2 = sb.toString();
			}
			if(pmTue3.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue3);
				pmTue3 = sb.toString();
			}
			if(pmTue4.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue4);
				pmTue4 = sb.toString();
			}
			if(pmTue5.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue5);
				pmTue5 = sb.toString();
			}
			if(pmTue6.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue6);
				pmTue6 = sb.toString();
			}
			if(pmTue7.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue7);
				pmTue7 = sb.toString();
			}
			if(pmTue8.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue8);
				pmTue8 = sb.toString();
			}
			if(pmTue9.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue9);
				pmTue9 = sb.toString();
			}
			if(pmTue10.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue10);
				pmTue10 = sb.toString();
			}
			if(pmTue11.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue11);
				pmTue11 = sb.toString();
			}
			if(pmTue12.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmTue12);
				pmTue12 = sb.toString();
			}
			StringBuffer sbTue= new StringBuffer();
			sbTue.append(pmTue1);
			sbTue.append(pmTue2);
			sbTue.append(pmTue3);
			sbTue.append(pmTue4);
			sbTue.append(pmTue5);
			sbTue.append(pmTue6);
			sbTue.append(pmTue7);
			sbTue.append(pmTue8);
			sbTue.append(pmTue9);
			sbTue.append(pmTue10);
			sbTue.append(pmTue11);
			sbTue.append(pmTue12);
			String strTue = sbTue.toString(); 
			//星期3的
			String pmWen1 = String.valueOf(pmWen.getTemp01());
			String pmWen2 = String.valueOf(pmWen.getTemp03());
			String pmWen3 = String.valueOf(pmWen.getTemp05());
			String pmWen4 = String.valueOf(pmWen.getTemp07());
			String pmWen5 = String.valueOf(pmWen.getTemp09());
			String pmWen6 = String.valueOf(pmWen.getTemp11());
			String pmWen7 = String.valueOf(pmWen.getTemp13());
			String pmWen8 = String.valueOf(pmWen.getTemp15());
			String pmWen9 = String.valueOf(pmWen.getTemp17());
			String pmWen10 = String.valueOf(pmWen.getTemp19());
			String pmWen11 = String.valueOf(pmWen.getTemp21());
			String pmWen12 = String.valueOf(pmWen.getTemp23());
			//如果温度值是一位数 比如3℃ 在这里转换为03
			if(pmWen1.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen1);
				pmWen1 = sb.toString();
			}
			if(pmWen2.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen2);
				pmWen2 = sb.toString();
			}
			if(pmWen3.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen3);
				pmWen3 = sb.toString();
			}
			if(pmWen4.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen4);
				pmWen4 = sb.toString();
			}
			if(pmWen5.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen5);
				pmWen5 = sb.toString();
			}
			if(pmWen6.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen6);
				pmWen6 = sb.toString();
			}
			if(pmWen7.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen7);
				pmWen7 = sb.toString();
			}
			if(pmWen8.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen8);
				pmWen8 = sb.toString();
			}
			if(pmWen9.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen9);
				pmWen9 = sb.toString();
			}
			if(pmWen10.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen10);
				pmWen10 = sb.toString();
			}
			if(pmWen11.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen11);
				pmWen11 = sb.toString();
			}
			if(pmWen12.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmWen12);
				pmWen12 = sb.toString();
			}
			StringBuffer sbWen= new StringBuffer();
			sbWen.append(pmWen1);
			sbWen.append(pmWen2);
			sbWen.append(pmWen3);
			sbWen.append(pmWen4);
			sbWen.append(pmWen5);
			sbWen.append(pmWen6);
			sbWen.append(pmWen7);
			sbWen.append(pmWen8);
			sbWen.append(pmWen9);
			sbWen.append(pmWen10);
			sbWen.append(pmWen11);
			sbWen.append(pmWen12);
			String strWen = sbWen.toString();
			//星期4的
			String pmThe1 = String.valueOf(pmThe.getTemp01());
			String pmThe2 = String.valueOf(pmThe.getTemp03());
			String pmThe3 = String.valueOf(pmThe.getTemp05());
			String pmThe4 = String.valueOf(pmThe.getTemp07());
			String pmThe5 = String.valueOf(pmThe.getTemp09());
			String pmThe6 = String.valueOf(pmThe.getTemp11());
			String pmThe7 = String.valueOf(pmThe.getTemp13());
			String pmThe8 = String.valueOf(pmThe.getTemp15());
			String pmThe9 = String.valueOf(pmThe.getTemp17());
			String pmThe10 = String.valueOf(pmThe.getTemp19());
			String pmThe11 = String.valueOf(pmThe.getTemp21());
			String pmThe12 = String.valueOf(pmThe.getTemp23());
			//如果温度值是一位数 比如3℃ 在这里转换为03
			if(pmThe1.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe1);
				pmThe1 = sb.toString();
			}
			if(pmThe2.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe2);
				pmThe2 = sb.toString();
			}
			if(pmThe3.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe3);
				pmThe3 = sb.toString();
			}
			if(pmThe4.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe4);
				pmThe4 = sb.toString();
			}
			if(pmThe5.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe5);
				pmThe5 = sb.toString();
			}
			if(pmThe6.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe6);
				pmThe6 = sb.toString();
			}
			if(pmThe7.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe7);
				pmThe7 = sb.toString();
			}
			if(pmThe8.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe8);
				pmThe8 = sb.toString();
			}
			if(pmThe9.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe9);
				pmThe9 = sb.toString();
			}
			if(pmThe10.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe10);
				pmThe10 = sb.toString();
			}
			if(pmThe11.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe11);
				pmThe11 = sb.toString();
			}
			if(pmThe12.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmThe12);
				pmThe12 = sb.toString();
			}
			StringBuffer sbThe= new StringBuffer();
			sbThe.append(pmThe1);
			sbThe.append(pmThe2);
			sbThe.append(pmThe3);
			sbThe.append(pmThe4);
			sbThe.append(pmThe5);
			sbThe.append(pmThe6);
			sbThe.append(pmThe7);
			sbThe.append(pmThe8);
			sbThe.append(pmThe9);
			sbThe.append(pmThe10);
			sbThe.append(pmThe11);
			sbThe.append(pmThe12);
			String strThe = sbThe.toString(); 
			
			//星期5的
			String pmFri1 = String.valueOf(pmFri.getTemp01());
			String pmFri2 = String.valueOf(pmFri.getTemp03());
			String pmFri3 = String.valueOf(pmFri.getTemp05());
			String pmFri4 = String.valueOf(pmFri.getTemp07());
			String pmFri5 = String.valueOf(pmFri.getTemp09());
			String pmFri6 = String.valueOf(pmFri.getTemp11());
			String pmFri7 = String.valueOf(pmFri.getTemp13());
			String pmFri8 = String.valueOf(pmFri.getTemp15());
			String pmFri9 = String.valueOf(pmFri.getTemp17());
			String pmFri10 = String.valueOf(pmFri.getTemp19());
			String pmFri11 = String.valueOf(pmFri.getTemp21());
			String pmFri12 = String.valueOf(pmFri.getTemp23());
			//如果温度值是一位数 比如3℃ 在这里转换为03
			if(pmFri1.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri1);
				pmFri1 = sb.toString();
			}
			if(pmFri2.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri2);
				pmFri2 = sb.toString();
			}
			if(pmFri3.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri3);
				pmFri3 = sb.toString();
			}
			if(pmFri4.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri4);
				pmFri4 = sb.toString();
			}
			if(pmFri5.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri5);
				pmFri5 = sb.toString();
			}
			if(pmFri6.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri6);
				pmFri6 = sb.toString();
			}
			if(pmFri7.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri7);
				pmFri7 = sb.toString();
			}
			if(pmFri8.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri8);
				pmFri8 = sb.toString();
			}
			if(pmFri9.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri9);
				pmFri9 = sb.toString();
			}
			if(pmFri10.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri10);
				pmFri10 = sb.toString();
			}
			if(pmFri11.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri11);
				pmFri11 = sb.toString();
			}
			if(pmFri12.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmFri12);
				pmFri12 = sb.toString();
			}
			StringBuffer sbFri= new StringBuffer();
			sbFri.append(pmFri1);
			sbFri.append(pmFri2);
			sbFri.append(pmFri3);
			sbFri.append(pmFri4);
			sbFri.append(pmFri5);
			sbFri.append(pmFri6);
			sbFri.append(pmFri7);
			sbFri.append(pmFri8);
			sbFri.append(pmFri9);
			sbFri.append(pmFri10);
			sbFri.append(pmFri11);
			sbFri.append(pmFri12);
			String strFri = sbFri.toString(); 
			//星期6的
			String pmSat1 = String.valueOf(pmSat.getTemp01());
			String pmSat2 = String.valueOf(pmSat.getTemp03());
			String pmSat3 = String.valueOf(pmSat.getTemp05());
			String pmSat4 = String.valueOf(pmSat.getTemp07());
			String pmSat5 = String.valueOf(pmSat.getTemp09());
			String pmSat6 = String.valueOf(pmSat.getTemp11());
			String pmSat7 = String.valueOf(pmSat.getTemp13());
			String pmSat8 = String.valueOf(pmSat.getTemp15());
			String pmSat9 = String.valueOf(pmSat.getTemp17());
			String pmSat10 = String.valueOf(pmSat.getTemp19());
			String pmSat11 = String.valueOf(pmSat.getTemp21());
			String pmSat12 = String.valueOf(pmSat.getTemp23());
			//如果温度值是一位数 比如3℃ 在这里转换为03
			if(pmSat1.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat1);
				pmSat1 = sb.toString();
			}
			if(pmSat2.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat2);
				pmSat2 = sb.toString();
			}
			if(pmSat3.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat3);
				pmSat3 = sb.toString();
			}
			if(pmSat4.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat4);
				pmSat4 = sb.toString();
			}
			if(pmSat5.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat5);
				pmSat5 = sb.toString();
			}
			if(pmSat6.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat6);
				pmSat6 = sb.toString();
			}
			if(pmSat7.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat7);
				pmSat7 = sb.toString();
			}
			if(pmSat8.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat8);
				pmSat8 = sb.toString();
			}
			if(pmSat9.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat9);
				pmSat9 = sb.toString();
			}
			if(pmSat10.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat10);
				pmSat10 = sb.toString();
			}
			if(pmSat11.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat11);
				pmSat11 = sb.toString();
			}
			if(pmSat12.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSat12);
				pmSat12 = sb.toString();
			}
			StringBuffer sbSat= new StringBuffer();
			sbSat.append(pmSat1);
			sbSat.append(pmSat2);
			sbSat.append(pmSat3);
			sbSat.append(pmSat4);
			sbSat.append(pmSat5);
			sbSat.append(pmSat6);
			sbSat.append(pmSat7);
			sbSat.append(pmSat8);
			sbSat.append(pmSat9);
			sbSat.append(pmSat10);
			sbSat.append(pmSat11);
			sbSat.append(pmSat12);
			String strSat = sbSat.toString(); 
			//星期天的
			String pmSun1 = String.valueOf(pmSun.getTemp01());
			String pmSun2 = String.valueOf(pmSun.getTemp03());
			String pmSun3 = String.valueOf(pmSun.getTemp05());
			String pmSun4 = String.valueOf(pmSun.getTemp07());
			String pmSun5 = String.valueOf(pmSun.getTemp09());
			String pmSun6 = String.valueOf(pmSun.getTemp11());
			String pmSun7 = String.valueOf(pmSun.getTemp13());
			String pmSun8 = String.valueOf(pmSun.getTemp15());
			String pmSun9 = String.valueOf(pmSun.getTemp17());
			String pmSun10 = String.valueOf(pmSun.getTemp19());
			String pmSun11 = String.valueOf(pmSun.getTemp21());
			String pmSun12 = String.valueOf(pmSun.getTemp23());
			//如果温度值是一位数 比如3℃ 在这里转换为03
			if(pmSun1.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun1);
				pmSun1 = sb.toString();
			}
			if(pmSun2.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun2);
				pmSun2 = sb.toString();
			}
			if(pmSun3.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun3);
				pmSun3 = sb.toString();
			}
			if(pmSun4.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun4);
				pmSun4 = sb.toString();
			}
			if(pmSun5.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun5);
				pmSun5 = sb.toString();
			}
			if(pmSun6.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun6);
				pmSun6 = sb.toString();
			}
			if(pmSun7.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun7);
				pmSun7 = sb.toString();
			}
			if(pmSun8.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun8);
				pmSun8 = sb.toString();
			}
			if(pmSun9.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun9);
				pmSun9 = sb.toString();
			}
			if(pmSun10.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun10);
				pmSun10 = sb.toString();
			}
			if(pmSun11.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun11);
				pmSun11 = sb.toString();
			}
			if(pmSun12.length()==1){
				StringBuffer sb= new StringBuffer();
				sb.append("0");
				sb.append(pmSun12);
				pmSun12 = sb.toString();
			}
			StringBuffer sbSun= new StringBuffer();
			sbSun.append(pmSun1);
			sbSun.append(pmSun2);
			sbSun.append(pmSun3);
			sbSun.append(pmSun4);
			sbSun.append(pmSun5);
			sbSun.append(pmSun6);
			sbSun.append(pmSun7);
			sbSun.append(pmSun8);
			sbSun.append(pmSun9);
			sbSun.append(pmSun10);
			sbSun.append(pmSun11);
			sbSun.append(pmSun12);
			String strSun = sbSun.toString();
			
			//生成命令码
			StringBuffer sbAll= new StringBuffer();
			sbAll.append(strMon);
			sbAll.append(strTue);
			sbAll.append(strWen);
			sbAll.append(strThe);
			sbAll.append(strFri);
			sbAll.append(strSat);
			sbAll.append(strSun);
			String cmdStr = sbAll.toString();
			
			command.setCmdCode(cmdStr);
			
			//将以上信息插入cmdList
			cmdList.add(i, command);
		}
		
		//循环插入所有的数据,完成!!
		for(Command cmd : cmdList){
			commandDAO.insertCommand(cmd);
		}
		
	}

	/**
	 * @return the planInfoDAO
	 */
	public PlanInfoDAO getPlanInfoDAO() {
		return planInfoDAO;
	}

	/**
	 * @param planInfoDAO the planInfoDAO to set
	 */
	public void setPlanInfoDAO(PlanInfoDAO planInfoDAO) {
		this.planInfoDAO = planInfoDAO;
	}

	/**
	 * @return the planModelDAO
	 */
	public PlanModelDAO getPlanModelDAO() {
		return planModelDAO;
	}

	/**
	 * @param planModelDAO the planModelDAO to set
	 */
	public void setPlanModelDAO(PlanModelDAO planModelDAO) {
		this.planModelDAO = planModelDAO;
	}

	/**
	 * @return the setPlanDAO
	 */
	public SetPlanDAO getSetPlanDAO() {
		return setPlanDAO;
	}

	/**
	 * @param setPlanDAO the setPlanDAO to set
	 */
	public void setSetPlanDAO(SetPlanDAO setPlanDAO) {
		this.setPlanDAO = setPlanDAO;
	}

	/**
	 * @return the commandDAO
	 */
	public CommandDAO getCommandDAO() {
		return commandDAO;
	}

	/**
	 * @param commandDAO the commandDAO to set
	 */
	public void setCommandDAO(CommandDAO commandDAO) {
		this.commandDAO = commandDAO;
	}

	/**
	 * @return the userInfoDAO
	 */
	public UserInfoDAO getUserInfoDAO() {
		return userInfoDAO;
	}

	/**
	 * @param userInfoDAO the userInfoDAO to set
	 */
	public void setUserInfoDAO(UserInfoDAO userInfoDAO) {
		this.userInfoDAO = userInfoDAO;
	}

	/**
	 * @return the unitInfoDAO
	 */
	public UnitInfoDAO getUnitInfoDAO() {
		return unitInfoDAO;
	}

	/**
	 * @param unitInfoDAO the unitInfoDAO to set
	 */
	public void setUnitInfoDAO(UnitInfoDAO unitInfoDAO) {
		this.unitInfoDAO = unitInfoDAO;
	}

	/**
	 * @return the buildInfoDAO
	 */
	public BuildInfoDAO getBuildInfoDAO() {
		return buildInfoDAO;
	}

	/**
	 * @param buildInfoDAO the buildInfoDAO to set
	 */
	public void setBuildInfoDAO(BuildInfoDAO buildInfoDAO) {
		this.buildInfoDAO = buildInfoDAO;
	}


	
}
 
分享到:
评论

相关推荐

    proteus仿真+keil源代码。STC15W4K32S4单片机读取DS18B20温度,并发送至串口。

    1. 初始化DS18B20:设置P3.6口为输入/输出,初始化单线通信协议,例如写入命令进行温度测量。 2. 读取DS18B20数据:按照DS18B20的协议读取温度值,这可能包括发送特定的读命令、等待转换完成和接收数据帧。 3. 设置...

    温度控制系统的定时测量、定时控制、数据记录功能扩展

    这部分电路主要用于人机交互,即显示温度测量结果和设置参数等,并通过键盘接收用户输入的操作命令。其接口地址为0x8000。 **AD转换电路:** 用于将模拟温度信号转换为数字信号,以便单片机处理。该电路接口地址为...

    C语言编写的温控报警程序

    本文将介绍一个基于C语言的温控报警程序,该程序具有显示日期、时间及星期的功能,适用于单片机系统,并且利用了DS18B20温度传感器来获取环境温度。以下是相关的核心知识点: 1. **C语言编程**:程序是用C语言编写...

    LCD12864 万年历 单片机 农历 显示 温度DS18B20 DS1302 AT24C02

    单片机是这个项目的核心控制器,它负责处理所有的输入和输出,包括读取日期和时间数据、与传感器通信、处理LCD12864的显示命令等。单片机的选择可能因设计而异,但常见的选择包括8位或32位的微控制器,如AVR、ARM...

    DS18B20 1602显示 DS1302 AT89S52

    `LCD_Wait()`函数用于在写入命令或数据后等待LCD响应,确保正确执行操作。`LCD_SetDisplay()`函数则用于设置LCD的显示模式,如是否开启显示、是否显示光标以及光标是否闪烁。 在程序中,`show_time()`函数应该是...

    基于STM32的液晶显示万年历的设计与实现(含课程设计文档).rar

    在本项目中,我们主要探讨的是如何利用STM32微控制器设计并实现一个液晶显示的万年历系统,同时还具备串口时间校准和显示温度的功能。STM32是一款广泛应用的ARM Cortex-M系列微控制器,以其高性能、低功耗、丰富的片...

    DS1302时钟+DS18B20+源程序

    编程时,我们需要掌握如何初始化传感器,发送读取温度命令,并解析返回的数据。 无线遥控部分可能涉及到射频(RF)技术或蓝牙(Bluetooth)等无线通信协议。无线遥控可以为系统增加远程操作和监控的功能,比如在...

    DS18B20加显示

    - **软件调试**:`Proteus`是一个虚拟原型设计工具,可以模拟硬件电路并实时运行代码,是单片机程序调试的重要辅助工具。 5. **系统集成**: - **电路设计**:除了温度传感器和液晶显示外,可能还包括时钟源、...

    基于51单片机的电子日历册

    在电子日历册中,51单片机通过执行预编译的程序来驱动各个功能模块,确保系统正常运行。 12864液晶显示屏是该电子日历的显示部分,它能显示生肖、年、月、日、星期、时、分、秒等信息。12864是指屏幕的分辨率,即...

    LCD显示DS1302

    它能够提供秒、分、小时、日期、月、年以及星期的信息。DS1302通过三线串行接口与微控制器进行通信,使得连接简单且占用较少的I/O资源。在本项目中,DS1302将被配置为从单片机接收命令,更新其内部时钟,并将时间...

    单片机开发小综和LCD1602_DS1032_DS18B20

    在这个“单片机开发小综和LCD1602_DS1032_DS18B20”项目中,开发者使用纯汇编语言完成了一个功能丰富的系统,包括日期显示、星期显示、时间显示以及温度测量。以下将详细介绍其中的关键技术点。 首先,**LCD1602** ...

    基于单片机ds1302和18b20的Proteus仿真设计资料

    对于18b20,需要初始化数据线并遵循1-Wire协议进行通信,发送命令读取温度数据。 在程序设计阶段,可以使用C语言或其他单片机编程语言,如汇编语言,编写控制ds1302和18b20的代码。这部分内容通常涉及串行通信协议...

    51写的闹钟程序,带调时调闹钟,测温等

    - `&lt;intrins.h&gt;`:包含了一些内联函数,用于优化代码执行效率。 #### 2. 宏定义 接下来定义了一系列宏,用于简化代码编写: - `#define uint unsigned int`:定义无符号整型变量。 - `#define uchar unsigned char...

    DS1302驱动的电子时钟源程序

    2. 读取时间:通过SPI发送特定的命令代码,比如0x8E(读秒寄存器)来读取当前时间。DS1302的寄存器地址分为读写,每个地址对应一个时间单位。 3. 设置时间:类似地,可以使用命令代码0x88(写秒寄存器)来设置时间...

    基于于PIC的实时时钟

    - **主函数**:`void main()`中执行了系统初始化、设置初始时间和日期,然后不断读取时间和温度并显示在LCD上。 #### 重要函数解析 ##### 延时函数 `delay(uint x)` 该函数实现了简单的软件延时,其参数`x`表示...

    高精度DS1302

    1. **高精度**:DS1302内部集成了一个温度补偿的晶体振荡器,可以提供±5ppm(百万分之一)的精度,确保了在不同环境温度下的稳定计时。 2. **永远不断电**:芯片内置电池引脚,当主电源断开时,可以通过备用电池...

    1602时钟 单片机

    标题中的“1602时钟 单片机”指的是基于单片机技术设计的一款时钟系统,其中1602通常是指LCD1602显示器模块,这种显示器广泛用于电子制作项目,如简单的时钟、温度计等,因为它提供了一个清晰的文本显示界面。...

    基于51单片机电子万年历论文

    1. **主控程序**:负责整个系统的调度管理,包括初始化各模块、读取时间数据、处理用户命令等。 2. **时间显示程序**:通过动态扫描技术控制数码管显示时间信息。 3. **日期计算程序**:根据当前时间计算具体的星期...

Global site tag (gtag.js) - Google Analytics