package com.changda.gjjapp.zhfwpt.service.impl.qdywquanxiankz;

import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.changda.cd4j.foundation.core.dto.ResultDto;
import com.changda.gjjapp.db.entity.M_XEKZB;
import com.changda.gjjapp.db.entity.M_XWINFO;
import com.changda.gjjapp.db.entity.M_YWZTKZ_2;
import com.changda.gjjapp.db.entity.TMP_YW_GDHK_QKMX_WH;
import com.changda.gjjapp.zhfwpt.dao.qdywqxgl.QuDaoQuanXianGuanLiDao;
import com.changda.gjjapp.zhfwpt.dto.qdywqxgl.DuanXinQuanXianGuanLiDto;
import com.changda.gjjapp.zhfwpt.dto.qdywqxgl.FwkzLogginInfoDto;
import com.changda.gjjapp.zhfwpt.dto.qdywqxgl.Page2;
import com.changda.gjjapp.zhfwpt.dto.qdywqxgl.PageDto;
import com.changda.gjjapp.zhfwpt.dto.qdywqxgl.QdzkLoggingInfoDto;
import com.changda.gjjapp.zhfwpt.dto.qdywqxgl.QuDaoQuanXianGuanLiDto;
import com.changda.gjjapp.zhfwpt.dto.yhxxgl.YongHuXinXiSearchDto;
import com.changda.gjjapp.zhfwpt.service.qdywquanxiankz.QuDaoQuanXianKongZhiService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
public class QuDaoQuanXianKZServiceImp implements QuDaoQuanXianKongZhiService {

	@Autowired
	private QuDaoQuanXianGuanLiDao quDaoQuanXianGuanLiDao;

	// 查询渠道状态表用于管理渠道权限
	@Override
	public List<QuDaoQuanXianGuanLiDto> quDaoZhuangTaiSearch(String primaryid) {
		List<Map<String, Object>> data = quDaoQuanXianGuanLiDao.quDaoZhuangTaiSearch(primaryid);
		List<QuDaoQuanXianGuanLiDto> list = new ArrayList<>();
		for (Map<String, Object> qdqxgl : data) {
			QuDaoQuanXianGuanLiDto qLiDto = new QuDaoQuanXianGuanLiDto();
			qLiDto.setPrimaryid(qdqxgl.get("PRIMARYID").toString());
			qLiDto.setQdid(qdqxgl.get("QDID").toString());
			qLiDto.setQdmc(qdqxgl.get("QDMC").toString());
			qLiDto.setQdzt(qdqxgl.get("QDZT").toString());	
			qLiDto.setFz(qdqxgl.get("FZ").toString());
			qLiDto.setMfzrs(qdqxgl.get("MFZRS").toString());
			qLiDto.setDjsj(qdqxgl.get("DJSJ").toString());
			list.add(qLiDto);
		}
		return list;
	}

	// 计算在线人数
	public void onlineUsers() throws ParseException {
//		long nd = 1000 * 24 * 60 * 60;
//		long nh = 1000 * 60 * 60;
//		long nm = 1000 * 60;
		List<Map<String, Object>> data = quDaoQuanXianGuanLiDao.quDaoZhuangTaiSearch(null);
		for (Map<String, Object> map : data) {
			String qdid = map.get("QDID").toString();
			// 待机时间
			String djsj = map.get("DJSJ").toString();
			long djsj2 = Long.parseLong(djsj);
			
			quDaoQuanXianGuanLiDao.updateOnlineUsers2(qdid, djsj);
//			List<Map<String, Object>> data2 = quDaoQuanXianGuanLiDao.onlineUsers(qdid);
//			for (Map<String, Object> map2 : data2) {
//				// 主键id
//				String id = map2.get("ID").toString();
//				String zhczsj = map2.get("ZHCZSJ").toString();
//				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//				// 当前系统时间
//				Date nowDate = sdf.parse(sdf.format(new Date()));
//				// 最后操作时间
//				Date zhczsj2 = sdf.parse(zhczsj);
//				// 获得两个时间的毫秒时间差异
//				long diff = nowDate.getTime() - zhczsj2.getTime();
//				// 计算差多少天
//				long day = diff / nd;
//				// 计算差多少小时
//				long hour = diff % nd / nh;
//				// 计算差多少分钟
//				long min = diff % nd % nh / nm;
//
//				if (day > 1) {
//					quDaoQuanXianGuanLiDao.updateOnlineUsers2(id);
//				}
//				if (min > djsj2) {
//					quDaoQuanXianGuanLiDao.updateOnlineUsers2(id);
//				}
//
//				// System.out.println(day + "天" + hour + "小时" + min + "分钟");
//			}
		}

	}

