mirror of https://github.com/jeecgboot/jeecg-boot
feat: better pagination and new filter logic for skuOrderPage
parent
af3540274c
commit
97793b76b4
|
@ -3,6 +3,7 @@ package org.jeecg.modules.business.controller.admin;
|
||||||
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;
|
||||||
|
@ -33,6 +34,8 @@ import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.jeecg.common.util.SqlInjectionUtil.specialFilterContentForDictSql;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: SKU表
|
* @Description: SKU表
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
|
@ -343,13 +346,53 @@ public class SkuController {
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@GetMapping("/skuListByClient")
|
||||||
|
public Result<?> skusListByClient(@RequestParam("clientId") String clientId) {
|
||||||
|
List<Sku> skus = skuService.listByClientId(clientId);
|
||||||
|
return Result.OK(skus);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/skusByClient")
|
@GetMapping("/skusByClient")
|
||||||
public Result<?> skusByClient(@RequestParam String clientId) {
|
public Result<?> skusByClient(@RequestParam(name = "clientId") String clientId,
|
||||||
List<SkuOrderPage> skuOrdersPage = skuService.fetchSkusByClient(clientId);
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||||
|
@RequestParam(name = "pageSize", defaultValue = "50") Integer pageSize,
|
||||||
|
@RequestParam(name = "column", defaultValue = "erp_code") String column,
|
||||||
|
@RequestParam(name = "order", defaultValue = "ASC") String order,
|
||||||
|
@RequestParam(name = "erpCodes", required = false) String erpCodes,
|
||||||
|
@RequestParam(name = "zhNames", required = false) String zhNames,
|
||||||
|
@RequestParam(name = "enNames", required = false) String enNames
|
||||||
|
) {
|
||||||
|
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) {
|
||||||
|
return Result.error("Error 400 Bad Request");
|
||||||
|
}
|
||||||
|
List<SkuOrderPage> allSkuOrdersPage = new ArrayList<>();
|
||||||
|
List<SkuOrderPage> skuOrdersPage = new ArrayList<>();
|
||||||
|
int total = 0;
|
||||||
|
if(erpCodes != null || zhNames != null || enNames != null) {
|
||||||
|
List<String> erpCodeList = erpCodes == null ? null : Arrays.asList(erpCodes.split(","));
|
||||||
|
List<String> zhNameList = zhNames == null ? null : Arrays.asList(zhNames.split(","));
|
||||||
|
List<String> enNameList = enNames == null ? null : Arrays.asList(enNames.split(","));
|
||||||
|
allSkuOrdersPage = skuService.fetchSkusByClientWithFilters(clientId, 1, -1, parsedColumn, parsedOrder, erpCodeList, zhNameList, enNameList);
|
||||||
|
skuOrdersPage = skuService.fetchSkusByClientWithFilters(clientId, pageNo, pageSize, parsedColumn, parsedOrder, erpCodeList, zhNameList, enNameList);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
allSkuOrdersPage = skuService.fetchSkusByClient(clientId, 1, -1, parsedColumn, parsedOrder);
|
||||||
|
skuOrdersPage = skuService.fetchSkusByClient(clientId, pageNo, pageSize, parsedColumn, parsedOrder);
|
||||||
|
}
|
||||||
|
total = allSkuOrdersPage.size();
|
||||||
IPage<SkuOrderPage> page = new Page<>();
|
IPage<SkuOrderPage> page = new Page<>();
|
||||||
page.setRecords(skuOrdersPage);
|
page.setRecords(skuOrdersPage);
|
||||||
page.setTotal(skuOrdersPage.size());
|
page.setCurrent(pageNo);
|
||||||
|
page.setSize(pageSize);
|
||||||
|
page.setTotal(total);
|
||||||
return Result.OK(page);
|
return Result.OK(page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,7 +508,7 @@ 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(name = "shopIds") String shopIds,
|
||||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||||
@RequestParam(name = "pageSize", defaultValue = "50") Integer pageSize,
|
@RequestParam(name = "pageSize", defaultValue = "50") Integer pageSize,
|
||||||
@RequestParam(name = "column", defaultValue = "order_time") String column,
|
@RequestParam(name = "column", defaultValue = "order_time") String column,
|
||||||
|
|
|
@ -54,7 +54,8 @@ public interface SkuMapper extends BaseMapper<Sku> {
|
||||||
|
|
||||||
List<SkuQuantity> getSkuQuantitiesFromOrderIds(@Param("orderIds") List<String> orderIds);
|
List<SkuQuantity> getSkuQuantitiesFromOrderIds(@Param("orderIds") List<String> orderIds);
|
||||||
|
|
||||||
List<SkuOrderPage> fetchSkusByClient(@Param("clientId") String clientId);
|
List<SkuOrderPage> fetchSkusByClient(@Param("clientId") String clientId, @Param("offset") Integer offset, @Param("size") Integer pageSize, @Param("column") String column, @Param("order") String order);
|
||||||
|
List<SkuOrderPage> fetchSkusByClientWithFilters(@Param("clientId") String clientId, @Param("offset") Integer offset, @Param("size") Integer pageSize, @Param("column") String column, @Param("order") String order, @Param("erpCodes") String erpCodesRegex, @Param("zhNames") String zhNamesRegex, @Param("enNames") String enNamesRegex);
|
||||||
|
|
||||||
String getIdFromErpCode(@Param("erpCode") String erpCode);
|
String getIdFromErpCode(@Param("erpCode") String erpCode);
|
||||||
|
|
||||||
|
@ -65,4 +66,6 @@ public interface SkuMapper extends BaseMapper<Sku> {
|
||||||
void updateBatchStockByIds(@Param("skus") List<Sku> skuToUpdate);
|
void updateBatchStockByIds(@Param("skus") List<Sku> skuToUpdate);
|
||||||
|
|
||||||
List<SkuOrderPage> getInventoryByInvoiceNumber(@Param("invoiceNumber") String invoiceNumber);
|
List<SkuOrderPage> getInventoryByInvoiceNumber(@Param("invoiceNumber") String invoiceNumber);
|
||||||
|
|
||||||
|
List<Sku> listByClientId(@Param("clientId") String clientId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@
|
||||||
JOIN shop s ON po.shop_id = s.id
|
JOIN shop s ON po.shop_id = s.id
|
||||||
JOIN client c ON s.owner_id = c.id
|
JOIN client c ON s.owner_id = c.id
|
||||||
WHERE c.id = #{clientId}
|
WHERE c.id = #{clientId}
|
||||||
AND po.erp_status IN ('1','2')
|
AND po.erp_status IN ('1','2')
|
||||||
AND poc.erp_status IN ('1','2')
|
AND poc.erp_status IN ('1','2')
|
||||||
GROUP BY sku_id
|
GROUP BY sku_id
|
||||||
)
|
)
|
||||||
|
@ -208,7 +208,92 @@
|
||||||
LEFT JOIN sales_42 s42 ON s.id = s42.sku_id
|
LEFT JOIN sales_42 s42 ON s.id = s42.sku_id
|
||||||
LEFT JOIN sales_7 s7 ON s.id = s7.sku_id
|
LEFT JOIN sales_7 s7 ON s.id = s7.sku_id
|
||||||
LEFT JOIN qtyInOrdersNotShipped ON s.id = qtyInOrdersNotShipped.ID
|
LEFT JOIN qtyInOrdersNotShipped ON s.id = qtyInOrdersNotShipped.ID
|
||||||
WHERE client_sku.client_id = #{clientId};
|
WHERE client_sku.client_id = #{clientId}
|
||||||
|
ORDER BY ${column} ${order}
|
||||||
|
<if test="size != -1">
|
||||||
|
LIMIT #{offset}, #{size}
|
||||||
|
</if>
|
||||||
|
;
|
||||||
|
</select>
|
||||||
|
<select id="fetchSkusByClientWithFilters" resultType="org.jeecg.modules.business.vo.SkuOrderPage">
|
||||||
|
WITH qtyInOrdersNotShippedCTE AS (
|
||||||
|
SELECT sku_id as ID, SUM(quantity) AS quantity
|
||||||
|
FROM platform_order_content poc
|
||||||
|
JOIN platform_order po ON poc.platform_order_id = po.id
|
||||||
|
JOIN shop s ON po.shop_id = s.id
|
||||||
|
JOIN client c ON s.owner_id = c.id
|
||||||
|
WHERE c.id = #{clientId}
|
||||||
|
AND po.erp_status IN ('1','2')
|
||||||
|
AND poc.erp_status IN ('1','2')
|
||||||
|
GROUP BY sku_id
|
||||||
|
)
|
||||||
|
SELECT s.id,
|
||||||
|
s.erp_code,
|
||||||
|
p.en_name as productEn,
|
||||||
|
p.zh_name as product,
|
||||||
|
s.purchasing_amount,
|
||||||
|
s.available_amount,
|
||||||
|
qtyInOrdersNotShippedCTE.quantity as qtyInOrdersNotShipped,
|
||||||
|
s.available_amount + s.purchasing_amount - IF(qtyInOrdersNotShippedCTE.quantity IS NULL, 0, qtyInOrdersNotShippedCTE.quantity) as stock,
|
||||||
|
s.image_source,
|
||||||
|
s.service_fee,
|
||||||
|
IF(sp.price_rmb IS NULL, sp.price,
|
||||||
|
(
|
||||||
|
ROUND(
|
||||||
|
sp.price_rmb /
|
||||||
|
(SELECT rate
|
||||||
|
FROM exchange_rates
|
||||||
|
WHERE original_currency = 'EUR' AND target_currency = 'RMB'
|
||||||
|
ORDER BY create_time DESC LIMIT 1)
|
||||||
|
,2)
|
||||||
|
)
|
||||||
|
) as sku_price,
|
||||||
|
sp.threshold as discount_moq,
|
||||||
|
IF(sp.price_rmb IS NULL, sp.discounted_price,
|
||||||
|
(
|
||||||
|
ROUND(
|
||||||
|
sp.discounted_price_rmb /
|
||||||
|
(SELECT rate
|
||||||
|
FROM exchange_rates
|
||||||
|
WHERE target_currency = 'EUR' AND original_currency = 'RMB'
|
||||||
|
ORDER BY create_time DESC LIMIT 1)
|
||||||
|
,2)
|
||||||
|
)
|
||||||
|
) as discounted_price,
|
||||||
|
s7.quantity as sales_last_week,
|
||||||
|
s28.quantity as sales_four_weeks,
|
||||||
|
s42.quantity as sales_six_weeks
|
||||||
|
FROM sku s
|
||||||
|
JOIN client_sku ON s.id = client_sku.sku_id
|
||||||
|
JOIN product p ON s.product_id = p.id
|
||||||
|
LEFT JOIN sku_current_price sp ON s.id = sp.sku_id
|
||||||
|
LEFT JOIN sales_28 s28 ON s.id = s28.sku_id
|
||||||
|
LEFT JOIN sales_42 s42 ON s.id = s42.sku_id
|
||||||
|
LEFT JOIN sales_7 s7 ON s.id = s7.sku_id
|
||||||
|
LEFT JOIN qtyInOrdersNotShippedCTE ON s.id = qtyInOrdersNotShippedCTE.ID
|
||||||
|
WHERE client_sku.client_id = #{clientId}
|
||||||
|
AND (
|
||||||
|
<if test="erpCodes != ''">
|
||||||
|
s.erp_code REGEXP #{erpCodes}
|
||||||
|
</if>
|
||||||
|
<if test="zhNames != ''">
|
||||||
|
<if test="erpCodes != ''">
|
||||||
|
AND
|
||||||
|
</if>
|
||||||
|
p.zh_name REGEXP #{zhNames}
|
||||||
|
</if>
|
||||||
|
<if test="enNames != ''">
|
||||||
|
<if test="erpCodes != '' || zhNames != ''">
|
||||||
|
AND
|
||||||
|
</if>
|
||||||
|
p.en_name REGEXP #{enNames}
|
||||||
|
</if>
|
||||||
|
)
|
||||||
|
ORDER BY ${column} ${order}
|
||||||
|
<if test="size != -1">
|
||||||
|
LIMIT #{offset}, #{size}
|
||||||
|
</if>
|
||||||
|
;
|
||||||
</select>
|
</select>
|
||||||
<select id="getInventoryByInvoiceNumber" resultType="org.jeecg.modules.business.vo.SkuOrderPage">
|
<select id="getInventoryByInvoiceNumber" resultType="org.jeecg.modules.business.vo.SkuOrderPage">
|
||||||
WITH skusFromInvoice AS (
|
WITH skusFromInvoice AS (
|
||||||
|
@ -316,4 +401,14 @@
|
||||||
#{sku.id}
|
#{sku.id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
<select id="listByClientId" resultType="org.jeecg.modules.business.vo.SkuOrderPage">
|
||||||
|
SELECT s.id,
|
||||||
|
s.erp_code,
|
||||||
|
p.en_name as productEn,
|
||||||
|
p.zh_name as product
|
||||||
|
FROM sku s
|
||||||
|
JOIN client_sku ON s.id = client_sku.sku_id
|
||||||
|
JOIN product p ON s.product_id = p.id
|
||||||
|
WHERE client_sku.client_id = #{clientId};
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -95,12 +95,13 @@ public interface ISkuService extends IService<Sku> {
|
||||||
|
|
||||||
List<SkuQuantity> getSkuQuantitiesFromOrderIds(List<String> orderIds);
|
List<SkuQuantity> getSkuQuantitiesFromOrderIds(List<String> orderIds);
|
||||||
|
|
||||||
List<SkuOrderPage> fetchSkusByClient(String clientId);
|
List<SkuOrderPage> fetchSkusByClient(String clientId, Integer pageNo, Integer pageSize, String column, String order);
|
||||||
|
List<SkuOrderPage> fetchSkusByClientWithFilters(String clientId, Integer pageNo, Integer pageSize, String column, String order, List<String> erpCodes, List<String> zhNames, List<String> enNames);
|
||||||
|
|
||||||
void addSkuQuantity(Map<String, Integer> quantityPurchased);
|
void addSkuQuantity(Map<String, Integer> quantityPurchased);
|
||||||
|
|
||||||
String getIdFromErpCode(String erpCode);
|
String getIdFromErpCode(String erpCode);
|
||||||
Sku getByErpCode(String erpCode);
|
Sku getByErpCode(String erpCode);
|
||||||
void updateBatchStockByIds(List<Sku> skuToUpdate);
|
void updateBatchStockByIds(List<Sku> skuToUpdate);
|
||||||
List<SkuOrderPage> getInventoryByInvoiceNumber(String invoiceNumber);
|
List<SkuOrderPage> getInventoryByInvoiceNumber(String invoiceNumber);
|
||||||
|
List<Sku> listByClientId(String clientId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,8 +417,37 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements ISkuS
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SkuOrderPage> fetchSkusByClient(String clientId) {
|
public List<SkuOrderPage> fetchSkusByClient(String clientId, Integer pageNo, Integer pageSize, String column, String order) {
|
||||||
return skuMapper.fetchSkusByClient(clientId);
|
int offset = (pageNo - 1) * pageSize;
|
||||||
|
return skuMapper.fetchSkusByClient(clientId, offset, pageSize, column, order);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SkuOrderPage> fetchSkusByClientWithFilters(String clientId, Integer pageNo, Integer pageSize, String column, String order, List<String> erpCodes, List<String> zhNames, List<String> enNames) {
|
||||||
|
int offset = (pageNo - 1) * pageSize;
|
||||||
|
StringBuilder erpCodesRegex= new StringBuilder(), zhNamesRegex = new StringBuilder(), enNamesRegex = new StringBuilder();
|
||||||
|
if(erpCodes != null){
|
||||||
|
erpCodesRegex.append("^");
|
||||||
|
for(String name : erpCodes){
|
||||||
|
erpCodesRegex.append("(?=.*").append(name).append(")");
|
||||||
|
}
|
||||||
|
erpCodesRegex.append(".*");
|
||||||
|
}
|
||||||
|
if(enNames != null){
|
||||||
|
enNamesRegex.append("^");
|
||||||
|
for(String name : enNames){
|
||||||
|
enNamesRegex.append("(?=.*").append(name).append(")");
|
||||||
|
}
|
||||||
|
enNamesRegex.append(".*");
|
||||||
|
}
|
||||||
|
if(zhNames != null){
|
||||||
|
zhNamesRegex.append("^");
|
||||||
|
for(String name : zhNames){
|
||||||
|
zhNamesRegex.append("(?=.*").append(name).append(")");
|
||||||
|
}
|
||||||
|
zhNamesRegex.append(".*$");
|
||||||
|
}
|
||||||
|
return skuMapper.fetchSkusByClientWithFilters(clientId, offset, pageSize, column, order, erpCodesRegex.toString(), zhNamesRegex.toString(), enNamesRegex.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -446,4 +475,9 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements ISkuS
|
||||||
return skuMapper.getInventoryByInvoiceNumber(invoiceNumber);
|
return skuMapper.getInventoryByInvoiceNumber(invoiceNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Sku> listByClientId(String clientId) {
|
||||||
|
return skuMapper.listByClientId(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue