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);
|
}
|
}
|