├── src
├── NewFile.xml
├── other.properties
├── routes.properties
├── database.properties
├── log4j.properties
├── guilinsoft
│ └── ddsx
│ │ ├── action
│ │ ├── Softupdatestatus.java
│ │ ├── Upload.java
│ │ ├── Taskselect.java
│ │ ├── Status.java
│ │ ├── Regetad.java
│ │ ├── Content.java
│ │ ├── Register.java
│ │ └── Tasks.java
│ │ ├── api
│ │ ├── G3API.java
│ │ ├── G3Manage.java
│ │ └── WdpfImpl.java
│ │ ├── quartz
│ │ ├── MTrigger.java
│ │ ├── 说明.txt
│ │ └── MCron.java
│ │ ├── util
│ │ ├── MMsg.java
│ │ ├── Tools.java
│ │ └── BuilderXml.java
│ │ └── core
│ │ └── MHttpServlet.java
└── config.properties
├── WebRoot
├── META-INF
│ └── MANIFEST.MF
├── WEB-INF
│ ├── lib
│ │ ├── c3p0-0.9.1.2.jar
│ │ ├── hessian-4.0.7.jar
│ │ ├── log4j-1.2.16.jar
│ │ ├── commons-dbutils-1.5.jar
│ │ ├── dom4j-2.0.0-ALPHA-2.jar
│ │ └── mysql-connector-java-5.0.5-bin.jar
│ └── web.xml
└── index.jsp
├── .mymetadata
├── .gitattributes
└── .gitignore
/src/NewFile.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/WebRoot/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path:
3 |
4 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/lib/c3p0-0.9.1.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hubs/WDPF/master/WebRoot/WEB-INF/lib/c3p0-0.9.1.2.jar
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/lib/hessian-4.0.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hubs/WDPF/master/WebRoot/WEB-INF/lib/hessian-4.0.7.jar
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/lib/log4j-1.2.16.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hubs/WDPF/master/WebRoot/WEB-INF/lib/log4j-1.2.16.jar
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/lib/commons-dbutils-1.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hubs/WDPF/master/WebRoot/WEB-INF/lib/commons-dbutils-1.5.jar
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/lib/dom4j-2.0.0-ALPHA-2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hubs/WDPF/master/WebRoot/WEB-INF/lib/dom4j-2.0.0-ALPHA-2.jar
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/lib/mysql-connector-java-5.0.5-bin.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hubs/WDPF/master/WebRoot/WEB-INF/lib/mysql-connector-java-5.0.5-bin.jar
--------------------------------------------------------------------------------
/src/other.properties:
--------------------------------------------------------------------------------
1 | #远程服务器下载地址
2 | target=http\://localhost\:28080/ddsx
3 | #本地项目地址
4 | base=http\://localhost\:28080/WDPF
5 | #定时器
6 | cron=1 * * * * ?
7 | #是否已启动定时器
8 | bool_start=false
--------------------------------------------------------------------------------
/src/routes.properties:
--------------------------------------------------------------------------------
1 | controller_package=com.gl.action
2 | default_controller=Welcome
3 | default_method=index
4 | backstage_package=backstage,xitong
5 | default_view =/xitong/login/login.jsp
6 |
7 |
--------------------------------------------------------------------------------
/src/database.properties:
--------------------------------------------------------------------------------
1 | hostname=localhost
2 | #192.168.1.110
3 | username=0CDCEBEDC74CCAED
4 | password=031C707A09F97905BF3A1701246E7F40
5 | #
6 | #031C707A09F97905BF3A1701246E7F40
7 | database=ddsx
8 | dbdriver=mysql
9 | port=3306
10 | cache_on=false
11 | mysql_path=D\://
12 |
--------------------------------------------------------------------------------
/.mymetadata:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/src/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootLogger=error,stdout, R
2 |
3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5 |
6 | log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n
7 |
8 | log4j.appender.R=org.apache.log4j.RollingFileAppender
9 | log4j.appender.R.File=firestorm.log
10 |
11 | log4j.appender.R.MaxFileSize=100KB
12 | log4j.appender.R.MaxBackupIndex=1
13 |
14 | log4j.appender.R.layout=org.apache.log4j.PatternLayout
15 | log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
16 |
17 | log4j.logger.com.codefutures=error
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/action/Softupdatestatus.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.action;
2 |
3 |
4 | import guilinsoft.ddsx.core.MHttpServlet;
5 |
6 | import java.io.IOException;
7 |
8 | import javax.servlet.ServletException;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 |
12 |
13 | public class Softupdatestatus extends MHttpServlet {
14 | private static final long serialVersionUID = 1L;
15 |
16 | @Override
17 | protected void service(HttpServletRequest req, HttpServletResponse resp)
18 | throws ServletException, IOException {
19 | begin(req);
20 | end();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/action/Upload.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.action;
2 |
3 |
4 | import guilinsoft.ddsx.core.MHttpServlet;
5 |
6 | import java.io.IOException;
7 |
8 | import javax.servlet.ServletException;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 |
12 | import com.jzero.cache.C;
13 | import com.jzero.util.MPrint;
14 |
15 |
16 | public class Upload extends MHttpServlet {
17 | private static final long serialVersionUID = 1L;
18 |
19 | @Override
20 | protected void service(HttpServletRequest req, HttpServletResponse resp)
21 | throws ServletException, IOException {
22 | begin(req);
23 | for(int i=0;i<10;i++){
24 | C.setCache("one_value_"+i, "one_"+i);
25 | }
26 | MPrint.print("内容上传");
27 | end();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/api/G3API.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.api;
2 |
3 | public interface G3API {
4 | /**
5 | * 审批成功, 更新任务状态 actionAuditAdSche
6 | */
7 | void releasetask(String groupId);
8 |
9 | /**
10 | * 发布播放列表
11 | */
12 | void release(String playlistId);
13 |
14 | /**
15 | * 群组下广告内容同步到终端 synchroGroupTaskToTerminal
16 | */
17 | void importad(String groupId,String terminalid);
18 |
19 | /**
20 | * 更新群组模板 editGroupTemplate
21 | */
22 | void changeTemplate(String groupid);
23 |
24 | /**
25 | * 更新播放列表发送状态 updateSendPlayListStatus
26 | */
27 | boolean timeLineReleasetask(String groupid);
28 |
29 | /**
30 | * 检查播放列表发送状态 checkSendPlayList,结果值用 | 分隔
31 | */
32 | String crossValidation(String groupid,String playlistid,String startDate,String endDate);
33 |
34 | /**
35 | * 按地市统计其下终端的连接壮态 SAByLocation2
36 | */
37 | void orderbystate();
38 |
39 | /**
40 | * 终端是否在线 ,返回记录的时间ymd his
41 | * shortnum:设备码
42 | */
43 | String getselecttime(String deviceId);
44 |
45 | /**
46 | * 生成模板文件 makeTemplateXML
47 | */
48 | boolean saveTemplateToXML(String templateid);
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/config.properties:
--------------------------------------------------------------------------------
1 | #log记录级别 NO,ERROR, DEBUG, INFO, ALL
2 | log_enabled=true
3 | log_level=ERROR
4 | log_reload=false
5 |
6 | #cookie管理,MToken
7 | cookie_prefix=
8 | cookie_domain=null
9 | cookie_path=/ddsx
10 |
11 | #INPUT
12 | charset=UTF-8
13 | #GLOBAL XSSFiltering INPUT
14 | global_xss_filtering=TRUE
15 |
16 |
17 | #token管理
18 | #是否开启验证MR
19 | csrf_protection=false
20 | csrf_token_name=csrf_jzero
21 | csrf_cookie_name=csrf_cookie_name
22 | #秒,二个小时
23 | csrf_expire=7200
24 |
25 | #是否开启压缩页面,还未实现,可参考多个filter拦截实现
26 | compress_output=false
27 |
28 | #pool 暂时实现的有 BoneCpPool,C3poPool,BasePool,ProxoolPool
29 | pool=C3poPool
30 | #数据库读取等待的最大时间(秒)
31 | db_max_time=60
32 | #数据库类型,暂时只实现了MySQL,其它的以后再完善
33 | db_type=CMySQL
34 |
35 | #显示参数项 properties
36 | show_prop=false
37 | #打印出当条语句执行的类与方法
38 | is_dev=true
39 | #查看当条SQL运行的时间
40 | show_run_time=false
41 | #是否显示执行的sql
42 | show_sql=true
43 |
44 | #充许URI字符 URI
45 | permitted_uri_chars=\\w*[,]*\\w*[,]*\\w*[,]*\\w*[,]*\\w[_]*\\w*
46 |
47 | sess_expiration =15
48 | sess_match_ip=true
49 | #是否需要需要浏览器
50 | sess_match_useragent=true
51 |
52 | #显示文件名后辍
53 | suffix=""
54 | DEFAULT_I18N_MAX_AGE_OF_COOKIE = 999999999;
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/quartz/MTrigger.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.quartz;
2 |
3 | import org.quartz.CronScheduleBuilder;
4 | import org.quartz.CronTrigger;
5 | import org.quartz.JobBuilder;
6 | import org.quartz.JobDetail;
7 | import org.quartz.Scheduler;
8 | import org.quartz.SchedulerFactory;
9 | import org.quartz.TriggerBuilder;
10 | import org.quartz.impl.StdSchedulerFactory;
11 |
12 | import com.jzero.util.MPrint;
13 | import com.jzero.util.MPro;
14 |
15 | public class MTrigger {
16 | private static MTrigger instanct=new MTrigger();
17 | private static SchedulerFactory sf = new StdSchedulerFactory();
18 | private MTrigger(){}
19 | public static MTrigger me(){
20 | return instanct;
21 | }
22 | public void run() throws Exception {
23 | MPrint.print(" 已执行定时任务 ...");
24 | Scheduler sched = sf.getScheduler();
25 | JobDetail job = JobBuilder.newJob(MCron.class).withIdentity("job1", "group1").build();
26 | //0 59 23 * * ? 每天23点59分触发
27 | CronTrigger trigger = (CronTrigger)TriggerBuilder.newTrigger().withIdentity("trigger1", "group1").withSchedule(CronScheduleBuilder.cronSchedule(MPro.me().getStr("cron"))).build();
28 |
29 | sched.scheduleJob(job, trigger);
30 | sched.start();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/api/G3Manage.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.api;
2 |
3 |
4 | public class G3Manage {
5 | private G3Manage() {
6 | }
7 | private static G3API g3api = new WdpfImpl();
8 | private static G3Manage instanct=new G3Manage();
9 | public static G3Manage me(){
10 | return instanct;
11 | }
12 | public void changeTemplate(String groupid) {
13 | g3api.changeTemplate(groupid);
14 | }
15 |
16 | public String crossValidation(String groupid, String playlistid,
17 | String startDate, String endDate) {
18 | return g3api.crossValidation(groupid, playlistid, startDate, endDate);
19 | }
20 |
21 | public String getselecttime(String deviceId) {
22 | return g3api.getselecttime(deviceId);
23 | }
24 |
25 | public void importad(String groupId, String terminalid) {
26 | g3api.importad(groupId, terminalid);
27 | }
28 |
29 | public void orderbystate() {
30 | g3api.orderbystate();
31 | }
32 |
33 | public void release(String playlistId) {
34 | g3api.release(playlistId);
35 | }
36 |
37 | public void releasetask(String groupId) {
38 | g3api.releasetask(groupId);
39 | }
40 |
41 | public boolean saveTemplateToXML(String templateid) {
42 | return g3api.saveTemplateToXML(templateid);
43 | }
44 |
45 | public boolean timeLineReleasetask(String groupid) {
46 | return g3api.timeLineReleasetask(groupid);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/util/MMsg.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.util;
2 |
3 | public class MMsg {
4 |
5 |
6 | //模板
7 | public static final String TB_TEMPLATE = "template";
8 |
9 |
10 | //子模板
11 | public static final String TB_SUBTEMPLATE = "subtemplate";
12 |
13 | //存放模板位置
14 | public static final String TB_RESOURCE = "m_resource";
15 |
16 | //播放列表
17 | public static final String TB_PLAYLISTTASKITEM = "playlisttaskitem";
18 |
19 | //群组表
20 | public static final String TB_TERMGROUP = "termgroup";
21 |
22 | //终端临时状态
23 | public static final String TB_TERMSTATETEMP = "termstatetemp";
24 |
25 | //终端表
26 | public static final String TB_TERMINAL = "terminal";
27 |
28 | public static final String TB_PLAYTASK = "PlayTask";
29 | public static final String TB_CONTENT = "Content";
30 | //终端ID
31 | public static final String INFO_DEVICEID = "x-device-id";
32 |
33 | //更新时间
34 | public static final String INFO_UPDATE_TIME = "updatetime";
35 |
36 | public static final String INFO_REGETAD = "-regetad";
37 |
38 | public static final String INFO_TEMPLATE_DOWN = "-template";
39 |
40 | /**
41 | * 2013-2-21
42 | * 0:未接收,1:已接收
43 | * 5:删除,3:已删除
44 | * 6:自定义的,模板ID,7:已下发
45 | */
46 | public static final int ADD_COMMEND = 0;
47 | public static final int ADD_COMMENDED = 1;
48 | public static final int DEL_ED_COMMEND = 3;
49 | public static final int DEL_COMMEND = 5;
50 | public static final int TEMPLATE_COMMEND = 6;
51 | public static final int TEMPLATE_ED_COMMEND = 7;
52 | /**
53 | * 2013-7-26:在接收状态时使用
54 | * 8:执行失败
55 | * 9:任务取消
56 | */
57 | public static final int TAST_ERROR = 8;
58 | public static final int TAST_CANEL = 9;
59 | }
60 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/core/MHttpServlet.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.core;
2 |
3 | import java.util.Enumeration;
4 |
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 |
8 | import com.jzero.util.MDate;
9 | import com.jzero.util.MPro;
10 | import com.jzero.util.Msg;
11 |
12 | public class MHttpServlet extends HttpServlet {
13 |
14 | private static final long serialVersionUID = 1L;
15 | static {
16 | MPro.me().load_file(Msg.DB_CONFIG).load_file(Msg.CONFIG).load_file(Msg.OTHER_CONFIG);
17 | }
18 | private String deviceid;
19 | private String nc;
20 | private String cnonce;
21 | @SuppressWarnings("unchecked")
22 | protected void begin(HttpServletRequest req){
23 | System.out.println("----------------------------------------"+getClass().getSimpleName()+" 开始 ----------------------"+req.getMethod()+","+MDate.get_ymd_hms());
24 | System.out.println("来源: "+req.getRequestURL()+"?"+req.getQueryString());
25 | Enumeration ene=req.getHeaderNames();
26 | while(ene.hasMoreElements()){
27 | String key=ene.nextElement();
28 | String v=req.getHeader(key);
29 | if(key.equals("x-device-id")){
30 | setDeviceid(v);
31 | }
32 | if(key.equals("authorization")){
33 | String[] auths=v.split(",");
34 | for(String str:auths){
35 | if(str.startsWith("nc")||str.startsWith("cnonce")){
36 | String[] kv = str.split("=");
37 | setNc(kv[0]);
38 | setCnonce(kv[1]);
39 | }
40 | }
41 | }
42 | System.out.println(key+" = "+v);
43 | }
44 | }
45 | protected void end(){
46 | System.out.println("----------------------------------------"+getClass().getSimpleName()+" 结束-----------------------");
47 | }
48 | public String getDeviceid() {
49 | return deviceid;
50 | }
51 | public void setDeviceid(String deviceid) {
52 | this.deviceid = deviceid;
53 | }
54 | public String getNc() {
55 | return nc;
56 | }
57 | public void setNc(String nc) {
58 | this.nc = nc;
59 | }
60 | public String getCnonce() {
61 | return cnonce;
62 | }
63 | public void setCnonce(String cnonce) {
64 | this.cnonce = cnonce;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/quartz/说明.txt:
--------------------------------------------------------------------------------
1 | CronTrigger配置格式:
2 |
3 | 格式: [秒] [分] [小时] [日] [月] [周] [年]
4 |
5 | 序号 说明
6 | 是否必填 允许填写的值 允许的通配符
7 | 1 秒 是 0-59 , - * /
8 | 2 分 是 0-59
9 | , - * /
10 | 3 小时 是 0-23 , - * /
11 | 4 日 是 1-31 , - * ? / L W
12 | 5 月 是 1-12 or JAN-DEC , - * /
13 | 6 周 是 1-7 or SUN-SAT , - * ? / L #
14 | 7 年 否 empty 或 1970-2099 , - * /
15 | 通配符说明:
16 | * 表示所有值. 例如:在分的字段上设置 "*",表示每一分钟都会触发。
17 | ? 表示不指定值。使用的场景为不需要关心当前设置这个字段的值。例如:要在每月的10号触发一个操作,但不关心是周几,所以需要周位置的那个字段设置为"?" 具体设置为 0 0 0 10 * ?
18 | - 表示区间。例如 在小时上设置 "10-12",表示 10,11,12点都会触发。
19 | , 表示指定多个值,例如在周字段上设置 "MON,WED,FRI" 表示周一,周三和周五触发
20 | / 用于递增触发。如在秒上面设置"5/15" 表示从5秒开始,每增15秒触发(5,20,35,50)。 在月字段上设置'1/3'所示每月1号开始,每隔三天触发一次。
21 | L 表示最后的意思。在日字段设置上,表示当月的最后一天(依据当前月份,如果是二月还会依据是否是润年[leap]), 在周字段上表示星期六,相当于"7"或"SAT"。如果在"L"前加上数字,则表示该数据的最后一个。例如在周字段上设置"6L"这样的格式,则表示“本月最后一个星期五"
22 | W 表示离指定日期的最近那个工作日(周一至周五). 例如在日字段上设置"15W",表示离每月15号最近的那个工作日触发。如果15号正好是周六,则找最近的周五(14号)触发, 如果15号是周未,则找最近的下周一(16号)触发.如果15号正好在工作日(周一至周五),则就在该天触发。如果指定格式为 "1W",它则表示每月1号往后最近的工作日触发。如果1号正是周六,则将在3号下周一触发。(注,"W"前只能设置具体的数字,不允许区间"-").
23 | 小提示
24 | 'L'和 'W'可以一组合使用。如果在日字段上设置"LW",则表示在本月的最后一个工作日触发(一般指发工资 )
25 |
26 | # 序号(表示每月的第几个周几),例如在周字段上设置"6#3"表示在每月的第三个周六.注意如果指定"#5",正好第五周没有周六,则不会触发该配置(用在母亲节和父亲节再合适不过了)
27 | 小提示
28 | 周字段的设置,若使用英文字母是不区分大小写的 MON 与mon相同.
29 |
30 |
31 |
32 | 常用示例:
33 |
34 | 0 0 12 * * ? 每天12点触发
35 | 0 15 10 ? * * 每天10点15分触发
36 | 0 15 10 * * ? 每天10点15分触发
37 | 0 15 10 * * ? * 每天10点15分触发
38 | 0 15 10 * * ? 2005 2005年每天10点15分触发
39 | 0 * 14 * * ? 每天下午的 2点到2点59分每分触发
40 | 0 0/5 14 * * ? 每天下午的 2点到2点59分(整点开始,每隔5分触发)
41 | 0 0/5 14,18 * * ? 每天下午的 2点到2点59分(整点开始,每隔5分触发)
42 | 每天下午的 18点到18点59分(整点开始,每隔5分触发)
43 | 0 0-5 14 * * ? 每天下午的 2点到2点05分每分触发
44 | 0 10,44 14 ? 3 WED 3月分每周三下午的 2点10分和2点44分触发
45 | 0 15 10 ? * MON-FRI 从周一到周五每天上午的10点15分触发
46 | 0 15 10 15 * ? 每月15号上午10点15分触发
47 | 0 15 10 L * ? 每月最后一天的10点15分触发
48 | 0 15 10 ? * 6L 每月最后一周的星期五的10点15分触发
49 | 0 15 10 ? * 6L 2002-2005 从2002年到2005年每月最后一周的星期五的10点15分触发
50 | 0 15 10 ? * 6#3 每月的第三周的星期五开始触发
51 | 0 0 12 1/5 * ? 每月的第一个中午开始每隔5天触发一次
52 | 0 11 11 11 11 ? 每年的11月11号 11点11分触发(光棍节)
--------------------------------------------------------------------------------
/WebRoot/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*,com.jzero.util.*,com.jzero.core.*,com.jzero.log.*,guilinsoft.ddsx.quartz.*,guilinsoft.ddsx.util.MMsg" pageEncoding="UTF-8"%>
2 |
3 |
4 |
5 |
11 |
12 |
13 | <%
14 | MPro.me().load_file(Msg.OTHER_CONFIG);
15 | boolean bool_run=MPro.me().getBool("bool_start");
16 | String subText=bool_run?"已运行":"运行定时器";
17 | String disabled=bool_run?"disabled='disabled'":"";
18 | %>
19 |
25 | <%
26 | String action=request.getParameter("action");
27 | if(!MCheck.isNull(action)&&action.equals("submit")){
28 | if(!bool_run){
29 | MPro.me().setValue("bool_start","true");
30 | try{
31 | MTrigger.me().run();
32 | }catch(Exception e){
33 | Log.me().write(e.getLocalizedMessage());
34 | }
35 | }
36 | }
37 | %>
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/action/Taskselect.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.action;
2 |
3 | import guilinsoft.ddsx.core.MHttpServlet;
4 | import guilinsoft.ddsx.util.MMsg;
5 | import guilinsoft.ddsx.util.Tools;
6 |
7 | import java.io.BufferedWriter;
8 | import java.io.IOException;
9 | import java.io.OutputStreamWriter;
10 |
11 | import javax.servlet.ServletException;
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 |
15 | import com.jzero.cache.C;
16 | import com.jzero.db.core.M;
17 | import com.jzero.util.MCheck;
18 |
19 |
20 | public class Taskselect extends MHttpServlet {
21 | private static final long serialVersionUID = 1L;
22 |
23 | @Override
24 | protected void service(HttpServletRequest req, HttpServletResponse resp)
25 | throws ServletException, IOException {
26 | begin(req);
27 | String cacheKey=getDeviceid()+MMsg.INFO_REGETAD;
28 | Object regetad=C.getCacheObj(cacheKey);
29 | if(!MCheck.isNull(regetad)){//不为空,说明已执行Regetad,需要将所有文件下发
30 | resp.setIntHeader("taskFlag", 1);
31 | Tools.update_termstatetemp(getDeviceid(), 1);//1:在线,0:不在线
32 | }else{
33 | Object deviceObj=C.getCacheObj(getDeviceid());
34 | if(!MCheck.isNull(deviceObj)){
35 | int tasks=getTasks();
36 | if(tasks>0){
37 | resp.setIntHeader("taskFlag", 1);
38 | }else{
39 | resp.setIntHeader("taskFlag", 0);
40 | }
41 | Tools.update_termstatetemp(getDeviceid(), 1);//1:在线,0:不在线
42 | }else{
43 | timeOut(resp);
44 | Tools.update_termstatetemp(getDeviceid(), 0);//1:在线,0:不在线
45 | }
46 | }
47 | end();
48 | }
49 | //进行任务的选择
50 | private int getTasks(){
51 | /**
52 | * 有新增,删除命令
53 | */
54 | String sql="SELECT cid FROM "+MMsg.TB_PLAYLISTTASKITEM+" WHERE terminalid = '"+getDeviceid()+"' AND (recvstate = '"+MMsg.ADD_COMMEND+"' OR recvstate = '"+MMsg.DEL_COMMEND+"' OR recvstate='"+MMsg.TEMPLATE_COMMEND+"' )";
55 | return M.me().get_count_sql(sql);
56 | }
57 | //超时
58 | private void timeOut(HttpServletResponse resp) {
59 | try {
60 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream()));
61 | resp.setStatus(HttpServletResponse.SC_REQUEST_TIMEOUT);//408 超时
62 | bw.write("");// //这里返回内容是body:"",如果省去这一段,会发出this http request
63 | bw.flush();
64 | bw.close();
65 | } catch (Exception e) {
66 | e.printStackTrace();
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/action/Status.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.action;
2 |
3 | import guilinsoft.ddsx.core.MHttpServlet;
4 | import guilinsoft.ddsx.util.MMsg;
5 |
6 | import java.io.IOException;
7 |
8 | import javax.servlet.ServletException;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 |
12 | import com.jzero.db.core.M;
13 | import com.jzero.util.MCnt;
14 | import com.jzero.util.MDate;
15 | import com.jzero.util.MRecord;
16 |
17 | public class Status extends MHttpServlet {
18 | private static final long serialVersionUID = 1L;
19 |
20 | @Override
21 | protected void service(HttpServletRequest req, HttpServletResponse resp)
22 | throws ServletException, IOException {
23 | begin(req);
24 | //String taskid=req.getParameter("taskid");//任务ID,暂时没用到
25 | String cid=req.getParameter("cid");//取到的是playlisttaskitem的serialno(主键)
26 | String status=req.getParameter("status");
27 | /**
28 | * status 01:下载成功
29 | * 02:执行失败
30 | * 03:任务失败
31 | * 06:删除成功
32 | */
33 | if(status.equals("01")||status.equals("1")){
34 | MRecord mRecord=M.me().one_t(MMsg.TB_PLAYLISTTASKITEM, MCnt.me().and_eq("serialno", cid).toStr());
35 | String type=mRecord.getStr("recvstate");//判断当前是资料下载还是模板下载
36 | if(type.equals(MMsg.TEMPLATE_COMMEND)){//如果是模板,则更新模板状态
37 | M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", MMsg.TEMPLATE_ED_COMMEND).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("serialno", cid).toStr());
38 | }else if(type.equals(MMsg.ADD_COMMEND)){//更新状态为下载成功
39 | M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", MMsg.ADD_COMMENDED).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("serialno", cid).toStr());
40 | }
41 | }else if(status.equals("06")||status.equals("6")){//更新状态为删除成功
42 | M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", MMsg.DEL_ED_COMMEND).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("serialno", cid).toStr());
43 | }else if(status.equals("2")||status.equals("02")){
44 | //更新状态为任务失败,这样在Taskselect时就会过滤这条数据
45 | M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", MMsg.TAST_ERROR).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("serialno", cid).toStr());
46 | }else if(status.equals("3")||status.equals("03")){
47 | //更新状态为任务取消
48 | M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate",MMsg.TAST_CANEL).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("serialno", cid).toStr());
49 | }
50 | end();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/action/Regetad.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.action;
2 |
3 |
4 | import guilinsoft.ddsx.core.MHttpServlet;
5 | import guilinsoft.ddsx.util.MMsg;
6 |
7 | import java.io.IOException;
8 |
9 | import javax.servlet.ServletException;
10 | import javax.servlet.http.HttpServletRequest;
11 | import javax.servlet.http.HttpServletResponse;
12 |
13 | import com.jzero.cache.C;
14 | import com.jzero.util.MPrint;
15 |
16 | /**
17 | * 初始化 U盘
18 | */
19 | public class Regetad extends MHttpServlet {
20 | private static final long serialVersionUID = 1L;
21 |
22 | @Override
23 | protected void service(HttpServletRequest req, HttpServletResponse resp)
24 | throws ServletException, IOException {
25 | begin(req);
26 | // build_xml();
27 | // build_other();
28 | //2013-2-19 格式化,在tasks里判断,如果为true,则下载全部,否则只针对下载
29 | String cacheKey=getDeviceid()+MMsg.INFO_REGETAD;
30 | C.setCache(true,cacheKey);
31 | MPrint.print("格式化U盘!");
32 | end();
33 | }
34 |
35 | // private void build_xml(){
36 | // MPrint.print("生成主模板.");
37 | // String templateid="74beca8fa770e5d6ca98e3d1b380c209";
38 | // MRecord temlate=M.me().one_t(MMsg.TB_TEMPLATE, MCnt.me().and_eq("templateid", templateid).toStr()); //主模板
39 | // List sub_template=M.me().get_where("subtemplate",MCnt.me().first_eq("templateid", templateid).toStr());//子模板
40 | // BuilderXml.me().xml_program(temlate,sub_template);
41 | // }
42 | // private void build_other(){
43 | // MPrint.print("生成其它模板.");
44 | // String groupId="B46601BA0D53D5BE69CF9702C60F3BD0";
45 | // MRecord groupRe=M.me().one_t(MMsg.TB_TERMGROUP,MCnt.me().and_eq("groupid", groupId).toStr());
46 | // //image.xml
47 | // List imageLst=M.me().sql(getXmlSql(groupId, "P"));
48 | // if(!MCheck.isNull(imageLst)){
49 | // BuilderXml.me().xml_image(groupRe, imageLst);
50 | // }
51 | //
52 | // //text.xml
53 | // List textLst=M.me().sql(getXmlSql(groupId, "W"));
54 | // if(!MCheck.isNull(textLst)){
55 | // BuilderXml.me().xml_text(groupRe, textLst);
56 | // }
57 | //
58 | // //movie.xml
59 | // List movieLst=M.me().sql(getXmlSql(groupId, "V"));
60 | // if(!MCheck.isNull(movieLst)){
61 | // BuilderXml.me().xml_movie(groupRe, movieLst);
62 | // }
63 | //
64 | // //scrollingtext.xml
65 | // List scrollLst=M.me().sql(getXmlSql(groupId, "S"));
66 | // if(!MCheck.isNull(scrollLst)){
67 | // BuilderXml.me().xml_scrollingtext(groupRe, scrollLst);
68 | // }
69 | // }
70 | // private String getXmlSql(String groupid,String type){
71 | // return "SELECT distinct cname,path FROM playlisttaskitem WHERE EXISTS (SELECT taskid FROM playtask WHERE approvestatus='P' AND groupid='"+groupid+"' AND endtime >NOW()) AND TYPE='"+type+"'";
72 | // }
73 | }
74 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 | hessianService
10 |
11 | com.caucho.hessian.server.HessianServlet
12 |
13 | service-class
14 |
15 | guilinsoft.ddsx.api.WdpfImpl
16 |
17 | 1
18 |
19 |
20 |
21 | hessianService
22 | /hessianService
23 |
24 |
25 |
26 | register
27 | guilinsoft.ddsx.action.Register
28 |
29 |
30 | taskselect
31 | guilinsoft.ddsx.action.Taskselect
32 |
33 |
34 | status
35 | guilinsoft.ddsx.action.Status
36 |
37 |
38 | softupdatestatus
39 | guilinsoft.ddsx.action.Softupdatestatus
40 |
41 |
42 | tasks
43 | guilinsoft.ddsx.action.Tasks
44 |
45 |
46 | content
47 | guilinsoft.ddsx.action.Content
48 |
49 |
50 | upload
51 | guilinsoft.ddsx.action.Upload
52 |
53 |
54 | regetad
55 | guilinsoft.ddsx.action.Regetad
56 |
57 |
58 |
59 |
60 |
61 | register
62 | /register
63 |
64 |
65 | taskselect
66 | /taskselect
67 |
68 |
69 | status
70 | /status
71 |
72 |
73 | softupdatestatus
74 | /softupdatestatus
75 |
76 |
77 | tasks
78 | /tasks
79 |
80 |
81 | content
82 | /content
83 |
84 |
85 | upload
86 | /upload
87 |
88 |
89 | regetad
90 | /regetad
91 |
92 |
93 | index.jsp
94 |
95 |
96 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 |
131 | # NuGet Packages Directory
132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133 | #packages/
134 |
135 | # Windows Azure Build Output
136 | csx
137 | *.build.csdef
138 |
139 | # Windows Store app package directory
140 | AppPackages/
141 |
142 | # Others
143 | sql/
144 | *.Cache
145 | ClientBin/
146 | [Ss]tyle[Cc]op.*
147 | ~$*
148 | *~
149 | *.dbmdl
150 | *.[Pp]ublish.xml
151 | *.pfx
152 | *.publishsettings
153 |
154 | # RIA/Silverlight projects
155 | Generated_Code/
156 |
157 | # Backup & report files from converting an old project file to a newer
158 | # Visual Studio version. Backup files are not needed, because we have git ;-)
159 | _UpgradeReport_Files/
160 | Backup*/
161 | UpgradeLog*.XML
162 | UpgradeLog*.htm
163 |
164 | # SQL Server files
165 | App_Data/*.mdf
166 | App_Data/*.ldf
167 |
168 | #############
169 | ## Windows detritus
170 | #############
171 |
172 | # Windows image file caches
173 | Thumbs.db
174 | ehthumbs.db
175 |
176 | # Folder config file
177 | Desktop.ini
178 |
179 | # Recycle Bin used on file shares
180 | $RECYCLE.BIN/
181 |
182 | # Mac crap
183 | .DS_Store
184 |
185 |
186 | #############
187 | ## Python
188 | #############
189 |
190 | *.py[co]
191 |
192 | # Packages
193 | *.egg
194 | *.egg-info
195 | dist/
196 | build/
197 | eggs/
198 | parts/
199 | var/
200 | sdist/
201 | develop-eggs/
202 | .installed.cfg
203 |
204 | # Installer logs
205 | pip-log.txt
206 |
207 | # Unit test / coverage reports
208 | .coverage
209 | .tox
210 |
211 | #Translations
212 | *.mo
213 |
214 | #Mr Developer
215 | .mr.developer.cfg
216 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/action/Content.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.action;
2 |
3 | import guilinsoft.ddsx.core.MHttpServlet;
4 | import guilinsoft.ddsx.util.MMsg;
5 | import guilinsoft.ddsx.util.Tools;
6 |
7 | import java.io.BufferedOutputStream;
8 | import java.io.File;
9 | import java.io.IOException;
10 | import java.io.RandomAccessFile;
11 | import java.net.URL;
12 | import java.util.Enumeration;
13 |
14 | import javax.servlet.ServletException;
15 | import javax.servlet.http.HttpServletRequest;
16 | import javax.servlet.http.HttpServletResponse;
17 |
18 | import com.jzero.db.core.M;
19 | import com.jzero.util.MCheck;
20 | import com.jzero.util.MCnt;
21 | import com.jzero.util.MPrint;
22 | import com.jzero.util.MRecord;
23 |
24 | public class Content extends MHttpServlet {
25 | private static final long serialVersionUID = 1L;
26 | private String range = null;
27 |
28 | @SuppressWarnings("unchecked")
29 | @Override
30 | protected void service(HttpServletRequest req, HttpServletResponse resp)
31 | throws ServletException, IOException {
32 | begin(req);
33 | Enumeration ene = req.getHeaderNames();
34 | while (ene.hasMoreElements()) {
35 | String key = (String) ene.nextElement();
36 | String v = req.getHeader(key);
37 | if (key.equals("range")) {
38 | range = v;
39 | }
40 | }
41 | MPrint.print("下载任务");
42 | try {
43 | down(resp,req);
44 | } catch (Exception e) {
45 | e.printStackTrace();
46 | }
47 | end();
48 | }
49 | //断点下载
50 | public void down(HttpServletResponse resp,HttpServletRequest request) throws Exception {
51 | String serno=request.getParameter("serialno");
52 | MRecord reObj=M.me().one_t(MMsg.TB_PLAYLISTTASKITEM, MCnt.me().and_eq("serialno", serno).toStr());
53 | String uri=Tools.getTargetBase()+"/"+reObj.getStr("url");
54 | MPrint.print("断点 uri= "+uri);
55 | URL url = new URL(uri);
56 | File file =new File("");
57 | long fileLen =url.openConnection().getContentLength();//file.length();
58 | long begin = 0;
59 | long end = fileLen - 1;
60 | String contentRange = null;
61 | if (!MCheck.isNull(range)) {
62 | // 设置状态
63 | resp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
64 | // 得到请求byte范围
65 | String rangeBytes = range.replace("bytes=", "");
66 | String[] rangeArr = rangeBytes.trim().split("-");
67 | begin = Long.parseLong(rangeArr[0]);
68 | // 如果请求有结束范围 eg:1024000-2058220
69 | if (rangeArr.length > 1) {
70 | end = Long.parseLong(rangeArr[1]);
71 | }
72 | contentRange = new StringBuffer("bytes ").append(begin).append("-").append(end).append("/").append(fileLen).toString();
73 | }
74 | resp.setContentType("application/x-msdownload");// 设备下载的编码方式
75 | resp.setHeader("Accept-Ranges", "bytes");
76 | resp.setHeader("Content-Range", contentRange);
77 | resp.addHeader("Content-Length", String.valueOf(end + 1 - begin)); // 设置下载内容的大小
78 | resp.setCharacterEncoding("UTF-8");
79 | RandomAccessFile randomf = null;
80 | try {
81 | BufferedOutputStream bw = new BufferedOutputStream(resp
82 | .getOutputStream());
83 | randomf = new RandomAccessFile(file, "r");
84 | byte[] bt = new byte[1024 * 1024];
85 | int i = -1;
86 | try {
87 | // 读取数据
88 | randomf.seek(begin);
89 | while ((i = randomf.read(bt)) != -1) {
90 | if (randomf.getFilePointer() >= end) {
91 | bw.write(bt, 0, (int) (i + end- randomf.getFilePointer() + 1));
92 | break;
93 | } else
94 | bw.write(bt, 0, i);
95 | }
96 | bw.flush();
97 | } catch (Exception e) {
98 | System.out.println("下载报错:" + e.toString());
99 | }
100 | } catch (Exception e) {
101 | e.printStackTrace();
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/action/Register.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.action;
2 |
3 | import guilinsoft.ddsx.core.MHttpServlet;
4 | import guilinsoft.ddsx.util.MMsg;
5 | import guilinsoft.ddsx.util.Tools;
6 |
7 | import java.io.BufferedWriter;
8 | import java.io.IOException;
9 | import java.io.OutputStreamWriter;
10 | import java.util.Enumeration;
11 |
12 | import javax.servlet.ServletException;
13 | import javax.servlet.http.HttpServletRequest;
14 | import javax.servlet.http.HttpServletResponse;
15 |
16 | import com.jzero.cache.C;
17 | import com.jzero.util.MCheck;
18 | import com.jzero.util.MDate;
19 | import com.jzero.util.MMD5;
20 | import com.jzero.util.MPrint;
21 | import com.jzero.util.MRecord;
22 |
23 | /**
24 | * 终端第一次连接上来进行注册
25 | */
26 | public class Register extends MHttpServlet {
27 | private static final long serialVersionUID = 1L;
28 | @SuppressWarnings("unchecked")
29 | @Override
30 | protected void service(HttpServletRequest req, HttpServletResponse resp)
31 | throws ServletException, IOException {
32 | begin(req);
33 | MRecord record = new MRecord();
34 | MRecord tempRecord=new MRecord();
35 | String temp[]=null;
36 | Enumeration ene = req.getHeaderNames();
37 | while (ene.hasMoreElements()) {
38 | String key = ene.nextElement();
39 | String v = req.getHeader(key);
40 | if(key.equals("authorization")){
41 | v=v.substring(v.indexOf("Digest")+6).replaceAll("\"", "");
42 | String[] auths=v.split(",");
43 | for(String s:auths){
44 | temp=s.split("=");
45 | if(temp.length>1){
46 | if(temp[0].equalsIgnoreCase("uri")){
47 | tempRecord.set(temp[0], s.substring(s.indexOf("=")+1));
48 | }else{
49 | tempRecord.set(temp[0].trim(), temp[1]);
50 | }
51 | }
52 | }
53 | }
54 | record.set(key, v);
55 | }
56 | String audit = record.getStr("authorization");
57 | MRecord inDatas=new MRecord();
58 | if (MCheck.isNull(audit)) {
59 | first_visit(resp);
60 | } else {
61 | boolean isOk=Tools.validateRegister(tempRecord);
62 | if(isOk){
63 | second_visit(resp);
64 | inDatas.set(MMsg.INFO_UPDATE_TIME, MDate.get_ymd_hms());
65 | inDatas.set(MMsg.INFO_DEVICEID, record.getStr(MMsg.INFO_DEVICEID));
66 | C.setCache(record, record.getStr(MMsg.INFO_DEVICEID)); //用于取缓存,登录时间
67 | Tools.update_termstatetemp(getDeviceid(), 0);
68 | }else{
69 | first_visit(resp);
70 | }
71 | }
72 | end();
73 | }
74 | private void second_visit(HttpServletResponse resp) {
75 | try {
76 | // 更新当前设备的在线状态
77 | // 假设这里验证成功,则返回200
78 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(resp
79 | .getOutputStream()));
80 | String au = "qop='auth',nextnonce='"
81 | + MMD5.toMD5ByJAVA(System.currentTimeMillis() + "")
82 | + "',rspauth='" + MMD5.toMD5ByJAVA(System.nanoTime() + "")
83 | + "' ,nc=" + getNc() +" ,cnonce="+getCnonce();
84 | MPrint.print("第二次返回:" + au);
85 | resp.setHeader("Authentication-Info", au);
86 | resp.setStatus(HttpServletResponse.SC_OK);
87 | bw.write("");// 这里返回内容是body:"",如果省去这一段,会发出this http request
88 | bw.flush();
89 | bw.close();
90 | } catch (Exception e) {
91 | e.printStackTrace();
92 | }
93 | }
94 | /**
95 | * 第一次回复
96 | */
97 | private void first_visit(HttpServletResponse resp) {
98 | try {
99 | BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(resp
100 | .getOutputStream()));
101 | String au = "Digest realm=\"wdpf@service.cmcc.cn\",qop=\"auth\",nonce=\""
102 | + Tools.random(32)
103 | + "\",opaque=\""
104 | + MMD5.toMD5ByJAVA(Tools.generate_id() + "") + "\"";
105 | MPrint.print("第一次回复: " + au);
106 | resp.setHeader("WWW-Authenticate", au);
107 | resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
108 | bw.write("");// //这里返回内容是body:"",如果省去这一段,会发出this http request
109 | // Authentication
110 | bw.flush();
111 | bw.close();
112 | } catch (Exception e) {
113 | e.printStackTrace();
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/util/Tools.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.util;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.util.Random;
8 |
9 | import com.jzero.db.core.M;
10 | import com.jzero.log.Log;
11 | import com.jzero.util.MCheck;
12 | import com.jzero.util.MCnt;
13 | import com.jzero.util.MDate;
14 | import com.jzero.util.MMD5;
15 | import com.jzero.util.MPrint;
16 | import com.jzero.util.MPro;
17 | import com.jzero.util.MRecord;
18 |
19 | public class Tools {
20 | public static String generate_id() {
21 | return MDate.getSimpleDateFormat("yyyyMMddHHmmssSSS").format(
22 | MDate.newDate())
23 | + random(15);
24 | }
25 |
26 | public static String random(int num) {
27 | Random random = new Random();
28 | char[] c = new char[num];
29 | for (int i = 0; i < num; i++) {
30 | int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; // 取得大写还是小写
31 | c[i] = (char) (choice + random.nextInt(26));
32 | }
33 | return new String(c);
34 | }
35 |
36 | // 要加"/"
37 | public static String getTargetBase() {
38 | return MPro.me().getStr("target");
39 | }
40 |
41 | // 要加"/"
42 | public static String getBase() {
43 | return MPro.me().getStr("base");
44 | }
45 |
46 | /**
47 | * 在登录时或orderbystate 时调用 登录时,将deviceid设备的状态全部制为0:表示不存在
48 | * 在调用orderbystate时将存在的状态制为1:表示存在
49 | *
50 | * @param deviceid
51 | */
52 | public static void update_termstatetemp(String deviceid, int state) {
53 | MRecord mRecord = M.me().one_t(MMsg.TB_TERMSTATETEMP,
54 | MCnt.me().and_eq("deviceid", deviceid).toStr());
55 | if (!MCheck.isNull(mRecord)) {
56 | if (!mRecord.getStr("state").equals(state)) { // 不相等的时候修改状态
57 | M.me().update(MMsg.TB_TERMSTATETEMP,new MRecord().set("state", state).set("selecttime", MDate.get_ymd_hms()),MCnt.me().first_eq("deviceid", deviceid).toStr());
58 | }
59 | } else {
60 | M.me().insert(MMsg.TB_TERMSTATETEMP,new MRecord().set("state", state).set("deviceid",deviceid).set("selecttime", MDate.get_ymd_hms()));
61 | }
62 | }
63 |
64 | public static boolean validateRegister(MRecord record) {
65 | String username =record.getStr("username").trim();
66 | String realm = record.getStr("realm").trim();
67 | String nonce= record.getStr("nonce").trim();
68 | String cnonce = record.getStr("cnonce").trim();
69 | String password ="a79352ec7f1946ebaaec2ceb3db64f98";
70 | String nc = record.getStr("nc").trim();
71 | String method = "GET".trim();
72 | String qop = record.getStr("qop").trim();
73 | String uri =record.getStr("uri").trim();
74 | String client_response=record.getStr("response");
75 |
76 | String secret = MMD5.toMD5ByJAVA(username + ":" + realm + ":"+ password);
77 | String A2 = MMD5.toMD5ByJAVA(method + ":" + uri);
78 | String data = nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + A2;// +":"+opaque;
79 | String server_response = MMD5.toMD5ByJAVA(secret + ":" + data);
80 | MPrint.print(client_response.length()+"="+server_response.length());
81 | MPrint.print(client_response+"="+server_response);
82 | return server_response.equals(client_response);
83 | }
84 | public static boolean checkFileExist(String file){
85 | File fpath=new File(file);
86 | return fpath.exists();
87 | }
88 | /**
89 | * 要使用绝对路径
90 | * @param sourceFile
91 | * @param destFile
92 | */
93 | public static void copyFile(String sourceFile,String destFile) {
94 | FileInputStream in =null;
95 | FileOutputStream out =null;
96 | byte[] buffer = new byte[102400];
97 | try {
98 | in = new FileInputStream(sourceFile);
99 | File dest = new File(destFile);
100 | if(!dest.exists()){//目标文件对应的目录不存在,创建新的目录
101 | int index = new String(destFile).lastIndexOf("/");
102 | String path = destFile.substring(0, index);
103 | new File(path).mkdirs();
104 | }
105 | out = new FileOutputStream(destFile);
106 | int num =0;
107 | while((num=in.read(buffer))!=-1){
108 | out.write(buffer,0,num);
109 | }
110 | } catch (Exception e){
111 | Log.me().write_error(e);
112 | } finally{
113 | try {
114 | if(in!=null)in.close();
115 | if(out!=null)out.close();
116 | } catch (IOException ex) {
117 | }
118 | }
119 | }
120 |
121 | public static void main(String[] args){
122 | long startTime =System.currentTimeMillis();
123 | System.out.println("start to copy");
124 | long endTime = System.currentTimeMillis();
125 | long time = (endTime-startTime)/1000;
126 | System.out.println("copy end;cost:"+time);
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/quartz/MCron.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.quartz;
2 |
3 |
4 | import guilinsoft.ddsx.api.G3Manage;
5 | import guilinsoft.ddsx.util.MMsg;
6 | import guilinsoft.ddsx.util.Tools;
7 |
8 | import java.util.List;
9 | import java.util.Map.Entry;
10 |
11 | import org.quartz.Job;
12 | import org.quartz.JobExecutionContext;
13 | import org.quartz.JobExecutionException;
14 |
15 | import com.jzero.db.core.M;
16 | import com.jzero.util.MCheck;
17 | import com.jzero.util.MCnt;
18 | import com.jzero.util.MDate;
19 | import com.jzero.util.MRecord;
20 |
21 | public class MCron implements Job {
22 | /**
23 | * 到期开始的内容:从playtask表读取starttime等于当天的内容导入到playlisttaskitem中,并创建新的xml等待终端读取;
24 | 过期终止的内容:从playtask表读取endtime等于当天的内容taskid->playlisttaskitem中,修改recstate=5,并创建新的xml等待终端读取。
25 | */
26 | public void execute(JobExecutionContext context)
27 | throws JobExecutionException {
28 | insert_starttime();
29 | delete_endtime();
30 |
31 | }
32 |
33 | /**
34 | * 将playlist当天的数据保存进playlistitem表中
35 | * 创建XML
36 | */
37 | private void insert_starttime() {
38 | String today=MDate.getSimpleDateFormat("yyyyMMdd").format(MDate.newDate());
39 | /**
40 | * 2013-4-25:
41 | * 1、将playlisttaskitem中未存在的数据查找出来(为了不重复查询)
42 | */
43 | String check_not_in_playlistitem="SELECT * FROM "+MMsg.TB_PLAYTASK+" WHERE starttime >= '"+today+"' AND approvestatus = 'P' AND STATUS = 'R' AND taskid NOT IN (SELECT taskid FROM "+MMsg.TB_PLAYLISTTASKITEM+" )";
44 | List not_in_playlistLst=M.me().sql(check_not_in_playlistitem);
45 | // List lst=M.me().get_where_n(MMsg.TB_PLAYTASK, MCnt.me().first("starttime",MEnum.GT_E, today).and_eq("approvestatus", "P").and_eq("status", "R").toStr());
46 | if(!MCheck.isNull(not_in_playlistLst)){
47 | //1、插入到playlistitem表中
48 | //2、生成XML
49 | MRecord distinctGroup=new MRecord();
50 | for(MRecord row:not_in_playlistLst){
51 | distinctGroup.set(row.getStr("groupid"), row.getStr("groupid"));
52 | //查找出当前群组下的所有终端
53 | String sql="select t.deviceid from "+MMsg.TB_TERMINAL+" t,"+MMsg.TB_TERMGROUP+" g where g.locationid=t.location and g.groupid='"+row.getStr("groupid")+"'";
54 | List terminalLst=M.me().sql(sql);
55 | if(!MCheck.isNull(terminalLst)){
56 | //查找到资料信息
57 | MRecord contentMR=M.me().one_t_n(MMsg.TB_CONTENT, MCnt.me().and_eq("contentid", row.getStr("contentid")).toStr());
58 | //一些统一信息
59 | MRecord mRecord=new MRecord().set("cid", row.getStr("tasklevel")).set("cname",getFileName(contentMR.getStr("path")))
60 | .set("csize", contentMR.getStr("timelength"))//这个size不算了随便一个值
61 | .set("path", contentMR.getStr("path"))
62 | .set("recvstate", "0")
63 | .set("taskid", row.getStr("taskid"))
64 | .set("url", contentMR.getStr("path"))
65 | .set("type", contentMR.getStr("type"));
66 | for(MRecord terminal:terminalLst){
67 | //2013-4-25:因为前面已经过滤掉了playlisttaskitem中存在的数据,所以在此不用再进行查询判断
68 | // String where=MCnt.me().and_eq("taskid", row.getStr("taskid")).and_eq("terminalid", terminal.getStr("deviceid")).and_eq("path", contentMR.getStr("path")).toStr();
69 | // boolean isExist=M.me().check(MMsg.TB_PLAYLISTTASKITEM, where);
70 | // if(!isExist){
71 | mRecord.set("serialno", Tools.generate_id()).set("terminalid", terminal.getStr("deviceid"));//终端号
72 | M.me().insert(MMsg.TB_PLAYLISTTASKITEM, mRecord);
73 | // }
74 | }
75 | }
76 | }
77 | for(Entry entry: distinctGroup.entrySet()) {
78 | G3Manage.me().releasetask(entry.getKey());
79 | }
80 | }
81 | }
82 | private String getFileName(String path){
83 | return path.substring(path.lastIndexOf("/")+1);
84 | }
85 |
86 | /**
87 | * endtime 超过当天的,则将playlistitem表中的状态改为5
88 | */
89 | private void delete_endtime() {
90 | String today=MDate.getSimpleDateFormat("yyyyMMdd").format(MDate.newDate());
91 | String playtasklistitem_sql="select recvstate,serialno from "+MMsg.TB_PLAYLISTTASKITEM+" where taskid in (select taskid from "+MMsg.TB_PLAYTASK+" where approvestatus = 'p' and ( endtime < '"+today+"' or status = 'C') )";
92 | List lst=M.me().sql(playtasklistitem_sql);
93 | /**
94 | * 1、根据taskid修改playlistitem中的接收状态,改为5(删除)
95 | * 2、重新生成xml文件
96 | */
97 | if(!MCheck.isNull(lst)){
98 | MRecord in=new MRecord();
99 | for(MRecord terminal:lst){
100 | String recvstate=terminal.getStr("recvstate");
101 | if("1".equals(recvstate)){//已经下载下去,将命令改成5
102 | in.set("recvstate", "5");
103 | }else if("0".equals(recvstate)){//还未下载下去,则直接变更为3
104 | in.set("recvstate", "3");
105 | }
106 | String where=MCnt.me().and_eq("serialno", terminal.getStr("serialno")).toStr();
107 | M.me().update(MMsg.TB_PLAYLISTTASKITEM,in, where);
108 | }
109 | //生成XML文件
110 | String playtask_sql="select distinct groupid from "+MMsg.TB_PLAYTASK+" where approvestatus = 'p' and ( endtime < '"+today+"' or status = 'C') ";
111 | List distinctGroup=M.me().sql(playtask_sql);
112 | for(MRecord groupid:distinctGroup){
113 | G3Manage.me().releasetask(groupid.getStr("groupid"));
114 | }
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/api/WdpfImpl.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.api;
2 |
3 | import guilinsoft.ddsx.util.BuilderXml;
4 | import guilinsoft.ddsx.util.MMsg;
5 | import guilinsoft.ddsx.util.Tools;
6 |
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | import com.jzero.cache.C;
11 | import com.jzero.cache.Cache;
12 | import com.jzero.db.core.M;
13 | import com.jzero.util.MCheck;
14 | import com.jzero.util.MCnt;
15 | import com.jzero.util.MPrint;
16 | import com.jzero.util.MRecord;
17 |
18 | public class WdpfImpl implements G3API {
19 | /**
20 | * 根据群组ID,生成当前群组所拥有的资源,在这里生成image.xml,movie.xml,text.xml
21 | */
22 | public void releasetask(String groupId) {
23 | MPrint.print("远程执行:releasetask 方法");
24 | MRecord groupRe=M.me().one_t(MMsg.TB_TERMGROUP,MCnt.me().and_eq("groupid", groupId).toStr());
25 | if(!MCheck.isNull(groupRe)){
26 | generateXML(groupRe, groupId);
27 | }
28 | }
29 |
30 | private void generateXML(MRecord groupRe,String groupId){
31 | //image.xml
32 | List imageLst=M.me().sql(getXmlSql(groupId, "P"));
33 | if(!MCheck.isNull(imageLst)){
34 | BuilderXml.me().xml_image(groupRe, imageLst);
35 | }
36 | //text.xml
37 | List textLst=M.me().sql(getXmlSql(groupId, "W"));
38 | if(!MCheck.isNull(textLst)){
39 | BuilderXml.me().xml_text(groupRe, textLst);
40 | }
41 |
42 | //movie.xml
43 | List movieLst=M.me().sql(getXmlSql(groupId, "V"));
44 | if(!MCheck.isNull(movieLst)){
45 | BuilderXml.me().xml_movie(groupRe, movieLst);
46 | }
47 |
48 | //scrollingtext.xml
49 | List scrollLst=M.me().sql(getXmlSql(groupId, "S"));
50 | if(!MCheck.isNull(scrollLst)){
51 | BuilderXml.me().xml_scrollingtext(groupRe, scrollLst);
52 | }
53 | }
54 |
55 | private String getXmlSql(String groupid,String type){
56 | return "SELECT DISTINCT cname,path FROM playlisttaskitem WHERE EXISTS (SELECT taskid FROM playtask WHERE approvestatus='P' AND groupid='"+groupid+"' AND endtime >=DATE_FORMAT(NOW(),'%Y%m%d')) AND TYPE='"+type+"' and recvstate!=3";
57 | }
58 | /**
59 | * 生成布局模板
60 | */
61 | public boolean saveTemplateToXML(String templateid) {
62 | MPrint.print("远程执行:saveTemplateToXML 方法");
63 | MRecord temlate=M.me().one_t(MMsg.TB_TEMPLATE, MCnt.me().and_eq("templateid", templateid).toStr()); //主模板
64 | List sub_template=M.me().get_where("subtemplate",MCnt.me().first_eq("templateid", templateid).toStr());//子模板
65 | BuilderXml.me().xml_program(temlate,sub_template);
66 | return true;
67 | }
68 | /**
69 | * 群组下广告内容同步到终端 synchroGroupTaskToTerminal
70 | * 生成XML
71 | */
72 | public void importad(String groupId, String terminalid) {
73 | MPrint.print("远程执行:importad 方法");
74 | MRecord groupRe=M.me().one_t(MMsg.TB_TERMGROUP,MCnt.me().and_eq("groupid", groupId).and_eq("templateid", terminalid).toStr());
75 | generateXML(groupRe, groupId);
76 | }
77 | /**
78 | * 终端是否在线 ,返回记录的时间ymd his
79 | * shortnum:设备码,返回最后更新时间
80 | */
81 | public String getselecttime(String deviceId) {
82 | Object device=C.getCacheObj(deviceId);
83 | String reStr=null;
84 | if(!MCheck.isNull(device)){
85 | MRecord mRecord=(MRecord) device;
86 | reStr=mRecord.getStr(MMsg.INFO_UPDATE_TIME);//取更新时间
87 | }
88 | return reStr;
89 | }
90 |
91 | /**
92 | * 按地市统计其下终端的连接壮态 SAByLocation2
93 | * 在这里更新: termstatetemp表,state:0:不在线,1:在线
94 | */
95 | public void orderbystate() {
96 | Map mRecord=C.get();
97 | for (Map.Entry entry : mRecord.entrySet()) {
98 | String k = entry.getKey();
99 | if (k.equals(MMsg.INFO_DEVICEID)) {
100 | Tools.update_termstatetemp(k, 1);
101 | }
102 | }
103 | }
104 | /**
105 | * 修改模板,使用在变更模板的时候
106 | */
107 | public void changeTemplate(String groupid) {
108 | /**
109 | * 在调用此方法之前调用 save_xml(创建主模板)
110 | * 1、根据groupid 从termgroup取出LOCATIONID(区域ID)
111 | * 2、根据locationid(区域ID)从terminal表中取出所有终端(deviceid)
112 | * 3、将deviceid等数据存入playlisttemp中
113 | */
114 | MRecord groupMr=M.me().one_t(MMsg.TB_TERMGROUP,MCnt.me().and_eq("groupid", groupid).toStr());
115 | MRecord resourceMR=M.me().one_t(MMsg.TB_RESOURCE, MCnt.me().and_eq("ftype", "T").and_eq("templateid", groupMr.getStr("templateid")).toStr());
116 | List terminalLst=M.me().get_where(MMsg.TB_TERMINAL, MCnt.me().first_eq("location", groupMr.getStr("locationid")).toStr());
117 | if(!MCheck.isNull(terminalLst)){
118 | String path=resourceMR.getStr("path")+"/program.xml";
119 | String imgpath=resourceMR.getStr("path")+"/"+resourceMR.getStr("fimg");
120 | /**
121 | * 在这里,我将taskid保存 图片的名称
122 | * 将url保存图片的地址
123 | */
124 | MRecord playlistMr=new MRecord().set("cname", "program.xml").set("recvstate", MMsg.TEMPLATE_COMMEND).set("type", "T").set("path",path).set("url", imgpath).set("taskid", resourceMR.getStr("fimg"));
125 | String where=null;
126 | for(MRecord row:terminalLst){
127 | //判断表中是否有数据,有则不插入
128 | where=MCnt.me().and_eq("cname", "program.xml").and_eq("path", path).and_eq("terminalid", row.getStr("deviceid")).and_eq("recvstate", MMsg.TEMPLATE_COMMEND).toStr();
129 | boolean isExist=M.me().check(MMsg.TB_PLAYLISTTASKITEM, where);
130 | if(!isExist){//不存在则插入
131 | playlistMr.set("serialno", Tools.generate_id()).set("terminalid", row.getStr("deviceid")).set("cid", "0").set("csize", 1);
132 | M.me().insert(MMsg.TB_PLAYLISTTASKITEM, playlistMr);
133 | }
134 | }
135 | }
136 |
137 | //2013-4-11:只需要下发主模板,program.xml,其它文件在有新资源时会自动生成.
138 | /**
139 | *
140 | //生成子模板
141 | List subTemplate=M.me().get_where(MMsg.TB_SUBTEMPLATE, MCnt.me().first_eq("templateid", groupMr.getStr("templateid")).toStr());
142 | if(!MCheck.isNull(subTemplate)){
143 | for(MRecord row:subTemplate){
144 | build_subtemplate(groupMr,row);
145 | }
146 | }
147 | **/
148 | }
149 | /**
150 | //读取文件类型
151 | private void build_subtemplate(MRecord groupRe,MRecord record){
152 | String type=record.getStr("type");
153 | if(type.equalsIgnoreCase("V")){ //视频
154 | BuilderXml.me().xml_movie(groupRe, null);
155 | }else if(type.equalsIgnoreCase("P")){ //图片
156 | BuilderXml.me().xml_image(groupRe, null);
157 | }else if(type.equalsIgnoreCase("W")){ //文本
158 | BuilderXml.me().xml_text(groupRe, null);
159 | }else if(type.equalsIgnoreCase("S")){ //滚动文本
160 | BuilderXml.me().xml_scrollingtext(groupRe, null);
161 | }
162 | }**/
163 | public static void main(String[] args) {
164 | WdpfImpl impl=new WdpfImpl();
165 | String groupid="03";
166 | impl.changeTemplate(groupid);
167 | }
168 |
169 | /*********************暂时还未用到***************************/
170 |
171 |
172 | public String crossValidation(String groupid, String playlistid,
173 | String startDate, String endDate) {
174 | MPrint.print("调用 crossValidation 方法");
175 | return "OK";
176 | }
177 |
178 |
179 |
180 | public void release(String playlistId) {
181 | MPrint.print("调用 release 方法");
182 | Map mRecord=C.get();
183 | for (Map.Entry entry : mRecord.entrySet()) {
184 | String k = entry.getKey();
185 | MPrint.print("name = "+k+", and value = "+entry.getValue().getValue());
186 | }
187 | }
188 |
189 | public boolean timeLineReleasetask(String groupid) {
190 | MPrint.print("调用 timeLineReleasetask 方法");
191 | return false;
192 | }
193 |
194 |
195 |
196 |
197 | }
198 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/util/BuilderXml.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.util;
2 |
3 | import java.io.FileWriter;
4 | import java.util.List;
5 |
6 | import org.dom4j.Document;
7 | import org.dom4j.DocumentHelper;
8 | import org.dom4j.Element;
9 | import org.dom4j.io.OutputFormat;
10 | import org.dom4j.io.XMLWriter;
11 |
12 | import com.jzero.db.cache.MFile;
13 | import com.jzero.db.core.M;
14 | import com.jzero.upload.MDown;
15 | import com.jzero.util.MCheck;
16 | import com.jzero.util.MCnt;
17 | import com.jzero.util.MPath;
18 | import com.jzero.util.MRecord;
19 | import com.jzero.util.MTool;
20 |
21 | /**
22 | * 成生XML模板
23 | */
24 | public class BuilderXml {
25 | private BuilderXml() {
26 | }
27 |
28 | private static BuilderXml xml = new BuilderXml();
29 |
30 | public static BuilderXml me() {
31 | return xml;
32 | }
33 | /***********************************************************布局文件XML开始******************************************************/
34 | /**
35 | * 布局文件,主在项目
36 | * @param subTemplate
37 | */
38 | public synchronized void xml_program(MRecord row, List subTemplate) {
39 | Document doc=DocumentHelper.createDocument();
40 |
41 | Element root=doc.addElement("program").addAttribute("id", Tools.generate_id()).addAttribute("issue", "G3media").addAttribute("templateid", row.getStr("templateid")).addAttribute("starttime", "20100101").addAttribute("endtime", "20991010");
42 | Element view=root.addElement("view").addAttribute("background",getFileName(row.getStr("path"))).addAttribute("width", row.getStr("width")).addAttribute("height", row.getStr("height"));
43 | Element viewport=null;//"bg.png"
44 | String type_name = null;
45 | String xywh[]=null;
46 | if(!MCheck.isNull(subTemplate)){
47 | for(MRecord record:subTemplate){
48 | type_name=get_type_name(record);//读取文件类型
49 | xywh=get_XYWH(record.getStr("position"));////读取坐标
50 | viewport=view.addElement("viewport").addAttribute("id", Tools.generate_id()).addAttribute("type", type_name).addAttribute("mpl", record.getStr("mplname"));
51 | viewport.addElement("layout").addAttribute("x", MTool.get(xywh, 0)).addAttribute("y", MTool.get(xywh, 1)).addAttribute("width", MTool.get(xywh, 2)).addAttribute("height", MTool.get(xywh, 3));
52 | }
53 | }
54 | save_root_xml(row,doc);
55 | }
56 | /**
57 | * 保存布局文件
58 | * @throws Exception
59 | */
60 | private void save_root_xml(MRecord tempRe,Document doc){
61 | //保存格式: xml/templateid/..xml
62 | String tempateid=tempRe.getStr("templateid");
63 | String path="/xml/"+tempateid;
64 | String filename ="program.xml";
65 | String full_path=MFile.createFile(MPath.me().getWebRoot()+path,"program.xml").getPath();
66 | builder(full_path,doc);//寫入XML
67 |
68 | String imgUrl = Tools.getTargetBase()+"/"+tempRe.getStr("path");
69 | String imagename =getFileName(imgUrl);
70 | full_path=MFile.createFile(MPath.me().getWebRoot()+path,imagename).getPath();
71 | try {
72 | MDown.saveUrlAs(imgUrl,full_path);
73 | } catch (Exception e) {
74 | e.printStackTrace();
75 | }//保存圖片
76 |
77 | //保存到表中
78 | MRecord inData=new MRecord().set("templateid", tempateid).set("path", path).set("ftype", "T").set("name", filename).set("fimg", imagename);
79 | String where=MCnt.me().and_eq("templateid", tempateid).and_eq("name",filename ).and_eq("ftype", "T").and_eq("fimg",imagename).toStr();
80 | insert(inData,where);
81 | }
82 | //读取坐标
83 | private String[] get_XYWH(String position){
84 | return position.split(",");
85 | }
86 |
87 | //读取文件类型
88 | private String get_type_name(MRecord record){
89 | String type_name = null;
90 | String type=record.getStr("type");
91 | if(type.equalsIgnoreCase("V")){ //视频
92 | type_name="video";
93 | }else if(type.equalsIgnoreCase("P")){ //图片
94 | type_name="image";
95 | }else if(type.equalsIgnoreCase("W")){ //文本
96 | type_name="text";
97 | }else if(type.equalsIgnoreCase("S")){ //滚动文本
98 | type_name="scrollingtext";
99 | }
100 | return type_name;
101 | }
102 | /***********************************************************布局文件XML结束******************************************************/
103 |
104 |
105 | /***********************************************************其它XML开始**********************************************************/
106 | /**
107 | * 图片xml
108 | */
109 | public synchronized void xml_image(MRecord groupRe,List imageLst) {
110 | Document doc=DocumentHelper.createDocument();
111 |
112 | Element root=doc.addElement("mpl").addAttribute("id", Tools.generate_id()).addAttribute("type", "image");
113 | Element seq=root.addElement("seq").addAttribute("id", Tools.generate_id()).addAttribute("starttime", "0000").addAttribute("endtime", "2359");
114 | if(!MCheck.isNull(imageLst)){
115 | for(MRecord row:imageLst){
116 | seq.addElement("media").addAttribute("id", Tools.generate_id()).addAttribute("name", row.getStr("cname")).addAttribute("src", getFileName(row.getStr("path")));
117 | }
118 | }
119 | save_xml(groupRe,"image.xml",doc);
120 | }
121 |
122 | /**
123 | * 静态文字
124 | */
125 | public synchronized void xml_text(MRecord groupRe,List textLst) {
126 | Document doc=DocumentHelper.createDocument();
127 |
128 | Element root=doc.addElement("mpl").addAttribute("id", Tools.generate_id()).addAttribute("type", "text");
129 | Element seq=root.addElement("seq").addAttribute("id", Tools.generate_id()).addAttribute("starttime", "0000").addAttribute("endtime", "2359");
130 | if(!MCheck.isNull(textLst)){
131 | for(MRecord row:textLst){
132 | seq.addElement("media").addAttribute("id", Tools.generate_id()).addAttribute("name", row.getStr("cname")).addAttribute("src", getFileName(row.getStr("path")));
133 | }
134 | }
135 | save_xml(groupRe,"text.xml",doc);
136 | }
137 |
138 | /**
139 | * 滚动文字
140 | */
141 | public synchronized void xml_scrollingtext(MRecord groupRe,List scrollLst) {
142 | Document doc=DocumentHelper.createDocument();
143 |
144 | Element root=doc.addElement("mpl").addAttribute("id", Tools.generate_id()).addAttribute("type", "scrollingtext");
145 | Element seq=root.addElement("seq").addAttribute("id", Tools.generate_id()).addAttribute("starttime", "0000").addAttribute("endtime", "2359");
146 | if(!MCheck.isNull(scrollLst)){
147 | for(MRecord row:scrollLst){
148 | seq.addElement("media").addAttribute("id", Tools.generate_id()).addAttribute("name", row.getStr("cname")).addAttribute("src", getFileName(row.getStr("path")));
149 | }
150 | }
151 | save_xml(groupRe,"scrollingtext.xml",doc);
152 | }
153 |
154 | /**
155 | * 视频xml
156 | */
157 | public synchronized void xml_movie(MRecord groupRe,List movieLst) {
158 | Document doc=DocumentHelper.createDocument();
159 |
160 | Element root=doc.addElement("mpl").addAttribute("id", Tools.generate_id()).addAttribute("type", "video");
161 | Element seq=root.addElement("seq").addAttribute("id", Tools.generate_id()).addAttribute("starttime", "0000").addAttribute("endtime", "2359");
162 | if(!MCheck.isNull(movieLst)){
163 | for(MRecord row:movieLst){
164 | seq.addElement("media").addAttribute("id", Tools.generate_id()).addAttribute("name", row.getStr("cname")).addAttribute("src", getFileName(row.getStr("path")));
165 | }
166 | }
167 | save_xml(groupRe,"movie.xml",doc);
168 | }
169 | /***********************************************************其它XML结束**********************************************************/
170 |
171 |
172 | /***********************************************************帮助方法开始**********************************************************/
173 | private String save_xml(MRecord groupRe,String filename,Document doc){
174 | //保存格式: xml/templateid/groupid/..xml
175 | String tempateid=groupRe.getStr("templateid");
176 | String groupid=groupRe.getStr("groupid");
177 | String path="/xml/"+tempateid+"/"+groupid;
178 | String full_path=MFile.createFile(MPath.me().getWebRoot()+path,filename).getPath();
179 | builder(full_path,doc);
180 |
181 | //保存到表中
182 | MRecord inData=new MRecord().set("templateid", tempateid).set("groupid", groupid).set("path", path).set("name", filename);
183 | if(filename.equals("movie.xml")){
184 | inData.set("ftype", "V");
185 | }else if(filename.equals("scrollingtext.xml")||filename.equals("text.xml")){
186 | inData.set("ftype", "W");
187 | }else if(filename.equals("image.xml")){
188 | inData.set("ftype", "P");
189 | }
190 |
191 | String where=MCnt.me().and_eq("templateid", tempateid).and_eq("groupid", groupid).and_eq("name",filename ).toStr();
192 | insert(inData,where);
193 | return full_path;
194 | }
195 | private String getFileName(String path){
196 | return path.substring(path.lastIndexOf("/")+1);
197 | }
198 | private void insert(MRecord inData,String where){
199 | boolean exist=M.me().check(MMsg.TB_RESOURCE, where);
200 | if(!exist){
201 | M.me().insert(MMsg.TB_RESOURCE, inData.set("id", Tools.generate_id()));
202 | }
203 | }
204 | /**
205 | * @param filepath 文件保存的路径
206 | * @param document 创建的文档
207 | */
208 | private void builder(String filepath, Document doc) {
209 | try {
210 | XMLWriter writer = new XMLWriter(new FileWriter(filepath));
211 | writer.write(doc);
212 | writer.close();
213 | printXML(doc);
214 | } catch (Exception e) {
215 | e.printStackTrace();
216 | }
217 | }
218 |
219 | private void printXML(Document doc) {
220 | // 设置了打印的格式,将读出到控制台的格式进行美化
221 | try {
222 | OutputFormat format = OutputFormat.createPrettyPrint();
223 | XMLWriter writer = new XMLWriter(System.out, format);
224 | writer.write(doc);
225 | } catch (Exception e) {
226 | e.printStackTrace();
227 | }
228 | }
229 | /***********************************************************帮助方法结束**********************************************************/
230 |
231 |
232 | }
233 |
--------------------------------------------------------------------------------
/src/guilinsoft/ddsx/action/Tasks.java:
--------------------------------------------------------------------------------
1 | package guilinsoft.ddsx.action;
2 | import guilinsoft.ddsx.core.MHttpServlet;
3 | import guilinsoft.ddsx.util.MMsg;
4 | import guilinsoft.ddsx.util.Tools;
5 |
6 | import java.io.BufferedWriter;
7 | import java.io.IOException;
8 | import java.io.OutputStreamWriter;
9 | import java.util.HashMap;
10 | import java.util.List;
11 | import java.util.Map;
12 |
13 | import javax.servlet.ServletException;
14 | import javax.servlet.http.HttpServletRequest;
15 | import javax.servlet.http.HttpServletResponse;
16 |
17 | import com.jzero.cache.C;
18 | import com.jzero.db.core.M;
19 | import com.jzero.log.Log;
20 | import com.jzero.util.MCheck;
21 | import com.jzero.util.MMD5;
22 | import com.jzero.util.MPrint;
23 | import com.jzero.util.MRecord;
24 |
25 |
26 | public class Tasks extends MHttpServlet {
27 | private static final long serialVersionUID = 1L;
28 | @Override
29 | protected void service(HttpServletRequest req, HttpServletResponse resp)
30 | throws ServletException, IOException {
31 | begin(req);
32 | String cacheKey=getDeviceid()+MMsg.INFO_REGETAD;
33 | Object regetad=C.getCacheObj(cacheKey);
34 | if(!MCheck.isNull(regetad)){
35 | replayAll(resp);//格式化,下发所有数据
36 | C.setCache(null, cacheKey);
37 | MPrint.print("------格式化操作.");
38 | }else{
39 | replay(resp);//针对性下发.
40 | MPrint.print("-----非格式化");
41 | }
42 | end();
43 | }
44 | //下发所有资源文件与XML
45 | private void replayAll(HttpServletResponse resp) {
46 | try{
47 | //xml资源文件
48 | String xml_sql="SELECT path,name,fimg FROM "+MMsg.TB_RESOURCE+" m,(SELECT g.groupid,g.templateid FROM "+MMsg.TB_TERMINAL+" t,"+MMsg.TB_TERMGROUP+" g WHERE t.location=g.locationid AND deviceid='"+getDeviceid()+"') b WHERE m.templateid=b.templateid AND ( m.groupid=b.groupid or m.fimg is not null)";
49 | //文件资源文件(因为模板 (T)没有terminalid ,所以检索不出)
50 | String resource_sql="SELECT distinct serialno,taskid ,cname,recvstate,csize,url FROM "+MMsg.TB_PLAYLISTTASKITEM+" WHERE terminalid = '"+getDeviceid()+"' AND (recvstate = '"+MMsg.ADD_COMMEND+"' OR recvstate='"+MMsg.ADD_COMMENDED+"')";
51 | List xml_lst=M.me().sql(xml_sql);
52 | List resource_lst=M.me().sql(resource_sql);
53 | int count=xml_lst.size()+resource_lst.size()+1;
54 | //XML 内容
55 | StringBuilder body=new StringBuilder();
56 | body.append("")
57 | .append("")
58 | .append(""+count+"")
59 | .append("06")
60 | .append(""+Tools.generate_id()+"")
61 | .append("901")
62 | .append("20991230093129")
63 | .append("");
64 | //循环xml 资源文件
65 | if(!MCheck.isNull(xml_lst)){
66 | for(MRecord xml:xml_lst){
67 | body.append("")
68 | .append(""+Tools.generate_id()+"")//因为是下载所有数据,所以有些模板文件不存在数据库中,所以这里不对cid进行处理
69 | .append(""+xml.getStr("name")+"")
70 | .append("0")//0:下载, 1:删除
71 | .append("2")//mpl
72 | .append(""+Tools.getBase()+xml.getStr("path")+"/"+xml.getStr("name")+"")
73 | .append("200")
74 | .append("");
75 | if(!MCheck.isNull(xml.getStr("fimg"))){//不為空,說明是主模板的圖片
76 | body.append("")
77 | .append(""+Tools.generate_id()+"")
78 | .append(""+xml.getStr("fimg")+"")
79 | .append("0")//0:下载, 1:删除
80 | .append("1")//img
81 | .append(""+Tools.getBase()+xml.getStr("path")+"/"+xml.getStr("fimg")+"")
82 | .append("200")
83 | .append("");
84 | }
85 | }
86 | }
87 | //循环显示文件
88 | if(!MCheck.isNull(resource_lst)){
89 | for(MRecord row:resource_lst){
90 | String name=row.getStr("cname");
91 | body.append("")
92 | .append(""+row.getStr("serialno")+"")
93 | .append(""+name+"");//video/"+name+"
94 | if(row.getInt("recvstate")==5){//0:新增,5:删除
95 | body.append("1"); //0:下载, 1:删除
96 | }else{
97 | body.append("0");
98 | }
99 | body.append("1")//"+ext+"
100 | .append(""+row.getStr("csize")+"")
101 | .append(""+Tools.getTargetBase()+"/"+row.getStr("url")+"")
102 | .append("");
103 | }
104 | }
105 | body.append("");
106 | body.append("");
107 | body.append("");
108 | String au = "qop=\"auth-int\",nextnonce=\"" + MMD5.toMD5ByJAVA(System.currentTimeMillis()+"")+ "\",rspauth=\"" + MMD5.toMD5ByJAVA(System.nanoTime()+"") + "\" nc="+getNc()+" cnonce="+getCnonce();
109 | resp.setStatus(HttpServletResponse.SC_OK);
110 | resp.setHeader("Authentication-Info", au);
111 | BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(resp.getOutputStream()));
112 | bw.write("");
113 | bw.write(body.toString());
114 | bw.flush();
115 | bw.close();
116 | MPrint.print("XML:"+body.toString());
117 | Log.me().write("XML:"+body.toString());
118 | //2013-7-26:交给status类处理
119 | // if(!MCheck.isNull(resource_lst)){
120 | // M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", 1).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("terminalid", getDeviceid()).and_eq("recvstate", MMsg.ADD_COMMEND).toStr());
121 | // M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", 3).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("terminalid", getDeviceid()).and_eq("recvstate", MMsg.DEL_COMMEND).toStr());
122 | // }
123 | }catch(Exception e){
124 | e.printStackTrace();
125 | }
126 | }
127 | /**
128 | * ctype ==1 ======> vcache 资源文件
129 | ctype ==2 ======> cache XML
130 | ctype ==其它 ====> web
131 | */
132 | private Map getTaskItem(){
133 | Map xmlMap=new HashMap();
134 | StringBuilder body=new StringBuilder();
135 | body.append("06")
136 | .append(""+Tools.generate_id()+"")
137 | .append("901")
138 | .append("20991230093129")
139 | .append("");
140 | //根据终端取出群组与模板,再从m_resource中取出它的xml文件路径
141 | /**
142 | * 1、取出所有增加与删除指令
143 | * 2、取出未下载的模板指令
144 | */
145 | // String sql="SELECT path,name,fimg,ftype FROM m_resource m,(SELECT g.groupid,g.templateid FROM terminal t,termgroup g WHERE t.location=g.locationid AND deviceid='"+getDeviceid()+"') b WHERE m.templateid=b.templateid AND m.ftype IN (SELECT TYPE FROM playlisttaskitem WHERE (terminalid ='"+getDeviceid()+"' AND (recvstate = '"+MMsg.ADD_COMMEND+"' OR recvstate = '"+MMsg.DEL_COMMEND+"' )) OR (m.groupid is null and terminalid in ( SELECT g.templateid FROM terminal t,termgroup g WHERE t.location = g.locationid AND deviceid = '"+getDeviceid()+"')))";
146 | String sql="SELECT path,name,fimg,ftype FROM m_resource m,(SELECT g.groupid,g.templateid FROM terminal t,termgroup g WHERE t.location=g.locationid AND deviceid='"+getDeviceid()+"') b WHERE m.templateid=b.templateid AND m.groupid=b.groupid AND m.ftype IN (SELECT distinct type FROM playlisttaskitem WHERE (terminalid ='"+getDeviceid()+"' AND (recvstate = '"+MMsg.ADD_COMMEND+"' OR recvstate = '"+MMsg.DEL_COMMEND+"' )))";
147 | List xmlLst=M.me().sql(sql);
148 | int size=0;
149 | if(!MCheck.isNull(xmlLst)){
150 | for(MRecord xml:xmlLst){
151 | String name=xml.getStr("name");
152 | if("program.xml".equals(name)){//如果是主模板,因为它带有图片,所以需要+1;
153 | size=1;
154 | }
155 | body.append("")
156 | .append(""+Tools.generate_id()+"")
157 | .append(""+xml.getStr("name")+"")
158 | .append("0")//0:下载, 1:删除
159 | .append("2")//mpl
160 | .append(""+Tools.getBase()+xml.getStr("path")+"/"+xml.getStr("name")+"")
161 | .append("200")
162 | .append("");
163 | }
164 | size+=xmlLst.size();
165 | xmlMap.put("size", size+"");
166 | }
167 | xmlMap.put("body", body.toString());
168 | return xmlMap;
169 | }
170 | /**
171 | * 视频文件进行断点续传
172 | * @param resp
173 | */
174 | private void replay(HttpServletResponse resp){
175 | try{
176 | //模板更换后需要下载的资源
177 | // List template_lst=M.me().get_data("", table, where, orderStr).get_where(MMsg.TB_PLAYLISTTASKITEM, MCnt.me().first_eq("type", "T").and_eq("recvstate", MMsg.TEMPLATE_COMMEND).and_eq("terminalid", getDeviceid()).toStr());
178 | List template_lst=M.me().sql("SELECT distinct serialno,path,url,taskid FROM playlisttaskitem WHERE TYPE='T' AND recvstate='"+MMsg.TEMPLATE_COMMEND+"' AND terminalid='"+getDeviceid()+"'");
179 | //未下载的资源文件 taskid ,
180 | String sql="SELECT distinct serialno,cname,recvstate,csize,url FROM "+MMsg.TB_PLAYLISTTASKITEM+" WHERE terminalid = '"+getDeviceid()+"' AND (recvstate = '"+MMsg.ADD_COMMEND+"' OR recvstate = '"+MMsg.DEL_COMMEND+"')";
181 | List lst=M.me().sql(sql);
182 | Map xmlMap=getTaskItem();//有问题
183 | int count=lst.size()+Integer.parseInt(xmlMap.get("size"));//资源文件+xml文件
184 | if(!MCheck.isNull(template_lst)){//当更换模板后
185 | count=count+2;
186 | }
187 | StringBuilder sb=new StringBuilder();
188 | sb.append("")
189 | .append("")
190 | .append(""+count+"")
191 | .append(xmlMap.get("body"));
192 | if(!MCheck.isNull(template_lst)){
193 | //循环更换模板后的资源
194 | for(MRecord row:template_lst){
195 | /**
196 | * 如果是每个终端对应一个模板,则可以选择 ftype="T" and recevid=7(未接收) TEST
197 | */
198 | // if(row.getStr("type").equals("T")){//不為空,說明是主模板的圖片
199 | sb.append("")
200 | .append(""+row.getStr("serialno")+"")
201 | .append("program.xml")
202 | .append("0")//0:下载, 1:删除
203 | .append("2")//mpl
204 | .append(""+Tools.getBase()+row.getStr("path")+"")
205 | .append("200")
206 | .append("");
207 | if(!MCheck.isNull(row.getStr("url"))){//不為空,說明是主模板的圖片
208 | sb.append("")
209 | .append(""+Tools.generate_id()+"")
210 | .append(""+row.getStr("taskid")+"")//哈哈,这里看不懂taskid了吧,我在changeTemplate时将taskid保存着图片的名称,将url保存着图片的路径
211 | .append("0")//0:下载, 1:删除
212 | .append("1")//img
213 | .append(""+Tools.getBase()+row.getStr("url")+"")
214 | .append("200")
215 | .append("");
216 | }
217 | }
218 | }
219 | // }else{
220 | //Foreach循环资源
221 | if(!MCheck.isNull(lst)){
222 | for(MRecord row:lst){
223 | sb.append("")
224 | .append(""+row.getStr("serialno")+"")
225 | .append(""+row.getStr("cname")+"");//video/"+name+"
226 | if(row.getInt("recvstate")==5){//0:新增,5:删除
227 | sb.append("1"); //0:下载, 1:删除
228 | }else{
229 | sb.append("0");
230 | }
231 | sb.append("1")//"+ext+"
232 | .append(""+row.getStr("csize")+"");
233 | // if(row.getStr("type").equalsIgnoreCase("V")){//如果是视频文件,则要求续传
234 | // sb.append(""+Tools.getBase()+"/content?serialno="+row.getStr("serialno")+"");
235 | // }else{
236 | sb.append(""+Tools.getTargetBase()+"/"+row.getStr("url")+"");
237 | // }
238 |
239 | sb.append("");
240 | }
241 | }
242 | sb.append("");
243 | sb.append("");
244 | sb.append("");
245 | String au = "qop=\"auth-int\",nextnonce=\"" + MMD5.toMD5ByJAVA(System.currentTimeMillis()+"")+ "\",rspauth=\"" + MMD5.toMD5ByJAVA(System.nanoTime()+"") + "\" nc="+getNc()+" cnonce="+getCnonce();
246 | resp.setStatus(HttpServletResponse.SC_OK);
247 | resp.setHeader("Authentication-Info", au);
248 | BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(resp.getOutputStream()));
249 | bw.write("");
250 | bw.write(sb.toString());
251 | bw.flush();
252 | bw.close();
253 | MPrint.print("XML:"+sb.toString());
254 | Log.me().write("XML:"+sb.toString());
255 | // if(!MCheck.isNull(lst)){
256 | // M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", MMsg.ADD_COMMENDED).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("terminalid", getDeviceid()).and_eq("recvstate", MMsg.ADD_COMMEND).toStr());
257 | // M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", MMsg.DEL_ED_COMMEND).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("terminalid", getDeviceid()).and_eq("recvstate", MMsg.DEL_COMMEND).toStr());
258 | // }
259 | // if(!MCheck.isNull(template_lst)){
260 | // M.me().update(MMsg.TB_PLAYLISTTASKITEM, new MRecord().set("recvstate", MMsg.TEMPLATE_ED_COMMEND).set("recvtime", MDate.get_ymd_hms_join()), MCnt.me().first_eq("terminalid", getDeviceid()).and_eq("recvstate", MMsg.TEMPLATE_COMMEND).toStr());
261 | // }
262 | }catch(Exception e){
263 | e.printStackTrace();
264 | }
265 | }
266 | }
267 |
--------------------------------------------------------------------------------