liupeng 4 anni fa
parent
commit
73195c3731

+ 28 - 3
code/sapparent/sapcms/src/main/java/org/fouram/controller/SapReportController.java

@@ -1,11 +1,16 @@
 package org.fouram.controller;
 
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
 import org.fouram.core.base.controller.BaseController;
+import org.fouram.core.util.ParamUtil;
 import org.fouram.core.util.ResultUtil;
 import org.fouram.dto.input.FindUsersDTO;
 import org.fouram.dto.input.SapReportAuthDTO.SapReportAuthDeleteDTO;
 import org.fouram.dto.input.SapReportAuthDTO.SapReportAuthSaveDTO;
 import org.fouram.dto.input.SapReportAuthDTO.SapReportAuthSelectListDTO;
+import org.fouram.entity.SapReportAuth;
 import org.fouram.service.SapCheckReportService;
 import org.fouram.service.SapOrgService;
 import org.fouram.service.SapReportAuthService;
@@ -13,9 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import com.google.common.collect.Lists;
+
 import io.swagger.annotations.Api;
 
 @Controller
@@ -38,7 +46,11 @@ public class SapReportController extends BaseController {
 
 	@PostMapping(value = "/saveReportAuth", produces = "application/json;charset=utf-8")
 	@ResponseBody
-	public Object saveReportAuth(@RequestBody SapReportAuthSaveDTO dto) throws Exception {
+	public Object saveReportAuth(@RequestBody SapReportAuthSaveDTO dto, @RequestHeader("userId") String userId)
+			throws Exception {
+		ParamUtil.isBlank(userId, "header参数userId不可以为空");
+		ParamUtil.isBlank(dto.getSapOrgIds(), "参数sapOrgIds不可以为空");
+		dto.setWxUserId(userId);
 		service.save(dto);
 		return ResultUtil.success();
 	}
@@ -52,13 +64,26 @@ public class SapReportController extends BaseController {
 	@PostMapping(value = "/deleteReportAuth", produces = "application/json;charset=utf-8")
 	@ResponseBody
 	public Object deleteReportAuth(@RequestBody SapReportAuthDeleteDTO dto) throws Exception {
+		ParamUtil.isNull(dto.getId(), "参数id不可以为空");
 		service.deleteById(dto.getId());
 		return ResultUtil.success();
 	}
-	
+
 	@PostMapping(value = "/selectUserReportList", produces = "application/json;charset=utf-8")
 	@ResponseBody
-	public Object selectUserReportList(@RequestBody FindUsersDTO dto) throws Exception {
+	public Object selectUserReportList(@RequestBody FindUsersDTO dto, @RequestHeader("userId") String userId)
+			throws Exception {
+		ParamUtil.isBlank(userId, "header参数userId不可以为空");
+		ParamUtil.isNull(dto.getPageSize(), "参数pageSize不可以为空");
+		ParamUtil.isNull(dto.getPageNumber(), "参数pageNumber不可以为空");
+		if(StringUtils.isBlank(dto.getDepartId())) {
+			List<SapReportAuth> auths = service.selectListByWxUserId(userId);
+			List<String> departIds = Lists.newArrayList();
+			for(SapReportAuth auth : auths) {
+				departIds.add(auth.getSapOrgId());
+			}
+			dto.setDepartIds(departIds);
+		}
 		return ResultUtil.success(reportService.findUserReports(dto), null);
 	}
 }

+ 3 - 2
code/sapparent/sapservice/src/main/java/org/fouram/core/base/exception/ControllerExceptionHandler.java

@@ -27,11 +27,12 @@ public class ControllerExceptionHandler {
 	@ExceptionHandler(Throwable.class)
 	public PageData exceptionHandler(Throwable ex) {
 		// 提示不输出报错日志
-		if (PromptException.class.getSimpleName().equals(ex.getClass().getSimpleName())) {
+		if (GiantInvalidArgumentException.class.getSimpleName().equals(ex.getClass().getSimpleName())
+				|| PromptException.class.getSimpleName().equals(ex.getClass().getSimpleName())) {
 			return AppUtil.error(ex.getMessage());
 		}
 		String messageContent = Tools.getExceptionAllInfo(ex);
-		if(WebConstants.isProduct()) {
+		if (WebConstants.isProduct()) {
 			WXCpMessageUtil.sendAdminError(messageContent);
 		}
 		log.error(messageContent);

+ 20 - 0
code/sapparent/sapservice/src/main/java/org/fouram/core/base/exception/GiantInvalidArgumentException.java

@@ -0,0 +1,20 @@
+package org.fouram.core.base.exception;
+
+public class GiantInvalidArgumentException extends RuntimeException {
+	private static final long serialVersionUID = -1605515531880249974L;
+
+	public GiantInvalidArgumentException() {
+	}
+
+	public GiantInvalidArgumentException(String message) {
+		super(message);
+	}
+
+	public GiantInvalidArgumentException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+	public GiantInvalidArgumentException(Throwable cause) {
+		super(cause);
+	}
+}

+ 30 - 0
code/sapparent/sapservice/src/main/java/org/fouram/core/util/ParamUtil.java

@@ -0,0 +1,30 @@
+package org.fouram.core.util;
+
+import java.util.Collection;
+
+import org.apache.commons.lang3.StringUtils;
+import org.fouram.core.base.exception.GiantInvalidArgumentException;
+
+public class ParamUtil {
+
+	public ParamUtil() {
+	}
+
+	public static void isBlank(String string, String msg) {
+		if (StringUtils.isBlank(string)) {
+			throw new GiantInvalidArgumentException(msg);
+		}
+	}
+
+	public static void isEmpty(Collection<?> collection, String msg) {
+		if (null == collection || collection.isEmpty()) {
+			throw new GiantInvalidArgumentException(msg);
+		}
+	}
+
+	public static void isNull(Object object, String msg) {
+		if (null == object) {
+			throw new GiantInvalidArgumentException(msg);
+		}
+	}
+}

+ 3 - 0
code/sapparent/sapservice/src/main/java/org/fouram/dto/input/FindUsersDTO.java

@@ -1,6 +1,7 @@
 package org.fouram.dto.input;
 
 import java.io.Serializable;
+import java.util.List;
 
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 
@@ -20,8 +21,10 @@ public class FindUsersDTO implements Serializable {
 	private String startDate;
 	private String endDate;
 	private String departId;
+	private List<String> departIds;
 	private String name;
 	private String status;
+	private String loginWxUserId;
 	private Integer pageNumber;
 	private Integer pageSize;
 }

+ 12 - 0
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapCheckReportMapper.xml

@@ -39,6 +39,12 @@
 		<if test="departId != null and departId != ''">
 			and (c.firstDepartId=#{departId} or c.secondDepartId=#{departId})
 		</if>
+		<if test="departIds != null and departIds != ''">
+			and c.firstDepartId in
+			<foreach collection="departIds" item="depId" separator="," open="(" close=")">
+				#{depId}
+			</foreach>
+		</if>
 		<if test="startDate != null and startDate != ''">
 			and a.checkinDay >= #{startDate} 
 		</if>
@@ -64,6 +70,12 @@
 		<if test="departId != null and departId != ''">
 			and (c.firstDepartId=#{departId} or c.secondDepartId=#{departId})
 		</if>
+		<if test="departIds != null and departIds != ''">
+			and c.firstDepartId in
+			<foreach collection="departIds" item="depId" separator="," open="(" close=")">
+				#{depId}
+			</foreach>
+		</if>
 		<if test="startDate != null and startDate != ''">
 			and a.checkinDay >= #{startDate} 
 		</if>

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

@@ -14,6 +14,10 @@
 		</if>
 	</select>
 	
+	<select id="selectListByWxUserId" resultType="SapReportAuth">
+		select a.* from sap_report_auth a where a.wxUserId = #{wxUserId}
+	</select>
+	
 	<delete id="deleteById">
 		delete from sap_report_auth where id = #{id}
 	</delete>

+ 4 - 2
code/sapparent/sapservice/src/main/java/org/fouram/service/SapCheckReportService.java

@@ -48,10 +48,11 @@ public class SapCheckReportService extends BaseService {
 				state = "异常";
 			}
 		}
-		Map<String, String> pd = Maps.newHashMap();
+		Map<String, Object> pd = Maps.newHashMap();
 		pd.put("startDate", startDate);
 		pd.put("endDate", endDate);
 		pd.put("departId", departId);
+		pd.put("departIds", dto.getDepartIds());
 		pd.put("name", name);
 		pd.put("state", state);
 		if (pageSize != null) {
@@ -149,10 +150,11 @@ public class SapCheckReportService extends BaseService {
 				state = "异常";
 			}
 		}
-		Map<String, String> pd = Maps.newHashMap();
+		Map<String, Object> pd = Maps.newHashMap();
 		pd.put("startDate", startDate);
 		pd.put("endDate", endDate);
 		pd.put("departId", departId);
+		pd.put("departIds", dto.getDepartIds());
 		pd.put("name", name);
 		pd.put("state", state);
 		return (Long) findObject("SapCheckReportMapper.findUserReportTotal", pd);

+ 5 - 0
code/sapparent/sapservice/src/main/java/org/fouram/service/SapReportAuthService.java

@@ -30,4 +30,9 @@ public class SapReportAuthService extends BaseService {
 	public void deleteById(Long id) throws Exception {
 		update("SapReportAuthMapper.deleteById", id);
 	}
+
+	@SuppressWarnings("unchecked")
+	public List<SapReportAuth> selectListByWxUserId(String wxUserId) throws Exception {
+		return (List<SapReportAuth>) findList("SapReportAuthMapper.selectListByWxUserId", wxUserId);
+	}
 }