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,56 +559,32 @@ 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("~");
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)) {
@ -597,6 +596,24 @@ public class SafetyExternalCertificateController {
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();
}
}

View File

@ -55,6 +55,7 @@
.table-hover > tbody > tr:hover {
cursor: pointer;
}
.input-clear-a {
color: white;
@ -143,11 +144,15 @@
}
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);
staffIds.push(item.staffId || "");
}
});
if (datas == "") {
if (ids.length === 0 && staffIds.length === 0) {
showAlert('d', '请先选择记录', 'mainAlertdiv');
} else {
swal({
@ -171,7 +176,10 @@
}
}).then(function (willDelete) {
if (willDelete) {
$.post(ext.contextPath + '/safety/externalCertificate/deletes.do', {ids: datas}, function (data) {
$.post(ext.contextPath + '/safety/externalCertificate/deletes.do', {
ids: ids.join(","),
staffIds: staffIds.join(",")
}, function (data) {
if (data > 0) {
$("#table").bootstrapTable('refresh');
// 初始化 作业类型
@ -204,11 +212,24 @@
var companyParam = $('#companyParam').val();
var issueDate = $('#reservationtimeD').val();
window.open(ext.contextPath + "/safety/externalCertificate/exportExcel.do?search_name=" + search_name
+ "&search_code=" + search_code
+ "&jobType=" + jobType
+ "&issueDate=" + issueDate
+ "&companyParam=" + companyParam
var checkedItems = $("#table").bootstrapTable('getSelections');
var ids = [];
var staffIds = [];
$.each(checkedItems, function (index, item) {
if (item.id) {
ids.push(item.id);
} else if (item.staffId) {
staffIds.push(item.staffId);
}
});
window.open(ext.contextPath + "/safety/externalCertificate/exportExcel.do?search_name=" + encodeURIComponent(search_name || "")
+ "&search_code=" + encodeURIComponent(search_code || "")
+ "&jobType=" + encodeURIComponent(jobType || "")
+ "&issueDate=" + encodeURIComponent(issueDate || "")
+ "&companyParam=" + encodeURIComponent(companyParam || "")
+ "&ids=" + encodeURIComponent(ids.join(","))
+ "&staffIds=" + encodeURIComponent(staffIds.join(","))
);
}
@ -234,6 +255,7 @@
// 初始化 表格数据
initFun();
});
// 时间筛选
function initDate1() {
var locale = {
@ -288,6 +310,7 @@
}
});
}
//作业类型下拉数据
function jobTypePulldown() {
//选择 从事岗位
@ -316,6 +339,7 @@
});
}, 'json');
}
//施工单位下拉数据
function companyPulldown() {
$.post(ext.contextPath + "/safety/externalStaff/companyPulldown.do", {}, function (data) {
@ -343,6 +367,7 @@
});
}, 'json');
}
// 初始表格
var nowDate = new Date();
var initFun = function () {
@ -391,17 +416,17 @@
field: 'company', // 返回json数据中的name
title: '施工单位名称', // 表格表头显示文字
align: 'center', // 左右居中
valign: 'middle', // 上下居中
valign: 'middle' // 上下居中
}, {
field: 'certificateName', // 返回json数据中的name
title: '证书名称', // 表格表头显示文字
align: 'center', // 左右居中
valign: 'middle', // 上下居中
valign: 'middle' // 上下居中
}, {
field: 'certificateNo', // 返回json数据中的name
title: '证书编号', // 表格表头显示文字
align: 'center', // 左右居中
valign: 'middle', // 上下居中
valign: 'middle' // 上下居中
}, {
field: 'jobCode', // 返回json数据中的name
title: '作业项目代码', // 表格表头显示文字
@ -411,17 +436,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: '有效期至', // 表格表头显示文字
@ -437,10 +462,20 @@
// 计算相差的天数
var days = Math.floor(usedTime / (24 * 3600 * 1000));
if (days <= 30) {
return {css:{"background-color":"rgba(220,29,54,1)","color":"rgba(255,255,255,1)"}};
return {
css: {
"background-color": "rgba(220,29,54,1)",
"color": "rgba(255,255,255,1)"
}
};
}
} else {
return {css:{"background-color":"rgba(220,29,54,1)","color":"rgba(255,255,255,1)"}};
return {
css: {
"background-color": "rgba(220,29,54,1)",
"color": "rgba(255,255,255,1)"
}
};
}
}
return {css: {}};
@ -522,11 +557,22 @@
var index = 0;
for (var prop in sortMap) {
var count = sortMap[prop] * 1;
$(target).bootstrapTable('mergeCells',{index:index, field:fieldName, colspan: colspan, rowspan: count});
$(target).bootstrapTable('mergeCells',{index:index, field:'company', colspan: colspan, rowspan: count});
$(target).bootstrapTable('mergeCells', {
index: index,
field: fieldName,
colspan: colspan,
rowspan: count
});
$(target).bootstrapTable('mergeCells', {
index: index,
field: 'company',
colspan: colspan,
rowspan: count
});
index += count;
}
}
var timedel = function () {
$('#reservationtimeD').val('');
timeRangeEnd = null;
@ -554,10 +600,12 @@
<div>
<div class="form-group" style="padding:0;">
<div class="btn-group" style="width: 300px;padding-bottom:10px;">
<button type="button" class="btn btn-default btn-sm" onclick="addFun();" style="margin-right: 15px"><i
<button type="button" class="btn btn-default btn-sm" onclick="addFun();"
style="margin-right: 15px"><i
class="fa fa-plus"></i> 新增
</button>
<button type="button" class="btn btn-default btn-sm" onclick="deletesFun();" style="margin-right: 15px"><i
<button type="button" class="btn btn-default btn-sm" onclick="deletesFun();"
style="margin-right: 15px"><i
class="fa fa-trash-o"></i> 删除
</button>
<button type="button" class="btn btn-default btn-sm" style="margin-right: 15px"
@ -575,12 +623,14 @@
<div class="form-group pull-right form-inline">
<div class="form-group">
<label class="form-label">施工单位名称:</label>
<select class="form-control select2" id="companyParam" name="companyParam" style="width: 180px;">
<select class="form-control select2" id="companyParam" name="companyParam"
style="width: 180px;">
</select>
</div>
<div class="form-group">
<label class="form-label">作业类型:</label>
<select class="form-control select2" id="jobTypeParam" name="jobTypeParam" style="width: 180px;">
<select class="form-control select2" id="jobTypeParam" name="jobTypeParam"
style="width: 180px;">
</select>
</div>
<div class="input-group input-group-sm" style="width: 200px;">

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: '有效期至', // 表格表头显示文字