111
wang-hao-jie
2022-08-25 d90da0759bd93c7f429f6a20bc835782ad927c02
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package com.boying.controller;
 
import com.boying.common.BaseController;
import com.boying.common.SystemConfigProperties;
import com.boying.common.util.StringUtil;
import com.boying.entity.Dept;
import com.boying.entity.User;
import com.boying.service.DeptService;
import com.boying.service.StudyRecordService;
import com.boying.service.UserService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
 
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.math.BigDecimal;
import java.util.List;
 
@RestController
@RequestMapping("user")
public class UserController extends BaseController {
 
    @Autowired
    private UserService userService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private SystemConfigProperties systemConfigProperties;
    @Autowired
    private StudyRecordService studyRecordService;
 
    @PostMapping("findPage")
    public Object findPage(String name,int page,int pageSize,Long deptId) {
        Pageable pageable = PageRequest.of(page-1,pageSize, Sort.Direction.DESC,"id");
        Page<User> pages = userService.findPageHaveLike(pageable,1,"name",name,"deptId",deptId);
        return success("",pages);
    }
 
    @PostMapping("save")
    public Object save(User user) {
        if(user.getId()==null){
            user.setPassword(user.getLoginName());
        }
        if(user.getId()==null){
            Dept dept = (Dept) deptService.findById(user.getDeptId());
            dept.setNum(dept.getNum()+1);
            deptService.save(dept);
        }
        userService.save(user);
        return success("保存成功");
    }
 
    @PostMapping("delete")
    public Object delete(Long id) {
        User user = (User) userService.findById(id);
 
        Dept dept = (Dept) deptService.findById(user.getDeptId());
        dept.setNum(dept.getNum()-1);
        if(dept.getNum()==0){
            dept.setUserName(null);
            dept.setUserId(null);
        }
        deptService.save(dept);
 
        userService.delete(id);
        return success("删除成功");
    }
 
    @PostMapping("login")
    public Object login(String loginName,String password,String openid) {
        if(StringUtil.isNullOrEmpty(loginName)||StringUtil.isNullOrEmpty(password)){
            return error("用户名和密码必填");
        }
        List<User> all = userService.findAll("loginName",loginName,"password",password);
        if(all.size()>0){
            User user = all.get(0);
//            user.setPdfs(studyRecordService.countByType(0,user.getId()));
//            user.setVideos(studyRecordService.countByType(1,user.getId()));
//            Integer time = studyRecordService.sumByTime(user.getId());
//            if(time!=null){
//                double d3 = (Double.valueOf(time))/60;
//                double v = new BigDecimal(d3).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
//                user.setTime(v);
//            }
            if(user.getDeptId()!=null){
                Dept dept = (Dept)deptService.findById(user.getDeptId());
                user.setDeptName(dept.getName());
            }
            user.setOpenid(openid);
            userService.save(user);
            return success("请求成功",user);
        }
 
 
        return error("用户名或密码不正确");
    }
 
    @PostMapping("updatePassword")
    public Object updatePassword(Long userId,String oldPassword,String newPassword) {
        List<User> all = userService.findAll("id",userId,"password",oldPassword);
        if(all.size()>0){
            User user = all.get(0);
            user.setPassword(newPassword);
            userService.save(user);
            return success("请求成功");
        }
        return error("旧密码不正确");
    }
 
    @PostMapping("updateImg")
    public Object updateImg(Long userId,HttpServletRequest request) throws Exception{
        User user = (User) userService.findById(userId);
        String path = "";
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        List<MultipartFile> imgs = multipartRequest.getFiles("img");
        for(MultipartFile imageFile:imgs){
            if (imageFile != null) {
                String fileExtension = FilenameUtils.getExtension(imageFile.getOriginalFilename());//获取后缀
                String newFileName = System.currentTimeMillis() + "." + fileExtension;//文件名称
                path+=newFileName;
                String newFilePath = systemConfigProperties.getUploadUserPath() + newFileName;//上传路径
                File destFile = new File(newFilePath);
                FileUtils.writeByteArrayToFile(destFile, imageFile.getBytes());
                break;
            }
        }
        user.setImg(path);
        userService.save(user);
        return success("修改成功",user);
    }
 
