diff --git a/src/main/java/com/syq/Interceptor/LoginInterceptor.java b/src/main/java/com/syq/Interceptor/LoginInterceptor.java index 869430ed9047062a805b6e5e8f9bb12c9e96c034..9ac424c503d2a1cd2ca6288523d62fd385e3a6d5 100644 --- a/src/main/java/com/syq/Interceptor/LoginInterceptor.java +++ b/src/main/java/com/syq/Interceptor/LoginInterceptor.java @@ -24,7 +24,7 @@ public class LoginInterceptor implements HandlerInterceptor{ } response.setCharacterEncoding("utf-8"); -// String tokenStr = request.getParameter("token"); + String tokenStr = request.getParameter("token"); String tokenStr2 = request.getHeader("token"); if (tokenStr2 != null && tokenStr2 != "") { try { @@ -36,16 +36,16 @@ public class LoginInterceptor implements HandlerInterceptor{ } } -// if (tokenStr != null && tokenStr != "") { -// try { -// Admin admin = TokenUtil.unsign(tokenStr, Admin.class); -// if (admin != null) { -// return true; -// } -// } catch (Exception e) { -// -// } -// } + if (tokenStr != null && tokenStr != "") { + try { + Admin admin = TokenUtil.unsign(tokenStr, Admin.class); + if (admin != null) { + return true; + } + } catch (Exception e) { + + } + } response.setCharacterEncoding("UTF-8"); response.setContentType("application/json; charset=utf-8"); JSONObject json = new JSONObject(); diff --git a/src/main/java/com/syq/controller/BooksController.java b/src/main/java/com/syq/controller/BooksController.java index bc306f939745cec20be3f87f55466d6bdb118dfe..420982bf42db475cf72342529f2511239b90d5f0 100644 --- a/src/main/java/com/syq/controller/BooksController.java +++ b/src/main/java/com/syq/controller/BooksController.java @@ -14,6 +14,7 @@ import com.syq.entity.BookType; import com.syq.entity.Books; import com.syq.entity.ResourcesRoom; import com.syq.service.BooksService; +import com.syq.util.ResultInfoUtil; @RestController @RequestMapping("/books") @@ -32,8 +33,9 @@ public class BooksController { @GetMapping public Object listBooksByPage(Books book,Integer btid,Integer page,Integer limit) { Pageable pageable = PageRequest.of(page-1, limit); - - return booksService.listBooksByPage(book,btid, pageable); + ResultInfoUtil listBooksByPage = booksService.listBooksByPage(book,btid, pageable); + System.out.println(listBooksByPage.toString()); + return listBooksByPage; } /** diff --git a/src/main/java/com/syq/controller/ChartController.java b/src/main/java/com/syq/controller/ChartController.java new file mode 100644 index 0000000000000000000000000000000000000000..35b573fd2cbdf780204c9199f57bd1559f64e1ee --- /dev/null +++ b/src/main/java/com/syq/controller/ChartController.java @@ -0,0 +1,120 @@ +package com.syq.controller; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +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 com.syq.entity.Chart; +import com.syq.entity.ResourcesRoom; +import com.syq.entity.Statistics; +import com.syq.service.ResourcesRoomService; +import com.syq.service.StatisticsService; + +@RequestMapping("admin") +@RestController +public class ChartController { + + //注入资源室 + @Autowired + private ResourcesRoomService resourcesRoomService; + + @Autowired + private StatisticsService statisticsService; + + @PostMapping("/test") + public Object test() { + System.out.println("我被执行了------------------------------------------------------"); + return 1; + } + + /** + * 生成资源室和机房图表 + * @param yearx + * @param monthx + * @param diff + * @return + */ + @GetMapping("chart1") + public Map chart1(String yearx,String monthx,Integer diff) { + Map map = new HashMap(); + //查询所有读书室 + List bookRooms = resourcesRoomService.findByDiff(diff); + //用于存放资源室名称 + List rrname = new ArrayList(); + //用于存放资源室id + List rids = new ArrayList<>(); + for (ResourcesRoom resourcesRoom : bookRooms) { + //将资源室名称存入集合 + rrname.add(resourcesRoom.getRname()); + //将资源室id存入集合 + rids.add(resourcesRoom.getRid()); + } + map.put("rrname", rrname); + //根据资源室id集合查询对应的统计 + List statistics = new ArrayList(); + if(!StringUtils.isEmpty(yearx)) {//判断如果年不为空,查询月份 + statistics = statisticsService.findMonthxByYearx(rids, yearx); + if(!StringUtils.isEmpty(monthx)) {//判断如果年,月不为空,查询天数 + statistics = statisticsService.findDayByMonthx(rids, yearx, monthx); + } + }else { + statistics = statisticsService.listStatisticByRid(rids); + } + String[] month = new String[statistics.size()]; + List list = new ArrayList<>(); + //获取所有月份但是有重复数据 + for (int i=0;i cList = new ArrayList<>(); + for(int i =0;i nums = new ArrayList<>(); + for(int j=0;j data; + private String type = "line"; + private Object areaStyle; + private boolean smooth = true; + public Chart() { + super(); + // TODO Auto-generated constructor stub + } + public Chart(String name, List data, String type, Object areaStyle, boolean smooth) { + super(); + this.name = name; + this.data = data; + this.type = type; + this.areaStyle = areaStyle; + this.smooth = smooth; + } + @Override + public String toString() { + return "Chart [name=" + name + ", data=" + data + ", type=" + type + ", areaStyle=" + areaStyle + ", smooth=" + + smooth + "]"; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public List getData() { + return data; + } + public void setData(List data) { + this.data = data; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public Object getAreaStyle() { + return areaStyle; + } + public void setAreaStyle(Object areaStyle) { + this.areaStyle = areaStyle; + } + public boolean isSmooth() { + return smooth; + } + public void setSmooth(boolean smooth) { + this.smooth = smooth; + } + + +} diff --git a/src/main/java/com/syq/entity/Statistics.java b/src/main/java/com/syq/entity/Statistics.java index 8e252a2ec340f88f329610fb0052bb9fc7e39d6d..2256e89aede315b432dcb53beb3c8fc808a6af04 100644 --- a/src/main/java/com/syq/entity/Statistics.java +++ b/src/main/java/com/syq/entity/Statistics.java @@ -31,14 +31,9 @@ public class Statistics { private Integer staid;//资源统计编号 private Integer peopleNums;//使用人次 - @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date yearx;//年 为避免关键字冲突加上x - - @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date monthx;// 月 - - @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date dayx;// 日 + private String yearx;//年 为避免关键字冲突加上x + private String monthx;// 月 + private String dayx;// 日 @JoinColumn(name = "rid") @ManyToOne(fetch = FetchType.EAGER) diff --git a/src/main/java/com/syq/repository/StatisticsRepository.java b/src/main/java/com/syq/repository/StatisticsRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..b340ee0ced56f5b4dc3ae0759d04ab3846396103 --- /dev/null +++ b/src/main/java/com/syq/repository/StatisticsRepository.java @@ -0,0 +1,43 @@ +package com.syq.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; + +import com.syq.entity.Statistics; + +public interface StatisticsRepository extends JpaRepository,JpaSpecificationExecutor{ + + /** + * 查询所有机房或读书室 + * @param rids + * @return + */ + @Query(value = "select * from statistics where rid in (?1) ",nativeQuery = true) + List findStatisticsByRid(List rids); + + /** + * 无用 + * @return + */ + @Query(value = "select sum(people_nums) from statistics where rid = ?1 and monthx = ?2 ",nativeQuery = true) + Integer CountStatisticByRidAndMonth(Integer rid,String monthx); + + /** + * 根据确定的年和资源室id来查询 + * @param yearx + * @return + */ + @Query(value = "select * from statistics where rid in (:rids) and yearx = :yearx ",nativeQuery = true) + List findMonthxByYearx(List rids,String yearx); + + /** + * 根据确定的年,月和资源室id来查询 + * @param yearx + * @return + */ + @Query(value = "select * from statistics where rid in (:rids) and yearx = :yearx and monthx = :monthx ",nativeQuery = true) + List findDayByMonthx(List rids,String yearx,String monthx); +} diff --git a/src/main/java/com/syq/service/StatisticsService.java b/src/main/java/com/syq/service/StatisticsService.java new file mode 100644 index 0000000000000000000000000000000000000000..04943b44099d8a8dca093fede3ad0f5f7d53b96d --- /dev/null +++ b/src/main/java/com/syq/service/StatisticsService.java @@ -0,0 +1,41 @@ +package com.syq.service; + +import java.util.List; + +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.repository.Query; + +import com.syq.entity.Statistics; + +public interface StatisticsService { + + /** + * 添加对某个资源室的统计 + * @param rid + * @return + */ + Statistics addStatistics(Statistics sta); + + /** + * 根据多个资源室id查询 + */ + List listStatisticByRid(List rids); + + + /** + * 根据月份和资源室id统计当月点击数量 + */ + Integer CountStatisticByRidAndMonth(Integer rid,String monthx); + + /** + * 多条件查询统计数量 + * @param sta + * @param rid + * @return + */ + Integer CountStatistics(Statistics sta,Integer rid); + + List findMonthxByYearx(List rids,String yearx); + + List findDayByMonthx(List rids,String yearx,String monthx); +} diff --git a/src/main/java/com/syq/service/impl/StatisticsServiceImpl.java b/src/main/java/com/syq/service/impl/StatisticsServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..47242fb0a8ecd9e14384161ff454ebb6b9a91e97 --- /dev/null +++ b/src/main/java/com/syq/service/impl/StatisticsServiceImpl.java @@ -0,0 +1,103 @@ +package com.syq.service.impl; + +import java.util.List; + +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Expression; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import com.syq.entity.Statistics; +import com.syq.entity.Students; +import com.syq.repository.StatisticsRepository; +import com.syq.service.StatisticsService; + +@Service +public class StatisticsServiceImpl implements StatisticsService { + + @Autowired + private StatisticsRepository statisticsRepository; + + @Override + public Statistics addStatistics(Statistics sta) { + // TODO Auto-generated method stub + return statisticsRepository.save(sta); + } + + @Override + public List listStatisticByRid(List rids) { + // TODO Auto-generated method stub + return statisticsRepository.findStatisticsByRid(rids); + } + + @Override + public Integer CountStatisticByRidAndMonth(Integer rid, String monthx) { + // TODO Auto-generated method stub + return statisticsRepository.CountStatisticByRidAndMonth(rid, monthx); + } + + @Override + public List findMonthxByYearx(List rids,String yearx) { + // TODO Auto-generated method stub + return statisticsRepository.findMonthxByYearx(rids,yearx); + } + + @Override + public List findDayByMonthx(List rids,String yearx, String monthx) { + // TODO Auto-generated method stub + return statisticsRepository.findDayByMonthx(rids,yearx, monthx); + } + + @Override + public Integer CountStatistics(Statistics sta, Integer rid) { + List statistics = statisticsRepository.findAll(getspec(sta,rid)); + Integer nums = 0; + for (Statistics s : statistics) { + nums += s.getPeopleNums(); + } + System.out.println(nums); + return nums; + } + + /** + * 动态SQL + * @param stu + * @return + */ + private Specification getspec(Statistics sta,Integer rid) { + // TODO Auto-generated method stub + return new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { + //创建动态SQL表达式 + Predicate predicate = criteriaBuilder.conjunction(); + //创建动态SQL集合 + List> expressions = predicate.getExpressions(); + //当年份不为空是 + if(!StringUtils.isEmpty(sta.getYearx())) { + expressions.add(criteriaBuilder.equal(root.get("yearx"), sta.getYearx())); + } + if(!StringUtils.isEmpty(sta.getMonthx())) { + expressions.add(criteriaBuilder.equal(root.get("monthx"), sta.getMonthx())); + } + if(!StringUtils.isEmpty(sta.getDayx())) { + expressions.add(criteriaBuilder.equal(root.get("dayx"), sta.getDayx())); + } + if(rid!=null) { + expressions.add(criteriaBuilder.equal(root.get("resourcesRoom").get("rid"), rid)); + } + return predicate; + } + }; + } + + +} diff --git a/src/main/java/com/syq/service/impl/StudentsServiceImpl.java b/src/main/java/com/syq/service/impl/StudentsServiceImpl.java index b536ef50da7fdcf2810ed98149b2433b00495573..02b1c0b4dd07709783b4cf6ab2282cacca1bf852 100644 --- a/src/main/java/com/syq/service/impl/StudentsServiceImpl.java +++ b/src/main/java/com/syq/service/impl/StudentsServiceImpl.java @@ -35,9 +35,10 @@ public class StudentsServiceImpl implements StudentsService{ public List exporExcel(String ids) { List sList = new ArrayList(); if(ids !=null && ids != "") { - for(int i =0;i stu = studentRepository.findById(id); sList.add(stu.get()); } diff --git a/src/main/java/com/syq/util/ResultInfoUtil.java b/src/main/java/com/syq/util/ResultInfoUtil.java index 940e7d85f51d8a10f443373cf2dd4da644af5275..ce55d3768ac00daa1a7313470aa40b5e44ec6500 100644 --- a/src/main/java/com/syq/util/ResultInfoUtil.java +++ b/src/main/java/com/syq/util/ResultInfoUtil.java @@ -8,7 +8,7 @@ public class ResultInfoUtil { private Integer count;//总条数 private List data ;//查询的返回的数据集合 private String msg="";//返回的消息 - private Integer code;//返回的状态码 + private Integer code = 0;//返回的状态码 public ResultInfoUtil() { super(); // TODO Auto-generated constructor stub