Browse Source

Merge branch 'hejq-hotfix-20180913' of ssh://10.10.101.21/source/platform-b2b into hotfix-txcloud-0919

hejq 7 years ago
parent
commit
5da7dbf7ae

+ 5 - 0
src/main/java/com/uas/platform/b2b/core/util/DateFormatUtils.java

@@ -24,4 +24,9 @@ public class DateFormatUtils {
      */
 	public static final FastDateFormat EXPORT_FORMAT = FastDateFormat.getInstance("yyyy年MM月dd日");
 
+    /**
+     * yyyy-MM-dd 00:00:00 每天凌晨
+     */
+    public static final FastDateFormat WEE_HOURS_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd 00:00:00");
+
 }

+ 17 - 0
src/main/java/com/uas/platform/b2b/core/util/DateUtils.java

@@ -209,4 +209,21 @@ public class DateUtils {
 	public static Integer addMonth(String date, int increase) {
 		return addMonth(parse(date, null), increase);
 	}
+
+    /**
+     * 天数加减
+     *
+     * @param date 传入日期
+     * @param increase 加减天数,负数表示减
+     * @return 处理后的日期
+     */
+    public static Date addDay(Date date, int increase) {
+        if (date == null) {
+            date = new Date();
+        }
+        Calendar calendar = new GregorianCalendar();
+        calendar.setTime(date);
+        calendar.add(Calendar.DATE, increase);
+        return calendar.getTime();
+    }
 }

+ 14 - 0
src/main/java/com/uas/platform/b2b/support/SysConf.java

@@ -70,6 +70,12 @@ public class SysConf {
 	@Value("#{sys.inquiryServiceUrl}")
 	private String inquiryServiceUrl;
 
+    /**
+     * 文件服务器的地址
+     */
+    @Value("#{sys.dfsFileUrl}")
+    private String dfsFileUrl;
+
     public String getRegisterUrl() {
         return registerUrl;
     }
@@ -149,4 +155,12 @@ public class SysConf {
 	public void setInquiryServiceUrl(String inquiryServiceUrl) {
 		this.inquiryServiceUrl = inquiryServiceUrl;
 	}
+
+    public String getDfsFileUrl() {
+        return dfsFileUrl;
+    }
+
+    public void setDfsFileUrl(String dfsFileUrl) {
+        this.dfsFileUrl = dfsFileUrl;
+    }
 }

+ 57 - 14
src/main/java/com/uas/platform/b2b/task/ErrorLogTask.java

@@ -1,10 +1,16 @@
 package com.uas.platform.b2b.task;
 
+import com.uas.platform.b2b.core.util.DateFormatUtils;
+import com.uas.platform.b2b.core.util.DateUtils;
+import com.uas.platform.b2b.dao.CommonDao;
+import com.uas.platform.b2b.dao.CommunalLogDao;
+import com.uas.platform.b2b.model.CommunalLog;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.util.Date;
+
 
 /**
  * 系统日志任务
@@ -17,25 +23,62 @@ import org.springframework.stereotype.Component;
 public class ErrorLogTask {
 
     @Autowired
-    private JdbcTemplate jdbcTemplate;
+    private CommonDao commonDao;
+
+    @Autowired
+    private CommunalLogDao communalLogDao;
 
     /**
      * 每天凌晨0点到2点开始执行
      */
     @Scheduled(cron = "0 0/5 0,1,2 * * ? ")
     public void deleteLogs() {
+        int increase = -2;
+        // 两天前时间
+        Date date = DateUtils.addDay(new Date(), increase);
+
+        // 整点格式
+        String dateString = DateFormatUtils.WEE_HOURS_FORMAT.format(date);
+
         // 先查询最大id
-        Long maxId = jdbcTemplate.queryForObject("select max(log_id) from log$error where date_format(log_date, '%Y-%m-%d') <= date_format(date_add(now(), interval -2 day), '%Y-%m-%d')", Long.class);
-
-        // 删除日志明细
-        jdbcTemplate.execute("delete from log$error$detail where log_logid in (select log_id from log$error " +
-                "where log_logid <= " + maxId + " limit 10000");
-        // 删除日志主表信息
-        jdbcTemplate.execute("delete from log$error " +
-                "where log_id <= " + maxId + " limit 10000");
-        // 删除单据记录
-        jdbcTemplate.execute("delete from erp$orders where date_format(or_date, '%Y-%m-%d') <= date_format(date_add(now(), interval -2 day), '%Y-%m-%d') limit 10000");
-        // 删除物料记录
-        jdbcTemplate.execute("delete from erp$products where date_format(pr_date, '%Y-%m-%d') <= date_format(date_add(now(), interval -2 day), '%Y-%m-%d') limit 10000");
+        Long maxId = commonDao.queryForObject("select max(log_id) from log$error where log_date <= ?",  Long.class, dateString);
+
+        if (null != maxId) {
+            // 删除日志明细
+            commonDao.getJdbcTemplate().execute("delete from log$error$detail where log_logid <= " + maxId + " limit 10000");
+
+            // 删除日志主表信息
+            commonDao.getJdbcTemplate().execute("delete from log$error " + "where log_id <= " + maxId + " limit 10000");
+
+            CommunalLog log = new CommunalLog();
+            log.setTitle("删除B2B异常日志");
+            log.setMessage("最大id" + maxId);
+            log.setTime(System.currentTimeMillis());
+            communalLogDao.save(log);
+        }
+
+        Long maxOrderId = commonDao.queryForObject("select max(or_id) from erp$orders where or_date <= ?",  Long.class, dateString);
+
+        if (null != maxOrderId) {
+            // 删除单据记录
+            commonDao.getJdbcTemplate().execute("delete from erp$orders where or_id <= " + maxOrderId + " limit 10000");
+            CommunalLog log = new CommunalLog();
+            log.setTitle("删除ERP不存在单据记录");
+            log.setMessage("最大id" + maxOrderId);
+            log.setTime(System.currentTimeMillis());
+            communalLogDao.save(log);
+        }
+
+        Long maxProductId = commonDao.queryForObject("select max(pr_id) from erp$products where pr_date <= ?",  Long.class, dateString);
+
+        if (null != maxProductId) {
+            // 删除物料记录
+            commonDao.getJdbcTemplate().execute("delete from erp$products where pr_id <= " + maxProductId + " limit 10000");
+            CommunalLog log = new CommunalLog();
+            log.setTitle("删除ERP不存在物料记录");
+            log.setMessage("最大id" + maxProductId);
+            log.setTime(System.currentTimeMillis());
+            communalLogDao.save(log);
+        }
     }
 }

