123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062 |
- package com.sinosoft.gps.bgd_duty.service;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.UnsupportedEncodingException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import javax.ws.rs.core.Context;
- import jxl.Workbook;
- import jxl.write.Label;
- import jxl.write.WritableCell;
- import jxl.write.WritableCellFormat;
- import jxl.write.WritableSheet;
- import jxl.write.WritableWorkbook;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- import org.apache.cxf.transport.http.AbstractHTTPDestination;
- import org.apache.log4j.Logger;
- import org.apache.poi.hssf.usermodel.HSSFCell;
- import org.apache.poi.hssf.usermodel.HSSFCellStyle;
- import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
- import org.apache.poi.hssf.usermodel.HSSFComment;
- import org.apache.poi.hssf.usermodel.HSSFFont;
- import org.apache.poi.hssf.usermodel.HSSFPatriarch;
- import org.apache.poi.hssf.usermodel.HSSFRichTextString;
- import org.apache.poi.hssf.usermodel.HSSFRow;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.hssf.util.CellRangeAddress;
- import org.apache.poi.hssf.util.HSSFColor;
- import org.apache.poi.hssf.util.Region;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.CellRange;
- import org.apache.poi.ss.usermodel.CellStyle;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.formaction.Parameter;
- import com.formaction.Utils;
- import com.formaction.dao.OperateAble;
- import com.formaction.dao.OperateImpl;
- import com.formaction.dao.assistant.AssistantAble;
- import com.formaction.dao.assistant.AssistantImpl;
- import com.formaction.vo.Msg;
- import com.formaction.vo.RowSet;
- import com.persistence.service.assitant.generator.IdentityGenerator;
- import com.persistence.service.exception.PersistenceException;
- import com.persistence.service.exception.TransformTypeException;
- import com.sinosoft.common.upLoad.impl.UpLoadFormImpl;
- import com.sinosoft.common.upLoad.service.UploadManageImpl;
- import com.sinosoft.common.upLoad.service.UploadManageable;
- import com.sinosoft.common.upLoad.util.SmartUpload;
- import com.sinosoft.common.upLoad.util.SmartUploadException;
- import com.sinosoft.common.util.JsonPluginsUtil;
- import com.sinosoft.em.alert.duty.records.dao.AlertDutyExcel;
- import com.sinosoft.em.alert.duty.records.dao.EcmDutyExcel;
- import com.sinosoft.em.alert.duty.records.vo.EcmDutyDetail;
- import com.sinosoft.em.alert.duty.records.vo.EcmEmDuty;
- import com.sinosoft.em.evaluate.scoreGrade.dao.ScoreGradeDao;
- import com.sinosoft.em.response.equipment.records.impl.RespEquipmentImpl;
- import com.sinosoft.gps.bgd_duty.dao.BgdDutyDao;
- import com.sinosoft.gps.bgd_duty.dao.BgdDutyExcel;
- import com.sinosoft.gps.bgd_duty.vo.DutyBean;
- import com.sinosoft.lz.system.department.Department;
- import com.sinosoft.lz.system.department.DepartmentDao;
- import com.sinosoft.lz.system.logon.vo.LoginInfo;
- import com.sinosoft.lz.system.userFriend.dao.SendMsgDao;
- import com.sysmodel.XFormFactory;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- import com.sysmodel.datamodel.xmlmodel.impl.MdpAttributeImpl;
- import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
- import com.system.configer.vo.WSClientConfigure;
- @Path("/BgdDutyService/")
- public class BgdDutyService {
-
- @Context
- private org.apache.cxf.jaxrs.ext.MessageContext mc;
-
- private final Logger log = Logger.getLogger(getClass());
-
- @POST
- @ProduceMime("application/json")
- @Path("/queryPid/")
- public String queryPid(String params){
- log.info(params);
- String classid = "";
- classid = Utils.getParameter("classid", params);
- if(classid!=null && !"".equals(classid)){
- classid = "335";
- }
- String fD_OBJECTID = IdentityGenerator.getIdentityGenerator().gerenalIdentity(new Integer(classid));
- return "{\"pid\":\""+fD_OBJECTID+"\"}";
- }
- @POST
- @ProduceMime("application/json")
- @Path("/queryQui/")
- public String queryQui(String params) throws PersistenceException, TransformTypeException {
- OperateAble persistence = new OperateImpl();
- AssistantAble assistant = new AssistantImpl();
- log.info(params);
- RowSet rowSet = new RowSet();
- String listId = Utils.getParameter("listId", params);
- String type = "";
- type = Utils.getParameter("type", params);
- String firstPageNum = Utils.getParameter("pager.pageNo", params) == null ? "0" : Utils
- .getParameter("pager.pageNo", params);
- String limit = Utils.getParameter("pager.pageSize", params) == null ? "10" : Utils
- .getParameter("pager.pageSize", params);
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listId);
- String condition = assistant.getSQLCondition(params, formList);
-
- String sort = Utils.getParameter("sort", params);// 排序字段
- String dir = Utils.getParameter("direction", params);// 升序还是降序
- // 根据 sort和dir的值判断 是否按照列排序了,如果都为空 说明是初次加载gird否则说明对gird列进行排序了。重新组装排序sql语句
- if (sort != null) {
- log.info("sort.length()=" + sort.length());
- if (sort.indexOf("_SHOW") > -1) {
- sort = sort.substring(0, sort.length() - 5);
- log.info("排序字段=" + sort);
- }
- String U_condition = condition.toUpperCase();
- if (U_condition.indexOf("ORDER") > -1) {
- log.info("------------=" + condition.toUpperCase());
- log.info("++++===" + U_condition.substring(0, U_condition.indexOf("ORDER")));
- condition = U_condition.substring(0, U_condition.indexOf("ORDER")) + " ORDER BY "
- + sort + " " + dir;
- } else {
- condition = condition + " order by " + sort + " " + dir;
- }
- log.info("----condition=" + condition);
- }
- StringBuffer sql = assistant.getSearchSql(formList, condition);
- if (formList.getQueryList().getPageSize() == 0 || "excel".equals(type)) {
- rowSet = persistence.queryAllDatas(formList, sql);
- } else {
- rowSet = persistence.queryPagingAllDatas(formList, sql, firstPageNum, limit);
- }
- rowSet = assistant.transformDate(rowSet, formList);// 修改日期格式化的问题 by
- log.info(JSONObject.fromObject(rowSet).toString());
- // 处理返回的结果,将结果适用于QuickUI
- JSONObject origin = JSONObject.fromObject(rowSet);
- String pageNoResult = origin.getString("total");
- String rowsResult = origin.getString("rows");
- String result = "{\"pager.pageNo\":" + firstPageNum + ",\"pager.totalRows\":"
- + pageNoResult + ",\"rows\":" + rowsResult + "}";
- log.info("qui====" + result);
- return result;
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/getlei_ZhiBan_Man")
- public String getlei_ZhiBan_Man(String params) {
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
- try {
- BgdDutyDao dutyDao = new BgdDutyDao();
- return dutyDao.zhiBanName(deptId);
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/emGetlei_ZhiBan_Man")
- public String emGetlei_ZhiBan_Man(String params) {
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
- try {
- BgdDutyDao dutyDao = new BgdDutyDao();
- return dutyDao.emzhiBanName(deptId);
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/getlei_ZhiBan_Man1")
- public String getlei_ZhiBan_Man1(String params) {
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
- try {
- BgdDutyDao dutyDao = new BgdDutyDao();
- return dutyDao.zhiBanName1(deptId);
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
-
- @ProduceMime("application/json")
- @POST
- @Path("/getlei_ZhiBan_Man2")
- public String getlei_ZhiBan_Man2(String params) {
- String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter("deptId", params);
- try {
- BgdDutyDao dutyDao = new BgdDutyDao();
- return dutyDao.zhiBanName2(deptId);
- } catch (PersistenceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- @SuppressWarnings("unused")
- @POST
- @ProduceMime("application/json")
- @Path("/delDetailByID/")
- public Msg delDetailByID(String params){
- Msg msg = new Msg();
- log.info(params);
- String fd_id = "";
- fd_id = Utils.getParameter("fd_objectid", params);
- log.info(fd_id);
- int result = 0;
- if(fd_id!= null && !"".equals(fd_id)){
- BgdDutyDao dutyDao = new BgdDutyDao();
- if(dutyDao.deleteDetail(fd_id)){
- msg.setInfo(Parameter.DELETE_SUCSESS);
- msg.setSucsess("true");
- }else{
- msg.setInfo(Parameter.DELETE_FAILURE);
- msg.setSucsess("false");
- }
- }
- return msg;
- }
- @POST
- @ProduceMime("application/json")
- @Path("/saveDetail/")
- public String saveDetail(String params){
- String result = "保存失败";
- try {
- params = new String(params.getBytes("ISO8859-1"), "UTF-8");
- log.info(params);
- String[] strs = null;
- String jsonStr = "";
- String duty_id = "";
- String fd_id = "";
- EcmDutyDetail detail = null;
- if(params!=null&&!"".equals(params)){
- strs = params.split("#");
- jsonStr = strs[0];
- duty_id = strs[1];
- fd_id = strs[2];
- detail = JsonPluginsUtil.jsonToBean(jsonStr.toLowerCase(), EcmDutyDetail.class);
- detail.setDuty_id(duty_id);
- BgdDutyDao dutyDao = new BgdDutyDao();
- if(fd_id!=null && !"".equals(fd_id)&& !"undefined".equalsIgnoreCase(fd_id)){
- detail.setFd_objectid(fd_id);
- dutyDao.updateDetail(detail);
- }else{
- dutyDao.saveDetail(detail);
- }
- result = "保存成功";
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return "{\"result\":"+result+"}";
- }
-
- @SuppressWarnings("unchecked")
- @POST
- @ProduceMime("application/json")
- @Path("/queryDetailByDutyId/")
- public String queryDetailByDutyId(String params){
- log.info(params);
- String dutyid = Utils.getParameter("dutyid", params);
- if(dutyid!=null && !"".equals(dutyid)&& !"undefined".equalsIgnoreCase(dutyid)){
- BgdDutyDao dutyDao = new BgdDutyDao();
-
- List<EcmDutyDetail> detailList = dutyDao.queryDetailByDutyid(dutyid);
- log.info(JsonPluginsUtil.beanListToJson(detailList));
- log.info(JSONArray.fromObject(detailList).toString());
-
- return " {\"rows\":"+JSONArray.fromObject(detailList).toString() +"}";
- }
- return "";
- }
- @POST
- @ProduceMime("application/json")
- @Path("/saveDuty/")
- public Msg saveDuty(String params){
- Msg msg = new Msg();
- log.info(params);
- try {
- if(params!=null&&!"".equals(params)&&!"undefined".equalsIgnoreCase(params)){
- params = java.net.URLDecoder.decode(params, "utf-8");
- System.out.println(params);
-
-
- String jsonString = params;
- List<DutyBean> detailList = new ArrayList<DutyBean>();
- if(jsonString!=null&&!"".equals(jsonString)&&!"undefined".equalsIgnoreCase(jsonString)){
- detailList = JsonPluginsUtil.jsonToBeanList(jsonString, DutyBean.class);
- }
- //得到任务id
- String task_id = detailList.get(0).getTASK_ID();
- System.out.println(jsonString);
- BgdDutyDao dutyDao = new BgdDutyDao();
-
- if(dutyDao.saveBgdDutyBatch(detailList)){
- dutyDao.update_renwu("1",task_id);
- msg.setInfo(Parameter.CREATE_SUCSESS);
- msg.setSucsess("true");
-
- System.out.println(msg.getSucsess());
- }else{
- msg.setInfo(Parameter.DELETE_FAILURE);
- msg.setSucsess("false");
- }
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return msg;
- }
-
-
-
- @POST
- @ProduceMime("application/json")
- @Path("/updateBgdDuty/")
- public Msg updateBgdDuty(String params){
- Msg msg = new Msg();
- log.info(params);
- try {
- if(params!=null&&!"".equals(params)&&!"undefined".equalsIgnoreCase(params)){
- params = java.net.URLDecoder.decode(params, "utf-8");
- System.out.println(params);
-
-
- String jsonString = params;
- List<DutyBean> detailList = new ArrayList<DutyBean>();
- if(jsonString!=null&&!"".equals(jsonString)&&!"undefined".equalsIgnoreCase(jsonString)){
- detailList = JsonPluginsUtil.jsonToBeanList(jsonString, DutyBean.class);
- }
- System.out.println(jsonString);
- BgdDutyDao dutyDao = new BgdDutyDao();
-
- if(dutyDao.updateBgdDutyBatch(detailList)){
- msg.setInfo(Parameter.CREATE_SUCSESS);
- msg.setSucsess("true");
-
- System.out.println(msg.getSucsess());
- }else{
- msg.setInfo(Parameter.DELETE_FAILURE);
- msg.setSucsess("false");
- }
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return msg;
- }
- /**
- * 根据task_id 查询保供电值班表的信息
- * @param params
- * @return
- */
-
- @SuppressWarnings("unchecked")
- @POST
- @ProduceMime("application/json")
- @Path("/getDutyByTaskId/")
- public String getDutyById(String params){
- log.info(params);
- String result="";
- String taskid = Utils.getParameter("taskid", params);
- DutyBean duty = null;
-
- if(taskid!=null && !"".equals(taskid)){
- BgdDutyDao dutyDao = new BgdDutyDao();
- List<DutyBean> datailList = dutyDao.getDutyById(taskid);
- result=" {\"rows\":"+JSONArray.fromObject(datailList).toString() +"}";
- }
- log.info(JsonPluginsUtil.beanToJson(duty));
- return result;
- }
-
-
- @POST
- @ProduceMime("application/json")
- @Path("/updateDuty/")
- public Msg updateDuty(String params){
- Msg msg = new Msg();
- log.info(params);
- try {
- params = java.net.URLDecoder.decode(params, "UTF-8");
- String fd_objectid = Utils.getParameter("fd_objectid", params);
- String name = Utils.getParameter("name", params);
- String dept_names = Utils.getParameter("dept_names", params);
- String oper_name = Utils.getParameter("oper_name", params);
- String oper_dept = Utils.getParameter("oper_dept", params);
- String oper_time = Utils.getParameter("oper_time", params);
- EcmEmDuty duty = new EcmEmDuty();
- duty.setFd_objectid(fd_objectid);
- duty.setName(name);
- duty.setDept_names(dept_names);
- duty.setOper_dept(oper_dept);
- duty.setOper_name(oper_name);
- duty.setOper_time(oper_time);
- BgdDutyDao dutyDao = new BgdDutyDao();
- if(dutyDao.updateDuty(duty)){
- msg.setInfo(Parameter.UPDATE_SUCSESS);
- msg.setSucsess("true");
- }else{
- msg.setInfo(Parameter.UPDATE_FAILURE);
- msg.setSucsess("false");
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- msg.setInfo(Parameter.UPDATE_FAILURE);
- msg.setSucsess("false");
- }
- return msg;
- }
-
- @POST
- @ProduceMime("application/json")
- @Path("/updateStat/")
- public Msg updateStat(String params){
- Msg msg = new Msg();
- try {
- params = java.net.URLDecoder.decode(params, "UTF-8");
- String objectIDs = Utils.getParameter("objectIDs", params);
- String has_duty = Utils.getParameter("has_duty", params);//任务表中的值班流程
- String flow_id = Utils.getParameter("flow_id", params); //值班表的流程id
- String rolback_info = Utils.getParameter("rolback_info", params); //值班表的流程id
- String reporttime = Utils.getParameter("time", params);
- BgdDutyDao dutyDao = new BgdDutyDao();
- if(dutyDao.updateStat(objectIDs.split(","),has_duty,flow_id,reporttime,rolback_info)){
- msg.setInfo(Parameter.OPER_SUCSESS);
- msg.setSucsess("true");
- }else{
- msg.setInfo(Parameter.OPER_FAILURE);
- msg.setSucsess("false");
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- msg.setInfo(Parameter.OPER_FAILURE);
- msg.setSucsess("false");
- }
- return msg;
- }
-
- @POST
- @ProduceMime("application/json")
- @Path("/deDutyDetail/")
- public String deDutyDetail(String params){
- Msg msg=new Msg();
- try {
- params=new String(params.getBytes("ISO8859-1"),"UTF-8");
- } catch (UnsupportedEncodingException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- String taskIDs = Utils.getParameter("ids", params) == null ? "" : Utils .getParameter("ids", params);
- System.out.println(taskIDs);
- String column_name = Utils.getParameter("column_name", params) == null ? "" : Utils .getParameter("column_name", params);
- String column_value = Utils.getParameter("column_value", params) == null ? "" : Utils .getParameter("column_value", params);
- String[] IDs=taskIDs.split(",");
- BgdDutyDao e=new BgdDutyDao();
- if(e.deDutyDetail(IDs,column_name,column_value)){
- msg.setInfo(Parameter.UPDATE_SUCSESS);
- msg.setSucsess("true");
- }else{
- msg.setInfo(Parameter.UPDATE_FAILURE);
- msg.setSucsess("false");
- }
- String result = JSONObject.fromObject(msg).toString();
-
- return result;
- }
- @POST
- @ProduceMime("application/json")
- @Path("/deleteDutyIds/")
- public Msg deleteDutyIds(String params){
- Msg msg = new Msg();
- String objectIDs = Utils.getParameter("objectIDs", params) == null ? "" : Utils .getParameter("objectIDs", params);
- BgdDutyDao dutyDao = new BgdDutyDao();
-
- if(dutyDao.deleteDuty(objectIDs.split(","))){
- msg.setInfo(Parameter.DELETE_SUCSESS);
- msg.setSucsess("true");
- }else{
- msg.setInfo(Parameter.DELETE_FAILURE);
- msg.setSucsess("false");
- }
- return msg;
- }
-
- // 2015-05-16
- @SuppressWarnings("unused")
- @POST
- @ProduceMime("text/html")
- @Path("/importExcel/")
- public Msg importExcel(@Context HttpServletRequest request,
- @Context HttpServletResponse response) {
- Msg msg = new Msg();
- UploadManageImpl upload = new UploadManageImpl();
- msg =upload.uploadDutyFilePath(request, response);
- if(msg.getSucsess()=="false"){
- String ret="{success : " + msg.getSucsess() + " , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
- return msg;
- }
-
- String resultString=msg.getInfo();
- System.out.println("resultString++++++++++++++++++++++++++++++"+resultString);
- LoginInfo loginInfo = (LoginInfo) request.getSession().getAttribute("loginInfo");
- if(resultString!=null&& !"".equals(resultString)){
- String[] strs = resultString.split(";");
- String flag = strs[0];
- String info = strs[1];
- String path = strs[2];
- System.out.println("path"+path);
- if("true".equals(flag)){
- EcmDutyExcel doExcel = new EcmDutyExcel();
- msg=doExcel.readExcel(path,loginInfo.getReal_name(),loginInfo.getDeptids(),loginInfo.getUser_id());
- if(msg.getSucsess().equals("false")){
- msg.setInfo("2");
- }else{
- msg.setSucsess("success");
- msg.setInfo("success");
- }
- }
- }
- String retString = "{success : '" + msg.getSucsess() + "' , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
- return msg ;
- }
-
- /**
- * 保供电 导入值班功能
- * @param request
- * @param response
- * @return
- */
-
- @SuppressWarnings( "unused")
- @POST
- @ProduceMime("text/html")
- @Path("/importExcel_bgd/")
- public String importExcel_bgd(@Context HttpServletRequest request,
- @Context HttpServletResponse response) {
- String task_id=request.getParameter("task_id");
- String realName=request.getParameter("realName");
- String deptId=request.getParameter("deptId");
- try {
- realName = java.net.URLDecoder.decode(java.net.URLDecoder.decode(realName, "utf-8"), "utf-8");
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //获取任务id
- Msg msg = new Msg();
- UploadManageImpl upload = new UploadManageImpl();
- msg =upload.uploadDutyFilePath(request, response);
- if(msg.getSucsess()=="false"){
- String ret="{success : " + msg.getSucsess() + " , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
- return ret;
- }
-
- String resultString=msg.getInfo();
- System.out.println("resultString++++++++++++++++++++++++++++++"+resultString);
- if(resultString!=null&& !"".equals(resultString)){
- String[] strs = resultString.split(";");
- String flag = strs[0];//true
- String info = strs[1];//success
- String path = strs[2];//路径
- System.out.println("path"+path);
- if("true".equals(flag)){
- BgdDutyExcel doExcel = new BgdDutyExcel();
-
- msg=doExcel.readExcel_bgd(path,realName,deptId,task_id);
- /*if(msg.getSucsess().equals("false")){
- msg.setInfo("3");
- }else{
- msg.setSucsess("success");
- msg.setInfo("success");
- }*/
- }
- }
- String retString = "{success : '" + msg.getSucsess() + "' , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
- return retString ;
- }
-
-
- /**
- * 保供电 导入保供电任务
- * @param request
- * @param response
- * @return
- */
-
- @SuppressWarnings( "unused")
- @POST
- @ProduceMime("text/html")
- @Path("/importExcel_task/")
- public String importExcel_task(@Context HttpServletRequest request,
- @Context HttpServletResponse response) {
- String realName=request.getParameter("realName");
- String deptId=request.getParameter("deptId");
- String deptName=request.getParameter("deptName");
- String userId=request.getParameter("userId");
- try {
- realName = java.net.URLDecoder.decode(java.net.URLDecoder.decode(realName, "utf-8"), "utf-8");
- deptName = java.net.URLDecoder.decode(java.net.URLDecoder.decode(deptName, "utf-8"), "utf-8");
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //获取任务id
- Msg msg = new Msg();
- UploadManageImpl upload = new UploadManageImpl();
- msg =upload.uploadDutyFilePath(request, response);
- if(msg.getSucsess()=="false"){
- String ret="{success : " + msg.getSucsess() + " , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
- return ret;
- }
-
- String resultString=msg.getInfo();
- System.out.println("resultString++++++++++++++++++++++++++++++"+resultString);
- if(resultString!=null&& !"".equals(resultString)){
- String[] strs = resultString.split(";");
- String flag = strs[0];//true
- String info = strs[1];//success
- String path = strs[2];//路径
- System.out.println("path"+path);
- if("true".equals(flag)){
- BgdDutyExcel doExcel = new BgdDutyExcel();
-
- msg=doExcel.readExcel_task(path,realName,deptId,userId,deptName);
- }
- }
- String retString = "{success : '" + msg.getSucsess() + "' , info : '" + msg.getInfo() + "',ObjectID:'ObjectID'}";
- return retString ;
- }
-
- /**
- * 根据 任务表的任务id 查询 保供电值班表的数据进行 导出
- * @param params
- * @return
- * @throws FileNotFoundException
- */
- @POST
- @ProduceMime("text/html")
- @Path("/exportAlertExcel/")
- public String exportAlertExcel(String params) throws FileNotFoundException{
- HttpServletRequest request = mc.getHttpServletRequest();
- HttpServletResponse response = mc.getHttpServletResponse();
- String filePath = request.getRealPath("excels");
- String fileName = UUID.randomUUID().toString()+".xls";
- FileOutputStream out = new FileOutputStream(filePath+"/"+fileName);
- log.info(filePath+"/"+fileName);
- String objectID = Utils.getParameter("objectID", params) == null ? "" : Utils.getParameter("objectID", params);
- BgdDutyDao dutyDao = new BgdDutyDao();
- DutyBean duty = dutyDao.getDutyBeanById(objectID);
- List<DutyBean> list = dutyDao.getDutyById(objectID);
- try {
- HSSFWorkbook workbook = new HSSFWorkbook();
- CellStyle cellStyle=workbook.createCellStyle();
- cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
- cellStyle.setWrapText(true);//设置自动换行
- //加边框
- cellStyle.setBottomBorderColor(HSSFColor.BLACK.index);
- cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
- cellStyle.setLeftBorderColor(HSSFColor.BLACK.index);
- cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
- cellStyle.setRightBorderColor(HSSFColor.BLACK.index);
- cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
- cellStyle.setTopBorderColor(HSSFColor.BLACK.index);
- cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
- //一页
- HSSFSheet childSheet = workbook.createSheet();
- //设置列宽
- childSheet.setColumnWidth(0, 5000);
- childSheet.setColumnWidth(1, 5000);
- childSheet.setColumnWidth(2, 5000);
- childSheet.setColumnWidth(3, 5000);
- childSheet.setColumnWidth(4, 5000);
- childSheet.setColumnWidth(5, 5000);
- childSheet.setColumnWidth(6, 5000);
- childSheet.setColumnWidth(7, 5000);
- // 起始行 // 结束行 // 其实列 // 结束列
- // CellRangeAddress region1 = new CellRangeAddress(0,0,0,7); //CellRangeAddress
- childSheet.addMergedRegion(new Region(0, (short)0, 0,(short)7));
- CellStyle cellStyle1=workbook.createCellStyle();
- cellStyle1.setWrapText(true); //换行
- HSSFRow row0 = childSheet.createRow(0);
- row0.setHeight((short)1000);
- HSSFCell cell00 = row0.createCell(0);
- cell00.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell00.setCellValue("填报说明:1、开始时间、结束时间:请按yyyy-MM-dd HH:mm:ss时间格式输入,如2015-10-24 18:30;2、值班领导、值班成员:请输入值班人姓名;3、领导电话、联系电话:分别输入值班领导的电话和值班成员的电话;4、值班方式:请选择在岗值班、电话值班、应急指挥中心值班;");
- cell00.setCellStyle(cellStyle1);
-
-
- HSSFRow row1 = childSheet.createRow(1);
- childSheet.addMergedRegion(new Region(1, (short)0, 1,(short)7));
-
- HSSFCell cell10 = childSheet.createRow(1).createCell(0);
- cell10.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell10.setCellValue("保供电值班安排表");
- cell10.setCellStyle(cellStyle);
-
- HSSFRow row2 = childSheet.createRow(2);
- HSSFCell cell20 = row2.createCell(0);
- cell20.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell20.setCellValue("开始时间");
-
- HSSFCell cell21 = row2.createCell(1);
- cell21.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell21.setCellValue("结束时间");
-
- HSSFCell cell22 = row2.createCell(2);
- cell22.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell22.setCellValue("值班领导");
-
- HSSFCell cell23 = row2.createCell(3);
- cell23.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell23.setCellValue("领导电话");
-
- HSSFCell cell24 = row2.createCell(4);
- cell24.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell24.setCellValue("值班方式");
-
- HSSFCell cell25 = row2.createCell(5);
- cell25.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell25.setCellValue("值班成员");
-
- HSSFCell cell26 = row2.createCell(6);
- cell26.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell26.setCellValue("联系电话");
-
- HSSFCell cell27 = row2.createCell(7);
- cell27.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取
- cell27.setCellValue("值班方式");
-
- System.out.println("list.size()++++++++++++++++++++++++++++++++++++++++++++++++++++++"+list.size());
- int listSize=list.size();
- for (int r = 3 ; r < list.size()+3; r++) {// 循环该 子sheet row
- DutyBean detail = list.get(listSize+2-r);
- HSSFRow rows = childSheet.createRow(r);
-
- HSSFCell cell0 = rows.createCell(0);
- cell0.setCellType(Cell.CELL_TYPE_STRING);
- cell0.setCellValue(detail.getSTART_TIME());
-
- HSSFCell cell1 = rows.createCell(1);
- cell1.setCellType(Cell.CELL_TYPE_STRING);
- cell1.setCellValue(detail.getEND_TIME());
-
- HSSFCell cell2 = rows.createCell(2);
- cell2.setCellType(Cell.CELL_TYPE_STRING);
- cell2.setCellValue(detail.getLEADER());
-
- HSSFCell cell3 = rows.createCell(3);
- cell3.setCellType(Cell.CELL_TYPE_STRING);
- cell3.setCellValue(detail.getLEADER_TEL());
-
- HSSFCell cell4 = rows.createCell(4);
- cell4.setCellType(Cell.CELL_TYPE_STRING);
- String modeway = detail.getLEADER_DUTY_MODE();
- // cell4.setCellValue(detail.getLEADER_DUTY_MODE());
- String wayVal1 = "在岗值班";
- if(modeway!=null&&"0".equals(modeway)){
- wayVal1 = "在岗值班";
- }
- if(modeway!=null&&"1".equals(modeway)){
- wayVal1 = "电话值班";
- }
- if(modeway!=null&&"2".equals(modeway)){
- wayVal1 = "应急指挥中心值班";
- }
- cell4.setCellValue(wayVal1);
-
- HSSFCell cell5 = rows.createCell(5);
- cell5.setCellType(Cell.CELL_TYPE_STRING);
- cell5.setCellValue(detail.getWATCH_MAN());
-
- HSSFCell cell6 = rows.createCell(6);
- cell6.setCellType(Cell.CELL_TYPE_STRING);
- cell6.setCellValue(detail.getWATCH_TEL());
-
- HSSFCell cell7 = rows.createCell(7);
- cell7.setCellType(Cell.CELL_TYPE_STRING);
- String dutyWay = detail.getDUTY_MODE();
- String wayVal = "在岗值班";
- if(dutyWay!=null&&"0".equals(dutyWay)){
- wayVal = "在岗值班";
- }
- if(dutyWay!=null&&"1".equals(dutyWay)){
- wayVal = "电话值班";
- }
- if(dutyWay!=null&&"2".equals(dutyWay)){
- wayVal = "应急指挥中心值班";
- }
- cell7.setCellValue(wayVal);
- }
- workbook.write(out);
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- log.info(fileName);
- return fileName;
- }
-
-
-
-
- @SuppressWarnings({ "static-access", "deprecation" })
- @ProduceMime("application/json")
- @POST
- @Path("/CreateToExcel")
- public String CreateToExcel(String params) {
-
- log.info("params:" + params);
-
- AssistantAble assistant = new AssistantImpl();
- String classID = Utils.getParameter("classId", params);
- String listId = Utils.getParameter("listId", params);
- String queryField = Utils.getParameter("queryField", params);
- FormListImpl formList = (FormListImpl) XFormFactory.getXFormModel().getFormList(listId);
-
- String condition = assistant.getSQLCondition(params, formList);
-
- log.info("queryField:" + queryField);
- log.info("condition:" + condition);
-
- queryField = queryField.substring(0, queryField.lastIndexOf(","));
- String[] queryFields = queryField.split(",");
-
- int ClassId = Integer.parseInt(classID);
- SysModel sysmodel = ModelFactory.getSysmodel();
- MdpClass mdpClass = sysmodel.getMdpClassByClassID(ClassId);
- // 获取表名称
- String tableName = mdpClass.getName();
- // 获取表的描述信息
- String description = mdpClass.getDescription();
- // 获取各个字段的名称
- List<MdpAttributeImpl> list = mdpClass.getAllMdpAttributes();
- Map<String,MdpAttributeImpl> map = new HashMap<String, MdpAttributeImpl>();
- for(MdpAttributeImpl mdp : list){
- map.put(mdp.getName().toUpperCase(), mdp);
- }
- Workbook wb = null;
- WritableWorkbook book = null;
- WritableSheet sheet = null;
-
- HttpServletRequest req =mc.getHttpServletRequest();
- String fileName = "";
- String filePath = req.getRealPath("excels");
- try {
- fileName =UUID.randomUUID().toString()+".xls";
- File myFilePath = new File( filePath+"/"+fileName);
-
- // 1.首先定义个workbook
- book = wb.createWorkbook(myFilePath);
- // 2.定义个sheet
- sheet = book.createSheet("第一页", 0);
- // 设置标题
- sheet.mergeCells(0, 0, queryFields.length - 1, 0);
- // 插入数据.
-
- book.write();
- book.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return fileName;
- }
-
- private void download(String path, HttpServletResponse response) {
- try {
- // path是指欲下载的文件的路径。
- File file = new File(path);
- // 取得文件名。
- String filename = file.getName();
- // 以流的形式下载文件。
- InputStream fis = new BufferedInputStream(new FileInputStream(path));
- byte[] buffer = new byte[fis.available()];
- fis.read(buffer);
- fis.close();
- // 清空response
- response.reset();
- // 设置response的Header
- response.addHeader("Content-Disposition", "attachment;filename="
- + new String(filename.getBytes()));
- response.addHeader("Content-Length", "" + file.length());
- OutputStream toClient = new BufferedOutputStream(
- response.getOutputStream());
- response.setContentType("application/vnd.ms-excel;charset=gb2312");
- toClient.write(buffer);
- toClient.flush();
- toClient.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- public org.apache.cxf.jaxrs.ext.MessageContext getMc() {
- return mc;
- }
- public void setMc(org.apache.cxf.jaxrs.ext.MessageContext mc) {
- this.mc = mc;
- }
- @POST
- @ProduceMime("application/json")
- @Path("/getMyInfo")
- public String getMyInfo(String param) {
- BgdDutyDao bdDao = new BgdDutyDao();
-
- return bdDao.getParameters(param) ;//保供电值班安排表---发布后的短信用到
- }
-
-
- @POST
- @ProduceMime("application/json")
- @Path("/getNameTel")
- public String getNameTel(String param) {
-
- String[] tempParam = param.split(",");
- String compId = "";
- String param1 = "";
- if(tempParam.length>0){
- for(int i=0; i<tempParam.length; i++){
- compId+= "'" + tempParam[i] + "'" + ",";
- }
- }
- if(compId.endsWith(",")){
- param1 = compId.substring(0,compId.length()-1);
- }
-
-
- String result="";
- //String data= Utils.getParameter("data", param);
- BgdDutyDao bdDao = new BgdDutyDao();
- result = bdDao.getsenMsg(param1);
-
- log.info("result===" + result);
-
- return result;
- }
-
- @POST
- @ProduceMime("application/json")
- @Path("/getNameTel1")
- public String getNameTel1(String param) {
-
- String[] tempParam = param.split(",");
- String compId = "";
- String param1 = "";
- if(tempParam.length>0){
- for(int i=0; i<tempParam.length; i++){
- compId+= "'" + tempParam[i] + "'" + ",";
- }
- }
- param1 = compId.substring(0,compId.length()-1);
-
-
- String result="";
- //String data= Utils.getParameter("data", param);
- BgdDutyDao bdDao = new BgdDutyDao();
- result = bdDao.getsenMsg1(param1);
-
- log.info("result===" + result);
-
- return result;
- }
-
-
- @POST
- @ProduceMime("application/json")
- @Path("/getTaskInfos")
- public String getTaskInfos(String param) {
- BgdDutyDao bdDao = new BgdDutyDao();
-
- return bdDao.getUsersTel(param);//保供电任务---发布后的短信用到
- }
-
- /**
- * 删除任务
- *
- * @param params
- * 表单参数信息
- * @return
- * @throws PersistenceException
- * @throws TransformTypeException
- */
- @POST
- @ProduceMime("application/json")
- @Path("/deleteTask/")
- public Msg deleteTask(String params) throws PersistenceException {
- BgdDutyDao bdDao = new BgdDutyDao();
- String objectIDs = Utils.getParameter("objectIDs", params) == null ? "" : Utils
- .getParameter("objectIDs", params);
- Msg msg = new Msg();
- try {
- msg = bdDao.deleteTask(objectIDs.split(","));
- return msg;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return msg;
- }
- }
|