	// 渠道状态实时状态控制
	@Override
	public void quDaoSSKZ() {
		// 手机App
		String App = "06";

		// 网厅
		String wt = "02";

		// 微信
		String wx = "05";

		// 智能终端
		String zhiNengZhongDuan = "07";

//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		Calendar c = Calendar.getInstance();
//		c = Calendar.getInstance();
//		c.add(Calendar.MINUTE, -5);
//		// 获取前五分钟 的时间
//		String LastMinute = sdf.format(c.getTime());
		//System.out.println("减后时间：" + LastMinute);
		// 智能终端在线人数
		int zhiNengZhongDuanCount = quDaoQuanXianGuanLiDao.quDaoFangWenCount(zhiNengZhongDuan);
		//System.out.println("智能终端"+zhiNengZhongDuanCount);
		// 网厅在线人数
		int wtCount = quDaoQuanXianGuanLiDao.quDaoFangWenCount( wt);
		//System.out.println("网厅在线人数：" + wtCount);
		// 微信在线人数
		int wxCount = quDaoQuanXianGuanLiDao.quDaoFangWenCount( wx);
		//System.out.println("微信在线人数"+wxCount);
		// 手机App在线人数
		int appCount = quDaoQuanXianGuanLiDao.quDaoFangWenCount( App);
		//System.out.println("手机app"+appCount);
		// 更新M_QDZTKZ（渠道控制表中前五分钟的在线人数）
		quDaoQuanXianGuanLiDao.updateOnlineUsers(zhiNengZhongDuan, zhiNengZhongDuanCount);
		quDaoQuanXianGuanLiDao.updateOnlineUsers(wt, wtCount);
		quDaoQuanXianGuanLiDao.updateOnlineUsers(wx, wxCount);
		quDaoQuanXianGuanLiDao.updateOnlineUsers(App, appCount);

		/*
		 * System.err.println("1111111111111111111111111111111"); // APP渠道状态
		 * Map<String, Object> quanXianGuanLiDtoAPP =
		 * quDaoQuanXianGuanLiDao.quDaoZhuangTai(App); System.err.println("APP"
		 * + quanXianGuanLiDtoAPP); // 微信渠道状态 Map<String, Object>
		 * quanXianGuanLiDtoWX = quDaoQuanXianGuanLiDao.quDaoZhuangTai(wx); //
		 * 网厅渠道状态 Map<String, Object> quanXianGuanLiDtoWT =
		 * quDaoQuanXianGuanLiDao.quDaoZhuangTai(wt); // 智能终端渠道状态 Map<String,
		 * Object> quanXianGuanLiDtoZNZD =
		 * quDaoQuanXianGuanLiDao.quDaoZhuangTai(zhiNengZhongDuan);
		 */

		/*
		 * Date now = new Date(); SimpleDateFormat dateFormat = new
		 * SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //获取手机app、微信、网厅、智能终端的控制时间
		 * Date appStartTime = (Date) quanXianGuanLiDtoAPP.get("KSSJ"); Date
		 * appEndTime = (Date) quanXianGuanLiDtoAPP.get("JSSJ");
		 * 
		 * Date wxStartTime = (Date) quanXianGuanLiDtoWX.get("KSSJ"); Date
		 * wxEndTime = (Date) quanXianGuanLiDtoWX.get("JSSJ");
		 * 
		 * Date wtStartTime = (Date) quanXianGuanLiDtoWT.get("KSSJ"); Date
		 * wtEndTime = (Date) quanXianGuanLiDtoWT.get("JSSJ");
		 * 
		 * Date znzdStartTime = (Date) quanXianGuanLiDtoZNZD.get("KSSJ"); Date
		 * znzdEndTime = (Date) quanXianGuanLiDtoZNZD.get("JSSJ");
		 */
		// System.err.println("222222222222222222222222222222222222222222");
		// 获取当前时间
		/*
		 * String data = dateFormat.format(now);
		 * 
		 * try { Date nowTime = dateFormat.parse(data);
		 * 
		 * // APP判断当前时间是否在停止时间中 如果是的状态改成2停止 如不是改成1启动 Calendar appdDate =
		 * Calendar.getInstance(); appdDate.setTime(nowTime); Calendar appBegin
		 * = Calendar.getInstance(); appBegin.setTime(appStartTime); Calendar
		 * appEnd = Calendar.getInstance(); appEnd.setTime(appEndTime); if
		 * (appdDate.after(appBegin) && appdDate.before(appEnd)) {
		 * quDaoQuanXianGuanLiDao.updateQuDaoStatus(App, 1); } else {
		 * quDaoQuanXianGuanLiDao.updateQuDaoStatus(App, 2); }
		 * 
		 * // 网厅判断当前时间是否在停止时间中 如果是的状态改成2停止 如不是改成1启动 Calendar wtDate =
		 * Calendar.getInstance(); wtDate.setTime(nowTime); Calendar wtBegin =
		 * Calendar.getInstance(); wtDate.setTime(wtStartTime); Calendar wtEnd =
		 * Calendar.getInstance(); wtEnd.setTime(wtEndTime); if
		 * (wtDate.after(wtBegin) && wtDate.before(wtEnd)) {
		 * quDaoQuanXianGuanLiDao.updateQuDaoStatus(wt, 1); } else {
		 * quDaoQuanXianGuanLiDao.updateQuDaoStatus(wt, 2); }
		 * 
		 * // 微信判断当前时间是否在停止时间中 如果是的状态改成2停止 如不是改成1启动 Calendar wxdDate =
		 * Calendar.getInstance(); wxdDate.setTime(nowTime); Calendar wxBegin =
		 * Calendar.getInstance(); wxdDate.setTime(wxStartTime); Calendar wxEnd
		 * = Calendar.getInstance(); wxEnd.setTime(wxEndTime); if
		 * (wxdDate.after(wxBegin) && wxdDate.before(wxEnd)) {
		 * quDaoQuanXianGuanLiDao.updateQuDaoStatus(wx, 1); } else {
		 * quDaoQuanXianGuanLiDao.updateQuDaoStatus(wx, 2); }
		 * 
		 * // 智能终端判断当前时间是否在停止时间中 如果是的状态改成2停止 如不是改成1启动 Calendar
		 * zhiNengZhongDuanDate = Calendar.getInstance();
		 * zhiNengZhongDuanDate.setTime(nowTime); Calendar zhiNengZhongDuanBegin
		 * = Calendar.getInstance();
		 * zhiNengZhongDuanDate.setTime(znzdStartTime); Calendar
		 * zhiNengZhongDuanEnd = Calendar.getInstance();
		 * zhiNengZhongDuanEnd.setTime(znzdEndTime); if
		 * (zhiNengZhongDuanDate.after(zhiNengZhongDuanBegin) &&
		 * zhiNengZhongDuanDate.before(zhiNengZhongDuanEnd)) {
		 * quDaoQuanXianGuanLiDao.updateQuDaoStatus(zhiNengZhongDuan, 1); } else
		 * { quDaoQuanXianGuanLiDao.updateQuDaoStatus(zhiNengZhongDuan, 2); }
		 */
		// System.err.println("3333333333333333333333333333333");
		///////////////////////////////////////////////////////////////////////////////
		// 实时管理在线人数阀值控制

		// 智能终端的访问人数限制的停止时间
		/*
		 * Date nowDate = new Date(); Date tzsjZNZDEndTime = (Date)
		 * quanXianGuanLiDtoZNZD.get("TZSJ");
		 * 
		 * 
		 * //微信的访问人数限制的停止时间 Date tzsjWXEndTime = (Date)
		 * quanXianGuanLiDtoWX.get("TZSJ");
		 * 
		 * 
		 * //手机App的访问人数限制的停止时间 Date tzsjAppEndTime = (Date)
		 * quanXianGuanLiDtoAPP.get("TZSJ");
		 * 
		 * 
		 * //网厅的访问人数限制的停止时间 Date tzsjWTEndTime = (Date)
		 * quanXianGuanLiDtoWT.get("TZSJ");
		 */

		// 停止时间，就是当前时间加上五分钟
		/*
		 * SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 * Calendar c2 = Calendar.getInstance(); c2 = Calendar.getInstance();
		 * c2.add(Calendar.MINUTE, +5); String tzsj = sdf2.format(c.getTime());
		 * 
		 * 
		 * System.err.println("44444444444444444444444444444444444444444444");
		 * //如果当前时间在停止时间之后，并且当前时间的访问人数超过了阀值数量，就改状态 boolean znzdflag =
		 * nowDate.after(tzsjZNZDEndTime); if (znzdflag) { // 智能终端限制人数 int
		 * zhiNengZhongDuanXianZhiCount =
		 * Integer.parseInt(quanXianGuanLiDtoZNZD.get("FZ").toString()); if
		 * (zhiNengZhongDuanCount >= zhiNengZhongDuanXianZhiCount) {
		 * quDaoQuanXianGuanLiDao.updateQuDaoSSStatus(zhiNengZhongDuan, 1,
		 * tzsj); } else {
		 * quDaoQuanXianGuanLiDao.updateQuDaoSSStatus(zhiNengZhongDuan, 2,
		 * null); } } boolean wxflag = nowDate.after(tzsjWXEndTime); if (wxflag)
		 * { // 微信限制人数 int wxXianZhiCount =
		 * Integer.parseInt(quanXianGuanLiDtoWX.get("FZ").toString()); if
		 * (wxCount >= wxXianZhiCount) {
		 * quDaoQuanXianGuanLiDao.updateQuDaoSSStatus(wx, 1, tzsj); } else {
		 * quDaoQuanXianGuanLiDao.updateQuDaoSSStatus(wx, 2, null); } } boolean
		 * appflag = nowDate.after(tzsjAppEndTime); if (appflag) { //手机app限制人数
		 * int appXianZhiCount =
		 * Integer.parseInt(quanXianGuanLiDtoAPP.get("FZ").toString()); if
		 * (appCount >= appXianZhiCount) {
		 * quDaoQuanXianGuanLiDao.updateQuDaoSSStatus(App, 1, tzsj); } else {
		 * quDaoQuanXianGuanLiDao.updateQuDaoSSStatus(App, 2, null); } } boolean
		 * wtflag = nowDate.after(tzsjWTEndTime); if (wtflag) { //网厅限制人数 int
		 * wtXianZhiCount =
		 * Integer.parseInt(quanXianGuanLiDtoWT.get("FZ").toString()); if
		 * (wtCount >= wtXianZhiCount) {
		 * quDaoQuanXianGuanLiDao.updateQuDaoSSStatus(wt, 1, tzsj); } else {
		 * quDaoQuanXianGuanLiDao.updateQuDaoSSStatus(App, 2, null); }
		 * 
		 * }
		 */

	}

