a
jiangping
2023-10-16 a69578ed877252e70d45d4753258b3d7b6937606
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
package doumeemes.service.ext.impl;
 
import com.alibaba.fastjson.JSONObject;
import doumeemes.core.constants.ResponseStatus;
import doumeemes.core.exception.BusinessException;
import doumeemes.core.model.LoginUserInfo;
import doumeemes.core.model.PageData;
import doumeemes.core.model.PageWrap;
import doumeemes.core.utils.Constants;
import doumeemes.core.utils.DateUtil;
import doumeemes.core.utils.dingding.DingDingUtil;
import doumeemes.core.utils.redis.RedisUtil;
import doumeemes.dao.business.model.CompanyUser;
import doumeemes.dao.business.model.Notices;
import doumeemes.dao.ext.CompanyUserExtMapper;
import doumeemes.dao.ext.dto.QueryNoticesExtDTO;
import doumeemes.dao.ext.vo.*;
import doumeemes.service.ext.CompanyExtService;
import doumeemes.service.ext.CompanyUserExtService;
import doumeemes.service.ext.NoticesExtService;
import doumeemes.dao.ext.NoticesExtMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
 
/**
 * 系统待办通知Service实现
 * @author 江蹄蹄
 * @date 2022/06/17 15:10
 */
@Service
public class NoticesExtServiceImpl implements NoticesExtService {
 
    @Autowired
    private NoticesExtMapper noticesExtMapper;
    @Autowired
    private CompanyExtService companyExtService;
    @Autowired
    private CompanyUserExtService companyUserExtService;
 
    @Override
    public PageData<NoticesExtListVO> findPage(PageWrap<QueryNoticesExtDTO> pageWrap) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), ResponseStatus.NOT_ALLOWED.getMessage());
        }
        pageWrap.getModel().setDeleted(Constants.ZERO);
        pageWrap.getModel().setRootId(user.getRootDepartment().getId());
        pageWrap.getModel().setCompanyUserId(user.getCompanyUser().getId());
        PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity());
        List<NoticesExtListVO> result = noticesExtMapper.selectList(pageWrap.getModel());
        return PageData.from(new PageInfo<>(result));
    }
 
    /**
     * 需要设置  companyUserId,title,content,type,url
     * @param model
     * @return
     */
    @Override
    public Integer sendNotice(Notices model) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), ResponseStatus.NOT_ALLOWED.getMessage());
        }
       return  sendNoticeDo(user,model);
 
    }
 
    private Integer sendNoticeDo(LoginUserInfo user, Notices model) {
        CompanyUserExtListVO cu = companyUserExtService.selectById(model.getCompanyUserId());
        if(cu == null){
            return null;
        }
        model.setId(UUID.randomUUID().toString());
        model.setDeleted(Constants.ZERO);
        model.setRootId(user.getRootDepartment().getId());
        model.setUserId(cu.getUserId());
        model.setDepartmentId(user.getCurComDepartment().getId());
        model.setStatus(Constants.ZERO);
        model.setCreateTime(DateUtil.getCurrentDate());
        model.setCreateUser(user.getId());
        CompanyExtListVO company = user.getCompany();
        model.setDdStatus(Constants.ZERO);
        if(StringUtils.isNotBlank(model.getUrl())){
            model.setUrl(model.getUrl().replace("{dbid}",model.getId()));
            if(StringUtils.isNotBlank(cu.getDdUserid())){
                try {
                    String token = companyExtService.getDingdingToken(company.getId());
                    JSONObject json = JSONObject.parseObject(company.getDingdingInfo());
                    Long agentId = Long.parseLong(json.getString("agentid"));
                    String taskId =  DingDingUtil.sendActionCardNotice(token,agentId,cu.getDdUserid(),model.getUrl(),model.getTitle(),model.getContent());
                    model.setDdParam(taskId);
                    model.setDdStatus(Constants.ONE);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        //插入数据
        return   noticesExtMapper.insert(model);
    }
 
    /**
     * 需要设置  companyUserId,title,content,type,url
     * @param model
     * @return
     */
    @Override
    public Integer sendNoticeNologin(Notices model,LoginUserInfo user) {
        if(user == null){
            return  null;
        }
        return  sendNoticeDo(user,model);
    }
    /**
     * @param param
     * @param
     */
    @Override
    public NoticeExtListCountVO pageCount(QueryNoticesExtDTO param){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!");
        }
        param.setDeleted(Constants.ZERO);
        //只能查看当前根组织的数据
        param.setRootId(user.getRootDepartment().getId());
        param.setUserId(user.getId());
        param.setCompanyUserId(user.getCompanyUser().getId());
 
        NoticeExtListCountVO result = new NoticeExtListCountVO();
        //全部数量
        result.setAllNum(noticesExtMapper.selectCount(param));
        param.setStatus(Constants.ZERO);
        //未完成数量
        result.setStartNum(noticesExtMapper.selectCount(param));
        param.setStatus(Constants.ONE);
        //未完成数量
        result.setEndNum(noticesExtMapper.selectCount(param));
        return result;
    }
 
    /**
     * 处理待办
     * @param objId 对象编码
     * @param type  通知类型
     * @param dealInfo 处理备注
     */
    @Override
    public void dealNotice(Integer objId,Integer type,String dealInfo){
        if(objId == null || type == null){
            return;
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), ResponseStatus.NOT_ALLOWED.getMessage());
        }
        QueryNoticesExtDTO dto = new QueryNoticesExtDTO();
        dto.setObjId(objId);
        dto.setType(type);
        dto.setDeleted(Constants.ZERO);
        NoticesExtListVO notice = noticesExtMapper.selectByModel(dto);
        if(notice == null){
            return;
        }
        Notices model = new Notices();
        model.setId(notice.getId());
        model.setDealDate(DateUtil.getCurrentDate());
        model.setStatus(Constants.ONE);
        model.setDealInfo(dealInfo);
          //插入数据
        noticesExtMapper.updateById(model);
    }
    @Override
    public  Integer create(Notices model){
         model.setUserId(105);
         model.setCompanyUserId(18);
         model.setTitle("测试工厂通知");
         model.setContent(StringUtils.defaultString(model.getContent(),"测试工厂通知内容"));
         model.setUrl("http://www.doumee.com");
         return  sendNotice(model);
    }
}