| | |
| | | package com.panzhihua.service_community.api; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.ComActActPrizeVO; |
| | | import com.panzhihua.common.model.vos.community.ComActActivityVO; |
| | | import com.panzhihua.common.model.vos.community.*; |
| | | import com.panzhihua.service_community.model.dos.ComActActPrizeDO; |
| | | import com.panzhihua.service_community.service.ComActActPrizeService; |
| | | import com.panzhihua.service_community.service.ComActActivityService; |
| | | import com.panzhihua.service_community.model.dos.ComActDynDO; |
| | | import com.panzhihua.service_community.service.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @program: springcloud_k8s_panzhihuazhihuishequ |
| | |
| | | private ComActActivityService comActActivityService; |
| | | @Resource |
| | | private ComActActPrizeService comActActPrizeService; |
| | | @Resource |
| | | private ComActDynService comActDynService; |
| | | @Resource |
| | | private ComActMicroWishService comActMicroWishService; |
| | | @Resource |
| | | private ComActEasyPhotoService comActEasyPhotoService; |
| | | |
| | | /** |
| | | * 新增社区活动 |
| | | * |
| | | * @param comActActivityVO 新增信息 |
| | | * @return 新增结果 |
| | | */ |
| | | @PostMapping("/activity") |
| | | @PostMapping("addactivity") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R addActivity(@RequestBody ComActActivityVO comActActivityVO){ |
| | | public R addActivity(@RequestBody ComActActivityVO comActActivityVO) { |
| | | R r = comActActivityService.addActivity(comActActivityVO); |
| | | boolean ok = r.isOk(); |
| | | if (ok) { |
| | | Long activityId = (Long)r.getData(); |
| | | Long activityId = (Long) r.getData(); |
| | | Integer hasPrize = comActActivityVO.getHasPrize(); |
| | | if (hasPrize.intValue()>0) { |
| | | if (hasPrize.intValue() > 0) { |
| | | List<ComActActPrizeVO> comActActPrizeVOList = comActActivityVO.getComActActPrizeVOList(); |
| | | if (!ObjectUtils.isEmpty(comActActPrizeVOList)) { |
| | | List<ComActActPrizeDO> comActActPrizeDOS=new ArrayList<>(); |
| | | List<ComActActPrizeDO> comActActPrizeDOS = new ArrayList<>(); |
| | | comActActPrizeVOList.forEach(comActActPrizeVO -> { |
| | | ComActActPrizeDO comActActPrizeDO=new ComActActPrizeDO(); |
| | | BeanUtils.copyProperties(comActActPrizeVO,comActActPrizeDO); |
| | | ComActActPrizeDO comActActPrizeDO = new ComActActPrizeDO(); |
| | | BeanUtils.copyProperties(comActActPrizeVO, comActActPrizeDO); |
| | | comActActPrizeDO.setActivityId(activityId); |
| | | comActActPrizeDOS.add(comActActPrizeDO); |
| | | }); |
| | | boolean saveBatch = comActActPrizeService.saveBatch(comActActPrizeDOS); |
| | | if (!saveBatch) { |
| | | throw new RuntimeException("奖品保存失败"); |
| | | return R.fail("保存奖品失败"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | return R.fail(); |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 编辑社区活动 |
| | | * |
| | | * @param comActActivityVO 编辑内容 |
| | | * @return 编辑结果 |
| | | */ |
| | | @PostMapping("putactivity") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R putActivity(@RequestBody ComActActivityVO comActActivityVO) { |
| | | R r = comActActivityService.putActivity(comActActivityVO); |
| | | List<ComActActPrizeVO> comActActPrizeVOList = comActActivityVO.getComActActPrizeVOList(); |
| | | boolean ok = r.isOk(); |
| | | if (ok) { |
| | | if (!ObjectUtils.isEmpty(comActActPrizeVOList)) { |
| | | Long actActivityVOId = comActActivityVO.getId(); |
| | | comActActPrizeService.remove(new QueryWrapper<ComActActPrizeDO>().lambda().eq(ComActActPrizeDO::getActivityId, actActivityVOId)); |
| | | if (!ObjectUtils.isEmpty(comActActPrizeVOList)) { |
| | | List<ComActActPrizeDO> comActActPrizeDOS = new ArrayList<>(); |
| | | comActActPrizeVOList.forEach(comActActPrizeVO -> { |
| | | ComActActPrizeDO comActActPrizeDO = new ComActActPrizeDO(); |
| | | BeanUtils.copyProperties(comActActPrizeVO, comActActPrizeDO); |
| | | comActActPrizeDO.setActivityId(actActivityVOId); |
| | | comActActPrizeDOS.add(comActActPrizeDO); |
| | | }); |
| | | boolean saveBatch = comActActPrizeService.saveBatch(comActActPrizeDOS); |
| | | if (!saveBatch) { |
| | | return R.fail("保存奖品失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return r; |
| | | } |
| | | |
| | | /** |
| | | * 删除社区活动 |
| | | * |
| | | * @param comActActivityVO 活动主键 |
| | | * @return 删除结果 |
| | | */ |
| | | @PostMapping("deleteactivity") |
| | | public R deleteActivity(@RequestBody ComActActivityVO comActActivityVO) { |
| | | boolean remove = comActActivityService.removeById(comActActivityVO.getId()); |
| | | if (remove) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询社区活动 |
| | | * |
| | | * @param comActActivityVO 查询参数 |
| | | * @return 分页集合 |
| | | */ |
| | | @PostMapping("pageActivity") |
| | | public R pageActivity(@RequestBody ComActActivityVO comActActivityVO) { |
| | | return comActActivityService.pageActivity(comActActivityVO); |
| | | } |
| | | |
| | | /** |
| | | * 发布活动 |
| | | * @param comActActivityVO 主键id 发布时间 |
| | | * @return 发布结果 |
| | | */ |
| | | @PostMapping("releaseactivity") |
| | | public R releaseActivity(@RequestBody ComActActivityVO comActActivityVO){ |
| | | return comActActivityService.releaseActivity(comActActivityVO); |
| | | } |
| | | |
| | | /** |
| | | * 取消活动 |
| | | * @param comActActivityVO 取消原因 |
| | | * @return 取消结果 |
| | | */ |
| | | @PostMapping("cancelactivity") |
| | | public R cancelActivity(@RequestBody ComActActivityVO comActActivityVO){ |
| | | return comActActivityService.cancelActivity(comActActivityVO); |
| | | } |
| | | |
| | | /** |
| | | * 活动详情 |
| | | * @param id 活动id |
| | | * @return 详情 |
| | | */ |
| | | @PostMapping("inforactivity") |
| | | public R inforActivity(@RequestParam("id") Long id){ |
| | | ComActActivityVO comActActivityVO = comActActivityService.inforActivity(id); |
| | | if (ObjectUtils.isEmpty(comActActivityVO)) { |
| | | return R.fail("活动不存在"); |
| | | } |
| | | List<ComActActPrizeDO> comActActPrizeDOS = comActActPrizeService.list(new QueryWrapper<ComActActPrizeDO>().lambda().eq(ComActActPrizeDO::getActivityId, id)); |
| | | if (!ObjectUtils.isEmpty(comActActPrizeDOS)) { |
| | | List<ComActActPrizeVO> comActActPrizeVOS=new ArrayList<>(); |
| | | comActActPrizeDOS.forEach(comActActPrizeDO -> { |
| | | ComActActPrizeVO comActActPrizeVO=new ComActActPrizeVO(); |
| | | BeanUtils.copyProperties(comActActPrizeDO,comActActPrizeVO); |
| | | comActActPrizeVOS.add(comActActPrizeVO); |
| | | }); |
| | | comActActivityVO.setComActActPrizeVOList(comActActPrizeVOS); |
| | | } |
| | | return R.ok(comActActivityVO); |
| | | } |
| | | |
| | | /** |
| | | * 活动报名名单 |
| | | * @param activitySignVO 查询参数 |
| | | * @return 报名人员集合 |
| | | */ |
| | | @PostMapping("listactivitysign") |
| | | public R listActivitySign(@RequestBody ActivitySignVO activitySignVO){ |
| | | return comActActivityService.listActivitySign(activitySignVO); |
| | | } |
| | | |
| | | /** |
| | | * 新增社区动态 |
| | | * @param comActDynVO 新增信息 |
| | | * @return 新增结果 |
| | | */ |
| | | @PostMapping("adddynamic") |
| | | public R addDynamic(@RequestBody ComActDynVO comActDynVO){ |
| | | ComActDynDO comActDynDO=new ComActDynDO(); |
| | | BeanUtils.copyProperties(comActDynVO,comActDynDO); |
| | | boolean save = comActDynService.save(comActDynDO); |
| | | if (save) { |
| | | // 最多只能设置三条置顶状态,后边设置会取消先前设置的置顶 |
| | | Integer isTopping = comActDynVO.getIsTopping(); |
| | | boolean b = isTopping.intValue() == 1; |
| | | if (b) { |
| | | List<ComActDynDO> list = comActDynService.list(new QueryWrapper<ComActDynDO>().lambda().eq(ComActDynDO::getIsTopping, 1).eq(ComActDynDO::getCommunityId,comActDynVO.getCommunityId())); |
| | | if (!ObjectUtils.isEmpty(list)) { |
| | | int size = list.size(); |
| | | if (size==4) { |
| | | List<ComActDynDO> collect = list.stream().sorted(Comparator.comparing(ComActDynDO::getCreateAt)).collect(Collectors.toList()); |
| | | ComActDynDO comActDynDO1 = collect.get(0); |
| | | comActDynDO1.setIsTopping(0); |
| | | boolean update = comActDynService.updateById(comActDynDO1); |
| | | if (!update) { |
| | | return R.fail("修改置顶状态失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 编辑社区动态 |
| | | * @param comActDynVO 编辑内容 |
| | | * @return 编辑结果 |
| | | */ |
| | | @PostMapping("putdynamic") |
| | | public R putDynamic(@RequestBody ComActDynVO comActDynVO){ |
| | | ComActDynDO comActDynDO=new ComActDynDO(); |
| | | BeanUtils.copyProperties(comActDynVO,comActDynDO); |
| | | boolean update = comActDynService.updateById(comActDynDO); |
| | | if (update) { |
| | | // 最多只能设置三条置顶状态,后边设置会取消先前设置的置顶 |
| | | Integer isTopping = comActDynVO.getIsTopping(); |
| | | boolean b = isTopping.intValue() == 1; |
| | | if (b) { |
| | | List<ComActDynDO> list = comActDynService.list(new QueryWrapper<ComActDynDO>().lambda().eq(ComActDynDO::getIsTopping, 1).eq(ComActDynDO::getCommunityId,comActDynVO.getCommunityId())); |
| | | if (!ObjectUtils.isEmpty(list)) { |
| | | int size = list.size(); |
| | | if (size==4) { |
| | | List<ComActDynDO> collect = list.stream().sorted(Comparator.comparing(ComActDynDO::getCreateAt)).collect(Collectors.toList()); |
| | | ComActDynDO comActDynDO1 = collect.get(0); |
| | | comActDynDO1.setIsTopping(0); |
| | | boolean updateById = comActDynService.updateById(comActDynDO1); |
| | | if (!updateById) { |
| | | return R.fail("修改置顶状态失败"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 删除社区动态 |
| | | * @param comActDynVO 动态id |
| | | * @return 删除结果 |
| | | */ |
| | | @PostMapping("deletedynamic") |
| | | public R deleteDynamic(@RequestBody ComActDynVO comActDynVO){ |
| | | boolean b = comActDynService.removeById(comActDynVO.getId()); |
| | | if (b) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询社区动态 |
| | | * @param comActDynVO 查询参数 |
| | | * @return 动态集合 |
| | | */ |
| | | @PostMapping("pagedynamic") |
| | | public R pageDynamic(@RequestBody ComActDynVO comActDynVO){ |
| | | return comActDynService.pageDynamic(comActDynVO); |
| | | } |
| | | |
| | | /** |
| | | * 社区动态详情 |
| | | * @param id 动态id |
| | | * @return 详情 |
| | | */ |
| | | @PostMapping("detaildynamic") |
| | | public R detailDynamic(@RequestParam("id") String id){ |
| | | return comActDynService.detailDynamic(id); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 分页查询随手拍 |
| | | * @param comActEasyPhotoVO 查询参数 |
| | | * @return 心愿列表 |
| | | */ |
| | | @PostMapping("pageeasyphoto") |
| | | public R pageEasyPhoto(@RequestBody ComActEasyPhotoVO comActEasyPhotoVO){ |
| | | return comActEasyPhotoService.pageEasyPhoto(comActEasyPhotoVO); |
| | | } |
| | | |
| | | /** |
| | | * 随手拍详情 |
| | | * @param id 随手拍主键 |
| | | * @return 详情内容 |
| | | */ |
| | | @PostMapping("detaileasyphoto") |
| | | public R detailEasyPhoto(@RequestParam("id")Long id){ |
| | | return comActEasyPhotoService.detailEasyPhoto(id); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询微心愿 |
| | | * @param comActMicroWishVO 查询参数 |
| | | * @return 分页集合 |
| | | */ |
| | | @PostMapping("pagemicrowish") |
| | | public R pageMicroWish(@RequestBody ComActMicroWishVO comActMicroWishVO){ |
| | | return comActMicroWishService.pageMicroWish(comActMicroWishVO); |
| | | } |
| | | |
| | | /** |
| | | * 心愿详情 |
| | | * @param id 查询主键 |
| | | * @return 心愿内容 |
| | | */ |
| | | @PostMapping("detailmicrowish") |
| | | public R detailMicroWish(@RequestParam("id")Long id){ |
| | | return comActMicroWishService.detailMicroWish(id); |
| | | } |
| | | |
| | | /** |
| | | * 审核、分配、反馈心愿 |
| | | * @param comActMicroWishVO 具体操作 |
| | | * @return 操作结果 |
| | | */ |
| | | @PostMapping("putlmicrowish") |
| | | public R putlMicroWish(@RequestBody ComActMicroWishVO comActMicroWishVO){ |
| | | R r = comActMicroWishService.putlMicroWish(comActMicroWishVO); |
| | | return r; |
| | | } |
| | | |
| | | } |