	// 更新渠道状态
	public ResultDto updateQDZT(String qdid, String fz, String djsj, String qdzt) {
		ResultDto resultDto = new ResultDto();
		int num = quDaoQuanXianGuanLiDao.updateQDZT(qdid, qdzt, fz, djsj);
		if (num > 0) {
			resultDto.setSuccess(true);
		} else {
			resultDto.setSuccess(false);
		}
		return resultDto;
	}

	// 修改阀值和控制渠道权限的时间
	@Override
	public boolean updateTimeAndFz(String kssj, String jssj, String ksrq, String tzrq, String fz, String qdid,
			int qdzt) {
		Integer fzNum = Integer.parseInt(fz);
		Integer kssjNum = Integer.parseInt(kssj);
		Integer jssjNum = Integer.parseInt(jssj);
		Integer ksrqNum = Integer.parseInt(ksrq);
		Integer tzrqNum = Integer.parseInt(tzrq);

		if (fz != null && !fz.equals("") && ksrqNum > 0 && ksrqNum <= 31 && tzrqNum <= 31 && tzrqNum >= ksrqNum) {
			if (fzNum > 0 && kssjNum >= 0000 && kssjNum <= 2400 && jssjNum >= kssjNum && jssjNum <= 2400) {
				int num = quDaoQuanXianGuanLiDao.updateTimeAndFz(kssj, fzNum, jssj, ksrq, tzrq, qdid, qdzt);
				if (num > 0) {
					return true;
				} else {
					return false;
				}

			} else {
				return false;
			}
		} else {
			return false;
		}

	}

