Code optimization

pull/6221/head
Qiuyi LI 2023-08-24 14:03:32 +02:00
parent 0eb6aadbff
commit 8da45dce22
7 changed files with 240 additions and 195 deletions

View File

@ -1,26 +1,27 @@
package org.jeecg.modules.business.controller.admin; package org.jeecg.modules.business.controller.admin;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.business.entity.TaskHistory;
import org.jeecg.modules.business.service.ITaskHistoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.business.entity.TaskHistory;
import org.jeecg.modules.business.service.ITaskHistoryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import javax.servlet.http.HttpServletRequest;
import org.jeecg.common.aspect.annotation.AutoLog; import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import static org.jeecg.modules.business.entity.TaskHistory.TaskStatus.CANCELLED;
/** /**
* @Description: task history * @Description: task history
@ -163,7 +164,7 @@ public class TaskHistoryController extends JeecgController<TaskHistory, ITaskHis
public Result<?> resetTask(@RequestParam("task") String taskCode) { public Result<?> resetTask(@RequestParam("task") String taskCode) {
List<TaskHistory> allRunningTasks = taskHistoryService.getAllRunningTasksByCode(taskCode); List<TaskHistory> allRunningTasks = taskHistoryService.getAllRunningTasksByCode(taskCode);
for(TaskHistory taskHistory: allRunningTasks) { for(TaskHistory taskHistory: allRunningTasks) {
taskHistory.setOngoing(-1); taskHistory.setOngoing(CANCELLED.getCode());
taskHistoryService.updateById(taskHistory); taskHistoryService.updateById(taskHistory);
} }
return Result.ok("Reset successful !"); return Result.ok("Reset successful !");

View File

@ -41,6 +41,9 @@ 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.modules.business.entity.Task.TaskCode.SI_G;
import static org.jeecg.modules.business.entity.TaskHistory.TaskStatus.*;
/** /**
* Controller for request related to shipping invoice * Controller for request related to shipping invoice
*/ */
@ -70,8 +73,6 @@ public class InvoiceController {
@Autowired @Autowired
private IQuartzJobService quartzJobService; private IQuartzJobService quartzJobService;
@Autowired @Autowired
private ITaskService pendingTaskService;
@Autowired
private ITaskHistoryService taskHistoryService; private ITaskHistoryService taskHistoryService;
@Autowired @Autowired
private FreeMarkerConfigurer freemarkerConfigurer; private FreeMarkerConfigurer freemarkerConfigurer;
@ -175,9 +176,8 @@ public class InvoiceController {
} }
if (pageList.getSize() > 0) { if (pageList.getSize() > 0) {
return Result.OK(pageList); return Result.OK(pageList);
} else {
return Result.error("No orders for selected client/shops");
} }
return Result.error("No orders for selected client/shops");
} }
@PostMapping(value = "/period") @PostMapping(value = "/period")
public Result<?> getValidPeriod(@RequestBody List<String> shopIDs) { public Result<?> getValidPeriod(@RequestBody List<String> shopIDs) {
@ -275,7 +275,7 @@ public class InvoiceController {
System.out.println("start : " + period.start() + "; end : " + period.end()); System.out.println("start : " + period.start() + "; end : " + period.end());
return Result.OK(period); return Result.OK(period);
} }
else return Result.error("No package in the selected period"); return Result.error("No package in the selected period");
} }
/** /**
@ -292,7 +292,7 @@ public class InvoiceController {
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");
} else { }
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);
@ -309,7 +309,6 @@ public class InvoiceController {
// on check s'il y a des SKU sans prix // on check s'il y a des SKU sans prix
return checkSkuPrices(args); return checkSkuPrices(args);
} }
}
/** /**
* Checks if all sku of order from shops between 2 dates are available * Checks if all sku of order from shops between 2 dates are available
@ -325,7 +324,7 @@ public class InvoiceController {
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");
} else { }
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);
@ -338,7 +337,6 @@ public class InvoiceController {
// on check s'il y a des SKU sans prix // on check s'il y a des SKU sans prix
return checkSkuPrices(args); return checkSkuPrices(args);
} }
}
/** /**
* Get binary data of the invoice file. * Get binary data of the invoice file.
@ -375,7 +373,7 @@ public class InvoiceController {
List<ShippingFeesEstimation> shippingFeesEstimation = shippingInvoiceService.getShippingFeesEstimation(errorMessages); List<ShippingFeesEstimation> shippingFeesEstimation = shippingInvoiceService.getShippingFeesEstimation(errorMessages);
if (shippingFeesEstimation.isEmpty()) { if (shippingFeesEstimation.isEmpty()) {
return Result.error("No data"); return Result.error("No data");
} else { }
Map<String, String> clientIDCodeMap = new HashMap<>(); Map<String, String> clientIDCodeMap = new HashMap<>();
for(ShippingFeesEstimation estimation: shippingFeesEstimation) { for(ShippingFeesEstimation estimation: shippingFeesEstimation) {
String clientId; String clientId;
@ -404,7 +402,6 @@ public class InvoiceController {
} }
return Result.OK(errorMessages.toString(), shippingFeesEstimation); return Result.OK(errorMessages.toString(), shippingFeesEstimation);
} }
}
/** /**
* Takes a list of ShippingFeesEstimations and groups the estimations by client * Takes a list of ShippingFeesEstimations and groups the estimations by client
@ -458,14 +455,14 @@ public class InvoiceController {
public Result<?> makeBreakdownInvoice(@RequestParam(value = "shipping[]", required = false) List<String> shippingClientIds, public Result<?> makeBreakdownInvoice(@RequestParam(value = "shipping[]", required = false) List<String> shippingClientIds,
@RequestParam(value = "complete[]", required = false) List<String> completeClientIds) throws IOException { @RequestParam(value = "complete[]", required = false) List<String> completeClientIds) throws IOException {
List<InvoiceMetaData> metaDataErrorList = new ArrayList<>(); List<InvoiceMetaData> metaDataErrorList = new ArrayList<>();
TaskHistory ongoingBITask = taskHistoryService.getLatestRunningTask("BI"); TaskHistory ongoingBITask = taskHistoryService.getLatestRunningTask(SI_G.name());
if(ongoingBITask != null) { if(ongoingBITask != null) {
return Result.error("Task is already run by " + ongoingBITask.getCreateBy() + ", please retry in a moment !"); return Result.error("Task is already run by " + ongoingBITask.getCreateBy() + ", please retry in a moment !");
} }
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
List<InvoiceMetaData> invoiceList = new ArrayList<>(); List<InvoiceMetaData> invoiceList = new ArrayList<>();
taskHistoryService.insert(new TaskHistory(sysUser.getUsername(), 1, "BI")); taskHistoryService.insert(new TaskHistory(sysUser.getUsername(), RUNNING.getCode(), SI_G.name()));
TaskHistory lastRunningTask = taskHistoryService.getLatestRunningTask("BI"); TaskHistory lastRunningTask = taskHistoryService.getLatestRunningTask(SI_G.name());
if(shippingClientIds != null) { if(shippingClientIds != null) {
log.info("Making shipping invoice for clients : {}", shippingClientIds); log.info("Making shipping invoice for clients : {}", shippingClientIds);
@ -475,15 +472,18 @@ public class InvoiceController {
log.info("Making complete shipping invoice for clients : {}", completeClientIds); log.info("Making complete shipping invoice for clients : {}", completeClientIds);
invoiceList.addAll(shippingInvoiceService.breakdownInvoiceClientByType(completeClientIds, 1)); invoiceList.addAll(shippingInvoiceService.breakdownInvoiceClientByType(completeClientIds, 1));
} }
if(!invoiceList.isEmpty()) { if (invoiceList.isEmpty()) {
lastRunningTask.setOngoing(SUCCESS.getCode());
taskHistoryService.updateById(lastRunningTask);
return Result.ok("Nothing invoiced");
}
List<String> filenameList = new ArrayList<>(); List<String> filenameList = new ArrayList<>();
log.info("Generating detail files ...0/{}", invoiceList.size()); log.info("Generating detail files ...0/{}", invoiceList.size());
int cpt = 1; int cpt = 1;
for (InvoiceMetaData metaData : invoiceList) { for (InvoiceMetaData metaData : invoiceList) {
if (metaData.getInvoiceCode().equals("error")) { if (metaData.getInvoiceCode().equals("error")) {
metaDataErrorList.add(metaData); metaDataErrorList.add(metaData);
} } else {
else {
filenameList.add(INVOICE_DIR + "//" + metaData.getFilename()); filenameList.add(INVOICE_DIR + "//" + metaData.getFilename());
List<FactureDetail> factureDetails = shippingInvoiceService.getInvoiceDetail(metaData.getInvoiceCode()); List<FactureDetail> factureDetails = shippingInvoiceService.getInvoiceDetail(metaData.getInvoiceCode());
List<SavRefundWithDetail> refunds = savRefundWithDetailService.getRefundsByInvoiceNumber(metaData.getInvoiceCode()); List<SavRefundWithDetail> refunds = savRefundWithDetailService.getRefundsByInvoiceNumber(metaData.getInvoiceCode());
@ -513,22 +513,16 @@ public class InvoiceController {
emailService.sendMessageWithAttachment(destEmail, subject, htmlBody, zipFilename, session); emailService.sendMessageWithAttachment(destEmail, subject, htmlBody, zipFilename, session);
log.info("Mail sent successfully"); log.info("Mail sent successfully");
lastRunningTask.setOngoing(0); lastRunningTask.setOngoing(SUCCESS.getCode());
taskHistoryService.updateById(lastRunningTask); taskHistoryService.updateById(lastRunningTask);
return Result.OK("component.email.emailSent"); return Result.OK("component.email.emailSent");
} } catch (Exception e) {
catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
lastRunningTask.setOngoing(CANCELLED.getCode());
lastRunningTask.setOngoing(-1);
taskHistoryService.updateById(lastRunningTask); taskHistoryService.updateById(lastRunningTask);
return Result.error("An error occurred while trying to send an email."); return Result.error("An error occurred while trying to send an email.");
} }
} }
lastRunningTask.setOngoing(0);
taskHistoryService.updateById(lastRunningTask);
return Result.ok("Nothing invoiced");
}
/** /**
* Get an estimate of shipping fees for selected orders * Get an estimate of shipping fees for selected orders
@ -553,7 +547,9 @@ public class InvoiceController {
String customerFullName; String customerFullName;
invoiceNumber = iShippingInvoiceService.getShippingInvoiceNumber(invoiceID); invoiceNumber = iShippingInvoiceService.getShippingInvoiceNumber(invoiceID);
// if invoice exists // if invoice exists
if(invoiceNumber != null) { if (invoiceNumber == null) {
return Result.error("Error 404 page not found.");
}
// if user is a customer, we check if he's the owner of the shops // if user is a customer, we check if he's the owner of the shops
Client client = iShippingInvoiceService.getShopOwnerFromInvoiceNumber(invoiceNumber); Client client = iShippingInvoiceService.getShopOwnerFromInvoiceNumber(invoiceNumber);
customerFullName = client.fullName(); customerFullName = client.fullName();
@ -577,8 +573,6 @@ public class InvoiceController {
json.put("currency", client.getCurrency()); json.put("currency", client.getCurrency());
return Result.OK(json); return Result.OK(json);
} }
return Result.error("Error 404 page not found.");
}
/** /**
* *

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.business.entity; package org.jeecg.modules.business.entity;
import java.io.Serializable; import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
@ -23,36 +24,56 @@ import io.swagger.annotations.ApiModelProperty;
public class Task implements Serializable { public class Task implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**主键*/ /**
*
*/
@TableId(type = IdType.ASSIGN_ID) @TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键") @ApiModelProperty(value = "主键")
private java.lang.String id; private java.lang.String id;
/**创建人*/ /**
*
*/
@ApiModelProperty(value = "创建人") @ApiModelProperty(value = "创建人")
private java.lang.String createBy; private java.lang.String createBy;
/**创建日期*/ /**
*
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期") @ApiModelProperty(value = "创建日期")
private java.util.Date createTime; private java.util.Date createTime;
/**更新人*/ /**
*
*/
@ApiModelProperty(value = "更新人") @ApiModelProperty(value = "更新人")
private java.lang.String updateBy; private java.lang.String updateBy;
/**更新日期*/ /**
*
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期") @ApiModelProperty(value = "更新日期")
private java.util.Date updateTime; private java.util.Date updateTime;
/**taskCode*/ /**
* taskCode
*/
@Excel(name = "taskCode", width = 15) @Excel(name = "taskCode", width = 15)
@ApiModelProperty(value = "taskCode") @ApiModelProperty(value = "taskCode")
private java.lang.String code; private java.lang.String code;
/**taskName*/ /**
* taskName
*/
@Excel(name = "taskName", width = 15) @Excel(name = "taskName", width = 15)
@ApiModelProperty(value = "taskName") @ApiModelProperty(value = "taskName")
private java.lang.String name; private java.lang.String name;
/**description*/ /**
* description
*/
@Excel(name = "description", width = 15) @Excel(name = "description", width = 15)
@ApiModelProperty(value = "description") @ApiModelProperty(value = "description")
private java.lang.String description; private java.lang.String description;
public enum TaskCode {
SI_G
}
} }

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.business.entity; package org.jeecg.modules.business.entity;
import java.io.Serializable; import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
@ -23,31 +24,45 @@ import io.swagger.annotations.ApiModelProperty;
public class TaskHistory implements Serializable { public class TaskHistory implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**主键*/ /**
*
*/
@TableId(type = IdType.ASSIGN_ID) @TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键") @ApiModelProperty(value = "主键")
private java.lang.String id; private java.lang.String id;
/**创建人*/ /**
*
*/
@ApiModelProperty(value = "创建人") @ApiModelProperty(value = "创建人")
private java.lang.String createBy; private java.lang.String createBy;
/**创建日期*/ /**
*
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期") @ApiModelProperty(value = "创建日期")
private java.util.Date createTime; private java.util.Date createTime;
/**更新人*/ /**
*
*/
@ApiModelProperty(value = "更新人") @ApiModelProperty(value = "更新人")
private java.lang.String updateBy; private java.lang.String updateBy;
/**更新日期*/ /**
*
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期") @ApiModelProperty(value = "更新日期")
private java.util.Date updateTime; private java.util.Date updateTime;
/**ongoing*/ /**
* ongoing
*/
@Excel(name = "ongoing", width = 15) @Excel(name = "ongoing", width = 15)
@ApiModelProperty(value = "ongoing") @ApiModelProperty(value = "ongoing")
private java.lang.Integer ongoing; private java.lang.Integer ongoing;
/**task code*/ /**
* task code
*/
@Excel(name = "task code", width = 15) @Excel(name = "task code", width = 15)
@ApiModelProperty(value = "task id") @ApiModelProperty(value = "task id")
private java.lang.String taskCode; private java.lang.String taskCode;
@ -60,4 +75,20 @@ public class TaskHistory implements Serializable {
public TaskHistory() { public TaskHistory() {
} }
public enum TaskStatus {
RUNNING(1),
SUCCESS(0),
CANCELLED(-1);
private final int code;
TaskStatus(int code) {
this.code = code;
}
public int getCode() {
return code;
}
}
} }

