From 7d996594cc3e0214adbe8ec2e125da0e4fdba1a7 Mon Sep 17 00:00:00 2001 From: Gauthier LO Date: Mon, 13 May 2024 09:46:22 +0200 Subject: [PATCH] feat : init vip and confirmed clients balance at client creation and some fixes --- db/routines/calculate_shipping_fees.sql | 43 +++++++++++++++++++ db/routines/get_registration_fees.sql | 26 +++++++++++ db/routines/purchase_total.sql | 12 ++++++ db/routines/shopErpToId.sql | 12 ++++++ db/routines/skuErpToId.sql | 12 ++++++ db/triggers/init_balance.sql | 15 +++++++ .../exception/JeecgBootExceptionHandler.java | 2 +- .../admin/UserClientController.java | 10 ++++- .../shippingInvoice/InvoiceController.java | 8 +++- 9 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 db/routines/calculate_shipping_fees.sql create mode 100644 db/routines/get_registration_fees.sql create mode 100644 db/routines/purchase_total.sql create mode 100644 db/routines/shopErpToId.sql create mode 100644 db/routines/skuErpToId.sql create mode 100644 db/triggers/init_balance.sql diff --git a/db/routines/calculate_shipping_fees.sql b/db/routines/calculate_shipping_fees.sql new file mode 100644 index 000000000..e1b7a9359 --- /dev/null +++ b/db/routines/calculate_shipping_fees.sql @@ -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; + diff --git a/db/routines/get_registration_fees.sql b/db/routines/get_registration_fees.sql new file mode 100644 index 000000000..8b8e85d95 --- /dev/null +++ b/db/routines/get_registration_fees.sql @@ -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; + diff --git a/db/routines/purchase_total.sql b/db/routines/purchase_total.sql new file mode 100644 index 000000000..68a4d717d --- /dev/null +++ b/db/routines/purchase_total.sql @@ -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; + diff --git a/db/routines/shopErpToId.sql b/db/routines/shopErpToId.sql new file mode 100644 index 000000000..8205ee8bb --- /dev/null +++ b/db/routines/shopErpToId.sql @@ -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; + diff --git a/db/routines/skuErpToId.sql b/db/routines/skuErpToId.sql new file mode 100644 index 000000000..da2137fd3 --- /dev/null +++ b/db/routines/skuErpToId.sql @@ -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; + diff --git a/db/triggers/init_balance.sql b/db/triggers/init_balance.sql new file mode 100644 index 000000000..cfef55fe7 --- /dev/null +++ b/db/triggers/init_balance.sql @@ -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 ; \ No newline at end of file diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java index 0c246f515..b735ceae1 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/JeecgBootExceptionHandler.java @@ -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()); } /** diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/UserClientController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/UserClientController.java index 7df4d67bd..99c0fbdb3 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/UserClientController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/UserClientController.java @@ -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> internalClientList = new HashMap<>(); internalClientList.put("internal", userClientService.listClients()); return Result.OK("internal usage", internalClientList); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java index e9a23a938..f25f26c22 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/admin/shippingInvoice/InvoiceController.java @@ -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 {