mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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<ComActSocialProjectDao, ComActSocialProject> 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<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, 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<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
    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<SocialProjectVO> 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<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);
    }
}