RelationManagerController.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.uas.sso.controller;
  2. import com.uas.sso.service.RelationService;
  3. import com.uas.sso.util.encry.Md5Utils;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.ui.ModelMap;
  8. import org.springframework.web.bind.annotation.GetMapping;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. /**
  12. * 用户企业关系管理controller
  13. *
  14. * @author wangmh
  15. * @date 2018/1/2
  16. */
  17. @RestController
  18. @RequestMapping("/api/relation")
  19. public class RelationManagerController extends BaseController {
  20. @Autowired
  21. private RelationService relationService;
  22. private static final Logger LOGGER = LoggerFactory.getLogger(RelationManagerController.class);
  23. /**
  24. * 分页获取用户企业关系信息
  25. * @param pageNumber 当前页数
  26. * @param pageSize 每页大小
  27. * @param timestamp 时间戳,与当前时间不能相差10分钟
  28. * @param encro 签名 md5(#{pageNumber}, #{pageSize}, #{timestamp}, ssoAccountSync),
  29. * @return
  30. */
  31. @GetMapping("/paging/info")
  32. public ModelMap getRelationByUpdateTime(int pageNumber, int pageSize, long timestamp, String encro) {
  33. // 验证时间
  34. long current = System.currentTimeMillis();
  35. if (Math.abs(current - timestamp) > 10 * 60 * 1000) {
  36. LOGGER.warn("全量更新:分页获取企业信息请求过期,当前时间:{},请求时间:{}", current, timestamp);
  37. return error("请求过期");
  38. }
  39. // 验证签名
  40. String laws = String.format("%s, %s, %s, %s", pageNumber, pageSize, timestamp, "ssoAccountSync");
  41. String str = Md5Utils.encode(laws, null);
  42. if (!str.equals(encro)) {
  43. LOGGER.warn("全量更新:分页获取企业信息签名错误,明文:{},签名:{}", laws, encro);
  44. return error("签名错误");
  45. }
  46. return success(relationService.getRelationInfo(pageNumber, pageSize));
  47. }
  48. }