diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteUserService.java b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteUserService.java index 3717264f..23c5ca50 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteUserService.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteUserService.java @@ -16,6 +16,7 @@ import com.op.system.api.factory.RemoteUserFallbackFactory; import com.op.system.api.model.LoginUser; import java.util.List; +import java.util.Map; /** * 用户服务 @@ -48,4 +49,12 @@ public interface RemoteUserService { @PostMapping("/file/upLoadFile") public R upLoadFile(@RequestBody List files); + + /** + * 获取可见数据源 + * @param user + * @return + */ + @PostMapping("/user/getPoolNameList") + public R>> getPoolNameList(@RequestBody SysUser user); } diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/domain/SysUser.java b/op-api/op-api-system/src/main/java/com/op/system/api/domain/SysUser.java index c4bfaf18..32c7dbb0 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/domain/SysUser.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/domain/SysUser.java @@ -14,8 +14,8 @@ import com.op.common.core.xss.Xss; /** * 用户对象 sys_user - * - * @author OP + * + * @author sf */ public class SysUser extends BaseEntity { private static final long serialVersionUID = 1L; @@ -85,6 +85,15 @@ public class SysUser extends BaseEntity { /** 角色ID */ private Long roleId; + private String datasourceId; + + public String getDatasourceId() { + return datasourceId; + } + + public void setDatasourceId(String datasourceId) { + this.datasourceId = datasourceId; + } public SysUser() { diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteUserFallbackFactory.java b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteUserFallbackFactory.java index 4ce7932f..2566a99b 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteUserFallbackFactory.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteUserFallbackFactory.java @@ -11,6 +11,7 @@ import com.op.system.api.domain.SysUser; import com.op.system.api.model.LoginUser; import java.util.List; +import java.util.Map; /** * 用户服务降级处理 @@ -39,6 +40,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory upLoadFile(List files) { return R.fail("上传失败:" + throwable.getMessage()); } + + @Override + public R>> getPoolNameList(SysUser user) { + return R.fail("工厂数据源获取失败:" + throwable.getMessage()); + } }; } } diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/model/LoginUser.java b/op-api/op-api-system/src/main/java/com/op/system/api/model/LoginUser.java index 977cfe45..99003902 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/model/LoginUser.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/model/LoginUser.java @@ -2,12 +2,13 @@ package com.op.system.api.model; import java.io.Serializable; import java.util.Set; + import com.op.system.api.domain.SysUser; /** * 用户信息 * - * @author OP + * @author sf */ public class LoginUser implements Serializable { private static final long serialVersionUID = 1L; @@ -51,6 +52,8 @@ public class LoginUser implements Serializable { * 角色列表 */ private Set roles; + // 可访问工厂数据源 + private String poolName; /** * 用户信息 @@ -128,4 +131,12 @@ public class LoginUser implements Serializable { public void setSysUser(SysUser sysUser) { this.sysUser = sysUser; } + + public String getPoolName() { + return poolName; + } + + public void setPoolName(String poolName) { + this.poolName = poolName; + } } diff --git a/op-auth/src/main/java/com/op/auth/service/SysLoginService.java b/op-auth/src/main/java/com/op/auth/service/SysLoginService.java index 2de21964..c5868ad1 100644 --- a/op-auth/src/main/java/com/op/auth/service/SysLoginService.java +++ b/op-auth/src/main/java/com/op/auth/service/SysLoginService.java @@ -1,7 +1,10 @@ package com.op.auth.service; +import java.util.concurrent.TimeUnit; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; + import com.op.common.core.constant.CacheConstants; import com.op.common.core.constant.Constants; import com.op.common.core.constant.SecurityConstants; @@ -20,8 +23,8 @@ import com.op.system.api.model.LoginUser; /** * 登录校验方法 - * - * @author OP + * + * @author sf */ @Component public class SysLoginService { @@ -86,7 +89,15 @@ public class SysLoginService { recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); throw new ServiceException("对不起,您的账号:" + username + " 已停用"); } + /****** 2023年4月20日17:01:52 检查是否配置工厂数据源 ******/ + if (StringUtils.isEmpty(userInfo.getPoolName())) { + recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户暂未分配工厂数据源,请联系管理员"); + throw new ServiceException("对不起,您的账号:" + username + " 暂未分配工厂数据源"); + } passwordService.validate(user, password); + // 缓存用户工厂数据源 + redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, userInfo.getPoolName(), + CacheConstants.REFRESH_TIME, TimeUnit.MINUTES); recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); return userInfo; } diff --git a/op-common/op-common-core/src/main/java/com/op/common/core/constant/CacheConstants.java b/op-common/op-common-core/src/main/java/com/op/common/core/constant/CacheConstants.java index 509b490d..2303b64a 100644 --- a/op-common/op-common-core/src/main/java/com/op/common/core/constant/CacheConstants.java +++ b/op-common/op-common-core/src/main/java/com/op/common/core/constant/CacheConstants.java @@ -2,7 +2,7 @@ package com.op.common.core.constant; /** * 缓存常量信息 - * + * * @author OP */ public class CacheConstants { @@ -55,4 +55,6 @@ public class CacheConstants { * 登录IP黑名单 cache key */ public static final String SYS_LOGIN_BLACKIPLIST = SYS_CONFIG_KEY + "sys.login.blackIPList"; + // 用户当前所选工厂 + public static final String USER_POOL_NAME_CURRENT = "user_pool_name_current:"; } diff --git a/op-common/op-common-core/src/main/java/com/op/common/core/web/domain/BaseEntity.java b/op-common/op-common-core/src/main/java/com/op/common/core/web/domain/BaseEntity.java index a0c7aad5..9d51a6bf 100644 --- a/op-common/op-common-core/src/main/java/com/op/common/core/web/domain/BaseEntity.java +++ b/op-common/op-common-core/src/main/java/com/op/common/core/web/domain/BaseEntity.java @@ -10,8 +10,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; /** * Entity基类 - * - * @author OP + * + * @author sf */ public class BaseEntity implements Serializable { private static final long serialVersionUID = 1L; @@ -36,6 +36,10 @@ public class BaseEntity implements Serializable { /** 备注 */ private String remark; + //数据源标识 + private String poolName; + //部门 + private Long deptId; /** 请求参数 */ @JsonInclude(JsonInclude.Include.NON_EMPTY) @@ -99,4 +103,20 @@ public class BaseEntity implements Serializable { public void setParams(Map params) { this.params = params; } + + public String getPoolName() { + return poolName; + } + + public void setPoolName(String poolName) { + this.poolName = poolName; + } + + public Long getDeptId() { + return deptId; + } + + public void setDeptId(Long deptId) { + this.deptId = deptId; + } } diff --git a/op-common/op-common-datascope/src/main/java/com/op/common/datascope/annotation/DataScope.java b/op-common/op-common-datascope/src/main/java/com/op/common/datascope/annotation/DataScope.java index 6e7d95d6..d4b68513 100644 --- a/op-common/op-common-datascope/src/main/java/com/op/common/datascope/annotation/DataScope.java +++ b/op-common/op-common-datascope/src/main/java/com/op/common/datascope/annotation/DataScope.java @@ -8,8 +8,8 @@ import java.lang.annotation.Target; /** * 数据权限过滤注解 - * - * @author OP + * + * @author sf */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) diff --git a/op-common/op-common-datascope/src/main/java/com/op/common/datascope/annotation/PoolDeptAuto.java b/op-common/op-common-datascope/src/main/java/com/op/common/datascope/annotation/PoolDeptAuto.java new file mode 100644 index 00000000..7a6692bd --- /dev/null +++ b/op-common/op-common-datascope/src/main/java/com/op/common/datascope/annotation/PoolDeptAuto.java @@ -0,0 +1,24 @@ +package com.op.common.datascope.annotation; + +import java.lang.annotation.*; + +/** + * 自动设置当前数据源及数据所属的部门 + * + * @ClassName: DataPoolDept + * @Description: TODO + * @author shichangzhou + * @date 2023年4月24日 下午5:47:07 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface PoolDeptAuto { + + // 是否自动设置数据源标识 + public boolean pool() default true; + + // 是否自动设置部门 + public boolean dept() default true; + +} diff --git a/op-common/op-common-datascope/src/main/java/com/op/common/datascope/aspect/DataScopeAspect.java b/op-common/op-common-datascope/src/main/java/com/op/common/datascope/aspect/DataScopeAspect.java index 863493c1..abde8aa0 100644 --- a/op-common/op-common-datascope/src/main/java/com/op/common/datascope/aspect/DataScopeAspect.java +++ b/op-common/op-common-datascope/src/main/java/com/op/common/datascope/aspect/DataScopeAspect.java @@ -1,16 +1,26 @@ package com.op.common.datascope.aspect; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; + +import com.op.common.datascope.annotation.DataScope; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; + +import com.op.common.core.constant.CacheConstants; import com.op.common.core.context.SecurityContextHolder; import com.op.common.core.text.Convert; import com.op.common.core.utils.StringUtils; import com.op.common.core.web.domain.BaseEntity; -import com.op.common.datascope.annotation.DataScope; + +import com.op.common.datascope.annotation.PoolDeptAuto; +import com.op.common.redis.service.RedisService; import com.op.common.security.utils.SecurityUtils; import com.op.system.api.domain.SysRole; import com.op.system.api.domain.SysUser; @@ -18,12 +28,18 @@ import com.op.system.api.model.LoginUser; /** * 数据过滤处理 - * - * @author OP + * + * @author sf */ @Aspect @Component public class DataScopeAspect { + + private static final Logger log = LoggerFactory.getLogger(DataScopeAspect.class); + + @Autowired + private RedisService redisService; + /** * 全部数据权限 */ @@ -60,6 +76,57 @@ public class DataScopeAspect { handleDataScope(point, controllerDataScope); } + @Before("@annotation(controllerPoolDeptAuto)") + public void doBefore(JoinPoint point, PoolDeptAuto controllerPoolDeptAuto) + throws SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchFieldException { + + Object obj = point.getArgs()[0]; + if (controllerPoolDeptAuto.pool()) { + log.debug("已开启自动设置数据源标识"); + Field field = null; + try { + field = obj.getClass().getSuperclass().getDeclaredField("poolName"); + } catch (NoSuchFieldException e) { + field = obj.getClass().getDeclaredField("poolName"); + log.error("If PoolDeptAuto annotation is used, the parameter must contain poolName!", e); + throw e; + } + field.setAccessible(true); + Object poolName = field.get(obj); + if (poolName == null) { + // 缓存用户工厂数据源 + poolName = redisService + .getCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + SecurityUtils.getUsername()); + if (StringUtils.isNotNull(poolName)) { + field.set(obj, poolName); + } else { + log.error("Cannot be found the current poolName!"); + } + } + } + if (controllerPoolDeptAuto.dept()) { + Field field = null; + try { + field = obj.getClass().getSuperclass().getDeclaredField("deptId"); + } catch (NoSuchFieldException e) { + field = obj.getClass().getDeclaredField("deptId"); + log.error("If PoolDeptAuto annotation is used, the parameter must contain deptId!", e); + throw e; + } + field.setAccessible(true); + Object deptId = field.get(obj); + if (deptId == null) { + // 获取当前的用户 + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (StringUtils.isNotNull(loginUser)) { + field.set(obj, loginUser.getSysUser().getDeptId()); + } else { + log.error("Cannot be found the current login user deptId!"); + } + } + } + } + protected void handleDataScope(final JoinPoint joinPoint, DataScope controllerDataScope) { // 获取当前的用户 LoginUser loginUser = SecurityUtils.getLoginUser(); @@ -77,7 +144,7 @@ public class DataScopeAspect { /** * 数据范围过滤 - * + * * @param joinPoint 切点 * @param user 用户 * @param deptAlias 部门别名 @@ -85,7 +152,7 @@ public class DataScopeAspect { * @param permission 权限字符 */ public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, - String permission) { + String permission) { StringBuilder sqlString = new StringBuilder(); List conditions = new ArrayList(); diff --git a/op-common/op-common-datasource/src/main/java/com/op/common/datasource/creator/DynamicDatasourceCreator.java b/op-common/op-common-datasource/src/main/java/com/op/common/datasource/creator/DynamicDatasourceCreator.java new file mode 100644 index 00000000..c1e747d3 --- /dev/null +++ b/op-common/op-common-datasource/src/main/java/com/op/common/datasource/creator/DynamicDatasourceCreator.java @@ -0,0 +1,36 @@ +package com.op.common.datasource.creator; + +import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; +import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.sql.DataSource; + +/** + * 动态创建数据源 + * + * @ClassName: DynamicDatasourceCreator + * @Description: TODO + * @author shichangzhou + * @date 2023年4月20日 下午1:15:09 + */ +@Component +public class DynamicDatasourceCreator { + + private static final Logger log = LoggerFactory.getLogger(DynamicDatasourceCreator.class); + @Resource + private DynamicRoutingDataSource dynamicRoutingDataSource; + @Resource + private DefaultDataSourceCreator defaultDataSourceCreator; + + public DataSource createDynamicDataSource(DataSourceProperty dataSourceProperty) { + log.info("Dynamic Datasource init....."); + DataSource dataSource = defaultDataSourceCreator.createDataSource(dataSourceProperty); + dynamicRoutingDataSource.addDataSource(dataSourceProperty.getPoolName(), dataSource); + return dataSource; + } +} diff --git a/op-common/op-common-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/op-common/op-common-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..0c6aabed --- /dev/null +++ b/op-common/op-common-datasource/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.op.common.datasource.creator.DynamicDatasourceCreator diff --git a/op-modules/op-mes/src/main/java/com/op/mes/config/DynamicDatasource.java b/op-modules/op-mes/src/main/java/com/op/mes/config/DynamicDatasource.java new file mode 100644 index 00000000..523a95cc --- /dev/null +++ b/op-modules/op-mes/src/main/java/com/op/mes/config/DynamicDatasource.java @@ -0,0 +1,53 @@ +package com.op.mes.config; + +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; +import com.op.common.core.domain.R; +import com.op.common.datasource.creator.DynamicDatasourceCreator; +import com.op.system.api.RemoteUserService; +import com.op.system.api.domain.SysUser; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * 初始化动态数据源 + * + * @ClassName: DynamicDatasource + * @Description: TODO + * @author shichangzhou + * @date 2023年4月19日 下午1:01:30 + */ +@Component +public class DynamicDatasource { + + @Resource + private DynamicDatasourceCreator dynamicDatasourceCreator; + @Autowired + private RemoteUserService remoteUserService; + + @PostConstruct + public void init() { + // 加载sf-cloud库的sys_datasource + SysUser sysUser = new SysUser(); + sysUser.setUserId(1L); + R>> dateSources0 = remoteUserService.getPoolNameList(sysUser); + List> dateSources = dateSources0.getData(); + for (Map dateSource : dateSources) { + DataSourceProperty sdp = new DataSourceProperty(); + sdp.setUrl(dateSource.get("url")); + sdp.setUsername(dateSource.get("userName")); + sdp.setPassword(dateSource.get("password")); + sdp.setDriverClassName(dateSource.get("driveClassName")); + sdp.setPoolName(dateSource.get("poolName"));// 这是数据源的key + sdp.setLazy(false); + dynamicDatasourceCreator.createDynamicDataSource(sdp); + } + + } +} diff --git a/op-modules/op-mes/src/main/java/com/op/mes/controller/BaseFileController.java b/op-modules/op-mes/src/main/java/com/op/mes/controller/BaseFileController.java index cb000551..81af94b5 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/controller/BaseFileController.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/controller/BaseFileController.java @@ -34,6 +34,7 @@ public class BaseFileController extends BaseController { */ @RequiresPermissions("system:file:list") @GetMapping("/list") + public TableDataInfo list(BaseFile baseFile) { startPage(); List list = baseFileService.selectBaseFileList(baseFile); diff --git a/op-modules/op-mes/src/main/java/com/op/mes/controller/ProRouteController.java b/op-modules/op-mes/src/main/java/com/op/mes/controller/ProRouteController.java index 7b1c4a24..95d568d3 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/controller/ProRouteController.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/controller/ProRouteController.java @@ -3,6 +3,7 @@ package com.op.mes.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.utils.poi.ExcelUtil; import com.op.common.core.utils.uuid.IdUtils; import com.op.common.core.web.domain.AjaxResult; diff --git a/op-modules/op-mes/src/main/java/com/op/mes/controller/ProRouteLineController.java b/op-modules/op-mes/src/main/java/com/op/mes/controller/ProRouteLineController.java new file mode 100644 index 00000000..4de67b4f --- /dev/null +++ b/op-modules/op-mes/src/main/java/com/op/mes/controller/ProRouteLineController.java @@ -0,0 +1,103 @@ +package com.op.mes.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.op.common.log.annotation.Log; +import com.op.common.log.enums.BusinessType; +import com.op.common.security.annotation.RequiresPermissions; +import com.op.mes.domain.ProRouteLine; +import com.op.mes.service.IProRouteLineService; +import com.op.common.core.web.controller.BaseController; +import com.op.common.core.web.domain.AjaxResult; +import com.op.common.core.utils.poi.ExcelUtil; +import com.op.common.core.web.page.TableDataInfo; + +/** + * 工艺线体关联Controller + * + * @author Open Platform + * @date 2023-07-13 + */ +@RestController +@RequestMapping("/pro/routeprodline") +public class ProRouteLineController extends BaseController { + @Autowired + private IProRouteLineService proRouteLineService; + + /** + * 查询工艺线体关联列表 + */ + //@RequiresPermissions("system:line:list") + @GetMapping("/list") + public TableDataInfo list(ProRouteLine proRouteLine) { + startPage(); + List list = proRouteLineService.selectProRouteLineList(proRouteLine); + return getDataTable(list); + } + + /** + * 导出工艺线体关联列表 + */ + //@RequiresPermissions("system:line:export") + @Log(title = "工艺线体关联", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, ProRouteLine proRouteLine) { + List list = proRouteLineService.selectProRouteLineList(proRouteLine); + ExcelUtil util = new ExcelUtil(ProRouteLine.class); + util.exportExcel(response, list, "工艺线体关联数据"); + } + + /** + * 获取工艺线体关联详细信息 + */ + //@RequiresPermissions("system:line:query") + @GetMapping(value = "/{recordId}") + public AjaxResult getInfo(@PathVariable("recordId") String recordId) { + return success(proRouteLineService.selectProRouteLineByRecordId(recordId)); + } + + /** + * 新增工艺线体关联 + */ + //@RequiresPermissions("system:line:add") + @Log(title = "工艺线体关联", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody ProRouteLine proRouteLine) { + return toAjax(proRouteLineService.insertProRouteLine(proRouteLine)); + } + + /** + * 修改工艺线体关联 + */ + //@RequiresPermissions("system:line:edit") + @Log(title = "工艺线体关联", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody ProRouteLine proRouteLine) { + return toAjax(proRouteLineService.updateProRouteLine(proRouteLine)); + } + + /** + * 删除工艺线体关联 + */ + //@RequiresPermissions("system:line:remove") + @Log(title = "工艺线体关联", businessType = BusinessType.DELETE) + @DeleteMapping("/{recordIds}") + public AjaxResult remove(@PathVariable String[] recordIds) { + return toAjax(proRouteLineService.deleteProRouteLineByRecordIds(recordIds)); + } + + /**穿梭框**/ + @GetMapping("/getList") + public ProRouteLine getList(ProRouteLine proRouteLine) { + return proRouteLineService.getList(proRouteLine); + } +} diff --git a/op-modules/op-mes/src/main/java/com/op/mes/domain/ProOrder.java b/op-modules/op-mes/src/main/java/com/op/mes/domain/ProOrder.java index ce270428..2c6740a3 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/domain/ProOrder.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/domain/ProOrder.java @@ -21,6 +21,10 @@ public class ProOrder extends TreeEntity { /** 计划工厂编码 */ @Excel(name = "计划工厂编码") + private String planFactoryCode; + + /** 计划工厂编码 */ + @Excel(name = "工厂编码") private String factoryCode; /** 订单类型 */ @@ -93,6 +97,14 @@ public class ProOrder extends TreeEntity { @Excel(name = "上级工单") private String parentOrder; + public String getPlanFactoryCode() { + return planFactoryCode; + } + + public void setPlanFactoryCode(String planFactoryCode) { + this.planFactoryCode = planFactoryCode; + } + /** 产品类型 */ @Excel(name = "产品类型") private String prodType; diff --git a/op-modules/op-mes/src/main/java/com/op/mes/domain/ProRouteLine.java b/op-modules/op-mes/src/main/java/com/op/mes/domain/ProRouteLine.java new file mode 100644 index 00000000..c2a46361 --- /dev/null +++ b/op-modules/op-mes/src/main/java/com/op/mes/domain/ProRouteLine.java @@ -0,0 +1,183 @@ +package com.op.mes.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.op.common.core.annotation.Excel; +import com.op.common.core.web.domain.BaseEntity; + +import java.util.List; + +/** + * 工艺线体关联对象 pro_route_line + * + * @author Open Platform + * @date 2023-07-13 + */ +public class ProRouteLine extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** 记录ID */ + private String recordId; + + /** 工艺路线ID */ + @Excel(name = "工艺路线ID") + private String routeId; + + /** 线体ID */ + @Excel(name = "线体ID") + private String itemId; + + /** 线体编码 */ + @Excel(name = "线体编码") + private String itemCode; + + /** 线体名称 */ + @Excel(name = "线体名称") + private String itemName; + + /** 预留字段1 */ + @Excel(name = "预留字段1") + private String attr1; + + /** 预留字段2 */ + @Excel(name = "预留字段2") + private String attr2; + + /** 预留字段3 */ + @Excel(name = "预留字段3") + private String attr3; + + /** 预留字段4 */ + @Excel(name = "预留字段4") + private String attr4; + + private String key; + private String label; + private List unSelect; + private List selected; + private List selectedValues; + + public List getSelectedValues() { + return selectedValues; + } + + public void setSelectedValues(List selectedValues) { + this.selectedValues = selectedValues; + } + + public List getUnSelect() { + return unSelect; + } + + public void setUnSelect(List unSelect) { + this.unSelect = unSelect; + } + + public List getSelected() { + return selected; + } + + public void setSelected(List selected) { + this.selected = selected; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public void setRecordId(String recordId) { + this.recordId = recordId; + } + + public String getRecordId() { + return recordId; + } + public void setRouteId(String routeId) { + this.routeId = routeId; + } + + public String getRouteId() { + return routeId; + } + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getItemId() { + return itemId; + } + public void setItemCode(String itemCode) { + this.itemCode = itemCode; + } + + public String getItemCode() { + return itemCode; + } + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public String getItemName() { + return itemName; + } + public void setAttr1(String attr1) { + this.attr1 = attr1; + } + + public String getAttr1() { + return attr1; + } + public void setAttr2(String attr2) { + this.attr2 = attr2; + } + + public String getAttr2() { + return attr2; + } + public void setAttr3(String attr3) { + this.attr3 = attr3; + } + + public String getAttr3() { + return attr3; + } + public void setAttr4(String attr4) { + this.attr4 = attr4; + } + + public String getAttr4() { + return attr4; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("recordId", getRecordId()) + .append("routeId", getRouteId()) + .append("itemId", getItemId()) + .append("itemCode", getItemCode()) + .append("itemName", getItemName()) + .append("remark", getRemark()) + .append("attr1", getAttr1()) + .append("attr2", getAttr2()) + .append("attr3", getAttr3()) + .append("attr4", getAttr4()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} diff --git a/op-modules/op-mes/src/main/java/com/op/mes/domain/SysDatasource.java b/op-modules/op-mes/src/main/java/com/op/mes/domain/SysDatasource.java new file mode 100644 index 00000000..4bfddeb8 --- /dev/null +++ b/op-modules/op-mes/src/main/java/com/op/mes/domain/SysDatasource.java @@ -0,0 +1,148 @@ +package com.op.mes.domain; + +import com.op.common.core.annotation.Excel; +import com.op.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 工厂数据库对象 sys_datasource + * + * @author sf + * @date 2023-04-20 + */ +public class SysDatasource extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 用户ID */ + private String id; + + /** 地址 */ + @Excel(name = "地址") + private String url; + + /** 用户名 */ + @Excel(name = "用户名") + private String userName; + + /** 密码 */ + @Excel(name = "密码") + private String password; + + /** 驱动 */ + @Excel(name = "驱动") + private String driveClassName; + + /** 数据源标识 */ + @Excel(name = "数据源标识") + private String poolName; + private String parkName; + + /** 帐号状态(0正常 */ + @Excel(name = "帐号状态", readConverterExp = "帐号状态(0正常") + private String status; + + /** 删除标志(0代表存在 */ + private String delFlag; + + public void setId(String id) + { + this.id = id; + } + + public String getId() + { + return id; + } + public void setUrl(String url) + { + this.url = url; + } + + public String getUrl() + { + return url; + } + public void setUserName(String userName) + { + this.userName = userName; + } + + public String getUserName() + { + return userName; + } + public void setPassword(String password) + { + this.password = password; + } + + public String getPassword() + { + return password; + } + public void setDriveClassName(String driveClassName) + { + this.driveClassName = driveClassName; + } + + public String getDriveClassName() + { + return driveClassName; + } + public void setPoolName(String poolName) + { + this.poolName = poolName; + } + + public String getPoolName() + { + return poolName; + } + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + public void setDelFlag(String delFlag) + { + this.delFlag = delFlag; + } + + public String getDelFlag() + { + return delFlag; + } + + public String getParkName() { + return parkName; + } + + public void setParkName(String parkName) { + this.parkName = parkName; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("url", getUrl()) + .append("userName", getUserName()) + .append("password", getPassword()) + .append("driveClassName", getDriveClassName()) + .append("poolName", getPoolName()) + .append("status", getStatus()) + .append("delFlag", getDelFlag()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/op-modules/op-mes/src/main/java/com/op/mes/mapper/ProRouteLineMapper.java b/op-modules/op-mes/src/main/java/com/op/mes/mapper/ProRouteLineMapper.java new file mode 100644 index 00000000..e694a96f --- /dev/null +++ b/op-modules/op-mes/src/main/java/com/op/mes/mapper/ProRouteLineMapper.java @@ -0,0 +1,68 @@ +package com.op.mes.mapper; + +import java.util.List; + +import com.op.mes.domain.ProRouteLine; +import org.apache.ibatis.annotations.Mapper; + +/** + * 工艺线体关联Mapper接口 + * + * @author Open Platform + * @date 2023-07-13 + */ +@Mapper +public interface ProRouteLineMapper { + /** + * 查询工艺线体关联 + * + * @param recordId 工艺线体关联主键 + * @return 工艺线体关联 + */ + public ProRouteLine selectProRouteLineByRecordId(String recordId); + + /** + * 查询工艺线体关联列表 + * + * @param proRouteLine 工艺线体关联 + * @return 工艺线体关联集合 + */ + public List selectProRouteLineList(ProRouteLine proRouteLine); + + /** + * 新增工艺线体关联 + * + * @param proRouteLine 工艺线体关联 + * @return 结果 + */ + public int insertProRouteLine(ProRouteLine proRouteLine); + + /** + * 修改工艺线体关联 + * + * @param proRouteLine 工艺线体关联 + * @return 结果 + */ + public int updateProRouteLine(ProRouteLine proRouteLine); + + /** + * 删除工艺线体关联 + * + * @param recordId 工艺线体关联主键 + * @return 结果 + */ + public int deleteProRouteLineByRecordId(String recordId); + + /** + * 批量删除工艺线体关联 + * + * @param recordIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteProRouteLineByRecordIds(String[] recordIds); + + public List getRouteProdLineListUndo(ProRouteLine proRouteLine); + List getRouteProdLineListDo(ProRouteLine proRouteLine); + + void deleteByRouteId(ProRouteLine proRouteLine); +} diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/IProRouteLineService.java b/op-modules/op-mes/src/main/java/com/op/mes/service/IProRouteLineService.java new file mode 100644 index 00000000..cac81023 --- /dev/null +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/IProRouteLineService.java @@ -0,0 +1,62 @@ +package com.op.mes.service; + +import java.util.List; +import com.op.mes.domain.ProRouteLine; + +/** + * 工艺线体关联Service接口 + * + * @author Open Platform + * @date 2023-07-13 + */ +public interface IProRouteLineService { + /** + * 查询工艺线体关联 + * + * @param recordId 工艺线体关联主键 + * @return 工艺线体关联 + */ + public ProRouteLine selectProRouteLineByRecordId(String recordId); + + /** + * 查询工艺线体关联列表 + * + * @param proRouteLine 工艺线体关联 + * @return 工艺线体关联集合 + */ + public List selectProRouteLineList(ProRouteLine proRouteLine); + + /** + * 新增工艺线体关联 + * + * @param proRouteLine 工艺线体关联 + * @return 结果 + */ + public int insertProRouteLine(ProRouteLine proRouteLine); + + /** + * 修改工艺线体关联 + * + * @param proRouteLine 工艺线体关联 + * @return 结果 + */ + public int updateProRouteLine(ProRouteLine proRouteLine); + + /** + * 批量删除工艺线体关联 + * + * @param recordIds 需要删除的工艺线体关联主键集合 + * @return 结果 + */ + public int deleteProRouteLineByRecordIds(String[] recordIds); + + /** + * 删除工艺线体关联信息 + * + * @param recordId 工艺线体关联主键 + * @return 结果 + */ + public int deleteProRouteLineByRecordId(String recordId); + + ProRouteLine getList(ProRouteLine proRouteLine); +} diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/BaseFileServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/BaseFileServiceImpl.java index a868b0d6..c3091faa 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/BaseFileServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/BaseFileServiceImpl.java @@ -1,5 +1,6 @@ package com.op.mes.service.impl; +import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.domain.BaseFileData; import com.op.common.core.utils.DateUtils; import com.op.mes.domain.BaseFile; @@ -28,6 +29,7 @@ public class BaseFileServiceImpl implements IBaseFileService { * @return 附件 */ @Override + @DS("#header.poolName") public BaseFile selectBaseFileByFileId(String fileId) { return baseFileMapper.selectBaseFileByFileId(fileId); } @@ -39,6 +41,7 @@ public class BaseFileServiceImpl implements IBaseFileService { * @return 附件 */ @Override + @DS("#header.poolName") public List selectBaseFileList(BaseFile baseFile) { return baseFileMapper.selectBaseFileList(baseFile); } @@ -50,6 +53,7 @@ public class BaseFileServiceImpl implements IBaseFileService { * @return 结果 */ @Override + @DS("#header.poolName") public int insertBaseFile(BaseFile baseFile) { baseFile.setCreateTime(DateUtils.getNowDate()); return baseFileMapper.insertBaseFile(baseFile); @@ -62,6 +66,7 @@ public class BaseFileServiceImpl implements IBaseFileService { * @return 结果 */ @Override + @DS("#header.poolName") public int updateBaseFile(BaseFile baseFile) { baseFile.setUpdateTime(DateUtils.getNowDate()); return baseFileMapper.updateBaseFile(baseFile); @@ -74,6 +79,7 @@ public class BaseFileServiceImpl implements IBaseFileService { * @return 结果 */ @Override + @DS("#header.poolName") public int deleteBaseFileByFileIds(String[] fileIds) { return baseFileMapper.deleteBaseFileByFileIds(fileIds); } @@ -85,6 +91,7 @@ public class BaseFileServiceImpl implements IBaseFileService { * @return 结果 */ @Override + @DS("#header.poolName") public int deleteBaseFileByFileId(String fileId) { return baseFileMapper.deleteBaseFileByFileId(fileId); } @@ -96,6 +103,7 @@ public class BaseFileServiceImpl implements IBaseFileService { * @return 结果 */ @Override + @DS("#header.poolName") public Boolean insertBaseFileBatch(List baseFiles) { return baseFileMapper.insertBaseFileBatch(baseFiles); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProOrderServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProOrderServiceImpl.java index 2c6eb78b..9b0109ad 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProOrderServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProOrderServiceImpl.java @@ -1,6 +1,8 @@ package com.op.mes.service.impl; import java.util.List; + +import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.utils.DateUtils; import com.op.common.core.utils.uuid.IdUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -27,6 +29,7 @@ public class ProOrderServiceImpl implements IProOrderService { * @return 订单 */ @Override + @DS("#header.poolName") public ProOrder selectProOrderById(String id) { return proOrderMapper.selectProOrderById(id); } @@ -38,6 +41,7 @@ public class ProOrderServiceImpl implements IProOrderService { * @return 订单 */ @Override + @DS("#header.poolName") public List selectProOrderList(ProOrder proOrder) { return proOrderMapper.selectProOrderList(proOrder); } @@ -49,6 +53,7 @@ public class ProOrderServiceImpl implements IProOrderService { * @return 结果 */ @Override + @DS("#header.poolName") public int insertProOrder(ProOrder proOrder) { proOrder.setId(IdUtils.fastSimpleUUID()); proOrder.setCreateTime(DateUtils.getNowDate()); @@ -62,6 +67,7 @@ public class ProOrderServiceImpl implements IProOrderService { * @return 结果 */ @Override + @DS("#header.poolName") public int updateProOrder(ProOrder proOrder) { proOrder.setUpdateTime(DateUtils.getNowDate()); return proOrderMapper.updateProOrder(proOrder); @@ -74,6 +80,7 @@ public class ProOrderServiceImpl implements IProOrderService { * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProOrderByIds(String[] ids) { return proOrderMapper.deleteProOrderByIds(ids); } @@ -85,6 +92,7 @@ public class ProOrderServiceImpl implements IProOrderService { * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProOrderById(String id) { return proOrderMapper.deleteProOrderById(id); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProProcessContentServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProProcessContentServiceImpl.java index 5c799a2a..607392f9 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProProcessContentServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProProcessContentServiceImpl.java @@ -2,6 +2,7 @@ package com.op.mes.service.impl; import java.util.List; +import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.utils.DateUtils; import com.op.common.core.utils.uuid.IdUtils; import com.op.mes.domain.ProProcessContent; @@ -29,6 +30,7 @@ public class ProProcessContentServiceImpl implements IProProcessContentService * @return 生产工序内容 */ @Override + @DS("#header.poolName") public ProProcessContent selectProProcessContentByContentId(String contentId) { return proProcessContentMapper.selectProProcessContentByContentId(contentId); @@ -41,6 +43,7 @@ public class ProProcessContentServiceImpl implements IProProcessContentService * @return 生产工序内容 */ @Override + @DS("#header.poolName") public List selectProProcessContentList(ProProcessContent proProcessContent) { return proProcessContentMapper.selectProProcessContentList(proProcessContent); @@ -53,6 +56,7 @@ public class ProProcessContentServiceImpl implements IProProcessContentService * @return 结果 */ @Override + @DS("#header.poolName") public int insertProProcessContent(ProProcessContent proProcessContent) { proProcessContent.setCreateTime(DateUtils.getNowDate()); @@ -67,6 +71,7 @@ public class ProProcessContentServiceImpl implements IProProcessContentService * @return 结果 */ @Override + @DS("#header.poolName") public int updateProProcessContent(ProProcessContent proProcessContent) { proProcessContent.setUpdateTime(DateUtils.getNowDate()); @@ -80,6 +85,7 @@ public class ProProcessContentServiceImpl implements IProProcessContentService * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProProcessContentByContentIds(String[] contentIds) { return proProcessContentMapper.deleteProProcessContentByContentIds(contentIds); @@ -92,6 +98,7 @@ public class ProProcessContentServiceImpl implements IProProcessContentService * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProProcessContentByContentId(String contentId) { return proProcessContentMapper.deleteProProcessContentByContentId(contentId); diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProProcessServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProProcessServiceImpl.java index e2e470e8..79e903e7 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProProcessServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProProcessServiceImpl.java @@ -1,5 +1,6 @@ package com.op.mes.service.impl; +import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.constant.UserConstants; import com.op.common.core.domain.BaseFileData; import com.op.common.core.utils.DateUtils; @@ -43,6 +44,7 @@ public class ProProcessServiceImpl implements IProProcessService * @return 生产工序 */ @Override + @DS("#header.poolName") public ProProcess selectProProcessByProcessId(String processId) { ProProcess p = proProcessMapper.selectProProcessByProcessId(processId); @@ -60,6 +62,7 @@ public class ProProcessServiceImpl implements IProProcessService * @return 生产工序 */ @Override + @DS("#header.poolName") public List selectProProcessList(ProProcess proProcess) { return proProcessMapper.selectProProcessList(proProcess); @@ -71,6 +74,7 @@ public class ProProcessServiceImpl implements IProProcessService * @return */ @Override + @DS("#header.poolName") public Boolean checkProcessCodeUnique(ProProcess proProcess) { ProProcess process = proProcessMapper.checkProcessCodeUnique(proProcess); if(StringUtils.isNotNull(process) && !process.getProcessId().equals(proProcess.getProcessId())){ @@ -86,6 +90,7 @@ public class ProProcessServiceImpl implements IProProcessService * @return */ @Override + @DS("#header.poolName") public Boolean checkProcessNameUnique(ProProcess proProcess) { ProProcess process = proProcessMapper.checkProcessNameUnique(proProcess); @@ -102,6 +107,7 @@ public class ProProcessServiceImpl implements IProProcessService * @return 结果 */ @Override + @DS("#header.poolName") public int insertProProcess(ProProcess proProcess) { proProcess.setProcessId(IdUtils.fastSimpleUUID()); @@ -135,6 +141,7 @@ public class ProProcessServiceImpl implements IProProcessService * @return 结果 */ @Override + @DS("#header.poolName") public int updateProProcess(ProProcess proProcess) { @@ -168,6 +175,7 @@ public class ProProcessServiceImpl implements IProProcessService * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProProcessByProcessIds(String[] processIds) { return proProcessMapper.deleteProProcessByProcessIds(processIds); @@ -180,6 +188,7 @@ public class ProProcessServiceImpl implements IProProcessService * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProProcessByProcessId(String processId) { return proProcessMapper.deleteProProcessByProcessId(processId); diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteLineServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteLineServiceImpl.java new file mode 100644 index 00000000..13063604 --- /dev/null +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteLineServiceImpl.java @@ -0,0 +1,129 @@ +package com.op.mes.service.impl; + +import java.util.Date; +import java.util.List; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.op.common.core.utils.DateUtils; +import com.op.common.core.utils.uuid.IdUtils; +import com.op.common.security.utils.SecurityUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.op.mes.mapper.ProRouteLineMapper; +import com.op.mes.domain.ProRouteLine; +import com.op.mes.service.IProRouteLineService; + +/** + * 工艺线体关联Service业务层处理 + * + * @author Open Platform + * @date 2023-07-13 + */ +@Service +public class ProRouteLineServiceImpl implements IProRouteLineService { + @Autowired + private ProRouteLineMapper proRouteLineMapper; + + /** + * 查询工艺线体关联 + * + * @param recordId 工艺线体关联主键 + * @return 工艺线体关联 + */ + @Override + @DS("#header.poolName") + public ProRouteLine selectProRouteLineByRecordId(String recordId) { + return proRouteLineMapper.selectProRouteLineByRecordId(recordId); + } + + /** + * 查询工艺线体关联列表 + * + * @param proRouteLine 工艺线体关联 + * @return 工艺线体关联 + */ + @Override + @DS("#header.poolName") + public List selectProRouteLineList(ProRouteLine proRouteLine) { + return proRouteLineMapper.selectProRouteLineList(proRouteLine); + } + + /** + * 新增工艺线体关联 + * + * @param proRouteLine 工艺线体关联 + * @return 结果 + */ + @Override + @DS("#header.poolName") + public int insertProRouteLine(ProRouteLine proRouteLine) { + Date now = DateUtils.getNowDate(); + if(StringUtils.isNotBlank(proRouteLine.getRouteId())){ + //删除之前的关联关系 + proRouteLineMapper.deleteByRouteId(proRouteLine); + } + if(proRouteLine.getSelectedValues()!=null){ + ProRouteLine proRouteLineDto =null; + for(String lineCode:proRouteLine.getSelectedValues()){ + proRouteLineDto = new ProRouteLine(); + proRouteLineDto.setRecordId(IdUtils.fastSimpleUUID()); + proRouteLineDto.setCreateTime(now); + proRouteLineDto.setCreateBy(SecurityUtils.getUsername()); + proRouteLineDto.setRouteId(proRouteLine.getRouteId()); + proRouteLineDto.setItemCode(lineCode); + proRouteLineMapper.insertProRouteLine(proRouteLineDto); + } + } + //新增关联关系 + return 1; + } + + /** + * 修改工艺线体关联 + * + * @param proRouteLine 工艺线体关联 + * @return 结果 + */ + @Override + @DS("#header.poolName") + public int updateProRouteLine(ProRouteLine proRouteLine) { + proRouteLine.setUpdateTime(DateUtils.getNowDate()); + return proRouteLineMapper.updateProRouteLine(proRouteLine); + } + + /** + * 批量删除工艺线体关联 + * + * @param recordIds 需要删除的工艺线体关联主键 + * @return 结果 + */ + @Override + @DS("#header.poolName") + public int deleteProRouteLineByRecordIds(String[] recordIds) { + return proRouteLineMapper.deleteProRouteLineByRecordIds(recordIds); + } + + /** + * 删除工艺线体关联信息 + * + * @param recordId 工艺线体关联主键 + * @return 结果 + */ + @Override + @DS("#header.poolName") + public int deleteProRouteLineByRecordId(String recordId) { + return proRouteLineMapper.deleteProRouteLineByRecordId(recordId); + } + + @Override + @DS("#header.poolName") + public ProRouteLine getList(ProRouteLine proRouteLine) { + ProRouteLine dto = new ProRouteLine(); + List unSelected= proRouteLineMapper.getRouteProdLineListUndo(proRouteLine); + dto.setUnSelect(unSelected); + List selected= proRouteLineMapper.getRouteProdLineListDo(proRouteLine); + dto.setSelected(selected); + return dto; + } +} diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteProcessServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteProcessServiceImpl.java index b2be4646..96b1b01a 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteProcessServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteProcessServiceImpl.java @@ -3,6 +3,7 @@ package com.op.mes.service.impl; import java.util.List; import java.util.stream.Collectors; +import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.constant.UserConstants; import com.op.common.core.utils.DateUtils; import com.op.common.core.utils.StringUtils; @@ -37,6 +38,7 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService * @return 工艺组成 */ @Override + @DS("#header.poolName") public ProRouteProcess selectProRouteProcessByRecordId(String recordId) { return proRouteProcessMapper.selectProRouteProcessByRecordId(recordId); @@ -49,12 +51,14 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService * @return 工艺组成 */ @Override + @DS("#header.poolName") public List selectProRouteProcessList(ProRouteProcess proRouteProcess) { return proRouteProcessMapper.selectProRouteProcessList(proRouteProcess); } @Override + @DS("#header.poolName") public Boolean checkOrderNumExists(ProRouteProcess proRouteProcess) { ProRouteProcess process = proRouteProcessMapper.checkOrderNumExists(proRouteProcess); String recordId = proRouteProcess.getRecordId(); @@ -65,6 +69,7 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService } @Override + @DS("#header.poolName") public Boolean checkProcessExists(ProRouteProcess proRouteProcess) { ProRouteProcess process = proRouteProcessMapper.checkProcessExists(proRouteProcess); String recordId = proRouteProcess.getRecordId(); @@ -75,6 +80,7 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService } @Override + @DS("#header.poolName") public Boolean checkUpdateFlagUnique(ProRouteProcess proRouteProcess) { ProRouteProcess process = proRouteProcessMapper.checkUpdateFlagUnique(proRouteProcess); String recordId = proRouteProcess.getRecordId(); @@ -115,11 +121,13 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService // } @Override + @DS("#header.poolName") public ProRouteProcess findPreProcess(ProRouteProcess proRouteProcess) { return proRouteProcessMapper.findPreProcess(proRouteProcess); } @Override + @DS("#header.poolName") public ProRouteProcess findNextProcess(ProRouteProcess proRouteProcess) { return proRouteProcessMapper.findNextProcess(proRouteProcess); } @@ -131,6 +139,7 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService * @return 结果 */ @Override + @DS("#header.poolName") public int insertProRouteProcess(ProRouteProcess proRouteProcess) { proRouteProcess.setCreateTime(DateUtils.getNowDate()); @@ -145,6 +154,7 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService * @return 结果 */ @Override + @DS("#header.poolName") public int updateProRouteProcess(ProRouteProcess proRouteProcess) { proRouteProcess.setUpdateTime(DateUtils.getNowDate()); @@ -158,6 +168,7 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProRouteProcessByRecordIds(String[] recordIds) { return proRouteProcessMapper.deleteProRouteProcessByRecordIds(recordIds); @@ -170,12 +181,14 @@ public class ProRouteProcessServiceImpl implements IProRouteProcessService * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProRouteProcessByRecordId(String recordId) { return proRouteProcessMapper.deleteProRouteProcessByRecordId(recordId); } @Override + @DS("#header.poolName") public int deleteByRouteId(String routeId) { return proRouteProcessMapper.deleteByRouteId(routeId); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteServiceImpl.java index 958bff26..cf28fd9c 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/ProRouteServiceImpl.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.constant.UserConstants; import com.op.common.core.domain.BaseFileData; import com.op.common.core.utils.DateUtils; @@ -41,6 +42,7 @@ public class ProRouteServiceImpl implements IProRouteService * @return 工艺路线 */ @Override + @DS("#header.poolName") public ProRoute selectProRouteByRouteId(String routeId) { @@ -59,6 +61,7 @@ public class ProRouteServiceImpl implements IProRouteService * @return 工艺路线 */ @Override + @DS("#header.poolName") public List selectProRouteList(ProRoute proRoute) { return proRouteMapper.selectProRouteList(proRoute); @@ -71,6 +74,7 @@ public class ProRouteServiceImpl implements IProRouteService @Override + @DS("#header.poolName") public Boolean checkRouteCodeUnique(ProRoute proRoute) { ProRoute route = proRouteMapper.checkRouteCodeUnique(proRoute); String routeId = proRoute.getRouteId(); @@ -87,6 +91,7 @@ public class ProRouteServiceImpl implements IProRouteService * @return 结果 */ @Override + @DS("#header.poolName") public int insertProRoute(ProRoute proRoute) { proRoute.setCreateTime(DateUtils.getNowDate()); @@ -119,6 +124,7 @@ public class ProRouteServiceImpl implements IProRouteService * @return 结果 */ @Override + @DS("#header.poolName") public int updateProRoute(ProRoute proRoute) { proRoute.setUpdateTime(DateUtils.getNowDate()); @@ -158,6 +164,7 @@ public class ProRouteServiceImpl implements IProRouteService * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProRouteByRouteIds(String[] routeIds) { return proRouteMapper.deleteProRouteByRouteIds(routeIds); @@ -170,6 +177,7 @@ public class ProRouteServiceImpl implements IProRouteService * @return 结果 */ @Override + @DS("#header.poolName") public int deleteProRouteByRouteId(String routeId) { return proRouteMapper.deleteProRouteByRouteId(routeId); diff --git a/op-modules/op-mes/src/main/resources/mapper/mes/ProOrderMapper.xml b/op-modules/op-mes/src/main/resources/mapper/mes/ProOrderMapper.xml index e4c7781e..766646ef 100644 --- a/op-modules/op-mes/src/main/resources/mapper/mes/ProOrderMapper.xml +++ b/op-modules/op-mes/src/main/resources/mapper/mes/ProOrderMapper.xml @@ -6,6 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -30,15 +31,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, factory_code, order_type, order_code, prod_code, prod_desc, quantity, quantity_split + select id, plan_factory_code, order_type, order_code, prod_code, prod_desc, quantity, quantity_split unit, worker_order, plan_pro_date, plan_complete, atrr1, atrr2, atrr3, - status, parent_order, create_by, create_time, update_by, update_time, prod_type + status, parent_order, create_by, create_time, update_by, update_time, prod_type, + factory_code from pro_order + + + and route_id = #{routeId} + and item_id = #{itemId} + and item_code = #{itemCode} + and item_name like concat('%', #{itemName}, '%') + and attr1 = #{attr1} + and attr2 = #{attr2} + and attr3 = #{attr3} + and attr4 = #{attr4} + + + + + + + + + insert into pro_route_line + + record_id, + route_id, + item_id, + item_code, + item_name, + remark, + attr1, + attr2, + attr3, + attr4, + create_by, + create_time, + update_by, + update_time, + + + #{recordId}, + #{routeId}, + #{itemId}, + #{itemCode}, + #{itemName}, + #{remark}, + #{attr1}, + #{attr2}, + #{attr3}, + #{attr4}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update pro_route_line + + route_id = #{routeId}, + item_id = #{itemId}, + item_code = #{itemCode}, + item_name = #{itemName}, + remark = #{remark}, + attr1 = #{attr1}, + attr2 = #{attr2}, + attr3 = #{attr3}, + attr4 = #{attr4}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where record_id = #{recordId} + + + + delete from pro_route_line where record_id = #{recordId} + + + + delete from pro_route_line where record_id in + + #{recordId} + + + + delete from pro_route_line where route_id = #{routeId} + + diff --git a/op-modules/op-sap/op-modules-sap.iml b/op-modules/op-sap/op-modules-sap.iml new file mode 100644 index 00000000..085e0bc9 --- /dev/null +++ b/op-modules/op-sap/op-modules-sap.iml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/op-modules/op-sap/src/main/lib/sapjco3.jar b/op-modules/op-sap/src/main/lib/sapjco3.jar new file mode 100644 index 00000000..8f123918 Binary files /dev/null and b/op-modules/op-sap/src/main/lib/sapjco3.jar differ diff --git a/op-modules/op-sap/src/main/resources/bootstrap.yml b/op-modules/op-sap/src/main/resources/bootstrap.yml index 77a2432a..736f5ce6 100644 --- a/op-modules/op-sap/src/main/resources/bootstrap.yml +++ b/op-modules/op-sap/src/main/resources/bootstrap.yml @@ -13,13 +13,13 @@ spring: cloud: nacos: discovery: - namespace: haiwei-test - group: ywl + namespace: lanju-op + group: zxl # 服务注册地址 server-addr: 140.249.53.142:8848 config: - namespace: haiwei-test - group: ywl + namespace: lanju-op + group: zxl #命名空间 #group: local # 配置中心地址 diff --git a/op-modules/op-system/src/main/java/com/op/system/config/DynamicDatasource.java b/op-modules/op-system/src/main/java/com/op/system/config/DynamicDatasource.java new file mode 100644 index 00000000..87590456 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/config/DynamicDatasource.java @@ -0,0 +1,47 @@ +package com.op.system.config; + +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; +import com.op.common.datasource.creator.DynamicDatasourceCreator; +import com.op.system.api.domain.SysUser; +import com.op.system.service.ISysUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * 初始化动态数据源 + * + * @ClassName: DynamicDatasource + * @Description: TODO + * @author shichangzhou + * @date 2023年4月19日 下午1:01:30 + */ +@Component +public class DynamicDatasource { + + @Resource + private DynamicDatasourceCreator dynamicDatasourceCreator; + @Autowired + private ISysUserService sysUserService; + + @PostConstruct + public void init() { + SysUser sysUser = new SysUser(); + sysUser.setUserId(1L); + List> dateSources = sysUserService.getPoolNameList(sysUser); + for (Map dateSource : dateSources) { + DataSourceProperty sdp = new DataSourceProperty(); + sdp.setUrl(dateSource.get("url")); + sdp.setUsername(dateSource.get("userName")); + sdp.setPassword(dateSource.get("password")); + sdp.setDriverClassName(dateSource.get("driveClassName")); + sdp.setPoolName(dateSource.get("poolName"));// 这是数据源的key + sdp.setLazy(false); + dynamicDatasourceCreator.createDynamicDataSource(sdp); + } + } +} diff --git a/op-modules/op-system/src/main/java/com/op/system/controller/SysDatasourceController.java b/op-modules/op-system/src/main/java/com/op/system/controller/SysDatasourceController.java new file mode 100644 index 00000000..cca59759 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/controller/SysDatasourceController.java @@ -0,0 +1,155 @@ +package com.op.system.controller; + +import com.op.common.core.utils.poi.ExcelUtil; +import com.op.common.core.web.controller.BaseController; +import com.op.common.core.web.domain.AjaxResult; +import com.op.common.core.web.page.TableDataInfo; +import com.op.common.log.annotation.Log; +import com.op.common.log.enums.BusinessType; +import com.op.common.security.annotation.RequiresPermissions; +import com.op.system.api.domain.SysUser; +import com.op.system.domain.SysDatasource; +import com.op.system.service.ISysDatasourceService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 工厂数据库Controller + * + * @author sf + * @date 2023-05-18 + */ +@RestController +@RequestMapping("/datasource") +public class SysDatasourceController extends BaseController { + @Autowired + private ISysDatasourceService sysDatasourceService; + + /** + * 查询工厂数据库列表 + */ + @RequiresPermissions("system:datasource:list") + @GetMapping("/list") + public TableDataInfo list(SysDatasource sysDatasource) { + startPage(); + List list = sysDatasourceService.selectSysDatasourceList(sysDatasource); + return getDataTable(list); + } + + /** + * 导出工厂数据库列表 + */ + @RequiresPermissions("system:datasource:export") + @Log(title = "工厂数据库", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, SysDatasource sysDatasource) { + List list = sysDatasourceService.selectSysDatasourceList(sysDatasource); + ExcelUtil util = new ExcelUtil(SysDatasource.class); + util.exportExcel(response, list, "工厂数据库数据"); + } + + /** + * 获取工厂数据库详细信息 + */ + @RequiresPermissions("system:datasource:query") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") String id) { + return success(sysDatasourceService.selectSysDatasourceById(id)); + } + + /** + * 新增工厂数据库 + */ + @RequiresPermissions("system:datasource:add") + @Log(title = "工厂数据库", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody SysDatasource sysDatasource) { + return toAjax(sysDatasourceService.insertSysDatasource(sysDatasource)); + } + + /** + * 修改工厂数据库 + */ + @RequiresPermissions("system:datasource:edit") + @Log(title = "工厂数据库", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody SysDatasource sysDatasource) { + return toAjax(sysDatasourceService.updateSysDatasource(sysDatasource)); + } + + /** + * 删除工厂数据库 + */ + @RequiresPermissions("system:datasource:remove") + @Log(title = "工厂数据库", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable String[] ids) { + return toAjax(sysDatasourceService.deleteSysDatasourceByIds(ids)); + } + + /** + * 查询已分配用户角色列表 + */ + @RequiresPermissions("system:datasource:edit") + @GetMapping("/authUser/allocatedList") + public TableDataInfo allocatedList(SysDatasource sysDatasource) { + startPage(); + List list = sysDatasourceService.selectAllocatedList(sysDatasource); + return getDataTable(list); + } + + /** + * 查询未分配用户角色列表 + */ + //@RequiresPermissions("system:role:list") + @GetMapping("/authUser/unallocatedList") + public TableDataInfo unallocatedList(SysUser user) { + startPage(); + List list = sysDatasourceService.selectUnallocatedList(user); + return getDataTable(list); + } + + /** + * 批量选择用户授权 + */ + //@RequiresPermissions("system:role:edit") + @Log(title = "数据源管理", businessType = BusinessType.GRANT) + @PutMapping("/authUser/selectAll") + public AjaxResult selectAuthUserAll(String datasourceId, Long[] userIds) { + //sysDatasourceService.checkRoleDataScope(datasourceId); + return toAjax(sysDatasourceService.insertAuthUsers(datasourceId, userIds)); + } + + /** + * 取消授权用户 + */ + //@RequiresPermissions("system:role:edit") + @Log(title = "数据源管理", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancel") + public AjaxResult cancelAuthUser(@RequestBody SysDatasource sysDatasource) { + return toAjax(sysDatasourceService.deleteAuthUser(sysDatasource)); + } + + /** + * 批量取消授权用户 + */ + //@RequiresPermissions("system:role:edit") + @Log(title = "角色管理", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancelAll") + public AjaxResult cancelAuthUserAll(String datasourceId, Long[] userIds) { + return toAjax(sysDatasourceService.deleteAuthUsers(datasourceId, userIds)); + } + + @RequiresPermissions("system:datasource:add") + @Log(title = "激活工厂数据库", businessType = BusinessType.UPDATE) + @GetMapping("/changeDBStatus/{datasourceId}") + public AjaxResult changeDBStatus(@PathVariable("datasourceId") String datasourceId) { + SysDatasource sysDatasource = new SysDatasource(); + sysDatasource.setDatasourceId(datasourceId); + return success(sysDatasourceService.changeDBStatus(sysDatasource)); + } + +} diff --git a/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java b/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java index 68f211f2..d203d999 100644 --- a/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java +++ b/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java @@ -2,11 +2,16 @@ package com.op.system.controller; import java.io.IOException; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; + import javax.servlet.http.HttpServletResponse; + import org.apache.commons.lang3.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -17,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; + +import com.op.common.core.constant.CacheConstants; import com.op.common.core.domain.R; import com.op.common.core.utils.StringUtils; import com.op.common.core.utils.poi.ExcelUtil; @@ -25,6 +32,7 @@ import com.op.common.core.web.domain.AjaxResult; import com.op.common.core.web.page.TableDataInfo; import com.op.common.log.annotation.Log; import com.op.common.log.enums.BusinessType; +import com.op.common.redis.service.RedisService; import com.op.common.security.annotation.InnerAuth; import com.op.common.security.annotation.RequiresPermissions; import com.op.common.security.utils.SecurityUtils; @@ -41,8 +49,8 @@ import com.op.system.service.ISysUserService; /** * 用户信息 - * - * @author OP + * + * @author sf */ @RestController @RequestMapping("/user") @@ -64,6 +72,8 @@ public class SysUserController extends BaseController { @Autowired private ISysConfigService configService; + @Autowired + private RedisService redisService; /** * 获取用户列表 @@ -103,7 +113,7 @@ public class SysUserController extends BaseController { } /** - * 获取当前用户信息 + * 获取当前用户信息,登录用的 */ @InnerAuth @GetMapping("/info/{username}") @@ -116,10 +126,15 @@ public class SysUserController extends BaseController { Set roles = permissionService.getRolePermission(sysUser); // 权限集合 Set permissions = permissionService.getMenuPermission(sysUser); + // 工厂数据源集合 + List> poolNameList = permissionService.getPoolNameList(sysUser); LoginUser sysUserVo = new LoginUser(); sysUserVo.setSysUser(sysUser); sysUserVo.setRoles(roles); sysUserVo.setPermissions(permissions); + if (!CollectionUtils.isEmpty(poolNameList)) { + sysUserVo.setPoolName(poolNameList.get(0).get("poolName")); + } return R.ok(sysUserVo); } @@ -140,8 +155,8 @@ public class SysUserController extends BaseController { } /** - * 获取用户信息 - * + * 获取用户信息,首页用的 + * * @return 用户信息 */ @GetMapping("getInfo") @@ -151,10 +166,16 @@ public class SysUserController extends BaseController { Set roles = permissionService.getRolePermission(user); // 权限集合 Set permissions = permissionService.getMenuPermission(user); + // 工厂数据源集合 + List> poolNameList = permissionService.getPoolNameList(user); + // 缓存用户工厂数据源 + String poolName = redisService.getCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + user.getUserName()); + user.setPoolName(poolName); AjaxResult ajax = AjaxResult.success(); ajax.put("user", user); ajax.put("roles", roles); ajax.put("permissions", permissions); + ajax.put("poolNameList", poolNameList); return ajax; } @@ -291,6 +312,25 @@ public class SysUserController extends BaseController { @RequiresPermissions("system:user:list") @GetMapping("/deptTree") public AjaxResult deptTree(SysDept dept) { + return success(deptService.selectDeptTreeList(dept)); } + + /** + * 变更工厂数据源 + */ + @RequiresPermissions("system:user:changePoolName") + @PutMapping("/changePoolName") + public AjaxResult changePoolName(@RequestBody SysUser user) { + String username = SecurityUtils.getUsername(); + // 缓存用户工厂数据源 + redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, user.getPoolName(), + CacheConstants.REFRESH_TIME, TimeUnit.MINUTES); + return success(); + } + + @PostMapping("/getPoolNameList") + public R>> getPoolNameLis(@RequestBody SysUser user) { + return R.ok(userService.getPoolNameList(user)); + } } diff --git a/op-modules/op-system/src/main/java/com/op/system/domain/SysDatasource.java b/op-modules/op-system/src/main/java/com/op/system/domain/SysDatasource.java new file mode 100644 index 00000000..5df9a859 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/domain/SysDatasource.java @@ -0,0 +1,240 @@ +package com.op.system.domain; + +import com.op.common.core.annotation.Excel; +import com.op.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 工厂数据库对象 sys_datasource + * + * @author sf + * @date 2023-05-18 + */ +public class SysDatasource extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键 */ + private String id; + + /** 地址 */ + @Excel(name = "地址") + private String url; + + /** ip:端口 */ + @Excel(name = "ip:端口") + private String ipPort; + + /** 用户名 */ + @Excel(name = "用户名") + private String userName; + + /** 密码 */ + @Excel(name = "密码") + private String password; + + /** 驱动 */ + @Excel(name = "驱动") + private String driveClassName; + + /** 数据源标识 */ + @Excel(name = "数据源标识") + private String poolName; + + /** 数据源名称 */ + @Excel(name = "数据源名称") + private String parkName; + + /** 帐号状态(0正常 */ + @Excel(name = "帐号状态", readConverterExp = "帐号状态(0正常") + private String status; + + /** 删除标志(0代表存在 */ + private String delFlag; + + /** 数据所属部门 */ + @Excel(name = "数据所属部门") + private Long deptId; + private String deptName; + + /** 0未创建 */ + @Excel(name = "0未创建") + private String schemaCreated; + private String datasourceId; + private String userId; + private String nickName; + private String systemType; + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getSystemType() { + return systemType; + } + + public void setSystemType(String systemType) { + this.systemType = systemType; + } + + public String getDatasourceId() { + return datasourceId; + } + + public void setDatasourceId(String datasourceId) { + this.datasourceId = datasourceId; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + + public void setId(String id) + { + this.id = id; + } + + public String getId() + { + return id; + } + public void setUrl(String url) + { + this.url = url; + } + + public String getUrl() + { + return url; + } + public void setIpPort(String ipPort) + { + this.ipPort = ipPort; + } + + public String getIpPort() + { + return ipPort; + } + public void setUserName(String userName) + { + this.userName = userName; + } + + public String getUserName() + { + return userName; + } + public void setPassword(String password) + { + this.password = password; + } + + public String getPassword() + { + return password; + } + public void setDriveClassName(String driveClassName) + { + this.driveClassName = driveClassName; + } + + public String getDriveClassName() + { + return driveClassName; + } + public void setPoolName(String poolName) + { + this.poolName = poolName; + } + + public String getPoolName() + { + return poolName; + } + public void setParkName(String parkName) + { + this.parkName = parkName; + } + + public String getParkName() + { + return parkName; + } + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + public void setDelFlag(String delFlag) + { + this.delFlag = delFlag; + } + + public String getDelFlag() + { + return delFlag; + } + public void setDeptId(Long deptId) + { + this.deptId = deptId; + } + + public Long getDeptId() + { + return deptId; + } + public void setSchemaCreated(String schemaCreated) + { + this.schemaCreated = schemaCreated; + } + + public String getSchemaCreated() + { + return schemaCreated; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("url", getUrl()) + .append("ipPort", getIpPort()) + .append("userName", getUserName()) + .append("password", getPassword()) + .append("driveClassName", getDriveClassName()) + .append("poolName", getPoolName()) + .append("parkName", getParkName()) + .append("status", getStatus()) + .append("delFlag", getDelFlag()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .append("deptId", getDeptId()) + .append("schemaCreated", getSchemaCreated()) + .toString(); + } +} diff --git a/op-modules/op-system/src/main/java/com/op/system/mapper/SysDatasourceMapper.java b/op-modules/op-system/src/main/java/com/op/system/mapper/SysDatasourceMapper.java new file mode 100644 index 00000000..a86c4f10 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/mapper/SysDatasourceMapper.java @@ -0,0 +1,78 @@ +package com.op.system.mapper; + +import com.op.system.api.domain.SysUser; +import com.op.system.domain.SysDatasource; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 工厂数据库Mapper接口 + * + * @author sf + * @date 2023-05-18 + */ +@Mapper +public interface SysDatasourceMapper +{ + /** + * 查询工厂数据库 + * + * @param id 工厂数据库主键 + * @return 工厂数据库 + */ + public SysDatasource selectSysDatasourceById(String id); + + /** + * 查询工厂数据库列表 + * + * @param sysDatasource 工厂数据库 + * @return 工厂数据库集合 + */ + public List selectSysDatasourceList(SysDatasource sysDatasource); + + /** + * 新增工厂数据库 + * + * @param sysDatasource 工厂数据库 + * @return 结果 + */ + public int insertSysDatasource(SysDatasource sysDatasource); + + /** + * 修改工厂数据库 + * + * @param sysDatasource 工厂数据库 + * @return 结果 + */ + public int updateSysDatasource(SysDatasource sysDatasource); + + /** + * 删除工厂数据库 + * + * @param id 工厂数据库主键 + * @return 结果 + */ + public int deleteSysDatasourceById(String id); + + /** + * 批量删除工厂数据库 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSysDatasourceByIds(String[] ids); + + List selectAllocatedList(SysDatasource sysDatasource); + + List selectUnallocatedList(SysUser user); + + int batchUserDB(List list); + + int deleteUserRoleInfo(SysDatasource sysDatasource); + + int deleteUserRoleInfos(@Param("datasourceId") String datasourceId, @Param("userIds") Long[] userIds); + + List selectDBListByDept(SysDatasource qo); +} diff --git a/op-modules/op-system/src/main/java/com/op/system/mapper/SysUserMapper.java b/op-modules/op-system/src/main/java/com/op/system/mapper/SysUserMapper.java index 63ce4674..1bbc40c9 100644 --- a/op-modules/op-system/src/main/java/com/op/system/mapper/SysUserMapper.java +++ b/op-modules/op-system/src/main/java/com/op/system/mapper/SysUserMapper.java @@ -1,18 +1,20 @@ package com.op.system.mapper; import java.util.List; +import java.util.Map; + import org.apache.ibatis.annotations.Param; import com.op.system.api.domain.SysUser; /** * 用户表 数据层 - * + * * @author OP */ public interface SysUserMapper { /** * 根据条件分页查询用户列表 - * + * * @param sysUser 用户信息 * @return 用户信息集合信息 */ @@ -20,7 +22,7 @@ public interface SysUserMapper { /** * 根据条件分页查询已配用户角色列表 - * + * * @param user 用户信息 * @return 用户信息集合信息 */ @@ -28,7 +30,7 @@ public interface SysUserMapper { /** * 根据条件分页查询未分配用户角色列表 - * + * * @param user 用户信息 * @return 用户信息集合信息 */ @@ -36,7 +38,7 @@ public interface SysUserMapper { /** * 通过用户名查询用户 - * + * * @param userName 用户名 * @return 用户对象信息 */ @@ -44,7 +46,7 @@ public interface SysUserMapper { /** * 通过用户ID查询用户 - * + * * @param userId 用户ID * @return 用户对象信息 */ @@ -52,7 +54,7 @@ public interface SysUserMapper { /** * 新增用户信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -60,7 +62,7 @@ public interface SysUserMapper { /** * 修改用户信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -68,7 +70,7 @@ public interface SysUserMapper { /** * 修改用户头像 - * + * * @param userName 用户名 * @param avatar 头像地址 * @return 结果 @@ -77,7 +79,7 @@ public interface SysUserMapper { /** * 重置用户密码 - * + * * @param userName 用户名 * @param password 密码 * @return 结果 @@ -86,7 +88,7 @@ public interface SysUserMapper { /** * 通过用户ID删除用户 - * + * * @param userId 用户ID * @return 结果 */ @@ -94,7 +96,7 @@ public interface SysUserMapper { /** * 批量删除用户信息 - * + * * @param userIds 需要删除的用户ID * @return 结果 */ @@ -102,7 +104,7 @@ public interface SysUserMapper { /** * 校验用户名称是否唯一 - * + * * @param userName 用户名称 * @return 结果 */ @@ -123,4 +125,6 @@ public interface SysUserMapper { * @return 结果 */ public SysUser checkEmailUnique(String email); + + public List> getPoolNameList(SysUser user); } diff --git a/op-modules/op-system/src/main/java/com/op/system/service/ISysDatasourceService.java b/op-modules/op-system/src/main/java/com/op/system/service/ISysDatasourceService.java new file mode 100644 index 00000000..09b205ab --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/service/ISysDatasourceService.java @@ -0,0 +1,77 @@ +package com.op.system.service; + +import com.op.system.api.domain.SysUser; +import com.op.system.domain.SysDatasource; + +import java.util.List; + +/** + * 工厂数据库Service接口 + * + * @author sf + * @date 2023-05-18 + */ +public interface ISysDatasourceService +{ + /** + * 查询工厂数据库 + * + * @param id 工厂数据库主键 + * @return 工厂数据库 + */ + public SysDatasource selectSysDatasourceById(String id); + + /** + * 查询工厂数据库列表 + * + * @param sysDatasource 工厂数据库 + * @return 工厂数据库集合 + */ + public List selectSysDatasourceList(SysDatasource sysDatasource); + + /** + * 新增工厂数据库 + * + * @param sysDatasource 工厂数据库 + * @return 结果 + */ + public int insertSysDatasource(SysDatasource sysDatasource); + + /** + * 修改工厂数据库 + * + * @param sysDatasource 工厂数据库 + * @return 结果 + */ + public int updateSysDatasource(SysDatasource sysDatasource); + + /** + * 批量删除工厂数据库 + * + * @param ids 需要删除的工厂数据库主键集合 + * @return 结果 + */ + public int deleteSysDatasourceByIds(String[] ids); + + /** + * 删除工厂数据库信息 + * + * @param id 工厂数据库主键 + * @return 结果 + */ + public int deleteSysDatasourceById(String id); + + List selectAllocatedList(SysDatasource sysDatasource); + + List selectUnallocatedList(SysUser user); + + void checkRoleDataScope(String datasourceId); + + int insertAuthUsers(String datasourceId, Long[] userIds); + + int deleteAuthUser(SysDatasource sysDatasource); + + int deleteAuthUsers(String datasourceId, Long[] userIds); + + String changeDBStatus(SysDatasource sysDatasource); +} diff --git a/op-modules/op-system/src/main/java/com/op/system/service/ISysPermissionService.java b/op-modules/op-system/src/main/java/com/op/system/service/ISysPermissionService.java index c8f68078..bf831458 100644 --- a/op-modules/op-system/src/main/java/com/op/system/service/ISysPermissionService.java +++ b/op-modules/op-system/src/main/java/com/op/system/service/ISysPermissionService.java @@ -1,18 +1,20 @@ package com.op.system.service; +import java.util.List; +import java.util.Map; import java.util.Set; import com.op.system.api.domain.SysUser; /** * 权限信息 服务层 - * + * * @author OP */ public interface ISysPermissionService { /** * 获取角色数据权限 - * + * * @param userId 用户Id * @return 角色权限信息 */ @@ -20,9 +22,12 @@ public interface ISysPermissionService { /** * 获取菜单数据权限 - * + * * @param userId 用户Id * @return 菜单权限信息 */ public Set getMenuPermission(SysUser user); + + // 用户工厂数据源 + public List> getPoolNameList(SysUser sysUser); } diff --git a/op-modules/op-system/src/main/java/com/op/system/service/ISysUserService.java b/op-modules/op-system/src/main/java/com/op/system/service/ISysUserService.java index 40c90d43..f735786a 100644 --- a/op-modules/op-system/src/main/java/com/op/system/service/ISysUserService.java +++ b/op-modules/op-system/src/main/java/com/op/system/service/ISysUserService.java @@ -1,17 +1,19 @@ package com.op.system.service; import java.util.List; +import java.util.Map; + import com.op.system.api.domain.SysUser; /** * 用户 业务层 - * + * * @author OP */ public interface ISysUserService { /** * 根据条件分页查询用户列表 - * + * * @param user 用户信息 * @return 用户信息集合信息 */ @@ -19,7 +21,7 @@ public interface ISysUserService { /** * 根据条件分页查询已分配用户角色列表 - * + * * @param user 用户信息 * @return 用户信息集合信息 */ @@ -27,7 +29,7 @@ public interface ISysUserService { /** * 根据条件分页查询未分配用户角色列表 - * + * * @param user 用户信息 * @return 用户信息集合信息 */ @@ -35,7 +37,7 @@ public interface ISysUserService { /** * 通过用户名查询用户 - * + * * @param userName 用户名 * @return 用户对象信息 */ @@ -43,7 +45,7 @@ public interface ISysUserService { /** * 通过用户ID查询用户 - * + * * @param userId 用户ID * @return 用户对象信息 */ @@ -51,7 +53,7 @@ public interface ISysUserService { /** * 根据用户ID查询用户所属角色组 - * + * * @param userName 用户名 * @return 结果 */ @@ -59,7 +61,7 @@ public interface ISysUserService { /** * 根据用户ID查询用户所属岗位组 - * + * * @param userName 用户名 * @return 结果 */ @@ -67,7 +69,7 @@ public interface ISysUserService { /** * 校验用户名称是否唯一 - * + * * @param user 用户信息 * @return 结果 */ @@ -91,21 +93,21 @@ public interface ISysUserService { /** * 校验用户是否允许操作 - * + * * @param user 用户信息 */ public void checkUserAllowed(SysUser user); /** * 校验用户是否有数据权限 - * + * * @param userId 用户id */ public void checkUserDataScope(Long userId); /** * 新增用户信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -113,7 +115,7 @@ public interface ISysUserService { /** * 注册用户信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -121,7 +123,7 @@ public interface ISysUserService { /** * 修改用户信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -129,7 +131,7 @@ public interface ISysUserService { /** * 用户授权角色 - * + * * @param userId 用户ID * @param roleIds 角色组 */ @@ -137,7 +139,7 @@ public interface ISysUserService { /** * 修改用户状态 - * + * * @param user 用户信息 * @return 结果 */ @@ -145,7 +147,7 @@ public interface ISysUserService { /** * 修改用户基本信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -153,7 +155,7 @@ public interface ISysUserService { /** * 修改用户头像 - * + * * @param userName 用户名 * @param avatar 头像地址 * @return 结果 @@ -162,7 +164,7 @@ public interface ISysUserService { /** * 重置用户密码 - * + * * @param user 用户信息 * @return 结果 */ @@ -170,7 +172,7 @@ public interface ISysUserService { /** * 重置用户密码 - * + * * @param userName 用户名 * @param password 密码 * @return 结果 @@ -179,7 +181,7 @@ public interface ISysUserService { /** * 通过用户ID删除用户 - * + * * @param userId 用户ID * @return 结果 */ @@ -187,7 +189,7 @@ public interface ISysUserService { /** * 批量删除用户信息 - * + * * @param userIds 需要删除的用户ID * @return 结果 */ @@ -195,11 +197,15 @@ public interface ISysUserService { /** * 导入用户数据 - * + * * @param userList 用户数据列表 * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 * @param operName 操作用户 * @return 结果 */ public String importUser(List userList, Boolean isUpdateSupport, String operName); + + // 查询用户可见数据源 + public List> getPoolNameList(SysUser user); + } diff --git a/op-modules/op-system/src/main/java/com/op/system/service/impl/SysDatasourceServiceImpl.java b/op-modules/op-system/src/main/java/com/op/system/service/impl/SysDatasourceServiceImpl.java new file mode 100644 index 00000000..2152e978 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/service/impl/SysDatasourceServiceImpl.java @@ -0,0 +1,224 @@ +package com.op.system.service.impl; + +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; +import com.op.common.core.utils.DateUtils; +import com.op.common.core.utils.StringUtils; +import com.op.common.core.utils.uuid.IdUtils; +import com.op.common.datasource.creator.DynamicDatasourceCreator; +import com.op.system.api.domain.SysUser; +import com.op.system.domain.SysDatasource; +import com.op.system.mapper.SysDatasourceMapper; +import com.op.system.service.ISysDatasourceService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * 工厂数据库Service业务层处理 + * + * @author sf + * @date 2023-05-18 + */ +@Service +public class SysDatasourceServiceImpl implements ISysDatasourceService { + private static final Logger log = LoggerFactory.getLogger(SysDatasourceServiceImpl.class); + @Autowired + private SysDatasourceMapper sysDatasourceMapper; + @Value("${sqlserve.prev}") + private String mysqlPrev; + @Value("${sqlserve.affter}") + private String mysqlAffter; + @Value("${sqlserve.poolName.prev}") + private String poolNamePrev; + @Value("${sqlserve.driver}") + private String driver; + @Resource + private DynamicDatasourceCreator dynamicDatasourceCreator; + + /** + * 查询工厂数据库 + * + * @param id 工厂数据库主键 + * @return 工厂数据库 + */ + @Override + public SysDatasource selectSysDatasourceById(String id) { + return sysDatasourceMapper.selectSysDatasourceById(id); + } + + /** + * 查询工厂数据库列表 + * + * @param sysDatasource 工厂数据库 + * @return 工厂数据库 + */ + @Override + public List selectSysDatasourceList(SysDatasource sysDatasource) { + return sysDatasourceMapper.selectSysDatasourceList(sysDatasource); + } + + /** + * 新增工厂数据库 + * + * @param sysDatasource 工厂数据库 + * @return 结果 + */ + @Override + public int insertSysDatasource(SysDatasource sysDatasource) { + sysDatasource.setCreateTime(DateUtils.getNowDate()); + sysDatasource.setId(IdUtils.randomUUID().replace("-","")); + sysDatasource.setDriveClassName(driver); + if(StringUtils.isNotEmpty(sysDatasource.getIpPort())){ + sysDatasource.setUrl(mysqlPrev+sysDatasource.getIpPort().split("/")[0] + +mysqlAffter+sysDatasource.getIpPort().split("/")[1]); + } + if(sysDatasource.getDeptId()!=null){ + if(StringUtils.isNotEmpty(sysDatasource.getSystemType())){ + sysDatasource.setPoolName(poolNamePrev+"_"+sysDatasource.getSystemType()+"_"+sysDatasource.getDeptId()); + }else{ + sysDatasource.setPoolName(poolNamePrev+"_"+sysDatasource.getDeptId()); + } + } + + return sysDatasourceMapper.insertSysDatasource(sysDatasource); + } + + /** + * 修改工厂数据库 + * + * @param sysDatasource 工厂数据库 + * @return 结果 + */ + @Override + public int updateSysDatasource(SysDatasource sysDatasource) { + + //修改之后status->1 不生效,需要重新测试链接才生效 + sysDatasource.setStatus("1"); + sysDatasource.setUpdateTime(DateUtils.getNowDate()); + return sysDatasourceMapper.updateSysDatasource(sysDatasource); + } + + /** + * 批量删除工厂数据库 + * + * @param ids 需要删除的工厂数据库主键 + * @return 结果 + */ + @Override + public int deleteSysDatasourceByIds(String[] ids) { + return sysDatasourceMapper.deleteSysDatasourceByIds(ids); + } + + /** + * 删除工厂数据库信息 + * + * @param id 工厂数据库主键 + * @return 结果 + */ + @Override + public int deleteSysDatasourceById(String id) { + return sysDatasourceMapper.deleteSysDatasourceById(id); + } + + @Override + public List selectAllocatedList(SysDatasource sysDatasource) { + return sysDatasourceMapper.selectAllocatedList(sysDatasource); + } + + @Override + public List selectUnallocatedList(SysUser user) { + return sysDatasourceMapper.selectUnallocatedList(user); + } + + @Override + public void checkRoleDataScope(String datasourceId) { +// if (!SysUser.isAdmin(SecurityUtils.getUserId())) { +// SysRole role = new SysRole(); +// role.setRoleId(roleId); +// List roles = SpringUtils.getAopProxy(this).selectRoleList(role); +// if (StringUtils.isEmpty(roles)) { +// throw new ServiceException("没有权限访问角色数据!"); +// } +// } + } + + @Override + public int insertAuthUsers(String datasourceId, Long[] userIds) { + // 新增用户与数据源管理 + List list = new ArrayList(); + for (Long userId : userIds) { + SysDatasource ur = new SysDatasource(); + ur.setUserId(userId.toString()); + ur.setDatasourceId(datasourceId.toString()); + list.add(ur); + } + return sysDatasourceMapper.batchUserDB(list); + } + + @Override + public int deleteAuthUser(SysDatasource sysDatasource) { + return sysDatasourceMapper.deleteUserRoleInfo(sysDatasource); + } + + @Override + public int deleteAuthUsers(String datasourceId, Long[] userIds) { + return sysDatasourceMapper.deleteUserRoleInfos(datasourceId, userIds); + } + + @Override + public String changeDBStatus(SysDatasource sd) { + + SysDatasource sysDatasource = sysDatasourceMapper.selectSysDatasourceById(sd.getDatasourceId()); + + if(sysDatasource == null){ + return "数据库链接不存在"; + } + try { + Class.forName(sysDatasource.getDriveClassName()); + Connection conn = DriverManager.getConnection(sysDatasource.getUrl(), + sysDatasource.getUserName(), + sysDatasource.getPassword()); + if (conn != null) { + if (conn.isClosed()) { + log.error("[{}]数据库连接检测异常:[{}]",sysDatasource.getPoolName()); + return "数据库链接异常,请检查数据库基本信息。";//假如打不开数据库链接则跳过初始化数据库 + } else { + //说明数据库可以正常连接,关闭测试连接 + conn.close(); + log.info("[{}]数据库连接检测正常", sysDatasource.getPoolName()); + } + } else { + log.error("[{}]数据库连接检测异常:[{}]", sysDatasource.getPoolName()); + return "数据库链接异常,请检查数据库基本信息。"; + } + + sysDatasource.setUpdateTime(DateUtils.getNowDate()); + sysDatasource.setStatus("0");//激活 + sysDatasourceMapper.updateSysDatasource(sysDatasource); + + DataSourceProperty dataSourceProperty = new DataSourceProperty(); + dataSourceProperty.setUrl(sysDatasource.getUrl()); + dataSourceProperty.setUsername(sysDatasource.getUserName()); + dataSourceProperty.setPassword(sysDatasource.getPassword()); + dataSourceProperty.setDriverClassName(sysDatasource.getDriveClassName()); + dataSourceProperty.setPoolName(sysDatasource.getPoolName());// 这是数据源的key + dataSourceProperty.setLazy(false); + dynamicDatasourceCreator.createDynamicDataSource(dataSourceProperty); + + return "数据库链接测试成功,数据库链接状态正常"; + }catch (ClassNotFoundException | SQLException classNotFoundException){ + return "数据库链接异常,请检查数据库基本信息。"; + } + + } + +} diff --git a/op-modules/op-system/src/main/java/com/op/system/service/impl/SysPermissionServiceImpl.java b/op-modules/op-system/src/main/java/com/op/system/service/impl/SysPermissionServiceImpl.java index 14483d45..93abec48 100644 --- a/op-modules/op-system/src/main/java/com/op/system/service/impl/SysPermissionServiceImpl.java +++ b/op-modules/op-system/src/main/java/com/op/system/service/impl/SysPermissionServiceImpl.java @@ -2,7 +2,10 @@ package com.op.system.service.impl; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; + +import com.op.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.op.system.api.domain.SysRole; @@ -13,7 +16,7 @@ import com.op.system.service.ISysRoleService; /** * 用户权限处理 - * + * * @author OP */ @Service @@ -23,10 +26,11 @@ public class SysPermissionServiceImpl implements ISysPermissionService { @Autowired private ISysMenuService menuService; - + @Autowired + private ISysUserService userService; /** * 获取角色数据权限 - * + * * @param userId 用户Id * @return 角色权限信息 */ @@ -44,7 +48,7 @@ public class SysPermissionServiceImpl implements ISysPermissionService { /** * 获取菜单数据权限 - * + * * @param userId 用户Id * @return 菜单权限信息 */ @@ -69,4 +73,8 @@ public class SysPermissionServiceImpl implements ISysPermissionService { } return perms; } + @Override + public List> getPoolNameList(SysUser user) { + return userService.getPoolNameList(user); + } } diff --git a/op-modules/op-system/src/main/java/com/op/system/service/impl/SysUserServiceImpl.java b/op-modules/op-system/src/main/java/com/op/system/service/impl/SysUserServiceImpl.java index c393bec6..6f860394 100644 --- a/op-modules/op-system/src/main/java/com/op/system/service/impl/SysUserServiceImpl.java +++ b/op-modules/op-system/src/main/java/com/op/system/service/impl/SysUserServiceImpl.java @@ -2,6 +2,7 @@ package com.op.system.service.impl; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import javax.validation.Validator; import org.slf4j.Logger; @@ -32,7 +33,7 @@ import com.op.system.service.ISysUserService; /** * 用户 业务层处理 - * + * * @author OP */ @Service @@ -62,7 +63,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 根据条件分页查询用户列表 - * + * * @param user 用户信息 * @return 用户信息集合信息 */ @@ -74,7 +75,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 根据条件分页查询已分配用户角色列表 - * + * * @param user 用户信息 * @return 用户信息集合信息 */ @@ -86,7 +87,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 根据条件分页查询未分配用户角色列表 - * + * * @param user 用户信息 * @return 用户信息集合信息 */ @@ -98,7 +99,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 通过用户名查询用户 - * + * * @param userName 用户名 * @return 用户对象信息 */ @@ -109,7 +110,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 通过用户ID查询用户 - * + * * @param userId 用户ID * @return 用户对象信息 */ @@ -120,7 +121,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 查询用户所属角色组 - * + * * @param userName 用户名 * @return 结果 */ @@ -135,7 +136,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 查询用户所属岗位组 - * + * * @param userName 用户名 * @return 结果 */ @@ -150,7 +151,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 校验用户名称是否唯一 - * + * * @param user 用户信息 * @return 结果 */ @@ -198,7 +199,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 校验用户是否允许操作 - * + * * @param user 用户信息 */ @Override @@ -210,7 +211,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 校验用户是否有数据权限 - * + * * @param userId 用户id */ @Override @@ -227,7 +228,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 新增保存用户信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -245,7 +246,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 注册用户信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -256,7 +257,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 修改保存用户信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -277,7 +278,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 用户授权角色 - * + * * @param userId 用户ID * @param roleIds 角色组 */ @@ -290,7 +291,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 修改用户状态 - * + * * @param user 用户信息 * @return 结果 */ @@ -301,7 +302,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 修改用户基本信息 - * + * * @param user 用户信息 * @return 结果 */ @@ -312,7 +313,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 修改用户头像 - * + * * @param userName 用户名 * @param avatar 头像地址 * @return 结果 @@ -324,7 +325,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 重置用户密码 - * + * * @param user 用户信息 * @return 结果 */ @@ -335,7 +336,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 重置用户密码 - * + * * @param userName 用户名 * @param password 密码 * @return 结果 @@ -347,7 +348,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 新增用户角色信息 - * + * * @param user 用户对象 */ public void insertUserRole(SysUser user) { @@ -356,7 +357,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 新增用户岗位信息 - * + * * @param user 用户对象 */ public void insertUserPost(SysUser user) { @@ -376,7 +377,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 新增用户角色信息 - * + * * @param userId 用户ID * @param roleIds 角色组 */ @@ -396,7 +397,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 通过用户ID删除用户 - * + * * @param userId 用户ID * @return 结果 */ @@ -412,7 +413,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 批量删除用户信息 - * + * * @param userIds 需要删除的用户ID * @return 结果 */ @@ -432,7 +433,7 @@ public class SysUserServiceImpl implements ISysUserService { /** * 导入用户数据 - * + * * @param userList 用户数据列表 * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 * @param operName 操作用户 @@ -487,5 +488,8 @@ public class SysUserServiceImpl implements ISysUserService { } return successMsg.toString(); } - + @Override + public List> getPoolNameList(SysUser user) { + return userMapper.getPoolNameList(user); + } } diff --git a/op-modules/op-system/src/main/resources/bootstrap.yml b/op-modules/op-system/src/main/resources/bootstrap.yml index 18669e66..fe34e4c4 100644 --- a/op-modules/op-system/src/main/resources/bootstrap.yml +++ b/op-modules/op-system/src/main/resources/bootstrap.yml @@ -29,3 +29,12 @@ spring: # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} +sqlserve: + #数据库链接前缀 + prev: jdbc:sqlserver:// + #数据库链接后缀 + affter: :1433;DatabaseName= + driver: com.microsoft.sqlserver.jdbc.SQLServerDriver + #数据标识前缀 + poolName: + prev: factory diff --git a/op-modules/op-system/src/main/resources/mapper/system/SysDatasourceMapper.xml b/op-modules/op-system/src/main/resources/mapper/system/SysDatasourceMapper.xml new file mode 100644 index 00000000..574232b0 --- /dev/null +++ b/op-modules/op-system/src/main/resources/mapper/system/SysDatasourceMapper.xml @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id, url, ip_port, user_name, password, drive_class_name, pool_name, park_name, + status, del_flag, create_by, create_time, update_by, update_time, remark,system_type, + dept_id, schema_created from sys_datasource + + + + + + + + + + + insert into sys_datasource + + id, + url, + ip_port, + user_name, + password, + drive_class_name, + pool_name, + park_name, + status, + del_flag, + create_by, + create_time, + update_by, + update_time, + remark, + dept_id, + schema_created, + system_type, + + + #{id}, + #{url}, + #{ipPort}, + #{userName}, + #{password}, + #{driveClassName}, + #{poolName}, + #{parkName}, + #{status}, + #{delFlag}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + #{deptId}, + #{schemaCreated}, + #{systemType}, + + + + insert into sys_user_datasource(user_id, datasource_id) values + + (#{item.userId},#{item.datasourceId}) + + + + + update sys_datasource + + url = #{url}, + ip_port = #{ipPort}, + user_name = #{userName}, + password = #{password}, + drive_class_name = #{driveClassName}, + pool_name = #{poolName}, + park_name = #{parkName}, + status = #{status}, + del_flag = #{delFlag}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + dept_id = #{deptId}, + schema_created = #{schemaCreated}, + system_type = #{systemType}, + + where id = #{id} + + + + delete from sys_datasource where id = #{id} + + + + delete from sys_datasource where id in + + #{id} + + + + delete from sys_user_datasource where user_id=#{userId} and datasource_id=#{datasourceId} + + + + delete from sys_user_datasource where datasource_id=#{datasourceId} and user_id in + + #{userId} + + + diff --git a/op-modules/op-system/src/main/resources/mapper/system/SysUserMapper.xml b/op-modules/op-system/src/main/resources/mapper/system/SysUserMapper.xml index 61cee8be..1e697385 100644 --- a/op-modules/op-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/op-modules/op-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -217,5 +217,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{userId} - + diff --git a/op-modules/op-wms/src/main/java/com/op/wms/config/DynamicDatasource.java b/op-modules/op-wms/src/main/java/com/op/wms/config/DynamicDatasource.java new file mode 100644 index 00000000..f3cedfee --- /dev/null +++ b/op-modules/op-wms/src/main/java/com/op/wms/config/DynamicDatasource.java @@ -0,0 +1,51 @@ +package com.op.wms.config; + +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; +import com.op.common.core.domain.R; +import com.op.common.datasource.creator.DynamicDatasourceCreator; +import com.op.system.api.RemoteUserService; +import com.op.system.api.domain.SysUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * 初始化动态数据源 + * + * @ClassName: DynamicDatasource + * @Description: TODO + * @author shichangzhou + * @date 2023年4月19日 下午1:01:30 + */ +@Component +public class DynamicDatasource { + + @Resource + private DynamicDatasourceCreator dynamicDatasourceCreator; + @Autowired + private RemoteUserService remoteUserService; + + @PostConstruct + public void init() { + // 加载sf-cloud库的sys_datasource + SysUser sysUser = new SysUser(); + sysUser.setUserId(1L); + R>> dateSources0 = remoteUserService.getPoolNameList(sysUser); + List> dateSources = dateSources0.getData(); + for (Map dateSource : dateSources) { + DataSourceProperty sdp = new DataSourceProperty(); + sdp.setUrl(dateSource.get("url")); + sdp.setUsername(dateSource.get("userName")); + sdp.setPassword(dateSource.get("password")); + sdp.setDriverClassName(dateSource.get("driveClassName")); + sdp.setPoolName(dateSource.get("poolName"));// 这是数据源的key + sdp.setLazy(false); + dynamicDatasourceCreator.createDynamicDataSource(sdp); + } + + } +} diff --git a/op-modules/op-wms/src/main/java/com/op/wms/controller/SysUserController.java b/op-modules/op-wms/src/main/java/com/op/wms/controller/SysUserController.java deleted file mode 100644 index 201e10b9..00000000 --- a/op-modules/op-wms/src/main/java/com/op/wms/controller/SysUserController.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.op.wms.controller; - -import java.io.IOException; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang3.ArrayUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -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.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; -import com.op.common.core.domain.R; -import com.op.common.core.utils.StringUtils; -import com.op.common.core.utils.poi.ExcelUtil; -import com.op.common.core.web.controller.BaseController; -import com.op.common.core.web.domain.AjaxResult; -import com.op.common.core.web.page.TableDataInfo; -import com.op.common.log.annotation.Log; -import com.op.common.log.enums.BusinessType; -import com.op.common.security.annotation.InnerAuth; -import com.op.common.security.annotation.RequiresPermissions; -import com.op.common.security.utils.SecurityUtils; -import com.op.system.api.domain.SysDept; -import com.op.system.api.domain.SysRole; -import com.op.system.api.domain.SysUser; -import com.op.system.api.model.LoginUser; -import com.op.wms.service.ISysUserService; - -/** - * 用户信息 - * - * @author OP - */ -@RestController -@RequestMapping("/user") -public class SysUserController extends BaseController { - @Autowired - private ISysUserService userService; - - - /** - * 获取用户列表 - */ - @RequiresPermissions("system:user:list") - @GetMapping("/list") - public TableDataInfo list(SysUser user) { - startPage(); - List list = userService.selectUserList(user); - return getDataTable(list); - } - - @Log(title = "用户管理", businessType = BusinessType.EXPORT) - @RequiresPermissions("system:user:export") - @PostMapping("/export") - public void export(HttpServletResponse response, SysUser user) { - List list = userService.selectUserList(user); - ExcelUtil util = new ExcelUtil(SysUser.class); - util.exportExcel(response, list, "用户数据"); - } - - - - @PostMapping("/importTemplate") - public void importTemplate(HttpServletResponse response) throws IOException { - ExcelUtil util = new ExcelUtil(SysUser.class); - util.importTemplateExcel(response, "用户数据"); - } - - - - /** - * 新增用户 - */ - @RequiresPermissions("system:user:add") - @Log(title = "用户管理", businessType = BusinessType.INSERT) - @PostMapping - public AjaxResult add(@Validated @RequestBody SysUser user) { - if (!userService.checkUserNameUnique(user)) { - return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); - } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { - return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); - } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { - return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); - } - user.setCreateBy(SecurityUtils.getUsername()); - user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); - return toAjax(userService.insertUser(user)); - } - - - - /** - * 重置密码 - */ - @RequiresPermissions("system:user:edit") - @Log(title = "用户管理", businessType = BusinessType.UPDATE) - @PutMapping("/resetPwd") - public AjaxResult resetPwd(@RequestBody SysUser user) { - userService.checkUserAllowed(user); - userService.checkUserDataScope(user.getUserId()); - user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); - user.setUpdateBy(SecurityUtils.getUsername()); - return toAjax(userService.resetPwd(user)); - } - - /** - * 状态修改 - */ - @RequiresPermissions("system:user:edit") - @Log(title = "用户管理", businessType = BusinessType.UPDATE) - @PutMapping("/changeStatus") - public AjaxResult changeStatus(@RequestBody SysUser user) { - userService.checkUserAllowed(user); - userService.checkUserDataScope(user.getUserId()); - user.setUpdateBy(SecurityUtils.getUsername()); - return toAjax(userService.updateUserStatus(user)); - } - -} diff --git a/op-modules/op-wms/src/main/java/com/op/wms/domain/SysUserRole.java b/op-modules/op-wms/src/main/java/com/op/wms/domain/SysUserRole.java deleted file mode 100644 index ddfa713a..00000000 --- a/op-modules/op-wms/src/main/java/com/op/wms/domain/SysUserRole.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.op.wms.domain; - -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - -/** - * 用户和角色关联 sys_user_role - * - * @author OP - */ -public class SysUserRole { - /** 用户ID */ - private Long userId; - - /** 角色ID */ - private Long roleId; - - public Long getUserId() { - return userId; - } - - public void setUserId(Long userId) { - this.userId = userId; - } - - public Long getRoleId() { - return roleId; - } - - public void setRoleId(Long roleId) { - this.roleId = roleId; - } - - @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("userId", getUserId()) - .append("roleId", getRoleId()).toString(); - } -} diff --git a/op-modules/op-wms/src/main/java/com/op/wms/mapper/SysUserMapper.java b/op-modules/op-wms/src/main/java/com/op/wms/mapper/SysUserMapper.java deleted file mode 100644 index c8568b65..00000000 --- a/op-modules/op-wms/src/main/java/com/op/wms/mapper/SysUserMapper.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.op.wms.mapper; - -import java.util.List; -import org.apache.ibatis.annotations.Param; -import com.op.system.api.domain.SysUser; - -/** - * 用户表 数据层 - * - * @author OP - */ -public interface SysUserMapper { - /** - * 根据条件分页查询用户列表 - * - * @param sysUser 用户信息 - * @return 用户信息集合信息 - */ - public List selectUserList(SysUser sysUser); - - /** - * 根据条件分页查询已配用户角色列表 - * - * @param user 用户信息 - * @return 用户信息集合信息 - */ - public List selectAllocatedList(SysUser user); - - /** - * 根据条件分页查询未分配用户角色列表 - * - * @param user 用户信息 - * @return 用户信息集合信息 - */ - public List selectUnallocatedList(SysUser user); - - /** - * 通过用户名查询用户 - * - * @param userName 用户名 - * @return 用户对象信息 - */ - public SysUser selectUserByUserName(String userName); - - /** - * 通过用户ID查询用户 - * - * @param userId 用户ID - * @return 用户对象信息 - */ - public SysUser selectUserById(Long userId); - - /** - * 新增用户信息 - * - * @param user 用户信息 - * @return 结果 - */ - public int insertUser(SysUser user); - - /** - * 修改用户信息 - * - * @param user 用户信息 - * @return 结果 - */ - public int updateUser(SysUser user); - - /** - * 修改用户头像 - * - * @param userName 用户名 - * @param avatar 头像地址 - * @return 结果 - */ - public int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar); - - /** - * 重置用户密码 - * - * @param userName 用户名 - * @param password 密码 - * @return 结果 - */ - public int resetUserPwd(@Param("userName") String userName, @Param("password") String password); - - /** - * 通过用户ID删除用户 - * - * @param userId 用户ID - * @return 结果 - */ - public int deleteUserById(Long userId); - - /** - * 批量删除用户信息 - * - * @param userIds 需要删除的用户ID - * @return 结果 - */ - public int deleteUserByIds(Long[] userIds); - - /** - * 校验用户名称是否唯一 - * - * @param userName 用户名称 - * @return 结果 - */ - public SysUser checkUserNameUnique(String userName); - - /** - * 校验手机号码是否唯一 - * - * @param phonenumber 手机号码 - * @return 结果 - */ - public SysUser checkPhoneUnique(String phonenumber); - - /** - * 校验email是否唯一 - * - * @param email 用户邮箱 - * @return 结果 - */ - public SysUser checkEmailUnique(String email); -} diff --git a/op-modules/op-wms/src/main/java/com/op/wms/service/ISysUserService.java b/op-modules/op-wms/src/main/java/com/op/wms/service/ISysUserService.java deleted file mode 100644 index 0633dc4c..00000000 --- a/op-modules/op-wms/src/main/java/com/op/wms/service/ISysUserService.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.op.wms.service; - -import java.util.List; -import com.op.system.api.domain.SysUser; - -/** - * 用户 业务层 - * - * @author OP - */ -public interface ISysUserService { - /** - * 根据条件分页查询用户列表 - * - * @param user 用户信息 - * @return 用户信息集合信息 - */ - public List selectUserList(SysUser user); - - /** - * 根据条件分页查询已分配用户角色列表 - * - * @param user 用户信息 - * @return 用户信息集合信息 - */ - public List selectAllocatedList(SysUser user); - - /** - * 根据条件分页查询未分配用户角色列表 - * - * @param user 用户信息 - * @return 用户信息集合信息 - */ - public List selectUnallocatedList(SysUser user); - - /** - * 通过用户名查询用户 - * - * @param userName 用户名 - * @return 用户对象信息 - */ - public SysUser selectUserByUserName(String userName); - - /** - * 通过用户ID查询用户 - * - * @param userId 用户ID - * @return 用户对象信息 - */ - public SysUser selectUserById(Long userId); - - /** - * 校验用户名称是否唯一 - * - * @param user 用户信息 - * @return 结果 - */ - public boolean checkUserNameUnique(SysUser user); - - /** - * 校验手机号码是否唯一 - * - * @param user 用户信息 - * @return 结果 - */ - public boolean checkPhoneUnique(SysUser user); - - /** - * 校验email是否唯一 - * - * @param user 用户信息 - * @return 结果 - */ - public boolean checkEmailUnique(SysUser user); - - /** - * 校验用户是否允许操作 - * - * @param user 用户信息 - */ - public void checkUserAllowed(SysUser user); - - /** - * 校验用户是否有数据权限 - * - * @param userId 用户id - */ - public void checkUserDataScope(Long userId); - - /** - * 新增用户信息 - * - * @param user 用户信息 - * @return 结果 - */ - public int insertUser(SysUser user); - - /** - * 注册用户信息 - * - * @param user 用户信息 - * @return 结果 - */ - public boolean registerUser(SysUser user); - - - /** - * 修改用户状态 - * - * @param user 用户信息 - * @return 结果 - */ - public int updateUserStatus(SysUser user); - - /** - * 修改用户基本信息 - * - * @param user 用户信息 - * @return 结果 - */ - public int updateUserProfile(SysUser user); - - /** - * 修改用户头像 - * - * @param userName 用户名 - * @param avatar 头像地址 - * @return 结果 - */ - public boolean updateUserAvatar(String userName, String avatar); - - /** - * 重置用户密码 - * - * @param user 用户信息 - * @return 结果 - */ - public int resetPwd(SysUser user); - - /** - * 重置用户密码 - * - * @param userName 用户名 - * @param password 密码 - * @return 结果 - */ - public int resetUserPwd(String userName, String password); - -} diff --git a/op-modules/op-wms/src/main/java/com/op/wms/service/impl/SysUserServiceImpl.java b/op-modules/op-wms/src/main/java/com/op/wms/service/impl/SysUserServiceImpl.java deleted file mode 100644 index 8d051f7f..00000000 --- a/op-modules/op-wms/src/main/java/com/op/wms/service/impl/SysUserServiceImpl.java +++ /dev/null @@ -1,264 +0,0 @@ -package com.op.wms.service.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import javax.validation.Validator; - - -import com.op.wms.mapper.SysUserMapper; -import com.op.wms.service.ISysUserService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; -import com.op.common.core.constant.UserConstants; -import com.op.common.core.exception.ServiceException; -import com.op.common.core.utils.SpringUtils; -import com.op.common.core.utils.StringUtils; -import com.op.common.core.utils.bean.BeanValidators; -import com.op.common.datascope.annotation.DataScope; -import com.op.common.security.utils.SecurityUtils; -import com.op.system.api.domain.SysRole; -import com.op.system.api.domain.SysUser; - - -/** - * 用户 业务层处理 - * - * @author OP - */ -@Service -public class SysUserServiceImpl implements ISysUserService { - private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); - - @Autowired - private SysUserMapper userMapper; - - - @Autowired - protected Validator validator; - - /** - * 根据条件分页查询用户列表 - * - * @param user 用户信息 - * @return 用户信息集合信息 - */ - @Override - @DataScope(deptAlias = "d", userAlias = "u") - public List selectUserList(SysUser user) { - return userMapper.selectUserList(user); - } - - /** - * 根据条件分页查询已分配用户角色列表 - * - * @param user 用户信息 - * @return 用户信息集合信息 - */ - @Override - @DataScope(deptAlias = "d", userAlias = "u") - public List selectAllocatedList(SysUser user) { - return userMapper.selectAllocatedList(user); - } - - /** - * 根据条件分页查询未分配用户角色列表 - * - * @param user 用户信息 - * @return 用户信息集合信息 - */ - @Override - @DataScope(deptAlias = "d", userAlias = "u") - public List selectUnallocatedList(SysUser user) { - return userMapper.selectUnallocatedList(user); - } - - /** - * 通过用户名查询用户 - * - * @param userName 用户名 - * @return 用户对象信息 - */ - @Override - public SysUser selectUserByUserName(String userName) { - return userMapper.selectUserByUserName(userName); - } - - /** - * 通过用户ID查询用户 - * - * @param userId 用户ID - * @return 用户对象信息 - */ - @Override - public SysUser selectUserById(Long userId) { - return userMapper.selectUserById(userId); - } - - - /** - * 校验用户名称是否唯一 - * - * @param user 用户信息 - * @return 结果 - */ - @Override - public boolean checkUserNameUnique(SysUser user) { - Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); - SysUser info = userMapper.checkUserNameUnique(user.getUserName()); - if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; - } - - /** - * 校验手机号码是否唯一 - * - * @param user 用户信息 - * @return - */ - @Override - public boolean checkPhoneUnique(SysUser user) { - Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); - SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber()); - if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; - } - - /** - * 校验email是否唯一 - * - * @param user 用户信息 - * @return - */ - @Override - public boolean checkEmailUnique(SysUser user) { - Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); - SysUser info = userMapper.checkEmailUnique(user.getEmail()); - if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; - } - - /** - * 校验用户是否允许操作 - * - * @param user 用户信息 - */ - @Override - public void checkUserAllowed(SysUser user) { - if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) { - throw new ServiceException("不允许操作超级管理员用户"); - } - } - - /** - * 校验用户是否有数据权限 - * - * @param userId 用户id - */ - @Override - public void checkUserDataScope(Long userId) { - if (!SysUser.isAdmin(SecurityUtils.getUserId())) { - SysUser user = new SysUser(); - user.setUserId(userId); - List users = SpringUtils.getAopProxy(this).selectUserList(user); - if (StringUtils.isEmpty(users)) { - throw new ServiceException("没有权限访问用户数据!"); - } - } - } - - /** - * 新增保存用户信息 - * - * @param user 用户信息 - * @return 结果 - */ - @Override - @Transactional(rollbackFor = Exception.class) - public int insertUser(SysUser user) { - // 新增用户信息 - int rows = userMapper.insertUser(user); - - return rows; - } - - /** - * 注册用户信息 - * - * @param user 用户信息 - * @return 结果 - */ - @Override - public boolean registerUser(SysUser user) { - return userMapper.insertUser(user) > 0; - } - - - /** - * 修改用户状态 - * - * @param user 用户信息 - * @return 结果 - */ - @Override - public int updateUserStatus(SysUser user) { - return userMapper.updateUser(user); - } - - /** - * 修改用户基本信息 - * - * @param user 用户信息 - * @return 结果 - */ - @Override - public int updateUserProfile(SysUser user) { - return userMapper.updateUser(user); - } - - /** - * 修改用户头像 - * - * @param userName 用户名 - * @param avatar 头像地址 - * @return 结果 - */ - @Override - public boolean updateUserAvatar(String userName, String avatar) { - return userMapper.updateUserAvatar(userName, avatar) > 0; - } - - /** - * 重置用户密码 - * - * @param user 用户信息 - * @return 结果 - */ - @Override - public int resetPwd(SysUser user) { - return userMapper.updateUser(user); - } - - /** - * 重置用户密码 - * - * @param userName 用户名 - * @param password 密码 - * @return 结果 - */ - @Override - public int resetUserPwd(String userName, String password) { - return userMapper.resetUserPwd(userName, password); - } - -}