This commit is contained in:
Timer
2026-04-21 23:45:48 +08:00
parent 6738104534
commit 2ca6153cda
4 changed files with 650 additions and 515 deletions

View File

@ -222,18 +222,50 @@ public class SafetyCertificateController {
@RequestMapping("/deletes.do")
@Transactional(rollbackFor = Exception.class)
public String delete(HttpServletRequest request, Model model, String[] ids) throws IOException {
public String delete(HttpServletRequest request, Model model,
@RequestParam(value = "ids", required = false) String ids,
@RequestParam(value = "staffIds", required = false) String staffIds) throws IOException {
int result = 0;
for (String id : ids) {
// 兼容:支持 ids/staffIds 传 CSV也支持重复参数数组
Set<String> idSet = new LinkedHashSet<>(parseRequestIds(request, "ids", ids));
idSet.addAll(parseRequestIds(request, "staffIds", staffIds));
for (String id : idSet) {
result += service.deleteById(id);
}
for (String id : ids) {
safetyFilesService.deleteByBizId(id);
}
model.addAttribute("result", result);
return "result";
}
private List<String> parseRequestIds(HttpServletRequest request, String paramName, String rawIds) {
List<String> result = new ArrayList<>(parseIdTokens(rawIds));
String[] values = request.getParameterValues(paramName);
if (values != null) {
for (String value : values) {
result.addAll(parseIdTokens(value));
}
}
return result;
}
private List<String> parseIdTokens(String rawIds) {
List<String> result = new ArrayList<>();
if (org.apache.commons.lang3.StringUtils.isBlank(rawIds) || "null".equals(rawIds)) {
return result;
}
String[] split = rawIds.split(",");
for (String id : split) {
String value = org.apache.commons.lang3.StringUtils.trim(id);
if (org.apache.commons.lang3.StringUtils.isNotBlank(value) && value.matches("^[0-9A-Za-z_-]+$")) {
result.add(value);
}
}
return result;
}
/**
* 跳转导入页面
*

View File

@ -339,16 +339,39 @@ public class SafetyExternalCertificateController {
@RequestMapping("/deletes.do")
@Transactional(rollbackFor = Exception.class)
public String delete(HttpServletRequest request, Model model, String[] ids) throws IOException {
public String delete(HttpServletRequest request, Model model,
@RequestParam(value = "ids", required = false) String ids,
@RequestParam(value = "staffIds", required = false) String staffIds) throws IOException {
int result = 0;
for (String id : ids) {
// 兼容:支持 ids/staffIds 传 CSV也支持重复参数数组
Set<String> certificateIdSet = new LinkedHashSet<>(parseRequestIds(request, "ids", ids));
Set<String> staffIdSet = new LinkedHashSet<>(parseRequestIds(request, "staffIds", staffIds));
for (String id : certificateIdSet) {
result += service.deleteById(id);
safetyFilesService.deleteByBizId(id);
}
for (String staffId : staffIdSet) {
safetyExternalStaffService.deleteById(staffId);
}
model.addAttribute("result", result);
return "result";
}
private List<String> parseRequestIds(HttpServletRequest request, String paramName, String rawIds) {
List<String> result = new ArrayList<>(parseExportIds(rawIds));
String[] values = request.getParameterValues(paramName);
if (values != null) {
for (String value : values) {
result.addAll(parseExportIds(value));
}
}
return result;
}
/**
* 跳转导入页面
*
@ -536,67 +559,61 @@ public class SafetyExternalCertificateController {
public void export(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "issueDate", required = false) String issueDate,
@RequestParam(value = "jobType", required = false) String jobType,
@RequestParam(value = "companyParam", required = false) String companyParam) throws IOException {
// 摘自列表查询接口 start
User cu = (User) request.getSession().getAttribute("cu");
@RequestParam(value = "companyParam", required = false) String companyParam,
@RequestParam(value = "search_name", required = false) String searchName,
@RequestParam(value = "ids", required = false) String ids,
@RequestParam(value = "staffIds", required = false) String staffIds) throws IOException {
// 与列表接口保持一致,避免“页面有数据但导出为空”
String sort = " sc.userid, sc.create_time ";
String order = " desc ";
String orderstr = " order by " + sort + " " + order;
String wherestr = " where flag='2' ";
if (request.getParameter("search_code") != null && !request.getParameter("search_code").isEmpty()) {
List<Unit> unitlist = unitService.getUnitChildrenById(request.getParameter("search_code"));
String pidstr = "";
for (int i = 0; i < unitlist.size(); i++) {
pidstr += "'" + unitlist.get(i).getId() + "',";
}
if (pidstr != "") {
pidstr = pidstr.substring(0, pidstr.length() - 1);
wherestr += "and u.pid in (" + pidstr + ") ";
}
} else {
Company company = unitService.getCompanyByUserId(cu.getId());
String companyId = "-1";
if (company != null) {
companyId = company.getId();
}
List<User> users = unitService.getChildrenUsersById(companyId);
String userIds = "";
for (User user : users) {
if (!userIds.isEmpty()) {
userIds += "','";
}
userIds += user.getId();
}
if (!userIds.isEmpty()) {
wherestr += "and u.id in ('" + userIds + "') ";
}
}
String wherestr = " where 1=1 ";
// 搜索框筛选
if (request.getParameter("search_name") != null && !request.getParameter("search_name").isEmpty()) {
wherestr += " and (sc.certificate_name like '%" + request.getParameter("search_name") + "%'" +
" or ses.name like '%" + request.getParameter("search_name") + "%')";
if (StringUtils.isNotBlank(searchName)) {
wherestr += " and (sc.certificate_name like '%" + searchName + "%'" +
" or ses.name like '%" + searchName + "%')";
}
// 领证时间筛选
if (StringUtils.isNotBlank(issueDate) && !"null".equals(issueDate)) {
String[] split = issueDate.split("~");
String issueDate_param_start_time = split[0].trim();
String issueDate_param_end_time = split[1].trim();
wherestr += " and sc.issue_date >= '" + issueDate_param_start_time + "'" +
" and sc.issue_date <= '" + issueDate_param_end_time + "'";
if (split.length == 2) {
String issueDate_param_start_time = split[0].trim();
String issueDate_param_end_time = split[1].trim();
wherestr += " and sc.issue_date >= '" + issueDate_param_start_time + "'" +
" and sc.issue_date <= '" + issueDate_param_end_time + "'";
}
}
//作业类型
// 作业类型
if (StringUtils.isNotBlank(jobType) && !"null".equals(jobType)) {
wherestr += " and sc.job_type = '" + jobType + "'";
}
//施工单位
// 施工单位
if (StringUtils.isNotBlank(companyParam) && !"null".equals(companyParam)) {
wherestr += " and ses.company = '" + companyParam + "'";
}
// 勾选导出:有勾选则仅导出勾选数据;无勾选则按筛选条件导出全部
List<String> certificateIdList = parseExportIds(ids);
List<String> staffIdList = parseExportIds(staffIds);
if (!CollectionUtils.isEmpty(certificateIdList) || !CollectionUtils.isEmpty(staffIdList)) {
StringBuilder selectedWhere = new StringBuilder(" and (");
if (!CollectionUtils.isEmpty(certificateIdList)) {
selectedWhere.append("sc.id in (").append(joinForSqlIn(certificateIdList)).append(")");
}
if (!CollectionUtils.isEmpty(staffIdList)) {
if (!CollectionUtils.isEmpty(certificateIdList)) {
selectedWhere.append(" or ");
}
selectedWhere.append("ses.id in (").append(joinForSqlIn(staffIdList)).append(")");
}
selectedWhere.append(")");
wherestr += selectedWhere;
}
List<SafetyExternalCertificateVo> list = this.service.selectListByConditionForExternal(wherestr + orderstr);
List<SafetyExternalCertificateExcel> excelList = new ArrayList<>();
SafetyExternalCertificateExcel excelEntity = null;
@ -605,7 +622,7 @@ public class SafetyExternalCertificateController {
BeanUtils.copyProperties(vo, excelEntity);
excelList.add(excelEntity);
}
// 摘自列表查询接口 end
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf8");
response.setHeader("Content-disposition", "attachment;filename=" + java.net.URLEncoder.encode("外部人员证书信息", "UTF-8") + ".xlsx");
@ -616,4 +633,31 @@ public class SafetyExternalCertificateController {
excelWriter.finish();
}
}
private List<String> parseExportIds(String rawIds) {
List<String> result = new ArrayList<>();
if (StringUtils.isBlank(rawIds) || "null".equals(rawIds)) {
return result;
}
String[] split = rawIds.split(",");
for (String id : split) {
String value = StringUtils.trim(id);
// 仅保留安全字符,避免拼接 SQL 时引入非法字符
if (StringUtils.isNotBlank(value) && value.matches("^[0-9A-Za-z_-]+$")) {
result.add(value);
}
}
return result;
}
private String joinForSqlIn(List<String> idList) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < idList.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append("'").append(idList.get(i)).append("'");
}
return sb.toString();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -129,11 +129,17 @@
};
var deletesFun = function () {
var checkedItems = $("#table").bootstrapTable('getSelections');
var datas = "";
var ids = [];
var staffIds = [];
$.each(checkedItems, function (index, item) {
datas += item.id + ",";
if (item.id) {
ids.push(item.id);
} else if (item.staffId) {
// 兼容模式若后续行模型提供备用ID批删也可工作
staffIds.push(item.staffId);
}
});
if (datas == "") {
if (ids.length === 0 && staffIds.length === 0) {
showAlert('d', '请先选择记录', 'mainAlertdiv');
} else {
swal({
@ -157,7 +163,10 @@
}
}).then(function (willDelete) {
if (willDelete) {
$.post(ext.contextPath + '/safety/internalCertificate/deletes.do', {ids: datas}, function (data) {
$.post(ext.contextPath + '/safety/internalCertificate/deletes.do', {
ids: ids.join(","),
staffIds: staffIds.join(",")
}, function (data) {
if (data > 0) {
$("#table").bootstrapTable('refresh');
// 初始化 作业类型
@ -313,17 +322,17 @@
field: 'jobType', // 返回json数据中的name
title: '作业类型', // 表格表头显示文字
align: 'center', // 左右居中
valign: 'middle', // 上下居中
valign: 'middle' // 上下居中
}, {
field: 'issuingAuthority', // 返回json数据中的name
title: '发证机构', // 表格表头显示文字
align: 'center', // 左右居中
valign: 'middle', // 上下居中
valign: 'middle' // 上下居中
}, {
field: 'issueDate', // 返回json数据中的name
title: '领证时间', // 表格表头显示文字
align: 'center', // 左右居中
valign: 'middle', // 上下居中
valign: 'middle' // 上下居中
}, {
field: 'expirationDate', // 返回json数据中的name
title: '有效期至', // 表格表头显示文字