Merge pull request #7 from LQYBill/dev

New MabangAPI & order archive job
pull/6221/head
Qiuyi LI 2023-07-06 16:42:05 +02:00 committed by GitHub
commit ef2f387112
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 187 additions and 76 deletions

View File

@ -1,11 +1,15 @@
package org.jeecg.modules.business.controller.admin;
import com.aspose.pdf.PageSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.CaseFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.tomcat.util.json.JSONParser;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
@ -22,6 +26,10 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import static org.apache.commons.lang3.StringUtils.stripAll;
import static org.jeecg.common.util.SqlInjectionUtil.specialFilterContentForDictSql;
/**
* @Description: 退
@ -38,7 +46,7 @@ public class SavRefundController extends JeecgController<SavRefund, ISavRefundSe
private ISavRefundService savRefundService;
@Autowired
private ISavRefundWithDetailService savRefundWithShopCodeService;
private ISavRefundWithDetailService savRefundWithDetailService;
/**
*
@ -53,12 +61,29 @@ public class SavRefundController extends JeecgController<SavRefund, ISavRefundSe
@ApiOperation(value = "售后退款-分页列表查询", notes = "售后退款-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(SavRefundWithDetail savRefund,
@RequestParam(name = "shop", defaultValue = "") String shop,
@RequestParam(name = "orderID", defaultValue = "") String platformOrderId,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "column", defaultValue = "invoice_umber") String column,
@RequestParam(name = "order", defaultValue = "ASC") String order,
HttpServletRequest req) {
QueryWrapper<SavRefundWithDetail> queryWrapper = QueryGenerator.initQueryWrapper(savRefund, req.getParameterMap());
Page<SavRefundWithDetail> page = new Page<>(pageNo, pageSize);
IPage<SavRefundWithDetail> pageList = savRefundWithShopCodeService.page(page, queryWrapper);
String parsedColumn = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, column.replace("_dictText",""));
try {
specialFilterContentForDictSql(parsedColumn);
}
catch (RuntimeException e) {
e.printStackTrace();
return Result.error("Error 400 : Bad Request");
}
String parsedShop = "%"+shop.toUpperCase()+"%";
String parsedPlatformOrderId = "%"+platformOrderId+"%";
if(!order.equalsIgnoreCase("ASC") && !order.equalsIgnoreCase("DESC")) {
return Result.error("Error 400 Bad Request");
}
List<SavRefundWithDetail> refundList = savRefundWithDetailService.fetchRefundsWhere(parsedShop, parsedPlatformOrderId, parsedColumn, order);
IPage<SavRefundWithDetail> pageList = new Page<>(pageNo, pageSize);
pageList.setRecords(refundList);
return Result.OK(pageList);
}

View File

@ -33,8 +33,9 @@ public class OrderListRawStream implements NetworkDataStream<OrderListResponse>
if (currentResponse.getDataCount() == 0) {
return null;
}
began = true;
toSend.setCursor(currentResponse.getNextCursor());
toSend.nextPage();
began = true;
return currentResponse;
}
@ -49,8 +50,8 @@ public class OrderListRawStream implements NetworkDataStream<OrderListResponse>
throw new IllegalStateException("Calling hasNext before begin");
}
// still has page left, true
if (toSend.getPage() <= currentResponse.getTotalPage()) {
log.info("page: {}/{}, has next", toSend.getPage(), currentResponse.getTotalPage());
if (currentResponse.getHasNext()) {
log.info("page: {}, has next", toSend.getPage());
return true;
}
// no page left, false
@ -72,6 +73,7 @@ public class OrderListRawStream implements NetworkDataStream<OrderListResponse>
log.info("Sending request for page {}.", toSend.getPage());
this.currentResponse = new OrderListRequest(toSend).send();
toSend.setCursor(currentResponse.getNextCursor());
toSend.nextPage();
return this.currentResponse;
}

View File

@ -18,11 +18,13 @@ public class OrderListRequestBody implements RequestBody {
private LocalDateTime endDate;
// 1.Normal 2.Abnormal 3.All
private final static String CAN_SEND = "3";
private String cursor = "";
private Integer page = 1;
private boolean hasNext = true;
@Override
public String api() {
return "order-get-order-list";
return "order-get-order-list-new";
}
@Override
@ -35,19 +37,29 @@ public class OrderListRequestBody implements RequestBody {
putNonNull(json, datetimeType.text() + "End", endDate, formatter::format);
}
putNonNull(json, "canSend", CAN_SEND);
putNonNull(json, "page", page);
putNonNull(json, "cursor", cursor);
return json;
}
void nextPage() {
setPage(this.page + 1);
String getCursor() {
return cursor;
}
void setCursor(String cursor) {
this.cursor = cursor;
}
int getPage() {
return page;
}
void setPage(int page) {
this.page = page;
}
void nextPage() {
this.page += 1;
}
boolean getHasNext() { return hasNext; }
void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
public OrderListRequestBody setStatus(OrderStatus status) {
this.status = status;
return this;
@ -73,8 +85,8 @@ public class OrderListRequestBody implements RequestBody {
return this;
}
public OrderListRequestBody setPage(int page) {
this.page = page;
public OrderListRequestBody setPage(String cursor) {
this.cursor = cursor;
return this;
}

View File

@ -5,15 +5,25 @@ import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.business.domain.api.mabang.Response;
import static cn.hutool.core.util.StrUtil.trim;
/**
* Immutable object
*/
@Slf4j
public class OrderListResponse extends Response {
/**
* total page number
* Response message
*/
private final int pageCount;
private String message;
/**
* Has next page
*/
private boolean hasNext;
/**
*
*/
private String nextCursor;
/**
* Total data number
*/
@ -25,9 +35,11 @@ public class OrderListResponse extends Response {
private final JSONObject rawData;
OrderListResponse(Code code, int pageCount, int dataCount, JSONArray data, JSONObject rawData) {
OrderListResponse(Code code, String message, String hasNext, String nextCursor, int dataCount, JSONArray data, JSONObject rawData) {
super(code);
this.pageCount = pageCount;
setMessage(message);
setHasNext(hasNext);
setNextCursor(nextCursor);
this.dataCount = dataCount;
this.data = data;
this.rawData = rawData;
@ -44,19 +56,37 @@ public class OrderListResponse extends Response {
public static OrderListResponse parse(JSONObject json) throws OrderListRequestErrorException {
log.debug("Constructing a response by json.");
String code = json.getString("code");
String message = json.getString("message");
if (code.equals(Code.ERROR.value))
throw new OrderListRequestErrorException(json.getString("message"));
throw new OrderListRequestErrorException(message);
JSONObject data = json.getJSONObject("data");
int pageCount = Integer.parseInt(data.getString("pageCount"));
int dataCount = Integer.parseInt(data.getString("dataCount"));
String hasNext = data.getString("hasNext");
String nextCursor = data.getString("nextCursor");
int dataCount = Integer.parseInt(data.getString("total"));
JSONArray realData = data.getJSONArray("data");
log.info("Constructed response: data contained {}, total page {}, total data {}", realData.size(), pageCount, dataCount);
return new OrderListResponse(Code.SUCCESS, pageCount, dataCount, realData, json);
log.info("Constructed response: data contained {}, total data {}", realData.size(), dataCount);
return new OrderListResponse(Code.SUCCESS, message, hasNext, nextCursor, dataCount, realData, json);
}
public int getTotalPage() {
return pageCount;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = trim(message);
}
public boolean getHasNext() {
return hasNext;
}
public void setHasNext(String hasNext) {
this.hasNext = hasNext.equals("true");
}
public String getNextCursor() {
return this.nextCursor;
}
public void setNextCursor(String nextCursor) {
this.nextCursor = nextCursor;
}
public JSONArray getData() {
@ -74,7 +104,6 @@ public class OrderListResponse extends Response {
@Override
public String toString() {
return "OrderListResponse{" +
"pageCount=" + pageCount +
", dataCount=" + dataCount +
'}';
}

View File

@ -45,8 +45,8 @@ public class DBArchivingJob implements Job {
private static final Integer DEFAULT_NUMBER_OF_DAYS = 365;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
LocalDateTime endDateTime = LocalDateTime.now(ZoneId.of(ZoneId.SHORT_IDS.get("CTT")));
LocalDateTime startDateTime = endDateTime.minusDays(DEFAULT_NUMBER_OF_DAYS);
LocalDateTime endDateTime = LocalDateTime.now(ZoneId.of(ZoneId.SHORT_IDS.get("CTT"))).minusDays(DEFAULT_NUMBER_OF_DAYS);
LocalDateTime startDateTime = null;
JobDataMap jobDataMap = context.getMergedJobDataMap();
String parameter = ((String) jobDataMap.get("parameter"));
if (parameter != null) {
@ -59,27 +59,37 @@ public class DBArchivingJob implements Job {
if (!jsonObject.isNull("endDateTime")) {
String endDateStr = jsonObject.getString("endDateTime");
endDateTime = LocalDateTime.parse(endDateStr);
if(endDateTime.isAfter(LocalDateTime.now(ZoneId.of(ZoneId.SHORT_IDS.get("CTT"))).minusDays(DEFAULT_NUMBER_OF_DAYS))) {
throw new RuntimeException("Error : Only orders older than 1 year can be archived !");
}
}
}
catch (JSONException e) {
log.error("Error while parsing parameter as JSON, falling back to default parameters.");
}
}
if (!endDateTime.isAfter(startDateTime)) {
throw new RuntimeException("EndDateTime must be strictly greater than StartDateTime !");
}
String startDate = startDateTime.toString().substring(0,10);
String startDate;
endDateTime = endDateTime.plusDays(1);
String endDate = endDateTime.toString().substring(0,10);
List<PlatformOrder> platformOrders;
if (startDateTime != null) {
if(!endDateTime.isAfter(startDateTime))
throw new RuntimeException("EndDateTime must be strictly greater than StartDateTime !");
startDate = startDateTime.toString().substring(0,10);
platformOrders = platformOrderService.fetchOrdersToArchiveBetweenDate(startDate, endDate);
log.info("Archiving entries between ["+startDate+" and "+endDate+"]");
}
else {
platformOrders = platformOrderService.fetchOrdersToArchiveBeforeDate(endDate);
log.info("Archiving entries before ["+endDate+"]");
}
if(platformOrders.size() > 0) {
// sauvegarde des entrées dans des listes
// suppression des entrées dans l'ancienne table
List<PlatformOrder> platformOrders = platformOrderService.fetchPlatformOrdersToArchive(startDate, endDate);
List<String> platformOrderIDs = platformOrders.stream().map(PlatformOrder::getId).collect(Collectors.toList());
List<PlatformOrderContent> platformOrderContents = platformOrderContentService.fetchPlatformOrderContentsToArchive(platformOrderIDs);
log.info("Archiving entries between ["+startDate+" and "+endDate+"]\n"
+"- Platform Order entries : " + platformOrders.size() + "\n"
log.info("- Platform Order entries : " + platformOrders.size() + "\n"
+ "- Platform Order Content entries : " + platformOrderContents.size());
platformOrderService.savePlatformOrderArchive(platformOrders);
platformOrderContentService.savePlatformOrderContentArchive(platformOrderContents);
@ -103,4 +113,8 @@ public class DBArchivingJob implements Job {
}
log.info("Archiving Done.");
}
else {
log.info("Nothing to archive !");
}
}
}

View File

@ -178,6 +178,7 @@ public interface PlatformOrderMapper extends BaseMapper<PlatformOrder> {
@Param("shops") List<String> shops,
@Param("erpStatuses") List<Integer> erpStatuses,
@Param("warehouses") List<String> warehouses);
List<PlatformOrder> fetchPlatformOrdersToArchive(@Param("startDate") String startDate, @Param("endDate") String endDate);
List<PlatformOrder> fetchOrdersToArchiveBetweenDate(@Param("startDate") String startDate, @Param("endDate") String endDate);
List<PlatformOrder> fetchOrdersToArchiveBeforeDate(@Param("endDate") String endDate);
void insertPlatformOrdersArchives(@Param("orders") List<PlatformOrder> platformOrders);
}

View File

@ -17,4 +17,5 @@ import java.util.List;
@Repository
public interface SavRefundWithDetailMapper extends BaseMapper<SavRefundWithDetail> {
List<SavRefundWithDetail> findUnprocessedRefundsByClient(@Param("clientId") String clientId);
List<SavRefundWithDetail> fetchRefundsWhere(@Param("shop") String shop, @Param("orderID") String orderID, @Param("column") String column, @Param("order") String order);
}

View File

@ -528,12 +528,18 @@
#{erpStatus}
</foreach>;
</select>
<select id="fetchPlatformOrdersToArchive" resultType="org.jeecg.modules.business.entity.PlatformOrder">
<select id="fetchOrdersToArchiveBetweenDate" resultType="org.jeecg.modules.business.entity.PlatformOrder">
SELECT *
FROM platform_order po
WHERE erp_status IN (4,5)
AND order_time BETWEEN #{startDate} AND #{endDate};
</select>
<select id="fetchOrdersToArchiveBeforeDate" resultType="org.jeecg.modules.business.entity.PlatformOrder">
SELECT *
FROM platform_order po
WHERE erp_status IN (4,5)
AND order_time &lt; #{endDate};
</select>
<insert id="insertPlatformOrdersArchives" parameterType="list">
INSERT INTO platform_order_delete(id, create_by,
create_time, update_by,

View File

@ -10,4 +10,13 @@
WHERE invoice_number IS NULL
AND s.owner_id = #{clientId}
</select>
<select id="fetchRefundsWhere" resultType="org.jeecg.modules.business.entity.SavRefundWithDetail">
SELECT sr.*
FROM sav_refund_with_detail sr
JOIN platform_order po ON sr.platform_order_id = po.id
JOIN shop s ON po.shop_id = s.id
WHERE s.erp_code LIKE #{shop}
AND po.platform_order_id LIKE #{orderID}
ORDER BY ${column} ${order};
</select>
</mapper>

View File

@ -145,17 +145,20 @@ public interface IPlatformOrderService extends IService<PlatformOrder> {
/**
* Fetch all platform orders between 2 dates and of status erp_status 4 or 5
* this list will then be archived
<<<<<<< HEAD
* @param startDate Start date time
* @param endDate End date time
=======
*
* @param startDate
* @param endDate
>>>>>>> 9c5c7432b6824185b589760c500b696f46f82c58
* @return List of PlatformOrder
*/
List<PlatformOrder> fetchPlatformOrdersToArchive(String startDate, String endDate);
List<PlatformOrder> fetchOrdersToArchiveBetweenDate(String startDate, String endDate);
/**
* Fetch all platform orders before endDate and of status erp_status 4 or 5
* this list will then be archived
*
* @param endDate Start date time
* @return List of PlatformOrder
*/
List<PlatformOrder> fetchOrdersToArchiveBeforeDate(String endDate);
/**
* Archive a list of platform orders

View File

@ -13,4 +13,5 @@ import java.util.List;
*/
public interface ISavRefundWithDetailService extends IService<SavRefundWithDetail> {
List<SavRefundWithDetail> findUnprocessedRefundsByClient(String clientId);
List<SavRefundWithDetail> fetchRefundsWhere(String shop, String orderID, String column, String order);
}

View File

@ -367,8 +367,12 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
return platformOrderMap.fetchUninvoicedShippedOrderIDInShops(startDate, endDate, shops, warehouses);
}
@Override
public List<PlatformOrder> fetchPlatformOrdersToArchive(String startDate, String endDate) {
return platformOrderMap.fetchPlatformOrdersToArchive(startDate, endDate);
public List<PlatformOrder> fetchOrdersToArchiveBetweenDate(String startDate, String endDate) {
return platformOrderMap.fetchOrdersToArchiveBetweenDate(startDate, endDate);
}
@Override
public List<PlatformOrder> fetchOrdersToArchiveBeforeDate(String endDate) {
return platformOrderMap.fetchOrdersToArchiveBeforeDate(endDate);
}
@Override
public void savePlatformOrderArchive(List<PlatformOrder> platformOrders) {

View File

@ -27,4 +27,8 @@ public class SavRefundWithDetailServiceImpl extends ServiceImpl<SavRefundWithDet
public List<SavRefundWithDetail> findUnprocessedRefundsByClient(String clientId) {
return savRefundMapper.findUnprocessedRefundsByClient(clientId);
}
@Override
public List<SavRefundWithDetail> fetchRefundsWhere(String shop, String orderID, String column, String order) {
return savRefundMapper.fetchRefundsWhere(shop, orderID, column, order);
}
}