|
@@ -0,0 +1,105 @@
|
|
|
+package com.jpsoft.proj.utils;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import com.jpsoft.framework.util.ApplicationContextUtils;
|
|
|
+import com.jpsoft.framework.util.DateUtil;
|
|
|
+import com.jpsoft.proj.kpi.service.WorkSummaryService;
|
|
|
+
|
|
|
+public class ThirdAPIUtils {
|
|
|
+
|
|
|
+ private static final String url="https://xpgjapi.xiaoxinda.com/mobile/workAttendance/queryMonthWorkStatus";
|
|
|
+
|
|
|
+ private static Map<String,String[]> workTags=new HashMap<String,String[]>(3); //缓存月份的工作日标记 year-month:x,x,x,x,x
|
|
|
+
|
|
|
+ private static Map<String,Long> refreshTimes=new HashMap<String,Long>(3); //记录刷新时间
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询指定月份的工作日标记
|
|
|
+ * @param workMonth yyyy-MM
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String[] loadWorkTagInMonth(String workMonth) {
|
|
|
+ String[] ym=workMonth.split("-");
|
|
|
+ Map<String,String> args=new HashMap<String,String>(2);
|
|
|
+ args.put("year",ym[0]);
|
|
|
+ args.put("month",ym[1]);
|
|
|
+ String rst=OkhttpUtils.post(url,args);
|
|
|
+ return StringUtils.isEmpty(rst)?null:rst.split(",");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String[] getWorkTagInMonth(String workMonth) {
|
|
|
+ if(workTags.get(workMonth)==null) {
|
|
|
+ String[] tags=loadWorkTagInMonth(workMonth);
|
|
|
+ putWorkTags(workMonth, tags);
|
|
|
+ }
|
|
|
+ return workTags.get(workMonth);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 线程同步的情况下进行刷新
|
|
|
+ * @param workMonth
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static void refreshWorkTags(final String workMonth) {
|
|
|
+ Long preTime=refreshTimes.get(workMonth);
|
|
|
+ Long nowTime=(new Date()).getTime();
|
|
|
+ if(preTime!=null&&(nowTime-preTime)<600000) { //10分钟内不再刷新
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ synchronized(ThirdAPIUtils.class) {
|
|
|
+ if(preTime!=null&&(nowTime-preTime)<600000) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ final String[] newtags=loadWorkTagInMonth(workMonth);
|
|
|
+ String[] oldtags=workTags.get(workMonth);
|
|
|
+ putWorkTags(workMonth, newtags);
|
|
|
+
|
|
|
+ if(oldtags==null) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ String n=StringUtils.join(newtags,","),d=StringUtils.join(oldtags,",");
|
|
|
+ if(!n.equals(d)) { //标记有变化,更新数据库workTag
|
|
|
+
|
|
|
+ new Thread(new Runnable() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+
|
|
|
+ WorkSummaryService service=ApplicationContextUtils.getBean("workSummaryService",WorkSummaryService.class);
|
|
|
+ service.updateWorkTagInMonth(workMonth, newtags);
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void putWorkTags(String workMonth,String[] tags) {
|
|
|
+ workTags.put(workMonth, tags);
|
|
|
+ refreshTimes.put(workMonth,(new Date()).getTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断某一天是否为工作日,默认为是
|
|
|
+ * @param date
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static int checkDayWorkTag(Date date) {
|
|
|
+ String str=DateUtil.format(date, "yyyy-MM-dd");
|
|
|
+ String[] tags=getWorkTagInMonth(str.substring(0, 7));
|
|
|
+ int day=Integer.parseInt(str.substring(8));
|
|
|
+ if(tags==null||tags.length<day) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return Integer.parseInt(tags[day-1]);
|
|
|
+ }
|
|
|
+}
|