YtiotTMaintenancePlanServicesImpl.java 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  1. package cn.com.usky.iot.maintenanceplan.service;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.Calendar;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.ArrayList;
  8. import java.util.Map;
  9. import cn.com.usky.iot.entity.YtiotTMaintenancePlan;
  10. import cn.com.usky.iot.entity.YtiotTPatrolPlan;
  11. import cn.com.usky.iot.entity.YtiotTRoute;
  12. import cn.com.usky.iot.entity.YtiotVUsercompany;
  13. import cn.com.usky.iot.entity.YtiotVUsercompanyId;
  14. import cn.com.usky.iot.entity.YtiotTAdmin;
  15. import cn.com.usky.iot.entity.YtiotTArea;
  16. import cn.com.usky.iot.entity.YtiotTInspectors;
  17. import cn.com.usky.iot.entity.YtiotTMaintenancePerson;
  18. import cn.com.usky.iot.entity.YtiotTRoute2;
  19. import cn.com.usky.iot.entity.YtiotVUsercompany;
  20. import cn.com.usky.iot.entity.YtiotVUsercompanyId;
  21. import cn.com.usky.iot.admin.dao.YtiotVUserCompanyDao;
  22. import cn.com.usky.iot.admin.dao.YtiotTAdminDao;
  23. import cn.com.usky.iot.maintenanceperson.dao.YtiotTMaintenancePersonDao;
  24. import cn.com.usky.iot.maintenanceplan.dao.YtiotTMaintenancePlanDao;
  25. import cn.com.usky.iot.route2.dao.YtiotTRoute2Dao;
  26. import cn.com.usky.utils.DaoResult;
  27. import cn.com.usky.utils.MD5Util;
  28. import net.sf.json.JSONArray;
  29. import net.sf.json.JSONObject;
  30. public class YtiotTMaintenancePlanServicesImpl implements YtiotTMaintenancePlanService {
  31. private YtiotTMaintenancePlanDao ytiotTMaintenancePlanDao;
  32. private YtiotVUserCompanyDao ytiotVUserCompanyDao;
  33. private YtiotTAdminDao ytiotTAdminDao;
  34. private YtiotTRoute2Dao ytiotTRoute2Dao;
  35. private YtiotTMaintenancePersonDao ytiotTMaintenancePersonDao;
  36. public YtiotTAdminDao getYtiotTAdminDao() {
  37. return ytiotTAdminDao;
  38. }
  39. public void setYtiotTAdminDao(YtiotTAdminDao ytiotTAdminDao) {
  40. this.ytiotTAdminDao = ytiotTAdminDao;
  41. }
  42. public YtiotTMaintenancePlanDao getYtiotTMaintenancePlanDao() {
  43. return ytiotTMaintenancePlanDao;
  44. }
  45. public void setYtiotTMaintenancePlanDao(YtiotTMaintenancePlanDao ytiotTMaintenancePlanDao) {
  46. this.ytiotTMaintenancePlanDao = ytiotTMaintenancePlanDao;
  47. }
  48. public YtiotVUserCompanyDao getYtiotVUserCompanyDao() {
  49. return ytiotVUserCompanyDao;
  50. }
  51. public void setYtiotVUserCompanyDao(YtiotVUserCompanyDao ytiotVUserCompanyDao) {
  52. this.ytiotVUserCompanyDao = ytiotVUserCompanyDao;
  53. }
  54. public YtiotTMaintenancePersonDao getYtiotTMaintenancePersonDao() {
  55. return ytiotTMaintenancePersonDao;
  56. }
  57. public void setYtiotTMaintenancePersonDao(YtiotTMaintenancePersonDao ytiotTMaintenancePersonDao) {
  58. this.ytiotTMaintenancePersonDao = ytiotTMaintenancePersonDao;
  59. }
  60. public YtiotTRoute2Dao getYtiotTRoute2Dao() {
  61. return ytiotTRoute2Dao;
  62. }
  63. public void setYtiotTRoute2Dao(YtiotTRoute2Dao ytiotTRoute2Dao) {
  64. this.ytiotTRoute2Dao = ytiotTRoute2Dao;
  65. }
  66. public boolean chk_string_param(String param) {
  67. if(param==null)
  68. return true;
  69. if(param.indexOf("=")>=0)
  70. return false;
  71. if(param.indexOf("\'")>=0)
  72. return false;
  73. if(param.indexOf("\"")>=0)
  74. return false;
  75. return true;
  76. }
  77. public String chkhw(String hqlwhere){
  78. if(hqlwhere==null)
  79. return " where ";
  80. else
  81. return hqlwhere+" and ";
  82. }
  83. public String fieldname(String field){
  84. if(field.equals("id"))
  85. return "id";
  86. if(field.equals("personnel"))
  87. return "personnel";
  88. if(field.equals("route"))
  89. return "route";
  90. if(field.equals("planned_date"))
  91. return "plannedDate";
  92. if(field.equals("start_time"))
  93. return "startTime";
  94. if(field.equals("end_time"))
  95. return "endTime";
  96. if(field.equals("completion_status"))
  97. return "completionStatus";
  98. if(field.equals("name"))
  99. return "name";
  100. if(field.equals("route_name"))
  101. return "routeName";
  102. if(field.equals("company_code"))
  103. return "companyCode";
  104. return null;
  105. }
  106. public static String[] getDates(String dateFrom, String dateEnd, String weekDays) {
  107. long time = 1l;
  108. long perDayMilSec = 24 * 60 * 60 * 1000;
  109. List<String> dateList = new ArrayList<String>();
  110. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  111. //需要查询的星期系数
  112. String strWeekNumber = weekForNum(weekDays);
  113. try {
  114. dateFrom = sdf.format(sdf.parse(dateFrom).getTime() - perDayMilSec);
  115. while (true) {
  116. time = sdf.parse(dateFrom).getTime();
  117. time = time + perDayMilSec;
  118. Date date = new Date(time);
  119. dateFrom = sdf.format(date);
  120. if (dateFrom.compareTo(dateEnd) <= 0) {
  121. //查询的某一时间的星期系数
  122. Integer weekDay = dayForWeek(date);
  123. //判断当期日期的星期系数是否是需要查询的
  124. if (strWeekNumber.indexOf(weekDay.toString())!=-1) {
  125. System.out.println(dateFrom);
  126. dateList.add(dateFrom);
  127. }
  128. } else {
  129. break;
  130. }
  131. }
  132. } catch (Exception e1) {
  133. e1.printStackTrace();
  134. }
  135. String[] dateArray = new String[dateList.size()];
  136. dateList.toArray(dateArray);
  137. return dateArray;
  138. }
  139. //等到当期时间的周系数。星期日:1,星期一:2,星期二:3,星期三:4,星期四:5,星期五:6,星期六:7
  140. public static Integer dayForWeek(Date date) {
  141. Calendar calendar = Calendar.getInstance();
  142. calendar.setTime(date);
  143. return calendar.get(Calendar.DAY_OF_WEEK);
  144. }
  145. /**
  146. * 得到对应星期的系数 星期日:1,星期一:2,星期二:3,星期三:4,星期四:5,星期五:6,星期六:7
  147. * @param weekDays 星期格式 星期一|星期二
  148. */
  149. public static String weekForNum(String weekDays){
  150. //返回结果为组合的星期系数
  151. String weekNumber = "";
  152. //解析传入的星期
  153. if(weekDays.indexOf("|")!=-1){//多个星期数
  154. String []strWeeks = weekDays.split("\\|");
  155. for(int i=0;i<strWeeks.length;i++){
  156. weekNumber = weekNumber + "" + getWeekNum(strWeeks[i]).toString();
  157. }
  158. }else{//一个星期数
  159. weekNumber = getWeekNum(weekDays).toString();
  160. }
  161. return weekNumber;
  162. }
  163. //将星期转换为对应的系数 星期日:1,星期一:2,星期二:3,星期三:4,星期四:5,星期五:6,星期六:7
  164. public static Integer getWeekNum(String strWeek){
  165. Integer number = 1;//默认为星期日
  166. if("星期日".equals(strWeek)){
  167. number = 1;
  168. }else if("星期一".equals(strWeek)){
  169. number = 2;
  170. }else if("星期二".equals(strWeek)){
  171. number = 3;
  172. }else if("星期三".equals(strWeek)){
  173. number = 4;
  174. }else if("星期四".equals(strWeek)){
  175. number = 5;
  176. }else if("星期五".equals(strWeek)){
  177. number = 6;
  178. }else if("星期六".equals(strWeek)){
  179. number = 7;
  180. }
  181. return number;
  182. }
  183. @Override
  184. public String appendMaintenancePlan(String queryJson) throws Exception {
  185. // TODO Auto-generated method stub
  186. String id = null;
  187. String personnel = null;
  188. String route = null;
  189. String Inspectiontime = null;
  190. String start_time = null;
  191. String end_time = null;
  192. String start_data = null;
  193. String end_data = null;
  194. String completion_status = null;
  195. String demoArray[]=null;
  196. String V_LOGINNAME = null;
  197. String Company_Code_List = null;
  198. JSONObject q_json = null;
  199. JSONArray jSONArray = new JSONArray();
  200. JSONObject json = new JSONObject();
  201. json.put("action", "appendMaintenancePlan");
  202. if(queryJson!=null) {
  203. q_json = JSONObject.fromObject(queryJson);
  204. personnel = q_json.has("personnel")?q_json.getString("personnel"):null;
  205. route = q_json.has("route")?q_json.getString("route"):null;
  206. Company_Code_List = q_json.has("company_code")?q_json.getString("company_code"):null;
  207. Inspectiontime = q_json.has("Inspectiontime")?q_json.getString("Inspectiontime"):null;
  208. start_time = q_json.has("start_time")?q_json.getString("start_time"):null;
  209. end_time = q_json.has("end_time")?q_json.getString("end_time"):null;
  210. start_data = q_json.has("start_data")?q_json.getString("start_data"):null;
  211. end_data = q_json.has("end_data")?q_json.getString("end_data"):null;
  212. completion_status = q_json.has("completion_status")?q_json.getString("completion_status"):null;
  213. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  214. json.put("query", queryJson);
  215. }
  216. // if((V_LOGINNAME!=null)&&(Company_Code_List==null)&&(!V_LOGINNAME.equals("admin"))) {
  217. // String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  218. // List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  219. // if(list.size()>0) {
  220. // for(int i=0;i<list.size();i++) {
  221. // YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  222. // YtiotVUsercompanyId oid = o.getId();
  223. // if(!oid.getOwnerCode().equals("10012")&& !oid.getOwnerCode().equals("10068")) {
  224. //
  225. // Company_Code_List = oid.getOwnerCode();
  226. //
  227. // }
  228. // }
  229. // }
  230. // }
  231. // System.out.println(Company_Code_List);
  232. demoArray=getDates(start_data, end_data,Inspectiontime);
  233. if(chk_string_param(personnel)&&chk_string_param(route)&&chk_string_param(Inspectiontime)
  234. &&chk_string_param(start_time)&&chk_string_param(end_time)&&chk_string_param(completion_status)) {
  235. YtiotTMaintenancePlan o = new YtiotTMaintenancePlan();
  236. // float F_HEIGHT1 = Float.parseFloat(F_HEIGHT);
  237. for(int i=0;i<demoArray.length;i++) {
  238. o.setPlannedDate(demoArray[i]);
  239. o.setPersonnel(personnel);
  240. o.setCompanyCode(Company_Code_List);
  241. o.setRoute(route);
  242. // o.setPlannedDate(planned_date);
  243. o.setStartTime(start_time);
  244. o.setEndTime(end_time);
  245. o.setCompletionStatus("0");
  246. DaoResult ret = ytiotTMaintenancePlanDao.add(o);
  247. }
  248. json.put("success", true);
  249. json.put("Msg", "成功加入数据库");
  250. }else {
  251. json.put("success", false);
  252. json.put("Msg", "参数验证错误");
  253. }
  254. return json.toString();
  255. }
  256. @Override
  257. public String updateMaintenancePlan(String queryJson) throws Exception {
  258. // TODO Auto-generated method stub
  259. String id = null;
  260. String personnel = null;
  261. String route = null;
  262. String planned_date = null;
  263. String start_time = null;
  264. String end_time = null;
  265. String completion_status = null;
  266. String hqlwhere = null;
  267. String hqlwhere1 = null;
  268. JSONObject q_json = null;
  269. JSONArray jSONArray = new JSONArray();
  270. JSONObject json = new JSONObject();
  271. json.put("action", "updateMaintenancePlan");
  272. if(queryJson!=null) {
  273. q_json = JSONObject.fromObject(queryJson);
  274. id = q_json.has("id")?q_json.getString("id"):null;
  275. personnel = q_json.has("personnel")?q_json.getString("personnel"):null;
  276. route = q_json.has("route")?q_json.getString("route"):null;
  277. planned_date = q_json.has("planned_date")?q_json.getString("planned_date"):null;
  278. start_time = q_json.has("start_time")?q_json.getString("start_time"):null;
  279. end_time = q_json.has("end_time")?q_json.getString("end_time"):null;
  280. completion_status = q_json.has("completion_status")?q_json.getString("completion_status"):null;
  281. json.put("query", queryJson);
  282. }
  283. if(personnel!=null)
  284. hqlwhere = "u."+fieldname("name")+"='"+personnel+"'";
  285. List list1 =ytiotTMaintenancePlanDao.query1(hqlwhere);
  286. YtiotTMaintenancePerson g = (YtiotTMaintenancePerson)list1.get(0);
  287. String personnel_id = Integer.toString(g.getId());
  288. if(route!=null)
  289. hqlwhere1 = "u."+fieldname("route_name")+"='"+route+"'";
  290. List list2 =ytiotTMaintenancePlanDao.query2(hqlwhere1);
  291. YtiotTRoute2 r = (YtiotTRoute2)list2.get(0);
  292. String route_id = Integer.toString(r.getId());
  293. if(chk_string_param(id)&&chk_string_param(route_id)&&chk_string_param(personnel_id)&&chk_string_param(planned_date)
  294. &&chk_string_param(start_time)&&chk_string_param(end_time)&&chk_string_param(completion_status)) {
  295. if(id!=null) {
  296. List list = ytiotTMaintenancePlanDao.query(" where u."+fieldname("id")+" ='"+id+"' ", null, null, null, null);
  297. if(list.size()>0) {
  298. YtiotTMaintenancePlan o = (YtiotTMaintenancePlan) list.get(0);
  299. if(personnel!=null)
  300. o.setPersonnel(personnel_id);
  301. if(route!=null)
  302. o.setRoute(route_id);
  303. if(planned_date!=null)
  304. o.setPlannedDate(planned_date);
  305. if(start_time!=null)
  306. o.setStartTime(start_time);
  307. if(end_time!=null)
  308. o.setEndTime(end_time);
  309. if(completion_status!=null)
  310. o.setCompletionStatus(completion_status);
  311. DaoResult ret = ytiotTMaintenancePlanDao.update(o);
  312. json.put("success", ret.isSuccess());
  313. json.put("MSG", ret.getResult());
  314. }else {
  315. json.put("success", false);
  316. json.put("MSG", "需要编辑的权限记录不存在");
  317. }
  318. }else {
  319. json.put("success", false);
  320. json.put("MSG", "记录ID不能为空");
  321. }
  322. }else {
  323. json.put("success", false);
  324. json.put("MSG", "参数验证错误");
  325. }
  326. return json.toString();
  327. }
  328. @Override
  329. public String getMaintenancePlanList(String queryJson, String page, String start, String limit, String sort) throws Exception {
  330. // TODO Auto-generated method stub
  331. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  332. String id = null;
  333. String personnel = null;
  334. String route = null;
  335. String planned_date = null;
  336. String start_time = null;
  337. String end_time = null;
  338. String completion_status = null;
  339. String company_code = null;
  340. String Company_Code_List = null;
  341. String V_LOGINNAME = null;
  342. String Page = null;
  343. String Start = null;
  344. JSONArray Sort = null;
  345. String Limit = null;
  346. String hqlwhere4 = null;
  347. String hqlwhere3 = null;
  348. String hqlwhere2 = null;
  349. String hqlwhere1 = null;
  350. String hqlwhere = null;
  351. String order = null;
  352. String dir = null;
  353. String order_str = null;
  354. JSONObject q_json = null;
  355. JSONArray jSONArray = new JSONArray();
  356. JSONObject json = new JSONObject();
  357. json.put("action", "getMaintenancePlanList");
  358. if(queryJson!=null) {
  359. q_json = JSONObject.fromObject(queryJson);
  360. id = q_json.has("id")?q_json.getString("id"):null;
  361. personnel = q_json.has("personnel")?q_json.getString("personnel"):null;
  362. route = q_json.has("route")?q_json.getString("route"):null;
  363. planned_date = q_json.has("planned_date")?q_json.getString("planned_date"):null;
  364. start_time = q_json.has("start_time")?q_json.getString("start_time"):null;
  365. end_time = q_json.has("end_time")?q_json.getString("end_time"):null;
  366. completion_status = q_json.has("completion_status")?q_json.getString("completion_status"):null;
  367. order = q_json.has("order")?q_json.getString("order"):null;
  368. dir = q_json.has("dir")?q_json.getString("dir"):null;
  369. Start = q_json.has("start")?q_json.getString("start"):(start!=null)?start:"0";
  370. Limit = q_json.has("limit")?q_json.getString("limit"):(limit!=null)?limit:null;
  371. Page = q_json.has("page")?q_json.getString("page"):(page!=null)?page:"0";
  372. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  373. json.put("query", queryJson);
  374. }
  375. if(personnel!=null) {
  376. hqlwhere3 = "u."+fieldname("name")+"='"+personnel+"'";
  377. List list3 =ytiotTMaintenancePlanDao.query1(hqlwhere3);
  378. YtiotTMaintenancePerson p = (YtiotTMaintenancePerson)list3.get(0);
  379. personnel = Integer.toString(p.getId());
  380. }
  381. if(route!=null) {
  382. hqlwhere4 = "u."+fieldname("route_name")+"='"+route+"'";
  383. List list4 =ytiotTMaintenancePlanDao.query2(hqlwhere4);
  384. YtiotTRoute2 t = (YtiotTRoute2)list4.get(0);
  385. route = Integer.toString(t.getId());
  386. }
  387. // System.out.println();
  388. if(sort!=null) {
  389. Sort = JSONArray.fromObject(sort);
  390. if((Sort.isArray())&&(Sort.size()>0)) {
  391. JSONObject s_json = Sort.getJSONObject(0);
  392. order = s_json.has("property")?s_json.getString("property"):order;
  393. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  394. }
  395. json.put("sort", sort);
  396. }
  397. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  398. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  399. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  400. if(list.size()>0) {
  401. for(int i=0;i<list.size();i++) {
  402. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  403. YtiotVUsercompanyId oid = o.getId();
  404. if(i==0)
  405. Company_Code_List = oid.getOwnerCode();
  406. else
  407. Company_Code_List += ","+oid.getOwnerCode();
  408. }
  409. }
  410. }
  411. Start = start;
  412. Limit = limit;
  413. Page = page;
  414. if(Company_Code_List!=null)
  415. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  416. if(personnel!=null)
  417. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("personnel")+"='"+personnel+"'";
  418. if(route!=null)
  419. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("route")+"='"+route+"'";
  420. if(start_time!=null)
  421. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("start_time")+"='"+start_time+"'";
  422. if(end_time!=null)
  423. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("end_time")+"='"+end_time+"'";
  424. if(planned_date!=null)
  425. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("planned_date")+" like '%"+planned_date+"%'";
  426. if(completion_status!=null)
  427. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("completion_status")+"='"+completion_status+"'";
  428. if(order!=null)
  429. order_str = " order by u."+fieldname(order);
  430. else
  431. order_str = " order by u."+fieldname("id");
  432. int totalCount = ytiotTMaintenancePlanDao.getCount(hqlwhere);
  433. //System.out.println(totalCount);
  434. json.put("totalCount", totalCount);
  435. if(Start!=null){
  436. if(Integer.parseInt(Start)>totalCount){
  437. Start = "0";
  438. Page = "0";
  439. }
  440. if(page==null)
  441. Page="0";
  442. }else{
  443. Start = "0";
  444. Page = "0";
  445. }
  446. json.put("page", Page);
  447. json.put("start", Start);
  448. json.put("limit", Limit);
  449. if(totalCount>0) {
  450. List list = ytiotTMaintenancePlanDao.query(hqlwhere, order_str, dir, Start, Limit);
  451. if(list.size()>0) {
  452. for(int i=0;i<list.size();i++) {
  453. YtiotTMaintenancePlan o = (YtiotTMaintenancePlan)list.get(i);
  454. Map map = new HashMap();
  455. if(o.getPersonnel()!=null) {
  456. hqlwhere1 = "u."+fieldname("id")+"='"+o.getPersonnel()+"'";
  457. List list1 = ytiotTMaintenancePlanDao.query1(hqlwhere1);
  458. if(list1.size()>0) {
  459. YtiotTMaintenancePerson g = (YtiotTMaintenancePerson)list1.get(0);
  460. map.put("personnel", g.getName());
  461. }
  462. }
  463. if(o.getRoute()!=null) {
  464. hqlwhere2 = "u."+fieldname("id")+"='"+o.getRoute()+"'";
  465. List list2 = ytiotTMaintenancePlanDao.query2(hqlwhere2);
  466. if(list2.size()>0) {
  467. YtiotTRoute2 r = (YtiotTRoute2)list2.get(0);
  468. map.put("route", r.getRouteName());
  469. }
  470. }
  471. map.put("id", o.getId());
  472. // map.put("personnel", o.getPersonnel());
  473. // map.put("route", o.getRoute());
  474. map.put("planned_date", o.getPlannedDate());
  475. map.put("start_time", o.getStartTime());
  476. map.put("end_time", o.getEndTime());
  477. map.put("completion_status", o.getCompletionStatus());
  478. //map.put("E_STATUS", o.getEStatus());
  479. // map.put("D_STORETIME", formatter.format(o.getDStoretime()));
  480. JSONObject jSONObject = JSONObject.fromObject(map);
  481. jSONArray.add(jSONObject);
  482. }
  483. json.put("RESULT", jSONArray);
  484. }
  485. }
  486. return json.toString();
  487. }
  488. @Override
  489. public String getMaintenancePlanExcelList(String queryJson) throws Exception {
  490. // TODO Auto-generated method stub
  491. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  492. String id = null;
  493. String personnel = null;
  494. String route = null;
  495. String planned_date = null;
  496. String start_time = null;
  497. String end_time = null;
  498. String completion_status = null;
  499. String company_code = null;
  500. String Company_Code_List = null;
  501. String V_LOGINNAME = null;
  502. String Page = null;
  503. String Start = null;
  504. JSONArray Sort = null;
  505. String Limit = null;
  506. String hqlwhere4 = null;
  507. String hqlwhere3 = null;
  508. String hqlwhere2 = null;
  509. String hqlwhere1 = null;
  510. String hqlwhere = null;
  511. String order = null;
  512. String dir = null;
  513. String order_str = null;
  514. JSONObject q_json = null;
  515. JSONArray jSONArray = new JSONArray();
  516. JSONObject json = new JSONObject();
  517. json.put("action", "getMaintenancePlanList");
  518. if(queryJson!=null) {
  519. q_json = JSONObject.fromObject(queryJson);
  520. id = q_json.has("id")?q_json.getString("id"):null;
  521. personnel = q_json.has("personnel")?q_json.getString("personnel"):null;
  522. route = q_json.has("route")?q_json.getString("route"):null;
  523. planned_date = q_json.has("planned_date")?q_json.getString("planned_date"):null;
  524. start_time = q_json.has("start_time")?q_json.getString("start_time"):null;
  525. end_time = q_json.has("end_time")?q_json.getString("end_time"):null;
  526. completion_status = q_json.has("completion_status")?q_json.getString("completion_status"):null;
  527. order = q_json.has("order")?q_json.getString("order"):null;
  528. dir = q_json.has("dir")?q_json.getString("dir"):null;
  529. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  530. json.put("query", queryJson);
  531. }
  532. if((personnel!=null)&&(personnel.length()>0)) {
  533. hqlwhere3 = "u."+fieldname("name")+"='"+personnel+"'";
  534. List list3 =ytiotTMaintenancePlanDao.query1(hqlwhere3);
  535. YtiotTInspectors p = (YtiotTInspectors)list3.get(0);
  536. personnel = Integer.toString(p.getId());
  537. }
  538. if((route!=null)&&(route.length()>0)) {
  539. hqlwhere4 = "u."+fieldname("route_name")+"='"+route+"'";
  540. List list4 =ytiotTMaintenancePlanDao.query2(hqlwhere4);
  541. YtiotTRoute t = (YtiotTRoute)list4.get(0);
  542. route = Integer.toString(t.getId());
  543. }
  544. // System.out.println();
  545. if((V_LOGINNAME!=null)&&(company_code==null)&&(Company_Code_List==null)) {
  546. String where = " where u.id.agentid='"+V_LOGINNAME+"' ";
  547. List list = ytiotVUserCompanyDao.query(where, null, null, null, null);
  548. if(list.size()>0) {
  549. for(int i=0;i<list.size();i++) {
  550. YtiotVUsercompany o = (YtiotVUsercompany)list.get(i);
  551. YtiotVUsercompanyId oid = o.getId();
  552. if(i==0)
  553. Company_Code_List = oid.getOwnerCode();
  554. else
  555. Company_Code_List += ","+oid.getOwnerCode();
  556. }
  557. }
  558. }
  559. if(Company_Code_List!=null)
  560. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+" in ("+Company_Code_List+") ";
  561. if((personnel!=null)&&(personnel.length()>0))
  562. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("personnel")+"='"+personnel+"'";
  563. if((route!=null)&&(route.length()>0))
  564. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("route")+"='"+route+"'";
  565. if((start_time!=null)&&(start_time.length()>0))
  566. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("start_time")+"='"+start_time+"'";
  567. if((end_time!=null)&&(end_time.length()>0))
  568. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("end_time")+"='"+end_time+"'";
  569. if((planned_date!=null)&&(planned_date.length()>0))
  570. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("planned_date")+"='"+planned_date+"'";
  571. if(completion_status!=null)
  572. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("completion_status")+"='"+completion_status+"'";
  573. System.out.println(hqlwhere);
  574. if(order!=null)
  575. order_str = " order by u."+fieldname(order);
  576. else
  577. order_str = " order by u."+fieldname("id");
  578. int totalCount = ytiotTMaintenancePlanDao.getCount(hqlwhere);
  579. json.put("totalCount", totalCount);
  580. if(totalCount>0) {
  581. List list = ytiotTMaintenancePlanDao.query(hqlwhere, order_str, dir, Start, Limit);
  582. if(list.size()>0) {
  583. for(int i=0;i<list.size();i++) {
  584. YtiotTMaintenancePlan o = (YtiotTMaintenancePlan)list.get(i);
  585. Map map = new HashMap();
  586. if(o.getPersonnel()!=null) {
  587. hqlwhere1 = "u."+fieldname("id")+"='"+o.getPersonnel()+"'";
  588. List list1 = ytiotTMaintenancePlanDao.query1(hqlwhere1);
  589. if(list1.size()>0) {
  590. YtiotTMaintenancePerson g = (YtiotTMaintenancePerson)list1.get(0);
  591. map.put("personnel", g.getName());
  592. }
  593. }
  594. if(o.getRoute()!=null) {
  595. hqlwhere2 = "u."+fieldname("id")+"='"+o.getRoute()+"'";
  596. List list2 = ytiotTMaintenancePlanDao.query2(hqlwhere2);
  597. if(list2.size()>0) {
  598. YtiotTRoute2 r = (YtiotTRoute2)list2.get(0);
  599. map.put("route", r.getRouteName());
  600. }
  601. }
  602. map.put("id", o.getId());
  603. map.put("planned_date", o.getPlannedDate());
  604. map.put("start_time", o.getStartTime());
  605. map.put("end_time", o.getEndTime());
  606. map.put("completion_status", o.getCompletionStatus());
  607. JSONObject jSONObject = JSONObject.fromObject(map);
  608. jSONArray.add(jSONObject);
  609. }
  610. json.put("result", jSONArray);
  611. }
  612. }
  613. return json.toString();
  614. }
  615. // 巡检记录
  616. @Override
  617. public String getCheckRecord2List(String queryJson, String page, String start, String limit, String sort) throws Exception {
  618. // TODO Auto-generated method stub
  619. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  620. //设置时间格式,将该时间格式的时间转换为时间戳
  621. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  622. String id = null;
  623. String personnel = null;
  624. String route = null;
  625. String planned_date = null;
  626. String start_time = null;
  627. String end_time = null;
  628. String completion_status = null;
  629. String sjc1=null;
  630. String sjc2=null;
  631. String company_code=null;
  632. String V_LOGINNAME = null;
  633. String V_PASSWORD = null;
  634. int E_STATUS=-1;
  635. String company_code_list = null;
  636. String Page = null;
  637. String Start = null;
  638. JSONArray Sort = null;
  639. String Limit = null;
  640. String hqlwhere4 = null;
  641. String hqlwhere3 = null;
  642. String hqlwhere2 = null;
  643. String hqlwhere1 = null;
  644. String hqlwhere = null;
  645. String order = null;
  646. String dir = null;
  647. String order_str = null;
  648. JSONObject q_json = null;
  649. JSONArray jSONArray = new JSONArray();
  650. JSONObject json = new JSONObject();
  651. json.put("action", "getMaintenancePlanList");
  652. if(queryJson!=null) {
  653. q_json = JSONObject.fromObject(queryJson);
  654. id = q_json.has("id")?q_json.getString("id"):null;
  655. personnel = q_json.has("personnel")?q_json.getString("personnel"):null;
  656. route = q_json.has("route")?q_json.getString("route"):null;
  657. planned_date = q_json.has("planned_date")?q_json.getString("planned_date"):null;
  658. start_time = q_json.has("start_time")?q_json.getString("start_time"):null;
  659. end_time = q_json.has("end_time")?q_json.getString("end_time"):null;
  660. completion_status = q_json.has("completion_status")?q_json.getString("completion_status"):null;
  661. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  662. V_PASSWORD = q_json.has("V_PASSWORD")?q_json.getString("V_PASSWORD"):null;
  663. order = q_json.has("order")?q_json.getString("order"):null;
  664. dir = q_json.has("dir")?q_json.getString("dir"):null;
  665. Start = q_json.has("start")?q_json.getString("start"):(start!=null)?start:"0";
  666. Limit = q_json.has("limit")?q_json.getString("limit"):(limit!=null)?limit:null;
  667. Page = q_json.has("page")?q_json.getString("page"):(page!=null)?page:"0";
  668. json.put("query", queryJson);
  669. }
  670. if((V_LOGINNAME!=null)&&(V_PASSWORD!=null)) {
  671. List list88 = ytiotTAdminDao.query(" where MD5(u.VLoginname)='"+MD5Util.EncoderByMd5(V_LOGINNAME)+"' and u.VPassword='"
  672. +V_PASSWORD+"' ", null, null, null, null);
  673. if(list88.size()>0) {
  674. YtiotTAdmin b2 = (YtiotTAdmin)list88.get(0);
  675. System.out.println("测试1"+b2.getEStatus());
  676. E_STATUS = Integer.parseInt(b2.getEStatus());
  677. // System.out.println("测试2"+E_STATUS);
  678. }
  679. }
  680. if(E_STATUS==1) {
  681. if(V_LOGINNAME!=null) {
  682. String where99 = " where u.id.agentid='"+V_LOGINNAME+"' ";
  683. List list66 = ytiotVUserCompanyDao.query(where99, null, null, null, null);
  684. if(list66.size()>0) {
  685. for(int i=0;i<list66.size();i++) {
  686. YtiotVUsercompany b1 = (YtiotVUsercompany)list66.get(i);
  687. YtiotVUsercompanyId oid = b1.getId();
  688. if(i==0)
  689. company_code_list = oid.getOwnerCode();
  690. else
  691. company_code_list += ","+oid.getOwnerCode();
  692. }
  693. }
  694. }
  695. if(personnel!=null) {
  696. hqlwhere3 = "u."+fieldname("name")+"='"+personnel+"'";
  697. List list3 =ytiotTMaintenancePlanDao.query1(hqlwhere3);
  698. YtiotTMaintenancePerson p = (YtiotTMaintenancePerson)list3.get(0);
  699. personnel = Integer.toString(p.getId());
  700. }
  701. if(route!=null) {
  702. hqlwhere4 = "u."+fieldname("route_name")+"='"+route+"'";
  703. List list4 =ytiotTMaintenancePlanDao.query2(hqlwhere4);
  704. YtiotTRoute2 t = (YtiotTRoute2)list4.get(0);
  705. route = Integer.toString(t.getId());
  706. }
  707. // System.out.println();
  708. if(sort!=null) {
  709. Sort = JSONArray.fromObject(sort);
  710. if((Sort.isArray())&&(Sort.size()>0)) {
  711. JSONObject s_json = Sort.getJSONObject(0);
  712. order = s_json.has("property")?s_json.getString("property"):order;
  713. dir = s_json.has("direction")?s_json.getString("direction"):dir;
  714. }
  715. json.put("sort", sort);
  716. }
  717. Start = start;
  718. Limit = limit;
  719. Page = page;
  720. if(company_code!=null)
  721. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+"='"+company_code+"'";
  722. if(company_code_list!=null)
  723. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+" in("+company_code_list+")";
  724. if(personnel!=null)
  725. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("personnel")+"='"+personnel+"'";
  726. if(route!=null)
  727. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("route")+"='"+route+"'";
  728. if(start_time!=null)
  729. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("start_time")+"='"+start_time+"'";
  730. if(end_time!=null)
  731. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("end_time")+"='"+end_time+"'";
  732. if(planned_date!=null)
  733. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("planned_date")+" like '%"+planned_date+"%'";
  734. if(completion_status!=null)
  735. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("completion_status")+"='"+completion_status+"'";
  736. if(order!=null)
  737. order_str = " order by u."+fieldname(order);
  738. else
  739. order_str = " order by u."+fieldname("id");
  740. int totalCount = ytiotTMaintenancePlanDao.getCount(hqlwhere);
  741. //System.out.println(totalCount);
  742. json.put("totalCount", totalCount);
  743. if(Start!=null){
  744. if(Integer.parseInt(Start)>totalCount){
  745. Start = "0";
  746. Page = "0";
  747. }
  748. if(page==null)
  749. Page="0";
  750. }else{
  751. Start = "0";
  752. Page = "0";
  753. }
  754. json.put("page", Page);
  755. json.put("start", Start);
  756. json.put("limit", Limit);
  757. if(totalCount>0) {
  758. List list = ytiotTMaintenancePlanDao.query(hqlwhere, order_str, dir, Start, Limit);
  759. if(list.size()>0) {
  760. //获得当天时间
  761. Date date1 = simpleDateFormat.parse(simpleDateFormat.format(new Date()));
  762. // System.out.println("测试三当前时间yyyy-MM-dd"+simpleDateFormat.format(new Date()));
  763. long time1 = date1.getTime()/1000;
  764. sjc1 = String.valueOf(time1);
  765. for(int i=0;i<list.size();i++) {
  766. YtiotTMaintenancePlan o = (YtiotTMaintenancePlan)list.get(i);
  767. Map map = new HashMap();
  768. //转换为时间戳
  769. // System.out.println("测试三记录时间yyyy-MM-dd"+o.getPlannedDate());
  770. Date date2 = simpleDateFormat.parse(o.getPlannedDate());
  771. long time2 = date2.getTime()/1000;
  772. sjc2 = String.valueOf(time2);
  773. if(Integer.parseInt(sjc2)<Integer.parseInt(sjc1)) {
  774. if(o.getPersonnel()!=null) {
  775. hqlwhere1 = "u."+fieldname("id")+"='"+o.getPersonnel()+"'";
  776. List list1 = ytiotTMaintenancePlanDao.query1(hqlwhere1);
  777. if(list1.size()>0) {
  778. YtiotTMaintenancePerson g = (YtiotTMaintenancePerson)list1.get(0);
  779. map.put("personnel", g.getName());
  780. }
  781. }
  782. if(o.getRoute()!=null) {
  783. hqlwhere2 = "u."+fieldname("id")+"='"+o.getRoute()+"'";
  784. List list2 = ytiotTMaintenancePlanDao.query2(hqlwhere2);
  785. if(list2.size()>0) {
  786. YtiotTRoute2 r = (YtiotTRoute2)list2.get(0);
  787. map.put("route", r.getRouteName());
  788. }
  789. }
  790. map.put("id", o.getId());
  791. // map.put("personnel", o.getPersonnel());
  792. // map.put("route", o.getRoute());
  793. map.put("planned_date", o.getPlannedDate());
  794. map.put("start_time", o.getStartTime());
  795. map.put("end_time", o.getEndTime());
  796. map.put("completion_status", o.getCompletionStatus());
  797. map.put("company_code1", o.getCompanyCode());
  798. JSONObject jSONObject = JSONObject.fromObject(map);
  799. jSONArray.add(jSONObject);
  800. }
  801. }
  802. json.put("RESULT", jSONArray);
  803. }
  804. }
  805. }else {
  806. json.put("success", "false");
  807. json.put("MSG", "用户权限错误,请重新登录后再试。");
  808. }
  809. return json.toString();
  810. }
  811. @Override
  812. public String getCheckRecord2ExcelList(String queryJson) throws Exception {
  813. // TODO Auto-generated method stub
  814. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  815. //设置时间格式,将该时间格式的时间转换为时间戳
  816. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  817. String id = null;
  818. String personnel = null;
  819. String route = null;
  820. String planned_date = null;
  821. String start_time = null;
  822. String end_time = null;
  823. String completion_status = null;
  824. String sjc1=null;
  825. String sjc2=null;
  826. String company_code=null;
  827. String V_LOGINNAME = null;
  828. String V_PASSWORD = null;
  829. int E_STATUS=-1;
  830. String company_code_list = null;
  831. String Page = null;
  832. String Start = null;
  833. JSONArray Sort = null;
  834. String Limit = null;
  835. String hqlwhere4 = null;
  836. String hqlwhere3 = null;
  837. String hqlwhere2 = null;
  838. String hqlwhere1 = null;
  839. String hqlwhere = null;
  840. String order = null;
  841. String dir = null;
  842. String order_str = null;
  843. JSONObject q_json = null;
  844. JSONArray jSONArray = new JSONArray();
  845. JSONObject json = new JSONObject();
  846. json.put("action", "getPatrolPlanList");
  847. if(queryJson!=null) {
  848. q_json = JSONObject.fromObject(queryJson);
  849. id = q_json.has("id")?q_json.getString("id"):null;
  850. personnel = q_json.has("personnel")?q_json.getString("personnel"):null;
  851. route = q_json.has("route")?q_json.getString("route"):null;
  852. planned_date = q_json.has("planned_date")?q_json.getString("planned_date"):null;
  853. start_time = q_json.has("start_time")?q_json.getString("start_time"):null;
  854. end_time = q_json.has("end_time")?q_json.getString("end_time"):null;
  855. completion_status = q_json.has("completion_status")?q_json.getString("completion_status"):null;
  856. V_LOGINNAME = q_json.has("V_LOGINNAME")?q_json.getString("V_LOGINNAME"):null;
  857. V_PASSWORD = q_json.has("V_PASSWORD")?q_json.getString("V_PASSWORD"):null;
  858. order = q_json.has("order")?q_json.getString("order"):null;
  859. dir = q_json.has("dir")?q_json.getString("dir"):null;
  860. json.put("query", queryJson);
  861. }
  862. if((V_LOGINNAME!=null)&&(V_PASSWORD!=null)) {
  863. List list88 = ytiotTAdminDao.query(" where MD5(u.VLoginname)='"+MD5Util.EncoderByMd5(V_LOGINNAME)+"' and u.VPassword='"
  864. +V_PASSWORD+"' ", null, null, null, null);
  865. if(list88.size()>0) {
  866. YtiotTAdmin b2 = (YtiotTAdmin)list88.get(0);
  867. // System.out.println("测试1"+b2.getEStatus());
  868. E_STATUS = Integer.parseInt(b2.getEStatus());
  869. // System.out.println("测试2"+E_STATUS);
  870. }
  871. }
  872. // System.out.println("bengkui"+E_STATUS);
  873. if(E_STATUS==1) {
  874. if(V_LOGINNAME!=null) {
  875. String where99 = " where u.id.agentid='"+V_LOGINNAME+"' ";
  876. List list66 = ytiotVUserCompanyDao.query(where99, null, null, null, null);
  877. if(list66.size()>0) {
  878. for(int i=0;i<list66.size();i++) {
  879. YtiotVUsercompany b1 = (YtiotVUsercompany)list66.get(i);
  880. YtiotVUsercompanyId oid = b1.getId();
  881. if(i==0)
  882. company_code_list = oid.getOwnerCode();
  883. else
  884. company_code_list += ","+oid.getOwnerCode();
  885. }
  886. }
  887. }
  888. if((personnel!=null)&&(personnel.length()>0)) {
  889. hqlwhere3 = "u."+fieldname("name")+"='"+personnel+"'";
  890. List list3 =ytiotTMaintenancePlanDao.query1(hqlwhere3);
  891. YtiotTMaintenancePerson p = (YtiotTMaintenancePerson)list3.get(0);
  892. personnel = Integer.toString(p.getId());
  893. }
  894. if((route!=null)&&(route.length()>0)) {
  895. hqlwhere4 = "u."+fieldname("route_name")+"='"+route+"'";
  896. List list4 =ytiotTMaintenancePlanDao.query2(hqlwhere4);
  897. YtiotTRoute2 t = (YtiotTRoute2)list4.get(0);
  898. route = Integer.toString(t.getId());
  899. }
  900. // System.out.println();
  901. if(company_code!=null)
  902. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+"='"+company_code+"'";
  903. if(company_code_list!=null)
  904. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("company_code")+" in("+company_code_list+")";
  905. if((personnel!=null)&&(personnel.length()>0))
  906. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("personnel")+"='"+personnel+"'";
  907. if((route!=null)&&(route.length()>0))
  908. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("route")+"='"+route+"'";
  909. if((start_time!=null)&&(start_time.length()>0))
  910. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("start_time")+"='"+start_time+"'";
  911. if((end_time!=null)&&(end_time.length()>0))
  912. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("end_time")+"='"+end_time+"'";
  913. if((planned_date!=null)&&(planned_date.length()>0))
  914. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("planned_date")+" like '%"+planned_date+"%'";
  915. if((completion_status!=null)&&(completion_status.length()>0))
  916. hqlwhere = chkhw(hqlwhere) + "u."+fieldname("completion_status")+"='"+completion_status+"'";
  917. if(order!=null)
  918. order_str = " order by u."+fieldname(order);
  919. else
  920. order_str = " order by u."+fieldname("id");
  921. int totalCount = ytiotTMaintenancePlanDao.getCount(hqlwhere);
  922. json.put("totalCount", totalCount);
  923. if(totalCount>0) {
  924. List list = ytiotTMaintenancePlanDao.query(hqlwhere, order_str, dir, Start, Limit);
  925. if(list.size()>0) {
  926. //获得当天时间
  927. Date date1 = simpleDateFormat.parse(simpleDateFormat.format(new Date()));
  928. // System.out.println("测试三当前时间yyyy-MM-dd"+simpleDateFormat.format(new Date()));
  929. long time1 = date1.getTime()/1000;
  930. sjc1 = String.valueOf(time1);
  931. for(int i=0;i<list.size();i++) {
  932. YtiotTMaintenancePlan o = (YtiotTMaintenancePlan)list.get(i);
  933. Map map = new HashMap();
  934. //转换为时间戳
  935. // System.out.println("测试三记录时间yyyy-MM-dd"+o.getPlannedDate());
  936. Date date2 = simpleDateFormat.parse(o.getPlannedDate());
  937. long time2 = date2.getTime()/1000;
  938. sjc2 = String.valueOf(time2);
  939. if(Integer.parseInt(sjc2)<Integer.parseInt(sjc1)) {
  940. if(o.getPersonnel()!=null) {
  941. hqlwhere1 = "u."+fieldname("id")+"='"+o.getPersonnel()+"'";
  942. List list1 = ytiotTMaintenancePlanDao.query1(hqlwhere1);
  943. if(list1.size()>0) {
  944. YtiotTMaintenancePerson g = (YtiotTMaintenancePerson)list1.get(0);
  945. map.put("personnel", g.getName());
  946. }
  947. }
  948. if(o.getRoute()!=null) {
  949. hqlwhere2 = "u."+fieldname("id")+"='"+o.getRoute()+"'";
  950. List list2 = ytiotTMaintenancePlanDao.query2(hqlwhere2);
  951. if(list2.size()>0) {
  952. YtiotTRoute2 r = (YtiotTRoute2)list2.get(0);
  953. map.put("route", r.getRouteName());
  954. }
  955. }
  956. map.put("id", o.getId());
  957. // map.put("personnel", o.getPersonnel());
  958. // map.put("route", o.getRoute());
  959. map.put("planned_date", o.getPlannedDate());
  960. map.put("start_time", o.getStartTime());
  961. map.put("end_time", o.getEndTime());
  962. map.put("completion_status", o.getCompletionStatus());
  963. map.put("company_code1", o.getCompanyCode());
  964. JSONObject jSONObject = JSONObject.fromObject(map);
  965. jSONArray.add(jSONObject);
  966. }
  967. }
  968. json.put("result", jSONArray);
  969. }
  970. }
  971. }else {
  972. json.put("success", "false");
  973. json.put("MSG", "用户权限错误,请重新登录后再试。");
  974. }
  975. return json.toString();
  976. }
  977. // @Override
  978. // public String getPatrolPointVerList(String queryJson, String page, String start, String limit, String sort) throws Exception {
  979. // // TODO Auto-generated method stub
  980. // SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  981. // String UQ_POINT_ID = null;
  982. // String I_ORDER_IDX = null;
  983. // String V_POINT_ADDRESS = null;
  984. // int I_FLOOR = 0;
  985. // String F_HEIGHT = null;
  986. // String I_VERSION = null;
  987. // String D_STORETIME = null;
  988. // String UQ_ADMIN_ID = null;
  989. // String V_COMMENT = null;
  990. //
  991. // String sqlwhere = null;
  992. // String order = null;
  993. // String dir = null;
  994. // String Start = null;
  995. // String Limit = null;
  996. // String Page = null;
  997. // String order_str = null;
  998. // JSONObject q_json = null;
  999. // JSONArray Sort = null;
  1000. // JSONArray jSONArray = new JSONArray();
  1001. // JSONObject json = new JSONObject();
  1002. // json.put("action", "getPointVerList");
  1003. // if(queryJson!=null) {
  1004. // q_json = JSONObject.fromObject(queryJson);
  1005. // UQ_POINT_ID = q_json.has("UQ_POINT_ID")?q_json.getString("UQ_POINT_ID"):null;
  1006. // V_POINT_ADDRESS = q_json.has("V_POINT_ADDRESS")?q_json.getString("V_POINT_ADDRESS"):null;
  1007. // I_FLOOR = q_json.has("I_FLOOR")?q_json.getInt("I_FLOOR"):0;
  1008. // //F_HEIGHT = q_json.has("F_HEIGHT")?q_json.getString("F_HEIGHT"):null;
  1009. // //I_ORDER_IDX= q_json.has("I_ORDER_IDX")?q_json.getString("I_ORDER_IDX"):null;
  1010. // UQ_ADMIN_ID = q_json.has("UQ_ADMIN_ID")?q_json.getString("UQ_ADMIN_ID"):null;
  1011. // I_VERSION = q_json.has("I_VERSION")?q_json.getString("I_VERSION"):null;
  1012. //// System.out.println("测试"+E_STATUS);
  1013. //
  1014. // order = q_json.has("order")?q_json.getString("order"):null;
  1015. // dir = q_json.has("dir")?q_json.getString("dir"):null;
  1016. // Start = q_json.has("start")?q_json.getString("start"):(start!=null)?start:"0";
  1017. // Limit = q_json.has("limit")?q_json.getString("limit"):(limit!=null)?limit:null;
  1018. // Page = q_json.has("page")?q_json.getString("page"):(page!=null)?page:"0";
  1019. // json.put("query", queryJson);
  1020. // }
  1021. //// System.out.println();
  1022. // if(sort!=null) {
  1023. // Sort = JSONArray.fromObject(sort);
  1024. // if((Sort.isArray())&&(Sort.size()>0)) {
  1025. // JSONObject s_json = Sort.getJSONObject(0);
  1026. // order = s_json.has("property")?s_json.getString("property"):order;
  1027. // dir = s_json.has("direction")?s_json.getString("direction"):dir;
  1028. // }
  1029. // json.put("sort", sort);
  1030. // }
  1031. //
  1032. //
  1033. // Start = start;
  1034. // Limit = limit;
  1035. // Page = page;
  1036. // if(V_POINT_ADDRESS!=null)
  1037. // sqlwhere = chkhw(sqlwhere) + "u."+fieldname("V_POINT_ADDRESS")+"='"+V_POINT_ADDRESS+"'";
  1038. // if(I_FLOOR!=0&&I_FLOOR>-1)
  1039. // sqlwhere = chkhw(sqlwhere) + "u."+fieldname("I_FLOOR")+"='"+I_FLOOR+"'";
  1040. //
  1041. // if(UQ_POINT_ID!=null)
  1042. // sqlwhere = chkhw(sqlwhere) + "u."+fieldname("UQ_POINT_ID")+"='"+UQ_POINT_ID+"'";
  1043. //
  1044. // if(UQ_ADMIN_ID!=null)
  1045. // sqlwhere = chkhw(sqlwhere) + "u."+fieldname("UQ_ADMIN_ID")+"='"+UQ_ADMIN_ID+"'";
  1046. //
  1047. // //hqlwhere = chkhw(hqlwhere) + "u."+fieldname("V_UNIT_NAME")+" like '%"+V_UNIT_NAME+"%'";
  1048. //// int b=Integer.parseInt(E_STATUS);
  1049. //// if(b!=10)
  1050. //// hqlwhere = chkhw(hqlwhere) + "u."+fieldname("E_STATUS")+"='"+E_STATUS+"'";
  1051. //
  1052. // if(order!=null)
  1053. // order_str = " order by u."+fieldname(order);
  1054. // else
  1055. // order_str = " order by u."+fieldname("UQ_POINT_ID");
  1056. //
  1057. // //System.out.println("测试:"+sqlwhere);
  1058. //// System.out.println(order_str);
  1059. //
  1060. // //YtiotTPointVerDao
  1061. // int totalCount = ytiotTPointVerDao.getCount(sqlwhere);
  1062. // //System.out.println("测试:"+totalCount);
  1063. // json.put("totalCount", totalCount);
  1064. // if(Start!=null){
  1065. // if(Integer.parseInt(Start)>totalCount){
  1066. // Start = "0";
  1067. // Page = "0";
  1068. // }else if(page==null)
  1069. // Page="0";
  1070. // }else{
  1071. // Start = "0";
  1072. // Page = "0";
  1073. // }
  1074. // json.put("page", Page);
  1075. // json.put("start", Start);
  1076. // json.put("limit", Limit);
  1077. //
  1078. //// System.out.println("测试:"+Page);
  1079. //// System.out.println("测试:"+Start);
  1080. //// System.out.println("测试:"+Limit);
  1081. // if(totalCount>0) {
  1082. // List list = ytiotTPointVerDao.query(sqlwhere, order_str, dir, Start, Limit);
  1083. // System.out.println(list);
  1084. // if(list.size()>0) {
  1085. // for(int i=0;i<list.size();i++) {
  1086. // YtiotTPointver o = (YtiotTPointver)list.get(i);
  1087. // Map map = new HashMap();
  1088. //
  1089. // map.put("UQ_POINT_ID", o.getUqPointId());
  1090. // map.put("V_POINT_ADDRESS", o.getVPointAddress());
  1091. // map.put("I_FLOOR", o.getIFloor());
  1092. // map.put("I_ORDER_IDX", o.getIOrderIdx());
  1093. // map.put("F_HEIGHT", o.getFHeight());
  1094. // map.put("I_VERSION", o.getIVersion());
  1095. // map.put("D_STORETIME", formatter.format(o.getDStoretime()));
  1096. // map.put("V_COMMENT", o.getVComment());
  1097. // map.put("UQ_ADMIN_ID", o.getUqAdminId());
  1098. // JSONObject jSONObject = JSONObject.fromObject(map);
  1099. // jSONArray.add(jSONObject);
  1100. // }
  1101. // json.put("RESULT", jSONArray);
  1102. // }
  1103. // }
  1104. // return json.toString();
  1105. //
  1106. // }
  1107. }