    @GetMapping("save2")
    public Object save2() {
        String a="130406197006010332\n" +
                "130406198707282132\n" +
                "130406196410172793\n" +
                "13040619790226033x\n" +
                "13040619661031061x\n" +
                "130406197002150354\n" +
                "130406196909290633\n" +
                "130406198706200318\n" +
                "130406197508130350\n" +
                "130406196408062712\n" +
                "130406196810170359\n" +
                "130406198704090936\n" +
                "130406197208130914\n" +
                "130481197802093474\n" +
                "130406197410260317\n" +
                "130406196706020350\n" +
                "130406197812210355\n" +
                "130406197105012739\n" +
                "130427198006051712\n" +
                "130406197809020315\n" +
                "130406196309110336\n" +
                "130406197809080334\n" +
                "130406197011150452\n" +
                "130406198410130225\n" +
                "130406196305112799\n" +
                "130406197806072734\n" +
                "130406198003200338\n" +
                "130406196612140319\n" +
                "130406198004032110\n" +
                "130406198708062756\n" +
                "130406197509120613\n" +
                "130406198801180335\n" +
                "130406196612010338\n" +
                "130406197912070652";
        String b = "靳文军\n" +
                "马旦\n" +
                "张爱军\n" +
                "王海涛\n" +
                "赵锡铎\n" +
                "张丙洲\n" +
                "王小红\n" +
                "陈晓明\n" +
                "梁志军\n" +
                "李平安\n" +
                "赵洪旺\n" +
                "杜彦\n" +
                "吝爱军\n" +
                "赵延军\n" +
                "陈志生\n" +
                "张永军\n" +
                "韩强\n" +
                "庞显庆\n" +
                "李广旭\n" +
                "李长征\n" +
                "蔡荣凯\n" +
                "孙保功\n" +
                "郜晓海\n" +
                "马国萍\n" +
                "房守民\n" +
                "刘海燕\n" +
                "刘明辉\n" +
                "李鹏\n" +
                "娄治海\n" +
                "申先平\n" +
                "范明晰\n" +
                "刘龙\n" +
                "李克荣\n" +
                "高永亮";
        String c = "15613065360\n" +
                "13231001331\n" +
                "15832018002\n" +
                "13831088171\n" +
                "13930086162\n" +
                "16973103549\n" +
                "13931022890\n" +
                "17731088883\n" +
                "15933889335\n" +
                "15028060726\n" +
                "15231838364\n" +
                "13930064953\n" +
                "13673106864\n" +
                "15031073073\n" +
                "18132976288\n" +
                "13831039272\n" +
                "13131081838\n" +
                "13463105147\n" +
                "15603100635\n" +
                "13730015890\n" +
                "13731030998\n" +
                "15832080436\n" +
                "13503103583\n" +
                "13831071453\n" +
                "13930090285\n" +
                "13831036765\n" +
                "13082100228\n" +
                "15032023892\n" +
                "13315005731\n" +
                "15503011019\n" +
                "13932037841\n" +
                "18830887653\n" +
                "13012115868\n" +
                "15031055520";
        String[] card = a.split("\n");
        String[] name = b.split("\n");
        String[] phone = c.split("\n");
        for(int i=0;i<card.length;i++){
            User user = new User();
            user.setDeptId(Long.valueOf(20));
            user.setPassword(phone[i]);
            user.setName(name[i]);
            user.setIdCard(card[i]);
            user.setPhone(phone[i]);
            user.setLoginName(phone[i]);
            userService.save(user);
        }
        System.out.println(card.length);
        return success("保存成功");
    }
 
}