	// 修改短信状态
	@Override
	public void updateDuanXinZT(String zjzxdm, String dxzt) {
		quDaoQuanXianGuanLiDao.updateDuanXinZT(zjzxdm, dxzt);
	}

	// 渠道开关控制接口
	@Override
	public List<QuDaoQuanXianGuanLiDto> qdkzInfo(String qdid) {
		List<Map<String, Object>> dataList = quDaoQuanXianGuanLiDao.qdkzInfo(qdid);
		List<QuDaoQuanXianGuanLiDto> list = new ArrayList<QuDaoQuanXianGuanLiDto>();
		for (Map<String, Object> map : dataList) {
			QuDaoQuanXianGuanLiDto qDto = new QuDaoQuanXianGuanLiDto();
			qDto.setQdid(map.get("QDID").toString());
			qDto.setQdmc(map.get("QDMC").toString());
			qDto.setQdzt(map.get("QDZT").toString());
			qDto.setFz(map.get("FZ").toString());
			qDto.setMfzrs(map.get("MFZRS").toString());
			qDto.setDjsj(map.get("DJSJ").toString());
			list.add(qDto);
		}
		return list;
	}

	// 业务控制2
	@Override
	public Map<String, Object> sreachM_YWZTKZ_2(int limit, int page,String ywczlx_2,String ywmc,String issh,String ywbm) {
		Map<String, Object> map = new HashMap<>();
		try {
			Page<M_YWZTKZ_2> page2 = PageHelper.startPage(page, limit, true);
			List<M_YWZTKZ_2> list = quDaoQuanXianGuanLiDao.sreachM_YWZTKZ_2(ywczlx_2,ywmc,issh,ywbm);
			int count = (int) page2.getTotal();
			map.put("total", count);
			map.put("data", list);
		} catch (Exception e) {
			System.out.println("业务控制显示异常");
		}

		return map;
	}

