mirror of https://github.com/jeecgboot/jeecg-boot
feat : client orders management
parent
28b637098f
commit
3b9d03eda3
|
@ -2,10 +2,8 @@ package org.jeecg.modules.business.controller;
|
||||||
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.shiro.SecurityUtils;
|
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.system.vo.LoginUser;
|
import org.jeecg.modules.business.service.ISecurityService;
|
||||||
import org.jeecg.modules.system.service.ISysDepartService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -18,13 +16,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SecurityController {
|
public class SecurityController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysDepartService sysDepartService;
|
private ISecurityService securityService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private Environment env;
|
private Environment env;
|
||||||
@GetMapping(value = "/isEmployee")
|
@GetMapping(value = "/isEmployee")
|
||||||
public Result<?> checkIsEmployee () {
|
public Result<?> checkIsEmployee () {
|
||||||
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
|
return Result.ok(securityService.checkIsEmployee());
|
||||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
||||||
return Result.ok(sysUser.getOrgCode().equals(companyOrgCode));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package org.jeecg.modules.business.controller.admin;
|
package org.jeecg.modules.business.controller.admin;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateTime;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.system.vo.LoginUser;
|
import org.jeecg.common.system.vo.LoginUser;
|
||||||
import org.jeecg.modules.business.service.DashboardService;
|
import org.jeecg.modules.business.service.DashboardService;
|
||||||
import org.jeecg.modules.system.service.ISysDepartService;
|
import org.jeecg.modules.business.service.ISecurityService;
|
||||||
import org.jeecg.modules.system.service.impl.SysBaseApiImpl;
|
import org.jeecg.modules.system.service.impl.SysBaseApiImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
@ -28,7 +27,7 @@ import java.util.Map;
|
||||||
public class AdminController {
|
public class AdminController {
|
||||||
@Autowired private DashboardService dashboardService;
|
@Autowired private DashboardService dashboardService;
|
||||||
@Autowired private SysBaseApiImpl sysBaseApi;
|
@Autowired private SysBaseApiImpl sysBaseApi;
|
||||||
@Autowired private ISysDepartService sysDepartService;
|
@Autowired private ISecurityService securityService;
|
||||||
@Autowired private Environment env;
|
@Autowired private Environment env;
|
||||||
|
|
||||||
private final Integer PERIOD = 5;
|
private final Integer PERIOD = 5;
|
||||||
|
@ -52,10 +51,9 @@ public class AdminController {
|
||||||
|
|
||||||
@GetMapping(value = "/packageStatuses")
|
@GetMapping(value = "/packageStatuses")
|
||||||
public Result<?> packageStatuses() {
|
public Result<?> packageStatuses() {
|
||||||
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
|
boolean isEmployee = securityService.checkIsEmployee();
|
||||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
String orgCode = sysUser.getOrgCode();
|
if(!isEmployee){
|
||||||
if(!companyOrgCode.equals(orgCode)){
|
|
||||||
log.info("User {}, tried to access /admin/packageStatuses but is not authorized.", sysUser.getUsername());
|
log.info("User {}, tried to access /admin/packageStatuses but is not authorized.", sysUser.getUsername());
|
||||||
return Result.error(403,"Not authorized to view this page.");
|
return Result.error(403,"Not authorized to view this page.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,15 +17,18 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.getorderlist.OrderStatus;
|
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderResponse;
|
||||||
|
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeWarehouseRequest;
|
||||||
|
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeWarehouseRequestBody;
|
||||||
|
import org.jeecg.modules.business.domain.api.mabang.getorderlist.*;
|
||||||
import org.jeecg.modules.business.domain.job.ThrottlingExecutorService;
|
import org.jeecg.modules.business.domain.job.ThrottlingExecutorService;
|
||||||
import org.jeecg.modules.business.entity.Client;
|
import org.jeecg.modules.business.entity.Client;
|
||||||
import org.jeecg.modules.business.mapper.PlatformOrderMapper;
|
import org.jeecg.modules.business.mapper.PlatformOrderMapper;
|
||||||
import org.jeecg.modules.business.service.*;
|
import org.jeecg.modules.business.service.*;
|
||||||
import org.jeecg.modules.business.vo.*;
|
import org.jeecg.modules.business.vo.*;
|
||||||
import org.jeecg.modules.system.service.ISysDepartService;
|
|
||||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||||
|
@ -55,8 +58,7 @@ import io.swagger.annotations.ApiOperation;
|
||||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||||
|
|
||||||
import static org.jeecg.modules.business.vo.PlatformOrderOperation.Action.CANCEL;
|
import static org.jeecg.modules.business.vo.PlatformOrderOperation.Action.*;
|
||||||
import static org.jeecg.modules.business.vo.PlatformOrderOperation.Action.SUSPEND;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 平台订单表
|
* @Description: 平台订单表
|
||||||
|
@ -82,7 +84,7 @@ public class PlatformOrderController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IShopService shopService;
|
private IShopService shopService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysDepartService sysDepartService;
|
private ISecurityService securityService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Environment env;
|
private Environment env;
|
||||||
|
@ -384,10 +386,10 @@ public class PlatformOrderController {
|
||||||
|
|
||||||
@PostMapping("/orderManagement")
|
@PostMapping("/orderManagement")
|
||||||
public Result<?> orderManagement(@RequestBody List<PlatformOrderOperation> orderOperations) throws IOException {
|
public Result<?> orderManagement(@RequestBody List<PlatformOrderOperation> orderOperations) throws IOException {
|
||||||
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
|
boolean isEmployee = securityService.checkIsEmployee();
|
||||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
Client client;
|
Client client;
|
||||||
if(!sysUser.getOrgCode().equals(companyOrgCode)) {
|
if(!isEmployee) {
|
||||||
client = clientService.getCurrentClient();
|
client = clientService.getCurrentClient();
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
return Result.error(500,"Client not found. Please contact administrator.");
|
return Result.error(500,"Client not found. Please contact administrator.");
|
||||||
|
@ -401,31 +403,38 @@ public class PlatformOrderController {
|
||||||
client = clientService.getByShopId(orderOperations.get(0).getShopId());
|
client = clientService.getByShopId(orderOperations.get(0).getShopId());
|
||||||
}
|
}
|
||||||
|
|
||||||
long suspendCount = 0, cancelCount = 0;
|
long suspendCount = 0, cancelCount = 0, editCount = 0;
|
||||||
List<PlatformOrderOperation> ordersToSuspend = orderOperations.stream()
|
List<PlatformOrderOperation> ordersToSuspend = orderOperations.stream()
|
||||||
.filter(orderOperation -> orderOperation.getAction().equalsIgnoreCase(SUSPEND.getValue()))
|
.filter(orderOperation -> orderOperation.getAction().equalsIgnoreCase(SUSPEND.getValue()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<PlatformOrderOperation> ordersToCancel = orderOperations.stream()
|
List<PlatformOrderOperation> ordersToCancel = orderOperations.stream()
|
||||||
.filter(orderOperation -> orderOperation.getAction().equalsIgnoreCase(CANCEL.getValue()))
|
.filter(orderOperation -> orderOperation.getAction().equalsIgnoreCase(CANCEL.getValue()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
List<PlatformOrderOperation> ordersToEdit = orderOperations.stream()
|
||||||
|
.filter(orderOperation -> orderOperation.getAction().equalsIgnoreCase(EDIT.getValue()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
for(PlatformOrderOperation orderOperation : ordersToSuspend) {
|
for(PlatformOrderOperation orderOperation : ordersToSuspend) {
|
||||||
suspendCount += orderOperation.getOrderIds().split(",").length;
|
suspendCount += orderOperation.getOrderIds().split(",").length;
|
||||||
}
|
}
|
||||||
for(PlatformOrderOperation orderOperation : ordersToCancel) {
|
for(PlatformOrderOperation orderOperation : ordersToCancel) {
|
||||||
cancelCount += orderOperation.getOrderIds().split(",").length;
|
cancelCount += orderOperation.getOrderIds().split(",").length;
|
||||||
}
|
}
|
||||||
|
editCount = ordersToEdit.size();
|
||||||
log.info("{} Orders to suspend: {}", suspendCount, ordersToSuspend);
|
log.info("{} Orders to suspend: {}", suspendCount, ordersToSuspend);
|
||||||
log.info("{} Orders to cancel: {}", cancelCount, ordersToCancel);
|
log.info("{} Orders to cancel: {}", cancelCount, ordersToCancel);
|
||||||
|
log.info("{} Orders to edit: {}", editCount, ordersToEdit);
|
||||||
|
|
||||||
Responses cancelResponses = new Responses();
|
Responses cancelResponses = new Responses();
|
||||||
Responses suspendResponses = new Responses();
|
Responses suspendResponses = new Responses();
|
||||||
// Cancel orders
|
Responses editResponses = new Responses();
|
||||||
ExecutorService cancelExecutorService = ThrottlingExecutorService.createExecutorService(DEFAULT_NUMBER_OF_THREADS,
|
|
||||||
|
ExecutorService executor = ThrottlingExecutorService.createExecutorService(DEFAULT_NUMBER_OF_THREADS,
|
||||||
MABANG_API_RATE_LIMIT_PER_MINUTE, TimeUnit.MINUTES);
|
MABANG_API_RATE_LIMIT_PER_MINUTE, TimeUnit.MINUTES);
|
||||||
|
// Cancel orders
|
||||||
List<CompletableFuture<Responses>> futuresCancel = ordersToCancel.stream()
|
List<CompletableFuture<Responses>> futuresCancel = ordersToCancel.stream()
|
||||||
.map(orderOperation -> CompletableFuture.supplyAsync(
|
.map(orderOperation -> CompletableFuture.supplyAsync(
|
||||||
() -> platformOrderMabangService.cancelOrders(orderOperation),
|
() -> platformOrderMabangService.cancelOrders(orderOperation),
|
||||||
cancelExecutorService)
|
executor)
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
List<Responses>cancelResults = futuresCancel.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
List<Responses>cancelResults = futuresCancel.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
cancelResults.forEach(res -> {
|
cancelResults.forEach(res -> {
|
||||||
|
@ -437,12 +446,10 @@ public class PlatformOrderController {
|
||||||
|
|
||||||
|
|
||||||
// Suspend orders
|
// Suspend orders
|
||||||
ExecutorService suspendExecutorService = ThrottlingExecutorService.createExecutorService(DEFAULT_NUMBER_OF_THREADS,
|
|
||||||
MABANG_API_RATE_LIMIT_PER_MINUTE, TimeUnit.MINUTES);
|
|
||||||
List<CompletableFuture<Responses>> futuresSuspend = ordersToSuspend.stream()
|
List<CompletableFuture<Responses>> futuresSuspend = ordersToSuspend.stream()
|
||||||
.map(orderOperation -> CompletableFuture.supplyAsync(
|
.map(orderOperation -> CompletableFuture.supplyAsync(
|
||||||
() -> platformOrderMabangService.suspendOrder(orderOperation),
|
() -> platformOrderMabangService.suspendOrder(orderOperation),
|
||||||
suspendExecutorService)
|
executor)
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
List<Responses> suspendResults = futuresSuspend.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
List<Responses> suspendResults = futuresSuspend.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
suspendResults.forEach(res -> {
|
suspendResults.forEach(res -> {
|
||||||
|
@ -451,9 +458,49 @@ public class PlatformOrderController {
|
||||||
});
|
});
|
||||||
log.info("{}/{} orders suspended successfully.", suspendResponses.getSuccesses().size(), suspendCount);
|
log.info("{}/{} orders suspended successfully.", suspendResponses.getSuccesses().size(), suspendCount);
|
||||||
|
|
||||||
|
// Edit orders
|
||||||
|
// First we clear logistic channel if order has one
|
||||||
|
List<List<String>> editOrderIds = Lists.partition(ordersToEdit.stream().map(PlatformOrderOperation::getOrderIds).collect(Collectors.toList()), 10);
|
||||||
|
List<Order> ordersWithTrackingNumber = new ArrayList<>();
|
||||||
|
|
||||||
|
List<OrderListRequestBody> requests = new ArrayList<>();
|
||||||
|
for (List<String> platformOrderIdList : editOrderIds) {
|
||||||
|
requests.add(new OrderListRequestBody().setPlatformOrderIds(platformOrderIdList));
|
||||||
|
}
|
||||||
|
List<Order> mabangOrders = platformOrderMabangService.getOrdersFromMabang(requests, executor);
|
||||||
|
for(Order mabangOrder : mabangOrders) {
|
||||||
|
if(!mabangOrder.getTrackingNumber().isEmpty()) {
|
||||||
|
ordersWithTrackingNumber.add(mabangOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
platformOrderMabangService.clearLogisticChannel(ordersWithTrackingNumber, executor);
|
||||||
|
|
||||||
|
List<CompletableFuture<Responses>> futuresEdit = ordersToEdit.stream()
|
||||||
|
.map(orderOperation -> CompletableFuture.supplyAsync(() -> {
|
||||||
|
ChangeWarehouseRequestBody body = new ChangeWarehouseRequestBody(orderOperation);
|
||||||
|
ChangeWarehouseRequest request = new ChangeWarehouseRequest(body);
|
||||||
|
ChangeOrderResponse response = request.send();
|
||||||
|
Responses r = new Responses();
|
||||||
|
if(response.success())
|
||||||
|
r.addSuccess(orderOperation.getOrderIds());
|
||||||
|
else
|
||||||
|
r.addFailure(orderOperation.getOrderIds());
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
executor)
|
||||||
|
).collect(Collectors.toList());
|
||||||
|
List<Responses> editResults = futuresEdit.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
|
editResults.forEach(res -> {
|
||||||
|
editResponses.getSuccesses().addAll(res.getSuccesses());
|
||||||
|
editResponses.getFailures().addAll(res.getFailures());
|
||||||
|
});
|
||||||
|
log.info("{}/{} orders edited successfully.", editResponses.getSuccesses().size(), editCount);
|
||||||
|
executor.shutdown();
|
||||||
|
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
result.put("cancelResult", cancelResponses);
|
result.put("cancelResult", cancelResponses);
|
||||||
result.put("suspendResult", suspendResponses);
|
result.put("suspendResult", suspendResponses);
|
||||||
|
result.put("editResult", editResponses);
|
||||||
|
|
||||||
// send mail
|
// send mail
|
||||||
String subject = "[" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "] Orders management report";
|
String subject = "[" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "] Orders management report";
|
||||||
|
@ -462,12 +509,18 @@ public class PlatformOrderController {
|
||||||
Map<String, Object> templateModel = new HashMap<>();
|
Map<String, Object> templateModel = new HashMap<>();
|
||||||
templateModel.put("firstname", client.getFirstName());
|
templateModel.put("firstname", client.getFirstName());
|
||||||
templateModel.put("lastname", client.getSurname());
|
templateModel.put("lastname", client.getSurname());
|
||||||
if(cancelCount > 0)
|
if(cancelCount > 0) {
|
||||||
templateModel.put("cancelSuccessCount", cancelResponses.getSuccesses().size() + "/" + cancelCount);
|
templateModel.put("cancelSuccessCount", cancelResponses.getSuccesses().size() + "/" + cancelCount);
|
||||||
if(suspendCount > 0)
|
templateModel.put("cancelFailures", cancelResponses.getFailures());
|
||||||
|
}
|
||||||
|
if(suspendCount > 0) {
|
||||||
templateModel.put("suspendSuccessCount", suspendResponses.getSuccesses().size() + "/" + suspendCount);
|
templateModel.put("suspendSuccessCount", suspendResponses.getSuccesses().size() + "/" + suspendCount);
|
||||||
templateModel.put("cancelFailures", cancelResponses.getFailures());
|
templateModel.put("suspendFailures", suspendResponses.getFailures());
|
||||||
templateModel.put("suspendFailures", suspendResponses.getFailures());
|
}
|
||||||
|
if(editCount > 0) {
|
||||||
|
templateModel.put("editSuccessCount", editResponses.getSuccesses().size() + "/" + editCount);
|
||||||
|
templateModel.put("editFailures", editResponses.getFailures());
|
||||||
|
}
|
||||||
|
|
||||||
Session session = Session.getInstance(prop, new Authenticator() {
|
Session session = Session.getInstance(prop, new Authenticator() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -488,4 +541,22 @@ public class PlatformOrderController {
|
||||||
|
|
||||||
return Result.OK(result);
|
return Result.OK(result);
|
||||||
}
|
}
|
||||||
|
@GetMapping("/recipientInfo")
|
||||||
|
public Result<?> getRecipientInfo(@RequestParam("orderId") String platformOrderId) {
|
||||||
|
|
||||||
|
OrderListRequestBody body = new OrderListRequestBody().setPlatformOrderIds(Collections.singletonList(platformOrderId));
|
||||||
|
OrderListRawStream rawStream = new OrderListRawStream(body);
|
||||||
|
OrderListStream stream = new OrderListStream(rawStream);
|
||||||
|
List<Order> orders = stream.all();
|
||||||
|
if(orders.isEmpty()) {
|
||||||
|
return Result.error(400, "Order not found.");
|
||||||
|
}
|
||||||
|
Order order = orders.get(0);
|
||||||
|
JSONObject recipient = new JSONObject();
|
||||||
|
recipient.put("recipient", order.getRecipient());
|
||||||
|
recipient.put("phone", order.getPhone1());
|
||||||
|
recipient.put("street1", order.getAddress());
|
||||||
|
recipient.put("street2", order.getAddress2());
|
||||||
|
return Result.OK(recipient);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.system.vo.LoginUser;
|
import org.jeecg.common.system.vo.LoginUser;
|
||||||
import org.jeecg.modules.business.entity.Client;
|
import org.jeecg.modules.business.entity.Client;
|
||||||
import org.jeecg.modules.business.entity.ClientCategory;
|
import org.jeecg.modules.business.entity.ClientCategory;
|
||||||
|
import org.jeecg.modules.business.service.ISecurityService;
|
||||||
import org.jeecg.modules.business.service.IUserClientService;
|
import org.jeecg.modules.business.service.IUserClientService;
|
||||||
import org.jeecg.modules.system.service.ISysDepartService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -27,7 +27,7 @@ public class UserClientController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IUserClientService userClientService;
|
private IUserClientService userClientService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysDepartService sysDepartService;
|
private ISecurityService securityService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private Environment env;
|
private Environment env;
|
||||||
/**
|
/**
|
||||||
|
@ -36,23 +36,21 @@ public class UserClientController {
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/getClient")
|
@GetMapping(value = "/getClient")
|
||||||
public Result<?> getClientByUserId() {
|
public Result<?> getClientByUserId() {
|
||||||
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
|
boolean isEmployee = securityService.checkIsEmployee();
|
||||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
if(isEmployee) {
|
||||||
String orgCode = loginUser.getOrgCode();
|
Map<String, List<Client>> internalClientList = new HashMap<>();
|
||||||
String userId = loginUser.getId();
|
internalClientList.put("internal", userClientService.listClients());
|
||||||
Client client = userClientService.getClientMinInfoByUserId(userId);
|
return Result.OK("internal usage", internalClientList);
|
||||||
if(client == null) {
|
}
|
||||||
if(orgCode.equals(companyOrgCode)) {
|
else {
|
||||||
Map<String, List<Client>> internalClientList = new HashMap<>();
|
String userId = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId();
|
||||||
internalClientList.put("internal", userClientService.listClients());
|
Client client = userClientService.getClientMinInfoByUserId(userId);
|
||||||
return Result.OK("internal usage", internalClientList);
|
if(client == null)
|
||||||
}
|
return Result.error(403, "Access Denied.");
|
||||||
else
|
Map<String, Client> clientMap = new HashMap<>();
|
||||||
return Result.error(403, "Access Denied.");
|
clientMap.put("client", client);
|
||||||
|
return Result.ok(clientMap);
|
||||||
}
|
}
|
||||||
Map<String, Client> clientMap = new HashMap<>();
|
|
||||||
clientMap.put("client", client);
|
|
||||||
return Result.ok(clientMap);
|
|
||||||
}
|
}
|
||||||
@GetMapping(value = "/getSelfServiceClients")
|
@GetMapping(value = "/getSelfServiceClients")
|
||||||
public Result<?> getSelfServiceClients() {
|
public Result<?> getSelfServiceClients() {
|
||||||
|
|
|
@ -5,11 +5,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.google.common.base.CaseFormat;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.tuple.MutableTriple;
|
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.jeecg.common.api.dto.message.TemplateMessageDTO;
|
import org.jeecg.common.api.dto.message.TemplateMessageDTO;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
@ -25,11 +25,9 @@ import org.jeecg.modules.business.mapper.PlatformOrderContentMapper;
|
||||||
import org.jeecg.modules.business.mapper.PlatformOrderMapper;
|
import org.jeecg.modules.business.mapper.PlatformOrderMapper;
|
||||||
import org.jeecg.modules.business.mapper.PurchaseOrderContentMapper;
|
import org.jeecg.modules.business.mapper.PurchaseOrderContentMapper;
|
||||||
import org.jeecg.modules.business.service.*;
|
import org.jeecg.modules.business.service.*;
|
||||||
import org.jeecg.modules.business.service.impl.ProviderMabangServiceImpl;
|
|
||||||
import org.jeecg.modules.business.vo.*;
|
import org.jeecg.modules.business.vo.*;
|
||||||
import org.jeecg.modules.quartz.entity.QuartzJob;
|
import org.jeecg.modules.quartz.entity.QuartzJob;
|
||||||
import org.jeecg.modules.quartz.service.IQuartzJobService;
|
import org.jeecg.modules.quartz.service.IQuartzJobService;
|
||||||
import org.jeecg.modules.system.service.ISysDepartService;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
@ -47,7 +45,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.net.StandardSocketOptions;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
@ -56,6 +53,7 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.jeecg.common.util.SqlInjectionUtil.specialFilterContentForDictSql;
|
||||||
import static org.jeecg.modules.business.entity.Invoice.InvoiceType.*;
|
import static org.jeecg.modules.business.entity.Invoice.InvoiceType.*;
|
||||||
import static org.jeecg.modules.business.entity.Task.TaskCode.SI_G;
|
import static org.jeecg.modules.business.entity.Task.TaskCode.SI_G;
|
||||||
import static org.jeecg.modules.business.entity.TaskHistory.TaskStatus.*;
|
import static org.jeecg.modules.business.entity.TaskHistory.TaskStatus.*;
|
||||||
|
@ -75,14 +73,10 @@ public class InvoiceController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IClientService clientService;
|
private IClientService clientService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ICurrencyService currencyService;
|
|
||||||
@Autowired
|
|
||||||
private ExchangeRatesMapper exchangeRatesMapper;
|
private ExchangeRatesMapper exchangeRatesMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IShopService shopService;
|
private IShopService shopService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ILogisticChannelService logisticChannelService;
|
|
||||||
@Autowired
|
|
||||||
private PlatformOrderShippingInvoiceService shippingInvoiceService;
|
private PlatformOrderShippingInvoiceService shippingInvoiceService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlatformOrderMapper platformOrderMapper;
|
private PlatformOrderMapper platformOrderMapper;
|
||||||
|
@ -93,8 +87,6 @@ public class InvoiceController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IProductService productService;
|
private IProductService productService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProviderMabangServiceImpl providerMabangService;
|
|
||||||
@Autowired
|
|
||||||
private IPurchaseOrderService purchaseOrderService;
|
private IPurchaseOrderService purchaseOrderService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private PurchaseOrderContentMapper purchaseOrderContentMapper;
|
private PurchaseOrderContentMapper purchaseOrderContentMapper;
|
||||||
|
@ -119,7 +111,7 @@ public class InvoiceController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysBaseAPI ISysBaseApi;
|
private ISysBaseAPI ISysBaseApi;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysDepartService sysDepartService;
|
private ISecurityService securityService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IUserClientService userClientService;
|
private IUserClientService userClientService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -228,7 +220,7 @@ public class InvoiceController {
|
||||||
}
|
}
|
||||||
@PostMapping(value = "/period")
|
@PostMapping(value = "/period")
|
||||||
public Result<?> getValidPeriod(@RequestBody List<String> shopIDs) {
|
public Result<?> getValidPeriod(@RequestBody List<String> shopIDs) {
|
||||||
log.info("Request for valid period for shops: " + shopIDs.toString());
|
log.info("Request for valid period for shops: {}", shopIDs.toString());
|
||||||
Period period = shippingInvoiceService.getValidPeriod(shopIDs);
|
Period period = shippingInvoiceService.getValidPeriod(shopIDs);
|
||||||
if (period.isValid())
|
if (period.isValid())
|
||||||
return Result.OK(period);
|
return Result.OK(period);
|
||||||
|
@ -455,8 +447,7 @@ public class InvoiceController {
|
||||||
}
|
}
|
||||||
@GetMapping(value = "/preShipping/orderTime")
|
@GetMapping(value = "/preShipping/orderTime")
|
||||||
public Result<?> getValidOrderTimePeriod(@RequestParam("shopIds[]") List<String> shopIDs, @RequestParam("erpStatuses[]") List<Integer> erpStatuses) {
|
public Result<?> getValidOrderTimePeriod(@RequestParam("shopIds[]") List<String> shopIDs, @RequestParam("erpStatuses[]") List<Integer> erpStatuses) {
|
||||||
log.info("Request for valid order time period for shops: " + shopIDs.toString() +
|
log.info("Request for valid order time period for shops: {} and erpStatuses : {}", shopIDs.toString(), erpStatuses.toString());
|
||||||
" and erpStatuses : " + erpStatuses.toString());
|
|
||||||
Period period = shippingInvoiceService.getValidOrderTimePeriod(shopIDs, erpStatuses);
|
Period period = shippingInvoiceService.getValidOrderTimePeriod(shopIDs, erpStatuses);
|
||||||
if (period.isValid()) {
|
if (period.isValid()) {
|
||||||
return Result.OK(period);
|
return Result.OK(period);
|
||||||
|
@ -475,15 +466,15 @@ public class InvoiceController {
|
||||||
public Result<?> getOrdersBetweenOrderDates(PlatformOrder platformOrder, @RequestBody ShippingInvoiceParam param, HttpServletRequest req) {
|
public Result<?> getOrdersBetweenOrderDates(PlatformOrder platformOrder, @RequestBody ShippingInvoiceParam param, HttpServletRequest req) {
|
||||||
QueryWrapper<PlatformOrder> queryWrapper = QueryGenerator.initQueryWrapper(platformOrder, req.getParameterMap());
|
QueryWrapper<PlatformOrder> queryWrapper = QueryGenerator.initQueryWrapper(platformOrder, req.getParameterMap());
|
||||||
LambdaQueryWrapper<PlatformOrder> lambdaQueryWrapper = queryWrapper.lambda();
|
LambdaQueryWrapper<PlatformOrder> lambdaQueryWrapper = queryWrapper.lambda();
|
||||||
log.info("Requesting orders for : " + param.toString());
|
log.info("Requesting orders for : {}", param.toString());
|
||||||
if (param.shopIDs() == null || param.shopIDs().isEmpty()) {
|
if (param.shopIDs() == null || param.shopIDs().isEmpty()) {
|
||||||
return Result.error("Missing shop IDs");
|
return Result.error("Missing shop IDs");
|
||||||
}
|
}
|
||||||
log.info("Specified shop IDs : " + param.shopIDs());
|
log.info("Specified shop IDs : {}", param.shopIDs());
|
||||||
lambdaQueryWrapper.in(PlatformOrder::getShopId, param.shopIDs());
|
lambdaQueryWrapper.in(PlatformOrder::getShopId, param.shopIDs());
|
||||||
lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber);
|
lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber);
|
||||||
if(param.getErpStatuses() != null) {
|
if(param.getErpStatuses() != null) {
|
||||||
log.info("Specified erpStatuses : " + param.getErpStatuses());
|
log.info("Specified erpStatuses : {}", param.getErpStatuses());
|
||||||
lambdaQueryWrapper.in(PlatformOrder::getErpStatus, param.getErpStatuses());
|
lambdaQueryWrapper.in(PlatformOrder::getErpStatus, param.getErpStatuses());
|
||||||
}
|
}
|
||||||
lambdaQueryWrapper.inSql(PlatformOrder::getId, "SELECT id FROM platform_order po WHERE po.order_time between '" + param.getStart() + "' AND '" + param.getEnd() + "'" );
|
lambdaQueryWrapper.inSql(PlatformOrder::getId, "SELECT id FROM platform_order po WHERE po.order_time between '" + param.getStart() + "' AND '" + param.getEnd() + "'" );
|
||||||
|
@ -516,24 +507,54 @@ public class InvoiceController {
|
||||||
* @return A triplet of order, shipping invoice availability and purchase invoice availability
|
* @return A triplet of order, shipping invoice availability and purchase invoice availability
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/preShipping/ordersStatusByShops")
|
@GetMapping(value = "/preShipping/ordersStatusByShops")
|
||||||
public Result<?> getOrdersStatusByShops(@RequestParam("shopIds") String shopIds) {
|
public Result<?> getOrdersStatusByShops(@RequestParam("shopIds") String shopIds,
|
||||||
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||||
|
@RequestParam(name = "pageSize", defaultValue = "50") Integer pageSize,
|
||||||
|
@RequestParam(name = "column", defaultValue = "order_time") String column,
|
||||||
|
@RequestParam(name = "order", defaultValue = "ASC") String order) {
|
||||||
log.info("User : {} is requesting uninvoiced orders for shops : [{}]",
|
log.info("User : {} is requesting uninvoiced orders for shops : [{}]",
|
||||||
((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername(),
|
((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername(),
|
||||||
shopIds);
|
shopIds);
|
||||||
|
String parsedColumn = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, column.replace("_dictText",""));
|
||||||
|
String parsedOrder = order.toUpperCase();
|
||||||
|
if(!parsedOrder.equals("ASC") && !parsedOrder.equals("DESC")) {
|
||||||
|
return Result.error("Error 400 Bad Request");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
specialFilterContentForDictSql(parsedColumn);
|
||||||
|
}
|
||||||
|
catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("Error 400 : Bad Request");
|
||||||
|
}
|
||||||
// checking shipping data availability
|
// checking shipping data availability
|
||||||
List<String> shopIdList = Arrays.asList(shopIds.split(","));
|
List<String> shopIdList = Arrays.asList(shopIds.split(","));
|
||||||
// fetch order that can be invoice either by shipping or purchase or both
|
// fetch order that can be invoiced either by shipping or purchase or both
|
||||||
List<PlatformOrder> orders = platformOrderService.findUninvoicedOrdersByShopForClient(shopIdList, Collections.singletonList(1));
|
LinkedList<PlatformOrder> allOrders = platformOrderService.findUninvoicedOrdersByShopForClient(shopIdList, Collections.singletonList(1), parsedColumn, parsedOrder, 1, -1);
|
||||||
|
int total = allOrders.size();
|
||||||
|
LinkedList<PlatformOrder> orders = platformOrderService.findUninvoicedOrdersByShopForClient(shopIdList, Collections.singletonList(1), parsedColumn, parsedOrder, pageNo, pageSize);
|
||||||
|
// LinkedList<PlatformOrder> sortedOrders = orders.stream().sorted(Comparator.comparing(PlatformOrder::getOrderTime)).collect(Collectors.toCollection(LinkedList::new));
|
||||||
if(orders.isEmpty())
|
if(orders.isEmpty())
|
||||||
return Result.OK("No order to invoice.");
|
return Result.OK("No order to invoice.");
|
||||||
Map<String, String> shops = shopService.listByIds(shopIdList).stream().collect(Collectors.toMap(Shop::getId, Shop::getName));
|
Map<String, String> shops = shopService.listByIds(shopIdList).stream().collect(Collectors.toMap(Shop::getId, Shop::getName));
|
||||||
List<String> orderIds = orders.stream().map(PlatformOrder::getId).collect(Collectors.toList());
|
List<String> orderIds = orders.stream().map(PlatformOrder::getId).collect(Collectors.toList());
|
||||||
Map<PlatformOrder, List<PlatformOrderContent>> orderContentMap = platformOrderService.fetchOrderData(orderIds);
|
Map<PlatformOrder, List<PlatformOrderContent>> orderContentMap = platformOrderService.fetchOrderData(orderIds);
|
||||||
|
// some orders may not have content, so we have to re-add them
|
||||||
|
if(orderIds.size() != orderContentMap.size()) {
|
||||||
|
List<String> orderIdsInMap = orderContentMap.keySet().stream().map(PlatformOrder::getId).collect(Collectors.toList());
|
||||||
|
List<String> orderIdsWithoutContent = orderIds.stream().filter(id -> !orderIdsInMap.contains(id)).collect(Collectors.toList());
|
||||||
|
List<PlatformOrder> ordersWithoutContent = platformOrderService.listByIds(orderIdsWithoutContent);
|
||||||
|
Map<PlatformOrder, List<PlatformOrderContent>> orderContentMapWithoutContent = new HashMap<>();
|
||||||
|
for(PlatformOrder po : ordersWithoutContent) {
|
||||||
|
orderContentMapWithoutContent.put(po, new ArrayList<>());
|
||||||
|
}
|
||||||
|
orderContentMap.putAll(orderContentMapWithoutContent);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, String> errorMapToOrderId = new HashMap<>();
|
Map<String, String> errorMapToOrderId = new HashMap<>();
|
||||||
List<PlatformOrderFront> orderFronts = new ArrayList<>();
|
List<PlatformOrderFront> orderFronts = new ArrayList<>();
|
||||||
|
|
||||||
|
int tmpCpt = 0;
|
||||||
for(Map.Entry<PlatformOrder, List<PlatformOrderContent>> entry : orderContentMap.entrySet()) {
|
for(Map.Entry<PlatformOrder, List<PlatformOrderContent>> entry : orderContentMap.entrySet()) {
|
||||||
PlatformOrderFront orderFront = new PlatformOrderFront();
|
PlatformOrderFront orderFront = new PlatformOrderFront();
|
||||||
BeanUtils.copyProperties(entry.getKey(), orderFront);
|
BeanUtils.copyProperties(entry.getKey(), orderFront);
|
||||||
|
@ -543,6 +564,18 @@ public class InvoiceController {
|
||||||
// set default value of shipping and purchase availability
|
// set default value of shipping and purchase availability
|
||||||
orderFront.setShippingAvailable(PlatformOrderFront.invoiceStatus.Available.code);
|
orderFront.setShippingAvailable(PlatformOrderFront.invoiceStatus.Available.code);
|
||||||
orderFront.setPurchaseAvailable(PlatformOrderFront.invoiceStatus.Available.code);
|
orderFront.setPurchaseAvailable(PlatformOrderFront.invoiceStatus.Available.code);
|
||||||
|
|
||||||
|
if(entry.getValue().isEmpty()) {
|
||||||
|
if(!errorMapToOrderId.containsKey(entry.getKey().getPlatformOrderId()))
|
||||||
|
errorMapToOrderId.put(entry.getKey().getPlatformOrderId(), "Error : order has no content : " + entry.getKey().getPlatformOrderId());
|
||||||
|
else
|
||||||
|
errorMapToOrderId.put(entry.getKey().getPlatformOrderId(), errorMapToOrderId.get(entry.getKey().getPlatformOrderId()) + " and has no content");
|
||||||
|
orderFront.setShippingAvailable(PlatformOrderFront.invoiceStatus.Unavailable.code);
|
||||||
|
orderFront.setPurchaseAvailable(PlatformOrderFront.invoiceStatus.Unavailable.code);
|
||||||
|
orderFronts.add(orderFront);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> skuIds = entry.getValue().stream().map(PlatformOrderContent::getSkuId).distinct().collect(Collectors.toList());
|
List<String> skuIds = entry.getValue().stream().map(PlatformOrderContent::getSkuId).distinct().collect(Collectors.toList());
|
||||||
// finds the first sku that isn't in db
|
// finds the first sku that isn't in db
|
||||||
List<Sku> skuIdsFound = skuService.listByIds(skuIds);
|
List<Sku> skuIdsFound = skuService.listByIds(skuIds);
|
||||||
|
@ -554,6 +587,7 @@ public class InvoiceController {
|
||||||
|
|
||||||
orderFront.setShippingAvailable(PlatformOrderFront.invoiceStatus.Unavailable.code);
|
orderFront.setShippingAvailable(PlatformOrderFront.invoiceStatus.Unavailable.code);
|
||||||
orderFront.setPurchaseAvailable(PlatformOrderFront.invoiceStatus.Unavailable.code);
|
orderFront.setPurchaseAvailable(PlatformOrderFront.invoiceStatus.Unavailable.code);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entry.getKey().getShippingInvoiceNumber() == null) {
|
if(entry.getKey().getShippingInvoiceNumber() == null) {
|
||||||
|
@ -646,7 +680,9 @@ public class InvoiceController {
|
||||||
|
|
||||||
IPage<PlatformOrderFront> page = new Page<>();
|
IPage<PlatformOrderFront> page = new Page<>();
|
||||||
page.setRecords(orderFronts);
|
page.setRecords(orderFronts);
|
||||||
page.setTotal(orderFronts.size());
|
page.setSize(pageSize);
|
||||||
|
page.setCurrent(pageNo);
|
||||||
|
page.setTotal(total);
|
||||||
return Result.OK(page);
|
return Result.OK(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -661,11 +697,11 @@ public class InvoiceController {
|
||||||
public Result<?> getOrdersBetweenDates(PlatformOrder platformOrder, @RequestBody ShippingInvoiceParam param, HttpServletRequest req) {
|
public Result<?> getOrdersBetweenDates(PlatformOrder platformOrder, @RequestBody ShippingInvoiceParam param, HttpServletRequest req) {
|
||||||
QueryWrapper<PlatformOrder> queryWrapper = QueryGenerator.initQueryWrapper(platformOrder, req.getParameterMap());
|
QueryWrapper<PlatformOrder> queryWrapper = QueryGenerator.initQueryWrapper(platformOrder, req.getParameterMap());
|
||||||
LambdaQueryWrapper<PlatformOrder> lambdaQueryWrapper = queryWrapper.lambda();
|
LambdaQueryWrapper<PlatformOrder> lambdaQueryWrapper = queryWrapper.lambda();
|
||||||
log.info("Requesting orders for : " + param.toString());
|
log.info("Requesting orders for : {}", param.toString());
|
||||||
if (param.shopIDs() == null || param.shopIDs().isEmpty()) {
|
if (param.shopIDs() == null || param.shopIDs().isEmpty()) {
|
||||||
return Result.error("Missing shop IDs");
|
return Result.error("Missing shop IDs");
|
||||||
}
|
}
|
||||||
log.info("Specified shop IDs : " + param.shopIDs());
|
log.info("Specified shop IDs : {}", param.shopIDs());
|
||||||
lambdaQueryWrapper.in(PlatformOrder::getShopId, param.shopIDs());
|
lambdaQueryWrapper.in(PlatformOrder::getShopId, param.shopIDs());
|
||||||
lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber);
|
lambdaQueryWrapper.isNull(PlatformOrder::getShippingInvoiceNumber);
|
||||||
lambdaQueryWrapper.inSql(PlatformOrder::getId, "SELECT id FROM platform_order po WHERE po.erp_status = '3' AND po.shipping_time between '" + param.getStart() + "' AND '" + param.getEnd() + "'" );
|
lambdaQueryWrapper.inSql(PlatformOrder::getId, "SELECT id FROM platform_order po WHERE po.erp_status = '3' AND po.shipping_time between '" + param.getStart() + "' AND '" + param.getEnd() + "'" );
|
||||||
|
@ -897,14 +933,20 @@ public class InvoiceController {
|
||||||
* @param param Parameters for creating a pre-shipping invoice
|
* @param param Parameters for creating a pre-shipping invoice
|
||||||
* @return One ShippingFeesEstimation
|
* @return One ShippingFeesEstimation
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/selfEstimateFees")
|
@PostMapping(value = "/completeFeesEstimation")
|
||||||
public Result<?> getPurchaseFeesEstimateByOrders(@RequestBody ShippingInvoiceOrderParam param) {
|
public Result<?> getCompleteFeesEstimation(@RequestBody ShippingInvoiceOrderParam param) {
|
||||||
|
boolean isEmployee = securityService.checkIsEmployee();
|
||||||
String currency = clientService.getById(param.clientID()).getCurrency();
|
String currency = clientService.getById(param.clientID()).getCurrency();
|
||||||
List<PlatformOrder> orders = platformOrderMapper.fetchByIds(param.orderIds());
|
List<PlatformOrder> orders = platformOrderMapper.fetchByIds(param.orderIds());
|
||||||
Map<String, List<PlatformOrder>> ordersMapByShop = orders.stream().collect(Collectors.groupingBy(PlatformOrder::getShopId));
|
Map<String, List<PlatformOrder>> ordersMapByShop = orders.stream().collect(Collectors.groupingBy(PlatformOrder::getShopId));
|
||||||
Map<String, Estimation> estimationsByShop = new HashMap<>();
|
Map<String, Estimation> estimationsByShop = new HashMap<>();
|
||||||
for(Map.Entry<String, List<PlatformOrder>> entry : ordersMapByShop.entrySet()) {
|
for(Map.Entry<String, List<PlatformOrder>> entry : ordersMapByShop.entrySet()) {
|
||||||
String shopId = entry.getKey();
|
String shopId = entry.getKey();
|
||||||
|
String shop;
|
||||||
|
if(!isEmployee)
|
||||||
|
shop = shopService.getNameById(shopId);
|
||||||
|
else
|
||||||
|
shop = shopService.getCodeById(shopId);
|
||||||
List<String> orderIds = entry.getValue().stream().map(PlatformOrder::getId).collect(Collectors.toList());
|
List<String> orderIds = entry.getValue().stream().map(PlatformOrder::getId).collect(Collectors.toList());
|
||||||
ShippingInvoiceOrderParam finalParam = new ShippingInvoiceOrderParam(param.clientID(), orderIds, param.getType());
|
ShippingInvoiceOrderParam finalParam = new ShippingInvoiceOrderParam(param.clientID(), orderIds, param.getType());
|
||||||
List<String> errorMessages = new ArrayList<>();
|
List<String> errorMessages = new ArrayList<>();
|
||||||
|
@ -912,6 +954,7 @@ public class InvoiceController {
|
||||||
finalParam.orderIds(), errorMessages);
|
finalParam.orderIds(), errorMessages);
|
||||||
if(shippingFeesEstimations.isEmpty())
|
if(shippingFeesEstimations.isEmpty())
|
||||||
return Result.OK("No estimation found.");
|
return Result.OK("No estimation found.");
|
||||||
|
String internalCode = shippingFeesEstimations.get(0).getCode();
|
||||||
|
|
||||||
// purchase estimation
|
// purchase estimation
|
||||||
// only calculate purchase estimation if products are not available and purchaseInvoiceNumber is null, else it's already been paid
|
// only calculate purchase estimation if products are not available and purchaseInvoiceNumber is null, else it's already been paid
|
||||||
|
@ -921,25 +964,37 @@ public class InvoiceController {
|
||||||
&& order.getPurchaseInvoiceNumber() == null
|
&& order.getPurchaseInvoiceNumber() == null
|
||||||
&& order.getVirtualProductAvailable().equals("0"))
|
&& order.getVirtualProductAvailable().equals("0"))
|
||||||
.map(PlatformOrder::getId).collect(Collectors.toList());
|
.map(PlatformOrder::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
BigDecimal shippingFeesEstimation = BigDecimal.ZERO;
|
BigDecimal shippingFeesEstimation = BigDecimal.ZERO;
|
||||||
BigDecimal purchaseEstimation = BigDecimal.ZERO;
|
BigDecimal purchaseEstimation = BigDecimal.ZERO;
|
||||||
|
int ordersToProccess = 0;
|
||||||
|
int processedOrders = 0;
|
||||||
boolean isCompleteInvoiceReady = true;
|
boolean isCompleteInvoiceReady = true;
|
||||||
|
|
||||||
for(ShippingFeesEstimation estimation: shippingFeesEstimations) {
|
for(ShippingFeesEstimation estimation: shippingFeesEstimations) {
|
||||||
shippingFeesEstimation = shippingFeesEstimation.add(estimation.getDueForProcessedOrders());
|
shippingFeesEstimation = shippingFeesEstimation.add(estimation.getDueForProcessedOrders());
|
||||||
|
ordersToProccess += estimation.getOrdersToProcess();
|
||||||
|
processedOrders += estimation.getProcessedOrders();
|
||||||
}
|
}
|
||||||
if(!orderIdsWithProductUnavailable.isEmpty()) {
|
if(!orderIdsWithProductUnavailable.isEmpty()) {
|
||||||
List<PlatformOrderContent> orderContents = platformOrderContentMap.fetchOrderContent(orderIdsWithProductUnavailable);
|
List<PlatformOrderContent> orderContents = platformOrderContentMap.fetchOrderContent(orderIdsWithProductUnavailable);
|
||||||
List<String> skuIds = orderContents.stream().map(PlatformOrderContent::getSkuId).collect(Collectors.toList());
|
List<String> skuIds = orderContents.stream().map(PlatformOrderContent::getSkuId).collect(Collectors.toList());
|
||||||
List<SkuPrice> skuPrices = platformOrderContentMap.searchSkuPrice(skuIds);
|
List<SkuPrice> skuPrices = platformOrderContentMap.searchSkuPrice(skuIds);
|
||||||
BigDecimal exchangeRateEurToRmb = exchangeRatesMapper.getLatestExchangeRate("EUR", "RMB");
|
BigDecimal exchangeRateEurToRmb = exchangeRatesMapper.getLatestExchangeRate("EUR", "RMB");
|
||||||
if(skuPrices.size() != skuIds.size()) {
|
for(SkuPrice skuPrice : skuPrices) {
|
||||||
isCompleteInvoiceReady = false;
|
if(skuPrice.getPrice() == null) {
|
||||||
errorMessages.add("Some sku prices are missing.");
|
isCompleteInvoiceReady = false;
|
||||||
|
errorMessages.add("Some sku prices are missing.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for(PlatformOrderContent content : orderContents){
|
for(PlatformOrderContent content : orderContents){
|
||||||
for (SkuPrice skuPrice : skuPrices) {
|
for (SkuPrice skuPrice : skuPrices) {
|
||||||
if(content.getSkuId().equals(skuPrice.getSkuId())) {
|
if(content.getSkuId().equals(skuPrice.getSkuId())) {
|
||||||
purchaseEstimation = purchaseEstimation.add(skuPrice.getPrice(content.getQuantity(), exchangeRateEurToRmb));
|
BigDecimal price = skuPrice.getPrice(content.getQuantity(), exchangeRateEurToRmb);
|
||||||
|
price = price.multiply(new BigDecimal(content.getQuantity()));
|
||||||
|
purchaseEstimation = purchaseEstimation.add(price);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -952,9 +1007,9 @@ public class InvoiceController {
|
||||||
purchaseEstimation = purchaseEstimation.multiply(exchangeRate).setScale(2, RoundingMode.CEILING);
|
purchaseEstimation = purchaseEstimation.multiply(exchangeRate).setScale(2, RoundingMode.CEILING);
|
||||||
shippingFeesEstimation = shippingFeesEstimation.multiply(exchangeRate).setScale(2, RoundingMode.CEILING);
|
shippingFeesEstimation = shippingFeesEstimation.multiply(exchangeRate).setScale(2, RoundingMode.CEILING);
|
||||||
}
|
}
|
||||||
log.info("Purchase Fee " + currency + " : " + purchaseEstimation);
|
log.info("Purchase Fee {} : {}", currency, purchaseEstimation);
|
||||||
log.info("Shipping Fee " + currency + " : " + shippingFeesEstimation);
|
log.info("Shipping Fee {} : {}", currency, shippingFeesEstimation);
|
||||||
estimationsByShop.put(shopId, new Estimation(shippingFeesEstimation, purchaseEstimation, currency, errorMessages, Collections.singletonList(shopId), "", "", isCompleteInvoiceReady));
|
estimationsByShop.put(shopId, new Estimation(internalCode, ordersToProccess, processedOrders, shippingFeesEstimation, purchaseEstimation, currency, errorMessages, shop, Collections.singletonList(shopId), "", "", isCompleteInvoiceReady, orderIds));
|
||||||
}
|
}
|
||||||
// return list of estimation by shop
|
// return list of estimation by shop
|
||||||
return Result.ok(estimationsByShop);
|
return Result.ok(estimationsByShop);
|
||||||
|
@ -962,9 +1017,8 @@ public class InvoiceController {
|
||||||
|
|
||||||
@GetMapping(value = "/checkInvoiceValidity")
|
@GetMapping(value = "/checkInvoiceValidity")
|
||||||
public Result<?> checkInvoiceValidity(@RequestParam("invoiceNumber") String invoiceNumber) {
|
public Result<?> checkInvoiceValidity(@RequestParam("invoiceNumber") String invoiceNumber) {
|
||||||
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
|
boolean isEmployee = securityService.checkIsEmployee();
|
||||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
String orgCode = sysUser.getOrgCode();
|
|
||||||
String email = sysUser.getEmail();
|
String email = sysUser.getEmail();
|
||||||
String invoiceID;
|
String invoiceID;
|
||||||
String customerFullName;
|
String customerFullName;
|
||||||
|
@ -985,7 +1039,7 @@ public class InvoiceController {
|
||||||
client = clientService.getClientFromPurchase(invoiceID);
|
client = clientService.getClientFromPurchase(invoiceID);
|
||||||
customerFullName = client.fullName();
|
customerFullName = client.fullName();
|
||||||
String destEmail;
|
String destEmail;
|
||||||
if(!orgCode.equals(companyOrgCode)) {
|
if(!isEmployee) {
|
||||||
log.info("User {} is trying to access invoice {} from client {}", sysUser.getUsername(), invoiceNumber, client.getInternalCode());
|
log.info("User {} is trying to access invoice {} from client {}", sysUser.getUsername(), invoiceNumber, client.getInternalCode());
|
||||||
Client userClient = userClientService.getClientByUserId(sysUser.getId());
|
Client userClient = userClientService.getClientByUserId(sysUser.getId());
|
||||||
|
|
||||||
|
|
|
@ -93,10 +93,14 @@ public class TransactionController {
|
||||||
List<String> errorMessages = new ArrayList<>();
|
List<String> errorMessages = new ArrayList<>();
|
||||||
List<String> shopIds = shopService.listIdByClient(clientId);
|
List<String> shopIds = shopService.listIdByClient(clientId);
|
||||||
List<PlatformOrder> shippingOrders = platformOrderService.findUninvoicedShippingOrdersByShopForClient(shopIds, Arrays.asList(1,2,3));
|
List<PlatformOrder> shippingOrders = platformOrderService.findUninvoicedShippingOrdersByShopForClient(shopIds, Arrays.asList(1,2,3));
|
||||||
|
List<String> orderIds = shippingOrders.stream().map(PlatformOrder::getId).collect(Collectors.toList());
|
||||||
Date startDate = null;
|
Date startDate = null;
|
||||||
Date endDate = null;
|
Date endDate = null;
|
||||||
List<ShippingFeesEstimation> shippingFeesEstimations;
|
List<ShippingFeesEstimation> shippingFeesEstimations;
|
||||||
BigDecimal shippingFeesEstimation = BigDecimal.ZERO;
|
BigDecimal shippingFeesEstimation = BigDecimal.ZERO;
|
||||||
|
String internalCode = "";
|
||||||
|
int ordersToProcess = 0;
|
||||||
|
int processedOrders = 0;
|
||||||
if(!shippingOrders.isEmpty()) {
|
if(!shippingOrders.isEmpty()) {
|
||||||
startDate = shippingOrders.stream().map(PlatformOrder::getOrderTime).min(Date::compareTo).get();
|
startDate = shippingOrders.stream().map(PlatformOrder::getOrderTime).min(Date::compareTo).get();
|
||||||
endDate = shippingOrders.stream().map(PlatformOrder::getOrderTime).max(Date::compareTo).get();
|
endDate = shippingOrders.stream().map(PlatformOrder::getOrderTime).max(Date::compareTo).get();
|
||||||
|
@ -109,7 +113,10 @@ public class TransactionController {
|
||||||
shippingFeesEstimations = factory.getEstimations(clientId, shippingOrderIds, errorMessages);
|
shippingFeesEstimations = factory.getEstimations(clientId, shippingOrderIds, errorMessages);
|
||||||
for (ShippingFeesEstimation estimation : shippingFeesEstimations) {
|
for (ShippingFeesEstimation estimation : shippingFeesEstimations) {
|
||||||
shippingFeesEstimation = shippingFeesEstimation.add(estimation.getDueForProcessedOrders());
|
shippingFeesEstimation = shippingFeesEstimation.add(estimation.getDueForProcessedOrders());
|
||||||
|
ordersToProcess += estimation.getOrdersToProcess();
|
||||||
|
processedOrders += estimation.getProcessedOrders();
|
||||||
}
|
}
|
||||||
|
internalCode = shippingFeesEstimations.get(0).getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// purchase estimation
|
// purchase estimation
|
||||||
|
@ -160,8 +167,8 @@ public class TransactionController {
|
||||||
shippingFeesEstimation = shippingFeesEstimation.multiply(exchangeRate).setScale(2, RoundingMode.CEILING);
|
shippingFeesEstimation = shippingFeesEstimation.multiply(exchangeRate).setScale(2, RoundingMode.CEILING);
|
||||||
|
|
||||||
}
|
}
|
||||||
log.info("Purchase Fee " + currency + " : " + purchaseEstimation);
|
log.info("Purchase Fee {} : {}", currency, purchaseEstimation);
|
||||||
log.info("Shipping Fee " + currency + " : " + shippingFeesEstimation);
|
log.info("Shipping Fee {} : {}", currency, shippingFeesEstimation);
|
||||||
// system notification
|
// system notification
|
||||||
String errors = SECTION_START;
|
String errors = SECTION_START;
|
||||||
int max_entries = 100;
|
int max_entries = 100;
|
||||||
|
@ -184,6 +191,6 @@ public class TransactionController {
|
||||||
ISysBaseApi.sendTemplateAnnouncement(message);
|
ISysBaseApi.sendTemplateAnnouncement(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Result.ok(new Estimation(shippingFeesEstimation, purchaseEstimation, currency, errorMessages, shopIds, new DateTime(startDate).toString(), new DateTime(endDate).toString(), isCompleteInvoiceReady));
|
return Result.ok(new Estimation(internalCode, ordersToProcess, processedOrders, shippingFeesEstimation, purchaseEstimation, currency, errorMessages,null, shopIds, new DateTime(startDate).toString(), new DateTime(endDate).toString(), isCompleteInvoiceReady, orderIds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import lombok.Setter;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.RequestBody;
|
import org.jeecg.modules.business.domain.api.mabang.RequestBody;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.getorderlist.Order;
|
import org.jeecg.modules.business.domain.api.mabang.getorderlist.Order;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.getorderlist.OrderItem;
|
import org.jeecg.modules.business.domain.api.mabang.getorderlist.OrderItem;
|
||||||
|
import org.jeecg.modules.business.vo.PlatformOrderOperation;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ public class ChangeWarehouseRequestBody implements RequestBody {
|
||||||
private String recipient;
|
private String recipient;
|
||||||
private String street1;
|
private String street1;
|
||||||
private String street2;
|
private String street2;
|
||||||
|
private String phone;
|
||||||
|
|
||||||
public ChangeWarehouseRequestBody(Order order, String warehouseName) {
|
public ChangeWarehouseRequestBody(Order order, String warehouseName) {
|
||||||
this.platformOrderId = order.getPlatformOrderId();
|
this.platformOrderId = order.getPlatformOrderId();
|
||||||
|
@ -27,8 +29,16 @@ public class ChangeWarehouseRequestBody implements RequestBody {
|
||||||
this.recipient = order.getRecipient();
|
this.recipient = order.getRecipient();
|
||||||
this.street1 = order.getAddress();
|
this.street1 = order.getAddress();
|
||||||
this.street2 = order.getAddress2();
|
this.street2 = order.getAddress2();
|
||||||
|
this.phone = order.getPhone1();
|
||||||
this.order = order;
|
this.order = order;
|
||||||
}
|
}
|
||||||
|
public ChangeWarehouseRequestBody(PlatformOrderOperation order) {
|
||||||
|
this.setOrderId(order.getOrderIds());
|
||||||
|
this.recipient = order.getRecipient();
|
||||||
|
this.street1 = order.getStreet1();
|
||||||
|
this.street2 = order.getStreet2();
|
||||||
|
this.phone = order.getPhone();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String api() {
|
public String api() {
|
||||||
|
@ -43,6 +53,9 @@ public class ChangeWarehouseRequestBody implements RequestBody {
|
||||||
putNonNull(json, "buyerName", recipient);
|
putNonNull(json, "buyerName", recipient);
|
||||||
putNonNull(json, "street1", street1);
|
putNonNull(json, "street1", street1);
|
||||||
putNonNull(json, "street2", street2);
|
putNonNull(json, "street2", street2);
|
||||||
|
putNonNull(json, "phone1", phone);
|
||||||
|
if(order == null)
|
||||||
|
return json;
|
||||||
if(order.getOrderItems() != null && !order.getOrderItems().isEmpty()) {
|
if(order.getOrderItems() != null && !order.getOrderItems().isEmpty()) {
|
||||||
for(OrderItem orderItem : order.getOrderItems()) {
|
for(OrderItem orderItem : order.getOrderItems()) {
|
||||||
if(!isSkuValidFormat(orderItem.getErpCode()))
|
if(!isSkuValidFormat(orderItem.getErpCode()))
|
||||||
|
@ -72,4 +85,8 @@ public class ChangeWarehouseRequestBody implements RequestBody {
|
||||||
json.put(key, mapper.apply(value));
|
json.put(key, mapper.apply(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void setOrderId(String orderId) {
|
||||||
|
// clean string from spaces, comas and quotes
|
||||||
|
this.platformOrderId = orderId.replaceAll("[,\\s\"]", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.jeecg.modules.business.domain.api.mabang.getorderlist.*;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendRequest;
|
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendRequest;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendRequestBody;
|
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendRequestBody;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendResponse;
|
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendResponse;
|
||||||
|
import org.jeecg.modules.business.service.IPlatformOrderMabangService;
|
||||||
import org.jeecg.modules.business.service.IPlatformOrderService;
|
import org.jeecg.modules.business.service.IPlatformOrderService;
|
||||||
import org.jeecg.modules.business.vo.Responses;
|
import org.jeecg.modules.business.vo.Responses;
|
||||||
import org.quartz.Job;
|
import org.quartz.Job;
|
||||||
|
@ -18,14 +19,12 @@ import org.quartz.JobExecutionContext;
|
||||||
import org.quartz.JobExecutionException;
|
import org.quartz.JobExecutionException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.text.Normalizer;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
@ -34,6 +33,8 @@ import static java.util.stream.Collectors.toList;
|
||||||
public class ChangeWarehouseJob implements Job {
|
public class ChangeWarehouseJob implements Job {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IPlatformOrderService platformOrderService;
|
private IPlatformOrderService platformOrderService;
|
||||||
|
@Autowired
|
||||||
|
private IPlatformOrderMabangService platformOrderMabangService;
|
||||||
|
|
||||||
private static final Integer DEFAULT_NUMBER_OF_DAYS = 5;
|
private static final Integer DEFAULT_NUMBER_OF_DAYS = 5;
|
||||||
private static final Integer DEFAULT_NUMBER_OF_THREADS = 10;
|
private static final Integer DEFAULT_NUMBER_OF_THREADS = 10;
|
||||||
|
@ -179,14 +180,9 @@ public class ChangeWarehouseJob implements Job {
|
||||||
}
|
}
|
||||||
public void replaceOrdersAccents(List<Order> orders) {
|
public void replaceOrdersAccents(List<Order> orders) {
|
||||||
for(Order order: orders) {
|
for(Order order: orders) {
|
||||||
order.setRecipient(stripAccents(order.getRecipient()));
|
order.setRecipient(platformOrderMabangService.stripAccents(order.getRecipient()));
|
||||||
order.setAddress(stripAccents(order.getAddress()));
|
order.setAddress(platformOrderMabangService.stripAccents(order.getAddress()));
|
||||||
order.setAddress2(stripAccents(order.getAddress2()));
|
order.setAddress2(platformOrderMabangService.stripAccents(order.getAddress2()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public String stripAccents(String input) {
|
|
||||||
input = Normalizer.normalize(input, Normalizer.Form.NFD);
|
|
||||||
input = input.replaceAll("[^\\p{ASCII}]", "");
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.codehaus.jettison.json.JSONObject;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.*;
|
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.*;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.getorderlist.*;
|
import org.jeecg.modules.business.domain.api.mabang.getorderlist.*;
|
||||||
import org.jeecg.modules.business.entity.PlatformOrder;
|
import org.jeecg.modules.business.entity.PlatformOrder;
|
||||||
|
import org.jeecg.modules.business.service.IPlatformOrderMabangService;
|
||||||
import org.jeecg.modules.business.service.IPlatformOrderService;
|
import org.jeecg.modules.business.service.IPlatformOrderService;
|
||||||
import org.quartz.Job;
|
import org.quartz.Job;
|
||||||
import org.quartz.JobDataMap;
|
import org.quartz.JobDataMap;
|
||||||
|
@ -34,6 +35,8 @@ public class RemoveVirtualProductJob implements Job {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IPlatformOrderService platformOrderService;
|
private IPlatformOrderService platformOrderService;
|
||||||
|
@Autowired
|
||||||
|
private IPlatformOrderMabangService platformOrderMabangService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||||
|
@ -88,28 +91,8 @@ public class RemoveVirtualProductJob implements Job {
|
||||||
for (List<String> platformOrderIdList : platformOrderIdLists) {
|
for (List<String> platformOrderIdList : platformOrderIdLists) {
|
||||||
requests.add(new OrderListRequestBody().setPlatformOrderIds(platformOrderIdList));
|
requests.add(new OrderListRequestBody().setPlatformOrderIds(platformOrderIdList));
|
||||||
}
|
}
|
||||||
List<Order> mabangOrders = new ArrayList<>();
|
|
||||||
|
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(DEFAULT_NUMBER_OF_THREADS);
|
ExecutorService executor = Executors.newFixedThreadPool(DEFAULT_NUMBER_OF_THREADS);
|
||||||
List<CompletableFuture<Boolean>> futures = requests.stream()
|
List<Order> mabangOrders = platformOrderMabangService.getOrdersFromMabang(requests, executor);
|
||||||
.map(request -> CompletableFuture.supplyAsync(() -> {
|
|
||||||
boolean success = false;
|
|
||||||
try {
|
|
||||||
OrderListRawStream rawStream = new OrderListRawStream(request);
|
|
||||||
OrderListStream stream = new OrderListStream(rawStream);
|
|
||||||
List<Order> orders = stream.all();
|
|
||||||
mabangOrders.addAll(orders);
|
|
||||||
success = !orders.isEmpty();
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
log.error("Error communicating with MabangAPI", e);
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}, executor))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
List<Boolean> results = futures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
|
||||||
long nbSuccesses = results.stream().filter(b -> b).count();
|
|
||||||
log.info("{}/{} requests have succeeded.", nbSuccesses, requests.size());
|
|
||||||
log.info("{}/{} mabang orders have been retrieved.", mabangOrders.size(), platformOrderIds.size());
|
|
||||||
|
|
||||||
log.info("Constructing virtual SKU removal requests");
|
log.info("Constructing virtual SKU removal requests");
|
||||||
List<Order> ordersWithLogistic = new ArrayList<>();
|
List<Order> ordersWithLogistic = new ArrayList<>();
|
||||||
|
@ -139,17 +122,7 @@ public class RemoveVirtualProductJob implements Job {
|
||||||
log.info("{} virtual SKU removal requests to be sent to MabangAPI", removeSkuRequests.size());
|
log.info("{} virtual SKU removal requests to be sent to MabangAPI", removeSkuRequests.size());
|
||||||
|
|
||||||
// First we delete the logistic channel names, otherwise we can't delete virtual skus
|
// First we delete the logistic channel names, otherwise we can't delete virtual skus
|
||||||
List<CompletableFuture<Boolean>> clearLogisticFutures = ordersWithLogistic.stream()
|
platformOrderMabangService.clearLogisticChannel(ordersWithLogistic, executor);
|
||||||
.map(orderWithLogistic -> CompletableFuture.supplyAsync(() -> {
|
|
||||||
ClearLogisticRequestBody body = new ClearLogisticRequestBody(orderWithLogistic.getPlatformOrderId());
|
|
||||||
ClearLogisticRequest request = new ClearLogisticRequest(body);
|
|
||||||
ClearLogisticResponse response = request.send();
|
|
||||||
return response.success();
|
|
||||||
}, executor))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
List<Boolean> logisticResults = clearLogisticFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
|
||||||
long logisticClearSuccessCount = logisticResults.stream().filter(b -> b).count();
|
|
||||||
log.info("{}/{} logistic channel names cleared successfully.", logisticClearSuccessCount, ordersWithLogistic.size());
|
|
||||||
|
|
||||||
List<CompletableFuture<Boolean>> removeSkuFutures = removeSkuRequests.stream()
|
List<CompletableFuture<Boolean>> removeSkuFutures = removeSkuRequests.stream()
|
||||||
.map(removeSkuRequestBody -> CompletableFuture.supplyAsync(() -> {
|
.map(removeSkuRequestBody -> CompletableFuture.supplyAsync(() -> {
|
||||||
|
@ -164,8 +137,8 @@ public class RemoveVirtualProductJob implements Job {
|
||||||
return success;
|
return success;
|
||||||
}, executor))
|
}, executor))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
results = removeSkuFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
List<Boolean> results = removeSkuFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
nbSuccesses = results.stream().filter(b -> b).count();
|
long nbSuccesses = results.stream().filter(b -> b).count();
|
||||||
log.info("{}/{} virtual SKU removal requests have succeeded.", nbSuccesses, removeSkuRequests.size());
|
log.info("{}/{} virtual SKU removal requests have succeeded.", nbSuccesses, removeSkuRequests.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,39 +102,6 @@ public class ShippingInvoice implements Serializable {
|
||||||
@ApiModelProperty(value = "currency ID")
|
@ApiModelProperty(value = "currency ID")
|
||||||
private java.lang.String currencyId;
|
private java.lang.String currencyId;
|
||||||
|
|
||||||
public void setID(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
public void setCreateBy(String user) {
|
|
||||||
this.createBy = user;
|
|
||||||
}
|
|
||||||
public void setCreateTime(Date createTime) {
|
|
||||||
this.createTime = createTime;
|
|
||||||
}
|
|
||||||
public void setUpdateBy(String updateBy) {
|
|
||||||
this.updateBy = updateBy;
|
|
||||||
}
|
|
||||||
public void setUpdateTime(Date updateTime) {
|
|
||||||
this.updateTime = updateTime;
|
|
||||||
}
|
|
||||||
public void setClientI(String clientId) {
|
|
||||||
this.clientId = clientId;
|
|
||||||
}
|
|
||||||
public void setInvoiceNumber(String invoiceNumber) {
|
|
||||||
this.invoiceNumber = invoiceNumber;
|
|
||||||
}
|
|
||||||
public void setTotalAmount(java.math.BigDecimal totalAmount) {
|
|
||||||
this.totalAmount = totalAmount;
|
|
||||||
}
|
|
||||||
public void setDiscountAmount(java.math.BigDecimal discountAmount) {
|
|
||||||
this.discountAmount = discountAmount;
|
|
||||||
}
|
|
||||||
public void setFinalAmount(java.math.BigDecimal finalAmount) {
|
|
||||||
this.finalAmount = finalAmount;
|
|
||||||
}
|
|
||||||
public void setPaidAmount(java.math.BigDecimal paidAmount) {
|
|
||||||
this.paidAmount = paidAmount;
|
|
||||||
}
|
|
||||||
public ShippingInvoice() {
|
public ShippingInvoice() {
|
||||||
// this.id = null;
|
// this.id = null;
|
||||||
// this.createBy = null;
|
// this.createBy = null;
|
||||||
|
|
|
@ -13,10 +13,7 @@ import org.jeecg.modules.business.vo.clientPlatformOrder.section.OrderQuantity;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 平台订单表
|
* @Description: 平台订单表
|
||||||
|
@ -193,7 +190,8 @@ public interface PlatformOrderMapper extends BaseMapper<PlatformOrder> {
|
||||||
|
|
||||||
List<PlatformOrder> findUninvoicedShippingOrdersByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
|
List<PlatformOrder> findUninvoicedShippingOrdersByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
|
||||||
List<PlatformOrder> fetchUninvoicedPurchaseOrdersByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
|
List<PlatformOrder> fetchUninvoicedPurchaseOrdersByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
|
||||||
List<PlatformOrder> findUninvoicedOrdersByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
|
LinkedList<PlatformOrder> findUninvoicedOrdersByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses,
|
||||||
|
@Param("column") String column, @Param("order") String order, @Param("offset") Integer offset, @Param("size") Integer pageSize);
|
||||||
List<String> findUninvoicedOrderIdsByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
|
List<String> findUninvoicedOrderIdsByShopForClient(@Param("shopIds") List<String> shopIds, @Param("erpStatuses") List<Integer> erpStatuses);
|
||||||
|
|
||||||
List<PlatformOrder> fetchEmptyLogisticChannelOrders(@Param("startDate") String startDate,@Param("endDate") String endDate);
|
List<PlatformOrder> fetchEmptyLogisticChannelOrders(@Param("startDate") String startDate,@Param("endDate") String endDate);
|
||||||
|
|
|
@ -24,4 +24,8 @@ public interface ShopMapper extends BaseMapper<Shop> {
|
||||||
List<String> selectShopIdByClient(@Param("clientID") String clientID);
|
List<String> selectShopIdByClient(@Param("clientID") String clientID);
|
||||||
|
|
||||||
List<String> getShopIdsByClientAndType(@Param("clientIds") List<String> clientIds, @Param("type") String clientType);
|
List<String> getShopIdsByClientAndType(@Param("clientIds") List<String> clientIds, @Param("type") String clientType);
|
||||||
|
|
||||||
|
String getNameById(@Param("shopId") String shopId);
|
||||||
|
|
||||||
|
String getCodeById(@Param("shopId") String shopId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -334,7 +334,7 @@
|
||||||
</foreach>);
|
</foreach>);
|
||||||
</update>
|
</update>
|
||||||
<select id="searchSkuPrice" resultType="org.jeecg.modules.business.entity.SkuPrice">
|
<select id="searchSkuPrice" resultType="org.jeecg.modules.business.entity.SkuPrice">
|
||||||
SELECT * FROM sku_price
|
SELECT DISTINCT * FROM sku_price
|
||||||
WHERE sku_id IN
|
WHERE sku_id IN
|
||||||
<foreach collection="skuIds" separator="," open="(" close=")" index="index" item="skuId">
|
<foreach collection="skuIds" separator="," open="(" close=")" index="index" item="skuId">
|
||||||
#{skuId}
|
#{skuId}
|
||||||
|
|
|
@ -648,7 +648,7 @@
|
||||||
</foreach>;
|
</foreach>;
|
||||||
</select>
|
</select>
|
||||||
<select id="findUninvoicedOrdersByShopForClient" resultType="org.jeecg.modules.business.entity.PlatformOrder">
|
<select id="findUninvoicedOrdersByShopForClient" resultType="org.jeecg.modules.business.entity.PlatformOrder">
|
||||||
SELECT *
|
SELECT id, order_time, platform_order_number
|
||||||
FROM platform_order
|
FROM platform_order
|
||||||
WHERE erp_status IN
|
WHERE erp_status IN
|
||||||
<foreach
|
<foreach
|
||||||
|
@ -674,7 +674,12 @@
|
||||||
item="shopId"
|
item="shopId"
|
||||||
>
|
>
|
||||||
#{shopId}
|
#{shopId}
|
||||||
</foreach>;
|
</foreach>
|
||||||
|
ORDER BY ${column} ${order}
|
||||||
|
<if test="size != -1">
|
||||||
|
LIMIT #{offset}, #{size}
|
||||||
|
</if>
|
||||||
|
;
|
||||||
</select>
|
</select>
|
||||||
<insert id="insertPlatformOrdersArchives" parameterType="list">
|
<insert id="insertPlatformOrdersArchives" parameterType="list">
|
||||||
INSERT INTO platform_order_delete(id, create_by,
|
INSERT INTO platform_order_delete(id, create_by,
|
||||||
|
|
|
@ -35,4 +35,14 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
AND cc.name = #{type}
|
AND cc.name = #{type}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getNameById" resultType="java.lang.String">
|
||||||
|
SELECT name
|
||||||
|
FROM shop
|
||||||
|
WHERE id = #{shopId};
|
||||||
|
</select>
|
||||||
|
<select id="getCodeById" resultType="java.lang.String">
|
||||||
|
SELECT erp_code
|
||||||
|
FROM shop
|
||||||
|
WHERE id = #{shopId};
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -2,11 +2,13 @@ package org.jeecg.modules.business.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.getorderlist.Order;
|
import org.jeecg.modules.business.domain.api.mabang.getorderlist.Order;
|
||||||
|
import org.jeecg.modules.business.domain.api.mabang.getorderlist.OrderListRequestBody;
|
||||||
import org.jeecg.modules.business.vo.PlatformOrderOperation;
|
import org.jeecg.modules.business.vo.PlatformOrderOperation;
|
||||||
import org.jeecg.modules.business.vo.Responses;
|
import org.jeecg.modules.business.vo.Responses;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Services related to operations on {@code Order} entity
|
* Services related to operations on {@code Order} entity
|
||||||
|
@ -32,4 +34,10 @@ public interface IPlatformOrderMabangService extends IService<Order> {
|
||||||
Responses suspendOrder(PlatformOrderOperation orderOperation);
|
Responses suspendOrder(PlatformOrderOperation orderOperation);
|
||||||
|
|
||||||
Responses cancelOrders(PlatformOrderOperation orderOperation);
|
Responses cancelOrders(PlatformOrderOperation orderOperation);
|
||||||
|
|
||||||
|
List<Order> getOrdersFromMabang(List<OrderListRequestBody> requests, ExecutorService executor);
|
||||||
|
|
||||||
|
void clearLogisticChannel(List<Order> orders, ExecutorService executor);
|
||||||
|
|
||||||
|
String stripAccents(String input);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,7 @@ import org.jeecg.modules.business.vo.clientPlatformOrder.section.OrdersStatistic
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 平台订单表
|
* @Description: 平台订单表
|
||||||
|
@ -205,9 +202,13 @@ public interface IPlatformOrderService extends IService<PlatformOrder> {
|
||||||
* Find all order that can be invoiced (shipping and purchase).
|
* Find all order that can be invoiced (shipping and purchase).
|
||||||
* @param shopIds
|
* @param shopIds
|
||||||
* @param erpStatuses
|
* @param erpStatuses
|
||||||
|
* @param column
|
||||||
|
* @param order
|
||||||
|
* @param pageNo
|
||||||
|
* @param pageSize
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<PlatformOrder> findUninvoicedOrdersByShopForClient(List<String> shopIds, List<Integer> erpStatuses);
|
LinkedList<PlatformOrder> findUninvoicedOrdersByShopForClient(List<String> shopIds, List<Integer> erpStatuses, String column, String order, Integer pageNo, Integer pageSize);
|
||||||
/**
|
/**
|
||||||
* Get ids of all order that can be invoiced by small clients (type 2) themselves.
|
* Get ids of all order that can be invoiced by small clients (type 2) themselves.
|
||||||
* @param shopIds list of shop id
|
* @param shopIds list of shop id
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.jeecg.modules.business.service;
|
||||||
|
|
||||||
|
public interface ISecurityService {
|
||||||
|
boolean checkIsEmployee();
|
||||||
|
}
|
|
@ -18,4 +18,8 @@ public interface IShopService extends IService<Shop> {
|
||||||
List<String> listIdByClient(String clientID);
|
List<String> listIdByClient(String clientID);
|
||||||
|
|
||||||
List<String> getShopIdsByClientAndType(List<String> clientIds, String clientType);
|
List<String> getShopIdsByClientAndType(List<String> clientIds, String clientType);
|
||||||
|
|
||||||
|
String getNameById(String shopId);
|
||||||
|
|
||||||
|
String getCodeById(String shopId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.jeecg.common.system.vo.LoginUser;
|
import org.jeecg.common.system.vo.LoginUser;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderRequest;
|
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.*;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderRequestBody;
|
import org.jeecg.modules.business.domain.api.mabang.getorderlist.*;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderResponse;
|
|
||||||
import org.jeecg.modules.business.domain.api.mabang.getorderlist.Order;
|
|
||||||
import org.jeecg.modules.business.domain.api.mabang.getorderlist.OrderItem;
|
|
||||||
import org.jeecg.modules.business.domain.api.mabang.getorderlist.OrderStatus;
|
|
||||||
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendRequest;
|
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendRequest;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendRequestBody;
|
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendRequestBody;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendResponse;
|
import org.jeecg.modules.business.domain.api.mabang.orderDoOrderAbnormal.OrderSuspendResponse;
|
||||||
|
@ -23,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.text.Normalizer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -267,7 +264,64 @@ public class PlatformOrderMabangServiceImpl extends ServiceImpl<PlatformOrderMab
|
||||||
return responses;
|
return responses;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateExistedOrders(List<Order> orders) {
|
/**
|
||||||
|
*
|
||||||
|
* @param requests List<OrderListRequestBody>
|
||||||
|
* @param executor ExecutorService
|
||||||
|
* @return orders retrieved from mabang
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Order> getOrdersFromMabang(List<OrderListRequestBody> requests, ExecutorService executor) {
|
||||||
|
List<Order> mabangOrders = new ArrayList<>();
|
||||||
|
|
||||||
|
List<CompletableFuture<Boolean>> futures = requests.stream()
|
||||||
|
.map(request -> CompletableFuture.supplyAsync(() -> {
|
||||||
|
boolean success = false;
|
||||||
|
try {
|
||||||
|
OrderListRawStream rawStream = new OrderListRawStream(request);
|
||||||
|
OrderListStream stream = new OrderListStream(rawStream);
|
||||||
|
List<Order> orders = stream.all();
|
||||||
|
mabangOrders.addAll(orders);
|
||||||
|
success = !orders.isEmpty();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.error("Error communicating with MabangAPI", e);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}, executor))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Boolean> results = futures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
|
long nbSuccesses = results.stream().filter(b -> b).count();
|
||||||
|
log.info("{}/{} requests have succeeded.", nbSuccesses, requests.size());
|
||||||
|
log.info("{}/{} mabang orders have been retrieved.", mabangOrders.size(), requests.size());
|
||||||
|
return mabangOrders;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a request to clear orders Logistic Channel to Mabang
|
||||||
|
* (usually it is called upon modifying an order)
|
||||||
|
* @param orders List<Order>
|
||||||
|
* @param executor Executor Service
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void clearLogisticChannel(List<Order> orders, ExecutorService executor) {
|
||||||
|
// First we delete the logistic channel names, otherwise we can't delete virtual skus
|
||||||
|
List<CompletableFuture<Boolean>> clearLogisticFutures = orders.stream()
|
||||||
|
.map(order -> CompletableFuture.supplyAsync(() -> {
|
||||||
|
ClearLogisticRequestBody body = new ClearLogisticRequestBody(order.getPlatformOrderId());
|
||||||
|
ClearLogisticRequest request = new ClearLogisticRequest(body);
|
||||||
|
ClearLogisticResponse response = request.send();
|
||||||
|
return response.success();
|
||||||
|
}, executor))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<Boolean> logisticResults = clearLogisticFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
|
long logisticClearSuccessCount = logisticResults.stream().filter(b -> b).count();
|
||||||
|
log.info("{}/{} logistic channel names cleared successfully.", logisticClearSuccessCount, orders.size());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String stripAccents(String input) {
|
||||||
|
input = Normalizer.normalize(input, Normalizer.Form.NFD);
|
||||||
|
input = input.replaceAll("[^\\p{ASCII}]", "");
|
||||||
|
return input;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,8 +429,9 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PlatformOrder> findUninvoicedOrdersByShopForClient(List<String> shopIds, List<Integer> erpStatuses) {
|
public LinkedList<PlatformOrder> findUninvoicedOrdersByShopForClient(List<String> shopIds, List<Integer> erpStatuses, String column, String order, Integer pageNo, Integer pageSize) {
|
||||||
return platformOrderMap.findUninvoicedOrdersByShopForClient(shopIds, erpStatuses);
|
int offset = (pageNo - 1) * pageSize;
|
||||||
|
return platformOrderMap.findUninvoicedOrdersByShopForClient(shopIds, erpStatuses, column, order, offset, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.jeecg.modules.business.service.impl;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
import org.jeecg.common.system.vo.LoginUser;
|
||||||
|
import org.jeecg.modules.business.service.ISecurityService;
|
||||||
|
import org.jeecg.modules.system.service.ISysDepartService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class SecurityServiceImp implements ISecurityService {
|
||||||
|
@Autowired private ISysDepartService sysDepartService;
|
||||||
|
@Autowired private Environment env;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkIsEmployee() {
|
||||||
|
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
|
||||||
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
|
return sysUser.getOrgCode().equals(companyOrgCode);
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,4 +38,14 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IS
|
||||||
public List<String> getShopIdsByClientAndType(List<String> clientIds, String clientType) {
|
public List<String> getShopIdsByClientAndType(List<String> clientIds, String clientType) {
|
||||||
return shopMapper.getShopIdsByClientAndType(clientIds, clientType);
|
return shopMapper.getShopIdsByClientAndType(clientIds, clientType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNameById(String shopId) {
|
||||||
|
return shopMapper.getNameById(shopId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCodeById(String shopId) {
|
||||||
|
return shopMapper.getCodeById(shopId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,32 +9,47 @@ import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Estimation {
|
public class Estimation {
|
||||||
|
private String code;
|
||||||
|
private Integer ordersToProcess;
|
||||||
|
private Integer processedOrders;
|
||||||
private BigDecimal shippingFeesEstimation;
|
private BigDecimal shippingFeesEstimation;
|
||||||
private BigDecimal purchaseEstimation;
|
private BigDecimal purchaseEstimation;
|
||||||
private BigDecimal totalEstimation;
|
private BigDecimal totalEstimation;
|
||||||
private String currency;
|
private String currency;
|
||||||
private List<String> errorMessages;
|
private List<String> errorMessages;
|
||||||
|
private String shop = "";
|
||||||
private List<String> shopIds;
|
private List<String> shopIds;
|
||||||
private String startDate;
|
private String startDate;
|
||||||
private String endDate;
|
private String endDate;
|
||||||
private boolean isCompleteInvoiceReady;
|
private boolean isCompleteInvoiceReady;
|
||||||
|
private List<String> orderIds;
|
||||||
public Estimation(@JsonProperty("shippingFeesEstimation") BigDecimal shippingFeesEstimation,
|
public Estimation(@JsonProperty("code") String code,
|
||||||
|
@JsonProperty("ordersToProcess") Integer ordersToProcess,
|
||||||
|
@JsonProperty("processedOrders") Integer processedOrders,
|
||||||
|
@JsonProperty("shippingFeesEstimation") BigDecimal shippingFeesEstimation,
|
||||||
@JsonProperty("purchaseEstimation") BigDecimal purchaseEstimation,
|
@JsonProperty("purchaseEstimation") BigDecimal purchaseEstimation,
|
||||||
@JsonProperty("currency") String currency,
|
@JsonProperty("currency") String currency,
|
||||||
@JsonProperty("errorMessages") List<String> errorMessages,
|
@JsonProperty("errorMessages") List<String> errorMessages,
|
||||||
@JsonProperty("orderIds") List<String> shopIds,
|
@JsonProperty("shop") String shop,
|
||||||
|
@JsonProperty("shopIds") List<String> shopIds,
|
||||||
@JsonProperty("startDate") String startDate,
|
@JsonProperty("startDate") String startDate,
|
||||||
@JsonProperty("endDate") String endDate,
|
@JsonProperty("endDate") String endDate,
|
||||||
@JsonProperty("isCompleteInvoiceReady") boolean isCompleteInvoiceReady) {
|
@JsonProperty("isCompleteInvoiceReady") boolean isCompleteInvoiceReady,
|
||||||
|
@JsonProperty("orderIds") List<String> orderIds
|
||||||
|
) {
|
||||||
|
this.code = code;
|
||||||
|
this.ordersToProcess = ordersToProcess;
|
||||||
|
this.processedOrders = processedOrders;
|
||||||
this.currency = currency;
|
this.currency = currency;
|
||||||
this.purchaseEstimation = purchaseEstimation;
|
this.purchaseEstimation = purchaseEstimation;
|
||||||
this.shippingFeesEstimation = shippingFeesEstimation;
|
this.shippingFeesEstimation = shippingFeesEstimation;
|
||||||
this.errorMessages = errorMessages;
|
this.errorMessages = errorMessages;
|
||||||
|
this.shop = shop;
|
||||||
this.shopIds = shopIds;
|
this.shopIds = shopIds;
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
this.isCompleteInvoiceReady = isCompleteInvoiceReady;
|
this.isCompleteInvoiceReady = isCompleteInvoiceReady;
|
||||||
|
this.orderIds = orderIds;
|
||||||
totalEstimation = shippingFeesEstimation.add(purchaseEstimation).setScale(2, RoundingMode.CEILING);
|
totalEstimation = shippingFeesEstimation.add(purchaseEstimation).setScale(2, RoundingMode.CEILING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,19 @@ public class PlatformOrderOperation {
|
||||||
private String action;
|
private String action;
|
||||||
@JSONField(name = "reason")
|
@JSONField(name = "reason")
|
||||||
private String reason;
|
private String reason;
|
||||||
|
@JSONField(name = "recipient")
|
||||||
|
private String recipient;
|
||||||
|
@JSONField(name = "phone")
|
||||||
|
private String phone;
|
||||||
|
@JSONField(name = "street1")
|
||||||
|
private String street1;
|
||||||
|
@JSONField(name = "street2")
|
||||||
|
private String street2;
|
||||||
|
|
||||||
public enum Action {
|
public enum Action {
|
||||||
CANCEL("cancel"),
|
CANCEL("cancel"),
|
||||||
SUSPEND("suspend");
|
SUSPEND("suspend"),
|
||||||
|
EDIT("edit");
|
||||||
|
|
||||||
private final String action;
|
private final String action;
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,22 @@
|
||||||
</tr>
|
</tr>
|
||||||
</#if>
|
</#if>
|
||||||
</#if>
|
</#if>
|
||||||
|
<#if editSuccessCount??>
|
||||||
|
<tr>
|
||||||
|
<td style="padding:0 0 35px 0;">Demandes de modification d'informations de commande : <b>${editSuccessCount}</b> réussie(s)</td>
|
||||||
|
</tr>
|
||||||
|
<#if editFailures?size gt 0 >
|
||||||
|
<tr>
|
||||||
|
<td style="padding:0 0 35px 0;">Demandes de modification de commande échouées :<br/>
|
||||||
|
<ul>
|
||||||
|
<#list editFailures as failure>
|
||||||
|
<li>${failure}</li>
|
||||||
|
</#list>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</#if>
|
||||||
|
</#if>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding:0 0 35px 0;">Pour toute information complémentaire nous vous invitons à vous rapprocher de votre conseiller.</td>
|
<td style="padding:0 0 35px 0;">Pour toute information complémentaire nous vous invitons à vous rapprocher de votre conseiller.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -2,7 +2,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.jeecgframework.boot</groupId>
|
<groupId>org.jeecgframework.boot</groupId>
|
||||||
<artifactId>jeecg-boot-parent</artifactId>
|
<artifactId>jeecg-boot-parent</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>3.6.3</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>WIA APP ${project.version}</name>
|
<name>WIA APP ${project.version}</name>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue