parent
0fdbf0e1e4
commit
12bf2c7468
@ -0,0 +1,11 @@
|
||||
package com.luoo.user.dao;
|
||||
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import com.luoo.user.pojo.UserCollect;
|
||||
|
||||
public interface UserCollectDao extends JpaRepository<UserCollect, Integer>, JpaSpecificationExecutor<UserCollect> {
|
||||
public UserCollect findByUserIdAndObjectIdAndCollectType(String userId, String objectId, Integer collectType);
|
||||
public long deleteByUserIdAndObjectIdAndCollectType(String userId, String objectId, Integer collectType);
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.luoo.user.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* 用户收藏
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="tb_user_collect")
|
||||
public class UserCollect implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 收藏ID
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
private Integer collectId;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 主体ID 期刊ID,歌曲ID
|
||||
*/
|
||||
private String objectId;
|
||||
|
||||
/**
|
||||
* 0:为歌曲,1:期刊
|
||||
*/
|
||||
private Integer collectType;
|
||||
|
||||
/**
|
||||
* 收藏时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date collectTime;
|
||||
}
|
@ -1,18 +1,45 @@
|
||||
package com.luoo.user.service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.luoo.user.dao.UserCollectDao;
|
||||
import com.luoo.user.dao.UserInfoDao;
|
||||
import com.luoo.user.pojo.UserCollect;
|
||||
|
||||
import api.StatusCode;
|
||||
import enums.CollectTypeEnum;
|
||||
import exception.BizException;
|
||||
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class UserCollectService {
|
||||
|
||||
@Autowired
|
||||
private UserCollectDao userCollectDao;
|
||||
public void saveCollect(String userId, String objectId, Integer collectType) {
|
||||
|
||||
CollectTypeEnum collectTypeEnum = CollectTypeEnum.getByType(collectType);
|
||||
if (null == collectTypeEnum) {
|
||||
throw new BizException(StatusCode.VALIDATE_FAILED);
|
||||
}
|
||||
UserCollect dbCollect = userCollectDao.findByUserIdAndObjectIdAndCollectType(userId, objectId, collectType);
|
||||
if (null!=dbCollect) {
|
||||
return;
|
||||
}
|
||||
UserCollect userCollect = new UserCollect();
|
||||
userCollect.setUserId(userId);
|
||||
userCollect.setCollectTime(new Date());
|
||||
userCollect.setObjectId(objectId);
|
||||
userCollect.setCollectType(collectType);
|
||||
userCollectDao.save(userCollect);
|
||||
}
|
||||
|
||||
public void deleteUserCollectByUserIdAndObjectIdAndCollectType(String userId, String objectId,
|
||||
Integer collectType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
userCollectDao.deleteByUserIdAndObjectIdAndCollectType(userId, objectId, collectType);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue