关于mybatis-plus单表查询 LambdaQueryWrapper
@Override
public DictMajorGradeResult findByMajorIdAndGrade(String majorId, String grade) {
if (majorId.isEmpty() || grade.isEmpty()) {
throw new ServiceException(500, "专业ID是空");
}
LambdaQueryWrapper<DictMajorGrade> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(DictMajorGrade::getMajorId, majorId)
.eq(DictMajorGrade::getGrade, grade);
DictMajorGrade dictMajorGrade = this.getOne(lambdaQueryWrapper);
if (dictMajorGrade == null) {
throw new ServiceException(500, "找不到专业年级记录,请检查查询条件");
}
DictMajorGradeResult dictMajorGradeResult = new DictMajorGradeResult();
ToolUtil.copyProperties(dictMajorGrade, dictMajorGradeResult);
return dictMajorGradeResult;
}
QueryWrapper<Topic> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("THESIS_SUBMIT_ID", thesisId);
List<Topic> tops = this.topicService.list(queryWrapper);
关于easypoi模板导出案例
@ResponseBody
@RequestMapping("/thesis/export")
public ResponseEntity<InputStreamResource> export() throws IOException {
List<TopicResult> topicResults = this.topicService.thesisExportList();
TemplateExportParams params = new TemplateExportParams(
"templet/thesisTopic.xlsx");
Map<String, Object> map = new HashMap<>();
map.put("maplist", topicResults);
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
HttpServletResponse response = super.getHttpServletResponse();
response.reset();
String fileName = IdWorker.getId()+".xlsx";
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
InputStream is = new ByteArrayInputStream(bos.toByteArray());
return super.renderFile(fileName, is);
}
关于导出按钮的js事件以及url
(注意:在修改完js记得及时清理浏览器缓存)
layui.use(['table', 'admin', 'ax', 'func','layer','form','element'], function () {
var $ = layui.$;
var table = layui.table;
var $ax = layui.ax;
var admin = layui.admin;
var func = layui.func;
var form = layui.form;
var layer = layui.layer;
var element = layui.element;
var load_index;
let cookieName = $('#cookieName').val();
element.render('nav');
var Topic = {
tableId: "topicTable"
};
Topic.initColumn = function () {
return [[
{type: 'checkbox'},
{field: 'seqId', hide: true, title: '主键'},
{field: 'topicName', sort: true, title: '课题名称'},
{field: 'teacherName', sort: true, title: '指导教师'},
{field: 'collegeName', sort: true, title: '学院'},
{field: 'major', sort: true, title: '专业'},
{field: 'studentId', sort: true, title: '学生学号'},
{field: 'studentName', sort: true, title: '学生姓名'},
]];
};
Topic.search = function () {
var queryData = {};
queryData['year'] = $('#YEAR').val();
queryData['studentName'] = $('#studentName').val();
queryData['collegeId'] = $('#collegeId').val();
table.reload(Topic.tableId, {
where: queryData, page: {curr: 1}
});
};
Topic.jumpAddPage = function () {
window.location.href = Feng.ctxPath + '/topic/add'
};
Topic.jumpEditPage = function (data) {
window.location.href = Feng.ctxPath + '/topic/edit?seqId=' + data.seqId
};
Topic.exportExcel = function () {
var checkRows = table.checkStatus(Topic.tableId);
if (checkRows.data.length === 0) {
Feng.error("至少选择一条数据!");
} else {
var ids = '';
for (var i = 0; i < checkRows.data.length; i++) {
ids = ids + checkRows.data[i].thesisSubmitId + ','
}
var cookieValue = 'start';
var Days = 1;
var exp = new Date();
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + exp.toGMTString();
load_index = layer.load(1);
window.location.href = Feng.ctxPath + '/lwxz/plxz?ids=' +ids+ '&cookieName=' + cookieName;
}
};
window.setInterval(function () {
var arr, reg = new RegExp("(^| )" + cookieName + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg)) {
if (arr[2] == 'finish') {
$('#btnExp').removeAttr("disabled");
layer.close(load_index)
} else {
$('#btnExp').attr({"disabled":"disabled"});
}
}
}, 3000);
var tableResult = table.render({
elem: '#' + Topic.tableId,
url: Feng.ctxPath + '/lwxz/list',
page: true,
height: "full-98",
cellMinWidth: 100,
where:{
"year" : $('#YEAR').val()
},
cols: Topic.initColumn()
});
$('#btnSearch').click(function () {
Topic.search();
});
$('#btnReset').click(function () {
$("#YEAR").val($("#yearHidden").val());
$("#collegeId").val('');
$("#studentName").val('');
form.render()
});
$('#btnExp').click(function () {
Topic.exportExcel();
});
$('#btnExpAll').click(function () {
window.location.href = Feng.ctxPath + '/lwxz/thesis/export?year=' + $("#YEAR").val();
});
table.on('tool(' + Topic.tableId + ')', function (obj) {
var data = obj.data;
var layEvent = obj.event;
if (layEvent === 'edit') {
Topic.jumpEditPage(data);
} else if (layEvent === 'delete') {
Topic.onDeleteItem(data);
}
});
});
复制按钮点击事件
WkLeadingGroup.copyYear = function () {
var checkRows = table.checkStatus(WkLeadingGroup.tableId);
if (checkRows.data.length === 0) {
Feng.error("请选择要复制的数据!");
} else {
var ids = '';
var years='';
for(var i=0; i< checkRows.data.length;i++){
ids = ids + checkRows.data[i].staffId + ','
years = years + checkRows.data[i].year+ ','
}
var ajax = new $ax(Feng.ctxPath + "/wkLeadingGroup/copy", function (data) {
Feng.success("复制成功!");
table.reload(WkLeadingGroup.tableId);
}, function (data) {
Feng.error("复制失败!" + data.responseJSON.message+ "!")
});
ajax.set({staffIds: ids});
ajax.set({years: years});
ajax.start();
}
};
$('#btnCopy').click(function () {
WkLeadingGroup.copyYear();
})
后端
@Override
public void copy(WkLeadingGroupParam param) {
String staffIds = param.getStaffIds();
String years = param.getYears();
param.setStaffIdList(Arrays.asList(staffIds.split(",")));
param.setYearList(Arrays.asList(years.split(",")));
List<String> staffIdList = param.getStaffIdList();
List<String> yearList = param.getYearList();
String currentYear = yearManageService.currentYear();
ArrayList<WkLeadingGroup> wkLeadingGroups = new ArrayList<>();
for (int i = 0; i < staffIdList.size(); i++) {
LambdaQueryWrapper<WkLeadingGroup> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(WkLeadingGroup::getStaffId, staffIdList.get(i))
.eq(WkLeadingGroup::getYear,yearList.get(i));
WkLeadingGroup wkLeadingGroup = this.getOne(lambdaQueryWrapper);
wkLeadingGroups.add(wkLeadingGroup);
}
for (WkLeadingGroup wkLeadingGroup : wkLeadingGroups) {
boolean save = this.save(wkLeadingGroup);
}
}