UserInterestServiceImpl.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.goafanti.user.service.impl;
  2. import java.util.Calendar;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.UUID;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import com.goafanti.common.dao.UserInterestMapper;
  9. import com.goafanti.common.model.UserInterest;
  10. import com.goafanti.core.mybatis.BaseMybatisDao;
  11. import com.goafanti.core.mybatis.page.Pagination;
  12. import com.goafanti.core.shiro.token.TokenManager;
  13. import com.goafanti.user.bo.InterestUserListBo;
  14. import com.goafanti.user.service.UserInterestService;
  15. @Service
  16. public class UserInterestServiceImpl extends BaseMybatisDao<UserInterestMapper> implements UserInterestService {
  17. @Autowired
  18. private UserInterestMapper userInterestMapper;
  19. @Override
  20. public UserInterest findByFromUidAndToUid(String fromUid, String toUid) {
  21. return userInterestMapper.findByFromUidAndToUid(fromUid, toUid);
  22. }
  23. @Override
  24. public String insert(String toUid) {
  25. UserInterest ui = new UserInterest();
  26. ui.setId(UUID.randomUUID().toString());
  27. ui.setFromUid(TokenManager.getUserId());
  28. ui.setToUid(toUid);
  29. Calendar now = Calendar.getInstance();
  30. now.set(Calendar.MILLISECOND, 0);
  31. ui.setCreateTime(now.getTime());
  32. userInterestMapper.insert(ui);
  33. return ui.getId();
  34. }
  35. @Override
  36. public UserInterest findByPrimaryKey(String id) {
  37. return userInterestMapper.selectByPrimaryKey(id);
  38. }
  39. @Override
  40. public int deleteByPrimaryKey(String id) {
  41. return userInterestMapper.deleteByPrimaryKey(id);
  42. }
  43. @SuppressWarnings("unchecked")
  44. @Override
  45. public Pagination<InterestUserListBo> listInterestUser(Integer pageNo, Integer pageSize, Integer userType) {
  46. Map<String, Object> params = new HashMap<>();
  47. if (pageNo == null || pageNo < 0) {
  48. pageNo = 1;
  49. }
  50. if (pageSize == null || pageSize < 0 || pageSize > 10) {
  51. pageSize = 10;
  52. }
  53. if (userType != null) {
  54. params.put("userType", userType);
  55. }
  56. params.put("fromUid", TokenManager.getUserId());
  57. return (Pagination<InterestUserListBo>) findPage("findInterestUserListByPage", "findInterestUserCount", params,
  58. pageNo, pageSize);
  59. }
  60. @Override
  61. public Integer countByToUid(String toUid) {
  62. return userInterestMapper.countByToUid(toUid);
  63. }
  64. }