Commit cdedc2ab by fanfr
1 parent 01ccd142
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
<packaging>war</packaging> <packaging>war</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>cn.com.glsx.dj.beis</groupId>
<artifactId>rpc-dj-beisen-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.com.glsx.merchants</groupId> <groupId>cn.com.glsx.merchants</groupId>
<artifactId>platform-merchants-api</artifactId> <artifactId>platform-merchants-api</artifactId>
<version>4.50.0-SNAPSHOT</version> <version>4.50.0-SNAPSHOT</version>
......
package cn.com.glsx.merchants.annotation.beisen;
import cn.com.glsx.merchants.enums.beisen.AccountEventEnum;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface BeiSenNotice {
AccountEventEnum type();
String description() default "";
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.merchants.aop.beisen;
import cn.com.glsx.dj.beisen.remote.BeiSenStaffRemote;
import cn.com.glsx.merchants.annotation.beisen.BeiSenNotice;
import cn.com.glsx.merchants.model.request.MerchantStaffRequest;
import cn.com.glsx.merchants.request.beisen.BeiSenStaffRequest;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.commons.lang3.ArrayUtils;
import org.aspectj.lang.reflect.MethodSignature;
import java.util.HashMap;
import java.util.Map;
@Slf4j
//@Aspect
//@Component
public class AccountEventAspect {
@Autowired
private BeiSenStaffRemote beiSenStaffRemote;
// @Pointcut("execution(* com.example.account.service.AccountService.updateEmployee(..))")
public void updateEmployeePointcut() {
}
// @Before("execution(* *(..)) && @annotation(beiSenNotice)")
// public void beforeHandle(JoinPoint joinPoint, BeiSenNotice beiSenNotice) {
// try {
// log.info("BeiSenNotice before handle ready");
// } catch (Exception e) {
// log.error("BeiSenNotice before handle error:{}", e.getMessage(), e);
// }
// }
//
// @AfterReturning(pointcut = "execution(* *(..)) && @annotation(beiSenNotice)", returning = "result")
// public void afterUpdateEmployee(JoinPoint joinPoint, Object result, BeiSenNotice beiSenNotice) {
// }
//
// @Around("execution(* *(..)) && @annotation(beiSenNotice)")
// public Object aroundHandle(ProceedingJoinPoint joinPoint, BeiSenNotice beiSenNotice) throws Throwable {
// long startTime = System.currentTimeMillis();
// log.info("BeiSenNotice around handle ready");
// Object result = joinPoint.proceed();
// try {
// log.info("proceed result:{},BeiSenNotice around handle start",result);
// beiSenNotice.type().getHandlerClass().newInstance().handle(new BeiSenStaffRequest());
// log.info("BeiSenNotice around handle end");
// } catch (Exception e) {
// log.error("BeiSenNotice around handle error:{}", e.getMessage(), e);
// } finally {
// log.info("BeiSenNotice around handle 耗时:{} ms", (System.currentTimeMillis() - startTime));
// }
// return result;
// }
//
// private BeiSenStaffRequest buildBeiSenStaffRequest(JoinPoint joinPoint) {
// BeiSenStaffRequest request = new BeiSenStaffRequest();
// Map<String, Object> argsMap = getArgsMap(joinPoint);
// request.setStaffName((String) argsMap.get("staffName"));
// request.setStaffJob((String) argsMap.get("staffJob"));
// request.setStaffPhone((String) argsMap.get("staffPhone"));
// request.setDelFlag((Byte) argsMap.get("delFlag"));
// request.setDelFlag((Byte) argsMap.get("delFlag"));
// request.setMerchantId((Integer) argsMap.get("merchantId"));
// request.setMerchantNo((Integer) argsMap.get("merchantNo"));
// request.setStatus((Integer) argsMap.get("status"));
// request.setStaffUuid((String) argsMap.get("staffUuid"));
// return request;
// }
//
// private Map<String, Object> getArgsMap(JoinPoint joinPoint) {
// Object[] args = joinPoint.getArgs();
// Signature signature = joinPoint.getSignature();
// MethodSignature methodSignature = (MethodSignature) signature;
// String[] parameterNames = methodSignature.getParameterNames();
// Map<String, Object> argsMap = new HashMap<>();
// for (int i = 0; i < parameterNames.length; i++) {
// argsMap.put(parameterNames[i], args[i]);
// }
// return argsMap;
// }
//
// @AfterThrowing(pointcut = "@annotation(cn.com.glsx.merchants.annotation.beisen.BeiSenNotice)", throwing = "ex")
// public void afterDeleteAccountError(JoinPoint joinPoint, Exception ex) {
// Object[] args = joinPoint.getArgs();
// String accountId = (String) args[0];
// System.err.println(ex.getMessage());
// }
//
// @After("@annotation(cn.com.glsx.merchants.annotation.beisen.BeiSenNotice)")
// public void afterDeleteAccount(JoinPoint joinPoint) {
// Object[] args = joinPoint.getArgs();
// String accountId = (String) args[0];
// System.out.println(accountId);
// }
}
package cn.com.glsx.merchants.aop.beisen;
import cn.com.glsx.merchants.annotation.beisen.BeiSenNotice;
import cn.com.glsx.merchants.enums.beisen.AccountEventEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
public class BeisenHandlerFactory {
@Autowired
private ApplicationContext applicationContext;
private final Map<AccountEventEnum, BetSenNoticeHandler> handlerMap = new HashMap<>();
@PostConstruct
public void init() {
Map<String, BetSenNoticeHandler> beans = applicationContext.getBeansOfType(BetSenNoticeHandler.class);
for (BetSenNoticeHandler handler : beans.values()) {
BeiSenNotice annotation = handler.getClass().getAnnotation(BeiSenNotice.class);
if (annotation != null) {
handlerMap.put(annotation.type(), handler);
}
}
}
public BetSenNoticeHandler getHandler(AccountEventEnum type) {
BetSenNoticeHandler handler = handlerMap.get(type);
if (handler == null) {
throw new IllegalArgumentException("No handler found for operation type: " + type);
}
return handler;
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.merchants.aop.beisen;
import cn.com.glsx.merchants.request.beisen.BeiSenStaffRequest;
public interface BetSenNoticeHandler {
void handle(BeiSenStaffRequest request);
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.merchants.aop.beisen;
import cn.com.glsx.dj.beisen.dto.BeiSenBaseResponseDTO;
import cn.com.glsx.dj.beisen.dto.org.response.GetByTimeWindowResponseDTO;
import cn.com.glsx.dj.beisen.dto.staff.request.BatchDataRequestDTO;
import cn.com.glsx.dj.beisen.dto.staff.request.ColumnValue;
import cn.com.glsx.dj.beisen.dto.staff.request.DataSetItem;
import cn.com.glsx.dj.beisen.remote.BeiSenStaffRemote;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.merchants.request.beisen.BeiSenStaffRequest;
import cn.com.glsx.merchants.service.BeiSenService;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.UuidUtils;
import com.esotericsoftware.minlog.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class CreateStaffHandler implements BetSenNoticeHandler {
@Autowired
private BeiSenStaffRemote beiSenStaffRemote;
@Autowired
private BeiSenService beiSenService;
@Override
public void handle(BeiSenStaffRequest request) {
List<GetByTimeWindowResponseDTO.OrganizationData> beiSenStaffData = beiSenService.scrollQueryWindow(request.getStaffPhone());
if (CollectionUtils.isEmpty(beiSenStaffData)) {
log.info("北森系统不存在该手机号员工 phone:{}", request.getStaffPhone());
}
BatchDataRequestDTO beisenRequest = new BatchDataRequestDTO();
beisenRequest.setMetaObjectName("TenantBase.extryfl");
List<DataSetItem> dataSetItems = new ArrayList<>();
DataSetItem dataSetItem = new DataSetItem();
dataSetItem.setId("c76164900b104472ba47b084b0d3e0e8");
Map<String, ColumnValue> columns = new HashMap<>();
ColumnValue columnValue = new ColumnValue();
columnValue.setValueType(0);
columnValue.setValue("测试园区店1111");
columns.put("extrenyuanfenlei", columnValue);
dataSetItem.setColumns(columns);
dataSetItems.add(dataSetItem);
beisenRequest.setDataSet(dataSetItems);
// RpcResponse<BeiSenBaseResponseDTO> response = beiSenStaffRemote.batchAddTag(beisenRequest);
// log.info("CreateStaffHandler.handle response:{}", JSONObject.toJSONString(response));
beiSenService.sout();
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.merchants.aop.beisen;
import cn.com.glsx.merchants.request.beisen.BeiSenStaffRequest;
import org.springframework.stereotype.Component;
@Component
public class DeleteStaffHandler implements BetSenNoticeHandler {
@Override
public void handle(BeiSenStaffRequest request) {
System.out.println("DELETE" + request);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.merchants.aop.beisen;
import cn.com.glsx.merchants.request.beisen.BeiSenStaffRequest;
import org.springframework.stereotype.Component;
@Component
public class UpdateStaffHandler implements BetSenNoticeHandler {
@Override
public void handle(BeiSenStaffRequest request) {
System.out.println("UPDATE " + request);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.merchants.config; package cn.com.glsx.merchants.config;
import cn.com.glsx.dj.beisen.remote.BeiSenOrgRemote;
import cn.com.glsx.dj.beisen.remote.BeiSenStaffRemote;
import cn.com.glsx.merchants.remote.*; import cn.com.glsx.merchants.remote.*;
import cn.com.glsx.stoassistant.remote.MerchantStaffScoreRemote; import cn.com.glsx.stoassistant.remote.MerchantStaffScoreRemote;
import cn.com.glsx.stoassistant.remote.MerchantStaffWithdrawalRemote; import cn.com.glsx.stoassistant.remote.MerchantStaffWithdrawalRemote;
...@@ -22,6 +24,16 @@ public class DubboConfig { ...@@ -22,6 +24,16 @@ public class DubboConfig {
private ReferenceBuilderFactory factory; private ReferenceBuilderFactory factory;
@Bean @Bean
public BeiSenOrgRemote getBeiSenOrgRemote() {
return factory.builder(BeiSenOrgRemote.class).check(false).timeout(30000).version("1.0.0").build();
}
@Bean
public BeiSenStaffRemote getBeiSenStaffRemote() {
return factory.builder(BeiSenStaffRemote.class).check(false).timeout(30000).version("1.0.0").build();
}
@Bean
public MerchantProductRemote getMerchantProductRemote() { public MerchantProductRemote getMerchantProductRemote() {
return factory.builder(MerchantProductRemote.class).check(false).timeout(30000).version("2.0.0").build(); return factory.builder(MerchantProductRemote.class).check(false).timeout(30000).version("2.0.0").build();
} }
......
package cn.com.glsx.merchants.config;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext context) {
applicationContext = context;
}
public static <T> T getBean(Class<T> beanClass) {
return applicationContext.getBean(beanClass);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.merchants.enums.beisen;
import cn.com.glsx.merchants.aop.beisen.*;
import cn.com.glsx.merchants.config.SpringContextHolder;
import lombok.Getter;
@Getter
public enum AccountEventEnum {
CREATE_ACCOUNT((int)1,"创建账户", CreateStaffHandler.class),
UPDATE_ACCOUNT((int)2,"更新账户", UpdateStaffHandler.class),
DELETE_ACCOUNT((int)3,"删除账户", DeleteStaffHandler.class),
UPDATE_ACCOUNT_STATUS((int)4,"更新账户状态", CreateStaffHandler.class),
UPDATE_ACCOUNT_YQ_MERCHANT((int)5,"变更园区店", CreateStaffHandler.class),
UPDATE_ACCOUNT_PHONE((int)6,"变更手机号", CreateStaffHandler.class),
;
private final int value;
private final String displayName;
private final Class<? extends BetSenNoticeHandler> handlerClass;
AccountEventEnum(Integer value, String displayName, Class<? extends BetSenNoticeHandler> handlerClass) {
this.value = value;
this.displayName = displayName;
this.handlerClass = handlerClass;
}
public static AccountEventEnum getByValue(Integer value){
if (value != null) {
for (AccountEventEnum temp: AccountEventEnum.values()) {
if (temp.getValue() == value.byteValue()) {
return temp;
}
}
}
return null;
}
public BetSenNoticeHandler getHandler() {
return SpringContextHolder.getBean(handlerClass);
}
}
package cn.com.glsx.merchants.request.beisen;
import lombok.Data;
import java.io.Serializable;
@Data
public class BeiSenStaffRequest implements Serializable {
/**
* 员工姓名
*/
private String staffName;
/**
* 职务
*/
private String staffJob;
/**
* 手机号
*/
private String staffPhone;
/**
* 是否删除:0=正常,-1=删除
*/
private Byte delFlag;
/**
* 商户id
*/
private Integer merchantId;
/**
* 商户号
*/
private Integer merchantNo;
/**
* 员工状态
*/
private Integer status;
private String staffUuid;
}
package cn.com.glsx.merchants.service;
import cn.com.glsx.dj.beisen.dto.org.request.GetByTimeWindowRequestDTO;
import cn.com.glsx.dj.beisen.dto.org.response.GetByTimeWindowResponseDTO;
import cn.com.glsx.dj.beisen.remote.BeiSenOrgRemote;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @Description
* @author chizw
* @create 2025/5/14 21:06
* @version ver.1.0.0
*/
@Slf4j
@Service
public class BeiSenService {
@Autowired
private BeiSenOrgRemote beiSenOrgRemote;
public void sout(){
log.info("get success");
}
public List<GetByTimeWindowResponseDTO.OrganizationData> scrollQueryWindow(String phone) {
List<GetByTimeWindowResponseDTO.OrganizationData> allData = new ArrayList<>();
boolean isOver = false;
int totalCount = 0;
GetByTimeWindowRequestDTO request = new GetByTimeWindowRequestDTO();
request.setStartTime(LocalDate.now().minusMonths(3).atStartOfDay().toString());
request.setStopTime(LocalDate.now().atStartOfDay().toString());
request.setCapacity(300);
do {
RpcResponse<GetByTimeWindowResponseDTO> response = beiSenOrgRemote.getByTimeWindow(request);
if (response == null || response.isFailed()) {
log.error("请求失败");
break;
}
GetByTimeWindowResponseDTO result = response.getResult();
if (result == null || !Objects.equals(200,result.getCode())) {
log.warn("北森API调用失败,request:{},response:{}", request, response);
break;
}
List<GetByTimeWindowResponseDTO.OrganizationData> data = result.getData();
if (CollectionUtils.isEmpty(data)) {
isOver = true;
}
if (StringUtils.isNotEmpty(phone)) {
List<GetByTimeWindowResponseDTO.OrganizationData> phoneData = data.stream()
.filter(s -> Objects.equals(s.getPhone(), phone)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(phoneData)) return phoneData;
}
request.setScrollId(result.getScrollId());
allData.addAll(data);
if (totalCount == 0) {
totalCount = totalCount + result.getTotal();
}
} while (!isOver);
return allData;
}
}
...@@ -3,9 +3,11 @@ package cn.com.glsx.merchants.service; ...@@ -3,9 +3,11 @@ package cn.com.glsx.merchants.service;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.annotation.beisen.BeiSenNotice;
import cn.com.glsx.merchants.config.SystemProperty; import cn.com.glsx.merchants.config.SystemProperty;
import cn.com.glsx.merchants.convert.ConvertRequest; import cn.com.glsx.merchants.convert.ConvertRequest;
import cn.com.glsx.merchants.convert.ConvertResponse; import cn.com.glsx.merchants.convert.ConvertResponse;
import cn.com.glsx.merchants.enums.beisen.AccountEventEnum;
import cn.com.glsx.merchants.model.request.StaffBatchRequest; import cn.com.glsx.merchants.model.request.StaffBatchRequest;
import cn.com.glsx.merchants.model.request.MerchantFileRequest; import cn.com.glsx.merchants.model.request.MerchantFileRequest;
import cn.com.glsx.merchants.model.request.MerchantStaffRequest; import cn.com.glsx.merchants.model.request.MerchantStaffRequest;
...@@ -29,6 +31,7 @@ import org.apache.commons.collections4.CollectionUtils; ...@@ -29,6 +31,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
......
...@@ -3,13 +3,20 @@ package cn.com.glsx.merchants.controller;/** ...@@ -3,13 +3,20 @@ package cn.com.glsx.merchants.controller;/**
* @date 2021/7/28 * @date 2021/7/28
*/ */
import cn.com.glsx.merchants.aop.beisen.CreateStaffHandler;
import cn.com.glsx.merchants.enums.StaffDepartmentEnum; import cn.com.glsx.merchants.enums.StaffDepartmentEnum;
import cn.com.glsx.merchants.request.beisen.BeiSenStaffRequest;
import cn.com.glsx.merchants.request.staff.StaffSaveRequest;
import cn.com.glsx.merchants.service.StaffService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.rop.impl.SimpleRopRequestContext;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import javax.xml.crypto.Data; import javax.xml.crypto.Data;
import java.util.Arrays;
/** /**
* @author zhouhaibao * @author zhouhaibao
...@@ -19,6 +26,12 @@ import javax.xml.crypto.Data; ...@@ -19,6 +26,12 @@ import javax.xml.crypto.Data;
*/ */
public class StaffControllerTest extends BaseControllerTest { public class StaffControllerTest extends BaseControllerTest {
@Autowired
private StaffService staffService;
@Autowired
private CreateStaffHandler createStaffHandler;
@Test @Test
public void Test01() throws Exception{ public void Test01() throws Exception{
System.out.println(StaffDepartmentEnum.getDepartmentName(2)); System.out.println(StaffDepartmentEnum.getDepartmentName(2));
...@@ -74,4 +87,28 @@ public class StaffControllerTest extends BaseControllerTest { ...@@ -74,4 +87,28 @@ public class StaffControllerTest extends BaseControllerTest {
params.add("pageNum","1"); params.add("pageNum","1");
System.out.println(post(params)); System.out.println(post(params));
} }
@Test
public void saveStaffTest(){
StaffSaveRequest request = new StaffSaveRequest();
request.setSource("glsx");
request.setMerchantId(58);
request.setStaffName("5858");
request.setStaffPhone("13642424232");
request.setPassword("123aaa");
request.setRoleIds(Arrays.asList(1221));
request.setVisibleInferiorMer("58,59");
request.setMesVerifyFlag(0);
request.setCreatedSource(1);
// SimpleRopRequestContext ropRequestContext = new SimpleRopRequestContext();
// request.setRopRequestContext(ropRequestContext);
staffService.saveStaff(request);
}
@Test
public void createStaffHandlerTest(){
BeiSenStaffRequest request = new BeiSenStaffRequest();
request.setStaffUuid("111");
createStaffHandler.handle(request);
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!