|
@@ -18,14 +18,25 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.maintenance.IotMaintenancePlan
|
|
|
import cn.iocoder.yudao.module.supplier.dal.dataobject.product.SupplierDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
+import lombok.Getter;
|
|
|
+import lombok.NoArgsConstructor;
|
|
|
+import lombok.Setter;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.sf.jsqlparser.JSQLParserException;
|
|
|
+import net.sf.jsqlparser.expression.Alias;
|
|
|
+import net.sf.jsqlparser.expression.Expression;
|
|
|
+import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
+import java.util.function.BiFunction;
|
|
|
+
|
|
|
/**
|
|
|
* system 模块的数据权限 Configuration
|
|
|
*
|
|
|
* @author 芋道源码
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
public class PmsDataPermissionConfiguration {
|
|
|
|
|
@@ -64,7 +75,121 @@ public class PmsDataPermissionConfiguration {
|
|
|
// user
|
|
|
rule.addUserColumn(AdminUserDO.class, "id");
|
|
|
rule.addUserColumn(SupplierDO.class, "creator");
|
|
|
+
|
|
|
+ // 为工单主表添加设备责任人条件
|
|
|
+ rule.addDeviceOwnerCondition("rq_iot_main_work_order",
|
|
|
+ DeviceOwnerConditionBuilder.createConditionGenerator(
|
|
|
+ new DeviceOwnerConditionBuilder.DeviceOwnerConfig()
|
|
|
+ .mainTable("rq_iot_main_work_order")
|
|
|
+ .mainTableIdColumn("id")
|
|
|
+ .bomTable("rq_iot_main_work_order_bom")
|
|
|
+ .bomTableMainIdColumn("work_order_id")
|
|
|
+ .bomTableDeviceIdColumn("device_id")
|
|
|
+ .devicePersonTable("rq_iot_device_person")
|
|
|
+ .devicePersonIdColumn("device_id")
|
|
|
+ .devicePersonPersonIdColumn("person_id")
|
|
|
+ )
|
|
|
+ );
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ // 设备责任人条件构建器
|
|
|
+ public static class DeviceOwnerConditionBuilder {
|
|
|
+ // 配置对象
|
|
|
+ @Getter
|
|
|
+ @Setter
|
|
|
+ @NoArgsConstructor
|
|
|
+ public static class DeviceOwnerConfig {
|
|
|
+ private String mainTable; // 主表名
|
|
|
+ private String mainTableIdColumn = "id"; // 主表ID字段名,默认为"id"
|
|
|
+ private String bomTable; // 业务子表名
|
|
|
+ private String bomTableMainIdColumn; // 业务子表关联主表的字段名
|
|
|
+ private String bomTableDeviceIdColumn; // 业务子表关联设备表的字段名
|
|
|
+ private String devicePersonTable; // 设备责任人表名
|
|
|
+ private String devicePersonIdColumn; // 设备责任人表关联设备的字段名
|
|
|
+ private String devicePersonPersonIdColumn; // 设备责任人表责任人ID字段名
|
|
|
+
|
|
|
+ // 流畅API设置方法
|
|
|
+ public DeviceOwnerConfig mainTable(String table) {
|
|
|
+ this.mainTable = table;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOwnerConfig mainTableIdColumn(String column) {
|
|
|
+ this.mainTableIdColumn = column;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOwnerConfig bomTable(String table) {
|
|
|
+ this.bomTable = table;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOwnerConfig bomTableMainIdColumn(String column) {
|
|
|
+ this.bomTableMainIdColumn = column;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOwnerConfig bomTableDeviceIdColumn(String column) {
|
|
|
+ this.bomTableDeviceIdColumn = column;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOwnerConfig devicePersonTable(String table) {
|
|
|
+ this.devicePersonTable = table;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOwnerConfig devicePersonIdColumn(String column) {
|
|
|
+ this.devicePersonIdColumn = column;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DeviceOwnerConfig devicePersonPersonIdColumn(String column) {
|
|
|
+ this.devicePersonPersonIdColumn = column;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建设备责任人条件生成器
|
|
|
+ *
|
|
|
+ * @param config 设备责任人配置
|
|
|
+ * @return 条件生成函数
|
|
|
+ */
|
|
|
+ public static BiFunction<Alias, Long, Expression> createConditionGenerator(
|
|
|
+ DeviceOwnerConfig config) {
|
|
|
+ return (tableAlias, userId) -> {
|
|
|
+ try {
|
|
|
+ // 处理表别名:如果别名存在则使用别名,否则使用表名
|
|
|
+ String tablePrefix = tableAlias != null ? tableAlias.getName() : config.mainTable;
|
|
|
+
|
|
|
+ // 构建列名表达式(使用表别名或表名)
|
|
|
+ String columnExpression = tablePrefix + "." + config.mainTableIdColumn;
|
|
|
+
|
|
|
+ // 构建完整的SQL条件表达式
|
|
|
+ String expressionSQL = String.format(
|
|
|
+ "%s IN (" +
|
|
|
+ "SELECT %s FROM %s " +
|
|
|
+ "WHERE %s IN (" +
|
|
|
+ " SELECT %s FROM %s WHERE %s = %d" +
|
|
|
+ ")" +
|
|
|
+ ")",
|
|
|
+ columnExpression,
|
|
|
+ config.bomTableMainIdColumn, config.bomTable,
|
|
|
+ config.bomTableDeviceIdColumn,
|
|
|
+ config.devicePersonIdColumn, config.devicePersonTable, config.devicePersonPersonIdColumn,
|
|
|
+ userId
|
|
|
+ );
|
|
|
+
|
|
|
+ // 解析为JSqlParser表达式
|
|
|
+ return CCJSqlParserUtil.parseCondExpression(expressionSQL);
|
|
|
+ } catch (JSQLParserException e) {
|
|
|
+ log.error("构建设备责任人条件失败", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|