View File

@ -289,7 +289,8 @@
purchase_fee = 0.0, purchase_fee = 0.0,
erp_status = erp_status =
CASE erp_status CASE erp_status
WHEN 4 THEN 3 WHEN '4' THEN '3'
ELSE erp_status
END END
WHERE platform_order_id IN (SELECT id FROM platform_order WHERE shipping_invoice_number = #{invoiceNumber}); WHERE platform_order_id IN (SELECT id FROM platform_order WHERE shipping_invoice_number = #{invoiceNumber});
</update> </update>
@ -302,7 +303,8 @@
purchase_fee = 0.0, purchase_fee = 0.0,
erp_status = erp_status =
CASE erp_status CASE erp_status
WHEN 4 THEN 3 WHEN '4' THEN '3'
ELSE erp_status
END END
WHERE platform_order_id IN WHERE platform_order_id IN
(SELECT id FROM platform_order (SELECT id FROM platform_order

View File

@ -598,9 +598,7 @@
erp_status = erp_status =
CASE erp_status CASE erp_status
WHEN '4' THEN '3' WHEN '4' THEN '3'
WHEN '3' THEN '3' ELSE erp_status
WHEN '1' THEN '1'
WHEN '2' THEN '2'
END END
WHERE shipping_invoice_number = #{invoiceNumber}; WHERE shipping_invoice_number = #{invoiceNumber};
</update> </update>
@ -614,9 +612,7 @@
erp_status = erp_status =
CASE erp_status CASE erp_status
WHEN '4' THEN '3' WHEN '4' THEN '3'
WHEN '3' THEN '3' ELSE erp_status
WHEN '1' THEN '1'
WHEN '2' THEN '2'
END END
WHERE shipping_invoice_number IN WHERE shipping_invoice_number IN
<foreach collection="invoiceNumbers" separator="," open="(" close=")" index="index" item="invoiceNumber"> <foreach collection="invoiceNumbers" separator="," open="(" close=")" index="index" item="invoiceNumber">

View File

@ -15,7 +15,7 @@ public interface ITaskHistoryService extends IService<TaskHistory> {
TaskHistory getLatestRunningTask(String taskCode); TaskHistory getLatestRunningTask(String taskCode);
List<TaskHistory> getAllRunningTasksByCode(String bi); List<TaskHistory> getAllRunningTasksByCode(String code);
void insert(TaskHistory taskHistory); void insert(TaskHistory taskHistory);
} }