Browse Source

考点考场统计一览表

zhuhaiwen 3 years ago
parent
commit
69a185401e

+ 5 - 0
oa-app/src/main/java/com/css/oa/exam/place/repository/IPlaceRepository.java

@ -35,4 +35,9 @@ public interface IPlaceRepository extends JpaRepository<Place, String>, JpaSpeci
35 35
    @Query("select p from Place p where p.exam_id  = :exam_id")
36 36
    List<Place> findAllByExam_id(String exam_id);
37 37
38
//    @Modifying
39
//    @Transactional
40
//    @Query("select p.uuid from Place p where p.exam_id  = :exam_id")
41
//    List<String> findIdsByExam_id(String exam_id);
42
38 43
}

+ 24 - 0
oa-app/src/main/java/com/css/oa/exam/report/bean/PRExcelEntity.java

@ -0,0 +1,24 @@
1
package com.css.oa.exam.report.bean;
2
3
import cn.afterturn.easypoi.excel.annotation.Excel;
4
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
5
import lombok.Data;
6
7
@Data
8
@ExcelTarget("deptUtil")
9
public class PRExcelEntity {
10
11
    @Excel(name = "考点", width = 20)
12
    private String place_name;
13
14
    @Excel(name = "考场", width = 20)
15
    private String room_name;
16
17
    @Excel(name = "考场可容纳人数")
18
    private int total;
19
20
    @Excel(name = "考场已分配人数")
21
    private int assigned_count;
22
23
24
}

+ 7 - 0
oa-app/src/main/java/com/css/oa/exam/report/bean/PRExportReq.java

@ -0,0 +1,7 @@
1
package com.css.oa.exam.report.bean;
2
3
public class PRExportReq {
4
5
    public String exam_id;
6
7
}

+ 11 - 0
oa-app/src/main/java/com/css/oa/exam/report/bean/PRReq.java

@ -0,0 +1,11 @@
1
package com.css.oa.exam.report.bean;
2
3
public class PRReq {
4
5
    public String exam_id;
6
7
    public int curPage;
8
9
    public int pageSize;
10
11
}

+ 33 - 4
oa-app/src/main/java/com/css/oa/exam/report/controller/ReportController.java

@ -2,10 +2,7 @@ package com.css.oa.exam.report.controller;
2 2
3 3
import com.css.oa.exam.assign.bean.AssignExportReq;
4 4
import com.css.oa.exam.base.BaseController;
5
import com.css.oa.exam.report.bean.PRPExportReq;
6
import com.css.oa.exam.report.bean.PRPReq;
7
import com.css.oa.exam.report.bean.UPExportReq;
8
import com.css.oa.exam.report.bean.UPReq;
5
import com.css.oa.exam.report.bean.*;
9 6
import com.css.oa.exam.report.service.ReportService;
10 7
import com.css.oa.utils.Result;
11 8
import io.swagger.annotations.Api;
@ -88,6 +85,7 @@ public class ReportController extends BaseController {
88 85
        }
89 86
        return result;
90 87
    }
88
91 89
    @ApiOperation(value = "统计报表-单位人员信息表-导出")
92 90
    @PostMapping("/up_export")
