Browse Source

统计报表=>考点考场人员信息

zhuhaiwen 3 years ago
parent
commit
b1a430a908

+ 3 - 0
oa-app/src/main/java/com/css/oa/exam/assign/repository/Assign.java

@ -60,6 +60,9 @@ public class Assign implements Serializable {
60 60
    public String level_name;
61 61
62 62
    @Transient
63
    public String subject_name;
64
65
    @Transient
63 66
    public int is_assign;
64 67
65 68
    @Transient

+ 5 - 0
oa-app/src/main/java/com/css/oa/exam/assign/repository/IAssignRepository.java

@ -49,4 +49,9 @@ public interface IAssignRepository extends JpaRepository<Assign, String>, JpaSpe
49 49
    @Query("select ass from Assign ass where ass.adm_num is not null and ass.student_id = :student_id")
50 50
    List<Assign> myAdm(String student_id);
51 51
52
    @Modifying
53
    @Transactional
54
    @Query("select ass from Assign ass where ass.exam_id = :exam_id and ass.place_id = :place_id")
55
    List<Assign> findAllByPlace_id(@Param("exam_id") String exam_id, @Param("place_id") String place_id);
56
52 57
}

+ 8 - 2
oa-app/src/main/java/com/css/oa/exam/assign/service/BaseAssignService.java

@ -7,6 +7,8 @@ import com.css.oa.exam.assign.repository.IAssignRecord;
7 7
import com.css.oa.exam.base.BaseVerifyService;
8 8
import com.css.oa.exam.constants.BoolState;
9 9
import com.css.oa.exam.constants.VerifyState;
10
import com.css.oa.exam.exam.repository.Exam;
11
import com.css.oa.exam.exam.repository.IExamRepository;
10 12
import com.css.oa.exam.place.repository.IPlaceRepository;
11 13
import com.css.oa.exam.place.repository.Place;
12 14
import com.css.oa.exam.student.repository.IStudentRepository;
@ -90,6 +92,9 @@ public class BaseAssignService extends BaseVerifyService {
90 92
        return null;
91 93
    }
92 94
95
    @Autowired
96
    IExamRepository examRepository;
97
93 98
    protected void setProperties(List<Assign> assignList) {
94 99
        //设置审核状态
95 100
        setVerifyState(assignList);
@ -108,8 +113,9 @@ public class BaseAssignService extends BaseVerifyService {
108 113
            Place place = placeRepository.findById(assign.getWant_place_id()).get();
109 114
            assign.setWant_place_name(place.getPlace_name());
110 115
111
            assign.setSeries_name("水利工程");
112
            assign.setLevel_name("中高级");
116
            Exam exam = examRepository.findById(assign.exam_id).get();
117
            assign.setSeries_name(exam.getSeries_name());
118
            assign.setLevel_name(exam.getLevel_name());
113 119
            boolean empty = TextUtils.isEmpty(assign.getRoom_id());
114 120
            assign.setIs_assign(empty ? BoolState.NO : BoolState.YES);
115 121
        }

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

@ -30,4 +30,9 @@ public interface IPlaceRepository extends JpaRepository<Place, String>, JpaSpeci
30 30
    @Query("select p from Place p where p.create_unit_id in :unitIds and p.exam_id = :exam_id and p.curr_unit_id = " + Unit.TOP_CODE)
31 31
    List<Place> findAllByUnitIds(List<String> unitIds, String exam_id);
32 32
33
    @Modifying
34
    @Transactional
35
    @Query("select p from Place p where p.exam_id  = :exam_id")
36
    List<Place> findAllByExam_id(String exam_id);
37
33 38
}

+ 42 - 0
oa-app/src/main/java/com/css/oa/exam/report/bean/PRPExcelEntity.java

@ -0,0 +1,42 @@
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
6
@ExcelTarget("deptUtil")
7
public class PRPExcelEntity {
8
9
    @Excel(name = "考场", width = 30, needMerge = true)
10
    private String room_name;
11
12
    @Excel(name = "姓名", width = 30, needMerge = true)
13
    private String name;
14
15
    @Excel(name = "身份证", width = 30, needMerge = true)
16
    private String card_num;
17
18
    @Excel(name = "准考证", width = 30, needMerge = true)
19
    private String adm_num;
20
21
    @Excel(name = "座位号", width = 30, needMerge = true)
22
    private String seat_num;
23
24
    @Excel(name = "报考系列", width = 30, needMerge = true)
25
    private String series_name;
26
27
    @Excel(name = "报考级别", width = 30, needMerge = true)
28
    private String level_name;
29
30
    @Excel(name = "报考科目", width = 30, needMerge = true)
31
    private String subject_name;
32
33
    @Excel(name = "照片", width = 30, needMerge = true)
34
    private String pic;
35
36
    @Excel(name = "签名", width = 30, needMerge = true)
37
    private String autograph;
38
39
//    @ExcelCollection(name = "员工信息")
40
//    private List<EmpUtil> emps;
41
42
}

