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; 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.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.google.common.base.CaseFormat;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; 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.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController; 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.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Arrays; 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: 退 * @Description: 退
@ -38,7 +46,7 @@ public class SavRefundController extends JeecgController<SavRefund, ISavRefundSe
private ISavRefundService savRefundService; private ISavRefundService savRefundService;
@Autowired @Autowired
private ISavRefundWithDetailService savRefundWithShopCodeService; private ISavRefundWithDetailService savRefundWithDetailService;
/** /**
* *
@ -53,12 +61,29 @@ public class SavRefundController extends JeecgController<SavRefund, ISavRefundSe
@ApiOperation(value = "售后退款-分页列表查询", notes = "售后退款-分页列表查询") @ApiOperation(value = "售后退款-分页列表查询", notes = "售后退款-分页列表查询")
@GetMapping(value = "/list") @GetMapping(value = "/list")
public Result<?> queryPageList(SavRefundWithDetail savRefund, 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 = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "column", defaultValue = "invoice_umber") String column,
@RequestParam(name = "order", defaultValue = "ASC") String order,
HttpServletRequest req) { HttpServletRequest req) {
QueryWrapper<SavRefundWithDetail> queryWrapper = QueryGenerator.initQueryWrapper(savRefund, req.getParameterMap()); String parsedColumn = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, column.replace("_dictText",""));
Page<SavRefundWithDetail> page = new Page<>(pageNo, pageSize); try {
IPage<SavRefundWithDetail> pageList = savRefundWithShopCodeService.page(page, queryWrapper); 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); return Result.OK(pageList);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -17,4 +17,5 @@ import java.util.List;
@Repository @Repository
public interface SavRefundWithDetailMapper extends BaseMapper<SavRefundWithDetail> { public interface SavRefundWithDetailMapper extends BaseMapper<SavRefundWithDetail> {
List<SavRefundWithDetail> findUnprocessedRefundsByClient(@Param("clientId") String clientId); 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} #{erpStatus}
</foreach>; </foreach>;
</select> </select>
<select id="fetchPlatformOrdersToArchive" resultType="org.jeecg.modules.business.entity.PlatformOrder"> <select id="fetchOrdersToArchiveBetweenDate" resultType="org.jeecg.modules.business.entity.PlatformOrder">
SELECT * SELECT *
FROM platform_order po FROM platform_order po
WHERE erp_status IN (4,5) WHERE erp_status IN (4,5)
AND order_time BETWEEN #{startDate} AND #{endDate}; AND order_time BETWEEN #{startDate} AND #{endDate};
</select> </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 id="insertPlatformOrdersArchives" parameterType="list">
INSERT INTO platform_order_delete(id, create_by, INSERT INTO platform_order_delete(id, create_by,
create_time, update_by, create_time, update_by,

View File

@ -10,4 +10,13 @@
WHERE invoice_number IS NULL WHERE invoice_number IS NULL
AND s.owner_id = #{clientId} AND s.owner_id = #{clientId}
</select> </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> </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 * Fetch all platform orders between 2 dates and of status erp_status 4 or 5
* this list will then be archived * this list will then be archived
<<<<<<< HEAD
* @param startDate Start date time * @param startDate Start date time
* @param endDate End date time * @param endDate End date time
=======
*
* @param startDate
* @param endDate
>>>>>>> 9c5c7432b6824185b589760c500b696f46f82c58
* @return List of PlatformOrder * @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 * Archive a list of platform orders

View File

@ -13,4 +13,5 @@ import java.util.List;
*/ */
public interface ISavRefundWithDetailService extends IService<SavRefundWithDetail> { public interface ISavRefundWithDetailService extends IService<SavRefundWithDetail> {
List<SavRefundWithDetail> findUnprocessedRefundsByClient(String clientId); 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); return platformOrderMap.fetchUninvoicedShippedOrderIDInShops(startDate, endDate, shops, warehouses);
} }
@Override @Override
public List<PlatformOrder> fetchPlatformOrdersToArchive(String startDate, String endDate) { public List<PlatformOrder> fetchOrdersToArchiveBetweenDate(String startDate, String endDate) {
return platformOrderMap.fetchPlatformOrdersToArchive(startDate, endDate); return platformOrderMap.fetchOrdersToArchiveBetweenDate(startDate, endDate);
}
@Override
public List<PlatformOrder> fetchOrdersToArchiveBeforeDate(String endDate) {
return platformOrderMap.fetchOrdersToArchiveBeforeDate(endDate);
} }
@Override @Override
public void savePlatformOrderArchive(List<PlatformOrder> platformOrders) { public void savePlatformOrderArchive(List<PlatformOrder> platformOrders) {

View File

@ -27,4 +27,8 @@ public class SavRefundWithDetailServiceImpl extends ServiceImpl<SavRefundWithDet
public List<SavRefundWithDetail> findUnprocessedRefundsByClient(String clientId) { public List<SavRefundWithDetail> findUnprocessedRefundsByClient(String clientId) {
return savRefundMapper.findUnprocessedRefundsByClient(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);
}
} }