	// 修改业务状态（保存按钮）
	@Override
	public ResultDto updateM_YWZTKZ_2State(String primaryid, String wtzt, String wxzt, String appzt, String znzdzt, String qyjssj, String qykssj, String qyksrq,
			String qyjsrq,String czlx,String czr,String qysjd,String ywbm,String ywlb) {
		ResultDto resultDto = new ResultDto();
		
		if (primaryid != null ) {
			String[] primaryids = primaryid.split(",");
			String[] ywlbs = ywlb.split(",");
			String[] ywbms = ywbm.split(",");
			String[] qysjds = qysjd.split(",");
			//String[] czrs = czr.split(",");
			for (int i = 0; i < primaryids.length; i++) {
				String id = primaryids[i];
				String ywlbs2 = ywlbs[i];
				String ywbms2 = ywbms[i];
				String qysjds2 = qysjds[i];
				//String czrs2 = czrs[i];
				int num2 = quDaoQuanXianGuanLiDao.updateM_YWZTKZ_2State(id,wtzt,wxzt,appzt,znzdzt,qyjssj,qykssj, qyksrq, qyjsrq,czlx);
				if (num2 > 0) {
					quDaoQuanXianGuanLiDao.fwkzLogging(ywlbs2, ywbms2, qysjds2, czr, "1", wxzt, appzt, znzdzt, wtzt);
					int num1 = quDaoQuanXianGuanLiDao.updateYWZT2("0", id,czlx);
					if (num1 > 0) {
						resultDto.setSuccess(true);
					} else {
						resultDto.setSuccess(false);
					}
					resultDto.setSuccess(true);
				} else {
					resultDto.setSuccess(false);
				}
			}
		}
		return resultDto;
	}

