Java tutorial
package com.qkj.qkjmanage.action; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.ServletActionContext; import org.iweb.sys.ActionAttr; import org.iweb.sys.ContextHelper; import org.iweb.sys.Weimimember_message; import com.alibaba.dingtalk.openapi.demo.Demo; import com.alibaba.dingtalk.openapi.demo.Vars; import com.alibaba.dingtalk.openapi.demo.auth.AuthHelper; import com.alibaba.dingtalk.openapi.demo.message.LightAppMessageDelivery; import com.alibaba.dingtalk.openapi.demo.message.MessageHelper; import com.dingtalk.open.client.api.model.corp.MessageBody; import com.dingtalk.open.client.api.model.corp.MessageType; import com.opensymphony.xwork2.ActionSupport; import com.qkj.qkjmanage.dao.OutcarDAO; import com.qkj.qkjmanage.dao.PoolDAO; import com.qkj.qkjmanage.dao.SendDAO; import com.qkj.qkjmanage.domain.Drivercar; import com.qkj.qkjmanage.domain.Outcar; import com.qkj.qkjmanage.domain.Poolcar; import com.qkj.qkjmanage.domain.Sendcar; import com.qkj.vehicle.dao.DriverDAO; import com.qkj.vehicle.domain.Driver_files; public class SendcarAction extends ActionSupport implements ActionAttr { private static final long serialVersionUID = 1L; private static Log log = LogFactory.getLog(SendcarAction.class); private Map<String, Object> map = new HashMap<String, Object>(); private SendDAO dao = new SendDAO(); private Sendcar sendcar; private List<Sendcar> sendcars; private Outcar outcar; private String message; private String viewFlag; private String car_driver_list; private Drivercar dcar; private List<Drivercar> dcars; private int recCount; private int pageSize; private int currPage; public int getRecCount() { return recCount; } public void setRecCount(int recCount) { this.recCount = recCount; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getCurrPage() { return currPage; } public void setCurrPage(int currPage) { this.currPage = currPage; } public String getCar_driver_list() { return car_driver_list; } public void setCar_driver_list(String car_driver_list) { this.car_driver_list = car_driver_list; } public Outcar getOutcar() { return outcar; } public void setOutcar(Outcar outcar) { this.outcar = outcar; } public Sendcar getSendcar() { return sendcar; } public void setSendcar(Sendcar sendcar) { this.sendcar = sendcar; } public List<Sendcar> getSendcars() { return sendcars; } public void setSendcars(List<Sendcar> sendcars) { this.sendcars = sendcars; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getViewFlag() { return viewFlag; } public void setViewFlag(String viewFlag) { this.viewFlag = viewFlag; } public Drivercar getDcar() { return dcar; } public void setDcar(Drivercar dcar) { this.dcar = dcar; } public List<Drivercar> getDcars() { return dcars; } public void setDcars(List<Drivercar> dcars) { this.dcars = dcars; } public String list() throws Exception { ContextHelper.isPermit("QKJ_QKJMANAGE_SEND_CAR"); try { map.clear(); if (sendcar == null) sendcar = new Sendcar(); ContextHelper.setSearchDeptPermit4Search("QKJ_QKJMANAGE_SEND_CAR", map, "apply_depts", "apply_user"); ContextHelper.SimpleSearchMap4Page("QKJ_QKJMANAGE_SEND_CAR", map, sendcar, viewFlag); map.put("back_send", 4);//? this.setPageSize(ContextHelper.getPageSize(map)); this.setCurrPage(ContextHelper.getCurrPage(map)); this.setSendcars(dao.list(map)); this.setRecCount(dao.getResultCount()); //path = "<a href='/manager/default'></a> > "; } catch (Exception e) { log.error(this.getClass().getName() + "!list ??:", e); throw new Exception(this.getClass().getName() + "!list ??:", e); } return SUCCESS; } public String add() throws Exception { try { dao.startTransaction(); sendcar.setSend_user(ContextHelper.getUserLoginUuid()); dao.add(sendcar); dao.commitTransaction(); } catch (Exception e) { log.error(this.getClass().getName() + "!add ?:", e); throw new Exception(this.getClass().getName() + "!add ?:", e); } finally { dao.endTransaction(); } return SUCCESS; } public String del() throws Exception { try { Integer outcar = null; if (sendcar != null && sendcar.getOutcar_id() != null) { outcar = sendcar.getOutcar_id(); } dao.delete(sendcar); sendcar = new Sendcar(); sendcar.setOutcar_id(outcar); setMessage("?!ID=" + sendcar.getUuid()); } catch (Exception e) { log.error(this.getClass().getName() + "!del ?:", e); throw new Exception(this.getClass().getName() + "!del ?:", e); } return SUCCESS; } public String sureSend() throws Exception { try { dao.startTransaction(); if (sendcar != null && sendcar.getOutcar_id() != null) { //? OutcarDAO ocd = new OutcarDAO(); outcar = new Outcar(); outcar.setUuid(sendcar.getOutcar_id()); outcar.setStatus(4); outcar.setLm_user(ContextHelper.getUserLoginUuid()); outcar.setLm_time(new Date()); ocd.mdyOutcarStatus(outcar); Outcar outmsg = new Outcar(); outmsg = (Outcar) ocd.get(sendcar.getOutcar_id()); //? SendDAO sd = new SendDAO(); PoolDAO pd = new PoolDAO(); map.clear(); map.put("outcar_id", outcar.getUuid()); this.setSendcars(sd.list(map)); List<Poolcar> pls = new ArrayList<Poolcar>(); pls = pd.list(map); StringBuffer url = new StringBuffer(); HttpServletRequest request = ServletActionContext.getRequest(); String url2 = request.getServerName().toString(); String uri = request.getRequestURI(); //url.append(url2.substring(0, url2.indexOf(uri))); url.append("http://cl.qkj.com.cn"); url.append("/qkjmanage/sendcar_edit?"); if (sendcars.size() > 0) { for (Sendcar s : sendcars) { List<Driver_files> d = new ArrayList<Driver_files>(); DriverDAO dr = new DriverDAO(); map.clear(); map.put("uuid", s.getDriver_id()); d = dr.list(map); for (Driver_files dd : d) { String meg = "" + timeStamp() + ";"; meg += "??;:" + outmsg.getApply_dept_name() + ";" + outmsg.getTheme() + "" + outmsg.getUse_date() + " " + outmsg.getUse_date_time() + ";" + ";" + outmsg.getStart_line() + ""; meg += outmsg.getEnd_line() + ";??" + outmsg.getAirport() + ";??" + outmsg.getApply_user() + ";" + ";??:" + s.getSeat_num() + ";??:" + outmsg.getPeple_phone() + ";???????????"; url.append("dcar.outcar_id=" + outcar.getUuid()); url.append("&dcar.send_id=" + s.getUuid());//id url.append("&dcar.driver_id=" + s.getDriver_id());//siji meg += "?:" + url.toString(); System.out.println(meg); if (dd.getDingdingid() != null) { Demo demo = new Demo(); demo.sendMessage(dd.getName() + meg, dd.getDingdingid()); } else { Weimimember_message wm = new Weimimember_message(); wm.sms_api2(dd.getPhone(), dd.getName(), meg); } if (outmsg.getPeple_phone() != null) { Weimimember_message wm = new Weimimember_message(); String meg2 = ""; meg2 = "" + timeStamp() + ";?;?:" + dd.getName() + ";???:" + dd.getPhone() + ";?" + s.getLicense(); meg2 += "???????????????????"; wm.sms_api2(outmsg.getPeple_phone(), "", meg2); } } } } if (pls.size() > 0) { for (Poolcar s : pls) { List<Driver_files> d = new ArrayList<Driver_files>(); DriverDAO dr = new DriverDAO(); map.clear(); map.put("uuid", s.getDriver_id()); d = dr.list(map); for (Driver_files dd : d) { String meg = ""; Weimimember_message wm = new Weimimember_message(); meg = "" + timeStamp() + ";"; meg += "??;:" + outmsg.getApply_dept_name() + ";" + outmsg.getTheme() + "" + outmsg.getUse_date() + " " + outmsg.getUse_date_time() + ";" + ";" + outmsg.getStart_line() + ""; meg += outmsg.getEnd_line() + ";??" + outmsg.getAirport() + ";??" + outmsg.getApply_user() + ";" + ";??:" + s.getSeat_num() + ";??:" + outmsg.getPeple_phone() + ";???????????"; if (dd.getDingdingid() != null) { Demo demo = new Demo(); demo.sendMessage(dd.getName() + meg, dd.getDingdingid()); } else { wm.sms_api2(dd.getPhone(), dd.getName(), meg); } if (outmsg.getPeple_phone() != null) { String meg2 = ""; meg2 = "" + timeStamp() + ";" + outmsg.getTheme() + "?;?:" + dd.getName() + ";???:" + dd.getPhone() + ";?" + s.getLicense(); meg2 += "???????????????????"; wm.sms_api2(outmsg.getPeple_phone(), "", meg2); } } } } } dao.commitTransaction(); } catch (Exception e) { log.error(this.getClass().getName() + "!add ?:", e); throw new Exception(this.getClass().getName() + "!add ?:", e); } finally { dao.endTransaction(); } return SUCCESS; } public String againsend() throws Exception { try { dao.startTransaction(); if (sendcar != null && sendcar.getOutcar_id() != null) { // OutcarDAO ocd = new OutcarDAO(); outcar = new Outcar(); outcar.setUuid(sendcar.getOutcar_id()); outcar.setStatus(3); outcar.setLm_user(ContextHelper.getUserLoginUuid()); outcar.setLm_time(new Date()); ocd.mdyOutcarStatus(outcar); //????? Outcar outmsg = new Outcar(); outmsg = (Outcar) ocd.get(sendcar.getOutcar_id()); //? SendDAO sd = new SendDAO(); PoolDAO pd = new PoolDAO(); map.clear(); map.put("outcar_id", outcar.getUuid()); this.setSendcars(sd.list(map)); List<Poolcar> pls = new ArrayList<Poolcar>(); pls = pd.list(map); if (sendcars.size() > 0) { for (Sendcar s : sendcars) { List<Driver_files> d = new ArrayList<Driver_files>(); DriverDAO dr = new DriverDAO(); map.clear(); map.put("uuid", s.getDriver_id()); d = dr.list(map); for (Driver_files dd : d) { String meg = ""; Weimimember_message wm = new Weimimember_message(); meg = "??;:" + outmsg.getApply_dept_name() + ";" + outmsg.getTheme() + "" + outmsg.getUse_date() + " " + outmsg.getUse_date_time() + ";" + ";" + outmsg.getStart_line() + ""; meg += outmsg.getEnd_line() + ";??" + outmsg.getApply_user() + ";" + ";??:" + s.getSeat_num() + ";??:" + outmsg.getPeple_phone() + ";?"; meg += ":" + timeStamp() + ";"; System.out.println(meg); if (dd.getDingdingid() != null) { Demo demo = new Demo(); demo.sendMessage(dd.getName() + meg, dd.getDingdingid()); } else { wm.sms_api2(dd.getPhone(), ":" + dd.getName() + "??", meg); } if (outmsg.getPeple_phone() != null) { String meg2 = ""; meg2 = "" + timeStamp() + ";" + outmsg.getTheme() + ";?:" + dd.getName() + ";???:" + dd.getPhone() + ";?" + s.getLicense(); meg2 += "??"; wm.sms_api2(outmsg.getPeple_phone(), "", meg2); } } } } if (pls.size() > 0) { for (Poolcar s : pls) { List<Driver_files> d = new ArrayList<Driver_files>(); DriverDAO dr = new DriverDAO(); map.clear(); map.put("uuid", s.getDriver_id()); d = dr.list(map); for (Driver_files dd : d) { String meg = ""; Weimimember_message wm = new Weimimember_message(); meg = "??;:" + outmsg.getApply_dept_name() + ";" + outmsg.getTheme() + "" + outmsg.getUse_date() + " " + outmsg.getUse_date_time() + ";" + ";" + outmsg.getStart_line() + ""; meg += outmsg.getEnd_line() + ";??" + outmsg.getApply_user() + ";" + ";??:" + s.getSeat_num() + ";??:" + outmsg.getPeple_phone() + ";?"; meg += ":" + timeStamp() + ";"; if (dd.getDingdingid() != null) { Demo demo = new Demo(); demo.sendMessage(dd.getName() + meg, dd.getDingdingid()); } else { wm.sms_api2(dd.getPhone(), ":" + dd.getName() + "??", meg + timeStamp()); } if (outmsg.getPeple_phone() != null) { String meg2 = ""; meg2 = "" + timeStamp() + ";" + outmsg.getTheme() + ";?:" + dd.getName() + ";???:" + dd.getPhone() + ";?" + s.getLicense(); meg2 += "??"; wm.sms_api2(outmsg.getPeple_phone(), "", meg2); } } } } } dao.commitTransaction(); } catch (Exception e) { log.error(this.getClass().getName() + "!add ?:", e); throw new Exception(this.getClass().getName() + "!add ?:", e); } finally { dao.endTransaction(); } return SUCCESS; } /** 38 * ? 39 * @return 40 */ public static String timeStamp() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String str = sdf.format(new Date()); return str; } @Override public String getPath() { // TODO Auto-generated method stub return null; } public static void main(String[] args) throws Exception { Weimimember_message wm = new Weimimember_message(); //wm.sms_api2(); } }