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