福利收货地址导出

This commit is contained in:
=
2025-12-09 13:56:33 +08:00
parent 075af05eb6
commit b28a3a81c9
5 changed files with 202 additions and 30 deletions
@@ -107,11 +107,19 @@ public class WelfareListController {
return Result.success(); return Result.success();
} }
@At
@SaCheckPermission("welfare.list.mange")
@ApiOperation("导出收货地址")
@Ok("void")
public void exportAddress(WelfareListPageForm pageForm, HttpServletResponse response) {
welfareListService.exportAddress(pageForm, response);
}
@At @At
@SaCheckPermission("welfare.list.mange") @SaCheckPermission("welfare.list.mange")
@ApiOperation("导出") @ApiOperation("导出")
@Ok("void") @Ok("void")
public void exportXlsx(@Param("pageForm") WelfareListPageForm pageForm, HttpServletResponse response) { public void exportXlsx(WelfareListPageForm pageForm, HttpServletResponse response) {
welfareListService.exportXlsx(pageForm, response); welfareListService.exportXlsx(pageForm, response);
} }
@@ -7,6 +7,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Date; import java.util.Date;
import java.util.Map;
import java.util.List;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
@@ -55,4 +57,7 @@ public class WelfareListPageForm extends PageForm {
@ApiModelProperty("在职状态") @ApiModelProperty("在职状态")
private String[] userStates; private String[] userStates;
@ApiModelProperty("导出的数据")
private List<Map<String, String>> columns;
} }
@@ -46,6 +46,13 @@ public interface WelfareListService extends BaseService<WelfareList> {
*/ */
void addWelfareUser(WelfareFilterUserPageForm pageForm); void addWelfareUser(WelfareFilterUserPageForm pageForm);
/**
* 导出收货地址
* @param pageForm
* @param response
*/
void exportAddress(WelfareListPageForm pageForm, HttpServletResponse response);
/** /**
* 导出 * 导出
* @param pageForm * @param pageForm
@@ -553,6 +553,82 @@ public class WelfareListServiceImpl extends BaseServiceImpl<WelfareList> impleme
dao().insert(welfareList); dao().insert(welfareList);
} }
@Override
public void exportAddress(WelfareListPageForm pageForm, HttpServletResponse response) {
Sql sql = Sqls.create("""
SELECT
t1.*,
t2.loginname,
t2.username,
t2.sex,
DATE_FORMAT(t2.birthday, '%Y-%m-%d') AS birthday,
CONCAT('收货人:',t3.userName,' 电话:',t3.tel,' 详细地址:',t3.province, t3.city, t3.county, t3.addressDetail) AS address
FROM
`welfare_list` t1
LEFT JOIN sys_user t2 ON t2.id = t1.userId
LEFT JOIN (
SELECT
userId,
userName,
tel,
province,
city,
county,
addressDetail,
ROW_NUMBER() OVER (PARTITION BY userId ORDER BY isDefault DESC, id) as rn
FROM welfare_member_address
) t3 ON t3.userId = t1.userId AND t3.rn = 1
$condition
""");
Cnd cnd = Cnd.NEW();
cnd.and("t1.projectId", "=", pageForm.getProjectId());
if (StrUtil.isNotBlank(pageForm.getUserName())) {
cnd.where().andLike("t2.username", pageForm.getUserName());
}
if (StrUtil.isNotBlank(pageForm.getLoginName())) {
cnd.where().andLike("t2.loginname", pageForm.getLoginName());
}
cnd.andEX("t2.sex", "=", pageForm.getSex());
cnd.andEX("t2.birthday", "=", pageForm.getBirthday());
if (pageForm.getBirthMonths() != null && pageForm.getBirthMonths().length > 0) {
cnd.andEX("MONTH(t2.birthday)", "in", pageForm.getBirthMonths());
}
cnd.andEX("t1.welfareUnitId", "in", pageForm.getUnitIds());
cnd.andEX("t1.welfareUnionId", "=", pageForm.getUnionId());
cnd.andEX("t1.personType", "in", pageForm.getPersonTypes());
cnd.andEX("t1.preparedBy", "in", pageForm.getPreparedBys());
cnd.andEX("t1.userState", "in", pageForm.getUserStates());
if (StrUtil.isAllBlank(pageForm.getPageOrderName(), pageForm.getPageOrderBy())) {
cnd.asc("t1.welfareUnionName");
cnd.asc("t1.welfareUnitName");
} else {
cnd.orderBy(pageForm.getPageOrderName(), PageUtil.getOrder(pageForm.getPageOrderBy()));
}
sql.setCondition(cnd);
List<NutMap> list = listMap(sql);
try {
Workbook workbook = null;
List<ExcelExportEntity> exportEntities = new ArrayList<>();
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
exportEntities.add(new ExcelExportEntity("收货地址", "address", 70));
exportEntities.add(new ExcelExportEntity("所属工会", "welfareUnionName", 20));
exportEntities.add(new ExcelExportEntity("所属单位", "welfareUnitName", 30));
ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.XSSF);
workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
CommonDownloadUtil.download("收货地址汇总.xlsx", workbook, response);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override @Override
public void exportXlsx(WelfareListPageForm pageForm, HttpServletResponse response) { public void exportXlsx(WelfareListPageForm pageForm, HttpServletResponse response) {
Sql sql = Sqls.create(""" Sql sql = Sqls.create("""
@@ -596,26 +672,46 @@ public class WelfareListServiceImpl extends BaseServiceImpl<WelfareList> impleme
sql.setCondition(cnd); sql.setCondition(cnd);
List<NutMap> list = listMap(sql); List<NutMap> list = listMap(sql);
List<ExcelExportEntity> entities = new ArrayList<>(); try {
entities.add(new ExcelExportEntity("工号", "loginname", 20)); Workbook workbook = null;
entities.add(new ExcelExportEntity("姓名", "username", 20)); if (Lang.isNotEmpty(pageForm.getColumns())) {
entities.add(new ExcelExportEntity("性别", "sex", 20)); List<ExcelExportEntity> exportEntities = new ArrayList<>();
entities.add(new ExcelExportEntity("出生日期", "birthday", 20));
entities.add(new ExcelExportEntity("人员类型", "personType", 20)); pageForm.getColumns().forEach(column -> {
entities.add(new ExcelExportEntity("聘用方式", "preparedBy", 20)); exportEntities.add(new ExcelExportEntity(column.get("label"), column.get("prop"), 20));
entities.add(new ExcelExportEntity("在职状态", "userState", 20)); });
entities.add(new ExcelExportEntity("所属工会", "welfareUnionName", 20)); ExportParams exportParams = new ExportParams();
entities.add(new ExcelExportEntity("所属单位", "welfareUnitName", 20)); exportParams.setType(ExcelType.XSSF);
entities.add(new ExcelExportEntity("备注", "remark", 20));
workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
} else {
workbook = setHistoryExcelData(list);
}
// 设置导出参数
ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.XSSF);
// 导出Excel并下载
try (Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entities, list)) {
CommonDownloadUtil.download("福利名单.xlsx", workbook, response); CommonDownloadUtil.download("福利名单.xlsx", workbook, response);
} catch (Exception e) { } catch (Exception e) {
log.error("导出Excel失败", e); e.printStackTrace();
} }
} }
public Workbook setHistoryExcelData(List<NutMap> list) {
List<ExcelExportEntity> exportEntities = new ArrayList<>();
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
exportEntities.add(new ExcelExportEntity("联系电话", "mobile", 20));
exportEntities.add(new ExcelExportEntity("身份证号", "idCard", 30));
exportEntities.add(new ExcelExportEntity("在职状态", "userState", 20));
exportEntities.add(new ExcelExportEntity("聘用方式", "preparedBy", 20));
exportEntities.add(new ExcelExportEntity("人员类型", "personType", 20));
exportEntities.add(new ExcelExportEntity("所属工会", "unionName", 20));
exportEntities.add(new ExcelExportEntity("所属单位", "unitName", 30));
// exportEntities.add(new ExcelExportEntity("来校年月", "comeSchoolDate", 30));
// exportEntities.add(new ExcelExportEntity("所在科室", "threeUnitName", 20));
// exportEntities.add(new ExcelExportEntity("工会小组", "unionGroupName", 30));
ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.XSSF);
return ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
}
} }
@@ -130,6 +130,9 @@ layout("/layouts/platform.html"){
<el-card class="mt10" shadow="never"> <el-card class="mt10" shadow="never">
<table-tool :app="this" label="福利名单"> <table-tool :app="this" label="福利名单">
<el-button :disabled="!pageForm.projectId" @click="exportAddress" icon="el-icon-download" size="small" type="primary">
导出收货地址
</el-button>
<el-button :disabled="!pageForm.projectId" @click="openExport" icon="el-icon-download" size="small" type="primary"> <el-button :disabled="!pageForm.projectId" @click="openExport" icon="el-icon-download" size="small" type="primary">
导出名单 导出名单
</el-button> </el-button>
@@ -145,6 +148,38 @@ layout("/layouts/platform.html"){
> >
添加人员 添加人员
</el-button> </el-button>
<el-popover
placement="bottom"
trigger="click"
width="200">
<div style="padding:4px 0;border-bottom:1px solid #eee;">
<el-button size="mini" @click="checkAll">全选</el-button>
<el-button size="mini" @click="invertCheck">反选</el-button>
</div>
<div style="max-height:40vh;overflow-y:auto;padding:6px 0;">
<el-checkbox-group v-model="checkedFields">
<el-checkbox
v-for="f in tableColumns"
:key="f.prop"
:label="f.prop"
style="display:block;margin:6px 0;">
{{ f.label }}
</el-checkbox>
</el-checkbox-group>
</div>
<el-button
slot="reference"
type="text"
icon="el-icon-s-operation"
size="small"
style="margin-left:12px;">
列设置
</el-button>
</el-popover>
</table-tool> </table-tool>
<el-table <el-table
@@ -159,15 +194,16 @@ layout("/layouts/platform.html"){
<el-table-column :index="indexMethod" label="序号" type="index" width="80px"></el-table-column> <el-table-column :index="indexMethod" label="序号" type="index" width="80px"></el-table-column>
<el-table-column <el-table-column
:key="column.prop" v-if="checkedFields.includes(column.prop)"
:label="column.label" :key="column.prop"
:prop="column.prop" :label="column.label"
:sortable="column.sortable" :prop="column.prop"
:width="column.width" :sortable="column.sortable"
align="center" :width="column.width"
header-align="center" align="center"
show-overflow-tooltip header-align="center"
v-for="column in tableColumns" show-overflow-tooltip
v-for="column in tableColumns"
> >
<template scope="{row}" v-if="column.prop=='isChoose'"> <template scope="{row}" v-if="column.prop=='isChoose'">
<span class="text-primary" v-if="row.isChoose">已选择</span> <span class="text-primary" v-if="row.isChoose">已选择</span>
@@ -241,8 +277,14 @@ layout("/layouts/platform.html"){
return null return null
} }
return null return null
},
showColumns() {
return this.tableColumns.filter(c => this.checkedFields.includes(c.prop));
} }
}, },
mounted() {
this.checkedFields = this.tableColumns.filter(c => c.checked !== 0).map(c => c.prop);
},
components: { components: {
add_welfare_list_by_select: ADD_WELFARE_LIST_BY_SELECT, add_welfare_list_by_select: ADD_WELFARE_LIST_BY_SELECT,
"file-import": httpVueLoader("/components/plugins/sysImport/index.vue?v=" + new Date().getTime()), "file-import": httpVueLoader("/components/plugins/sysImport/index.vue?v=" + new Date().getTime()),
@@ -251,6 +293,7 @@ layout("/layouts/platform.html"){
}, },
data() { data() {
return { return {
checkedFields: [],
pageForm: { pageForm: {
searchName: "username", searchName: "username",
year: new Date().getFullYear().toString() year: new Date().getFullYear().toString()
@@ -282,13 +325,26 @@ layout("/layouts/platform.html"){
} }
}, },
methods: { methods: {
// 导出收货地址
exportAddress() {
this.$downLoad("/platform/welfare/list/mange/exportAddress", this.pageForm)
},
// 导出名单 // 导出名单
openExport() { openExport() {
this.$downLoad("/platform/welfare/list/mange/exportXlsx", { const pageForm = clone(this.pageForm)
pageForm: JSON.stringify(this.pageForm) const data = this.tableColumns.filter(item => this.checkedFields.includes(item.prop)).map(item => {
return {prop: item.prop, label: item.label}
}) })
pageForm.columns = JSON.stringify(data)
this.$downLoad("/platform/welfare/list/mange/exportXlsx", pageForm)
},
checkAll() {
this.checkedFields = this.tableColumns.map(c => c.prop);
},
invertCheck() {
const all = this.tableColumns.map(c => c.prop);
this.checkedFields = all.filter(p => !this.checkedFields.includes(p));
}, },
successImport() { successImport() {
this.doSearch() this.doSearch()
this.importDialog = false this.importDialog = false