liupeng 4 年 前
コミット
dc2a4b5a9a

+ 34 - 0
code/sapparent/sapcms/src/main/java/org/fouram/controller/ApiController.java

@@ -19,8 +19,10 @@ import org.fouram.core.util.ConfConfig;
 import org.fouram.core.util.LoggerUtil;
 import org.fouram.entity.SapOrg;
 import org.fouram.entity.SapUser;
+import org.fouram.service.SapCheckService;
 import org.fouram.service.SapOrgService;
 import org.fouram.service.SapUserService;
+import org.fouram.service.WxDepartService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -39,6 +41,10 @@ public class ApiController extends BaseController {
 	@Autowired
 	private SapUserService sapUserService;
 	@Autowired
+	private WxDepartService wxDepartService;
+	@Autowired
+	private SapCheckService sapCheckService;
+	@Autowired
 	private static final String TOKEN = "UserId";
 
 	/**
@@ -213,5 +219,33 @@ public class ApiController extends BaseController {
 		}
 		return true;
 	}
+	
+	@RequestMapping(value = "/findDepartJSON", produces = "application/json;charset=utf-8")
+	@ResponseBody
+	public Object findDepartJSON(HttpServletRequest request) {
+		try {
+			return AppUtil.success(wxDepartService.findDepartJSON(), null);
+		} catch (Exception e) {
+			LoggerUtil.error(e);
+			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
+		}
+	}
+	
+	
+	@RequestMapping(value = "/findUserReports", produces = "application/json;charset=utf-8")
+	@ResponseBody
+	public Object findUsers(HttpServletRequest request) {
+		try {
+			// 开始时间、结束时间、 部门、姓名
+			String startDate = getPageData().getString("startDate");
+			String endDate = getPageData().getString("endDate");
+			String departId = getPageData().getString("departId");
+			String name = getPageData().getString("name");
+			return AppUtil.success(sapCheckService.findUserReports(startDate, endDate, departId, name), null);
+		} catch (Exception e) {
+			LoggerUtil.error(e);
+			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
+		}
+	}
 
 }

+ 1 - 1
code/sapparent/sapservice/src/main/java/org/fouram/core/util/TreeUtil.java

@@ -15,7 +15,7 @@ import com.google.common.collect.Maps;
 public class TreeUtil {
 
 	public static <T> List<T> buildTreeSimple(List<T> list) throws Exception {
-		return buildTreeNormal(list, "id", "parentId", "children", "wxDepartId", false, WebConstants.TOP_DEPART.toString());
+		return buildTreeNormal(list, "id", "parentId", "children", "orderBy", false, WebConstants.TOP_DEPART.toString());
 	}
 
 	public static <T> List<T> buildTreeNormal(List<T> list, String idProperty, String parentIdProperty,

+ 2 - 0
code/sapparent/sapservice/src/main/java/org/fouram/entity/WxDepart.java

@@ -1,6 +1,7 @@
 package org.fouram.entity;
 
 import java.io.Serializable;
+import java.util.List;
 
 import org.apache.ibatis.type.Alias;
 
@@ -21,4 +22,5 @@ public class WxDepart implements Serializable {
 	private String name;
 	private Long parentId;
 	private Long orderBy;
+	private List<WxDepart> children;
 }

+ 2 - 0
code/sapparent/sapservice/src/main/java/org/fouram/entity/WxUser.java

@@ -20,6 +20,8 @@ public class WxUser implements Serializable {
 	private String userId;
 	private String name;
 	private Long departId;
+	private Long firstDepartId;
 	private String firstDepartName;
+	private Long secondDepartId;
 	private String secondDepartName;
 }

+ 17 - 0
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapCheckMapper.xml

@@ -160,4 +160,21 @@
 	<update id="deleteCheckoutEnd">
 		delete from sap_checkout_end where id = #{id}
 	</update>
+	
+	<select id="findUserReports" resultType="Map">
+		SELECT a.* from sap_check_report a where 1=1 
+		<if test="departId != null and departId != ''">
+			and (firstDepartId=#{departId} or secondDepartId=#{departId})
+		</if>
+		<if test="startDate != null and startDate != ''">
+			and checkinDay >= #{startDate} 
+		</if>
+		<if test="endDate != null and endDate != ''">
+			and checkinDay &lt;= #{endDate} 
+		</if>
+		<if test="name != null and name != ''">
+			and name like CONCAT(CONCAT('%', #{name}),'%')
+		</if>
+		order by userId, checkinDay 
+	</select>
 </mapper>

+ 4 - 0
code/sapparent/sapservice/src/main/java/org/fouram/mapper/WxDepartMapper.xml

@@ -9,4 +9,8 @@
 	<select id="selectById" resultType="WxDepart">
 		select * from wx_depart where id=#{id}
 	</select>
+	
+	<select id="selectChildrenByParentId" resultType="WxDepart">
+		select * from wx_depart where parentId=#{id}
+	</select>
 </mapper>

+ 4 - 3
code/sapparent/sapservice/src/main/java/org/fouram/mapper/WxUserMapper.xml

@@ -6,8 +6,8 @@
 	</select>
 
 	<insert id="save">
-		insert into wx_user(userId,name,departId,firstDepartName,secondDepartName,sapExists) 
-		values (#{userId},#{name},#{departId},#{firstDepartName},#{secondDepartName},'0')
+		insert into wx_user(userId,name,departId,firstDepartName,firstDepartId,secondDepartName,secondDepartId,sapExists) 
+		values (#{userId},#{name},#{departId},#{firstDepartName},#{firstDepartId},#{secondDepartName},#{secondDepartId},'0')
 	</insert>
 	
 	<update id="updateAllDelete">
@@ -16,7 +16,8 @@
 	
 	<update id="update">
 		update wx_user 
-		set departId=#{departId},firstDepartName=#{firstDepartName},secondDepartName=#{secondDepartName},delFlag=0
+		set departId=#{departId},firstDepartName=#{firstDepartName},firstDepartId=#{firstDepartId},
+			secondDepartName=#{secondDepartName},secondDepartId=#{secondDepartId},delFlag=0
 		where userId=#{userId}
 	</update>
 	

+ 9 - 0
code/sapparent/sapservice/src/main/java/org/fouram/service/SapCheckService.java

@@ -214,4 +214,13 @@ public class SapCheckService extends BaseService {
 		}
 		return false;
 	}
+
+	public Object findUserReports(String startDate, String endDate, String departId, String name) throws Exception {
+		Map<String, String> pd = Maps.newHashMap();
+		pd.put("startDate", startDate);
+		pd.put("endDate", endDate);
+		pd.put("departId", departId);
+		pd.put("name", name);
+		return findList("SapCheckMapper.findUserReports", pd);
+	}
 }

+ 18 - 0
code/sapparent/sapservice/src/main/java/org/fouram/service/WxDepartService.java

@@ -7,9 +7,12 @@ import java.util.List;
 import org.fouram.constants.WebConstants;
 import org.fouram.core.base.service.BaseService;
 import org.fouram.core.plugin.weixin.cp.util.WXCpDepartUtil;
+import org.fouram.core.util.TreeUtil;
 import org.fouram.entity.WxDepart;
 import org.springframework.stereotype.Service;
 
+import com.google.common.collect.Lists;
+
 import me.chanjar.weixin.cp.bean.WxCpDepart;
 
 @Service
@@ -44,4 +47,19 @@ public class WxDepartService extends BaseService {
 	public WxDepart selectById(Long id) throws Exception {
 		return (WxDepart) findObject("WxDepartMapper.selectById", id);
 	}
+	
+	@SuppressWarnings("unchecked")
+	public List<WxDepart> selectChildrenByParentId(Long id) throws Exception {
+		return (List<WxDepart>) findList("WxDepartMapper.selectChildrenByParentId", id);
+	}
+
+	public Object findDepartJSON() throws Exception {
+		List<WxDepart> result = Lists.newArrayList();
+		List<WxDepart> departs = selectChildrenByParentId(WebConstants.TOP_DEPART);
+		departs.forEach(depart -> result.add(depart));
+		for(WxDepart depart : departs) {
+			selectChildrenByParentId(depart.getId()).forEach(dept -> result.add(dept));
+		}
+		return TreeUtil.buildTreeSimple(result);
+	}
 }

+ 2 - 0
code/sapparent/sapservice/src/main/java/org/fouram/service/WxUserService.java

@@ -36,9 +36,11 @@ public class WxUserService extends BaseService {
 			departs = getUserDepart(wxUser.getDepartId());
 			if (departs.size() > 0) {
 				wxUser.setFirstDepartName(departs.get(0).getName());
+				wxUser.setFirstDepartId(departs.get(0).getId());
 			}
 			if (departs.size() > 1) {
 				wxUser.setSecondDepartName(departs.get(1).getName());
+				wxUser.setSecondDepartId(departs.get(1).getId());
 			}
 			dbUser = selectById(userId);
 			if (dbUser == null) {