+ 19 - 0
oa-app/src/main/java/com/css/oa/exam/report/bean/PRPExportReq.java

@ -0,0 +1,19 @@
1
package com.css.oa.exam.report.bean;
2
3
import com.css.oa.exam.constants.ExportDTO;
4
5
import java.util.ArrayList;
6
import java.util.List;
7
8
public class PRPExportReq {
9
10
    public String exam_id;
11
12
    public int curPage;
13
14
    public int pageSize;
15
16
    //key value
17
    public List<ExportDTO> dtos = new ArrayList<>();
18
19
}

+ 16 - 0
oa-app/src/main/java/com/css/oa/exam/report/bean/PRPReq.java

@ -0,0 +1,16 @@
1
package com.css.oa.exam.report.bean;
2
3
import com.css.oa.exam.constants.ExportDTO;
4
5
import java.util.ArrayList;
6
import java.util.List;
7
8
public class PRPReq {
9
10
    public String place_id;
11
12
    public int curPage;
13
14
    public int pageSize;
15
16
}

+ 27 - 9
oa-app/src/main/java/com/css/oa/exam/report/controller/ReportController.java

@ -1,6 +1,9 @@
1 1
package com.css.oa.exam.report.controller;
2 2
3
import com.css.oa.exam.assign.bean.AssignExportReq;
3 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;
4 7
import com.css.oa.exam.report.service.ReportService;
5 8
import com.css.oa.utils.Result;
6 9
import io.swagger.annotations.Api;
@ -9,6 +12,7 @@ import org.apache.http.util.TextUtils;
9 12
import org.springframework.beans.factory.annotation.Autowired;
10 13
import org.springframework.web.bind.annotation.*;
11 14
15
import javax.servlet.http.HttpServletResponse;
12 16
import java.util.HashMap;
13 17
import java.util.List;
14 18
import java.util.Map;
@ -36,12 +40,12 @@ public class ReportController extends BaseController {
36 40
    }
37 41
38 42
    @ApiOperation(value = "统计报表-考点考场人员信息")
39
    @GetMapping("/roomPeople")