	// 渠道状态修改
	@Override
	public ResultDto updateQD_state(String qdzt, String fz, String djsj, String primaryid,String qdid,String czr) {
		ResultDto resultDto = new ResultDto();
		int num = quDaoQuanXianGuanLiDao.updateQD_state(qdzt, fz, djsj, primaryid);
		if (num > 0) {
			//渠道总控修改日志记录
			quDaoQuanXianGuanLiDao.qdzkLogging(qdzt, fz, djsj, qdid, czr, "0");
			resultDto.setSuccess(true);
		} else {
			resultDto.setSuccess(false);
		}

		return resultDto;
	}

	// 修改审核后业务状态
	@Override
	public ResultDto updateSHState(String primaryid,String czlx,String ywlb,String ywbm,String qysjd,String czr,String wxzt,String appzt,String znzdzt,String wtzt) {
		ResultDto resultDto = new ResultDto();

		int num1 = quDaoQuanXianGuanLiDao.updateYWZT2("1", primaryid,czlx);
		if (num1 > 0) {
			resultDto.setSuccess(true);
		} else {
			resultDto.setSuccess(false);
		}
		int num2 = quDaoQuanXianGuanLiDao.updateSHState(primaryid,czlx);
		if (num2 > 0) {
			quDaoQuanXianGuanLiDao.fwkzLogging(ywlb, ywbm, qysjd, czr, "3", wxzt, appzt, znzdzt, wtzt);
			resultDto.setSuccess(true);
		} else {
			resultDto.setSuccess(false);
		}
   
		return resultDto;
	}

	// 渠道业务控制接口
	@Override
	public int qdztkzInterface(String ywbm,String qdid) {
		M_YWZTKZ_2 mYwztkz_2  = quDaoQuanXianGuanLiDao.qdztkzInterface(ywbm);
		String tstzr = mYwztkz_2.getTstzr();
		// 特殊时间停止
		if (tstzr != null) {
			String[] tstzrs = tstzr.split(",");
			for (int i = 0; i < tstzrs.length; i++) {
				String tzr = tstzrs[i];
				String[] tstzsjs = tzr.split("-");
				String kssj = tstzsjs[0];// 开始拒绝时间
				String jssj = tstzsjs[0].substring(0, 2) + "2359";// 结束拒绝时间
				if (tstzsjs.length > 1) {
					jssj = tstzsjs[1];
				}
				if (kssj.length() == 6 && kssj.length() == 6) {
					boolean kssj_f = false;
					if (kssj.matches("^[0-3][0-9][0-2][0-9][0-5][0-9]$")) {
						kssj_f = true;
					}
					boolean jssj_f = false;
					if (jssj.matches("^[0-3][0-9][0-2][0-9][0-5][0-9]$")) {
						jssj_f = true;
					}
					if (kssj_f && jssj_f) {
						Date dt = new Date();
						SimpleDateFormat sdf = new SimpleDateFormat("ddHHmm");
						String nowdayhm = sdf.format(dt);
						int nowdayhm_i = Integer.parseInt(nowdayhm);
						int kssj_i = Integer.parseInt(kssj);
						int jssj_i = Integer.parseInt(jssj);
						if (nowdayhm_i >= kssj_i && nowdayhm_i <= jssj_i) {
							return 0;
						}
					}
				}

			}
		}
		
		String temp_str = "";
		Date dt = new Date();
		// 最后的aa表示“上午”或“下午” HH表示24小时制 如果换成hh表示12小时制
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		temp_str = sdf.format(dt);
		// 日期
		String day = temp_str.substring(8, 10);
		// 时间
		String sj = temp_str.substring(11, 13) + temp_str.substring(14, 16);
		int num = 0;
		// 审核业务状态
		int shywzt = 0;
		
		if (qdid.equals("02")) {
			shywzt = mYwztkz_2.getShwtzt();
		}else if (qdid.equals("05")) {
			shywzt = mYwztkz_2.getShwxzt();
		}else if (qdid.equals("06")) {
			shywzt = mYwztkz_2.getShappzt();
		}else {
			shywzt = mYwztkz_2.getShznzdzt();
		}
		
		if (shywzt > 0) {
			num = quDaoQuanXianGuanLiDao.qdztkzInterface2(ywbm, day, sj);
			if (num > 0) {
				return 1;
			} else {
				return 0;
			}
		} else {
			return 0;
		}
	}

