评语一条龙

develop
zhouj1203@hotmail.com 4 months ago
parent 0e38d74d08
commit 2e6d04aeff

@ -1,11 +1,10 @@
package cn.teammodel.controller.admin.controller; package cn.teammodel.controller.admin.controller;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.controller.admin.service.ArtService;
import cn.teammodel.controller.admin.service.CommonService; import cn.teammodel.controller.admin.service.CommonService;
import cn.teammodel.model.dto.admin.art.ArtFindDto; import cn.teammodel.model.dto.admin.common.CommentDto;
import cn.teammodel.model.dto.admin.common.GCDto; import cn.teammodel.model.dto.admin.common.GCDto;
import cn.teammodel.model.vo.admin.ArtElementsVo; import cn.teammodel.model.entity.common.Comment;
import cn.teammodel.model.vo.admin.GradeAndClassVo; import cn.teammodel.model.vo.admin.GradeAndClassVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -15,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
@ -32,4 +30,22 @@ public class CommonController {
List<GradeAndClassVo> res = commonService.getGradeAndClass(gcDto); List<GradeAndClassVo> res = commonService.getGradeAndClass(gcDto);
return R.success(res); return R.success(res);
} }
@PostMapping("save")
@ApiOperation("保存评语")
public R<Comment> saveOrUpdateComment(@Valid @RequestBody Comment comment) {
Comment res = commonService.saveOrUpdateComment(comment);
return R.success(res);
}
@PostMapping("delete")
@ApiOperation("删除评语")
public R<List<String>> deleteComment(@Valid @RequestBody CommentDto comment) {
List<String> res = commonService.deleteComment(comment);
return R.success(res);
}
@PostMapping("find")
@ApiOperation("根据ID查询评语评语")
public R<List<Comment>> findComment(@Valid @RequestBody Comment comment) {
List<Comment> res = commonService.getCommentById(comment);
return R.success(res);
}
} }

@ -1,10 +1,15 @@
package cn.teammodel.controller.admin.service; package cn.teammodel.controller.admin.service;
import cn.teammodel.model.dto.admin.common.CommentDto;
import cn.teammodel.model.dto.admin.common.GCDto; import cn.teammodel.model.dto.admin.common.GCDto;
import cn.teammodel.model.entity.common.Comment;
import cn.teammodel.model.vo.admin.GradeAndClassVo; import cn.teammodel.model.vo.admin.GradeAndClassVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
public interface CommonService { public interface CommonService {
List<GradeAndClassVo> getGradeAndClass(GCDto gcDto); List<GradeAndClassVo> getGradeAndClass(GCDto gcDto);
Comment saveOrUpdateComment(Comment comment);
List<String> deleteComment(CommentDto comment);
List<Comment> getCommentById(Comment comment);
} }

@ -1,19 +1,26 @@
package cn.teammodel.controller.admin.service.impl; package cn.teammodel.controller.admin.service.impl;
import cn.teammodel.controller.admin.service.CommonService; import cn.teammodel.controller.admin.service.CommonService;
import cn.teammodel.model.dto.admin.common.CommentDto;
import cn.teammodel.model.dto.admin.common.GCDto; import cn.teammodel.model.dto.admin.common.GCDto;
import cn.teammodel.model.entity.common.Comment;
import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.ClassInfo;
import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.School;
import cn.teammodel.model.vo.admin.GradeAndClassVo; import cn.teammodel.model.vo.admin.GradeAndClassVo;
import cn.teammodel.repository.ClassRepository; import cn.teammodel.repository.ClassRepository;
import cn.teammodel.repository.CommentRepository;
import cn.teammodel.repository.SchoolRepository; import cn.teammodel.repository.SchoolRepository;
import cn.teammodel.utils.MonthToNumberConverter; import cn.teammodel.utils.MonthToNumberConverter;
import com.azure.cosmos.models.CosmosPatchOperations;
import com.azure.cosmos.models.PartitionKey;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.Month; import java.time.Month;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -25,6 +32,8 @@ public class CommonServiceImpl implements CommonService {
private SchoolRepository schoolRepository; private SchoolRepository schoolRepository;
@Resource @Resource
private ClassRepository classRepository; private ClassRepository classRepository;
@Resource
private CommentRepository commentRepository;
@Override @Override
public List<GradeAndClassVo> getGradeAndClass(GCDto gcDto) { public List<GradeAndClassVo> getGradeAndClass(GCDto gcDto) {
@ -99,4 +108,39 @@ public class CommonServiceImpl implements CommonService {
throw new RuntimeException("获取当前学校当前学段年级班级信息失败"); throw new RuntimeException("获取当前学校当前学段年级班级信息失败");
} }
} }
@Override
public Comment saveOrUpdateComment(Comment comment) {
List<Comment> comments = commentRepository.findById(comment.getId(),comment.getSchool());
Comment existingComment = comments.stream().findFirst().orElse(null);
if (existingComment != null) {
// 如果评论对象存在,则进行更新操作
// 这里你可以根据需要更新评论对象的属性
existingComment.setContent(comment.getContent());
existingComment.setUpdateTime(Instant.now().toEpochMilli());
commentRepository.deleteById(existingComment.getId(),new PartitionKey(existingComment.getSchool()));
// 最后保存更新后的评论对象
return commentRepository.save(existingComment);
} else {
// 如果评论对象不存在,则创建新的记录
comment.setCode("Comment-"+ comment.getSchool());
comment.setCreateTime(Instant.now().toEpochMilli());
return commentRepository.save(comment);
}
}
@Override
public List<String> deleteComment(CommentDto comment) {
for (String id : comment.getIds()) {
commentRepository.deleteById(id,new PartitionKey(comment.getCode()));
}
return comment.getIds();
}
@Override
public List<Comment> getCommentById(Comment comment) {
return commentRepository.findById(comment.getId(),comment.getSchool());
}
} }

@ -0,0 +1,14 @@
package cn.teammodel.model.dto.admin.common;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class CommentDto {
@ApiModelProperty("需要删除的id集合")
private List<String> ids;
@ApiModelProperty("完成的编码如Comment-hbcn")
private String code;
}

@ -12,18 +12,21 @@ import lombok.EqualsAndHashCode;
@Data @Data
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Comment extends BaseItem { public class Comment extends BaseItem {
@ApiModelProperty("活动内容")
private String content; private String content;
private String creatorId; private String creatorId;
private String creatorName; private String creatorName;
@ApiModelProperty("学校编码")
private String school; private String school;
private String studentId; private String studentId;
@ApiModelProperty("活动ID")
private String activityId; private String activityId;
@ApiModelProperty("活动类型") @ApiModelProperty("活动类型")
private String activityType; private String activityType;
@ApiModelProperty("评论类型") @ApiModelProperty("评论类型")
private String contentType; private String contentType;
private String pk = "comment"; private String pk = "Comment";
//private int ttl = -1; private int ttl = -1;
private Long createTime; private Long createTime;
private Long updateTime; private Long updateTime;

@ -0,0 +1,19 @@
package cn.teammodel.repository;
import cn.teammodel.model.entity.common.Comment;
import cn.teammodel.model.entity.school.School;
import com.azure.cosmos.models.CosmosPatchOperations;
import com.azure.cosmos.models.PartitionKey;
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface CommentRepository extends CosmosRepository<Comment, String> {
@Query("select * from Comment as s where s.id = @id and s.pk = 'Comment' and s.school = @school ")
List<Comment> findById(@Param("id") String id, @Param("school") String school);
}
Loading…
Cancel
Save