| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.common.model.dtos.community.social.PageProjectDTO; |
| | | import com.panzhihua.common.model.dtos.community.social.PageProjectSignListDTO; |
| | | import com.panzhihua.common.model.dtos.property.CommonPage; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.social.SocialProjectVO; |
| | | import com.panzhihua.common.utlis.DateUtils; |
| | | import com.panzhihua.service_community.dao.ComActDAO; |
| | | import com.panzhihua.service_community.dao.ComActSocialMemberDao; |
| | | import com.panzhihua.service_community.dao.ComActSocialOrgDao; |
| | | import com.panzhihua.service_community.dao.ComActSocialProjectSignDAO; |
| | | import com.panzhihua.service_community.entity.ComActSocialMember; |
| | | import com.panzhihua.service_community.entity.ComActSocialOrg; |
| | | import com.panzhihua.service_community.entity.ComActSocialProject; |
| | | import com.panzhihua.service_community.dao.ComActSocialProjectDao; |
| | | import com.panzhihua.service_community.entity.ComActSocialProjectSign; |
| | | import com.panzhihua.service_community.entity.ProjectRelationVO; |
| | | import com.panzhihua.service_community.model.dos.ComActDO; |
| | | import com.panzhihua.service_community.service.ComActSocialProjectService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | |
| | | /** |
| | | * 三社联动项目表(ComActSocialProject)表服务实现类 |
| | |
| | | private ComActSocialProjectDao comActSocialProjectDao; |
| | | @Resource |
| | | private ComActDAO comActDAO; |
| | | @Resource |
| | | private ComActSocialOrgDao comActSocialOrgDao; |
| | | @Resource |
| | | private ComActSocialProjectSignDAO comActSocialProjectSignDAO; |
| | | @Resource |
| | | private ComActSocialMemberDao comActSocialMemberDao; |
| | | |
| | | @Override |
| | | public R pageList(CommonPage commonPage) { |
| | | if(commonPage.getParamId2()!=null){ |
| | | ComActDO comActDO=comActDAO.selectById(commonPage.getCommunityId()); |
| | | if(comActDO!=null){ |
| | | commonPage.setStreetId(comActDO.getStreetId()); |
| | | } |
| | | ComActDO comActDO=comActDAO.selectById(commonPage.getCommunityId()); |
| | | if(comActDO!=null){ |
| | | commonPage.setStreetId(comActDO.getStreetId()); |
| | | } |
| | | } |
| | | return R.ok(comActSocialProjectDao.pageList(new Page(commonPage.getPage(),commonPage.getSize()),commonPage)); |
| | | Integer userType = commonPage.getUserType(); |
| | | if (nonNull(userType) && userType.equals(3)) { |
| | | ComActSocialOrg comActSocialOrg = comActSocialOrgDao.selectOne(new LambdaQueryWrapper<ComActSocialOrg>() |
| | | .eq(ComActSocialOrg::getUserId, commonPage.getUserId())); |
| | | if (nonNull(comActSocialOrg)) { |
| | | commonPage.setOrgId(comActSocialOrg.getId()); |
| | | } |
| | | } |
| | | if (nonNull(userType) && userType.equals(4)) { |
| | | ComActSocialMember socialMember = comActSocialMemberDao.selectOne(new LambdaQueryWrapper<ComActSocialMember>() |
| | | .eq(ComActSocialMember::getUserId, commonPage.getUserId())); |
| | | if (nonNull(socialMember)) { |
| | | commonPage.setOrgId(socialMember.getOrgId()); |
| | | } |
| | | } |
| | | IPage<SocialProjectVO> pageList = comActSocialProjectDao.pageList(new Page(commonPage.getPage(), commonPage.getSize()), commonPage); |
| | | setSignUpStatus(pageList.getRecords()); |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | | private void setSignUpStatus(List<SocialProjectVO> projectVOList) { |
| | | if (!projectVOList.isEmpty()) { |
| | | projectVOList.forEach(e -> { |
| | | Integer status = e.getStatus(); |
| | | Date signUpEnd = e.getSignUpEnd(); |
| | | if (status.equals(2) && nonNull(signUpEnd)) { |
| | | e.setSignUpStatus(signUpEnd.compareTo(new Date()) >= 0 ? 1 : 2); |
| | | } else if (!status.equals(2)) { |
| | | e.setSignUpStatus(3); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public R getByApplet(Long id) { |
| | | public R getByApplet(Long id, Long userId) { |
| | | ComActSocialProject comActSocialProject=this.comActSocialProjectDao.selectById(id); |
| | | comActSocialProject.setViews(comActSocialProject.getViews()+1); |
| | | comActSocialProjectDao.updateById(comActSocialProject); |
| | | return R.ok(comActSocialProjectDao.getByApplet(id)); |
| | | SocialProjectVO projectVO = comActSocialProjectDao.getByApplet(id); |
| | | if (nonNull(projectVO)) { |
| | | List<SocialProjectVO> list = new ArrayList<>(); |
| | | list.add(projectVO); |
| | | setSignUpStatus(list); |
| | | ComActSocialOrg socialOrg = comActSocialOrgDao.selectOrgByUserId(userId); |
| | | Integer signCount = nonNull(socialOrg) ? comActSocialProjectSignDAO.selectCount(new LambdaQueryWrapper<ComActSocialProjectSign>() |
| | | .eq(ComActSocialProjectSign::getProjectId, projectVO.getId()).eq(ComActSocialProjectSign::getOrgId, socialOrg.getId())) : 0; |
| | | if(!projectVO.getSignUpStatus().equals(1) || signCount > 0) { |
| | | projectVO.setIsCouldSign(2); |
| | | } else { |
| | | projectVO.setIsCouldSign(1); |
| | | } |
| | | } |
| | | return R.ok(projectVO); |
| | | } |
| | | |
| | | @Override |
| | |
| | | projectRelationVO.setSocialProjectVOIPage(socialProjectVOIPage); |
| | | return R.ok(projectRelationVO); |
| | | } |
| | | |
| | | /** |
| | | * 修改数据 |
| | | * |
| | | * @param socialProjectVO 实体对象 |
| | | * @return 修改结果 |
| | | */ |
| | | @Override |
| | | public R updateProject(SocialProjectVO socialProjectVO) { |
| | | Integer status = socialProjectVO.getStatus(); |
| | | if (nonNull(status) && status.equals(4)) { |
| | | List<ComActSocialProject> unEndProject = this.baseMapper.selectList(new LambdaQueryWrapper<ComActSocialProject>() |
| | | .eq(ComActSocialProject::getParentId, socialProjectVO.getId()) |
| | | .notIn(ComActSocialProject::getStatus, 4)); |
| | | if (!unEndProject.isEmpty()) { |
| | | return R.fail("该项目尚有子项目未结束"); |
| | | } |
| | | } |
| | | ComActSocialProject comActSocialProject=new ComActSocialProject(); |
| | | BeanUtils.copyProperties(socialProjectVO,comActSocialProject); |
| | | int result = this.baseMapper.updateById(comActSocialProject); |
| | | if (result > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("操作失败,请重试"); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询项目报名列表 |
| | | * @param pageProjectSignListDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R pageProjectSignList(PageProjectSignListDTO pageProjectSignListDTO) { |
| | | Page page = new Page<>(); |
| | | page.setCurrent(pageProjectSignListDTO.getPageNum()); |
| | | page.setSize(pageProjectSignListDTO.getPageSize()); |
| | | return R.ok(this.baseMapper.pageProjectSignList(page, pageProjectSignListDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 项目公开报名 |
| | | * @param projectId |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R signProject(Long projectId, Long userId) { |
| | | ComActSocialProject project = this.baseMapper.selectById(projectId); |
| | | if (isNull(project)) { |
| | | return R.fail("资源不存在"); |
| | | } |
| | | if (!project.getStatus().equals(2)) { |
| | | return R.fail("项目暂未公示"); |
| | | } |
| | | ComActSocialOrg socialOrg = comActSocialOrgDao.selectOrgByUserId(userId); |
| | | if (isNull(socialOrg)) { |
| | | return R.fail("您不是组织联系人,暂无法进行报名"); |
| | | } |
| | | Integer signCount = comActSocialProjectSignDAO.selectCount(new LambdaQueryWrapper<ComActSocialProjectSign>() |
| | | .eq(ComActSocialProjectSign::getProjectId, projectId).eq(ComActSocialProjectSign::getOrgId, socialOrg.getId())); |
| | | if (signCount > 0) { |
| | | return R.fail("请勿重复报名"); |
| | | } |
| | | ComActSocialProjectSign socialProjectSign = new ComActSocialProjectSign(); |
| | | socialProjectSign.setProjectId(projectId); |
| | | socialProjectSign.setOrgId(socialOrg.getId()); |
| | | socialProjectSign.setUserId(userId); |
| | | int result = comActSocialProjectSignDAO.insert(socialProjectSign); |
| | | return result > 0 ? R.ok() : R.fail("操作失败,请重新尝试"); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询用户报名的项目 |
| | | * @param pageProjectDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R pageProjectWhichIsSignedByUser(PageProjectDTO pageProjectDTO) { |
| | | Page page = new Page<>(); |
| | | page.setCurrent(pageProjectDTO.getPageNum()); |
| | | page.setSize(pageProjectDTO.getPageSize()); |
| | | IPage<SocialProjectVO> pageList = this.baseMapper.pageProjectWhichIsSignedByUser(page, pageProjectDTO); |
| | | setSignUpStatus(pageList.getRecords()); |
| | | return R.ok(pageList); |
| | | } |
| | | } |