This commit is contained in:
Paidax
2025-11-11 17:16:43 +08:00
parent dea071e25f
commit e7d3670c5a
12 changed files with 242 additions and 33 deletions
@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
import org.nutz.lang.util.NutMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -18,9 +19,9 @@ import java.util.Map;
* @注释 没有定义的数据对象的读取
*/
@Slf4j
public class NoModelDataListener implements ReadListener<Map<String, Object>> {
public class NoModelDataListener implements ReadListener<Map<Integer, String>> {
private boolean isFirstRow = true;
private boolean firstRow = true;
// 表头数据
@Getter
private List<String> headers = new ArrayList<>();
@@ -29,17 +30,31 @@ public class NoModelDataListener implements ReadListener<Map<String, Object>> {
private List<NutMap> dataList = new ArrayList<>();
@Override
public void invoke(Map<String, Object> rowMap, AnalysisContext context) {
if (isFirstRow) {
headers = new ArrayList<>(rowMap.keySet());
isFirstRow = false;
public void invoke(Map<Integer, String> rowMap, AnalysisContext context) {
if (firstRow) {
// 第一行是表头:按列索引存 header
headers = new ArrayList<>(Collections.nCopies(rowMap.size(), ""));
for (Map.Entry<Integer, String> entry : rowMap.entrySet()) {
headers.set(entry.getKey(), entry.getValue());
}
firstRow = false;
} else {
// 后续行是数据:用 header 作为 key
NutMap nutMap = new NutMap();
nutMap.putAll(rowMap);
for (Map.Entry<Integer, String> entry : rowMap.entrySet()) {
Integer colIndex = entry.getKey();
String value = entry.getValue();
String header = colIndex < headers.size() ? headers.get(colIndex) : "Column" + colIndex;
nutMap.put(header, value);
}
dataList.add(nutMap);
}
}
public List<NutMap> getDataList() {
return dataList;
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
log.info("共读取 {} 行数据(不含表头)", dataList.size());
@@ -3,6 +3,7 @@ package com.budwk.app.zhgh.staffmanage.personnelcheck.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.budwk.app.base.page.Pagination;
import com.budwk.app.base.result.Result;
import com.budwk.app.zhgh.staffmanage.personnelcheck.model.CheckTaskBusinessConfig;
import com.budwk.app.zhgh.staffmanage.personnelcheck.service.CheckTaskCommonService;
import com.budwk.app.zhgh.staffmanage.personnelcheck.vo.pageform.CheckTaskCommonPageForm;
import io.swagger.annotations.Api;
@@ -13,10 +14,12 @@ import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import javax.validation.Valid;
import java.util.List;
/**
* @version 1.0
@@ -71,8 +74,16 @@ public class CheckTaskSingleController {
LEFT JOIN `user` u ON u.loginname = person.loginname
$condition
""");
CheckTaskBusinessConfig config = dao.fetch(CheckTaskBusinessConfig.class, Cnd.where(CheckTaskBusinessConfig::getCode, "=", pageForm.getTaskCode()));
List<NutMap> list = config.getWorkflowSteps();
// 找出第一个步骤
String stepCode = list.get(0).getString("stepCode");
Cnd cnd = Cnd.NEW();
pageForm.buildSearch(cnd, "u.");
sql.setCondition(cnd);
Pagination pagination = checkTaskCommonService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
return Result.success(pagination);
@@ -89,6 +100,6 @@ public class CheckTaskSingleController {
@At
@SaCheckPermission("personnel.check.verification.single")
public Result findOne(@Valid String id){
return Result.success();
}
}
@@ -9,6 +9,7 @@ import com.budwk.app.base.annotation.SLog;
import com.budwk.app.base.page.Pagination;
import com.budwk.app.base.result.Result;
import com.budwk.app.flow.engine.FlowEngine;
import com.budwk.app.sys.services.SysFileService;
import com.budwk.app.zhgh.staffmanage.personnelcheck.model.CheckTaskBusinessConfig;
import com.budwk.app.zhgh.staffmanage.personnelcheck.model.CheckTaskFiledConfig;
import com.budwk.app.zhgh.staffmanage.personnelcheck.model.CheckTaskVerification;
@@ -55,6 +56,8 @@ public class CheckTaskVerificationController {
@Inject
private FlowEngine flowEngine;
@Inject
private SysFileService sysFileService;
@Inject
private CheckTaskCommonService checkTaskCommonService;
@@ -68,10 +71,12 @@ public class CheckTaskVerificationController {
@At
@SaCheckPermission("personnel.check.verification.manage")
public Result pageData(CheckTaskManagePageForm pageForm){
Sql sql = Sqls.create("SELECT * FROM check_task $condition");
Sql sql = Sqls.create("SELECT * FROM check_task_verification $condition");
Cnd cnd = Cnd.NEW();
cnd.andEX("YEAR(createTime)", "=", pageForm.getYear());
cnd.andEX("taskName", "like", "%" + pageForm.getSearchKeyword() + "%");
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
cnd.and("taskName", "like", "%" + pageForm.getSearchKeyword() + "%");
}
sql.setCondition(cnd);
Pagination pagination = checkTaskCommonService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
return Result.success(pagination);
@@ -98,14 +103,26 @@ public class CheckTaskVerificationController {
// 1.界面可能会对相关审核步骤做修改,修改审核流程配置
dao.update(vo.getBusinessConfig());
// 2.新增或者修改事项任务
// 2.保存文件
String filePath = sysFileService.uploadReturnUrl("MINIO", file);
// 3.新增或者修改事项任务
CheckTaskVerification verification = new CheckTaskVerification();
verification.setId(vo.getId());
verification.setYear(DateUtil.thisYear());
verification.setTitle(vo.getTitle());
verification.setBusinessType(vo.getBusinessType());
// 存储文件名及文件路径
verification.setFileName(file.getSubmittedFileName());
verification.setFilePath(filePath);
verification.setStartTime(vo.getStartTime());
verification.setEndTime(vo.getEndTime());
verification.setStatus("进行中");
verification.setCreateTime(vo.getCreateTime() == null ? DateUtil.date() : vo.getCreateTime());
verification.setYear(DateUtil.year(verification.getCreateTime()));
dao.insertOrUpdate(verification);
// 3.往字段表里面插入数据,最好做下字段映射,把相关字段与数据库的字段对应(忽略,前端做好了字段对应)
// 4.往字段表里面插入数据,最好做下字段映射,把相关字段与数据库的字段对应(忽略,前端做好了字段对应)
// todo 字段映射
List<CheckTaskFiledConfig> fieldConfig = vo.getFieldConfig();
fieldConfig.forEach(v -> {
@@ -114,10 +131,10 @@ public class CheckTaskVerificationController {
});
dao.insert(fieldConfig);
// 4.读取文件,构造数据(动态字段 data),往 CheckTaskPersonnel 表中插入数据
// 5.读取文件,构造数据(动态字段 data),往 CheckTaskPersonnel 表中插入数据
// todo 读取文件 转换成数据 同时还要把字段转化成数据库的字段来存储
List<CheckTaskPersonnel> personnelData = checkTaskCommonService.readFile(fieldConfig, file);
dao.fastInsert(personnelData);
return Result.success();
}
@@ -128,9 +145,9 @@ public class CheckTaskVerificationController {
@SaCheckPermission("personnel.check.verification.manage")
@SLog(tag = "核对任务", msg = "删除核对任务ID:${args[0]}")
public Result onDelete(String id){
dao.clear(CheckTaskVerification.class, Cnd.where("id", "=", id));
dao.clear(CheckTaskPersonnel.class, Cnd.where("taskId", "=", id));
flowEngine.processInstanceService().deleteProcessInstanceByBusinessKey(id);
dao.clear(CheckTaskVerification.class, Cnd.where(CheckTaskVerification::getId, "=", id));
dao.clear(CheckTaskPersonnel.class, Cnd.where(CheckTaskPersonnel::getTaskId, "=", id));
dao.clear(CheckTaskFiledConfig.class, Cnd.where(CheckTaskFiledConfig::getTaskId, "=", id));
return Result.success();
}
@@ -54,7 +54,7 @@ public class CheckTaskPersonnel extends BaseModel {
@Column
@Comment("动态扩展字段(用户表其余列)")
@ColDefine(type = ColType.MYSQL_JSON)
private List<NutMap> data;
private NutMap data;
@Column
@Default("0")
@@ -52,6 +52,11 @@ public class CheckTaskVerification extends BaseModel {
@ColDefine(type = ColType.VARCHAR, width = 255)
private String fileName;
@Column
@Comment("文件路径")
@ColDefine(type = ColType.VARCHAR, width = 255)
private String filePath;
@Column
@Comment("开始时间")
@ColDefine(type = ColType.DATETIME)
@@ -11,10 +11,13 @@ import com.budwk.app.zhgh.staffmanage.personnelcheck.service.CheckTaskCommonServ
import org.apache.poi.ss.formula.functions.T;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.random.R;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.upload.TempFile;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @version 1.0
@@ -37,16 +40,66 @@ public class CheckTaskCommonServiceImpl extends BaseServiceImpl<CheckTaskPersonn
EasyExcel.read(file.getInputStream(), listener)
.sheet()
.headRowNumber(0)
.doRead();
// 表格数据列
List<NutMap> dataList = listener.getDataList();
// 处理fieldConfig中存储的字段名称和字段代码
List<NutMap> result = convertExcelHeadersToFieldCodes(dataList, fieldConfig);
// 上面取到的result,需要转换成CheckTaskPersonnel插入数据库
List<CheckTaskPersonnel> personnelList = result.stream().map(item -> {
CheckTaskPersonnel personnel = new CheckTaskPersonnel();
personnel.setId(R.UU32());
// 工号是必须的,所以不能为空
personnel.setLoginname(item.getString("loginname"));
personnel.setTaskId(fieldConfig.get(0).getTaskId());
personnel.setData(item);
// 设置默认的当前步骤
personnel.setCurrentStep("待核对");
return personnel;
}).toList();
return personnelList;
} catch (Exception e) {
e.printStackTrace();
return null;
}
return null;
}
/**
* 将 Excel 表头转换为字段代码
*
* @param excelData Excel 表数据
* @param fieldConfigs 字段配置列表
* @return 转换后的数据
*/
public static List<NutMap> convertExcelHeadersToFieldCodes(
List<NutMap> excelData,
List<CheckTaskFiledConfig> fieldConfigs) {
Map<String, String> headerToCode = fieldConfigs.stream()
.collect(Collectors.toMap(
CheckTaskFiledConfig::getFieldName,
CheckTaskFiledConfig::getFieldCode,
(a, b) -> a // 保留第一个
));
return excelData.stream().map(original -> {
NutMap converted = new NutMap();
original.forEach((header, value) -> {
String code = headerToCode.get(header);
if (code != null) {
converted.put(code, value);
}
// 否则忽略或保留,按需
});
return converted;
}).collect(Collectors.toList());
}
}
@@ -21,23 +21,24 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true)
public class CheckTaskCommonPageForm extends PageForm {
// 工会id
@ApiModelProperty("事项id")
private String taskId;
@ApiModelProperty("事项CODE")
private String taskCode;
@ApiModelProperty("工会id")
private String unionId;
// 单位id
@ApiModelProperty("单位id")
private String unitId;
// 在职状态
@ApiModelProperty("在职状态")
private List<String> userStates;
// 在职状态
@ApiModelProperty("编制类别")
private List<String> preparedBys;
// 教职工类别
@ApiModelProperty("教职工类别")
private List<String> personTypes;