派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.qxueyou.scc.admin.schoolRoll.impl;
 
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.RandomUtil;
import com.qxueyou.scc.admin.classes.model.ClsClass;
import com.qxueyou.scc.admin.schoolRoll.ISchoolRollService;
import com.qxueyou.scc.base.model.ExcelExportParam;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.service.impl.CommonAppService;
import com.qxueyou.scc.base.util.ClientUtils;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.ExcelExportUtils;
import com.qxueyou.scc.base.util.TraceUtils;
import com.qxueyou.scc.teach.student.model.StuStudent;
import com.qxueyou.scc.user.model.UserRegistration;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
 
@Service
public class SchoolRollServiceImpl extends CommonAppService implements ISchoolRollService {
 
 
 
    @Override
    public List<StuStudent> findSchoolRollList(Integer limit, Integer pageNum, String keyword, String status) {
 
        StringBuffer hql=new StringBuffer("from StuStudent where name like ? and status=? and deleteFlag is false");
 
        List<Object> args = CollectionUtils.newList(keyword + "%", status);
 
        hql.append(" order by createTime desc");
 
        List<StuStudent> list = findList(hql.toString(), new Pager(limit, pageNum), args, StuStudent.class);
 
        return list;
    }
 
    @Override
    public int findSchoolRollListCount(String keyword, String status) {
        StringBuffer hql=new StringBuffer("from StuStudent where name like ? and status=? and deleteFlag is false");
 
        List<Object> args = CollectionUtils.newList(keyword + "%", status);
 
        return findCount(hql.toString(),args);
    }
 
    @Override
    public Result updateSchool(String [] studentIds, String classId) {
        for (String studentId:
                studentIds) {
            StringBuffer hql=new StringBuffer("from StuStudent where studentId=? and deleteFlag is false");
 
            List<Object> args = CollectionUtils.newList(studentId);
 
            StuStudent stuStudent = findUnique(hql.toString(), args, StuStudent.class);
 
            if(stuStudent!=null && classId!=null){
                stuStudent.setClassId(classId);
                save(stuStudent);
            }else {
                return new Result(false,"班级不存在或学生不存在");
            }
        }
 
        return new Result(true);
 
    }
 
    @Override
    public void deriveStudentMessage() {
        StringBuffer hql=new StringBuffer("from StuStudent where status=? and deleteFlag is false");
 
        List<Object> args = CollectionUtils.newList("active");
 
        List<StuStudent> stuStudents = find(hql.toString(), args, StuStudent.class);
 
        ExcelExportUtils<StuStudent> ex = new ExcelExportUtils<StuStudent>();
        String[] headers = { "姓名", "性别" ,"手机号" ,"身份证"};
        List<StuStudent> dataset = new ArrayList<StuStudent>();
        for (StuStudent stuStudent:
        stuStudents) {
            StuStudent u = new StuStudent();
            u.setName(stuStudent.getName());
            u.setSex(stuStudent.getSex());
            u.setMobilePhone(stuStudent.getMobilePhone());
            u.setStudentNo(stuStudent.getStudentNo());
            dataset.add(u);
        }
 
        ExcelExportParam<StuStudent> obj = new ExcelExportParam<StuStudent>();
        obj.setColData(dataset);
        obj.setHeaders(headers);
 
        try {
            OutputStream out = new FileOutputStream("D://Student.xls");
            obj.setOut(out);
            ex.exportExcel(obj);
            out.close();
            System.out.println("excel导出成功!");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        try {
            OutputStream out = new FileOutputStream("D://Student.xls");
            List<String> lst = new ArrayList<String>();
            lst.add("className");
            lst.add("userName");
            obj.setLstColumn(lst);
            obj.setOut(out);
            ex.exportExcelByColomn(obj);
            out.close();
            System.out.println("excel指定列导出成功!");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    @Override
    public Result loopStudentIds(String[] studentIds) {
        for (String studentId:
             studentIds) {
            auditStudent(studentId);
        }
        return new Result(true);
    }
 
    private Result auditStudent(String studentId) {
        StuStudent student = read(StuStudent.class, studentId);
        TraceUtils.setUpdateTrace(student);
        String currentTime = LocalDateTimeUtil.format(LocalDateTime.now(), "yyMMddHHmmssSSS");
 
        String examCardNo = currentTime.concat(RandomUtil.randomNumbers(1));
 
        student.setStudentNumber(examCardNo);
        student.setStatus(StuStudent.STATUS_ACTIVE);
        save(student);
 
        return new Result(true);
    }
 
    @Override
    public List<ClsClass> findClass() {
        StringBuffer hql=new StringBuffer("from ClsClass where deleteFlag is false");
 
        List<Object> arg = CollectionUtils.newList();
 
        List<ClsClass> clsClasses = find(hql.toString(), arg, ClsClass.class);
 
        return clsClasses;
    }
 
}