40
    public Result roomPeople() {
43
    @PostMapping("/prp")
44
    public Result prp(@RequestBody PRPReq req) {
41 45
        Result<Map> result = null;
42 46
        try {
43
//            Map obj = mService.roomPeople();
44
//            result = setResult("res", obj);
47
            Map obj = mService.prp(req);
48
            result = setResult("res", obj);
45 49
        } catch (Exception e) {
46 50
            result = setErr(e.toString());
47 51
            e.printStackTrace();
@ -49,9 +53,23 @@ public class ReportController extends BaseController {
49 53
        return result;
50 54
    }
51 55
56
    @ApiOperation(value = "统计报表-考点考场人员信息-导出")
57
    @PostMapping("/prp_export")
58
    public void prp_export(HttpServletResponse response, @RequestBody PRPExportReq req) {
59
        try {
60
            if (TextUtils.isEmpty(req.exam_id)) {
61
                exportPrint(response, "exam_id不能为空");
62
            }
63
            mService.prp_export(response, req);
64
        } catch (Exception e) {
65
            System.out.println(e.getMessage());
66
            exportPrint(response, e.getMessage());
67
        }
68
    }
69
52 70
    @ApiOperation(value = "统计报表-单位人员信息表")
53
    @GetMapping("/unitPeople")
54
    public Result unitPeople() {
71
    @GetMapping("/unit_personnel")
72
    public Result unit_personnel() {
55 73
        Result<Map> result = null;
56 74
        try {
57 75
//            Map obj = mService.unitPeople();
@ -64,8 +82,8 @@ public class ReportController extends BaseController {
64 82
    }
65 83
66 84
    @ApiOperation(value = "统计报表-考点考场统计一览表")
67
    @GetMapping("/place_room")
68
    public Result place_room() {
85
    @GetMapping("/place_room_multi")
86
    public Result place_room_multi() {
69 87
        Result<Map> result = null;
70 88
        try {
71 89
//            Map obj = mService.place_room();
@ -77,7 +95,7 @@ public class ReportController extends BaseController {
77 95
        return result;
78 96
    }
79 97
80
    @ApiOperation(value = "统计报表-考点考场统计一览表")
98
    @ApiOperation(value = "统计报表-督考员一览表")
81 99
    @GetMapping("/monitor")
82 100
    public Result monitor() {
83 101
        Result<Map> result = null;

+ 136 - 6
oa-app/src/main/java/com/css/oa/exam/report/service/ReportService.java

@ -1,9 +1,52 @@
1 1
package com.css.oa.exam.report.service;
2 2
3
import cn.afterturn.easypoi.excel.ExcelExportUtil;
4
import cn.afterturn.easypoi.excel.entity.ExportParams;
5
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
6
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
7
import com.css.oa.exam.admin.bean.Admin;
8
import com.css.oa.exam.assign.bean.AssignExportReq;
9
import com.css.oa.exam.assign.repository.Assign;
10
import com.css.oa.exam.assign.repository.AssignRecord;
11
import com.css.oa.exam.assign.repository.IAssignRepository;
3 12
import com.css.oa.exam.base.BaseService;
13
import com.css.oa.exam.constants.BoolState;
14
import com.css.oa.exam.constants.ExamConfig;
15
import com.css.oa.exam.constants.ExportDTO;
16
import com.css.oa.exam.exam.repository.Exam;
17
import com.css.oa.exam.exam.repository.IExamRepository;
18
import com.css.oa.exam.place.repository.IPlaceRepository;
19
import com.css.oa.exam.place.repository.Place;
20
import com.css.oa.exam.report.bean.PRPExcelEntity;
21
import com.css.oa.exam.report.bean.PRPExportReq;
22
import com.css.oa.exam.report.bean.PRPReq;
23
import com.css.oa.exam.room.repository.IRoomRepository;
24
import com.css.oa.exam.score.bean.AnalyseColumn;
25
import com.css.oa.exam.student.repository.IStudentRepository;
26
import com.css.oa.exam.student.repository.Student;
27
import com.css.oa.exam.util.CopyObjTool;
28
import com.css.oa.exam.util.ExcelDelegate;
29
import com.css.oa.exam.util.ExportHelper;
4 30
import lombok.extern.slf4j.Slf4j;
31
import org.apache.http.util.TextUtils;
32
import org.apache.poi.hssf.usermodel.HSSFRow;
33
import org.apache.poi.hssf.usermodel.HSSFSheet;
34
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
35
import org.apache.poi.ss.usermodel.Workbook;
36
import org.springframework.beans.BeanUtils;
37
import org.springframework.beans.factory.annotation.Autowired;
38
import org.springframework.data.domain.Page;
39
import org.springframework.data.domain.PageRequest;
40
import org.springframework.data.jpa.domain.Specification;
5 41
import org.springframework.stereotype.Service;
6 42
43
import javax.persistence.criteria.*;
44
import javax.servlet.http.HttpServletResponse;
45
import java.io.BufferedOutputStream;
46
import java.io.ByteArrayInputStream;
47
import java.io.ByteArrayOutputStream;
48
import java.io.OutputStream;
49
import java.net.URLEncoder;
7 50
import java.util.ArrayList;
8 51
import java.util.HashMap;
9 52
import java.util.List;
@ -21,11 +64,98 @@ public class ReportService extends BaseService implements IReportService {
21 64
        map.put("list", arr);
22 65
        return map;
23 66
    }
24
//
25
//    @Autowired
26
//    IExamRepository repository;
27
//
28
//    @Autowired
29
//    IUnitRepository unitRepository;
67
68
    @Autowired
69
    IRoomRepository roomRepository;
70
    @Autowired
71
    IAssignRepository assignRepository;
72
    @Autowired
73
    IStudentRepository studentRepository;
74
    @Autowired
75
    IExamRepository examRepository;
76
77
    public Map prp(PRPReq req) {
78
        if (req.pageSize == 0) {
79
            req.pageSize = 20;
80
        }
81
        List<String> roomIds = roomRepository.findAllIdByPlace_id(req.place_id);
82
        Specification<Assign> spec = new Specification<Assign>() {
83
            @Override
84
            public Predicate toPredicate(Root<Assign> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
85
                List<Predicate> predicateList = new ArrayList<>();
86
                //0.所属考试
87
                if (roomIds.size() > 0) {
88
                    Path<String> path = root.get("room_id");//定义查询的字段
89
                    CriteriaBuilder.In<String> in = criteriaBuilder.in(path);
90
                    for (int i = 0; i < roomIds.size(); i++) {
91
                        in.value(roomIds.get(i));//存入值
92
                    }
93
                    predicateList.add(in);
94
                }
95
                Predicate[] pre = new Predicate[predicateList.size()];
96
                pre = predicateList.toArray(pre);
97
                return criteriaQuery.where(pre).getRestriction();
98
            }
99
        };
100
        PageRequest pageReques = PageRequest.of(req.curPage, req.pageSize);
101
        Page<Assign> pages = assignRepository.findAll(spec, pageReques);
102
        List<Assign> list = pages.getContent();
103
104
        setAssignProperties(list);
105
        Map map = new HashMap();
106
        map.put("total", list.size());
107
        map.put("list", list);
108
        return map;
109
    }
110
111
    private void setAssignProperties(List<Assign> list) {
112
        for (Assign assign : list) {
113
            //附加学生信息
114
            String student_id = assign.getStudent_id();
115
            Student student = studentRepository.findById(student_id).get();
116
            CopyObjTool.copyProperties(student, assign);
117
            Exam exam = examRepository.findById(assign.exam_id).get();
118
            assign.setSeries_name(exam.getSeries_name());
119
            assign.setLevel_name(exam.getLevel_name());
120
            assign.setSubject_name(exam.getSubject_name());
121
        }
122
    }
123
124
    @Autowired
125
    IPlaceRepository placeRepository;
126
127
    public void prp_export(HttpServletResponse response, PRPExportReq req) {
128
        //查询所有考点
129
        List<Place> places = placeRepository.findAllByExam_id(req.exam_id);
130
131
        List<Map<String, Object>> sheetsList = new ArrayList<>();
132
        for (int i = 0; i < places.size(); i++) {
133
            Place place = places.get(i);
134
            List<Assign> list = assignRepository.findAllByPlace_id(req.exam_id, place.getUuid());
135
            setAssignProperties(list);
136
            List<PRPExcelEntity> beans = new ArrayList<>();
137
            for (Assign assign : list) {
138
                PRPExcelEntity entity = new PRPExcelEntity();
139
                BeanUtils.copyProperties(assign, entity);
140
                beans.add(entity);
141
            }
142
            ExportParams exportParams = new ExportParams();
143
            exportParams.setSheetName(place.getPlace_name());
144
            // 创建sheet1使用得map
145
            Map<String, Object> map = new HashMap<>();
146
            // title的参数为ExportParams类型,目前仅仅在ExportParams中设置了sheetName
147
            map.put("title", exportParams);
148
            // 模版导出对应得实体类型
149
            map.put("entity", PRPExcelEntity.class);
150
            // sheet中要填充得数据
151
            map.put("data", beans);
152
            sheetsList.add(map);
153
        }
154
        // 执行方法
155
        Workbook workBook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF);
156
        workBook.createCellStyle().setLocked(true);
157
        ExcelDelegate.exportExcel(workBook, "考点考场人员信息.xls", response);
158
159
    }
30 160
31 161
}

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

@ -36,4 +36,9 @@ public interface IRoomRepository extends JpaRepository<Room, String>, JpaSpecifi
36 36
    @Query("select r from Room r where r.create_unit_id in :unitIds and r.place_id = :place_id and r.curr_unit_id = " + Unit.TOP_CODE)
37 37
    List<Room> findAllByUnitIds(List<String> unitIds, String place_id);
38 38
39
    @Modifying
40
    @Transactional
41
    @Query("select r.uuid from Room r where r.place_id = :place_id")
42
    List<String> findAllIdByPlace_id(@Param("place_id") String place_id);
43
39 44
}

+ 1 - 1
oa-app/src/main/java/com/css/oa/exam/score/service/ScoreService.java

@ -274,7 +274,7 @@ public class ScoreService extends BaseVerifyService implements IScoreService {
274 274
            }
275 275
            data.add(columns);
276 276
        }
277
277
        //原生POI
278 278
        //1.实例化HSSFWorkbook
279 279
        HSSFWorkbook workbook = new HSSFWorkbook();
280 280
        //2.创建一个Excel表单,参数为sheet的名字

+ 34 - 0
oa-app/src/main/java/com/css/oa/exam/util/ExportHelper.java

@ -0,0 +1,34 @@
1
package com.css.oa.exam.util;
2
3
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
4
5
import javax.servlet.http.HttpServletResponse;
6
import java.io.BufferedOutputStream;
7
import java.io.OutputStream;
8
9
public class ExportHelper {
10
11
    public static void export(HttpServletResponse response, HSSFWorkbook workbook,String fileName){
12
        try {
13
            //String fileName = "成绩分析-导出.xls";
14
            //清空response
15
            response.reset();
16
            //设置response的Header
17
            response.addHeader("Access-Control-Allow-Origin", "*");
18
            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
19
            response.setCharacterEncoding("UTF-8");
20
            response.setHeader("content-Type", "application/vnd.ms-excel");
21
            response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
22
23
            OutputStream os = new BufferedOutputStream(response.getOutputStream());
24
            //将excel写入到输出流中
25
            workbook.write(os);
26
            os.flush();
27
            os.close();
28
            System.out.println("设置浏览器下载成功!");
29
        } catch (Exception e) {
30
            System.out.println("设置浏览器下载失败!");
31
            e.printStackTrace();
32
        }
33
    }
34
}