Blame view

src/main/java/com/objecteye/service/impl/SpecialAuthenticationServiceImpl.java 3.99 KB
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
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
  package com.objecteye.service.impl;
  
  import com.alibaba.fastjson.JSON;
  import com.alibaba.fastjson.JSONObject;
  import com.objecteye.entity.PageResult;
  import com.objecteye.pojo.SpecialAuthenticationUrlConfig;
  import com.objecteye.service.ISpecialAuthenticationService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.data.mongodb.core.MongoTemplate;
  import org.springframework.data.mongodb.core.query.Criteria;
  import org.springframework.data.mongodb.core.query.Query;
  import org.springframework.stereotype.Component;
  
  import java.util.List;
  import java.util.Map;
  
  @Component
  public class SpecialAuthenticationServiceImpl implements ISpecialAuthenticationService {
  
      @Autowired
      private MongoTemplate mongoTemplate;
  
      /**
       * 分页查询
       *
       * @param requestMap 请求参数
       * @return 结果集
       */
      @Override
      public PageResult findByPage(Map<String, Object> requestMap) {
          Integer pagevolume = (Integer) requestMap.get("pagevolume");
          Integer currentpage = (Integer) requestMap.get("currentpage");
  
          List<SpecialAuthenticationUrlConfig> specialAuthenticationUrlConfigs = mongoTemplate
                  .find(new Query().limit(pagevolume).skip((currentpage - 1) * pagevolume), SpecialAuthenticationUrlConfig.class);
          long total = mongoTemplate
                  .count(new Query().limit(pagevolume).skip((currentpage - 1) * pagevolume), SpecialAuthenticationUrlConfig.class);
          total = (long) Math.ceil((double) total / pagevolume);
          return new PageResult<>(total, specialAuthenticationUrlConfigs);
      }
  
      /**
       * 添加特殊地址权限要求
       *
       * @param requestMap 请求参数
       * @return 结果集
       */
      @Override
      public JSONObject addConfig(Map<String, Object> requestMap) {
          SpecialAuthenticationUrlConfig urlConfig = JSON.parseObject(JSON.toJSONString(requestMap), SpecialAuthenticationUrlConfig.class);
          urlConfig = mongoTemplate.insert(urlConfig);
          JSONObject resultObj = new JSONObject();
          if (urlConfig.getId() == null) {
              resultObj.put("error", "数据创建失败");
          } else {
              resultObj.put("id", urlConfig.getId());
          }
          return resultObj;
      }
  
      /**
       * 更新配置信息
       *
       * @param requestMap 请求参数
       * @return 结果集
       */
      @Override
      public JSONObject updateConfig(Map<String, Object> requestMap) {
          SpecialAuthenticationUrlConfig urlConfig = JSON.parseObject(JSON.toJSONString(requestMap), SpecialAuthenticationUrlConfig.class);
          long count = mongoTemplate.count(Query.query(Criteria.where("id").is(urlConfig.getId())), SpecialAuthenticationUrlConfig.class);
          JSONObject resultObj = new JSONObject();
          if (count == 0) {
              resultObj.put("error", "数据不存在");
          } else {
              mongoTemplate.save(urlConfig);
          }
          return resultObj;
      }
  
      /**
       * 删除配置信息
       *
       * @param requestMap 请求参数
       * @return 结果集
       */
      @Override
      public JSONObject deleteConfig(Map<String, Object> requestMap) {
          SpecialAuthenticationUrlConfig urlConfig = JSON.parseObject(JSON.toJSONString(requestMap), SpecialAuthenticationUrlConfig.class);
          mongoTemplate.remove(Query.query(Criteria.where("id").is(urlConfig.getId())), SpecialAuthenticationUrlConfig.class);
          return new JSONObject();
      }
  
      /**
       * 校验相同配置信息是否存在
       *
       * @param requestMap 请求参数
       * @return 结果集
       */
      @Override
      public JSONObject checkConfig(Map<String, Object> requestMap) {
          SpecialAuthenticationUrlConfig urlConfig = JSON.parseObject(JSON.toJSONString(requestMap), SpecialAuthenticationUrlConfig.class);
          long count = mongoTemplate.count(Query.query(Criteria.where("id").is(urlConfig.getId())), SpecialAuthenticationUrlConfig.class);
          JSONObject resultObj = new JSONObject();
          resultObj.put("count", count);
          return resultObj;
      }
  }