package com.panzhihua.service_community.service.impl; 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 lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; 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)表服务实现类 * * @author makejava * @since 2021-12-22 14:02:48 */ @Slf4j @Service public class ComActSocialProjectServiceImpl extends ServiceImpl implements ComActSocialProjectService { @Resource 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()); } } Integer userType = commonPage.getUserType(); if (nonNull(userType) && userType.equals(3)) { ComActSocialOrg comActSocialOrg = comActSocialOrgDao.selectOne(new LambdaQueryWrapper() .eq(ComActSocialOrg::getUserId, commonPage.getUserId())); if (nonNull(comActSocialOrg)) { commonPage.setOrgId(comActSocialOrg.getId()); } } if (nonNull(userType) && userType.equals(4)) { ComActSocialMember socialMember = comActSocialMemberDao.selectOne(new LambdaQueryWrapper() .eq(ComActSocialMember::getUserId, commonPage.getUserId())); if (nonNull(socialMember)) { commonPage.setOrgId(socialMember.getOrgId()); } } IPage pageList = comActSocialProjectDao.pageList(new Page(commonPage.getPage(), commonPage.getSize()), commonPage); setSignUpStatus(pageList.getRecords()); return R.ok(pageList); } private void setSignUpStatus(List 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, Long userId) { ComActSocialProject comActSocialProject=this.comActSocialProjectDao.selectById(id); comActSocialProject.setViews(comActSocialProject.getViews()+1); comActSocialProjectDao.updateById(comActSocialProject); SocialProjectVO projectVO = comActSocialProjectDao.getByApplet(id); if (nonNull(projectVO)) { List list = new ArrayList<>(); list.add(projectVO); setSignUpStatus(list); ComActSocialOrg socialOrg = comActSocialOrgDao.selectOrgByUserId(userId); Integer signCount = nonNull(socialOrg) ? comActSocialProjectSignDAO.selectCount(new LambdaQueryWrapper() .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 public R getByBackstage(Long id) { return R.ok(comActSocialProjectDao.getByApplet(id)); } @Override public R getProject(CommonPage commonPage) { if(commonPage.getParamId()==null){ return R.fail("数据异常"); } ProjectRelationVO projectRelationVO=new ProjectRelationVO(); SocialProjectVO comActSocialProject=this.comActSocialProjectDao.selectByLevel(commonPage.getParamId()); if(comActSocialProject.getLevel()==2){ SocialProjectVO comActSocialProject1=this.comActSocialProjectDao.selectByLevel(comActSocialProject.getParentId()); if(comActSocialProject1!=null){ projectRelationVO.setFatherProjectLevelOne(comActSocialProject1); } } if(comActSocialProject.getLevel()==3){ SocialProjectVO comActSocialProject1=this.comActSocialProjectDao.selectByLevel(comActSocialProject.getParentId()); if(comActSocialProject1!=null){ projectRelationVO.setFatherProjectLevelTwo(comActSocialProject1); SocialProjectVO comActSocialProject2=this.comActSocialProjectDao.selectByLevel(comActSocialProject1.getParentId()); if(comActSocialProject2!=null){ projectRelationVO.setFatherProjectLevelOne(comActSocialProject2); } } } IPage socialProjectVOIPage=this.comActSocialProjectDao.pageList(new Page(commonPage.getPage(),commonPage.getSize()),commonPage); 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 unEndProject = this.baseMapper.selectList(new LambdaQueryWrapper() .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() .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 pageList = this.baseMapper.pageProjectWhichIsSignedByUser(page, pageProjectDTO); setSignUpStatus(pageList.getRecords()); return R.ok(pageList); } }