浏览代码

接口调整:加载月工作小结时,返回工作日标记;保存工作小结时先进行更新操作;工作日标记进行登录时的刷新、比对操作

chenwen 3 年之前
父节点
当前提交
0f9edc65c9

+ 44 - 0
pom.xml

@@ -133,8 +133,37 @@
 			<artifactId>jtds</artifactId>
 			<version>1.2.5</version>
 		</dependency>
+		
+		<dependency>
+		    <groupId>com.squareup.okhttp3</groupId>
+		    <artifactId>okhttp</artifactId>
+		    <version>3.10.0</version>
+		</dependency>
       
   </dependencies>
+  
+  <profiles>
+        <profile>
+            <id>dev</id>
+            <properties>
+                <env>dev</env>
+                <jdbc.url>192.168</jdbc.url>
+            </properties>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+        </profile>
+        
+        <profile>
+            <id>prd</id>
+            <properties>
+                <env>prd</env>
+                <jdbc.username>prd_username</jdbc.username>
+             </properties>
+        </profile>
+    </profiles>
+    
+    
   <build>
     <finalName>jp-kpi</finalName>
     <plugins>
@@ -165,5 +194,20 @@
 			</plugin>
 			
 		</plugins>
+		
+    	<!-- <resources>
+    		<resource>
+                <directory>WEB-INF/config</directory>
+                <excludes>
+                    <exclude>dev/*</exclude>
+                    <exclude>prd/*</exclude>
+                </excludes>
+                <filtering>true</filtering>
+            </resource>
+            
+            
+       </resources> -->
   </build>
+  
+  
 </project>

+ 17 - 1
src/main/java/com/jpsoft/proj/kpi/controller/WorkSummaryController.java

@@ -1,5 +1,6 @@
 package com.jpsoft.proj.kpi.controller;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -18,11 +19,13 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.jpsoft.framework.util.DateUtil;
 import com.jpsoft.proj.kpi.service.WorkSummaryService;
 import com.jpsoft.proj.model.TaskSummary;
 import com.jpsoft.proj.utils.MapUtils;
 import com.jpsoft.proj.utils.RespVO;
 import com.jpsoft.proj.utils.RespVOBuilder;
+import com.jpsoft.proj.utils.ThirdAPIUtils;
 
 @RestController
 @RequestMapping("/**/api")
