| 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); | 
|         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); | 
|     } | 
| } |