feat : init vip and confirmed clients balance at client creation and some fixes

pull/6221/head
Gauthier LO 2024-05-13 09:46:22 +02:00
parent 8f81e84c54
commit 7d996594cc
9 changed files with 136 additions and 4 deletions

View File

@ -0,0 +1,43 @@
create
definer = admin@`%` function calculate_shipping_fees(logistic_channel varchar(50), country varchar(2),
shipping_date date, weight int) returns double
BEGIN
DECLARE minimum_weight INT;
DECLARE minimum_weight_price double;
DECLARE cal_unit INT;
DECLARE cal_unit_price double;
DECLARE additional_cost double;
DECLARE shipping_fee double;
SELECT lcp.minimum_weight,
lcp.minimum_weight_price,
lcp.cal_unit,
lcp.cal_unit_price,
lcp.additional_cost
INTO minimum_weight,
minimum_weight_price,
cal_unit,
cal_unit_price,
additional_cost
FROM logistic_channel_price lcp
JOIN logistic_channel lc ON lc.id = lcp.channel_id
WHERE lc.zh_name = logistic_channel
AND weight_range_start <= weight
AND weight_range_end >= weight
AND effective_country = country
AND effective_date <= shipping_date
ORDER BY effective_date
DESC
LIMIT 1;
IF weight = 0 THEN
SET shipping_fee = 0;
ELSEIF weight < minimum_weight THEN
SET shipping_fee = minimum_weight_price;
ELSE
SET shipping_fee = ((weight - minimum_weight) / cal_unit) * cal_unit_price + minimum_weight_price;
END IF;
RETURN shipping_fee;
END;

View File

@ -0,0 +1,26 @@
create
definer = admin@`%` function get_registration_fees(logistic_channel varchar(50), country varchar(2),
shipping_date date, weight int) returns double
BEGIN
DECLARE registration_fee double;
SELECT lcp.registration_fee
INTO registration_fee
FROM logistic_channel_price lcp
JOIN logistic_channel lc ON lc.id = lcp.channel_id
WHERE lc.zh_name = logistic_channel
AND weight_range_start <= weight
AND weight_range_end >= weight
AND effective_country = country
AND effective_date <= shipping_date
ORDER BY effective_date
DESC
LIMIT 1;
IF weight = 0 THEN
RETURN 0;
ELSE
RETURN registration_fee;
END IF;
END;

View File

@ -0,0 +1,12 @@
create
definer = admin@`%` function purchase_total(invoice_number varchar(12)) returns decimal(10, 2)
BEGIN
RETURN (
SELECT SUM(poc.purchase_fee) as total
FROM platform_order_content as poc
JOIN platform_order po
ON po.id = poc.platform_order_id
WHERE po.shipping_invoice_number = invoice_number
);
END;

View File

@ -0,0 +1,12 @@
create
definer = admin@`%` function shopErpToId(erp varchar(36)) returns varchar(36) reads sql data
BEGIN
DECLARE found_shop_id varchar(36);
SET found_shop_id = (SELECT id FROM shop WHERE erp_code = erp);
IF found_shop_id IS NOT NULL THEN
RETURN found_shop_id;
ELSE
RETURN erp;
END IF;
END;

View File

@ -0,0 +1,12 @@
create
definer = admin@`%` function skuErpToId(sku varchar(100)) returns varchar(100)
BEGIN
DECLARE found_sku_id varchar(36);
SET found_sku_id = (SELECT id FROM sku WHERE erp_code = sku);
IF found_sku_id IS NOT NULL THEN
RETURN found_sku_id;
ELSE
RETURN sku;
END IF;
END;

View File

@ -0,0 +1,15 @@
DELIMITER $$
CREATE TRIGGER init_balance
AFTER INSERT ON client FOR EACH ROW
BEGIN
DECLARE clientCategory VARCHAR(10);
SET @clientCategory := (SELECT name FROM client_category WHERE id=NEW.client_category_id);
IF @clientCategory = 'vip' OR @clientCategory = 'confirmed' THEN
INSERT INTO balance (id, create_by, create_time, client_id, currency_id, operation_type, amount)
VALUES (UUID(), NEW.create_by, NOW(), NEW.id, (SELECT id FROM currency WHERE code = 'EUR'), 'init', 0),
(UUID(), NEW.create_by, NOW(), NEW.id, (SELECT id FROM currency WHERE code = 'USD'), 'init', 0);
END IF;
END$$
DELIMITER ;

View File

@ -83,7 +83,7 @@ public class JeecgBootExceptionHandler {
return Result.error(errorInfoEnum.getError());
}
//update-end---author:zyf ---date:20220411 for处理Sentinel限流自定义异常
return Result.error("操作失败,"+e.getMessage());
return Result.error("Error : "+e.getMessage());
}
/**

View File

@ -8,7 +8,9 @@ import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.business.entity.Client;
import org.jeecg.modules.business.entity.ClientCategory;
import org.jeecg.modules.business.service.IUserClientService;
import org.jeecg.modules.system.service.ISysDepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -24,17 +26,23 @@ import java.util.Map;
public class UserClientController {
@Autowired
private IUserClientService userClientService;
@Autowired
private ISysDepartService sysDepartService;
@Autowired
private Environment env;
/**
* Checks if the user is a client or internal user
* @return the client's info OR a list of clients
*/
@GetMapping(value = "/getClient")
public Result<?> getClientByUserId() {
String companyOrgCode = sysDepartService.queryCodeByDepartName(env.getProperty("company.orgName"));
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String orgCode = loginUser.getOrgCode();
String userId = loginUser.getId();
Client client = userClientService.getClientMinInfoByUserId(userId);
if(client == null) {
if(loginUser.getOrgCode().contains("A01") || loginUser.getOrgCode().contains("A03")) {
if(orgCode.equals(companyOrgCode)) {
Map<String, List<Client>> internalClientList = new HashMap<>();
internalClientList.put("internal", userClientService.listClients());
return Result.OK("internal usage", internalClientList);

View File

@ -121,6 +121,8 @@ public class InvoiceController {
@Autowired
private ISysDepartService sysDepartService;
@Autowired
private IUserClientService userClientService;
@Autowired
Environment env;
@Value("${jeecg.path.shippingInvoiceDir}")
@ -984,8 +986,10 @@ public class InvoiceController {
customerFullName = client.fullName();
String destEmail;
if(!orgCode.equals(companyOrgCode)) {
System.out.println(email + " - " + client.getEmail());
if(!client.getEmail().equals(email)) {
log.info("User {} is trying to access invoice {} from client {}", sysUser.getUsername(), invoiceNumber, client.getInternalCode());
Client userClient = userClientService.getClientByUserId(sysUser.getId());
if(!client.getId().equals(userClient.getId())) {
return Result.error(403,"Not authorized to view this page.");
}
else {