mirror of https://github.com/jeecgboot/jeecg-boot
product order
parent
fdd5159032
commit
48f445856d
|
@ -12,14 +12,9 @@ import org.jeecg.common.aspect.annotation.AutoLog;
|
|||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.business.entity.ShippingDiscount;
|
||||
import org.jeecg.modules.business.entity.Sku;
|
||||
import org.jeecg.modules.business.entity.SkuDeclaredValue;
|
||||
import org.jeecg.modules.business.entity.SkuPrice;
|
||||
import org.jeecg.modules.business.entity.*;
|
||||
import org.jeecg.modules.business.service.*;
|
||||
import org.jeecg.modules.business.vo.SkuName;
|
||||
import org.jeecg.modules.business.vo.SkuPage;
|
||||
import org.jeecg.modules.business.vo.SkuUpdate;
|
||||
import org.jeecg.modules.business.vo.*;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
|
@ -46,7 +41,7 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
@Api(tags = "SKU表")
|
||||
@RestController
|
||||
@RequestMapping("/business/sku")
|
||||
@RequestMapping("/sku")
|
||||
@Slf4j
|
||||
public class SkuController {
|
||||
@Autowired
|
||||
|
@ -57,6 +52,8 @@ public class SkuController {
|
|||
private IShippingDiscountService shippingDiscountService;
|
||||
@Autowired
|
||||
private ISkuDeclaredValueService skuDeclaredValueService;
|
||||
@Autowired
|
||||
private IClientService clientService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
|
@ -349,10 +346,10 @@ public class SkuController {
|
|||
|
||||
@GetMapping("/skusByClient")
|
||||
public Result<?> skusByClient(@RequestParam String clientId) {
|
||||
List<Sku> skus = skuService.fetchSkusByClient(clientId);
|
||||
IPage<Sku> page = new Page<>();
|
||||
page.setRecords(skus);
|
||||
page.setTotal(skus.size());
|
||||
List<SkuOrderPage> skuOrdersPage = skuService.fetchSkusByClient(clientId);
|
||||
IPage<SkuOrderPage> page = new Page<>();
|
||||
page.setRecords(skuOrdersPage);
|
||||
page.setTotal(skuOrdersPage.size());
|
||||
return Result.OK(page);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -418,7 +418,27 @@ public class InvoiceController {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/makeManualSkuPurchaseInvoice")
|
||||
public Result<?> createOrder(@RequestBody Map<String, Integer> payload) {
|
||||
InvoiceMetaData metaData;
|
||||
List<SkuQuantity> skuQuantities = new ArrayList<>();
|
||||
for(Map.Entry<String, Integer> entry : payload.entrySet()) {
|
||||
String skuId = skuService.getIdFromErpCode(entry.getKey());
|
||||
skuQuantities.add(new SkuQuantity(skuId, entry.getValue()));
|
||||
}
|
||||
try {
|
||||
String purchaseId = purchaseOrderService.addPurchase(skuQuantities);
|
||||
metaData = purchaseOrderService.makeInvoice(purchaseId);
|
||||
return Result.OK(metaData);
|
||||
} catch (UserException e) {
|
||||
return Result.error(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
return Result.error("Sorry, server error, please try later");
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@GetMapping(value = "/preShipping/orderTime")
|
||||
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() +
|
||||
|
|
|
@ -27,4 +27,6 @@ public interface ClientMapper extends BaseMapper<Client> {
|
|||
Client getClientFromPurchase(@Param("purchaseId") String purchaseId);
|
||||
|
||||
List<String> getClientsFromPurchases(@Param("purchaseIds") List<String> purchaseIds);
|
||||
|
||||
Client getClientBySku(@Param("skuId") String skuId);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.business.mapper;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.business.entity.Sku;
|
||||
import org.jeecg.modules.business.vo.SkuOrderPage;
|
||||
import org.jeecg.modules.business.vo.SkuQuantity;
|
||||
import org.jeecg.modules.business.vo.SkuUpdate;
|
||||
import org.jeecg.modules.business.vo.inventory.InventoryRecord;
|
||||
|
@ -53,5 +54,7 @@ public interface SkuMapper extends BaseMapper<Sku> {
|
|||
|
||||
List<SkuQuantity> getSkuQuantitiesFromOrderIds(@Param("orderIds") List<String> orderIds);
|
||||
|
||||
List<Sku> fetchSkusByClient(@Param("clientId") String clientId);
|
||||
List<SkuOrderPage> fetchSkusByClient(@Param("clientId") String clientId);
|
||||
|
||||
String getIdFromErpCode(@Param("erpCode") String erpCode);
|
||||
}
|
||||
|
|
|
@ -58,4 +58,10 @@
|
|||
#{purchaseId}
|
||||
</foreach>;
|
||||
</select>
|
||||
<select id="getClientBySku" resultType="org.jeecg.modules.business.entity.Client">
|
||||
SELECT c.*
|
||||
FROM client c
|
||||
JOIN client_sku cs ON c.id = cs.client_id
|
||||
WHERE cs.sku_id = #{skuId};
|
||||
</select>
|
||||
</mapper>
|
|
@ -151,11 +151,66 @@
|
|||
AND virtual_product_available = 0
|
||||
GROUP BY sku_id;
|
||||
</select>
|
||||
<select id="fetchSkusByClient" resultType="org.jeecg.modules.business.entity.Sku">
|
||||
SELECT s.id, s.erp_code, CONCAT(p.code, '(', p.zh_name,')') as product_id ,s.purchasing_amount, s.available_amount, s.image_source, s.shipping_discount, s.service_fee
|
||||
<select id="fetchSkusByClient" resultType="org.jeecg.modules.business.vo.SkuOrderPage">
|
||||
WITH qtyInOrdersNotShipped 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.zh_name as product,
|
||||
s.purchasing_amount,
|
||||
s.available_amount,
|
||||
qtyInOrdersNotShipped.quantity as qtyInOrdersNotShipped,
|
||||
IF(s.available_amount IS NULL, 0, s.available_amount) + IF(s.purchasing_amount IS NULL, 0, s.purchasing_amount) - IF(qtyInOrdersNotShipped.quantity IS NULL, 0, qtyInOrdersNotShipped.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 cs ON s.id = cs.sku_id
|
||||
JOIN product p ON s.product_id = p.id
|
||||
JOIN client_sku cs ON s.id = cs.sku_id
|
||||
JOIN product p ON s.product_id = p.id
|
||||
LEFT JOIN sku_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 qtyInOrdersNotShipped ON s.id = qtyInOrdersNotShipped.ID
|
||||
WHERE cs.client_id = #{clientId};
|
||||
</select>
|
||||
<select id="getIdFromErpCode" resultType="java.lang.String">
|
||||
SELECT id
|
||||
FROM sku
|
||||
WHERE erp_code = #{erpCode};
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -54,4 +54,6 @@ public interface IClientService extends IService<Client> {
|
|||
Client getClientFromPurchase(String purchaseId);
|
||||
|
||||
List<String> getClientsFromPurchases(List<String> purchaseIds);
|
||||
|
||||
Client getClientBySku(String skuId);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.io.Serializable;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: SKU表
|
||||
|
@ -94,5 +95,9 @@ public interface ISkuService extends IService<Sku> {
|
|||
|
||||
List<SkuQuantity> getSkuQuantitiesFromOrderIds(List<String> orderIds);
|
||||
|
||||
List<Sku> fetchSkusByClient(String clientId);
|
||||
List<SkuOrderPage> fetchSkusByClient(String clientId);
|
||||
|
||||
void addSkuQuantity(Map<String, Integer> quantityPurchased);
|
||||
|
||||
String getIdFromErpCode(String erpCode);
|
||||
}
|
||||
|
|
|
@ -138,6 +138,11 @@ public class ClientServiceImpl extends ServiceImpl<ClientMapper, Client> impleme
|
|||
return clientMapper.getClientsFromPurchases(purchaseIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Client getClientBySku(String skuId) {
|
||||
return clientMapper.getClientBySku(skuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientEntity(String id) {
|
||||
return clientMapper.getClientEntity(id);
|
||||
|
|
|
@ -412,7 +412,17 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements ISkuS
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Sku> fetchSkusByClient(String clientId) {
|
||||
public List<SkuOrderPage> fetchSkusByClient(String clientId) {
|
||||
return skuMapper.fetchSkusByClient(clientId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSkuQuantity(Map<String, Integer> quantityPurchased) {
|
||||
skuMapper.addSkuQuantity(quantityPurchased);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdFromErpCode(String erpCode) {
|
||||
return skuMapper.getIdFromErpCode(erpCode);
|
||||
}
|
||||
}
|
|
@ -328,19 +328,6 @@ public class PurchaseOrderServiceImpl extends ServiceImpl<PurchaseOrderMapper, P
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated a purchase order based on sku quantity, and
|
||||
* these quantities are recorded to client's inventory.
|
||||
*
|
||||
* @param skuQuantities a list of platform orders
|
||||
* @return the purchase order's identifier (UUID)
|
||||
*/
|
||||
@Override
|
||||
public String addPurchase(List<SkuQuantity> skuQuantities) throws UserException {
|
||||
return addPurchase(skuQuantities, Collections.emptyList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generated a purchase order based on sku quantity, these sku are bought
|
||||
* for some platform orders, their quantity may higher than those in platform
|
||||
|
@ -434,6 +421,93 @@ public class PurchaseOrderServiceImpl extends ServiceImpl<PurchaseOrderMapper, P
|
|||
// 4. return purchase id
|
||||
return purchaseID;
|
||||
}
|
||||
/**
|
||||
* Generated a purchase order based on sku quantity, hand-picked by sales
|
||||
* @param skuQuantities a list of platform orders
|
||||
* @return the purchase order's identifier (UUID)
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public String addPurchase(List<SkuQuantity> skuQuantities) throws UserException {
|
||||
|
||||
Client client = clientService.getCurrentClient();
|
||||
if(client == null) {
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
if(sysUser.getOrgCode().contains("A01") || sysUser.getOrgCode().contains("A03")) {
|
||||
client = clientService.getClientBySku(skuQuantities.get(0).getID());
|
||||
}
|
||||
else
|
||||
throw new UserException("User is not a client");
|
||||
}
|
||||
String currencyId = currencyService.getIdByCode(client.getCurrency());
|
||||
List<OrderContentDetail> details = platformOrderService.searchPurchaseOrderDetail(skuQuantities);
|
||||
OrdersStatisticData data = OrdersStatisticData.makeData(details, null);
|
||||
|
||||
String purchaseID = UUID.randomUUID().toString();
|
||||
|
||||
String lastInvoiceNumber = purchaseOrderMapper.lastInvoiceNumber();
|
||||
String invoiceNumber = new PurchaseInvoiceCodeRule().next(lastInvoiceNumber);
|
||||
// 1. save purchase itself
|
||||
purchaseOrderMapper.addPurchase(
|
||||
purchaseID,
|
||||
client.fullName(),
|
||||
currencyId,
|
||||
client.getId(),
|
||||
data.getEstimatedTotalPrice(),
|
||||
data.getReducedAmount(),
|
||||
data.finalAmount(),
|
||||
invoiceNumber
|
||||
);
|
||||
|
||||
// 2. save purchase's content
|
||||
List<OrderContentEntry> entries = details.stream()
|
||||
.map(
|
||||
d -> (
|
||||
new OrderContentEntry(
|
||||
d.getQuantity(),
|
||||
d.totalPrice(),
|
||||
d.getSkuDetail().getSkuId()
|
||||
)
|
||||
)
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
purchaseOrderContentMapper.addAll(client.fullName(), purchaseID, entries);
|
||||
Map<String, Integer> quantityPurchased = skuQuantities.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
SkuQuantity::getID,
|
||||
SkuQuantity::getQuantity
|
||||
)
|
||||
);
|
||||
skuService.addSkuQuantity(quantityPurchased);
|
||||
|
||||
// 3. save the application of promotion information
|
||||
List<PromotionHistoryEntry> promotionHistoryEntries = details.stream()
|
||||
.filter(orderContentDetail -> orderContentDetail.getSkuDetail().getPromotion() != Promotion.ZERO_PROMOTION)
|
||||
.map(orderContentDetail -> {
|
||||
String promotion = orderContentDetail.getSkuDetail().getPromotion().getId();
|
||||
int count = orderContentDetail.promotionCount();
|
||||
return new PromotionHistoryEntry(promotion, count);
|
||||
}).collect(Collectors.toList());
|
||||
if (!promotionHistoryEntries.isEmpty()) {
|
||||
skuPromotionHistoryMapper.addAll(client.fullName(), promotionHistoryEntries, purchaseID);
|
||||
}
|
||||
|
||||
// TODO use real client address
|
||||
// send email to client
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("client", client.getFirstName());
|
||||
map.put("order_number", invoiceNumber);
|
||||
pushMsgUtil.sendMessage(
|
||||
SendMsgTypeEnum.EMAIL.getType(),
|
||||
"purchase_order_confirmation",
|
||||
map,
|
||||
"service@wia-sourcing.com"
|
||||
);
|
||||
|
||||
// 4. return purchase id
|
||||
return purchaseID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
package org.jeecg.modules.business.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import org.jeecg.modules.business.entity.SkuPrice;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
|
||||
|
||||
/**
|
||||
* @Description: SKU表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2021-08-13
|
||||
* @Version: V1.2
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "skuOrderPage对象", description = "SKU表")
|
||||
public class SkuOrderPage {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
@Excel(name = "商品ID", width = 15, dictTable = "product", dicText = "code", dicCode = "id")
|
||||
@Dict(dictTable = "product", dicText = "code", dicCode = "id")
|
||||
@ApiModelProperty(value = "商品ID")
|
||||
private String product;
|
||||
/**
|
||||
* ERP中商品代码
|
||||
*/
|
||||
@Excel(name = "ERP中商品代码", width = 15)
|
||||
@ApiModelProperty(value = "ERP中商品代码")
|
||||
private String erpCode;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
@Excel(name = "库存数量", width = 15)
|
||||
@ApiModelProperty(value = "库存数量")
|
||||
private Integer availableAmount;
|
||||
/**
|
||||
* 在途数量
|
||||
*/
|
||||
@Excel(name = "在途数量", width = 15)
|
||||
@ApiModelProperty(value = "在途数量")
|
||||
private Integer purchasingAmount;
|
||||
/**
|
||||
* 未发货数量
|
||||
*/
|
||||
@Excel(name = "未发货数量", width = 15)
|
||||
@ApiModelProperty(value = "未发货数量")
|
||||
private Integer qtyInOrdersNotShipped;
|
||||
/**
|
||||
* stock
|
||||
*/
|
||||
@Excel(name = "stock", width = 15)
|
||||
@ApiModelProperty(value = "stock")
|
||||
private Integer stock;
|
||||
/**
|
||||
* 图片链接
|
||||
*/
|
||||
@Excel(name = "图片链接", width = 15)
|
||||
@ApiModelProperty(value = "图片链接")
|
||||
private String imageSource;
|
||||
/**
|
||||
* 运费折扣
|
||||
*/
|
||||
@Excel(name = "运费折扣", width = 15)
|
||||
@ApiModelProperty(value = "运费折扣")
|
||||
private java.math.BigDecimal shippingDiscount;
|
||||
/**
|
||||
* 服务费
|
||||
*/
|
||||
@Excel(name = "服务费", width = 15)
|
||||
@ApiModelProperty(value = "服务费")
|
||||
private java.math.BigDecimal serviceFee;
|
||||
/**
|
||||
* SKU价格
|
||||
*/
|
||||
@ExcelCollection(name = "SKU价格")
|
||||
@ApiModelProperty(value = "SKU价格")
|
||||
private java.math.BigDecimal skuPrice;
|
||||
/**
|
||||
* 优惠价起订量
|
||||
*/
|
||||
@Excel(name = "优惠价起订量", width = 15)
|
||||
@ApiModelProperty(value = "优惠价起订量")
|
||||
private java.lang.Integer discountMoq;
|
||||
/**
|
||||
* 优惠价
|
||||
*/
|
||||
@Excel(name = "优惠价", width = 15)
|
||||
@ApiModelProperty(value = "优惠价")
|
||||
private java.math.BigDecimal discountedPrice;
|
||||
/**
|
||||
* Sales last week
|
||||
*/
|
||||
@Excel(name = "sales last week", width = 15)
|
||||
@ApiModelProperty(value = "sales last week")
|
||||
private java.lang.Integer salesLastWeek;
|
||||
/**
|
||||
* Sales last four week
|
||||
*/
|
||||
@Excel(name = "sales last 28 days", width = 15)
|
||||
@ApiModelProperty(value = "sales last 28 days")
|
||||
private java.lang.Integer salesFourWeeks;
|
||||
/**
|
||||
* Sales last six weeks
|
||||
*/
|
||||
@Excel(name = "sales last 42 days", width = 15)
|
||||
@ApiModelProperty(value = "sales last 42 days")
|
||||
private java.lang.Integer salesSixWeeks;
|
||||
}
|
Loading…
Reference in New Issue