	// 短信控制信息
	@Override
	public Map<String, Object> dxkzInfo(String page,String limit) throws IOException {
		Map<String, Object> map = new HashMap<>();
		PageDto pDto = new PageDto();
		int pageNum = Integer.parseInt(page);
		int pageSize2 = Integer.parseInt(limit);

	    
//		pDto.setSizeCountStart(String.valueOf(sizeCountStart));
//		pDto.setSizeCountEnd(String.valueOf(sizeCountEnd));
		String fileName = "mybatis.xml";
		InputStream inputStream = Resources.getResourceAsStream(fileName);
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		SqlSession sqlSession = sqlSessionFactory.openSession(false);// 通过这种方式打开的SqlSession，autoCommit默认为false，需要手动提交事务
		DuanXinQuanXianGuanLiDto qDto = new DuanXinQuanXianGuanLiDto();
		sqlSession.selectList("com.changda.gjjapp.zhfwpt.dao.qdywqxgl.QuDaoQuanXianGuanLiDao.dxkzInfo",qDto);
		
		Page<DuanXinQuanXianGuanLiDto> page2 = PageHelper.startPage(pageNum, pageSize2, true);
		
		// 循环查询临时表
		List<DuanXinQuanXianGuanLiDto> list2 = sqlSession.selectList("com.changda.gjjapp.zhfwpt.dao.qdywqxgl.QuDaoQuanXianGuanLiDao.tMP_SMS_DIS",pDto);
		
		
		List<Page2> list = sqlSession.selectList("com.changda.gjjapp.zhfwpt.dao.qdywqxgl.QuDaoQuanXianGuanLiDao.tMP_SMS_DIS2");
		//总记录数
		Page2 page3=list.get(0);

		map.put("total", page3.getRowCount());
		map.put("list", list2); 
		
		// 提交事务
		sqlSession.commit();
		sqlSession.close();
		inputStream.close();
		return map;

	}

	//限额控制信息
	@Override
	public List<M_XEKZB> xekzInfo() {
		
		return quDaoQuanXianGuanLiDao.xekzInfo();
	}

	//修改限额值
	@Override
	public ResultDto xeUpdate(String id, String value) {
		ResultDto resultDto = new ResultDto();
		int num = quDaoQuanXianGuanLiDao.xeUpdate(id, value);
		if (num > 0) {
			resultDto.setSuccess(true);
		}else {
			resultDto.setSuccess(false);
		}
		return resultDto;
	}


    //渠道总控修改日志记录
	@Override
	public Map<String, Object> qdzkLoggingInfo(String qdid,String czsj,int page, int limit) {
		Map<String, Object> map = new HashMap<>();
		try {
			Page<QdzkLoggingInfoDto> page2 = PageHelper.startPage(page, limit, true);
			List<QdzkLoggingInfoDto> list = quDaoQuanXianGuanLiDao.qdzkLoggingInfo(czsj,qdid);
			int count = (int) page2.getTotal();
			map.put("total", count);
			map.put("data", list);
		} catch (Exception e) {
			System.out.println("渠道总控日志异常");
		}

		return map;

	}

	//服务控制日志记录
	@Override
	public Map<String, Object> fwkzLoggingInfo(int page,int limit,String ywbm) {
		Map<String, Object> map = new HashMap<>();
		try {
			Page<FwkzLogginInfoDto> page2 = PageHelper.startPage(page, limit, true);
			List<FwkzLogginInfoDto> list = quDaoQuanXianGuanLiDao.fwkzLoggingInfo(ywbm);
			int count = (int) page2.getTotal();
			map.put("total", count);
			map.put("data", list);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("服务控制显示异常");
		}

		return map;
	}


}