93 91
    public void up_export(HttpServletResponse response, @RequestBody UPExportReq req) {
@ -103,6 +101,37 @@ public class ReportController extends BaseController {
103 101
    }
104 102
105 103
    @ApiOperation(value = "统计报表-考点考场统计一览表")
104
    @GetMapping("/pr")
105
    public Result pr(@RequestBody PRReq req) {
106
        Result<Map> result = null;
107
        try {
108
            if (TextUtils.isEmpty(req.exam_id)) {
109
                return setErr("exam_id不能为空");
110
            }
111
            Map obj = mService.pr(req);
112
            result = setResult("res", obj);
113
        } catch (Exception e) {
114
            result = setErr(e.toString());
115
            e.printStackTrace();
116
        }
117
        return result;
118
    }
119
120
    @ApiOperation(value = "统计报表-考点考场统计一览表-导出")
121
    @PostMapping("/pr_export")
122
    public void pr_export(HttpServletResponse response, @RequestBody PRExportReq req) {
123
        try {
124
            if (TextUtils.isEmpty(req.exam_id)) {
125
                exportPrint(response, "exam_id不能为空");
126
            }
127
            mService.pr_export(response, req);
128
        } catch (Exception e) {
129
            System.out.println(e.getMessage());
130
            exportPrint(response, e.getMessage());
131
        }
132
    }
133
134
    @ApiOperation(value = "统计报表-考点考场统计一览表")
106 135
    @GetMapping("/place_room_multi")
107 136
    public Result place_room_multi() {
108 137
        Result<Map> result = null;

+ 153 - 1
oa-app/src/main/java/com/css/oa/exam/report/service/ReportService.java

@ -19,6 +19,7 @@ import com.css.oa.exam.place.repository.IPlaceRepository;
19 19
import com.css.oa.exam.place.repository.Place;
20 20
import com.css.oa.exam.report.bean.*;
21 21
import com.css.oa.exam.room.repository.IRoomRepository;
22
import com.css.oa.exam.room.repository.Room;
22 23
import com.css.oa.exam.score.bean.AnalyseColumn;
23 24
import com.css.oa.exam.student.repository.IStudentRepository;
24 25
import com.css.oa.exam.student.repository.Student;
@ -219,7 +220,7 @@ public class ReportService extends BaseService implements IReportService {
219 220
            //这个考试里边,某个单位下的所有考生
220 221
            List<String> thisUnitStuIds = new ArrayList<>();
221 222
            for (int j = 0; j < stus.size(); j++) {
222
                if(stus.get(i).unit_id.equalsIgnoreCase(unit.uuid)){
223
                if (stus.get(i).unit_id.equalsIgnoreCase(unit.uuid)) {
223 224
                    thisUnitStuIds.add(stus.get(j).uuid);
224 225
                }
225 226
            }
@ -248,4 +249,155 @@ public class ReportService extends BaseService implements IReportService {
248 249
        workBook.createCellStyle().setLocked(true);
249 250
        ExcelDelegate.exportExcel(workBook, "单位人员信息表.xls", response);
250 251
    }
252
253
    public Map pr(PRReq req) {
254
        if (req.pageSize == 0) {
255
            req.pageSize = 20;
256
        }
257
        List<Place> places = placeRepository.findAllByExam_id(req.exam_id);
258
        List<String> placeIds = new ArrayList<>();
259
        for (Place place : places) {
260
            placeIds.add(place.getUuid());
261
        }
262
        Specification<Room> roomSpec = new Specification<Room>() {
263
            @Override
264
            public Predicate toPredicate(Root<Room> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
265
                List<Predicate> predicateList = new ArrayList<>();
266
                if (placeIds.size() > 0) {
267
                    Path<String> path = root.get("student_id");//定义查询的字段
268
                    CriteriaBuilder.In<String> in = criteriaBuilder.in(path);
269
                    for (int i = 0; i < placeIds.size(); i++) {
270
                        in.value(placeIds.get(i));//存入值
271
                    }
272
                    predicateList.add(in);
273
                }
274
                Predicate[] pre = new Predicate[predicateList.size()];
275
                pre = predicateList.toArray(pre);
276
277
                Order place_order = criteriaBuilder.asc(root.get("place_id"));
278
                criteriaQuery.orderBy(place_order);
279
                criteriaQuery.where(pre);
280
                return criteriaQuery.getRestriction();
281
            }
282
        };
283
        PageRequest pageReques = PageRequest.of(req.curPage, req.pageSize);
284
        Page<Room> pages = roomRepository.findAll(roomSpec, pageReques);
285
        List<Room> rooms = pages.getContent();
286
287
        List<PRExcelEntity> list = new ArrayList();
288
        for (int i = 0; i < rooms.size(); i++) {
289
            Room room = rooms.get(i);
290
            PRExcelEntity entity = new PRExcelEntity();
291
            String pName = "";
292
            for (Place p : places) {
293
                if (room.getPlace_id().equalsIgnoreCase(p.getUuid())) {
294
                    pName = p.getPlace_name();
295
                    break;
296
                }
297
            }
298
            entity.setPlace_name(pName);
299
            entity.setRoom_name(room.getRoom_name());
300
            entity.setTotal(room.getPeaple_count());
301
            //查询已经分配的人数
302
            Specification<Assign> spec = new Specification<Assign>() {
303
                @Override
304
                public Predicate toPredicate(Root<Assign> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
305
                    List<Predicate> predicateList = new ArrayList<>();
306
                    //0.所属考试
307
                    if (!TextUtils.isEmpty(req.exam_id)) {
308
                        Predicate exam_id = criteriaBuilder.equal(root.get("exam_id").as(String.class), req.exam_id);
309
                        predicateList.add(exam_id);
310
                    }
311
                    String room_id = room.getUuid();
312
                    if (!TextUtils.isEmpty(room_id)) {
313
                        Predicate exam_id = criteriaBuilder.equal(root.get("room_id").as(String.class), room_id);
314
                        predicateList.add(exam_id);
315
                    }
316
                    Predicate[] pre = new Predicate[predicateList.size()];
317
                    pre = predicateList.toArray(pre);
318
319
                    Order place_order = criteriaBuilder.asc(root.get("place_id"));
320
                    Order room_order = criteriaBuilder.asc(root.get("room_id"));
321
                    criteriaQuery.orderBy(place_order, room_order);
322
                    criteriaQuery.where(pre);
323
                    return criteriaQuery.getRestriction();
324
                }
325
            };
326
            long count = assignRepository.count(spec);
327
            entity.setAssigned_count((int) count);
328
            list.add(entity);
329
        }
330
        Map map = new HashMap();
331
        map.put("total", list.size());
332
        map.put("list", list);
333
        return map;
334
    }
335
336
    public void pr_export(HttpServletResponse response, PRExportReq req) {
337
        List<Place> places = placeRepository.findAllByExam_id(req.exam_id);
338
        List<String> placeIds = new ArrayList<>();
339
        for (Place place : places) {
340
            placeIds.add(place.getUuid());
341
        }
342
        List<Room> rooms = roomRepository.findAllByPlace_ids(placeIds);
343
        List<PRExcelEntity> list = new ArrayList();
344
        for (int i = 0; i < rooms.size(); i++) {
345
            Room room = rooms.get(i);
346
            PRExcelEntity entity = new PRExcelEntity();
347
            String pName = "";
348
            for (Place p : places) {
349
                if (room.getPlace_id().equalsIgnoreCase(p.getUuid())) {
350
                    pName = p.getPlace_name();
351
                    break;
352
                }
353
            }
354
            entity.setPlace_name(pName);
355
            entity.setRoom_name(room.getRoom_name());
356
            entity.setTotal(room.getPeaple_count());
357
            //查询已经分配的人数
358
            Specification<Assign> spec = new Specification<Assign>() {
359
                @Override
360
                public Predicate toPredicate(Root<Assign> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
361
                    List<Predicate> predicateList = new ArrayList<>();
362
                    //0.所属考试
363
                    if (!TextUtils.isEmpty(req.exam_id)) {
364
                        Predicate exam_id = criteriaBuilder.equal(root.get("exam_id").as(String.class), req.exam_id);
365
                        predicateList.add(exam_id);
366
                    }
367
                    String room_id = room.getUuid();
368
                    if (!TextUtils.isEmpty(room_id)) {
369
                        Predicate exam_id = criteriaBuilder.equal(root.get("room_id").as(String.class), room_id);
370
                        predicateList.add(exam_id);
371
                    }
372
                    Predicate[] pre = new Predicate[predicateList.size()];
373
                    pre = predicateList.toArray(pre);
374
                    criteriaQuery.where(pre);
375
                    return criteriaQuery.getRestriction();
376
                }
377
            };
378
            long count = assignRepository.count(spec);
379
            entity.setAssigned_count((int) count);
380
            list.add(entity);
381
        }
382
383
        //原料 beans
384
        List<Map<String, Object>> sheetsList = new ArrayList<>();
385
        List<PRExcelEntity> beans = new ArrayList<>();
386
        beans = list;
387
        ExportParams exportParams = new ExportParams();
388
        exportParams.setSheetName("考点考场统计一览表");
389
        // 创建sheet1使用得map
390
        Map<String, Object> oneSheet = new HashMap<>();
391
        // title的参数为ExportParams类型,目前仅仅在ExportParams中设置了sheetName
392
        oneSheet.put("title", exportParams);
393
        // 模版导出对应得实体类型
394
        oneSheet.put("entity", PRExcelEntity.class);
395
        // sheet中要填充得数据
396
        oneSheet.put("data", beans);
397
        sheetsList.add(oneSheet);
398
        // 执行方法
399
        Workbook workBook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF);
400
        workBook.createCellStyle().setLocked(true);
401
        ExcelDelegate.exportExcel(workBook, "考点考场统计一览表.xls", response);
402
    }
251 403
}

+ 5 - 0
oa-app/src/main/java/com/css/oa/exam/room/repository/IRoomRepository.java

@ -41,4 +41,9 @@ public interface IRoomRepository extends JpaRepository<Room, String>, JpaSpecifi
41 41
    @Query("select r.uuid from Room r where r.place_id = :place_id")
42 42
    List<String> findAllIdByPlace_id(@Param("place_id") String place_id);
43 43
44
    @Modifying
45
    @Transactional
46
    @Query("select r from Room r where r.place_id in :place_ids")
47
    List<Room> findAllByPlace_ids(@Param("place_ids") List<String> place_ids);
48
44 49
}