liupeng 4 years ago
parent
commit
1a61b82b83

+ 2 - 0
code/sapparent/sapcms/src/main/java/org/fouram/controller/SapReportController.java

@@ -56,6 +56,8 @@ public class SapReportController extends BaseController {
 	@PostMapping(value = "/selectReportAuthList", produces = "application/json;charset=utf-8")
 	@ResponseBody
 	public Object selectReportAuthList(@RequestBody SapReportAuthSelectListDTO dto) throws Exception {
+		ParamUtil.isNull(dto.getPageNumber(), "参数pageNumber不可以为空");
+		ParamUtil.isNull(dto.getPageSize(), "参数pageSize不可以为空");
 		return ResultUtil.success(service.selectList(dto), null);
 	}
 

+ 174 - 166
code/sapparent/sapservice/src/main/java/org/fouram/core/base/service/BaseService.java

@@ -1,166 +1,174 @@
-package org.fouram.core.base.service;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import org.fouram.constants.WebConstants;
-import org.fouram.core.base.dao.DAO;
-import org.fouram.core.base.exception.PromptException;
-import org.fouram.core.util.Base64Util;
-import org.fouram.core.util.ConfConfig;
-import org.fouram.core.util.JsonNodeUtil;
-import org.fouram.core.util.Tools;
-import org.fouram.entity.SapUser;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpHeaders;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.collect.Lists;
-
-/**
- * 业务逻辑层基类
- */
-public abstract class BaseService {
-
-	@Resource(name = "daoSupport")
-	private DAO dao;
-	@Autowired
-	protected RequestService requestService;
-
-	public Integer save(String sqlStr, Object paramObj) throws Exception {
-		return dao.save(sqlStr, paramObj);
-	}
-
-	public Integer update(String sqlStr, Object paramObj) throws Exception {
-		return dao.update(sqlStr, paramObj);
-	}
-
-	public Integer delete(String sqlStr, Object paramObj) throws Exception {
-		return dao.delete(sqlStr, paramObj);
-	}
-
-	public Object findObject(String sqlStr, Object paramObj) throws Exception {
-		return dao.findForObject(sqlStr, paramObj);
-	}
-
-	public Object findList(String sqlStr, Object paramObj) throws Exception {
-		return dao.findForList(sqlStr, paramObj);
-	}
-
-	public HttpHeaders getHttpHeaders() {
-		HttpHeaders headers = new HttpHeaders();
-		StringBuilder stringBuilder = new StringBuilder();
-		String sapApiUser = ConfConfig.getConfigString("sapApi.user");
-		String authorizationStr = stringBuilder.append("Basic ").append(Base64Util.encodeString(sapApiUser)).toString();
-		headers.add("Authorization", authorizationStr);
-		return headers;
-	}
-
-	public static void main(String[] args) {
-		StringBuilder stringBuilder = new StringBuilder();
-		String sapApiUser = "APIADMIN@cmccoltdD:1234567";
-		String authorizationStr = stringBuilder.append("Basic ").append(Base64Util.encodeString(sapApiUser)).toString();
-		System.out.println("测试:" + authorizationStr);
-
-		stringBuilder = new StringBuilder();
-		sapApiUser = "API01@cmccoltd:cmccoltd123";
-		authorizationStr = stringBuilder.append("Basic ").append(Base64Util.encodeString(sapApiUser)).toString();
-		System.out.println("正式:" + authorizationStr);
-	}
-
-	public String getPersonIds(List<SapUser> sapUsers) {
-		String personIds = "";
-		for (SapUser sapUser : sapUsers) {
-			personIds += "'" + sapUser.getPersonId() + "',";
-		}
-		return personIds;
-	}
-
-	public String getUserIds(List<SapUser> sapUsers) {
-		String userIds = "";
-		for (SapUser sapUser : sapUsers) {
-			userIds += "'" + sapUser.getUserId() + "',";
-		}
-		return userIds;
-	}
-
-	public static String formatPosition(String str) {
-		if (Tools.isEmpty(str)) {
-			return "";
-		}
-		str = str.replace("\n", "");
-		return str;
-	}
-
-	public static String formatBusinessPhone(String str) {
-		if (Tools.isEmpty(str)) {
-			return "";
-		}
-		// 021 80171999 -> 021-80171999
-		if (str.length() == 12) {
-			str = str.replace(" ", "-");
-		}
-		if (str.indexOf("x") > -1) {
-			str = str.replace("x", "-");
-		}
-		return str;
-	}
-
-	public Map<String, List<String>> groupList(List<String> list, int groupSize) {
-		int listSize = list.size();
-		int toIndex = groupSize;
-		Map<String, List<String>> map = new HashMap<>(); // 用map存起来新的分组后数据
-		int keyToken = 0;
-		for (int i = 0; i < list.size(); i += groupSize) {
-			if (i + groupSize > listSize) { // 作用为toIndex最后没有100条数据则剩余几条newList中就装几条
-				toIndex = listSize - i;
-			}
-			List<String> newList = list.subList(i, i + toIndex);
-			List<String> userIds = Lists.newArrayList();
-			for (String userId : newList) {
-				userIds.add(userId);
-			}
-			map.put("keyName" + keyToken, userIds);
-			keyToken++;
-		}
-		return map;
-	}
-
-	public String getUserIdList(List<String> sapUserIds) {
-		String userIds = "";
-		for (String sapUser : sapUserIds) {
-			userIds += "'" + sapUser + "',";
-		}
-		return userIds;
-	}
-
-	public void throwPromptException(String msg) throws Exception {
-		throw new PromptException(msg);
-	}
-
-	private String getPicklistLabelUrl(String optionId) {
-		return "https://api15.sapsf.cn/odata/v2/PicklistLabel(locale='zh_CN',optionId=" + optionId + ")?$format=json";
-	}
-
-	public String getLabelValue(String optionId) {
-		if (Tools.isEmpty(optionId)) {
-			return "";
-		}
-		if (WebConstants.LABEL_MAP.containsKey(optionId)) {
-			return WebConstants.LABEL_MAP.get(optionId);
-		} else {
-			String value = "";
-			try {
-				String url = getPicklistLabelUrl(optionId);
-				JsonNode node = requestService.getForObject(url, getHttpHeaders());
-				value = JsonNodeUtil.getValue(node, "d", "label");
-			} catch (Exception e) {
-			}
-			WebConstants.LABEL_MAP.put(optionId, value);
-			return value;
-		}
-	}
-}
+package org.fouram.core.base.service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.fouram.constants.WebConstants;
+import org.fouram.core.base.dao.DAO;
+import org.fouram.core.base.exception.PromptException;
+import org.fouram.core.util.Base64Util;
+import org.fouram.core.util.ConfConfig;
+import org.fouram.core.util.JsonNodeUtil;
+import org.fouram.core.util.Tools;
+import org.fouram.entity.SapUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.Lists;
+
+/**
+ * 业务逻辑层基类
+ */
+public abstract class BaseService {
+
+	@Resource(name = "daoSupport")
+	private DAO dao;
+	@Autowired
+	protected RequestService requestService;
+
+	public Integer save(String sqlStr, Object paramObj) throws Exception {
+		return dao.save(sqlStr, paramObj);
+	}
+
+	public Integer update(String sqlStr, Object paramObj) throws Exception {
+		return dao.update(sqlStr, paramObj);
+	}
+
+	public Integer delete(String sqlStr, Object paramObj) throws Exception {
+		return dao.delete(sqlStr, paramObj);
+	}
+
+	public Object findObject(String sqlStr, Object paramObj) throws Exception {
+		return dao.findForObject(sqlStr, paramObj);
+	}
+
+	public Object findList(String sqlStr, Object paramObj) throws Exception {
+		return dao.findForList(sqlStr, paramObj);
+	}
+
+	public HttpHeaders getHttpHeaders() {
+		HttpHeaders headers = new HttpHeaders();
+		StringBuilder stringBuilder = new StringBuilder();
+		String sapApiUser = ConfConfig.getConfigString("sapApi.user");
+		String authorizationStr = stringBuilder.append("Basic ").append(Base64Util.encodeString(sapApiUser)).toString();
+		headers.add("Authorization", authorizationStr);
+		return headers;
+	}
+
+	public static void main(String[] args) {
+		StringBuilder stringBuilder = new StringBuilder();
+		String sapApiUser = "APIADMIN@cmccoltdD:1234567";
+		String authorizationStr = stringBuilder.append("Basic ").append(Base64Util.encodeString(sapApiUser)).toString();
+		System.out.println("测试:" + authorizationStr);
+
+		stringBuilder = new StringBuilder();
+		sapApiUser = "API01@cmccoltd:cmccoltd123";
+		authorizationStr = stringBuilder.append("Basic ").append(Base64Util.encodeString(sapApiUser)).toString();
+		System.out.println("正式:" + authorizationStr);
+	}
+
+	public String getPersonIds(List<SapUser> sapUsers) {
+		String personIds = "";
+		for (SapUser sapUser : sapUsers) {
+			personIds += "'" + sapUser.getPersonId() + "',";
+		}
+		return personIds;
+	}
+
+	public String getUserIds(List<SapUser> sapUsers) {
+		String userIds = "";
+		for (SapUser sapUser : sapUsers) {
+			userIds += "'" + sapUser.getUserId() + "',";
+		}
+		return userIds;
+	}
+
+	public static String formatPosition(String str) {
+		if (Tools.isEmpty(str)) {
+			return "";
+		}
+		str = str.replace("\n", "");
+		return str;
+	}
+
+	public static String formatBusinessPhone(String str) {
+		if (Tools.isEmpty(str)) {
+			return "";
+		}
+		// 021 80171999 -> 021-80171999
+		if (str.length() == 12) {
+			str = str.replace(" ", "-");
+		}
+		if (str.indexOf("x") > -1) {
+			str = str.replace("x", "-");
+		}
+		return str;
+	}
+
+	public Map<String, List<String>> groupList(List<String> list, int groupSize) {
+		int listSize = list.size();
+		int toIndex = groupSize;
+		Map<String, List<String>> map = new HashMap<>(); // 用map存起来新的分组后数据
+		int keyToken = 0;
+		for (int i = 0; i < list.size(); i += groupSize) {
+			if (i + groupSize > listSize) { // 作用为toIndex最后没有100条数据则剩余几条newList中就装几条
+				toIndex = listSize - i;
+			}
+			List<String> newList = list.subList(i, i + toIndex);
+			List<String> userIds = Lists.newArrayList();
+			for (String userId : newList) {
+				userIds.add(userId);
+			}
+			map.put("keyName" + keyToken, userIds);
+			keyToken++;
+		}
+		return map;
+	}
+
+	public String getUserIdList(List<String> sapUserIds) {
+		String userIds = "";
+		for (String sapUser : sapUserIds) {
+			userIds += "'" + sapUser + "',";
+		}
+		return userIds;
+	}
+
+	public void throwPromptException(String msg) throws Exception {
+		throw new PromptException(msg);
+	}
+
+	private String getPicklistLabelUrl(String optionId) {
+		return "https://api15.sapsf.cn/odata/v2/PicklistLabel(locale='zh_CN',optionId=" + optionId + ")?$format=json";
+	}
+
+	public String getLabelValue(String optionId) {
+		if (Tools.isEmpty(optionId)) {
+			return "";
+		}
+		if (WebConstants.LABEL_MAP.containsKey(optionId)) {
+			return WebConstants.LABEL_MAP.get(optionId);
+		} else {
+			String value = "";
+			try {
+				String url = getPicklistLabelUrl(optionId);
+				JsonNode node = requestService.getForObject(url, getHttpHeaders());
+				value = JsonNodeUtil.getValue(node, "d", "label");
+			} catch (Exception e) {
+			}
+			WebConstants.LABEL_MAP.put(optionId, value);
+			return value;
+		}
+	}
+	
+	public static JSONObject getPageResult(List<? extends Object> list, Object total) {
+		JSONObject object = new JSONObject();
+		object.put("total", total);
+		object.put("data", list);
+		return object;
+	}
+}

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

@@ -31,6 +31,9 @@ public class SapReportAuthDTO implements Serializable {
 	public static class SapReportAuthSelectListDTO implements Serializable {
 		private static final long serialVersionUID = 1L;
 		private String wxName;
+		private Integer pageNumber;
+		private Integer pageSize;
+		private Integer pageCurrent;
 	}
 
 	@Data

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

@@ -12,6 +12,9 @@
 		<if test="wxName != null and wxName != ''">
 			and b.name like CONCAT(CONCAT('%', #{wxName}),'%')
 		</if>
+		<if test="pageCurrent != null">
+			limit ${pageCurrent}, ${pageSize}
+		</if>
 	</select>
 	
 	<select id="selectListByWxUserId" resultType="SapReportAuth">

+ 0 - 7
code/sapparent/sapservice/src/main/java/org/fouram/service/SapCheckReportService.java

@@ -22,13 +22,6 @@ public class SapCheckReportService extends BaseService {
 		return getPageResult(list, total);
 	}
 
-	public static JSONObject getPageResult(List<? extends Object> list, Object total) {
-		JSONObject object = new JSONObject();
-		object.put("total", total);
-		object.put("data", list);
-		return object;
-	}
-
 	@SuppressWarnings("unchecked")
 	public List<Map<String, Object>> findUserReports(FindUsersDTO dto) throws Exception {
 		String startDate = dto.getStartDate();

+ 8 - 2
code/sapparent/sapservice/src/main/java/org/fouram/service/SapReportAuthService.java

@@ -10,6 +10,8 @@ import org.fouram.entity.SapReportAuth;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import com.alibaba.fastjson.JSONObject;
+
 @Service
 @Transactional
 public class SapReportAuthService extends BaseService {
@@ -23,8 +25,12 @@ public class SapReportAuthService extends BaseService {
 	}
 
 	@SuppressWarnings("unchecked")
-	public List<SapReportAuth> selectList(SapReportAuthSelectListDTO dto) throws Exception {
-		return (List<SapReportAuth>) findList("SapReportAuthMapper.selectList", dto);
+	public JSONObject selectList(SapReportAuthSelectListDTO dto) throws Exception {
+		dto.setPageCurrent(dto.getPageSize() * (dto.getPageNumber() - 1));
+		List<SapReportAuth> pageList = (List<SapReportAuth>) findList("SapReportAuthMapper.selectList", dto);
+		dto.setPageCurrent(null);
+		List<SapReportAuth> allList = (List<SapReportAuth>) findList("SapReportAuthMapper.selectList", dto);
+		return getPageResult(pageList, Long.valueOf(allList.size()));
 	}
 
 	public void deleteById(Long id) throws Exception {