+ 14 - 5
src/main/java/com/uas/platform/b2b/temporary/model/FileUrl.java

@@ -1,5 +1,9 @@
 package com.uas.platform.b2b.temporary.model;
 
+
+import com.uas.platform.b2b.core.util.ContextUtils;
+import com.uas.platform.b2b.support.SysConf;
+
 /**
  * 文件服务器的基本链接
  *
@@ -7,29 +11,34 @@ package com.uas.platform.b2b.temporary.model;
  */
 public class FileUrl {
 
+    /**
+     * 文件服务器地址
+     */
+    private static final String DFS_FILE_URL = ContextUtils.getBean(SysConf.class).getDfsFileUrl();
+    
     /**
      * 文件上传
      */
-    public final static String FILE_UPLOAD = "http://10.10.100.200:9999/file/upload";
+    public final static String FILE_UPLOAD = DFS_FILE_URL + "/file/upload";
 
 
     /**
      * 文件下载
      */
-    public final static String FILE_DOWNLOAD = "http://10.10.100.200:9999/file/download";
+    public final static String FILE_DOWNLOAD = DFS_FILE_URL + "/file/download";
 
     /**
      * 文件删除
      */
-    public final static String FILE_DELETE = "http://10.10.100.200:9999/file/delete";
+    public final static String FILE_DELETE = DFS_FILE_URL + "/file/delete";
 
     /**
      * 文件信息
      */
-    public final static String FILE_INFO = "http://10.10.100.200:9999/file/info";
+    public final static String FILE_INFO = DFS_FILE_URL + "/file/info";
 
     /**
      * 文件额外属性
      */
-    public final static String FILE_METADATA = "http://10.10.100.200:9999/file/metadata";
+    public final static String FILE_METADATA = DFS_FILE_URL + "/file/metadata";
 }

+ 4 - 1
src/main/resources/dev/sys.properties

@@ -20,4 +20,7 @@ inquiryServiceUrl=http://218.17.158.219:24000/
 messageServiceIp=http://message.ubtob.com/
 
 #search url
-searchUrl=http://10.10.100.191:8081
+searchUrl=http://10.10.100.191:8081
+
+#dfs file url
+dfsFileUrl=http://10.10.100.200:9999

+ 4 - 1
src/main/resources/prod/sys.properties

@@ -20,4 +20,7 @@ inquiryServiceUrl=https://api-inquiry.usoftmall.com/
 messageServiceIp=http://message.ubtob.com/
 
 #search url
-searchUrl=http://10.10.100.179:8081
+searchUrl=http://10.10.100.179:8081
+
+# dfs file url
+dfsFileUrl=http://dfs-api.ubtob.com

+ 4 - 1
src/main/resources/test/sys.properties

@@ -22,4 +22,7 @@ inquiryServiceUrl=http://218.17.158.219:24000
 messageServiceIp=http://message.ubtob.com/
 
 #search url
-searchUrl=http://10.10.100.191:8081
+searchUrl=http://10.10.100.191:8081
+
+#dfs file url
+dfsFileUrl=http://10.10.100.200:9999

+ 4 - 1
src/main/resources/txcloud/sys.properties

@@ -20,4 +20,7 @@ inquiryServiceUrl=https://api-inquiry.usoftchina.com/
 messageServiceIp=http://message.ubtob.com/
 
 #search url
-searchUrl=http://172.21.0.6:8081
+searchUrl=http://172.21.0.6:8081
+
+# dfs file url
+dfsFileUrl=http://dfs-api.ubtob.com