郑永安
2023-06-19 f65443d8abeaedc9d102324565e8368e7c9d90c8
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
package com.gk.firework.Service.ServiceImpl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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.gk.firework.Domain.BlackList;
import com.gk.firework.Domain.Enterprise;
import com.gk.firework.Domain.Enum.EnterpriseStatus;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.UserInfo;
import com.gk.firework.Domain.Utils.FilterObject;
import com.gk.firework.Domain.Utils.StringUtils;
import com.gk.firework.Mapper.BlackListMapper;
import com.gk.firework.Mapper.EnterpriseMapper;
import com.gk.firework.Service.BlackListService;
import com.gk.firework.Service.EnterpriseService;
import com.gk.firework.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
 
@Service("blackListService")
public class BlackListServiceImpl extends ServiceImpl<BlackListMapper, BlackList> implements BlackListService {
 
 
    @Autowired
    private UserService userService;
    @Autowired
    private BlackListMapper blackListMapper;
    @Autowired
    private EnterpriseService enterpriseService;
 
 
    /**
    * @Description: 修改
    * @date 2021/7/9 15:15
    */
    @Override
    @Transactional
    public void addBlackList(BlackList blackList, UserInfo user) {
 
        String enterprisename = blackList.getEnterprisename();
        if (StringUtils.isBlank(enterprisename))
            throw new BusinessException("请填写企业名称");
 
        Enterprise enterprise = enterpriseService.selectEnterpriseByName(enterprisename);
        if (enterprise == null)
            throw new BusinessException("企业信息不存在");
 
        blackList.setCreateby(user.getUsername());
        blackList.setCreatetime(new Date());
        blackList.setCreatebyid(user.getId());
        blackList.setValidflag(Boolean.TRUE);
        this.save(blackList);
        //停用企业
        //1.修改企业状态为 停止
        enterpriseService.setEnterpriseStatus(EnterpriseStatus.OFF, enterprise.getId());
 
        //2.修改企业用户isdel=1     3.修改终端用户isdel=1
        List<UserInfo> userList = userService.selectByCompanyId(enterprise.getId(),0);
        if (userList.size() != 2) {
            throw new BusinessException("发生错误,请联系管理员");
        }
        for (UserInfo info : userList) {
            userService.deleteById(info.getId());
        }
    }
 
 
    /**
    * @Description: 删除
    * @date 2021/7/9 15:15
    */
    @Override
    @Transactional
    public void delBlackList(Long id, UserInfo user) {
        if (id == null)
            throw new BusinessException("参数传递错误,请联系管理员");
        BlackList one = this.getById(id);
        if (one == null) throw new BusinessException("数据不存在,请联系管理员");
        String enterprisename = one.getEnterprisename();
        Enterprise enterprise = enterpriseService.selectEnterpriseByName(enterprisename);
        one.setValidflag(Boolean.FALSE);
        one.setModifyby(user.getUsername());
        one.setModifytime(new Date());
        this.updateById(one);
        //启用
        //1.修改企业状态为 启用
        enterpriseService.setEnterpriseStatus(EnterpriseStatus.ON, id);
        //2.修改企业用户isdel 0
        //3.修改终端用户isdel 0
        List<UserInfo> userList = userService.selectByCompanyId(enterprise.getId(),1);
        if (userList.size() != 2) {
            throw new BusinessException("发生错误,请联系管理员");
        }
        for (UserInfo info : userList) {
            userService.recoverOneById(info.getId());
        }
    }
 
    @Override
    public IPage selectPages(Page<BlackList> page, Map filter, UserInfo user) {
        Map<String, Object> params = new HashMap<>();
        //可见自己建的  管理员(1,2)没有限制
        if (user.getType() != 1 && user.getType() != 2) {
            params.put("createbyid", user.getId());
        }
 
        //页面过滤
        params.put("enterprisename", filter.get("enterprisename"));
        List<BlackList> data = blackListMapper.selectPages(page, params);
        return page.setRecords(data);
 
    }
 
    /**
    * @Description: 根据企业编号查找企业企业名单
    * @date 2021/7/9 16:51
    */
    @Override
    public BlackList getByEnterprisenumber(String enterprisenumber) {
        if (StringUtils.isBlank(enterprisenumber)) {
            throw new BusinessException("单位编号不能为空");
        }
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getEnterprisenumber, enterprisenumber)
                    .eq(BlackList::getValidflag,Boolean.TRUE);
        return blackListMapper.selectOne(queryWrapper);
    }
 
 
}