Skip to content

Commit

Permalink
合并冲突,已发布到服务器
Browse files Browse the repository at this point in the history
  • Loading branch information
Evans-xie committed May 1, 2018
1 parent e765f90 commit 37d2d4b
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.selfcreate.qingxie.controller.avtivity;
package com.selfcreate.qingxie.controller.avtivity;

import java.util.*;

import com.selfcreate.qingxie.bean.activity.*;
import com.selfcreate.qingxie.bean.user.Favourite;
import com.selfcreate.qingxie.bean.user.User;
import com.selfcreate.qingxie.bean.user.UserActivityHours;
import com.selfcreate.qingxie.bean.user.ArriveConfirm;
import com.selfcreate.qingxie.exception.QingxieInnerException;
import com.selfcreate.qingxie.service.file.FileService;
import com.selfcreate.qingxie.service.user.UserActivityHourService;
Expand All @@ -27,6 +28,9 @@
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.selfcreate.qingxie.bean.Msg;
import com.selfcreate.qingxie.bean.user.ArriveConfirm;
import com.selfcreate.qingxie.bean.user.Favourite;
import com.selfcreate.qingxie.bean.user.User;
import com.selfcreate.qingxie.bean.user.UserActivity;
import com.selfcreate.qingxie.service.activity.ActivityService;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -52,59 +56,128 @@ public class ActivityController {

/**
* 获取某个活动报名人数
*
* @param activityId
* @return
*/
@ResponseBody
@RequestMapping(value = "/{activityId}/getApplyNumber", method = RequestMethod.GET)
public Msg getApplyNumber(@PathVariable("activityId") Integer activityId){
if(activityId != null){
public Msg getApplyNumber(@PathVariable("activityId") Integer activityId) {
if (activityId != null) {
return Msg.success().add("applyNumber", userActivityService.getApplyNumber(activityId));
}else{
} else {
return Msg.error();
}
}

/**
* 活动签到修改
*
* @param activityId
* @param arriveConfirms
* @return
*/
@ResponseBody
@RequestMapping(value = "/{activityId}/modifyConfirm", method = RequestMethod.POST)
public Msg modifyConfirm(@PathVariable("activityId") Integer activityId, @RequestBody ArriveConfirm[] arriveConfirms) {
if (arriveConfirms != null) {
for (ArriveConfirm arriveConfirm : arriveConfirms) {
UserActivity userActivity = userActivityService.getByActivityIdAndUserId(activityId, arriveConfirm.getUserId());
if (userActivity != null) {
int count = userActivity.getCount();
System.out.println(count);
if (arriveConfirm.getIsArrived()) {
count++;
System.out.println(count);
} else {
count--;
System.out.println(count);
}
userActivity.setCount(count);
userActivityService.update(userActivity);
} else {
return Msg.error("该活动无此志愿者");
}

}
return Msg.success("签到修改成功");
}
return Msg.error("传入数据有误");
}

/**
* 活动签到确认
*
* @param activityId
* @param arriveConfirms
* @return
*/
@ResponseBody
@RequestMapping(value = "/{activityId}/arriveConfirm", method = RequestMethod.POST)
public Msg arriveConfirm(@PathVariable("activityId") Integer activityId, @RequestBody ArriveConfirm[] arriveConfirms) {
if (arriveConfirms != null) {
for (ArriveConfirm arriveConfirm : arriveConfirms) {
UserActivity userActivity = userActivityService.getByActivityIdAndUserId(activityId, arriveConfirm.getUserId());
if (userActivity != null) {
int count = userActivity.getCount();
System.out.println(count);
if (arriveConfirm.getIsArrived()) {
count++;
System.out.println(count);
userActivity.setCount(count);
userActivityService.update(userActivity);
}
} else {
return Msg.error("该活动无此志愿者");
}

}
return Msg.success("签到成功");
}
return Msg.error("传入数据有误");
}

/**
* 活动推进,1表示未开始,2表示进行中,3表示已结束
*
* @param activityId
* @return
*/
@ResponseBody
@RequestMapping(value = "/{activityId}/boostActivity", method = RequestMethod.POST)
public Msg boostActivity(@PathVariable("activityId") Integer activityId){
if(activityId != null){
public Msg boostActivity(@PathVariable("activityId") Integer activityId) {
if (activityId != null) {
Activity activity = activityService.getById(activityId);
int status = activity.getStatus();
if(status == 3){
if (status == 3) {
return Msg.error("活动已结束,无法推进");
}else if(status ==2){
status ++;
} else if (status == 2) {
status++;
activity.setStatus(status);
activityService.updateActivity(activity);
//此时推进则表示活动即将结束,需要给志愿者们保存工时
//1.获取该活动的所有志愿者
List<UserActivity> userActivities = userActivityService.getByActivityId(activityId);
for (UserActivity userActivity : userActivities){
for (UserActivity userActivity : userActivities) {
UserActivityHours userActivityHours = new UserActivityHours();
userActivityHours.setUserId(userActivity.getUserId());
userActivityHours.setActivityId(activityId);
//青协工作人员和活动负责人每次工时上浮2个
if(userActivity.getStuff() == 1 || userActivity.getStuff() == 2){
if (userActivity.getStuff() == 1 || userActivity.getStuff() == 2) {
userActivityHours.setVoluntaryHours((int) (userActivity.getCount() * (activity.getHourPerTime() + 2)));
}else{
} else {
userActivityHours.setVoluntaryHours((int) (userActivity.getCount() * activity.getHourPerTime()));
}
userActivityHourService.add(userActivityHours);
}
return Msg.success("测试");
}else{
status ++;
} else {
status++;
activity.setStatus(status);
activityService.updateActivity(activity);
return Msg.success("推进成功");
}
}else{
} else {
return Msg.error("请选择活动");
}
}
Expand All @@ -119,7 +192,7 @@ public Msg boostActivity(@PathVariable("activityId") Integer activityId){
public Msg getHomePagePic() {
logger.info("》》》请求获取首页轮播图");
List<Activity> activities = activityService.getAll();
List<String> homePagePics = new ArrayList<String>();
List<HomePagePicInfo> homePagePicInfos = new ArrayList<HomePagePicInfo>();
Collections.sort(activities, new Comparator<Activity>() {
// 降序排列
@Override
Expand All @@ -138,18 +211,21 @@ public int compare(Activity o1, Activity o2) {
System.out.println(activities);
int i = 0;
for (Activity activity : activities) {
String homePagePic = activity.getHomepagePic();
if (homePagePic != null) {
if (activity.getHomepagePic() != null) {
HomePagePicInfo homePagePicInfo = new HomePagePicInfo();
homePagePicInfo.setActivityId(activity.getId());
homePagePicInfo.setGeneral(activity.getGeneral());
homePagePicInfo.setHomePagePic(activity.getHomepagePic());
// System.out.println(homePagePic);
homePagePics.add(homePagePic);
i ++;
homePagePicInfos.add(homePagePicInfo);
i++;
}
if (i == 4) {
break;
}
}
// System.out.println(homePagePics);
return Msg.success("处理成功").add("homePagePics", homePagePics);
return Msg.success("处理成功").add("homePagePics", homePagePicInfos);
}

/**
Expand All @@ -168,19 +244,21 @@ public Msg releaseActivity(@RequestBody Activity activity) {
return Msg.error("活动信息不能为空");
}
}

@ResponseBody
@RequestMapping(value = "/{activityId}/volunteers", method = RequestMethod.GET)
public Msg getVolunteerNumber(@PathVariable("activityId") Integer activityId){
public Msg getVolunteerNumber(@PathVariable("activityId") Integer activityId) {
List<UserActivity> userActivities = userActivityService.getAllVolunteersByActivityId(activityId);
List<Integer> ids = new ArrayList<Integer>();
for (UserActivity userActivity :userActivities){
for (UserActivity userActivity : userActivities) {
ids.add(userActivity.getUserId());
}
List<User> users = userService.getUsersByIds(ids);
String[] fileds = { "id", "studentId", "name", "telephone", "qq"};
String[] fileds = {"id", "studentId", "name", "telephone", "qq"};
List<Map<String, Object>> response = ResponseUtil.getResultMap(users, fileds);
return Msg.success().add("volunteers", response);
return Msg.success().add("volunteers", response);
}

/**
* 返回首页数据
* Activity:活动id,活动名称,首页图片路径,活动简介
Expand Down Expand Up @@ -285,18 +363,22 @@ public Msg getForks(@PathVariable("userId") int userId) {

/**
* 添加活动至我的收藏
*
* @param favourite
* @return
*/
@ResponseBody
@RequestMapping(value = "/addFork", method = RequestMethod.POST)
public Msg addFork(@RequestBody Favourite favourite){
public Msg addFork(@RequestBody Favourite favourite) {
try {
if(favourite != null){
logger.info("》》》用户id为" + favourite.getUserId() + "请求添加" + favourite.getActivityId() +"到我的收藏");
if (favourite != null) {
logger.info("》》》用户id为" + favourite.getUserId() + "请求添加" + favourite.getActivityId() + "到我的收藏");
if (activityService.isForkAgain(favourite.getUserId(), favourite.getActivityId())) {
return Msg.error("该活动已收藏");
}
activityService.addFork(favourite);
return Msg.success("添加成功");
}else{
} else {
return Msg.error("传入信息有误!");
}

Expand Down Expand Up @@ -359,21 +441,22 @@ public Msg joinActivity(@PathVariable("activityId") int activityId, @PathVariabl
/**
* 活动照片上传接口
* FIXME:权限验证
*
* @param request
* @param userId 上传用户的id
* @param userId 上传用户的id
* @param pic
* @return
*/
@ResponseBody
@RequestMapping(value = "/{userId}/pic/add", method = RequestMethod.POST)
public Msg pushActivity(HttpServletRequest request, @PathVariable("userId") int userId, @RequestParam(value="pic",required=false)MultipartFile pic) {
if(pic==null||pic.getSize()==0){
public Msg pushActivity(HttpServletRequest request, @PathVariable("userId") int userId, @RequestParam(value = "pic", required = false) MultipartFile pic) {
if (pic == null || pic.getSize() == 0) {
return Msg.error("上传图片为空");
}
try {
String accessPath=picService.save2Local(pic, pic.getOriginalFilename());
String accessPath = picService.save2Local(pic, pic.getOriginalFilename());
return Msg.success("图片上传成功").add("picAccessPath", accessPath);
}catch (QingxieInnerException e){
} catch (QingxieInnerException e) {
return Msg.error(e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public interface ActivityService {

void releaseActivity(Activity activity);

void signUp(Integer userId, Integer activityId);

void addFork(Favourite favourite);

void updateActivity(Activity activity);

boolean isForkAgain(Integer userId, Integer activityId);

void signUp(Integer userId,Integer activityId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@ public class ActivityServiceImpl implements ActivityService {

/**
* 判断是否重复收藏
*
* @param userId
* @param activityId
* @return
*/
public boolean isForkAgain(Integer userId, Integer activityId){
FavouriteExample example = new FavouriteExample();
Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andActivityIdEqualTo(activityId);
if(favouriteMapper.selectByExample(example).size() > 0){
return true;
}else{
return false;
}
@Override
public boolean isForkAgain(Integer userId, Integer activityId) {
FavouriteExample example = new FavouriteExample();
Criteria criteria = example.createCriteria();
criteria.andUserIdEqualTo(userId);
criteria.andActivityIdEqualTo(activityId);
if (favouriteMapper.selectByExample(example).size() > 0) {
return true;
} else {
return false;
}
}

/**
* 根据活动id获取活动信息
*
Expand Down Expand Up @@ -194,41 +196,45 @@ public void releaseActivity(Activity activity) {
* 3.重复报名
* 4.权限验证
* todo:验证是否在报名中
*
* @param userId
* @param activityId
*/
@Override
public void signUp(Integer userId, Integer activityId) {
//查询是否已存在报名信息
UserActivityExample example=new UserActivityExample();
UserActivityExample example = new UserActivityExample();
example.createCriteria().andUserIdEqualTo(userId).andActivityIdEqualTo(activityId);
boolean hasSignedUp=userActivityMapper.selectByExample(example).size()>0;
if(hasSignedUp){
boolean hasSignedUp = userActivityMapper.selectByExample(example).size() > 0;
if (hasSignedUp) {
throw new RepeatOperateException("重复报名");
}
UserActivity userActivity=new UserActivity(userId,activityId,0,1,0);
try{
UserActivity userActivity = new UserActivity(userId, activityId, 0, 1, 0);
try {
userActivityMapper.insert(userActivity);
}catch (Exception e){
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new QingxieInnerException("数据库异常");
}
}

/**
* 添加至我的收藏
*
* @param favourite
*/
@Override
public void addFork(Favourite favourite){
public void addFork(Favourite favourite) {
favouriteMapper.insertSelective(favourite);
}

/**
* 更新活动记录
*
* @param activity
*/
@Override
public void updateActivity(Activity activity){
public void updateActivity(Activity activity) {
activityMapper.updateByPrimaryKey(activity);
}

Expand Down
Loading

0 comments on commit 37d2d4b

Please sign in to comment.