费用提交
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
package com.baiyue.lastleg.procurement.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/** 方向变更只读门禁,购买与收货事实仍归原履约模型。 */
|
||||
@Mapper
|
||||
public interface ProcurementDirectionMapper {
|
||||
/** 已发生的购买或起运仓事实禁止通过审核切换方向。 */
|
||||
@Select("SELECT EXISTS(SELECT 1 FROM ll_procurement_flow WHERE order_id=#{orderId} AND "
|
||||
+ "(purchased_at IS NOT NULL OR actual_warehouse_id IS NOT NULL OR overseas_shipped_at IS NOT NULL))")
|
||||
boolean hasStarted(@Param("orderId") long orderId);
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baiyue.lastleg.procurement.repository;
|
||||
|
||||
import com.baiyue.lastleg.procurement.mapper.ProcurementDirectionMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/** 采购方向审核的数据访问边界。 */
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class ProcurementDirectionRepository {
|
||||
private final ProcurementDirectionMapper mapper;
|
||||
/** 在订单行锁内读取履约事实,避免改向重解释原始货物来源。 */
|
||||
public boolean hasStarted(long orderId) { return mapper.hasStarted(orderId); }
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baiyue.lastleg.procurement.service;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
/** 采购方向决定起运仓类型,历史两段编码分别代表起运段和目的地段。 */
|
||||
public final class ProcurementDirection {
|
||||
public static final String IMPORT = "OVERSEAS_TO_DOMESTIC";
|
||||
public static final String EXPORT = "DOMESTIC_TO_OVERSEAS";
|
||||
private ProcurementDirection() { }
|
||||
/** 旧订单缺少方向时保持原进口流程。 */
|
||||
public static String normalize(String value) {
|
||||
if (value == null) return IMPORT;
|
||||
if (!IMPORT.equals(value) && !EXPORT.equals(value)) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "采购方向无效");
|
||||
return value;
|
||||
}
|
||||
/** 展示区域随方向切换,不改历史技术段编码和关联。 */
|
||||
public static String display(String text, String direction) {
|
||||
if (text == null || !EXPORT.equals(normalize(direction))) return text;
|
||||
return text.replace("海外", "__ORIGIN__").replace("国内", "海外").replace("__ORIGIN__", "国内");
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.baiyue.lastleg.financefee;
|
||||
|
||||
import com.baiyue.common.security.AuthenticatedUser;
|
||||
import com.baiyue.lastleg.financefee.controller.PlatformOverseasFeeSourceController;
|
||||
import com.baiyue.lastleg.financefee.service.OverseasFeeDeliveryService;
|
||||
import com.baiyue.lastleg.financefee.service.OverseasFeeSourceService;
|
||||
import com.baiyue.lastleg.financefee.service.OverseasManualFeeService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class PlatformOverseasFeeSourceControllerSecurityTest {
|
||||
@Test
|
||||
void rejectsNonPlatformTenantBeforeReadingFeeData() throws Exception {
|
||||
var controller = new PlatformOverseasFeeSourceController(
|
||||
mock(OverseasFeeSourceService.class), mock(OverseasManualFeeService.class),
|
||||
mock(OverseasFeeDeliveryService.class));
|
||||
var mvc = MockMvcBuilders.standaloneSetup(controller)
|
||||
.setCustomArgumentResolvers(identity(new AuthenticatedUser(7L, 42L, 0L, 1L,
|
||||
"customer-user", "LASTLEG", "WEB", Set.of())))
|
||||
.build();
|
||||
|
||||
mvc.perform(get("/api/platform/v1/last-leg/finance-fee-sources"))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
private static HandlerMethodArgumentResolver identity(AuthenticatedUser user) {
|
||||
return new HandlerMethodArgumentResolver() {
|
||||
@Override public boolean supportsParameter(org.springframework.core.MethodParameter parameter) {
|
||||
return parameter.getParameterType() == AuthenticatedUser.class;
|
||||
}
|
||||
|
||||
@Override public Object resolveArgument(org.springframework.core.MethodParameter parameter,
|
||||
org.springframework.web.method.support.ModelAndViewContainer container,
|
||||
org.springframework.web.context.request.NativeWebRequest request,
|
||||
org.springframework.web.bind.support.WebDataBinderFactory binder) {
|
||||
return user;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baiyue.lastleg.procurement.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||
import com.baiyue.lastleg.procurement.mapper.ProcurementDirectionMapper;
|
||||
import com.baiyue.lastleg.procurement.repository.ProcurementDirectionRepository;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import java.util.UUID;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ProcurementDirectionPersistenceTest {
|
||||
@Test void directionGateReadsOnlyThisOrdersRecordedFacts() throws Exception {
|
||||
var ds = new DriverManagerDataSource("jdbc:h2:mem:"+UUID.randomUUID()+";MODE=MySQL;DB_CLOSE_DELAY=-1","sa","");
|
||||
var jdbc = new JdbcTemplate(ds);
|
||||
jdbc.execute("CREATE TABLE ll_procurement_flow(order_id BIGINT PRIMARY KEY,purchased_at TIMESTAMP,actual_warehouse_id BIGINT,overseas_shipped_at TIMESTAMP)");
|
||||
var config = new MybatisConfiguration(); config.addMapper(ProcurementDirectionMapper.class);
|
||||
var factory = new MybatisSqlSessionFactoryBean(); factory.setDataSource(ds); factory.setConfiguration(config);
|
||||
var repository = new ProcurementDirectionRepository(new SqlSessionTemplate(factory.getObject()).getMapper(ProcurementDirectionMapper.class));
|
||||
assertThat(repository.hasStarted(1)).isFalse();
|
||||
jdbc.update("INSERT INTO ll_procurement_flow(order_id) VALUES(1)");
|
||||
assertThat(repository.hasStarted(1)).isFalse();
|
||||
jdbc.update("UPDATE ll_procurement_flow SET purchased_at=CURRENT_TIMESTAMP WHERE order_id=1");
|
||||
assertThat(repository.hasStarted(1)).isTrue();
|
||||
assertThat(repository.hasStarted(2)).isFalse();
|
||||
jdbc.update("UPDATE ll_procurement_flow SET purchased_at=NULL,actual_warehouse_id=91 WHERE order_id=1");
|
||||
assertThat(repository.hasStarted(1)).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user