| | |
| | | package com.panzhihua.applets.api; |
| | | |
| | | import com.panzhihua.applets.config.WxMaConfiguration; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.panzhihua.applets.weixin.CheckService; |
| | | import com.panzhihua.common.constants.Constants; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.model.dtos.community.*; |
| | | import com.panzhihua.common.model.dtos.community.integral.admin.AddComActIntegralUserDTO; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.ComActDiscussCommentVO; |
| | | import com.panzhihua.common.model.vos.community.ComActDiscussVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.utlis.DateUtils; |
| | | import com.panzhihua.common.validated.AddGroup; |
| | | import com.panzhihua.common.validated.PutGroup; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.validation.Valid; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * @program: springcloud_k8s_panzhihuazhihuishequ |
| | |
| | | @Resource |
| | | private CheckService checkService; |
| | | |
| | | |
| | | @ApiOperation(value = "一起议-新增") |
| | | @PostMapping("discuss") |
| | | public R addDiscuss(@RequestBody @Validated(AddGroup.class) ComActDiscussDTO comActDiscussDTO) { |
| | | // 微信内容审核 |
| | | String openid = this.getLoginUserInfo().getOpenid(); |
| | | String appId = this.getAppId(); |
| | | // 微信内容审核 |
| | | String discussSubject = comActDiscussDTO.getDiscussSubject(); |
| | | if (!checkService.checkMessage(discussSubject)) { |
| | | return R.fail("内容违规"); |
| | | if (StrUtil.isNotBlank(discussSubject)) { |
| | | String result = checkService.checkMessageBy(discussSubject, openid, appId); |
| | | if (StrUtil.isNotBlank(result)) { |
| | | return R.fail(501, "填写内容存在 " + result + " 违规信息"); |
| | | } |
| | | } |
| | | |
| | | //微信图片审核 |
| | | String photoPah = comActDiscussDTO.getPhotoPah(); |
| | | if (StrUtil.isNotBlank(photoPah)) { |
| | | if (!checkService.checkImageBy(photoPah, appId)) { |
| | | return R.fail(501, "上传图片存在违规信息"); |
| | | } |
| | | } |
| | | |
| | | Integer type = comActDiscussDTO.getType(); |
| | | String voteTitle = comActDiscussDTO.getVoteTitle(); |
| | | List<ComActDiscussOptionDTO> discussOptions = comActDiscussDTO.getDiscussOptions(); |
| | | if (type.equals(2)) { |
| | | if(ObjectUtils.isEmpty(voteTitle)){ |
| | | if (ObjectUtils.isEmpty(voteTitle)) { |
| | | return R.fail("投票标题不能为空"); |
| | | } |
| | | if(ObjectUtils.isEmpty(discussOptions)){ |
| | | if (ObjectUtils.isEmpty(discussOptions)) { |
| | | return R.fail("选项不能为空"); |
| | | } |
| | | if (discussOptions.size() < 2) { |
| | | return R.fail("请至少设置两个投票选项"); |
| | | } |
| | | //设置投票开始时间 nowDate |
| | | comActDiscussDTO.setStartTime(DateUtils.format(new Date(), DateUtils.ymdhms_format)); |
| | | } |
| | | String address = comActDiscussDTO.getAddress(); |
| | | if (ObjectUtils.isEmpty(address)) { |
| | | return R.fail("地址不能为空"); |
| | | }else if(address.contains("null")){ |
| | | } else if (address.contains("null")) { |
| | | comActDiscussDTO.setAddress(null); |
| | | } |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | |
| | | Long communityId = loginUserInfo.getCommunityId(); |
| | | comActDiscussDTO.setUserId(userId); |
| | | comActDiscussDTO.setCommunityId(communityId); |
| | | comActDiscussDTO.setIsApplets(true); |
| | | comActDiscussDTO.setLoginUserInfo(loginUserInfo); |
| | | return communityService.addDiscuss(comActDiscussDTO); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "一起议-分页查询",response = ComActDiscussVO.class) |
| | | @ApiOperation(value = "一起议-分页查询", response = ComActDiscussVO.class) |
| | | @PostMapping("pagediscuss") |
| | | public R pageDiscuss(@RequestBody PageComActDiscussDTO pageComActDiscussDTO) { |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | | pageComActDiscussDTO.setCommunityId(loginUserInfo.getCommunityId()); |
| | | Integer isMy = pageComActDiscussDTO.getIsMy(); |
| | | if (null!=isMy&&isMy.intValue()==1) { |
| | | pageComActDiscussDTO.setUserId(loginUserInfo.getUserId()); |
| | | if (Objects.isNull(pageComActDiscussDTO.getType())) { |
| | | return R.fail("查询类型不能为空"); |
| | | } |
| | | pageComActDiscussDTO.setLoginUserId(loginUserInfo.getUserId()); |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin(); |
| | | if (loginUserInfo != null) { |
| | | pageComActDiscussDTO.setCommunityId(loginUserInfo.getCommunityId()); |
| | | pageComActDiscussDTO.setLoginUserId(loginUserInfo.getUserId()); |
| | | |
| | | Integer isMy = pageComActDiscussDTO.getIsMy(); |
| | | if (null != isMy && isMy.intValue() == 1) { |
| | | pageComActDiscussDTO.setUserId(loginUserInfo.getUserId()); |
| | | } |
| | | } |
| | | return communityService.pageDiscussApplets(pageComActDiscussDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-分页查询-脱敏", response = ComActDiscussVO.class) |
| | | @PostMapping("pageDiscussDesensitize") |
| | | public R pageDiscussDesensitize(@RequestBody PageComActDiscussDTO pageComActDiscussDTO) { |
| | | if (Objects.isNull(pageComActDiscussDTO.getType())) { |
| | | return R.fail("查询类型不能为空"); |
| | | } |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin(); |
| | | if (loginUserInfo != null) { |
| | | pageComActDiscussDTO.setCommunityId(loginUserInfo.getCommunityId()); |
| | | pageComActDiscussDTO.setLoginUserId(loginUserInfo.getUserId()); |
| | | |
| | | Integer isMy = pageComActDiscussDTO.getIsMy(); |
| | | if (null != isMy && isMy.intValue() == 1) { |
| | | pageComActDiscussDTO.setUserId(loginUserInfo.getUserId()); |
| | | } |
| | | } |
| | | return communityService.pageDiscussAppletsDesensitize(pageComActDiscussDTO); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "一起议-回复") |
| | | @PostMapping("discusscomment") |
| | |
| | | return R.fail("回复不能为空"); |
| | | } |
| | | Long discussId = comActDiscussCommentDTO.getDiscussId(); |
| | | if (null==discussId||0==discussId) { |
| | | if (null == discussId || 0 == discussId) { |
| | | return R.fail("一起议主键不能为空"); |
| | | } |
| | | String result = checkService.checkMessageBy(comment, this.getLoginUserInfo().getOpenid(), this.getAppId()); |
| | | if (StrUtil.isNotBlank(result)) { |
| | | return R.fail(501, "填写内容存在 " + result + " 违规信息"); |
| | | } |
| | | comActDiscussCommentDTO.setUserId(this.getUserId()); |
| | | // 议事投票计算积分 |
| | | AddComActIntegralUserDTO integralUserDTO = new AddComActIntegralUserDTO(discussId, |
| | | AddComActIntegralUserDTO.integralType.cyystp, this.getCommunityId(), this.getUserId()); |
| | | integralUserDTO.setIsComment(1); |
| | | communityService.addIntegralTradeAdmin(integralUserDTO); |
| | | return communityService.addDiscussComment(comActDiscussCommentDTO); |
| | | |
| | | } |
| | |
| | | return communityService.putDiscussCommentUser(comActDiscussUserDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-详情",response = ComActDiscussVO.class) |
| | | @ApiOperation(value = "一起议-详情", response = ComActDiscussVO.class) |
| | | @GetMapping("discuss") |
| | | @ApiImplicitParam(name = "id",value = "一起议主键",required = true) |
| | | @ApiImplicitParam(name = "id", value = "一起议主键", required = true) |
| | | public R detailDiscuss(@RequestParam("id") Long id) { |
| | | Long userId = this.getUserId(); |
| | | return communityService.detailDiscussApplets(id,userId); |
| | | Long userId = 0L; |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin(); |
| | | if (loginUserInfo != null) { |
| | | userId = loginUserInfo.getUserId(); |
| | | } |
| | | return communityService.detailDiscussApplets(id, userId); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-评论-分页查询",response = ComActDiscussCommentVO.class) |
| | | @ApiOperation(value = "一起议-详情-脱敏", response = ComActDiscussVO.class) |
| | | @GetMapping("discussDesensitize") |
| | | @ApiImplicitParam(name = "id", value = "一起议主键", required = true) |
| | | public R detailDiscussDesensitize(@RequestParam("id") Long id) { |
| | | Long userId = 0L; |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin(); |
| | | if (loginUserInfo != null) { |
| | | userId = loginUserInfo.getUserId(); |
| | | } |
| | | return communityService.detailDiscussAppletsDesensitize(id, userId); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-评论-分页查询", response = ComActDiscussCommentVO.class) |
| | | @PostMapping("pagediscusscomment") |
| | | public R pageDiscussComment(@RequestBody PageComActDiscussCommentDTO pageComActDiscussCommentDTO) { |
| | | Long id = pageComActDiscussCommentDTO.getId(); |
| | | if (null==id||0==id) { |
| | | if (null == id || 0 == id) { |
| | | return R.fail("一起议主键不能为空"); |
| | | } |
| | | pageComActDiscussCommentDTO.setLoginUserId(this.getUserId()); |
| | | Long userId = 0L; |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin(); |
| | | if (loginUserInfo != null) { |
| | | userId = loginUserInfo.getUserId(); |
| | | } |
| | | pageComActDiscussCommentDTO.setLoginUserId(userId); |
| | | return communityService.pageDiscussCommentApplets(pageComActDiscussCommentDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-评论-分页查询-脱敏", response = ComActDiscussCommentVO.class) |
| | | @PostMapping("pageDiscussCommentDesensitize") |
| | | public R pageDiscussCommentDesensitize(@RequestBody PageComActDiscussCommentDTO pageComActDiscussCommentDTO) { |
| | | Long id = pageComActDiscussCommentDTO.getId(); |
| | | if (null == id || 0 == id) { |
| | | return R.fail("一起议主键不能为空"); |
| | | } |
| | | Long userId = 0L; |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin(); |
| | | if (loginUserInfo != null) { |
| | | userId = loginUserInfo.getUserId(); |
| | | } |
| | | pageComActDiscussCommentDTO.setLoginUserId(userId); |
| | | return communityService.pageDiscussCommentAppletsDesensitize(pageComActDiscussCommentDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-评论-回复") |
| | |
| | | return R.fail("回复不能为空"); |
| | | } |
| | | Long id = comActDiscussCommentDTO.getId(); |
| | | if (null==id||0==id) { |
| | | if (null == id || 0 == id) { |
| | | return R.fail("评论主键不能为空"); |
| | | } |
| | | String result = checkService.checkMessageBy(comment, this.getLoginUserInfo().getOpenid(), this.getAppId()); |
| | | if (StrUtil.isNotBlank(result)) { |
| | | return R.fail(501, "填写内容存在 " + result + " 违规信息"); |
| | | } |
| | | comActDiscussCommentDTO.setUserId(this.getUserId()); |
| | | return communityService.addDiscussCommentBack(comActDiscussCommentDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-投票") |
| | | @GetMapping("discussoptionuser") |
| | | @ApiImplicitParam(name = "id",value = "一起议选项主键",required = true) |
| | | public R addDiscussOptionUser(@RequestParam("id") Long id) { |
| | | if (null==id||0==id) { |
| | | return R.fail("选项主键不能为空"); |
| | | @PostMapping("discussoptionuser") |
| | | public R addDiscussOptionUser(@RequestBody @Valid DiscussVoteOptionDTO discussVoteOptionDTO) { |
| | | List<ComActDiscussVoteOptionDTO> options = discussVoteOptionDTO.getOptions(); |
| | | if (options.isEmpty()) { |
| | | return R.fail("选项内容不能为空"); |
| | | } |
| | | ComActDiscussOptionUserDTO comActDiscussOptionUserDTO=new ComActDiscussOptionUserDTO(); |
| | | comActDiscussOptionUserDTO.setDiscussOptionId(id); |
| | | comActDiscussOptionUserDTO.setUserId(this.getUserId()); |
| | | return communityService.addDiscussOptionUser(comActDiscussOptionUserDTO); |
| | | discussVoteOptionDTO.setUserId(this.getUserId()); |
| | | options.forEach(option -> { |
| | | // 议事投票计算积分 |
| | | AddComActIntegralUserDTO integralUserDTO = new AddComActIntegralUserDTO(option.getId(), |
| | | AddComActIntegralUserDTO.integralType.cyystp, this.getCommunityId(), this.getUserId()); |
| | | integralUserDTO.setIsComment(2); |
| | | communityService.addIntegralTradeAdmin(integralUserDTO); |
| | | }); |
| | | return communityService.addDiscussOptionUser(discussVoteOptionDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-增加浏览量") |
| | | @PostMapping("discuss/increase-view-num") |
| | | public void increaseViewNum(@RequestParam("discussId") |
| | | @ApiParam(value = "一起议主键id", required = true) |
| | | Long discussId) { |
| | | communityService.increaseViewNum(discussId); |
| | | } |
| | | |
| | | @ApiOperation(value = "一起议-公布/编辑投票结果") |
| | | @PostMapping("discuss/edit-result") |
| | | public R editDiscussResult(@RequestBody @Validated(PutGroup.class) ComActDiscussDTO comActDiscussDTO) { |
| | | comActDiscussDTO.setUserId(this.getUserId()); |
| | | return communityService.editDiscussResult(comActDiscussDTO); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "一起议-获取是否有发布权限", response = Boolean.class) |
| | | @GetMapping("discuss/permissions") |
| | | public R getDiscussPermissions() { |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | | ComActDiscussDTO comActDiscussDTO = new ComActDiscussDTO(); |
| | | comActDiscussDTO.setLoginUserInfo(loginUserInfo); |
| | | comActDiscussDTO.setIsApplets(true); |
| | | comActDiscussDTO.setCommunityId(loginUserInfo.getCommunityId()); |
| | | return communityService.getDiscussPermissions(comActDiscussDTO); |
| | | } |
| | | } |