|
|
@@ -1,5 +1,7 @@
|
|
|
package com.usoftchina.saas.sale.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.usoft.b2b.access.entity.UserAccount;
|
|
|
import com.usoft.b2b.access.utils.AccessUtils;
|
|
|
import com.usoftchina.saas.account.api.AccountApi;
|
|
|
@@ -9,10 +11,11 @@ import com.usoftchina.saas.account.dto.CompanyDTO;
|
|
|
import com.usoftchina.saas.base.Result;
|
|
|
import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
import com.usoftchina.saas.exception.BizException;
|
|
|
-import com.usoftchina.saas.sale.dto.apcheck.SaveOperationData;
|
|
|
+import com.usoftchina.saas.sale.dto.apcheck.*;
|
|
|
import com.usoftchina.saas.sale.service.ApCheckService;
|
|
|
import com.usoftchina.saas.utils.JsonUtils;
|
|
|
import com.usoftchina.saas.utils.ObjectUtils;
|
|
|
+import com.usoftchina.saas.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -20,6 +23,11 @@ import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Consumer;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @Author chenwei
|
|
|
* @Date 2019/01/28
|
|
|
@@ -42,25 +50,47 @@ public class ApCheckServiceImpl implements ApCheckService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public String getCustApcheck(int count, int page, String searchFilter, String sorting) {
|
|
|
+ public Object getCustApcheck(int count, int page, String searchFilter, String sorting) {
|
|
|
Long userUU = accountApi.getAccountById(BaseContextHolder.getUserId()).getData().getUu();
|
|
|
Long enUU = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData().getUu();
|
|
|
UserAccount account = new UserAccount();
|
|
|
account.setAppId("SAAS");
|
|
|
account.setUserUU(userUU);
|
|
|
account.setSpaceUU(enUU);
|
|
|
- String getUrl = b2bUrl + CUSTAPCHECKURL + "?count=" + count + "&page=" + page + "&searchFilter=" + searchFilter + " &sorting=" + sorting;
|
|
|
- String result = null;
|
|
|
+ JSONObject response = null;
|
|
|
+ JSONArray result = new JSONArray();
|
|
|
try {
|
|
|
- result = AccessUtils.getForObject(getUrl, account, String.class);
|
|
|
+ String getUrl = b2bUrl + CUSTAPCHECKURL + "?count=" + count + "&page=" + page + "&searchFilter=" + URLEncoder.encode(searchFilter, "UTF-8");
|
|
|
+ if (!StringUtils.isEmpty(sorting)) {
|
|
|
+ getUrl += "&sorting=" + URLEncoder.encode(sorting, "utf-8");
|
|
|
+ }
|
|
|
+ response = AccessUtils.getForObject(getUrl, account, JSONObject.class);
|
|
|
+ JSONArray content = response.getJSONArray("content");
|
|
|
+ if (!content.isEmpty()){
|
|
|
+ for (int i = 0; i < content.size(); i++) {
|
|
|
+ JSONArray resultSubList = new JSONArray();
|
|
|
+ JSONObject custApCheckData = content.getJSONObject(i);
|
|
|
+ JSONArray amountDetailList = custApCheckData.getJSONArray("amountDetailList");
|
|
|
+ for (int j = 0; j < amountDetailList.size(); j++) {
|
|
|
+ JSONObject amountDetail = amountDetailList.getJSONObject(j);
|
|
|
+ amountDetail.put("apId", custApCheckData.getLongValue("id")); //ID
|
|
|
+ amountDetail.put("custName", custApCheckData.getJSONObject("myEnterprise").getString("enName"));
|
|
|
+ amountDetail.put("custUU", custApCheckData.getJSONObject("myEnterprise").getString("uu"));
|
|
|
+ resultSubList.add(amountDetail);
|
|
|
+ }
|
|
|
+ result.addAll(resultSubList);
|
|
|
+ }
|
|
|
+ response.put("content", result);
|
|
|
+ response.put("totalElement", result.size());
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
throw new BizException(80000, e.getMessage());
|
|
|
}
|
|
|
- return result;
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String getAllByKeywords(Long fromDate, Long endDate, Long customerUU, Double taxRate, String factory, String prodTitle, String suuorname, String prodSpec) {
|
|
|
+ public Object getAllByKeywords(Long fromDate, Long endDate, Long customerUU, Double taxRate, String factory, String prodTitle, String suuorname, String prodSpec, String currency) {
|
|
|
Long userUU = accountApi.getAccountById(BaseContextHolder.getUserId()).getData().getUu();
|
|
|
Long enUU = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData().getUu();
|
|
|
UserAccount account = new UserAccount();
|
|
|
@@ -80,19 +110,82 @@ public class ApCheckServiceImpl implements ApCheckService {
|
|
|
if (!ObjectUtils.isEmpty(prodSpec)){
|
|
|
getUrl += "&prodSpec=" + prodSpec;
|
|
|
}
|
|
|
- String result = null;
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ ApCheckProdIO apCheckProdIO = null;
|
|
|
try {
|
|
|
- result = AccessUtils.getForObject(getUrl, account, String.class);
|
|
|
+ apCheckProdIO = AccessUtils.getForObject(getUrl, account, ApCheckProdIO.class);
|
|
|
+ Set<Map<String, String>> currencySet = new HashSet<Map<String, String>>();
|
|
|
+ apCheckProdIO.getThisMonthCount().forEach(apCheckAmount -> {
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put(apCheckAmount.getCurrency(), apCheckAmount.getCurrency());
|
|
|
+ currencySet.add(map);
|
|
|
+ });
|
|
|
+ //币别
|
|
|
+ result.put("currencys", currencySet);
|
|
|
+ /* 主表数据 */
|
|
|
+ result.put("main", generateMainData(apCheckProdIO, currency));
|
|
|
+ /* 明细表数据 */
|
|
|
+ result.put("items", apCheckProdIO.getDetails().stream().filter(apCheckProdIODetail -> currency.equals(apCheckProdIODetail.getCurrency())).collect(Collectors.toList()));
|
|
|
} catch (Exception e) {
|
|
|
throw new BizException(80000, e.getMessage());
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private Map<String, Object> generateMainData(ApCheckProdIO apCheckProdIO, String currency){
|
|
|
+ /* 主表数据 */
|
|
|
+ Map<String, Object> mainMap = new HashMap<String, Object>();
|
|
|
+ Optional<ApCheckAmount> optional = null;
|
|
|
+ //本期应收
|
|
|
+ if (apCheckProdIO.getThisMonthCount().size() > 0) {
|
|
|
+ optional = apCheckProdIO.getThisMonthCount().stream().filter(apCheckAmount -> currency.equals(apCheckAmount.getCurrency())).findFirst();
|
|
|
+ mainMap.put("thisMonthCount", optional.isPresent() ? optional.get() : null);
|
|
|
+ }else {
|
|
|
+ mainMap.put("thisMonthCount", null);
|
|
|
+ }
|
|
|
+ //本期已对账
|
|
|
+ if (apCheckProdIO.getThisMonthDoneCount().size() > 0) {
|
|
|
+ optional = apCheckProdIO.getThisMonthDoneCount().stream().filter(apCheckAmount -> currency.equals(apCheckAmount.getCurrency())).findFirst();
|
|
|
+ mainMap.put("thisMonthDoneCount", optional.isPresent() ? optional.get() : null);
|
|
|
+ }else {
|
|
|
+ mainMap.put("thisMonthDoneCount", null);
|
|
|
+ }
|
|
|
+ //本期未对账
|
|
|
+ if (apCheckProdIO.getThisMonthTodoCount().size() > 0) {
|
|
|
+ optional = apCheckProdIO.getThisMonthTodoCount().stream().filter(apCheckAmount -> currency.equals(apCheckAmount.getCurrency())).findFirst();
|
|
|
+ mainMap.put("thisMonthTodoCount", optional.isPresent() ? optional.get() : null);
|
|
|
+ }else {
|
|
|
+ mainMap.put("thisMonthTodoCount", null);
|
|
|
+ }
|
|
|
+ //应收总额
|
|
|
+ if (apCheckProdIO.getTotalCount().size() > 0) {
|
|
|
+ optional = apCheckProdIO.getTotalCount().stream().filter(apCheckAmount -> currency.equals(apCheckAmount.getCurrency())).findFirst();
|
|
|
+ mainMap.put("totalCount", optional.isPresent() ? optional.get() : null);
|
|
|
+ }else {
|
|
|
+ mainMap.put("totalCount", null);
|
|
|
+ }
|
|
|
+ //本期发货
|
|
|
+ if (apCheckProdIO.getThisPeriodSendAmount().size() > 0) {
|
|
|
+ optional = apCheckProdIO.getThisPeriodSendAmount().stream().filter(apCheckAmount -> currency.equals(apCheckAmount.getCurrency())).findFirst();
|
|
|
+ mainMap.put("thisPeriodSendAmount", optional.isPresent() ? optional.get() : null);
|
|
|
+ }else {
|
|
|
+ mainMap.put("thisPeriodSendAmount", null);
|
|
|
+ }
|
|
|
+ //本期已收
|
|
|
+ if (apCheckProdIO.getThisPeriodDoneAmount().size() > 0) {
|
|
|
+ optional = apCheckProdIO.getThisMonthDoneCount().stream().filter(apCheckAmount -> currency.equals(apCheckAmount.getCurrency())).findFirst();
|
|
|
+ mainMap.put("thisPeriodDoneAmount", optional.isPresent() ? optional.get() : null);
|
|
|
+ }else {
|
|
|
+ mainMap.put("thisPeriodDoneAmount", null);
|
|
|
+ }
|
|
|
+ return mainMap;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ModelMap operationSave(SaveOperationData saveOperationData) {
|
|
|
Result<AccountDTO> accountResult = accountApi.getAccountById(BaseContextHolder.getUserId());
|
|
|
Result<CompanyDTO> companyResult = companyApi.getCompanyById(BaseContextHolder.getCompanyId());
|
|
|
+ ModelMap result = null;
|
|
|
if (accountResult.isSuccess() && companyResult.isSuccess()) {
|
|
|
Long userUU = accountResult.getData().getUu();
|
|
|
Long enUU = companyResult.getData().getUu();
|
|
|
@@ -103,18 +196,17 @@ public class ApCheckServiceImpl implements ApCheckService {
|
|
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
|
|
map.add("json", JsonUtils.toJsonString(saveOperationData));
|
|
|
String url = b2bUrl + SAVEAPCHECKURL;
|
|
|
- String result = null;
|
|
|
try {
|
|
|
- result = AccessUtils.postForObject(url, account, String.class, map);
|
|
|
+ result = AccessUtils.postForObject(url, account, ModelMap.class, map);
|
|
|
} catch (Exception e){
|
|
|
throw new BizException(80000, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- return new ModelMap("success");
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String apCheckInfo(Long id) {
|
|
|
+ public Object apCheckInfo(Long id) {
|
|
|
Long userUU = accountApi.getAccountById(BaseContextHolder.getUserId()).getData().getUu();
|
|
|
Long enUU = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData().getUu();
|
|
|
UserAccount account = new UserAccount();
|
|
|
@@ -122,27 +214,30 @@ public class ApCheckServiceImpl implements ApCheckService {
|
|
|
account.setUserUU(userUU);
|
|
|
account.setSpaceUU(enUU);
|
|
|
String url = b2bUrl + "/sale/apCheck/" + id + "/info";
|
|
|
- String result = null;
|
|
|
+ PurchaseApCheck result = null;
|
|
|
try {
|
|
|
- result = AccessUtils.getForObject(url, account, String.class);
|
|
|
+ result = AccessUtils.getForObject(url, account, PurchaseApCheck.class);
|
|
|
} catch (Exception e){
|
|
|
throw new BizException(80000, e.getMessage());
|
|
|
}
|
|
|
- return null;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String apCheckList(int count, int page, String searchFilter, String sorting) {
|
|
|
+ public Object apCheckList(int count, int page, String searchFilter, String sorting) {
|
|
|
Long userUU = accountApi.getAccountById(BaseContextHolder.getUserId()).getData().getUu();
|
|
|
Long enUU = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData().getUu();
|
|
|
UserAccount account = new UserAccount();
|
|
|
account.setAppId("SAAS");
|
|
|
account.setUserUU(userUU);
|
|
|
account.setSpaceUU(enUU);
|
|
|
- String url = b2bUrl + APCHECKLISTURL + "?count=" + count + "&page=" + page + "&searchFilter=" + searchFilter + "&sorting=" + sorting;
|
|
|
- String result = null;
|
|
|
+ SPage<PurchaseApCheck> result = null;
|
|
|
try {
|
|
|
- result = AccessUtils.getForObject(url, account, String.class);
|
|
|
+ String url = b2bUrl + APCHECKLISTURL + "?count=" + count + "&page=" + page + "&searchFilter=" + URLEncoder.encode(searchFilter, "UTF-8");
|
|
|
+ if (!StringUtils.isEmpty(sorting)) {
|
|
|
+ url += "&sorting=" + URLEncoder.encode(sorting, "utf-8");
|
|
|
+ }
|
|
|
+ result = AccessUtils.getForObject(url, account, SPage.class);
|
|
|
} catch (Exception e) {
|
|
|
throw new BizException(80000, e.getMessage());
|
|
|
}
|