修改活动响应实体

master
pan 4 years ago
parent 750c6dbcf7
commit 541f73dd38
  1. 12
      src/main/java/com/share/help/controller/ActivityController.java
  2. 10
      src/main/java/com/share/help/dao/ActivityMapper.java
  3. 25
      src/main/java/com/share/help/entity/custorm/ActivityDetail.java
  4. 10
      src/main/java/com/share/help/service/ActivityService.java
  5. 4
      src/main/java/com/share/help/service/LeaveWordService.java
  6. 9
      src/main/resources/mapping/ActivityMapper.xml
  7. 10
      src/test/java/com/share/help/HelpApplicationTests.java

@ -1,11 +1,7 @@
package com.share.help.controller;
import com.share.help.Constants;
import com.share.help.entity.ActivityEntity;
import com.share.help.entity.custorm.FindActivityRes;
import com.share.help.entity.custorm.HelpRes;
import com.share.help.entity.custorm.SeekHelpSum;
import com.share.help.entity.custorm.UserWithName;
import com.share.help.entity.custorm.*;
import com.share.help.form.*;
import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse;
@ -67,11 +63,11 @@ public class ActivityController {
* @return 返回活动列表
*/
@GetMapping(Constants.ACTIVITY_INTERFACE_FIND_ID)
public JSONResponse<DefaultRes,ActivityEntity> find(@PathVariable Long activityId){
if(activityId==null){
public JSONResponse<DefaultRes, ActivityDetail> find(@PathVariable Long activityId,@CookieValue(Constants.USER_COOKIE) String userId){
if(activityId==null||StringUtils.isEmpty(userId)){
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}else{
return activityService.find(activityId);
return activityService.find(activityId,userId);
}
}

@ -1,10 +1,14 @@
package com.share.help.dao;
import com.share.help.entity.ActivityEntity;
import com.share.help.entity.custorm.ActivityDetail;
import com.share.help.entity.custorm.ActivitySimple;
import com.share.help.entity.custorm.FindActivityRes;
import com.share.help.entity.custorm.SeekHelpSum;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -36,9 +40,7 @@ public interface ActivityMapper {
* @param activityId 活动id
* @return 返回活动信息
*/
@Select("select * from activity where activity_id=#{activityId}")
@ResultMap("activityMap")
ActivityEntity findOne(@Param("activityId") Long activityId);
ActivityDetail findOne(@Param("activityId") Long activityId,@Param("userId") String userId);
/**
* 分页查询活动

@ -0,0 +1,25 @@
package com.share.help.entity.custorm;
import java.sql.Timestamp;
public class ActivityDetail extends ActivitySimple{
private Timestamp activityStartTime;
private Timestamp activityEndTime;
public Timestamp getActivityStartTime() {
return activityStartTime;
}
public void setActivityStartTime(Timestamp activityStartTime) {
this.activityStartTime = activityStartTime;
}
public Timestamp getActivityEndTime() {
return activityEndTime;
}
public void setActivityEndTime(Timestamp activityEndTime) {
this.activityEndTime = activityEndTime;
}
}

@ -139,12 +139,12 @@ public class ActivityService{
* @param activityId 活动id
* @return 返回活动详情信息
*/
public JSONResponse<DefaultRes,ActivityEntity> find(Long activityId){
ActivityEntity activityEntity=activityMapper.findOne(activityId);
if(activityEntity==null){
public JSONResponse<DefaultRes,ActivityDetail> find(Long activityId,String userId){
ActivityDetail activityDetail=activityMapper.findOne(activityId,userId);
if(activityDetail==null){
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}else{
return new JSONResponse<DefaultRes,ActivityEntity>(DefaultRes.ok,Result.OK).setBody(activityEntity);
return new JSONResponse<DefaultRes,ActivityDetail>(DefaultRes.ok,Result.OK).setBody(activityDetail);
}
}
@ -185,7 +185,7 @@ public class ActivityService{
LeaveWordEntity leaveWordEntity=new LeaveWordEntity();
leaveWordEntity.setType(activityForm.getActivityStatus().name());
leaveWordEntity.setSourceUserId(activityForm.getUserId());
ActivityEntity activity=activityMapper.findOne(activityForm.getActivityId());
ActivityDetail activity=activityMapper.findOne(activityForm.getActivityId(),activityForm.getUserId());
if(activity==null){
throw new RuntimeException("查询活动记录失败");
}

@ -3,9 +3,9 @@ package com.share.help.service;
import com.share.help.dao.ActivityMapper;
import com.share.help.dao.FriendMapper;
import com.share.help.dao.LeaveWordMapper;
import com.share.help.entity.ActivityEntity;
import com.share.help.entity.FriendEntity;
import com.share.help.entity.LeaveWordEntity;
import com.share.help.entity.custorm.ActivityDetail;
import com.share.help.entity.custorm.LeaveWordRes;
import com.share.help.form.*;
import com.share.help.res.DefaultRes;
@ -48,7 +48,7 @@ public class LeaveWordService {
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select((findLeaveWordForm.getCurrentPage()-1)*pageSize,pageSize,findLeaveWordForm.getUserId());
for(LeaveWordRes wordRes:leaveWordRes){
if(LeaveWordType.friend!=wordRes.getType()&&wordRes.getActivityId()!=null){
ActivityEntity activityEntity=activityMapper.findOne(wordRes.getActivityId());
ActivityDetail activityEntity=activityMapper.findOne(wordRes.getActivityId(),findLeaveWordForm.getUserId());
wordRes.setTitle(activityEntity.getTitle());
wordRes.setContent(activityEntity.getContent());
}

@ -15,7 +15,7 @@
<result property="userId" column="user_id"/>
</resultMap>
<resultMap id="activitySimpleMap" type="com.share.help.entity.custorm.ActivitySimple">
<resultMap id="activitySimpleMap" type="com.share.help.entity.custorm.ActivityDetail">
<id property="activityId" column="activity_id"/>
<result property="userId" column="user_id"/>
<result property="title" column="title"/>
@ -32,6 +32,13 @@
limit #{start},#{count}
</select>
<select id="findOne" resultMap="activitySimpleMap">
select activity_id,user_id,title,content,activity_img,(activity_id in(select distinct activity_id from activity_history
where activity_history.user_id=#{userId})) as hasApply,now()>activity_start_time as hasStart
,activity_start_time as activityStartTime,activity_end_time as activityEndTime from activity
where activity_id=#{activityId}
</select>
<select id="count" resultType="com.share.help.entity.custorm.FindActivityRes">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity
</select>

@ -1,7 +1,6 @@
package com.share.help;
import com.share.help.dao.*;
import com.share.help.entity.ActivityEntity;
import com.share.help.entity.ActivityHistoryEntity;
import com.share.help.entity.UserEntity;
import com.share.help.entity.custorm.*;
@ -167,12 +166,7 @@ class HelpApplicationTests {
@Test
public void testAddActivity(){
ActivityEntity activityEntity=activityMapper.findOne(63L);
activityEntity.setActivityId(null);
activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis()));
activityMapper.insert(activityEntity);
ActivitySimple activityEntity=activityMapper.findOne(63L,"222");
}
// 求助信息统计
@ -208,7 +202,7 @@ class HelpApplicationTests {
public void queryLeaveWord(){
Page<List<LeaveWordRes>> listPage=leaveWordMapper.count(10,"777");
Assertions.assertNotNull(listPage);
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select(0,3,"777");
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select(0,3,"123");
Assertions.assertFalse(leaveWordRes.isEmpty());
}

Loading…
Cancel
Save