first commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
## 基础层
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.mhd.user.infrastructure.dict;
|
||||
|
||||
/**
|
||||
* @Description 认证审核状态:0-无状态,1-已注册未认证,2-已认证待审核,3-审核通过,4-已驳回
|
||||
* @Author Alex
|
||||
* @Date 2023/1/10 17:38
|
||||
*/
|
||||
public enum AuthStatusEnum {
|
||||
|
||||
ONE("未认证", 1),
|
||||
TWO("正在审核", 2),
|
||||
THREE("认证成功", 3),
|
||||
FOUR("认证失败", 4),
|
||||
FIVE("认证失效", 5);
|
||||
|
||||
private String name;
|
||||
private Integer code;
|
||||
|
||||
private AuthStatusEnum(String name, Integer code) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static String getName(Integer code) {
|
||||
for (AuthStatusEnum roleEnum : AuthStatusEnum.values()) {
|
||||
if (code.equals(roleEnum.getCode())) {
|
||||
return roleEnum.getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getCode(String name) {
|
||||
for (AuthStatusEnum roleEnum : AuthStatusEnum.values()) {
|
||||
if (name.equals(roleEnum.getName())) {
|
||||
return roleEnum.getCode();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.mhd.user.infrastructure.dict;
|
||||
|
||||
/**
|
||||
* @Description 认证提交状态:0-无状态,1-未认证,2-正在审核,3-认证通过,4-认证失败,5-认证失效
|
||||
* @Author Alex
|
||||
* @Date 2023/1/10 17:39
|
||||
*/
|
||||
public enum FillStatusEnum {
|
||||
|
||||
ONE("未认证", 1),
|
||||
TWO("正在审核", 2),
|
||||
THREE("认证通过", 3),
|
||||
FOUR("认证失败", 4),
|
||||
FIVE("认证失效", 5);
|
||||
|
||||
private String name;
|
||||
private Integer code;
|
||||
|
||||
private FillStatusEnum(String name, Integer code) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static String getName(Integer code) {
|
||||
for (FillStatusEnum roleEnum : FillStatusEnum.values()) {
|
||||
if (code.equals(roleEnum.getCode())) {
|
||||
return roleEnum.getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getCode(String name) {
|
||||
for (FillStatusEnum roleEnum : FillStatusEnum.values()) {
|
||||
if (name.equals(roleEnum.getName())) {
|
||||
return roleEnum.getCode();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.mhd.user.infrastructure.dict;
|
||||
|
||||
/**
|
||||
* @Description 认证提交状态:0-无状态,1-未认证,2-已认证完成
|
||||
* @Author Alex
|
||||
* @Date 2023/1/10 17:39
|
||||
*/
|
||||
public enum VehicleFillStatusEnum {
|
||||
|
||||
ONE("未认证", 1),
|
||||
TWO("已认证", 2);
|
||||
|
||||
private String name;
|
||||
private Integer code;
|
||||
|
||||
private VehicleFillStatusEnum(String name, Integer code) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static String getName(Integer code) {
|
||||
for (VehicleFillStatusEnum roleEnum : VehicleFillStatusEnum.values()) {
|
||||
if (code.equals(roleEnum.getCode())) {
|
||||
return roleEnum.getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getCode(String name) {
|
||||
for (VehicleFillStatusEnum roleEnum : VehicleFillStatusEnum.values()) {
|
||||
if (name.equals(roleEnum.getName())) {
|
||||
return roleEnum.getCode();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mhd.user.infrastructure.dto;
|
||||
|
||||
import com.mhd.common.core.web.domain.BaseVOEntity;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CheckDO extends BaseVOEntity {
|
||||
|
||||
@ApiModelProperty(name = "手机号码")
|
||||
private String userPhone;
|
||||
@ApiModelProperty(name = "用户姓名(真实姓名)")
|
||||
private String userName;
|
||||
@ApiModelProperty(name = "登录账号(2-20位)")
|
||||
private String userAccount;
|
||||
@ApiModelProperty(name = "登录密码")
|
||||
private String userPassword;
|
||||
@ApiModelProperty(name = "支付密码")
|
||||
private String userPayPassword;
|
||||
@ApiModelProperty(name = "身份证号")
|
||||
private String userIdcardNumber;
|
||||
@ApiModelProperty(name = "邮箱")
|
||||
private String userEmail;
|
||||
|
||||
@ApiModelProperty(value = "数据来源(1-数字物流 2-TMS)")
|
||||
private Integer dataSources;
|
||||
|
||||
}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
package com.mhd.user.infrastructure.feign;
|
||||
|
||||
import com.mhd.common.core.domain.dto.OrganizationDto;
|
||||
import com.mhd.common.core.domain.dto.ProjectUserDTO;
|
||||
import com.mhd.common.core.domain.dto.RoleMenuDTO;
|
||||
import com.mhd.common.core.domain.dto.SysTenantsDTO;
|
||||
import com.mhd.common.core.domain.entity.R;
|
||||
import com.mhd.common.core.domain.po.MenuPo;
|
||||
import com.mhd.common.core.domain.po.OrganizationPo;
|
||||
import com.mhd.common.core.domain.po.SysTenantsPo;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.system.api.feign.FeignAutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 调用产品中台-组织模块
|
||||
* @Author Alex
|
||||
* @Date 2022/12/2 13:38
|
||||
*/
|
||||
@FeignClient(value = "mhd-product-service",configuration = FeignAutoConfiguration.class)
|
||||
public interface ProductServiceFeign {
|
||||
|
||||
/**
|
||||
* @Description 获取一级组织
|
||||
* @Author Alex
|
||||
* @Date 2022/12/2 13:37
|
||||
*/
|
||||
@GetMapping("/organization/selectTopId/{id}")
|
||||
public AjaxResult getTopOrganization(@PathVariable("id") Long id);
|
||||
|
||||
@GetMapping("/organization/getInfo/{id}")
|
||||
public AjaxResult getOrganizationInfo(@PathVariable("id") Long id);
|
||||
|
||||
@GetMapping("/organization/selectTopIdByTenantsDomainName/{tenantsDomainName}")
|
||||
public AjaxResult selectTopIdByTenantsDomainName(@PathVariable("tenantsDomainName") String tenantsDomainName);
|
||||
|
||||
/**
|
||||
* 查询全部菜单树形结构(管理员)
|
||||
*/
|
||||
@GetMapping(value = "/menu/selectMenuIdListPo")
|
||||
public AjaxResult selectMenuIdListPo();
|
||||
|
||||
/**
|
||||
* 查询菜单树形结构(当前登录人)
|
||||
*/
|
||||
@GetMapping(value = "/menu/getCurrentMenuIds")
|
||||
public AjaxResult getCurrentMenuIds();
|
||||
|
||||
@GetMapping("/organization/getOrganizationIdsByOrganizationId/{organizationId}")
|
||||
public AjaxResult getOrganizationIdsByOrganizationId(@PathVariable("organizationId") Long organizationId);
|
||||
|
||||
@PostMapping("/organization/getOrganizationIdsByOrganizationIds")
|
||||
public AjaxResult getOrganizationIdsByOrganizationIds(@RequestBody List<Long> organizationIds);
|
||||
|
||||
/**
|
||||
* 修改组织
|
||||
*/
|
||||
@PutMapping("/organization/update")
|
||||
public AjaxResult organizationUpdate(@RequestBody OrganizationDto organizationDto);
|
||||
|
||||
/**
|
||||
* 根据applicationName查询定时任务集合
|
||||
*/
|
||||
@GetMapping(value = "/elasticJob/elasticJobList/{applicationName}")
|
||||
public AjaxResult elasticJobList(@PathVariable("applicationName") String applicationName);
|
||||
|
||||
/**
|
||||
* 根据id查询组织信息
|
||||
*/
|
||||
@GetMapping(value = "/organization/getInfo/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id);
|
||||
|
||||
/**
|
||||
* 修改组织负责人信息
|
||||
* @param organizationDto
|
||||
*/
|
||||
@PostMapping("/organization/updatePrincipal")
|
||||
public AjaxResult updatePrincipal(OrganizationDto organizationDto);
|
||||
/**
|
||||
* 修改租户一级账号信息
|
||||
* @param sysTenantsDTO
|
||||
*/
|
||||
@PostMapping("/tenants/updateUserAccount")
|
||||
public AjaxResult updateUserAccount(SysTenantsDTO sysTenantsDTO);
|
||||
|
||||
@GetMapping("/organization/selectTopIdByTenantsDomainName/{tenantsDomainName}")
|
||||
public AjaxResult getOrganizationByPath(@PathVariable("tenantsDomainName") String tenantsDomainName);
|
||||
|
||||
/**
|
||||
* 根据角色编码配置组织菜单权限
|
||||
* @param organizationDto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/organization/editOrganizationMenu")
|
||||
R<List<Long>> editOrganizationMenu(@RequestBody OrganizationDto organizationDto);
|
||||
|
||||
/**
|
||||
* 根据来源id和组织id获取所有的菜单
|
||||
* @param roleMenuDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/menu/getMenuBySourceId")
|
||||
R<List<MenuPo>> getMenuBySourceId(@RequestBody RoleMenuDTO roleMenuDTO);
|
||||
|
||||
/**
|
||||
* 根据组织id查询租户信息
|
||||
* @param organizationId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/tenants/getTenantsByOrgan")
|
||||
public R<SysTenantsPo> getTenantsByOrgan(@RequestParam("organizationId") Long organizationId);
|
||||
|
||||
/**
|
||||
* @Description 根据id查询组织信息(包含所有的子组织id)
|
||||
* @Author Alex
|
||||
* @Date 2022/12/6 22:11
|
||||
*/
|
||||
@GetMapping("/organization/getInfoForIdList/{id}")
|
||||
R<OrganizationPo> getInfoForIdList(@PathVariable("id") Long id);
|
||||
|
||||
/**
|
||||
* 开放接口-获取配置的组织信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/tenants/getTenantsInfoByOpen")
|
||||
public R<SysTenantsPo> getTenantsInfoByOpen();
|
||||
|
||||
/**
|
||||
* 绑定子账户/解绑子账户
|
||||
*/
|
||||
@PostMapping("/projectManagementApi/bindAccount")
|
||||
public AjaxResult bindAccount(@RequestBody ProjectUserDTO projectUserDTO);
|
||||
|
||||
/**
|
||||
* 关联项目
|
||||
*/
|
||||
@PostMapping("/projectManagementApi/bindAccountBatch")
|
||||
public AjaxResult bindAccountBatch(@RequestBody List<ProjectUserDTO> projectUserDTOS);
|
||||
|
||||
/**
|
||||
* oss上传文件
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/menu/uploadFeign",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public AjaxResult uploadFeign(@RequestPart("file") MultipartFile file);
|
||||
|
||||
/**
|
||||
* 产品列表(根据菜单id查询)
|
||||
* @param menuIdList
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/product/getProductIdList")
|
||||
public R<List<Long>> getProductIdList(@RequestBody List<Long> menuIdList);
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.mhd.user.infrastructure.feign;
|
||||
|
||||
import com.mhd.common.core.domain.entity.R;
|
||||
import com.mhd.common.core.domain.po.DispatchPo;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient("mhd-special-logistics-service")
|
||||
public interface SpecialLogisticsFeign {
|
||||
@PostMapping("/dispatchApi/getAllList")
|
||||
R<List<DispatchPo>> getAllList(@RequestBody List<Long> driverIdList);
|
||||
|
||||
@GetMapping("/dispatchApi/getDispatchNum")
|
||||
AjaxResult getDispatchNum();
|
||||
|
||||
@GetMapping("/OrderApiPc/getOrderNum/{userId}")
|
||||
AjaxResult getOrderNum(@PathVariable("userId") Long userId);
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.mhd.user.infrastructure.feign;
|
||||
|
||||
import com.mhd.common.core.domain.dto.NoticeMessageLoggingDto;
|
||||
import com.mhd.common.core.domain.dto.SysProvinceCityCountyDTO;
|
||||
import com.mhd.common.core.domain.dto.UserFormConfigDto;
|
||||
import com.mhd.common.core.domain.dto.WebSocketDTO;
|
||||
import com.mhd.common.core.domain.dto.open.SystemOpenApiLogDTO;
|
||||
import com.mhd.common.core.domain.dto.open.ThirdPartyServiceReqLogDTO;
|
||||
import com.mhd.common.core.domain.entity.R;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.system.api.domain.SysDictData;
|
||||
import com.mhd.system.api.feign.FeignAutoConfiguration;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(value = "mhd-system", configuration = FeignAutoConfiguration.class)
|
||||
public interface SystemServiceFeign {
|
||||
|
||||
|
||||
@GetMapping("/dict/data/{dictCode}")
|
||||
public AjaxResult getTopOrganization(@PathVariable("dictCode") Long dictCode);
|
||||
|
||||
@PostMapping("/dict/data/findDatalist")
|
||||
public AjaxResult findDatalist(@RequestBody SysDictData sysDictData);
|
||||
|
||||
@GetMapping("/dict/data/type/{dictType}")
|
||||
public AjaxResult selectListByDictType(@PathVariable("dictType") String dictType);
|
||||
|
||||
@PostMapping("/basicApi/findAreaInfo")
|
||||
public AjaxResult findAreaInfo(@RequestBody SysProvinceCityCountyDTO sysProvinceCityCountyDTO);
|
||||
|
||||
@PostMapping("/basicApi/findAreaInfoByProvince")
|
||||
public AjaxResult findAreaInfoByProvince(@RequestBody SysProvinceCityCountyDTO sysProvinceCityCountyDTO);
|
||||
|
||||
/**
|
||||
* 获取用户所在组织的开关配置信息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/userConfigSwitchApi/getUserConfigSwitchInfo")
|
||||
public AjaxResult getUserConfigSwitchInfo();
|
||||
|
||||
/**
|
||||
* 群发消息
|
||||
*/
|
||||
@PostMapping("/webSocketApi/bulkSend")
|
||||
public AjaxResult bulkSend(@RequestBody WebSocketDTO webSocketDTO);
|
||||
|
||||
/**
|
||||
* 单个消息
|
||||
*/
|
||||
@PostMapping("/webSocketApi/oneSend")
|
||||
public AjaxResult oneSend(@RequestBody WebSocketDTO webSocketDTO);
|
||||
|
||||
/**
|
||||
* PC获取租户自定义单配置
|
||||
*/
|
||||
@ApiOperation("PC获取租户自定义单配置")
|
||||
@PostMapping(value = "/userFormConfigApi/getPcUserFromConfigByFeign")
|
||||
public AjaxResult getPcUserFromConfigByFeign(@RequestBody UserFormConfigDto userFormConfigDto);
|
||||
|
||||
@PostMapping("/messageManageApi/addMessageLogging")
|
||||
public AjaxResult addMessageLogging(@RequestBody NoticeMessageLoggingDto noticeMessageLoggingDto);
|
||||
|
||||
/**
|
||||
* 根据条件查询分类字典数据列表
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/dict/data/getDictDataList")
|
||||
public R<List<SysDictData>> getDictDataList(@RequestBody SysDictData sysDictData);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.mhd.user.infrastructure.feign.vo;
|
||||
|
||||
import com.mhd.common.core.annotation.Excel;
|
||||
import com.mhd.common.core.annotation.Excel.ColumnType;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 字典数据表 sys_dict_data
|
||||
*
|
||||
* @author mhd
|
||||
*/
|
||||
@Data
|
||||
public class SysDictDataVo
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 字典编码 */
|
||||
@Excel(name = "字典编码", cellType = ColumnType.NUMERIC)
|
||||
private Long dictCode;
|
||||
|
||||
/** 字典排序 */
|
||||
@Excel(name = "字典排序", cellType = ColumnType.NUMERIC)
|
||||
private Long dictSort;
|
||||
|
||||
/** 字典标签 */
|
||||
@Excel(name = "字典标签")
|
||||
private String dictLabel;
|
||||
|
||||
/** 字典键值 */
|
||||
@Excel(name = "字典键值")
|
||||
private String dictValue;
|
||||
|
||||
/** 字典类型 */
|
||||
@Excel(name = "字典类型")
|
||||
private String dictType;
|
||||
|
||||
/** 样式属性(其他样式扩展) */
|
||||
private String cssClass;
|
||||
|
||||
/** 表格字典样式 */
|
||||
private String listClass;
|
||||
|
||||
/** 是否默认(Y是 N否) */
|
||||
@Excel(name = "是否默认", readConverterExp = "Y=是,N=否")
|
||||
private String isDefault;
|
||||
|
||||
/** 状态(0正常 1停用) */
|
||||
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
|
||||
/** 组织表ID */
|
||||
private Long organizationId;
|
||||
|
||||
/** 组织名称 */
|
||||
private String organizationName;
|
||||
|
||||
/** 一级组织表ID */
|
||||
private Long topOrganizationId;
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.mhd.user.infrastructure.mq.publisher;
|
||||
|
||||
import com.mhd.user.domain.userAggregate.event.ShipperEventPublisher;
|
||||
import com.mhd.system.api.event.object.ShipperNameChangedEvent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.stream.function.StreamBridge;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
@RequiredArgsConstructor
|
||||
public class ShipperEventPublisherImpl implements ShipperEventPublisher {
|
||||
|
||||
private static final String SHIPPER_NAME_CHANGED_BINDING = "shipperNameChanged-out-0";
|
||||
|
||||
private final StreamBridge streamBridge;
|
||||
|
||||
@Override
|
||||
public void publish(ShipperNameChangedEvent event) {
|
||||
log.info("准备发布货主名称变更事件: {}", event);
|
||||
try {
|
||||
boolean isSent = streamBridge.send(SHIPPER_NAME_CHANGED_BINDING, MessageBuilder.withPayload(event).build());
|
||||
if (isSent) {
|
||||
log.info("事件发布成功: userId = {}", event.getUserId());
|
||||
} else {
|
||||
log.warn("事件发送失败");
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.warn("事件发送异常,: msg:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.mhd.user.infrastructure.util;
|
||||
|
||||
import com.mhd.common.core.utils.StringUtils;
|
||||
|
||||
public class DesensitizedUtil {
|
||||
/**
|
||||
* 姓名脱敏
|
||||
* 规则:
|
||||
* 1、两位姓名,如:王京 置换为 王*
|
||||
* 2、大于两位,如:王京京 置换为 王*京
|
||||
* 王京京京 置换为 王*京
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static String desensitizedName(String name){
|
||||
if(StringUtils.isNotEmpty(name)){
|
||||
if(name.length() == 2){
|
||||
name = name.replaceAll("(.).+", "$1*");
|
||||
}
|
||||
if(name.length() > 2){
|
||||
name = name.replaceAll("(.).+(.)", "$1*$2");
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号脱敏
|
||||
* 规则:保留前三后四,如:18812349876 置换为 188****9876
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
public static String desensitizedPhone(String phone){
|
||||
if(StringUtils.isNotEmpty(phone)){
|
||||
phone = phone.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2");
|
||||
}
|
||||
return phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份证脱敏(支持18位和15位)
|
||||
* 规则:保留前六后三,如:123456789987654321 置换为 123456*********321
|
||||
* @param idCard
|
||||
* @return
|
||||
*/
|
||||
public static String desensitizedIdNumber(String idCard){
|
||||
if (StringUtils.isNotEmpty(idCard)) {
|
||||
if (idCard.length() >= 15){
|
||||
idCard = idCard.replaceAll("(\\w{6})\\w*(\\w{3})", "$1******$2");
|
||||
}else {
|
||||
idCard = idCard.replaceAll("(\\w{2})\\w*(\\w{2})", "$1***$2");
|
||||
}
|
||||
}
|
||||
return idCard;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("==== 姓名脱敏 =====");
|
||||
String name2 = "王京";
|
||||
String name3 = "王京京";
|
||||
String name4 = "王京京京";
|
||||
System.out.printf("\n姓名:%s, 脱敏后:%s", name2, DesensitizedUtil.desensitizedName(name2));
|
||||
System.out.printf("\n姓名:%s, 脱敏后:%s", name3, DesensitizedUtil.desensitizedName(name3));
|
||||
System.out.printf("\n姓名:%s, 脱敏后:%s", name4, DesensitizedUtil.desensitizedName(name4));
|
||||
|
||||
System.out.println("\n==== 手机号脱敏 =====");
|
||||
String phone = "18812349876";
|
||||
System.out.printf("\n手机号:%s, 脱敏后:%s", phone, DesensitizedUtil.desensitizedPhone(phone));
|
||||
|
||||
System.out.println("\n==== 身份证脱敏 =====");
|
||||
String idCard = "123456789987654321";
|
||||
System.out.printf("\n身份证:%s, 脱敏后:%s", idCard, DesensitizedUtil.desensitizedIdNumber(idCard));
|
||||
String idCard2 = "12345678";
|
||||
System.out.printf("\n身份证:%s, 脱敏后:%s", idCard2, DesensitizedUtil.desensitizedIdNumber(idCard2));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
package com.mhd.user.infrastructure.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.XML;
|
||||
import com.mhd.common.core.utils.SpringUtils;
|
||||
import com.mhd.common.core.utils.poi.WpsImg;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.user.infrastructure.feign.ProductServiceFeign;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItem;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||
import org.apache.poi.ss.usermodel.PictureData;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
/**
|
||||
* wps图片工具类
|
||||
*/
|
||||
@Slf4j
|
||||
public class WpsImgUtil {
|
||||
|
||||
/**
|
||||
* 获取wps中的图片
|
||||
* 包括嵌入形式图片和浮动形式图片
|
||||
* <p>
|
||||
* 嵌入形式图片返回方式:
|
||||
* 以map方式返回
|
||||
* 键为行列格式 =DISPIMG("ID",1) 字符串
|
||||
* <p>
|
||||
* 浮动形式图片返回方式:
|
||||
* 以map方式返回
|
||||
* 键为行列格式 x-y 字符串
|
||||
*
|
||||
* @param dispStrList
|
||||
* @param simpleFile
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Map<String, WpsImg> getWpsImgs(List<String> dispStrList, MultipartFile simpleFile) throws IOException {
|
||||
List<WpsImg> wpsImgList = new ArrayList<>();
|
||||
for (String dispStr : dispStrList) {
|
||||
if (Objects.nonNull(dispStr) && dispStr.startsWith("=DISPIMG")) {
|
||||
int start = dispStr.indexOf("\"");
|
||||
int end = dispStr.lastIndexOf("\"");
|
||||
if (start != -1 && end != -1) {
|
||||
String imgId = dispStr.substring(start + 1, end);
|
||||
WpsImg wpsImg = new WpsImg();
|
||||
wpsImg.setType(0);
|
||||
wpsImg.setImgId(imgId);
|
||||
wpsImg.setCellStr(dispStr);
|
||||
wpsImgList.add(wpsImg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZipInputStream zis = new ZipInputStream(simpleFile.getInputStream());
|
||||
try {
|
||||
ZipEntry entry;
|
||||
while ((entry = zis.getNextEntry()) != null) {
|
||||
try {
|
||||
final String fileName = entry.getName();
|
||||
if (Objects.equals(fileName, "xl/cellimages.xml")) {
|
||||
String content = IOUtils.toString(zis, CharsetUtil.UTF_8);
|
||||
JSONObject js = XML.toJSONObject(content);
|
||||
if (Objects.isNull(js)) {
|
||||
continue;
|
||||
}
|
||||
JSONObject cellImages = js.getJSONObject("etc:cellImages");
|
||||
if (Objects.isNull(cellImages)) {
|
||||
continue;
|
||||
}
|
||||
JSONArray cellImage = null;
|
||||
try {
|
||||
cellImage = cellImages.getJSONArray("etc:cellImage");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (Objects.isNull(cellImage)) {
|
||||
JSONObject cellImageObj = null;
|
||||
try {
|
||||
cellImageObj = cellImages.getJSONObject("etc:cellImage");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (Objects.nonNull(cellImageObj)) {
|
||||
cellImage = new JSONArray();
|
||||
cellImage.add(cellImageObj);
|
||||
}
|
||||
}
|
||||
if (Objects.isNull(cellImage)) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < cellImage.size(); i++) {
|
||||
JSONObject imageItem = cellImage.getJSONObject(i);
|
||||
if (Objects.isNull(imageItem)) {
|
||||
continue;
|
||||
}
|
||||
JSONObject pic = imageItem.getJSONObject("xdr:pic");
|
||||
if (Objects.isNull(pic)) {
|
||||
continue;
|
||||
}
|
||||
JSONObject nvPicPr = pic.getJSONObject("xdr:nvPicPr");
|
||||
if (Objects.isNull(nvPicPr)) {
|
||||
continue;
|
||||
}
|
||||
JSONObject cNvPr = nvPicPr.getJSONObject("xdr:cNvPr");
|
||||
if (Objects.isNull(cNvPr)) {
|
||||
continue;
|
||||
}
|
||||
String name = cNvPr.getStr("name");
|
||||
if (StringUtils.isNotEmpty(name)) {
|
||||
List<WpsImg> wpsImgs = wpsImgList.stream().filter(item -> Objects.equals(item.getImgId(), name)).collect(Collectors.toList());
|
||||
if (!wpsImgs.isEmpty()) {
|
||||
JSONObject blipFill = pic.getJSONObject("xdr:blipFill");
|
||||
if (Objects.isNull(blipFill)) {
|
||||
continue;
|
||||
}
|
||||
JSONObject blip = blipFill.getJSONObject("a:blip");
|
||||
if (Objects.isNull(blip)) {
|
||||
continue;
|
||||
}
|
||||
String embed = blip.getStr("r:embed");
|
||||
wpsImgs.forEach(x -> x.setRId(embed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
zis.closeEntry();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
zis.close();
|
||||
}
|
||||
ZipInputStream fzis = new ZipInputStream(simpleFile.getInputStream());
|
||||
try {
|
||||
ZipEntry entry;
|
||||
while ((entry = fzis.getNextEntry()) != null) {
|
||||
try {
|
||||
final String fileName = entry.getName();
|
||||
if (Objects.equals(fileName, "xl/_rels/cellimages.xml.rels")) {
|
||||
String content = IOUtils.toString(fzis, CharsetUtil.UTF_8);
|
||||
JSONObject js = XML.toJSONObject(content);
|
||||
JSONObject relationships = js.getJSONObject("Relationships");
|
||||
if (Objects.isNull(relationships)) {
|
||||
continue;
|
||||
}
|
||||
JSONArray relationship = null;
|
||||
try {
|
||||
relationship = relationships.getJSONArray("Relationship");
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
if (Objects.isNull(relationship)) {
|
||||
try {
|
||||
JSONObject relationshipObj = relationships.getJSONObject("Relationship");
|
||||
if (Objects.nonNull(relationshipObj)) {
|
||||
relationship = new JSONArray();
|
||||
relationship.add(relationshipObj);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
if (Objects.isNull(relationship)) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < relationship.size(); i++) {
|
||||
JSONObject relaItem = relationship.getJSONObject(i);
|
||||
if (Objects.isNull(relaItem)) {
|
||||
continue;
|
||||
}
|
||||
String id = relaItem.getStr("Id");
|
||||
String target = "/xl/" + relaItem.getStr("Target");
|
||||
if (StringUtils.isNotEmpty(id)) {
|
||||
//wps 重复图片会保存为一个,所以这个处理下,相同rid 指向同一个图片
|
||||
List<WpsImg> wpsImgs = wpsImgList.stream().filter(item -> Objects.equals(item.getRId(), id)).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(wpsImgs)) {
|
||||
wpsImgs.forEach(x -> x.setImgName(target));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fzis.closeEntry();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fzis.close();
|
||||
}
|
||||
|
||||
Workbook workbook = WorkbookFactory.create(simpleFile.getInputStream());
|
||||
List<XSSFPictureData> allPictures = (List<XSSFPictureData>) workbook.getAllPictures();
|
||||
for (XSSFPictureData pictureData : allPictures) {
|
||||
PackagePartName partName = pictureData.getPackagePart().getPartName();
|
||||
URI uri = partName.getURI();
|
||||
//wps 重复图片会保存为一个,所以这个处理下,相同rid 指向同一个图片
|
||||
List<WpsImg> wpsImgs = wpsImgList.stream().filter(item -> Objects.equals(item.getImgName(), uri.toString())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(wpsImgs)) {
|
||||
wpsImgs.forEach(x -> x.setPictureData(pictureData));
|
||||
}
|
||||
}
|
||||
Map<String, WpsImg> result = new HashMap<>();
|
||||
for (WpsImg wpsImg : wpsImgList) {
|
||||
result.put(wpsImg.getCellStr(), wpsImg);
|
||||
}
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.getSheetAt(0);
|
||||
Map<String, WpsImg> flotPictures = WpsImgUtil.getFlotPictures(sheet);
|
||||
result.putAll(flotPictures);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取浮动形式的图片
|
||||
* 以map方式返回
|
||||
* 键为行列格式 x-y
|
||||
*
|
||||
* @param xssfSheet
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, WpsImg> getFlotPictures(XSSFSheet xssfSheet) {
|
||||
Map<String, WpsImg> map = new HashMap<>();
|
||||
XSSFDrawing drawingPatriarch = xssfSheet.getDrawingPatriarch();
|
||||
if (Objects.isNull(drawingPatriarch)) {
|
||||
return map;
|
||||
}
|
||||
List<XSSFShape> list = drawingPatriarch.getShapes();
|
||||
for (XSSFShape shape : list) {
|
||||
XSSFPicture picture = (XSSFPicture) shape;
|
||||
XSSFClientAnchor xssfClientAnchor = (XSSFClientAnchor) picture.getAnchor();
|
||||
XSSFPictureData pdata = picture.getPictureData();
|
||||
// 行号-列号
|
||||
String key = xssfClientAnchor.getRow1() + "-" + xssfClientAnchor.getCol1();
|
||||
WpsImg wpsImg = new WpsImg();
|
||||
wpsImg.setPictureData(pdata);
|
||||
wpsImg.setType(1);
|
||||
map.put(key, wpsImg);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片属性ID
|
||||
*/
|
||||
public static <T> List<String> getDispimgList(List<T> list) {
|
||||
List<String> pictureIds = new ArrayList<>();
|
||||
try {
|
||||
|
||||
for (T object : list) {
|
||||
// 获取对象的类
|
||||
Class<?> objClass = object.getClass();
|
||||
|
||||
// 获取类中所有声明的字段(包括私有字段)
|
||||
Field[] fields = objClass.getDeclaredFields();
|
||||
// 遍历字段并获取其值
|
||||
for (Field field : fields) {
|
||||
// 设置字段可访问(如果是私有字段)
|
||||
field.setAccessible(true);
|
||||
|
||||
// 获取字段值
|
||||
Object value = field.get(object);
|
||||
if (value instanceof String) {
|
||||
if (StrUtil.contains(value.toString(), "=DISPIMG")) {
|
||||
pictureIds.add(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取图片属性ID异常", e);
|
||||
}
|
||||
|
||||
return pictureIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片属性ID
|
||||
*/
|
||||
public static <T> void setDispimgUrl(List<T> list, Map<String, WpsImg> wpsImgs) {
|
||||
try {
|
||||
ProductServiceFeign productServiceFeign = SpringUtils.getBean(ProductServiceFeign.class);
|
||||
for (T object : list) {
|
||||
// 获取对象的类
|
||||
Class<?> objClass = object.getClass();
|
||||
// 获取类中所有声明的字段(包括私有字段)
|
||||
Field[] fields = objClass.getDeclaredFields();
|
||||
// 遍历字段并获取其值
|
||||
for (Field field : fields) {
|
||||
// 设置字段可访问(如果是私有字段)
|
||||
field.setAccessible(true);
|
||||
// 获取字段值
|
||||
Object value = field.get(object);
|
||||
if (value instanceof String) {
|
||||
String s = value.toString();
|
||||
if (wpsImgs.containsKey(s)) {
|
||||
WpsImg wpsImg = wpsImgs.get(s);
|
||||
PictureData pictureData = wpsImg.getPictureData();
|
||||
byte[] data = pictureData.getData();
|
||||
try (OutputStream os = Files.newOutputStream(Paths.get("/images/" + wpsImg.getImgId() + ".jpeg"))) {
|
||||
// OutputStream os = Files.newOutputStream(Paths.get("E:\\images" + wpsImg.getImgId() + ".jpeg"));
|
||||
os.write(data);
|
||||
}
|
||||
File file = new File("/images/" + wpsImg.getImgId() + ".jpeg");
|
||||
// File file = new File("E:\\images" + wpsImg.getImgId() + ".jpeg");
|
||||
MultipartFile cMultiFile = getMultipartFile(file);
|
||||
AjaxResult ajaxResult = productServiceFeign.uploadFeign(cMultiFile);
|
||||
if ("200".equals(String.valueOf(ajaxResult.get("code")))) {
|
||||
String imgUrl = ajaxResult.get(AjaxResult.MSG_TAG).toString();
|
||||
field.set(object, imgUrl);
|
||||
}
|
||||
file.delete();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("添加图片地址异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* file转multiPartFile
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static MultipartFile getMultipartFile(File file) {
|
||||
DiskFileItem item = new DiskFileItem("file"
|
||||
, MediaType.MULTIPART_FORM_DATA_VALUE
|
||||
, true
|
||||
, file.getName()
|
||||
, (int) file.length()
|
||||
, file.getParentFile());
|
||||
try {
|
||||
OutputStream os = item.getOutputStream();
|
||||
os.write(FileUtils.readFileToByteArray(file));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new CommonsMultipartFile(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.mhd.user.infrastructure.util.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 数据权限注解
|
||||
* @author zg
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DataPermissions {
|
||||
String cacheName();//缓存逻辑名称
|
||||
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package com.mhd.user.infrastructure.util.annotation;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.mhd.common.core.domain.entity.R;
|
||||
import com.mhd.common.core.domain.po.OrganizationPo;
|
||||
import com.mhd.common.core.domain.po.UserPo;
|
||||
import com.mhd.common.core.exception.ServiceException;
|
||||
import com.mhd.user.application.service.UserApplicationService;
|
||||
import com.mhd.user.domain.userAggregate.repository.todo.UserDataPermissionDO;
|
||||
import com.mhd.common.core.domain.po.UserDataPermissionPO;
|
||||
import com.mhd.common.core.enums.RoleEnum;
|
||||
import com.mhd.common.security.utils.SecurityUtils;
|
||||
import com.mhd.system.api.model.LoginUser;
|
||||
import com.mhd.user.infrastructure.feign.ProductServiceFeign;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Aspect
|
||||
public class SetDataPermissions {
|
||||
|
||||
@Autowired
|
||||
private UserApplicationService userApplicationService;
|
||||
@Resource
|
||||
private ProductServiceFeign productServiceFeign;
|
||||
|
||||
@Before("@annotation(dst)")
|
||||
public void dosetFeildValue(JoinPoint pjp, DataPermissions dst) throws Throwable {
|
||||
Object[] args = pjp.getArgs(); //获取目标对象方法参数
|
||||
//获取当前登陆人
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
OrganizationPo organizationPo = loginUser.getOrganizationPo();
|
||||
String s = dst.cacheName();
|
||||
Long permissionmenuId = getFieldValue(args, "permissionMenuId");
|
||||
//主要权限
|
||||
if ("master".equals(s)) {
|
||||
if (loginUser != null) {
|
||||
//判断当前用户是否是超级管理员/租户管理员还是普通用户,如果是超级管理员则返回全部组织,租户管理员则返回租户所属组织的全部组织,普通用户需要判断数据权限
|
||||
if (loginUser.getUserPo().getRoleCode().contains(RoleEnum.SUPER_ADMIN.getCode())) {
|
||||
//全部不加限制条件
|
||||
} else if (loginUser.getUserPo().getRoleCode().contains(RoleEnum.PLAT_ADMIN.getCode())) {
|
||||
R<OrganizationPo> organizationInfo = productServiceFeign.getInfoForIdList(loginUser.getUserPo().getOrganizationId());
|
||||
if (ObjectUtil.isNull(organizationInfo) || ObjectUtil.isNull(organizationInfo.getData())) {
|
||||
throw new ServiceException("登录用户组织不存在");
|
||||
}
|
||||
OrganizationPo data = organizationInfo.getData();
|
||||
List<Long> organizationIdList = data.getOrganizationIdList();
|
||||
objectSetValue(args, "organizationIdList", organizationIdList);
|
||||
} else {
|
||||
objectSetValue(args, "organizationId", loginUser.getUserPo().getOrganizationId());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (s.contains("wlhyUser")) {
|
||||
String feild = s.substring(s.indexOf("_") + 1);
|
||||
if (organizationPo.getOrganizationState() != null && organizationPo.getOrganizationState() == 1){
|
||||
if (userPo.getUserAccountType() != null && (ObjectUtil.equal(userPo.getUserAccountType(), 3) || ObjectUtil.equal(userPo.getUserAccountType(), 4))){
|
||||
objectSetValue(args,"topOrganizationId",organizationPo.getOrganizationId());
|
||||
}else {
|
||||
//企业员工需要查询企业货主创建的数据
|
||||
if (ObjectUtil.equal(userPo.getUserAccountType(), 5)){
|
||||
objectSetValue(args,feild,userPo.getCreateBy());
|
||||
}else {
|
||||
objectSetValue(args,feild,userPo.getUserId());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (userPo.getUserAccountType() != null && (ObjectUtil.equal(userPo.getUserAccountType(), 2) || ObjectUtil.equal(userPo.getUserAccountType(), 4))){
|
||||
objectSetValue(args,"organizationId",organizationPo.getOrganizationId());
|
||||
} else {
|
||||
//企业员工需要查询企业货主创建的数据
|
||||
if (ObjectUtil.equal(userPo.getUserAccountType(), 5)){
|
||||
objectSetValue(args,feild,userPo.getCreateBy());
|
||||
}else {
|
||||
objectSetValue(args,feild,userPo.getUserId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (s.contains("wlhyRole")) {
|
||||
String feild = s.substring(s.indexOf("_") + 1);
|
||||
if (userPo.getUserAccountType() != null){
|
||||
if (ObjectUtil.equal(userPo.getUserAccountType(), 3) || ObjectUtil.equal(userPo.getUserAccountType(), 2) || ObjectUtil.equal(userPo.getUserAccountType(), 4)){
|
||||
objectSetValue(args,"organizationId",organizationPo.getOrganizationId());
|
||||
objectSetValue(args,"roleGrade",2);
|
||||
}else if (ObjectUtil.equal(userPo.getUserAccountType(), 5)){
|
||||
objectSetValue(args,feild,userPo.getCreateBy());
|
||||
objectSetValue(args,"roleGrade",3);
|
||||
}else if (ObjectUtil.equal(userPo.getUserAccountType(), 1)){
|
||||
objectSetValue(args,feild,userPo.getUserId());
|
||||
objectSetValue(args,"roleGrade",3);
|
||||
}else {
|
||||
objectSetValue(args,feild,userPo.getUserId());
|
||||
}
|
||||
}else {
|
||||
objectSetValue(args,feild,userPo.getUserId());
|
||||
}
|
||||
}
|
||||
else if (s.contains("tenants")){
|
||||
objectSetValue(args, "topOrganizationId", userPo.getTopOrganizationId());
|
||||
}
|
||||
}
|
||||
|
||||
public void objectSetValue(Object[] args, String fieldName, Object value){
|
||||
for (Object arg : args) {
|
||||
Field field = ReflectionUtils.findField(arg.getClass(), fieldName);
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
ReflectionUtils.setField(field, arg, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Long getFieldValue(Object[] args, String field) {
|
||||
Long a = null;
|
||||
for (Object arg : args) {
|
||||
try {
|
||||
Field fieldName = arg.getClass().getDeclaredField(field);
|
||||
if (fieldName != null) {
|
||||
fieldName.setAccessible(true);
|
||||
Object o = fieldName.get(arg);
|
||||
if (o != null) {
|
||||
a = Long.valueOf(o.toString());
|
||||
return a;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package com.mhd.user.infrastructure.util.menu;
|
||||
|
||||
import com.mhd.common.core.domain.entity.R;
|
||||
import com.mhd.common.core.domain.po.MenuVo;
|
||||
import com.mhd.common.core.domain.po.UserRoleMenuPO;
|
||||
import com.mhd.user.domain.roleAggregate.repository.todo.RoleMenuDo;
|
||||
import com.mhd.user.domain.userAggregate.repository.todo.UserMenuDo;
|
||||
import com.mhd.user.infrastructure.feign.ProductServiceFeign;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class UserRoleMenuUtils {
|
||||
|
||||
@Resource
|
||||
private ProductServiceFeign productServiceFeign;
|
||||
/**
|
||||
* 封装唯一key,前端唯一值使用
|
||||
* @param list
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public List<UserRoleMenuPO> packKey(List<UserRoleMenuPO> list, String type){
|
||||
if (list == null || list.isEmpty()){
|
||||
return list;
|
||||
}
|
||||
list.forEach(e->e.setIdKey(type+e.getMenuId()));
|
||||
list = this.packProduct(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装唯一key,前端唯一值使用
|
||||
* @param roleMenuDo
|
||||
* @return
|
||||
*/
|
||||
public void removeKey(RoleMenuDo roleMenuDo){
|
||||
if (roleMenuDo.getIdKeyList() != null && !roleMenuDo.getIdKeyList().isEmpty()){
|
||||
List<String> idKeyList = roleMenuDo.getIdKeyList();
|
||||
List<Long> menuIdList = new ArrayList<>();
|
||||
idKeyList = idKeyList.stream().filter(e -> e.contains("02-")).collect(Collectors.toList());
|
||||
for (String s : idKeyList) {
|
||||
Long menuId = Long.valueOf(s.substring(s.lastIndexOf("-") + 1));
|
||||
menuIdList.add(menuId);
|
||||
}
|
||||
roleMenuDo.setMenuIds(menuIdList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装唯一key,前端唯一值使用
|
||||
* @param userMenuDo
|
||||
* @return
|
||||
*/
|
||||
public void removeKeyByRoleMenu(UserMenuDo userMenuDo){
|
||||
if (userMenuDo.getIdKeyList() != null && !userMenuDo.getIdKeyList().isEmpty()){
|
||||
List<String> idKeyList = userMenuDo.getIdKeyList();
|
||||
List<Long> menuIdList = new ArrayList<>();
|
||||
idKeyList = idKeyList.stream().filter(e -> e.contains("02-")).collect(Collectors.toList());
|
||||
for (String s : idKeyList) {
|
||||
Long menuId = Long.valueOf(s.substring(s.lastIndexOf("-") + 1));
|
||||
menuIdList.add(menuId);
|
||||
}
|
||||
userMenuDo.setMenuIds(menuIdList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品
|
||||
* @param list
|
||||
*/
|
||||
public List<UserRoleMenuPO> packProduct(List<UserRoleMenuPO> list){
|
||||
if (list != null || !list.isEmpty()){
|
||||
List<Long> collect = list.stream().map(UserRoleMenuPO::getMenuId).collect(Collectors.toList());
|
||||
R<List<Long>> productIdList = productServiceFeign.getProductIdList(collect);
|
||||
List<Long> data = productIdList.getData();
|
||||
if (data != null || !data.isEmpty()){
|
||||
List<UserRoleMenuPO> userRoleMenuPOList = new ArrayList<>();
|
||||
for (Long id : data){
|
||||
UserRoleMenuPO userRoleMenuPO = new UserRoleMenuPO();
|
||||
userRoleMenuPO.setMenuId(id);
|
||||
userRoleMenuPO.setIdKey("01-"+id);
|
||||
userRoleMenuPOList.add(userRoleMenuPO);
|
||||
}
|
||||
list.addAll(userRoleMenuPOList);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据两个菜单的集合判断是否应该存在产品
|
||||
* @param userRoleMenuPOList
|
||||
* @param menuVoList
|
||||
* @return
|
||||
*/
|
||||
public List<UserRoleMenuPO> matchingData(List<UserRoleMenuPO> userRoleMenuPOList, List<MenuVo> menuVoList) {
|
||||
if (menuVoList == null || menuVoList.isEmpty()){
|
||||
return userRoleMenuPOList;
|
||||
}
|
||||
Map<String, UserRoleMenuPO> collect = userRoleMenuPOList.stream().collect(Collectors.toMap(UserRoleMenuPO::getIdKey, Function.identity(),(m, n)->m));
|
||||
//第一层属于产品层
|
||||
for (MenuVo menuVo : menuVoList) {
|
||||
UserRoleMenuPO userRoleMenuPO = collect.get(menuVo.getIdKey());
|
||||
if (userRoleMenuPO != null){
|
||||
List<MenuVo> children = menuVo.getChildren();
|
||||
if (children != null && !children.isEmpty()){
|
||||
for (MenuVo child : children) {
|
||||
if (collect.get(child.getIdKey()) == null){
|
||||
collect.remove(menuVo.getIdKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(collect.values());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user