1 packagecom.cn.elec.service.impl;2 importjava.util.HashMap;3 importjava.util.List;4 importjava.util.Map;5
6 importjavax.annotation.Resource;7 importorg.springframework.stereotype.Service;8
9
10 importcom.cn.elec.dao.ElecRunCommonMsgDao;11 importcom.cn.elec.dao.IElecRunSituationDao;12 importcom.cn.elec.domain.ElecRunCommonMsg;13 importcom.cn.elec.domain.ElecRunSituation;14 importcom.cn.elec.service.ElecRunSituationService;15 importcom.cn.elec.utils.StringUtils;16
17 @Service(ElecRunSituationService.SERVICE_NAME)18 public class ElecRunSituationServiceImpl implementsElecRunSituationService {19 @Resource(name=IElecRunSituationDao.DAO_NAME)20 privateIElecRunSituationDao dao;21
22 @Resource(name=ElecRunCommonMsgDao.DAO_NAME)23 privateElecRunCommonMsgDao msg_dao;24
25
26 public voidsaveRunMeseage(ElecRunSituation entity) {27 //1. 清空碎片表里面所有的数据
28 List list=msg_dao.findCollectionByConditionNoPage("", null, null);29 msg_dao.deleteByCollection(list);30
31 //2. 将站点运行情况和设备运行情况切片
32 String station=entity.getSituationRun();33 String devRun=entity.getDevRun();34 List station_list=StringUtils.getContentByList(station, 20);35 List devRun_list=StringUtils.getContentByList(devRun, 20);36 //3. 保存切片的数据37 //保存站点的运行情况
38 for (int i = 0; i
41 msgg.setContent(station_list.get(i));42 msgg.setType("1");43 msgg.setOrderby(i+1);44 msg_dao.save(msgg);45 }46
47 //3. 保存切片的数据48 //保存站点的运行情况
49 for (int i = 0; i
52 msge.setContent(devRun_list.get(i));53 msge.setType("2");54 msge.setOrderby(i+1);55 msg_dao.save(msge);56 }57 //4. 更新或者保存ElecCommonMsg
58 dao.saveRunMeseage(entity);59 }60
61 publicElecRunSituation findRunMesage() {62 //return dao.findRunMesage();63 //1. 查询所有的切片数据(分类型查询)
64
65 String condition = " and o.type = ?";66 Object[] params = new Object[]{"1"};67 Map orderby = new HashMap();68 orderby.put("o.orderby", "asc");69 List list =
70 msg_dao.findCollectionByConditionNoPage(condition, params, orderby);71
72 String station_content = ""; //站点的运行情况
73 for(ElecRunCommonMsg content : list)74 {75 station_content = station_content +content.getContent();76 }77
78 //查询设备的运行情况
79 condition = " and o.type = ?";80 params = new Object[]{"2"};81 orderby = new HashMap();82 orderby.put("o.orderby", "asc");83 list =
84 msg_dao.findCollectionByConditionNoPage(condition, params, orderby);85
86 String dev_content = ""; //设备的运行情况
87 for(ElecRunCommonMsg content : list)88 {89 dev_content = dev_content +content.getContent();90 }91
92
93 ElecRunSituation msg =dao.findRunMesage();94 if(null !=msg)95 {96 //3. 设置站点的运行情况和设备的运行情况
97 msg.setDevRun(dev_content);98 msg.setSituationRun(station_content);99
100 returnmsg;101 }102
103 return null;104 }105 }