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
package com.panzhihua.service_community.service.impl;
 
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.property.CommonPage;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComActSocialOrgVO;
import com.panzhihua.common.model.vos.user.AdministratorsUserVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.entity.ComActCommittee;
import com.panzhihua.service_community.entity.ComActSocialOrg;
import com.panzhihua.service_community.dao.ComActSocialOrgDao;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.service.ComActSocialOrgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
 
/**
 * 社会组织(ComActSocialOrg)表服务实现类
 *
 * @author makejava
 * @since 2021-09-17 10:45:30
 */
@Slf4j
@Service
public class ComActSocialOrgServiceImpl extends ServiceImpl<ComActSocialOrgDao, ComActSocialOrg> implements ComActSocialOrgService {
@Resource
private ComActSocialOrgDao comActSocialOrgDao;
@Resource
private UserService userService;
@Resource
private ComActDAO comActDAO;
    @Override
    public R pageList(CommonPage commonPage) {
        return R.ok(comActSocialOrgDao.pageList(new Page(commonPage.getPage(),commonPage.getSize()),commonPage));
    }
 
    @Override
    public R selectById(Long id) {
        return R.ok(comActSocialOrgDao.detail(id));
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R insert(ComActSocialOrgVO comActSocialOrgVO) {
        if(comActSocialOrgVO!=null){
            ComActSocialOrg comActSocialOrg=new ComActSocialOrg();
            BeanUtils.copyProperties(comActSocialOrgVO,comActSocialOrg);
            AdministratorsUserVO administratorsUserVO=new AdministratorsUserVO();
            administratorsUserVO.setType(3);
            administratorsUserVO.setAccount(comActSocialOrgVO.getAccount());
            administratorsUserVO.setPassword(comActSocialOrgVO.getPassword());
            //根据roleId判断是普通社会组织还是定制三社
            if(comActSocialOrgVO.getRoleId()==null){
                administratorsUserVO.setSocialType(2);
                administratorsUserVO.setRoleId(777777777L);
                comActSocialOrg.setIsSociety(1);
                Long affiliatedUnit = comActSocialOrg.getAffiliatedUnit();
                Integer affiliatedUnitType = comActSocialOrg.getAffiliatedUnitType();
                if (affiliatedUnitType.equals(2)) {
                    administratorsUserVO.setCommunityId(affiliatedUnit);
                    ComActDO comActDO = comActDAO.selectById(affiliatedUnit);
                    comActSocialOrg.setStreetId(comActDO.getStreetId());
                }
                administratorsUserVO.setName(comActSocialOrgVO.getCorporationName());
            } else {
                administratorsUserVO.setRoleId(comActSocialOrgVO.getRoleId());
                if(comActSocialOrg.getCommunityId()!=null){
                    administratorsUserVO.setCommunityId(comActSocialOrg.getCommunityId());
                    ComActDO comActDO = comActDAO.selectById(comActSocialOrg.getCommunityId());
                    comActSocialOrg.setStreetId(comActDO.getStreetId());
                }
                administratorsUserVO.setName(comActSocialOrgVO.getContactName());
            }
            administratorsUserVO.setPhone(comActSocialOrgVO.getContactPhone());
            R r=userService.addUserBackstageProperty(administratorsUserVO);
            if(R.isOk(r)){
                comActSocialOrg.setUserId(Long.parseLong(r.getData().toString()));
                comActSocialOrg.setCreateAt(DateUtil.date());
                this.comActSocialOrgDao.insert(comActSocialOrg);
                return R.ok();
            }
            return R.fail("账号或手机号已存在");
        }
        return R.fail();
    }
 
    @Override
    public R update(ComActSocialOrgVO comActSocialOrgVO) {
        if(comActSocialOrgVO!=null){
            ComActSocialOrg comActSocialOrg=new ComActSocialOrg();
            BeanUtils.copyProperties(comActSocialOrgVO,comActSocialOrg);
            AdministratorsUserVO administratorsUserVO=new AdministratorsUserVO();
            if(comActSocialOrgVO.getRoleId() == null) {
                administratorsUserVO.setRoleId(777777777L);
            } else {
                administratorsUserVO.setRoleId(comActSocialOrgVO.getRoleId());
            }
            ComActSocialOrg comPropertyBase=this.comActSocialOrgDao.selectById(comActSocialOrgVO.getId());
            administratorsUserVO.setUserId(comPropertyBase.getUserId());
            administratorsUserVO.setLastLoginTime(DateUtil.date());
            administratorsUserVO.setAccount(comActSocialOrgVO.getAccount());
            administratorsUserVO.setPassword(comActSocialOrgVO.getPassword());
            Integer status = comActSocialOrgVO.getStatus();
            administratorsUserVO.setStatus(status.equals(0) ? 2 : 1);
            this.userService.putUserBackstage(administratorsUserVO);
            this.comActSocialOrgDao.updateById(comActSocialOrg);
            return R.ok();
        }
        return R.fail();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R delete(Long id) {
        ComActSocialOrg comActSocialOrg=comActSocialOrgDao.selectById(id);
        if(comActSocialOrg!=null){
            if(comActSocialOrg.getUserId()!=null){
                AdministratorsUserVO administratorsUserVO=new AdministratorsUserVO();
                administratorsUserVO.setUserId(comActSocialOrg.getUserId());
                administratorsUserVO.setCommunityId(comActSocialOrg.getCommunityId());
                userService.deleteUserBackstage(administratorsUserVO);
                this.comActSocialOrgDao.deleteById(id);
                return R.ok();
            }
        }
        return R.fail("用户账号错误");
    }
}