一、原数据查询格式
{
"total": 27,
"rows": [
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:38",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:38",
"id": 425,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期四",
"bclb": "白班",
"banciT": "江苏0830-1730",
"pdate": "08:30-17:30",
"ptime": "12:30-13:30",
"btime": "07:56",
"etime": "21:32",
"znote": null,
"zdkxq": "07:56,08:14,20:02,21:32",
"zthsb": null,
"fadate": "20240201",
"wdate": "2024-02-04 04:31:55",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:38",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:38",
"id": 1605,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期五",
"bclb": "白班",
"banciT": "江苏0830-1730",
"pdate": "08:30-17:30",
"ptime": "12:30-13:30",
"btime": "08:15",
"etime": "17:55",
"znote": null,
"zdkxq": "08:15,17:55",
"zthsb": null,
"fadate": "20240202",
"wdate": "2024-02-05 04:31:52",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:38",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:38",
"id": 2802,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期六",
"bclb": "白班",
"banciT": "江苏0830-1730",
"pdate": "08:30-17:30",
"ptime": "12:30-13:30",
"btime": "07:51",
"etime": "17:32",
"znote": null,
"zdkxq": "07:51,17:32",
"zthsb": null,
"fadate": "20240203",
"wdate": "2024-02-06 04:31:42",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:38",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:38",
"id": 3274,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期日",
"bclb": "休息",
"banciT": "江苏0830-1730假",
"pdate": null,
"ptime": "00:00-08:30,12:30-13:30,17:30-18:00",
"btime": null,
"etime": null,
"znote": null,
"zdkxq": null,
"zthsb": null,
"fadate": "20240204",
"wdate": "2024-02-07 04:31:37",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:38",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:38",
"id": 4156,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期一",
"bclb": "白班",
"banciT": "江苏0830-1730",
"pdate": "08:30-17:30",
"ptime": "12:30-13:30",
"btime": "08:11",
"etime": "18:58",
"znote": null,
"zdkxq": "08:11,18:58",
"zthsb": null,
"fadate": "20240205",
"wdate": "2024-02-08 04:31:51",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:38",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:38",
"id": 5219,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期二",
"bclb": "白班",
"banciT": "江苏0830-1730",
"pdate": "08:30-17:30",
"ptime": "12:30-13:30",
"btime": "08:04",
"etime": "17:31",
"znote": null,
"zdkxq": "08:04,08:24",
"zthsb": "是",
"fadate": "20240206",
"wdate": "2024-02-09 04:31:53",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:38",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:38",
"id": 6393,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期三",
"bclb": "休息",
"banciT": "江苏0830-1730假",
"pdate": null,
"ptime": "00:00-08:30,12:30-13:30,17:30-18:00",
"btime": null,
"etime": null,
"znote": null,
"zdkxq": null,
"zthsb": null,
"fadate": "20240207",
"wdate": "2024-02-10 04:31:40",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:38",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:38",
"id": 6789,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期四",
"bclb": "休息",
"banciT": "江苏0830-1730假",
"pdate": null,
"ptime": "00:00-08:30,12:30-13:30,17:30-18:00",
"btime": null,
"etime": null,
"znote": null,
"zdkxq": null,
"zthsb": null,
"fadate": "20240208",
"wdate": "2024-02-11 04:31:33",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:39",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:39",
"id": 7685,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期五",
"bclb": "休息",
"banciT": "江苏0830-1730假",
"pdate": null,
"ptime": "00:00-08:30,12:30-13:30,17:30-18:00",
"btime": null,
"etime": null,
"znote": null,
"zdkxq": null,
"zthsb": null,
"fadate": "20240209",
"wdate": "2024-02-12 04:31:55",
"delFlag": "0"
},
{
"createBy": "Task",
"createName": "Task",
"createTime": "2024-02-28T08:55:39",
"updateBy": "Task",
"updateName": "Task",
"updateTime": "2024-02-28T08:55:39",
"id": 8407,
"pernr": "139000",
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": "星期六",
"bclb": "休息",
"banciT": "江苏0830-1730假",
"pdate": null,
"ptime": "00:00-08:30,12:30-13:30,17:30-18:00",
"btime": null,
"etime": null,
"znote": null,
"zdkxq": null,
"zthsb": null,
"fadate": "20240210",
"wdate": "2024-02-13 04:31:34",
"delFlag": "0"
}
],
"code": 200,
"msg": "查询成功"
}
原数据格式为每条显示,但数据中有很多重复的信息 需要分组显示如下列格式:
{
"total": 1,
"rows": [
{
"pnalt": "139000",
"name": "陈sir",
"gender": "男",
"orgeh": "开发部",
"rmark": null,
"bclb": null,
"btime": null,
"etime": null,
"fadate": null,
"info": [
{
"20240201": {
"btime": "07:56",
"rmark": "星期四",
"etime": "21:32",
"bclb": "白班"
}
},
{
"20240202": {
"btime": "08:15",
"rmark": "星期五",
"etime": "17:55",
"bclb": "白班"
}
},
{
"20240203": {
"btime": "07:51",
"rmark": "星期六",
"etime": "17:32",
"bclb": "白班"
}
},
{
"20240204": {
"btime": "null",
"rmark": "星期日",
"etime": "null",
"bclb": "休息"
}
},
{
"20240205": {
"btime": "08:11",
"rmark": "星期一",
"etime": "18:58",
"bclb": "白班"
}
},
{
"20240206": {
"btime": "08:04",
"rmark": "星期二",
"etime": "17:31",
"bclb": "白班"
}
},
{
"20240207": {
"btime": "null",
"rmark": "星期三",
"etime": "null",
"bclb": "休息"
}
},
{
"20240208": {
"btime": "null",
"rmark": "星期四",
"etime": "null",
"bclb": "休息"
}
},
{
"20240209": {
"btime": "null",
"rmark": "星期五",
"etime": "null",
"bclb": "休息"
}
},
{
"20240210": {
"btime": "null",
"rmark": "星期六",
"etime": "null",
"bclb": "休息"
}
},
{
"20240211": {
"btime": "null",
"rmark": "星期日",
"etime": "null",
"bclb": "休息"
}
},
{
"20240212": {
"btime": "null",
"rmark": "星期一",
"etime": "null",
"bclb": "休息"
}
},
{
"20240213": {
"btime": "null",
"rmark": "星期二",
"etime": "null",
"bclb": "休息"
}
},
{
"20240214": {
"btime": "null",
"rmark": "星期三",
"etime": "null",
"bclb": "休息"
}
},
{
"20240215": {
"btime": "null",
"rmark": "星期四",
"etime": "null",
"bclb": "休息"
}
},
{
"20240216": {
"btime": "null",
"rmark": "星期五",
"etime": "null",
"bclb": "休息"
}
},
{
"20240217": {
"btime": "null",
"rmark": "星期六",
"etime": "null",
"bclb": "休息"
}
},
{
"20240218": {
"btime": "null",
"rmark": "星期日",
"etime": "null",
"bclb": "白班"
}
},
{
"20240219": {
"btime": "null",
"rmark": "星期一",
"etime": "null",
"bclb": "白班"
}
},
{
"20240220": {
"btime": "08:29",
"rmark": "星期二",
"etime": "20:00",
"bclb": "白班"
}
},
{
"20240221": {
"btime": "08:25",
"rmark": "星期三",
"etime": "20:08",
"bclb": "白班"
}
},
{
"20240222": {
"btime": "08:12",
"rmark": "星期四",
"etime": "20:27",
"bclb": "白班"
}
},
{
"20240223": {
"btime": "08:13",
"rmark": "星期五",
"etime": "20:13",
"bclb": "白班"
}
},
{
"20240224": {
"btime": "08:19",
"rmark": "星期六",
"etime": "18:05",
"bclb": "休息"
}
},
{
"20240225": {
"btime": "null",
"rmark": "星期日",
"etime": "null",
"bclb": "休息"
}
},
{
"20240226": {
"btime": "08:11",
"rmark": "星期一",
"etime": "20:06",
"bclb": "白班"
}
},
{
"20240227": {
"btime": "08:00",
"rmark": "星期二",
"etime": "20:05",
"bclb": "白班"
}
}
]
}
],
"code": 200,
"msg": "查询成功"
}
二、实体类
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AttendanceStructureVo {
private String pnalt;
private String name;
private String gender;
private String orgeh;
private String rmark;
private String bclb;
private String btime;
private String etime;
private String fadate;
private List<Map<String, Map<String, String>>> info;
public AttendanceStructureVo(String pnalt, String name, String gender, String orgeh, List<Map<String, Map<String, String>>> info) {
this.pnalt = pnalt;
this.name = name;
this.gender = gender;
this.orgeh = orgeh;
this.info = info;
}
}
三、代码展示
@Override
public TableDataInfo<AttendanceStructureVo> selectAttendanceGrouping(AttendanceBo bo, PageQuery pageQuery) {
List<AttendanceStructureVo> entityList = bAttendanceMapper.selectAttendanceGrouping(bo);
List<AttendanceStructureVo> result = new ArrayList<>();
if (entityList.size() > 0) {
result = entityList.stream()
.collect(Collectors.groupingBy(AttendanceStructureVo::getPnalt)) // 先按工号分组
.entrySet().stream()
.map(entry -> {
String pnalt = entry.getKey();
List<Map<String, Map<String, String>>> info = entry.getValue().stream()
.collect(Collectors.groupingBy(AttendanceStructureVo::getFadate, LinkedHashMap::new, Collectors.toCollection(LinkedHashSet::new)))
.entrySet().stream()
.map(dateEntry -> {
Map<String, String> mapValue = new HashMap<>();
mapValue.put("bclb", dateEntry.getValue().stream().map(AttendanceStructureVo::getBclb).collect(Collectors.joining(",")));
mapValue.put("rmark", dateEntry.getValue().stream().map(AttendanceStructureVo::getRmark).collect(Collectors.joining(",")));
mapValue.put("btime", dateEntry.getValue().stream().map(AttendanceStructureVo::getBtime).collect(Collectors.joining(",")));
mapValue.put("etime", dateEntry.getValue().stream().map(AttendanceStructureVo::getEtime).collect(Collectors.joining(",")));
Map<String, Map<String, String>> dateInfo = new TreeMap<>();
dateInfo.put(dateEntry.getKey(), mapValue);
return dateInfo;
})
.collect(Collectors.toList());
return new AttendanceStructureVo(pnalt, entry.getValue().get(0).getName(), entry.getValue().get(0).getGender(), entry.getValue().get(0).getOrgeh(), info);
})
.collect(Collectors.toList());
}
Page<AttendanceStructureVo> page = new Page<>();
if (pageQuery.getPageNum() != null && pageQuery.getPageSize() != null) {
page.setCurrent(pageQuery.getPageNum());
page.setSize(pageQuery.getPageSize());
// 手动分页,获取当前页的数据列表
int startIndex = (int) ((page.getCurrent() - 1) * page.getSize());
int endIndex = (int) Math.min(startIndex + page.getSize(), result.size());
List<AttendanceStructureVo> currentList = result.subList(startIndex, endIndex);
// 设置总记录数和当前页数据列表
page.setTotal(result.size());
page.setRecords(currentList);
} else {
page.setRecords(result);
page.setTotal(result.size());
}
return TableDataInfo.build(page);
}