DemandInterestServiceImpl.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.goafanti.demand.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.DemandInterestMapper;
  9. import com.goafanti.common.model.DemandInterest;
  10. import com.goafanti.common.model.User;
  11. import com.goafanti.common.utils.StringUtils;
  12. import com.goafanti.core.mybatis.BaseMybatisDao;
  13. import com.goafanti.core.mybatis.page.Pagination;
  14. import com.goafanti.core.shiro.token.TokenManager;
  15. import com.goafanti.demand.service.DemandInterestService;
  16. import com.goafanti.portal.bo.DemandInterestListBo;
  17. @Service
  18. public class DemandInterestServiceImpl extends BaseMybatisDao<DemandInterestMapper> implements DemandInterestService {
  19. @Autowired
  20. private DemandInterestMapper demandInterestMapper;
  21. @Override
  22. public int saveCancelDemandInterest(String id) {
  23. return demandInterestMapper.deleteByPrimaryKey(id,TokenManager.getUserId());
  24. }
  25. @Override
  26. public String saveDemandInterest(String id) {
  27. DemandInterest di = new DemandInterest();
  28. di.setId(UUID.randomUUID().toString());
  29. di.setDemandId(id);
  30. Calendar now = Calendar.getInstance();
  31. now.set(Calendar.MILLISECOND, 0);
  32. di.setCreateTime(now.getTime());
  33. di.setUid(TokenManager.getUserId());
  34. if (StringUtils.isBlank(di.getUid())){
  35. return null;
  36. }
  37. demandInterestMapper.insert(di);
  38. return di.getId();
  39. }
  40. @Override
  41. public DemandInterest selectDemandInterestByUidAndDemandId(String uid, String id) {
  42. return demandInterestMapper.selectDemandInterestByUidAndDemandId(uid, id);
  43. }
  44. @SuppressWarnings("unchecked")
  45. @Override
  46. public Pagination<DemandInterestListBo> listDemandInterest(Integer pNo, Integer pSize) {
  47. Map<String, Object> params = new HashMap<>();
  48. if (pNo == null || pNo < 0) {
  49. pNo = 1;
  50. }
  51. if (pSize == null || pSize < 0 || pSize > 10) {
  52. pSize = 10;
  53. }
  54. if (TokenManager.getToken() instanceof User) {
  55. params.put("uid", TokenManager.getUserId());
  56. }
  57. return (Pagination<DemandInterestListBo>) findPage("findDemandInterestListByPage",
  58. "findDemandInterestCount", params, pNo, pSize);
  59. }
  60. @Override
  61. public int countDemandInterest(String id) {
  62. return demandInterestMapper.countInterestById(id);
  63. }
  64. }