@@ -32,9 +35,20 @@ public class WorkSummaryController {
 	@Autowired
 	private WorkSummaryService  service;
 	
+	@GetMapping("/refreshWorkTag")
+	public RespVO refreshWorkTag(@NotNull(message = "考勤月份不能为空") @Pattern(regexp="^\\d{4}-\\d{2}$",message = "考勤月份格式不正确:yyyy-MM") String workMonth) {
+		//手动刷新指定月份的工作日标记
+		ThirdAPIUtils.refreshWorkTags(workMonth);
+		return RespVOBuilder.ok();
+	}
+	
 	
 	@GetMapping("/getUsIdByNum")
 	public RespVO  getUsIdByNum(@NotBlank(message = "工号不能为空") String workNum) {
+		
+		//相当于登录,进行工作日标记的刷新,刷新当月
+		ThirdAPIUtils.refreshWorkTags(DateUtil.format(new Date(), "yyyy-MM"));
+		
 		return RespVOBuilder.ok(service.getUserByNumber(workNum));
 	}
 	
@@ -57,7 +71,8 @@ public class WorkSummaryController {
 	@GetMapping("/loadMonthWorkSummary")
 	public RespVO loadMonthWorkSummary(@NotBlank(message = "员工编号不能为空") String usId,@NotNull(message = "考勤月份不能为空") @Pattern(regexp="^\\d{4}-\\d{2}$",message = "考勤月份格式不正确:yyyy-MM") String workMonth) {
 		List<Map<String,Object>> workLogs=service.loadMonthWorkLog(usId, workMonth);
-		return RespVOBuilder.ok(workLogs);
+		
+		return RespVOBuilder.ok(MapUtils.builder("workLogs",workLogs,"workTags",ThirdAPIUtils.getWorkTagInMonth(workMonth)));
 	}
 	
 	/**
@@ -68,6 +83,7 @@ public class WorkSummaryController {
 	@PostMapping("saveDailyWorkSummary")
 	public RespVO  saveDailyWorkSummary(@Valid TaskSummary  newSummary) {
 		newSummary.updateSameUserId(newSummary.getUserid());
+		newSummary.setWorkday(ThirdAPIUtils.checkDayWorkTag(newSummary.getDates()));
 		service.saveDailyWorkSummary(newSummary);
 		return RespVOBuilder.ok();
 	}

+ 36 - 3
src/main/java/com/jpsoft/proj/kpi/service/WorkSummaryService.java

@@ -1,5 +1,7 @@
 package com.jpsoft.proj.kpi.service;
 
+import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -19,6 +21,30 @@ public class WorkSummaryService {
 	@Autowired
 	private SpringJdbcDAO  dao;
 	
+	/**
+	   * 更新库中
+	 * @param month
+	 * @param tags
+	 */
+	public void updateWorkTagInMonth(String month,String[] tags) {
+		if(StringUtils.isEmpty(month)||tags==null) {
+			return;
+		}
+		String sql="update tasksummary  set workday=? where CONVERT(varchar(100),Dates, 23)=?";
+		Date d=DateUtil.parse(month+"-01");
+		Calendar ca=Calendar.getInstance();
+		ca.setTime(d);
+		int maxDays=ca.getActualMaximum(Calendar.DATE);
+		List<Object[]> params=new ArrayList<Object[]>(maxDays);
+		for(int i=0;i<maxDays&&i<tags.length;i++) {
+			if(i>0) {
+				ca.add(Calendar.DAY_OF_MONTH, 1);
+			}
+			params.add(new Object[]{DateUtil.format(ca.getTime(), "yyyy-MM-dd"),tags[i]});
+		}
+		dao.getJdbcTemplate().batchUpdate(sql, params);
+	}
+	
 	/**
 	 * 查询某一天指定某些员工的工作小结提交数据
 	 * @param usIds
@@ -87,9 +113,16 @@ public class WorkSummaryService {
 	 * @return
 	 */
 	public void saveDailyWorkSummary(TaskSummary newSummary) {
-		delWorkSummary(newSummary.getUserid(),DateUtil.format(newSummary.getDates(), "yyyy-MM-dd"));
-		newSummary.setModifytime(new Date());
-		dao.insertPojo(newSummary, "TaskSummary");
+		String sql="update TaskSummary set modifytime=?,workday=?,program=?,pid=?,summary=?,sid=?,message=?,mid=?,clinch=?,cid=? where userid=? and CONVERT(varchar(100),Dates, 23)=?";
+		int num=dao.getJdbcTemplate().update(sql, new Date(),newSummary.getWorkday(),newSummary.getProgram(),newSummary.getPid(),newSummary.getSummary(),newSummary.getSid(),newSummary.getMessage(),newSummary.getMid(),newSummary.getClinch(),newSummary.getCid(),newSummary.getUserid(),DateUtil.format(newSummary.getDates(), "yyyy-MM-dd"));
+		if(num==0) {  //没有记录则新增
+			newSummary.setModifytime(new Date());
+			newSummary.setCreatetime(new Date());
+			newSummary.setChecked(0);
+			newSummary.setDelflag(0);
+			dao.insertPojo(newSummary, "TaskSummary");
+		}
+		
 	}
 	
 	

+ 55 - 0
src/main/java/com/jpsoft/proj/model/TaskSummary.java

@@ -40,6 +40,13 @@ public class TaskSummary {
 	
 	private String cid;
 	
+	private Integer delflag;
+	
+	private Integer checked;
+	
+	private Date  createtime;
+	
+	private Integer workday;
 	
 	
 	public void updateSameUserId(String userId) {
@@ -138,4 +145,52 @@ public class TaskSummary {
 	public void setCid(String cid) {
 		this.cid = cid;
 	}
+
+
+
+	public Integer getDelflag() {
+		return delflag;
+	}
+
+
+
+	public void setDelflag(Integer delflag) {
+		this.delflag = delflag;
+	}
+
+
+
+	public Integer getChecked() {
+		return checked;
+	}
+
+
+
+	public void setChecked(Integer checked) {
+		this.checked = checked;
+	}
+
+
+
+	public Date getCreatetime() {
+		return createtime;
+	}
+
+
+
+	public void setCreatetime(Date createtime) {
+		this.createtime = createtime;
+	}
+
+
+
+	public Integer getWorkday() {
+		return workday;
+	}
+
+
+
+	public void setWorkday(Integer workday) {
+		this.workday = workday;
+	}
 }

+ 96 - 0
src/main/java/com/jpsoft/proj/utils/OkhttpUtils.java

@@ -0,0 +1,96 @@
+package com.jpsoft.proj.utils;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.Call;
+import okhttp3.FormBody;
+import okhttp3.FormBody.Builder;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+public class OkhttpUtils {
+
+	private static OkHttpClient singleton;
+	
+	
+	private OkhttpUtils(){
+
+    }
+	
+	public static OkHttpClient getInstance() {
+        if (singleton == null)
+        {
+            synchronized (OkhttpUtils.class)
+            {
+                if (singleton == null)
+                {
+                    singleton = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS).build();
+                }
+            }
+        }
+        return singleton;
+    }
+	
+	
+	public static String get(String url){
+		try{
+			OkHttpClient client=OkhttpUtils.getInstance();
+			Request req=new Request.Builder()
+			.url(url)
+			.get()
+			.build();
+			Response response = client.newCall(req).execute();
+		    if (response.isSuccessful()) {
+		        return response.body().string();
+		    } else {
+		        return null;
+		    }
+
+	
+		}
+		catch (Exception e) {
+		      e.printStackTrace();
+		      return null;
+	     }
+		
+	}
+	
+	public static String post(String url,Map<String,String> args){
+		return post(url,args,null);
+	}
+	
+	
+	public static String post(String url,Map<String,String> args,Map<String,String> headers){
+	  try {
+		
+		OkHttpClient client=OkhttpUtils.getInstance();
+		Builder b=new FormBody.Builder();
+		for(String key : args.keySet()){
+			b.add(key, args.get(key));
+		}
+		
+		okhttp3.Request.Builder rb=new Request.Builder();
+		if(headers!=null&&headers.size()>0){
+			for(String h : headers.keySet()){
+				rb.addHeader(h, headers.get(h));
+			}
+		}
+		
+		Request req=rb.url(url)
+        .post(b.build())
+        .build();
+        final Call call = client.newCall(req);
+        Response rmtResp=call.execute();
+        return rmtResp.isSuccessful()?rmtResp.body().string():null;
+	    } catch (Exception e) {
+	      e.printStackTrace();
+	      return null;
+        }
+       
+	}
+	
+	
+
+}

+ 105 - 0
src/main/java/com/jpsoft/proj/utils/ThirdAPIUtils.java

@@ -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]);
+	}
+}