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
package com.boying.controller.phone;
 
import com.boying.common.BaseController;
import com.boying.common.util.DateUtil;
import com.boying.entity.ChangDept;
import com.boying.entity.Dept;
import com.boying.entity.User;
import com.boying.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.math.BigDecimal;
import java.util.*;
 
 
@RestController
@RequestMapping("changeDept")
public class ChangeDeptController extends BaseController {
 
    @Autowired
    private ChangDeptService changDeptService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private UserService userService;
    @Autowired
    private StudyDataService studyDataService;
    @Autowired
    private ZiLiaoDataService ziLiaoDataService;
    @Autowired
    private StudyRecordService studyRecordService;
 
 
 
    @PostMapping("getStatisticByUserId")
    public Object getStatisticByUserId(Long userId) {
        User user = (User) userService.findById(userId);
        user.setPdfs(studyRecordService.countByType(0,user.getId()));
        user.setVideos(studyRecordService.countByType(1,user.getId()));
        //Integer time = studyRecordService.sumByTime(user.getId());
        Integer time = studyRecordService.sumByXueShi(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(time);
        }
        return success("请求成功",user);
    }
 
    @PostMapping("save")
    public Object save(ChangDept changDept) {
        Dept dept = (Dept) deptService.findById(changDept.getDeptId());
        if(dept.getUserId()!=null){
            if(changDept.getUserId()==dept.getUserId()){
                return error("您是会长,若要转会请联系后台管理员");
            }
        }
        Dept dept2 = (Dept) deptService.findById(changDept.getNewDeptId());
        if(dept2.getUserId()==null){
            return error("您想要转入的工会暂时没有管理员,无法进行转会");
        }
 
        User user = (User) userService.findById(changDept.getUserId());
 
        changDept.setUserName(user.getName());
        changDept.setDeptName(dept.getName());
        changDept.setNewDeptName(dept2.getName());
        changDept.setShenHeId(dept2.getUserId());
        changDept.setShenHeId2(dept.getUserId());
        changDeptService.save(changDept);
 
        if(changDept.getStatus()==1){
            user.setDeptId(dept2.getId());
            userService.save(user);
            dept.setNum(dept.getNum()-1);
            deptService.save(dept);
            dept2.setNum(dept2.getNum()+1);
            deptService.save(dept2);
        }
        return success("保存成功");
    }
 
    @PostMapping("updateStatus")
    public Object save(Long id,int status) {
        ChangDept changDept = (ChangDept) changDeptService.findById(id);
        changDept.setStatus2(status);
        changDeptService.save(changDept);
        return success("操作成功");
    }
 
    @PostMapping("findIndex")
    public Object findIndex(Long userId) {
        Pageable pageable = PageRequest.of(0,5, Sort.Direction.DESC,"id");
        Map<String,Object> map = new HashMap<>();
        map.put("studys",studyDataService.count());
        map.put("ziLiaos",ziLiaoDataService.count());
 
        Integer time = studyRecordService.sumByXueShi(userId);
        if(time!=null){
//            double d3 = (Double.valueOf(time))/60;
//            double v = new BigDecimal(d3).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
            map.put("time",time);
        }else{
            map.put("time",0);
        }
 
        String date = DateUtil.DateToString(new Date(),"yyyy-MM-dd");
        Date d = DateUtil.stringDateFormat(date+" 00:00:00",null);
        Integer todayTime = studyRecordService.sumByTime2(userId,d);
        if(todayTime!=null){
//            double d3 = (Double.valueOf(todayTime))/60;
//            double v = new BigDecimal(d3).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
            map.put("todayTime",todayTime);
        }else{
            map.put("todayTime",0);
        }
 
        map.put("studyUpdate",studyDataService.findPage(pageable).getContent());
        map.put("ziLiaoUpdate",ziLiaoDataService.findPage(pageable).getContent());
        map.put("changeUpdate",changDeptService.findPage(pageable).getContent());
        return success("请求成功",map);
    }
 
    @PostMapping("findAll")
    public Object findAll(Long userId) {
        List list = changDeptService.findAll("userId", userId);
        return success("请求成功",list);
    }
 
    @PostMapping("findStudyIndex")
    public Object findStudyIndex(Long userId) {
        User user = (User) userService.findById(userId);
        Map<String,Object> map = new HashMap<>();
        List<Object> list = studyRecordService.paiMing();
        List<Object> list2 = new ArrayList<>();
        for(Object obj:list){
            Object o[] = (Object[]) obj;
            Map<String,Object> m = new HashMap<>();
            m.put("name",o[1]);
            //double d = (Double.valueOf(o[0].toString()))/60;
            double d = Double.valueOf(o[0].toString());
            double v = new BigDecimal(d).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
            m.put("time",v);
            list2.add(m);
        }
        map.put("paiMing",list2);
        long count = userService.count();
 
        Specification<User> specification = new Specification<User>() {
            @Override
            public Predicate toPredicate(Root<User> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
                List<Predicate> list = new ArrayList<Predicate>();
                list.add(cb.gt(root.get("sumTime"), user.getSumTime()));
                Predicate[] arr = new Predicate[list.size()];
                cq.where(list.toArray(arr));
                return null;
            }
        };
        long count2 = userService.count(specification);
        map.put("myPaiMing",(count2+1)+"/"+count);
 
        Integer time = studyRecordService.sumByXueShi(userId);
        if(time!=null){
            //double d = (Double.valueOf(time))/60;
            //double v = new BigDecimal(d).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
            map.put("time",time);
        }else{
            map.put("time",0);
        }
 
        String date = DateUtil.DateToString(new Date(),"yyyy");
        Date d = DateUtil.stringDateFormat(date+"-01-01 00:00:00",null);
        Integer yearTime = studyRecordService.sumByTime2(userId,d);
        if(yearTime!=null){
            //double d2 = (Double.valueOf(yearTime))/60;
            //double v = new BigDecimal(d2).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
            map.put("yearTime",yearTime);
        }else{
            map.put("yearTime",0);
        }
 
        String date2 = DateUtil.DateToString(new Date(),"yyyy-MM");
        Date d2 = DateUtil.stringDateFormat(date2+"-01 00:00:00",null);
        Integer monthTime = studyRecordService.sumByTime2(userId,d2);
        if(monthTime!=null){
            //double d3 = (Double.valueOf(monthTime))/60;
            //double v = new BigDecimal(d3).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
            map.put("monthTime",monthTime);
        }else{
            map.put("monthTime",0);
        }
 
        return success("请求成功",map);
    }
}