Commit 8de5987c by 宋祥

1.优化:接口返回封装pager类

parent 85449e9a
......@@ -16,7 +16,6 @@ import com.baosight.hggp.util.StringUtils;
import com.baosight.iplat4j.core.exception.PlatException;
import java.io.IOException;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
......@@ -50,8 +49,8 @@ public class DcOpenApi {
*
* @param pageIndex 当前页
*/
public static Pager<DcUserList> userList(int pageIndex)
throws IOException, InstantiationException, IllegalAccessException {
public static Pager<DcUserList> userList(int pageIndex) throws IOException, InstantiationException,
IllegalAccessException {
JSONObject paramJson = DcApiUtils.buildParamJson(pageIndex);
String result = HttpUtils.post(DeChengConst.USER_LIST, DcApiUtils.buildHeader(), JSON.toJSONString(paramJson),
HttpUtils.JSON_MEDIA_TYPE);
......@@ -84,7 +83,7 @@ public class DcOpenApi {
* @param endTime 结束日期 20240820
* @param pageIndex 当前页
*/
public static List<DcChance> chanceList(String startTime, String endTime, int pageIndex) throws IOException {
public static Pager<DcChance> chanceList(String startTime, String endTime, int pageIndex) throws IOException {
JSONArray dataJsons = new JSONArray();
dataJsons.add(DcApiUtils.buildValueJson("a_date_0", startTime));
dataJsons.add(DcApiUtils.buildValueJson("a_date_1", endTime));
......@@ -103,7 +102,7 @@ public class DcOpenApi {
*
* @param pageIndex 当前页
*/
public static List<DcContractList> contactList(int pageIndex) throws IOException {
public static Pager<DcContractList> contactList(int pageIndex) throws IOException {
JSONArray dataJsons = new JSONArray();
dataJsons.add(DcApiUtils.buildValueJson("pageindex", pageIndex));
dataJsons.add(DcApiUtils.buildValueJson("pagesize", 100));
......
......@@ -191,12 +191,24 @@ public class DcApiUtils {
* @param result
* @return
*/
public static <T> List<T> handleResult(String result, Class<T> clazz) {
public static <T> Pager<T> handleResult(String result, Class<T> clazz) {
JSONObject resultJson = JSONObject.parseObject(result);
// 异常处理
handleMessage(resultJson);
// 获取结果数据集
JSONObject bodyJson = resultJson.getJSONObject("body");
JSONObject sourceJson = bodyJson.getJSONObject("source");
JSONObject tableJson = sourceJson.getJSONObject("table");
// 构建结果数据集
return buildTableData(resultJson, clazz);
Pager pager = new Pager<T>();
pager.setData(buildTableData(tableJson, clazz));
// 分页数据
JSONObject pageJson = tableJson.getJSONObject("page");
pager.setPageIndex(pageJson.getInteger("pageindex"));
pager.setPageSize(pageJson.getInteger("pagesize"));
pager.setTotalRows(pageJson.getInteger("recordcount"));
pager.setTotalPages(pageJson.getInteger("pagecount"));
return pager;
}
/**
......@@ -221,15 +233,12 @@ public class DcApiUtils {
/**
* 构建数据集
*
* @param resultJson
* @param tableJson
* @param clazz
* @param <T>
* @return
*/
public static <T> List<T> buildTableData(JSONObject resultJson, Class<T> clazz) {
JSONObject bodyJson = resultJson.getJSONObject("body");
JSONObject sourceJson = bodyJson.getJSONObject("source");
JSONObject tableJson = sourceJson.getJSONObject("table");
public static <T> List<T> buildTableData(JSONObject tableJson, Class<T> clazz) {
JSONArray colJsons = tableJson.getJSONArray("cols");
JSONArray rowJsons = tableJson.getJSONArray("rows");
return rowJsons.stream().map(item -> {
......
......@@ -3,6 +3,7 @@ package com.baosight.hggp.hg.sc.service;
import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.extapp.decheng.api.DcOpenApi;
import com.baosight.hggp.core.extapp.decheng.model.DcContractList;
import com.baosight.hggp.core.model.Pager;
import com.baosight.hggp.core.utils.ThreadUtils;
import com.baosight.hggp.hg.pz.domain.HGPZ009;
import com.baosight.hggp.hg.pz.tools.HGPZTools;
......@@ -125,12 +126,13 @@ public class ServiceHGSC101 extends ServiceEPBase {
if (pageIndex > 1000) {
break;
}
List<DcContractList> zbContracts = DcOpenApi.contactList(pageIndex);
if (CollectionUtils.isEmpty(zbContracts)) {
Pager<DcContractList> pager = DcOpenApi.contactList(pageIndex);
List<DcContractList> dcContractLists = pager.getData();
if (CollectionUtils.isEmpty(dcContractLists) || pageIndex > pager.getTotalPages()) {
break;
}
// 写入合同数据
saveContractData(accountCode, zbContracts);
saveContractData(accountCode, dcContractLists);
pageIndex++;
}
}
......@@ -139,14 +141,14 @@ public class ServiceHGSC101 extends ServiceEPBase {
* 写入合同信息
*
* @param accountCode
* @param zbContracts
* @param dcContractLists
*/
private void saveContractData(String accountCode, List<DcContractList> zbContracts) {
private void saveContractData(String accountCode, List<DcContractList> dcContractLists) {
// 查询帐套信息
HGPZ009 dbPz009 = HGPZTools.HgPz009.getByCode(accountCode);
String prefix = dbPz009.getLoginPrefix();
for (DcContractList zbContract : zbContracts) {
String projCode = prefix + zbContract.getOrd();
for (DcContractList dcContractList : dcContractLists) {
String projCode = prefix + dcContractList.getOrd();
HGSC001 dbSc001 = HGSCTools.Hgsc001.getByCode(projCode);
if (dbSc001 == null) {
dbSc001 = new HGSC001();
......@@ -154,12 +156,12 @@ public class ServiceHGSC101 extends ServiceEPBase {
dbSc001.setDepCode(accountCode);
dbSc001.setDepName(dbPz009.getAccountName());
dbSc001.setProjCode(projCode);
dbSc001.setProjName(zbContract.getTitle());
dbSc001.setProjName(dcContractList.getTitle());
DaoUtils.insert(HGSC001.INSERT, dbSc001);
} else {
Map updateMap = new HashMap();
updateMap.put(HGSC001.FIELD_proj_code, projCode);
updateMap.put(HGSC001.FIELD_proj_name, zbContract.getTitle());
updateMap.put(HGSC001.FIELD_proj_name, dcContractList.getTitle());
DaoUtils.insert(HgScSqlConstant.HgSc001.UPDATE_PROJ_NAME, dbSc001);
}
}
......
......@@ -150,34 +150,34 @@ public class ServiceHGXSOrg extends ServiceBase {
private void syncDcDeptData(String accountCode) throws IOException, InstantiationException, IllegalAccessException {
int pageIndex = 1;
Pager<DcDeptList> pager = DcOpenApi.deptList(pageIndex);
List<DcDeptList> zbDepts = pager.getData();
if (CollectionUtils.isEmpty(zbDepts)) {
List<DcDeptList> dcDeptLists = pager.getData();
if (CollectionUtils.isEmpty(dcDeptLists)) {
return;
}
// 写入合同数据
syncDcDeptData(accountCode, zbDepts);
syncDcDeptData(accountCode, dcDeptLists);
}
/**
* 写入部门信息
*
* @param accountCode
* @param zbDepts
* @param dcDeptLists
*/
private void syncDcDeptData(String accountCode, List<DcDeptList> zbDepts) {
private void syncDcDeptData(String accountCode, List<DcDeptList> dcDeptLists) {
// 查询帐套信息
HGPZ009 dbPz009 = HGPZTools.HgPz009.getByCode(accountCode);
for (DcDeptList zbDept : zbDepts) {
String orgId = dbPz009.getLoginPrefix() + zbDept.getNodeId();
for (DcDeptList dcDeptList : dcDeptLists) {
String orgId = dbPz009.getLoginPrefix() + dcDeptList.getNodeId();
Org dbOrg = HGXSTools.XsOrg.get(orgId);
if (dbOrg == null) {
dbOrg = new Org();
dbOrg.setOrgId(orgId);
this.syncDcDeptAdd(accountCode, zbDept, dbOrg, dbPz009);
this.syncDcDeptAdd(accountCode, dcDeptList, dbOrg, dbPz009);
} else {
Map updateMap = new HashMap();
updateMap.put(Org.FIELD_ORG_ID, orgId);
updateMap.put(Org.FIELD_ORG_CNAME, zbDept.getNodeText());
updateMap.put(Org.FIELD_ORG_CNAME, dcDeptList.getNodeText());
updateMap.put(Org.FIELD_REC_REVISOR, "System");
updateMap.put(Org.FIELD_REC_REVISE_TIME, DateUtils.shortDateTime());
updateMap.put(Org.FIELD_IS_DELETED, DeleteFlagEnum.UN_REMOVE.getCode().toString());
......@@ -194,16 +194,16 @@ public class ServiceHGXSOrg extends ServiceBase {
* @param dbOrg
* @param dbPz009
*/
private void syncDcDeptAdd(String accountCode, DcDeptList zbDept, Org dbOrg, HGPZ009 dbPz009) {
private void syncDcDeptAdd(String accountCode, DcDeptList dcDeptList, Org dbOrg, HGPZ009 dbPz009) {
String orgId = dbOrg.getOrgId();
dbOrg.setAccountCode(accountCode);
dbOrg.setOrgEname(orgId);
dbOrg.setOrgCname(zbDept.getNodeText());
dbOrg.setOrgCname(dcDeptList.getNodeText());
dbOrg.setOrgType(OrgTypeEnum.DEPT.getCode());
dbOrg.setParentOrgId("-1".equals(zbDept.getParentId())
? accountCode : dbPz009.getLoginPrefix() + zbDept.getParentId());
dbOrg.setParentOrgId("-1".equals(dcDeptList.getParentId())
? accountCode : dbPz009.getLoginPrefix() + dcDeptList.getParentId());
dbOrg.setEstablishDate("20240101");
dbOrg.setSortIndex(zbDept.getFullSort());
dbOrg.setSortIndex(dcDeptList.getFullSort());
dbOrg.setCompanyCode(accountCode);
dbOrg.setCompanyName(dbPz009.getAccountName());
dbOrg.setRecCreator("System");
......
......@@ -238,12 +238,12 @@ public class ServiceHGXSUser extends ServiceBase {
break;
}
Pager<DcUserList> pager = DcOpenApi.userList(pageIndex);
List<DcUserList> zbUsers = pager.getData();
if (CollectionUtils.isEmpty(zbUsers) || pageIndex > pager.getTotalPages()) {
List<DcUserList> dcUserLists = pager.getData();
if (CollectionUtils.isEmpty(dcUserLists) || pageIndex > pager.getTotalPages()) {
break;
}
// 写入合同数据
syncDcUserData(accountCode, zbUsers);
syncDcUserData(accountCode, dcUserLists);
pageIndex++;
}
}
......@@ -252,14 +252,14 @@ public class ServiceHGXSUser extends ServiceBase {
* 写入用户信息
*
* @param accountCode
* @param ZbUserLists
* @param dcUserLists
*/
private void syncDcUserData(String accountCode, List<DcUserList> ZbUserLists) {
private void syncDcUserData(String accountCode, List<DcUserList> dcUserLists) {
// 查询帐套信息
HGPZ009 dbPz009 = HGPZTools.HgPz009.getByCode(accountCode);
for (DcUserList zbUserList : ZbUserLists) {
for (DcUserList dcUserList : dcUserLists) {
try {
syncDcUserSingle(dbPz009, zbUserList.getOrd());
syncDcUserSingle(dbPz009, dcUserList.getOrd());
} catch (Exception e) {
log.error("同步德诚用户失败:{}", e.getMessage(), e);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment