@ -1,19 +1,29 @@
package com.share.help.service ;
import com.share.help.Util ;
import com.share.help.dao.ActivityHistoryMapper ;
import com.share.help.dao.ActivityMapper ;
import com.share.help.dao.LeaveWordMapper ;
import com.share.help.entity.ActivityEntity ;
import com.share.help.entity.ActivityHistoryEntity ;
import com.share.help.entity.LeaveWordEntity ;
import com.share.help.form.ApplyActivityForm ;
import com.share.help.form.FindActivityForm ;
import com.share.help.form.LeaveWordType ;
import com.share.help.form.SendHelpForm ;
import com.share.help.res.JSONResponse ;
import com.share.help.res.Result ;
import com.share.help.res.SendHelpRes ;
import com.share.help.res.activity.ActivityDetailRes ;
import com.share.help.res.activity.ActivitySimple ;
import com.share.help.res.activity.ApplyActivityRes ;
import com.share.help.res.activity.FindActivityRes ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import java.sql.Timestamp ;
import java.util.List ;
@ -27,6 +37,12 @@ public class ActivityService{
@Autowired
private ActivityMapper activityMapper ;
@Autowired
private ActivityHistoryMapper activityHistoryMapper ;
@Autowired
private LeaveWordMapper leaveWordMapper ;
@Autowired
private ImageService imageService ;
@ -38,7 +54,7 @@ public class ActivityService{
private int rowSize ;
private Logger logger = LoggerFactory . getLogger ( ActivityService . class ) ;
/ * *
* 发布求助信息
@ -47,6 +63,7 @@ public class ActivityService{
* /
public JSONResponse < SendHelpRes , Void > sendHelp ( SendHelpForm sendHelpForm ) {
ActivityEntity activityEntity = new ActivityEntity ( ) ;
activityEntity . setUserId ( sendHelpForm . getUserId ( ) ) ;
activityEntity . setTitle ( sendHelpForm . getTitle ( ) ) ;
activityEntity . setContent ( sendHelpForm . getContent ( ) ) ;
activityEntity . setSeekHelpTime ( new Timestamp ( System . currentTimeMillis ( ) ) ) ;
@ -55,6 +72,7 @@ public class ActivityService{
//保存活动背景图
String imageName = imageService . saveImg ( sendHelpForm . getActivityImgFile ( ) ) ;
if ( imageName = = null ) {
logger . error ( "活动背景图保存失败" ) ;
return new JSONResponse < > ( SendHelpRes . fail , Result . FAIL ) ;
}
activityEntity . setActivityImg ( imageName ) ;
@ -94,4 +112,40 @@ public class ActivityService{
}
}
/ * *
* 报名活动
* @param activityForm 报名名单
* @return 返回报名结果
* /
@Transactional
public JSONResponse < ApplyActivityRes , Void > apply ( ApplyActivityForm activityForm ) {
// 保存到活动历史记录
ActivityHistoryEntity activityEntity = new ActivityHistoryEntity ( ) ;
activityEntity . setActivityId ( activityForm . getActivityId ( ) ) ;
activityEntity . setUserId ( activityForm . getUserId ( ) ) ;
activityEntity . setCreateTime ( new Timestamp ( System . currentTimeMillis ( ) ) ) ;
activityEntity . setActivityStatus ( activityForm . getActivityStatus ( ) . name ( ) ) ;
if ( ! activityHistoryMapper . insert ( activityEntity ) ) {
logger . error ( "保存活动历史记录失败" ) ;
return new JSONResponse < > ( ApplyActivityRes . fail , Result . FAIL ) ;
}
// 给求助用户发送留言
LeaveWordEntity leaveWordEntity = new LeaveWordEntity ( ) ;
leaveWordEntity . setType ( LeaveWordType . apply . name ( ) ) ;
leaveWordEntity . setSourceUserId ( activityForm . getUserId ( ) ) ;
ActivityEntity activity = activityMapper . findOne ( activityForm . getActivityId ( ) ) ;
if ( activity = = null ) {
logger . error ( "查询活动记录失败" ) ;
return new JSONResponse < > ( ApplyActivityRes . fail , Result . FAIL ) ;
}
leaveWordEntity . setTargetUserId ( activity . getUserId ( ) ) ;
leaveWordEntity . setActivityId ( activityForm . getActivityId ( ) ) ;
leaveWordEntity . setCreateTime ( new Timestamp ( System . currentTimeMillis ( ) ) ) ;
if ( leaveWordMapper . insert ( leaveWordEntity ) ) {
logger . error ( "保存留言信息失败" ) ;
}
return new JSONResponse < > ( ApplyActivityRes . ok , Result . OK ) ;
}
}