Changes
This commit is contained in:
@@ -18,6 +18,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
@@ -110,14 +111,39 @@ public class FlowDesignController {
|
||||
@ApiOperation("获取流程设计分页列表")
|
||||
@SaCheckPermission("flow.design")
|
||||
public Result pageData(PageForm pageForm, String displayName, String name, String category, Boolean deployed) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
pd.*
|
||||
FROM
|
||||
wf_process_design pd
|
||||
LEFT JOIN wf_process_category pc ON pc.id = pd.category
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
|
||||
cnd.and(Cnd.likeEX(ProcessDesign::getDisplayName, displayName));
|
||||
cnd.and(Cnd.likeEX(ProcessDesign::getName, name));
|
||||
cnd.andEX(ProcessDesign::getCategory, "=", category);
|
||||
cnd.andEX(ProcessDesign::getIsDeployed, "=", deployed);
|
||||
cnd.and(Cnd.likeEX("pd.displayName", displayName));
|
||||
cnd.and(Cnd.likeEX("pd.name", name));
|
||||
cnd.andEX("pd.category", "=", category);
|
||||
cnd.andEX("pd.isDeployed", "=", deployed);
|
||||
if ("sortNo".equals(pageForm.getPageOrderName())) {
|
||||
if ("descending".equals(pageForm.getPageOrderBy())) {
|
||||
cnd.desc("pd.sortNo");
|
||||
} else {
|
||||
cnd.asc("pd.sortNo");
|
||||
}
|
||||
} else if ("category".equals(pageForm.getPageOrderName())) {
|
||||
if ("descending".equals(pageForm.getPageOrderBy())) {
|
||||
cnd.desc("pc.name");
|
||||
} else {
|
||||
cnd.asc("pc.name");
|
||||
}
|
||||
} else {
|
||||
cnd.asc("pd.sortNo");
|
||||
}
|
||||
cnd.asc("pd.id");
|
||||
|
||||
Pagination pagination = processDesignService.listPage(pageForm.getPageNumber(), pageForm.getPageSize(), cnd);
|
||||
sql.setCondition(cnd);
|
||||
Pagination pagination = processDesignService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
@@ -206,6 +232,17 @@ public class FlowDesignController {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("修改流程设计排序编码")
|
||||
@SaCheckPermission("flow.design")
|
||||
public Result updateSortNo(@Param("id") Long id, @Param("sortNo") Integer sortNo) {
|
||||
if (id == null || sortNo == null || sortNo < 0) {
|
||||
return Result.error("排序编码必须是非负整数");
|
||||
}
|
||||
processDesignService.update(Chain.make("sortNo", sortNo), Cnd.where(ProcessDesign::getId, "=", id));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckLogin
|
||||
@ApiOperation("获取流程设计任务参与者处理类")
|
||||
|
||||
@@ -68,6 +68,11 @@ public class ProcessDesign extends BaseModel {
|
||||
@Column
|
||||
private Integer isDeployed;
|
||||
|
||||
@Comment("排序编码")
|
||||
@Column
|
||||
@Default("0")
|
||||
private Integer sortNo;
|
||||
|
||||
@Comment("备注")
|
||||
@Column
|
||||
private String remark;
|
||||
|
||||
@@ -0,0 +1,451 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.annotation.SLog;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.CommonDownloadUtil;
|
||||
import com.budwk.app.sys.enums.SysDataImportPlugin;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.entity.Record;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.AdaptBy;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
import org.nutz.mvc.upload.UploadAdaptor;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@IocBean
|
||||
@Ok("json:full")
|
||||
@At("/platform/sys/data/tool")
|
||||
@Api("系统数据高级工具")
|
||||
public class SysDataToolController {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/data/tool/index.html")
|
||||
@SaCheckPermission("sys.data.advanced.tool")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("查询数据库中的表")
|
||||
@SaCheckPermission("sys.data.advanced.tool")
|
||||
public Result tableNames() {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
table_name,
|
||||
table_rows,
|
||||
table_comment
|
||||
FROM
|
||||
information_schema.TABLES
|
||||
WHERE
|
||||
table_schema = (SELECT DATABASE())
|
||||
ORDER BY
|
||||
table_name
|
||||
""");
|
||||
return Result.success(sysUserService.listMap(sql));
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("查询数据表字段")
|
||||
@SaCheckPermission("sys.data.advanced.tool")
|
||||
public Result columns(String tableName) {
|
||||
if (StrUtil.isBlank(tableName)) {
|
||||
return Result.error("请选择数据表");
|
||||
}
|
||||
return Result.success(getColumns(tableName));
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("执行高级导入")
|
||||
@SLog(tag = "数据管理-高级工具", msg = "执行高级导入")
|
||||
@SaCheckPermission("sys.data.advanced.tool")
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
public Result importData(@Param("file") TempFile file,
|
||||
String tableName,
|
||||
String relation,
|
||||
Integer method,
|
||||
String field,
|
||||
String plugins) throws IOException {
|
||||
if (file == null) {
|
||||
return Result.error("请上传 Excel 文件");
|
||||
}
|
||||
if (StrUtil.isBlank(tableName)) {
|
||||
return Result.error("请选择数据表");
|
||||
}
|
||||
if (method == null) {
|
||||
return Result.error("请选择导入方式");
|
||||
}
|
||||
if ((method == 1 || method == 3) && StrUtil.isBlank(field)) {
|
||||
return Result.error("请选择关键字段");
|
||||
}
|
||||
if (StrUtil.isBlank(relation)) {
|
||||
return Result.error("请配置字段对应关系");
|
||||
}
|
||||
|
||||
List<Record> columns = getColumns(tableName);
|
||||
if (columns.isEmpty()) {
|
||||
return Result.error("未获取到数据表字段");
|
||||
}
|
||||
|
||||
NutMap[] relations = parseRelations(relation);
|
||||
List<NutMap> dataList = getDataForExcel(file, relations);
|
||||
List<SysDataImportPlugin> pluginList = parsePlugins(plugins);
|
||||
pluginList.sort(Comparator.comparingInt(SysDataImportPlugin::getLocation));
|
||||
Record pkRecord = getPrimaryKey(columns).orElse(null);
|
||||
Set<String> tableColumns = new HashSet<>();
|
||||
columns.forEach(column -> tableColumns.add(column.getString("column_name")));
|
||||
|
||||
int total = 0;
|
||||
int success = 0;
|
||||
List<ImportError> errors = new ArrayList<>();
|
||||
|
||||
for (NutMap row : dataList) {
|
||||
total++;
|
||||
try {
|
||||
if (StrUtil.isNotBlank(field)) {
|
||||
row.setv(field, row.getString(field));
|
||||
}
|
||||
|
||||
Chain chain = buildChain(row, tableColumns);
|
||||
if (chain == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object pk;
|
||||
if (method == 1) {
|
||||
Record currentRecord = sysUserService.dao().fetch(tableName, Cnd.where(field, "=", row.get(field)));
|
||||
if (currentRecord == null) {
|
||||
pk = prepareBefore(tableName, pkRecord, field, pluginList, true, chain, row, tableColumns);
|
||||
sysUserService.dao().insert(tableName, chain);
|
||||
} else {
|
||||
pk = prepareBefore(tableName, pkRecord, field, pluginList, false, chain, row, tableColumns);
|
||||
sysUserService.dao().update(tableName, chain, Cnd.where(field, "=", row.get(field)));
|
||||
}
|
||||
} else if (method == 2) {
|
||||
pk = prepareBefore(tableName, pkRecord, field, pluginList, true, chain, row, tableColumns);
|
||||
sysUserService.dao().insert(tableName, chain);
|
||||
} else if (method == 3) {
|
||||
pk = prepareBefore(tableName, pkRecord, field, pluginList, false, chain, row, tableColumns);
|
||||
sysUserService.dao().update(tableName, chain, Cnd.where(field, "=", row.get(field)));
|
||||
} else {
|
||||
throw new IllegalArgumentException("导入方式不正确");
|
||||
}
|
||||
|
||||
applyAfterPlugins(tableName, tableColumns, chain, pk, pluginList);
|
||||
success++;
|
||||
} catch (Exception e) {
|
||||
log.error("高级导入失败, table={}, row={}", tableName, row, e);
|
||||
errors.add(new ImportError(Json.toJson(row), e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
String cacheKey = "";
|
||||
if (!errors.isEmpty()) {
|
||||
cacheKey = R.UU32();
|
||||
redisService.setex(cacheKey, 60 * 60 * 5, Json.toJson(errors));
|
||||
}
|
||||
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success(NutMap.NEW().addv("total", total).addv("success", success).addv("cacheKey", cacheKey));
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@ApiOperation("导出错误记录")
|
||||
@SaCheckPermission("sys.data.advanced.tool")
|
||||
public void exportErrors(HttpServletResponse response, String cacheKey) {
|
||||
if (StrUtil.isBlank(cacheKey)) {
|
||||
CommonDownloadUtil.download("导入错误记录.xlsx",
|
||||
ExcelExportUtil.exportExcel(new ExportParams(), ImportError.class, new ArrayList<>()),
|
||||
response);
|
||||
return;
|
||||
}
|
||||
String json = redisService.get(cacheKey);
|
||||
List<ImportError> errors = StrUtil.isBlank(json) ? new ArrayList<>() : Json.fromJsonAsList(ImportError.class, json);
|
||||
CommonDownloadUtil.download("导入错误记录.xlsx",
|
||||
ExcelExportUtil.exportExcel(new ExportParams(), ImportError.class, errors),
|
||||
response);
|
||||
}
|
||||
|
||||
private void applyAfterPlugins(String tableName,
|
||||
Set<String> tableColumns,
|
||||
Chain chain,
|
||||
Object pk,
|
||||
List<SysDataImportPlugin> pluginList) {
|
||||
if (pluginList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SysDataImportPlugin.PluginContext context = new SysDataImportPlugin.PluginContext(
|
||||
tableName,
|
||||
tableColumns,
|
||||
chain,
|
||||
pk,
|
||||
sysUserService.dao(),
|
||||
sysRoleService
|
||||
);
|
||||
pluginList.forEach(plugin -> plugin.after(context));
|
||||
}
|
||||
|
||||
private Object prepareBefore(String tableName,
|
||||
Record pkRecord,
|
||||
String field,
|
||||
List<SysDataImportPlugin> pluginList,
|
||||
boolean save,
|
||||
Chain chain,
|
||||
NutMap row,
|
||||
Set<String> tableColumns) {
|
||||
Object pk = resolvePrimaryKeyValue(tableName, pkRecord, field, save, chain, row);
|
||||
SysDataImportPlugin.PluginContext context = new SysDataImportPlugin.PluginContext(
|
||||
tableName,
|
||||
tableColumns,
|
||||
chain,
|
||||
pk,
|
||||
sysUserService.dao(),
|
||||
sysRoleService
|
||||
);
|
||||
pluginList.forEach(plugin -> plugin.before(context));
|
||||
return pk;
|
||||
}
|
||||
|
||||
private Object resolvePrimaryKeyValue(String tableName,
|
||||
Record pkRecord,
|
||||
String field,
|
||||
boolean save,
|
||||
Chain chain,
|
||||
NutMap row) {
|
||||
if (pkRecord == null) {
|
||||
return null;
|
||||
}
|
||||
String pkColumnName = pkRecord.getString("column_name");
|
||||
String pkColumnType = pkRecord.getString("column_type");
|
||||
|
||||
Object pk;
|
||||
if (save) {
|
||||
pk = row.get(pkColumnName);
|
||||
if (pk == null) {
|
||||
pk = generatePrimaryKey(pkColumnType);
|
||||
chain.add(pkColumnName, pk);
|
||||
}
|
||||
} else {
|
||||
Record record = sysUserService.dao().fetch(tableName, Cnd.where(field, "=", row.get(field)));
|
||||
if (record == null) {
|
||||
throw new IllegalArgumentException("未找到关键字段匹配的记录");
|
||||
}
|
||||
pk = record.get(pkColumnName);
|
||||
}
|
||||
|
||||
if (pk == null) {
|
||||
throw new IllegalArgumentException("主键生成失败");
|
||||
}
|
||||
return pk;
|
||||
}
|
||||
|
||||
private Object generatePrimaryKey(String pkColumnType) {
|
||||
if (StrUtil.isBlank(pkColumnType)) {
|
||||
return R.UU32();
|
||||
}
|
||||
return switch (pkColumnType.toLowerCase()) {
|
||||
case "int", "integer" -> R.random(1000, 9999);
|
||||
case "varchar(16)" -> R.UU16();
|
||||
case "varchar(64)" -> R.UU64();
|
||||
default -> R.UU32();
|
||||
};
|
||||
}
|
||||
|
||||
private Chain buildChain(NutMap row, Set<String> tableColumns) {
|
||||
NutMap filtered = NutMap.NEW();
|
||||
row.forEach((key, value) -> {
|
||||
if (key != null && tableColumns.contains(key)) {
|
||||
filtered.addv(key, value);
|
||||
}
|
||||
});
|
||||
return filtered.isEmpty() ? null : Chain.from(filtered);
|
||||
}
|
||||
|
||||
private NutMap[] parseRelations(String relationJson) {
|
||||
List<NutMap> relationList = Json.fromJsonAsList(NutMap.class, relationJson);
|
||||
return relationList.toArray(new NutMap[0]);
|
||||
}
|
||||
|
||||
private List<SysDataImportPlugin> parsePlugins(String pluginsJson) {
|
||||
if (StrUtil.isBlank(pluginsJson)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> pluginNames = Json.fromJsonAsList(String.class, pluginsJson);
|
||||
List<SysDataImportPlugin> plugins = new ArrayList<>();
|
||||
for (String pluginName : pluginNames) {
|
||||
if (StrUtil.isBlank(pluginName)) {
|
||||
continue;
|
||||
}
|
||||
plugins.add(SysDataImportPlugin.valueOf(pluginName));
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
private Optional<Record> getPrimaryKey(List<Record> columns) {
|
||||
return columns.stream().filter(column -> "PRI".equalsIgnoreCase(column.getString("column_key"))).findFirst();
|
||||
}
|
||||
|
||||
private List<Record> getColumns(String tableName) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
column_name,
|
||||
is_nullable,
|
||||
column_type,
|
||||
column_key,
|
||||
column_comment
|
||||
FROM
|
||||
information_schema.COLUMNS
|
||||
WHERE
|
||||
table_name = @tableName
|
||||
AND table_schema = (SELECT DATABASE())
|
||||
ORDER BY
|
||||
ordinal_position
|
||||
""").setParam("tableName", tableName);
|
||||
return sysUserService.list(sql);
|
||||
}
|
||||
|
||||
private List<NutMap> getDataForExcel(TempFile file, NutMap[] relation) throws IOException {
|
||||
List<NutMap> result = new ArrayList<>();
|
||||
Map<Integer, String> headerColumnMap = new HashMap<>();
|
||||
|
||||
Sheet sheet = WorkbookFactory.create(file.getInputStream()).getSheetAt(0);
|
||||
Row headerRow = sheet.getRow(0);
|
||||
if (headerRow == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int columnNum = headerRow.getPhysicalNumberOfCells();
|
||||
for (int i = 0; i < columnNum; i++) {
|
||||
Cell cell = headerRow.getCell(i);
|
||||
if (cell == null) {
|
||||
continue;
|
||||
}
|
||||
String header = cell.getStringCellValue();
|
||||
for (NutMap item : relation) {
|
||||
if (StrUtil.equals(item.getString("relation"), header)) {
|
||||
headerColumnMap.put(i, item.getString("column_name"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int rowNum = sheet.getPhysicalNumberOfRows();
|
||||
for (int i = 1; i < rowNum; i++) {
|
||||
Row row = sheet.getRow(i);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
NutMap data = NutMap.NEW();
|
||||
for (int j = 0; j < columnNum; j++) {
|
||||
String columnName = headerColumnMap.get(j);
|
||||
if (columnName == null) {
|
||||
continue;
|
||||
}
|
||||
data.setv(columnName, getCellValue(row.getCell(j)));
|
||||
}
|
||||
if (!data.isEmpty()) {
|
||||
result.add(data);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object getCellValue(Cell cell) {
|
||||
if (cell == null) {
|
||||
return null;
|
||||
}
|
||||
CellType cellType = cell.getCellType();
|
||||
if (cellType == CellType.NUMERIC) {
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
Date date = cell.getDateCellValue();
|
||||
return DATE_TIME_FORMATTER.format(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()));
|
||||
}
|
||||
double numericValue = cell.getNumericCellValue();
|
||||
BigDecimal decimal = BigDecimal.valueOf(numericValue);
|
||||
if (String.valueOf(numericValue).contains("E")) {
|
||||
return decimal.toPlainString();
|
||||
}
|
||||
if (numericValue == Math.rint(numericValue)) {
|
||||
return decimal.toBigInteger();
|
||||
}
|
||||
return numericValue;
|
||||
}
|
||||
if (cellType == CellType.STRING) {
|
||||
return cell.getStringCellValue();
|
||||
}
|
||||
if (cellType == CellType.BOOLEAN) {
|
||||
return cell.getBooleanCellValue();
|
||||
}
|
||||
if (cellType == CellType.ERROR) {
|
||||
return cell.getErrorCellValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class ImportError {
|
||||
@Excel(name = "行数据", width = 80)
|
||||
private String row;
|
||||
|
||||
@Excel(name = "错误原因", width = 40)
|
||||
private String errorMsg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.budwk.app.sys.enums;
|
||||
|
||||
import com.budwk.app.base.annotation.DictEnum;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.utils.PwdUtil;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import lombok.Getter;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.lang.random.R;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 高级导入工具插件。
|
||||
*/
|
||||
@Getter
|
||||
@DictEnum(key = "sysDataImportPlugin", name = "系统数据高级工具插件")
|
||||
public enum SysDataImportPlugin {
|
||||
|
||||
USER_INIT(1, "初始化系统用户"),
|
||||
MEMBER_INIT(2, "设置为会员");
|
||||
|
||||
private final int location;
|
||||
private final String description;
|
||||
|
||||
SysDataImportPlugin(int location, String description) {
|
||||
this.location = location;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void before(PluginContext context) {
|
||||
if (!context.isSysUserTable()) {
|
||||
return;
|
||||
}
|
||||
if (this == USER_INIT) {
|
||||
String salt = R.UU32();
|
||||
context.addValue("salt", salt);
|
||||
context.addValue("password", PwdUtil.getPassword(PwdUtil.generate(12), salt));
|
||||
context.addValue("loginCount", 0);
|
||||
context.addValue("disabled", false);
|
||||
return;
|
||||
}
|
||||
if (this == MEMBER_INIT) {
|
||||
context.addValue("member", true);
|
||||
context.addValue("memberTime", new Date());
|
||||
}
|
||||
}
|
||||
|
||||
public void after(PluginContext context) {
|
||||
if (!context.isSysUserTable()) {
|
||||
return;
|
||||
}
|
||||
if (this == USER_INIT) {
|
||||
context.ensureRole(RoleConstant.PUBLIC);
|
||||
return;
|
||||
}
|
||||
if (this == MEMBER_INIT) {
|
||||
context.ensureRole(RoleConstant.MEMBER);
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class PluginContext {
|
||||
private final String tableName;
|
||||
private final Set<String> tableColumns;
|
||||
private final Chain chain;
|
||||
private final Object pk;
|
||||
private final Dao dao;
|
||||
private final SysRoleService sysRoleService;
|
||||
|
||||
public PluginContext(String tableName,
|
||||
Set<String> tableColumns,
|
||||
Chain chain,
|
||||
Object pk,
|
||||
Dao dao,
|
||||
SysRoleService sysRoleService) {
|
||||
this.tableName = tableName;
|
||||
this.tableColumns = tableColumns;
|
||||
this.chain = chain;
|
||||
this.pk = pk;
|
||||
this.dao = dao;
|
||||
this.sysRoleService = sysRoleService;
|
||||
}
|
||||
|
||||
public boolean isSysUserTable() {
|
||||
return "sys_user".equalsIgnoreCase(tableName);
|
||||
}
|
||||
|
||||
public boolean hasColumn(String columnName) {
|
||||
return tableColumns.contains(columnName);
|
||||
}
|
||||
|
||||
public void addValue(String columnName, Object value) {
|
||||
if (hasColumn(columnName)) {
|
||||
chain.add(columnName, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void ensureRole(RoleConstant roleConstant) {
|
||||
if (pk == null || !isSysUserTable()) {
|
||||
return;
|
||||
}
|
||||
Sys_role sysRole = sysRoleService.getByCode(roleConstant);
|
||||
if (sysRole == null) {
|
||||
return;
|
||||
}
|
||||
int count = dao.count(Sys_user_role.class, Cnd.where("userId", "=", String.valueOf(pk))
|
||||
.and("roleId", "=", sysRole.getId()));
|
||||
if (count > 0) {
|
||||
return;
|
||||
}
|
||||
Sys_user_role userRole = new Sys_user_role();
|
||||
userRole.setUserId(String.valueOf(pk));
|
||||
userRole.setRoleId(sysRole.getId());
|
||||
dao.insert(userRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
-10
@@ -311,10 +311,7 @@ public class ActivityBasicScopeController {
|
||||
cnd.orderBy(activityUserScopePageParam.getPageOrderName(), activityUserScopePageParam.getPageOrderBy().equalsIgnoreCase("ascending") ? "ASC" : "DESC");
|
||||
}
|
||||
|
||||
if (activityUserScopePageParam.getActivityGroupId() != null) {
|
||||
Sql sqlx = activityBasicScopeService.buildGroupUserIdSubSql(activityUserScopePageParam.getActivityGroupId());
|
||||
cnd.and("u.id", activityUserScopePageParam.getReverseSelection() ? "IN" : "NOT IN", sqlx);
|
||||
}
|
||||
appendActivityGroupCondition(cnd, activityUserScopePageParam);
|
||||
|
||||
cnd.andEX("u.id", IN_OR_NIN_OP, activityUserScopePageParam.getUserId());
|
||||
|
||||
@@ -326,7 +323,7 @@ public class ActivityBasicScopeController {
|
||||
cnd.and("u.welfareMember", EQ_OR_NEQ_OP, 1);
|
||||
}
|
||||
if (ArrayUtils.contains(activityUserScopePageParam.getMemberTypes(), "基金会员")) {
|
||||
cnd.and(new Static(" u.loginname " + IN_OR_NIN_OP + " (select loginname from sick_fund_member)"));
|
||||
cnd.and("u.aidFundMember", EQ_OR_NEQ_OP, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,8 +348,12 @@ public class ActivityBasicScopeController {
|
||||
if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())){
|
||||
cnd.andEX("u.unionid", "=", SecurityUtil.getUnionId());
|
||||
}
|
||||
cnd.andEX("u.unionid", EQ_OR_NEQ_OP, activityUserScopePageParam.getUnionId());
|
||||
cnd.andEX("u.unitid", EQ_OR_NEQ_OP, activityUserScopePageParam.getUnitId());
|
||||
String[] unionIds = getUnionIds(activityUserScopePageParam);
|
||||
if (Lang.isNotEmpty(unionIds)) {
|
||||
cnd.andEX("u.unionid", IN_OR_NIN_OP, unionIds);
|
||||
} else {
|
||||
cnd.andEX("u.unionid", EQ_OR_NEQ_OP, activityUserScopePageParam.getUnionId());
|
||||
}
|
||||
cnd.andEX("u.personType", IN_OR_NIN_OP, activityUserScopePageParam.getPersonTypes());
|
||||
cnd.andEX("u.userState", IN_OR_NIN_OP, activityUserScopePageParam.getUserStates());
|
||||
cnd.andEX("u.sex", IN_OR_NIN_OP, activityUserScopePageParam.getSexTypes());
|
||||
@@ -367,6 +368,34 @@ public class ActivityBasicScopeController {
|
||||
|
||||
}
|
||||
|
||||
private void appendActivityGroupCondition(Cnd cnd, ActivityUserScopePageParam activityUserScopePageParam) {
|
||||
Integer activityGroupId = activityUserScopePageParam.getActivityGroupId();
|
||||
if (activityGroupId == null) {
|
||||
return;
|
||||
}
|
||||
boolean reverseSelection = Boolean.TRUE.equals(activityUserScopePageParam.getReverseSelection());
|
||||
Integer groupType = activityBasicScopeService.getGroupType(activityGroupId);
|
||||
if (GROUP_TYPE_RESULT == groupType) {
|
||||
String existsSql = """
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM activity_user_scope aus
|
||||
WHERE aus.groupId = %d
|
||||
AND aus.userId = u.id
|
||||
)
|
||||
""".formatted(activityGroupId);
|
||||
cnd.and(new Static(reverseSelection ? existsSql : "NOT " + existsSql));
|
||||
return;
|
||||
}
|
||||
|
||||
ActivityUserScope groupInfo = activityBasicScopeService.getGroupInfo(activityGroupId);
|
||||
if (groupInfo == null || StrUtil.isBlank(groupInfo.getGroupSql())) {
|
||||
return;
|
||||
}
|
||||
String groupSql = "(" + groupInfo.getGroupSql() + ")";
|
||||
cnd.and(new Static(reverseSelection ? groupSql : "NOT " + groupSql));
|
||||
}
|
||||
|
||||
/**
|
||||
* 结果分组会把当前筛选出的用户快照保存下来,因此只落 userId 明细数据。
|
||||
*/
|
||||
@@ -550,7 +579,7 @@ public class ActivityBasicScopeController {
|
||||
conditionList.add("u.welfareMember " + eqOrNeq + " 1");
|
||||
}
|
||||
if (ArrayUtils.contains(activityUserScopePageParam.getMemberTypes(), "基金会员")) {
|
||||
conditionList.add("u.loginname " + inOrNotIn + " (select loginname from sick_fund_member)");
|
||||
conditionList.add("u.aidFundMember " + eqOrNeq + " 1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,8 +603,12 @@ public class ActivityBasicScopeController {
|
||||
conditionList.add("u.unionid = " + wrapSqlValue(SecurityUtil.getUnionId()));
|
||||
}
|
||||
|
||||
addSingleValueCondition(conditionList, "u.unionid", eqOrNeq, activityUserScopePageParam.getUnionId());
|
||||
addSingleValueCondition(conditionList, "u.unitid", eqOrNeq, activityUserScopePageParam.getUnitId());
|
||||
String[] unionIds = getUnionIds(activityUserScopePageParam);
|
||||
if (Lang.isNotEmpty(unionIds)) {
|
||||
addArrayCondition(conditionList, "u.unionid", inOrNotIn, unionIds);
|
||||
} else {
|
||||
addSingleValueCondition(conditionList, "u.unionid", eqOrNeq, activityUserScopePageParam.getUnionId());
|
||||
}
|
||||
addArrayCondition(conditionList, "u.personType", inOrNotIn, activityUserScopePageParam.getPersonTypes());
|
||||
addArrayCondition(conditionList, "u.userState", inOrNotIn, activityUserScopePageParam.getUserStates());
|
||||
addArrayCondition(conditionList, "u.sex", inOrNotIn, activityUserScopePageParam.getSexTypes());
|
||||
@@ -610,6 +643,16 @@ public class ActivityBasicScopeController {
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getUnionIds(ActivityUserScopePageParam activityUserScopePageParam) {
|
||||
if (Lang.isNotEmpty(activityUserScopePageParam.getUnionIds())) {
|
||||
return activityUserScopePageParam.getUnionIds();
|
||||
}
|
||||
if (StrUtil.isNotBlank(activityUserScopePageParam.getUnionId())) {
|
||||
return new String[]{activityUserScopePageParam.getUnionId()};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addArrayCondition(List<String> conditionList, String columnName, String operator, String[] values) {
|
||||
if (Lang.isNotEmpty(values)) {
|
||||
conditionList.add(columnName + " " + operator + " (" + buildSqlStringList(values) + ")");
|
||||
|
||||
@@ -20,7 +20,8 @@ import java.io.Serializable;
|
||||
@Comment("活动人员范围设置")
|
||||
@TableIndexes({
|
||||
@Index(name = "INDEX_ACTIVITY_USER_SCOPE_GROUPID", fields = {"groupId"}, unique = false),
|
||||
@Index(name = "INDEX_ACTIVITY_USER_SCOPE_USERID", fields = {"userId"}, unique = false)
|
||||
@Index(name = "INDEX_ACTIVITY_USER_SCOPE_USERID", fields = {"userId"}, unique = false),
|
||||
@Index(name = "INDEX_ACTIVITY_USER_SCOPE_GROUPID_USERID", fields = {"groupId", "userId"}, unique = false)
|
||||
})
|
||||
public class ActivityUserScope extends BaseModel implements Serializable {
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ActivityUserScopePageParam extends PageForm {
|
||||
|
||||
// 工会id
|
||||
private String unionId;
|
||||
private String[] unionIds;
|
||||
// 单位id
|
||||
private String unitId;
|
||||
// 人类型
|
||||
|
||||
Reference in New Issue
Block a user