This commit is contained in:
@@ -64,4 +64,24 @@ public class CommonConstants {
|
||||
* 默认sortKey
|
||||
*/
|
||||
public static final Integer DEFAULT_SORT_KEY = 999;
|
||||
|
||||
/**
|
||||
* action type
|
||||
*/
|
||||
public static final String ACTION_TYPE_STORY_CREATE = "story_create";
|
||||
public static final String ACTION_TYPE_STORY_UPDATE = "story_update";
|
||||
public static final String ACTION_TYPE_STORY_DELETE = "story_delete";
|
||||
public static final String ACTION_TYPE_STORY_ITEM_CREATE = "story_item_create";
|
||||
public static final String ACTION_TYPE_STORY_ITEM_UPDATE = "story_item_update";
|
||||
public static final String ACTION_TYPE_STORY_ITEM_DELETE = "story_item_delete";
|
||||
|
||||
/**
|
||||
* action remark
|
||||
*/
|
||||
public static final String ACTION_REMARK_STORY_CREATE = "创建故事";
|
||||
public static final String ACTION_REMARK_STORY_UPDATE = "更新故事";
|
||||
public static final String ACTION_REMARK_STORY_DELETE = "删除故事";
|
||||
public static final String ACTION_REMARK_STORY_ITEM_CREATE = "创建故事子项";
|
||||
public static final String ACTION_REMARK_STORY_ITEM_UPDATE = "更新故事子项";
|
||||
public static final String ACTION_REMARK_STORY_ITEM_DELETE = "删除故事子项";
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ public interface CommonRelationMapper {
|
||||
List<String> getStoryItemsByImageInstanceId(String imageInstanceId);
|
||||
|
||||
void deleteImageStoryItemRelation(String imageInstanceId, String storyItemId);
|
||||
void deleteRelationByRelaId(String instanceId);
|
||||
}
|
||||
|
||||
@@ -166,6 +166,9 @@ public class FileServiceImpl implements FileService {
|
||||
imageInfo.setIsDeleted(CommonConstants.DELETED);
|
||||
imageInfo.setUpdateTime(LocalDateTime.now());
|
||||
imageInfoMapper.update(imageInfo);
|
||||
|
||||
// 删除关联关系
|
||||
commonRelationMapper.deleteRelationByRelaId(instanceId);
|
||||
} catch (Exception e) {
|
||||
log.error("删除图片失败", e);
|
||||
throw new CustomException(500, "删除图片失败");
|
||||
|
||||
@@ -30,4 +30,12 @@
|
||||
INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id)
|
||||
VALUES (#{relaId}, #{subRelaId}, #{relationType}, #{userId})
|
||||
</insert>
|
||||
|
||||
<delete id="deleteRelationByRelaId">
|
||||
UPDATE common_relation
|
||||
SET is_delete = 1,
|
||||
update_time = NOW()
|
||||
WHERE rela_id = #{imageInstanceId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -12,6 +12,8 @@ public class Story {
|
||||
private String description;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDateTime storyTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
private String updateId;
|
||||
|
||||
@@ -13,11 +13,11 @@ public class StoryItem {
|
||||
private String description;
|
||||
private String location;
|
||||
private String createId;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime storyItemTime;
|
||||
private Integer isDelete;
|
||||
private String coverInstanceId;
|
||||
|
||||
@@ -8,6 +8,11 @@ import java.util.List;
|
||||
public interface StoryActivityService {
|
||||
void logActivity(StoryActivity activity);
|
||||
|
||||
/**
|
||||
* record activity log
|
||||
* @return
|
||||
*/
|
||||
|
||||
List<StoryActivity> listMyAndFriendsActivities();
|
||||
|
||||
/**
|
||||
|
||||
@@ -224,11 +224,12 @@ public class StoryItemServiceImpl implements StoryItemService {
|
||||
}
|
||||
|
||||
private void buildStoryItemImageRelation(String storyItemId, String imageIds) {
|
||||
String currentId = currentUserId();
|
||||
CommonRelationDTO relationDTO = new CommonRelationDTO();
|
||||
relationDTO.setRelaId(storyItemId);
|
||||
relationDTO.setSubRelaId(imageIds);
|
||||
relationDTO.setRelationType(CommonConstants.RELATION_STORY_ITEM_AND_IMAGE);
|
||||
relationDTO.setUserId("9999");
|
||||
relationDTO.setUserId(currentId);
|
||||
relationDTO.setCreateTime(LocalDateTime.now());
|
||||
relationDTO.setUpdateTime(LocalDateTime.now());
|
||||
commonRelationMapper.insertRelation(relationDTO);
|
||||
|
||||
@@ -33,6 +33,14 @@ public class StoryServiceImpl implements StoryService {
|
||||
|
||||
@Autowired
|
||||
private StoryActivityService storyActivityService;
|
||||
|
||||
private String getCurrentUserId() {
|
||||
String currentUserId = UserContextUtils.getCurrentUserId();
|
||||
if (currentUserId == null || currentUserId.isEmpty()) {
|
||||
throw new CustomException(ResponseEnum.UNAUTHORIZED, "未获取到用户身份");
|
||||
}
|
||||
return currentUserId;
|
||||
}
|
||||
@Override
|
||||
public void createStory(StoryVo storyVo) {
|
||||
try {
|
||||
@@ -47,6 +55,7 @@ public class StoryServiceImpl implements StoryService {
|
||||
story.setInstanceId(IdUtils.randomUuidUpper());
|
||||
story.setDescription(storyVo.getDescription());
|
||||
story.setStatus(storyVo.getStatus());
|
||||
story.setStoryTime(storyVo.getStoryTime());
|
||||
story.setCreateTime(LocalDateTime.now());
|
||||
story.setUpdateTime(LocalDateTime.now());
|
||||
story.setLogo(storyVo.getLogo());
|
||||
@@ -56,14 +65,15 @@ public class StoryServiceImpl implements StoryService {
|
||||
StoryPermissionVo permissionVo = new StoryPermissionVo();
|
||||
permissionVo.setStoryInstanceId(story.getInstanceId());
|
||||
permissionVo.setUserId(currentUserId);
|
||||
permissionVo.setPermissionType(CommonConstants.STORY_PERMISSION_TYPE_OWNER); // 创建者权限
|
||||
// 创建者权限
|
||||
permissionVo.setPermissionType(CommonConstants.STORY_PERMISSION_TYPE_OWNER);
|
||||
storyPermissionService.createPermission(permissionVo);
|
||||
|
||||
StoryActivity activity = new StoryActivity();
|
||||
activity.setActorId(currentUserId);
|
||||
activity.setAction("create_story");
|
||||
activity.setAction(CommonConstants.ACTION_TYPE_STORY_CREATE);
|
||||
activity.setStoryInstanceId(story.getInstanceId());
|
||||
activity.setRemark("创建故事");
|
||||
activity.setRemark(CommonConstants.ACTION_REMARK_STORY_CREATE);
|
||||
storyActivityService.logActivity(activity);
|
||||
} catch (Exception e) {
|
||||
log.error("创建故事失败", e);
|
||||
@@ -73,40 +83,48 @@ public class StoryServiceImpl implements StoryService {
|
||||
|
||||
@Override
|
||||
public void updateStory(StoryVo storyVo, String storyId) {
|
||||
String currentUserId = getCurrentUserId();
|
||||
|
||||
Story story = storyMapper.selectByInstanceId(storyId);
|
||||
if (story == null) {
|
||||
throw new CustomException(ResponseEnum.NOT_FOUND);
|
||||
}
|
||||
|
||||
story.setTitle(storyVo.getTitle());
|
||||
story.setDescription(storyVo.getDescription());
|
||||
story.setStatus(storyVo.getStatus());
|
||||
story.setStoryTime(storyVo.getStoryTime());
|
||||
story.setUpdateTime(LocalDateTime.now());
|
||||
story.setLogo(storyVo.getLogo());
|
||||
|
||||
String currentUserId = UserContextUtils.getCurrentUserId();
|
||||
if (currentUserId != null && !currentUserId.isEmpty()) {
|
||||
story.setUpdateId(currentUserId);
|
||||
}
|
||||
storyMapper.update(story);
|
||||
|
||||
StoryActivity activity = new StoryActivity();
|
||||
activity.setActorId(currentUserId);
|
||||
activity.setAction("update_story");
|
||||
activity.setAction(CommonConstants.ACTION_TYPE_STORY_UPDATE);
|
||||
activity.setStoryInstanceId(storyId);
|
||||
activity.setRemark("更新故事");
|
||||
activity.setRemark(CommonConstants.ACTION_REMARK_STORY_UPDATE);
|
||||
storyActivityService.logActivity(activity);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStory(String storyId) {
|
||||
String currentUserId = getCurrentUserId();
|
||||
Story story = storyMapper.selectByInstanceId(storyId);
|
||||
if (story == null) {
|
||||
throw new CustomException(ResponseEnum.NOT_FOUND);
|
||||
}
|
||||
// delete story
|
||||
storyMapper.deleteByInstanceId(storyId);
|
||||
// delete permission
|
||||
storyPermissionService.deletePermission(storyId);
|
||||
// delete activity
|
||||
StoryActivity activity = new StoryActivity();
|
||||
activity.setActorId(currentUserId);
|
||||
activity.setAction(CommonConstants.ACTION_TYPE_STORY_DELETE);
|
||||
activity.setStoryInstanceId(storyId);
|
||||
activity.setRemark(CommonConstants.ACTION_REMARK_STORY_DELETE);
|
||||
storyActivityService.logActivity(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,10 +149,7 @@ public class StoryServiceImpl implements StoryService {
|
||||
@Override
|
||||
public List<Story> getStories(StoryVo storyVo) {
|
||||
try {
|
||||
String currentUserId = UserContextUtils.getCurrentUserId();
|
||||
if (currentUserId == null || currentUserId.isEmpty()) {
|
||||
throw new CustomException(ResponseEnum.UNAUTHORIZED, "未获取到用户身份");
|
||||
}
|
||||
String currentUserId = getCurrentUserId();
|
||||
return storyMapper.selectByOwnerId(currentUserId);
|
||||
} catch (Exception e) {
|
||||
log.error("查询用户故事列表失败", e);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.timeline.story.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class StoryVo {
|
||||
private String id;
|
||||
@@ -11,4 +14,6 @@ public class StoryVo {
|
||||
private String description;
|
||||
private String status;
|
||||
private String logo;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDateTime storyTime;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<mapper namespace="com.timeline.story.dao.StoryMapper">
|
||||
|
||||
<insert id="insert">
|
||||
INSERT INTO story (instance_id, title, description, owner_id, status, logo)
|
||||
VALUES (#{instanceId}, #{title}, #{description}, #{ownerId}, #{status}, #{logo})
|
||||
INSERT INTO story (instance_id, title, description, owner_id, status, logo, story_time)
|
||||
VALUES (#{instanceId}, #{title}, #{description}, #{ownerId}, #{status}, #{logo}, #{storyTime})
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
@@ -16,12 +16,13 @@
|
||||
update_id = #{updateId},
|
||||
status = #{status},
|
||||
update_time = NOW(),
|
||||
story_time = #{storyTime},
|
||||
logo = #{logo}
|
||||
WHERE instance_id = #{instanceId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteByInstanceId">
|
||||
UPDATE story SET story.is_delete = 1 WHERE instance_id = #{instanceId}
|
||||
UPDATE story SET story.is_delete = 1, update_time = NOW() WHERE instance_id = #{instanceId}
|
||||
</delete>
|
||||
|
||||
<select id="selectByInstanceId" resultType="com.timeline.story.entity.Story">
|
||||
|
||||
Reference in New Issue
Block a user