| | |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.dao.business.dao.CompanyMapper; |
| | | import com.doumee.dao.business.model.CarUseBook; |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.model.Visits; |
| | | import com.doumee.dao.system.model.SystemDictData; |
| | | import com.doumee.service.business.CompanyService; |
| | | import com.github.xiaoymin.knife4j.core.util.CollectionUtils; |
| | | import com.taobao.api.ApiException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.text.DateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | public String getToken(){ |
| | | String accessToken = systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.ACCESS_TOKEN).getCode(); |
| | | return accessToken; |
| | | } |
| | | |
| | | |
| | | public OapiV2UserGetuserinfoResponse.UserGetByCodeResponse getDDUserByCode(String code) throws ApiException { |
| | | DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo"); |
| | | OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest(); |
| | | req.setCode(code); |
| | | OapiV2UserGetuserinfoResponse rsp = client.execute(req, getToken()); |
| | | if(rsp.getErrcode().equals(Constants.DD_ERR_CODE)){ |
| | | return rsp.getResult(); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),rsp.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public void workInfoOANotice(Long agentId,String userIds,OapiMessageCorpconversationAsyncsendV2Request.Msg msg)throws ApiException { |
| | | DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"); |
| | | OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request(); |
| | | request.setAgentId(agentId); |
| | | request.setUseridList(userIds); |
| | | request.setToAllUser(false); |
| | | |
| | | request.setMsg(msg); |
| | | OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(request, getToken()); |
| | | if(rsp.getErrcode().equals(Constants.DD_ERR_CODE)){ |
| | | |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),rsp.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 访客申请/报备 OA 工作通知 内容 |
| | | * @param visits |
| | | * @param title |
| | | * @return |
| | | */ |
| | | public OapiMessageCorpconversationAsyncsendV2Request.Msg getVisitNoticeMsg(Visits visits,String title){ |
| | | OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg(); |
| | | msg.setMsgtype("oa"); |
| | | OapiMessageCorpconversationAsyncsendV2Request.OA oa = new OapiMessageCorpconversationAsyncsendV2Request.OA(); |
| | | oa.setMessageUrl(""); |
| | | OapiMessageCorpconversationAsyncsendV2Request.Head head = new OapiMessageCorpconversationAsyncsendV2Request.Head(); |
| | | head.setText(title); |
| | | head.setBgcolor("#279BAA"); |
| | | oa.setHead(head); |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Body body = new OapiMessageCorpconversationAsyncsendV2Request.Body(); |
| | | body.setTitle(!Constants.equalsInteger(visits.getType(),Constants.TWO)?visits.getName()+"的访客申请":"的访客报备"); |
| | | List<OapiMessageCorpconversationAsyncsendV2Request.Form> formList = new ArrayList<>(); |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form visitUser = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | visitUser.setKey("来访人"); |
| | | visitUser.setValue(visits.getName()); |
| | | formList.add(visitUser); |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form inDate = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | inDate.setKey("入园时间"); |
| | | inDate.setValue(DateUtil.formatDate(visits.getStarttime(),"MM-dd HH:mm")); |
| | | formList.add(inDate); |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form outDate = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | outDate.setKey("离园时间"); |
| | | outDate.setValue(DateUtil.formatDate(visits.getEndtime(),"MM-dd HH:mm")); |
| | | formList.add(outDate); |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form inReason = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | inReason.setKey("来访事由"); |
| | | inReason.setValue(visits.getReason()); |
| | | formList.add(inReason); |
| | | |
| | | if(StringUtils.isNotBlank(visits.getCarNos())){ |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form carNos = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | carNos.setKey("随访车辆"); |
| | | carNos.setValue(visits.getCarNos()); |
| | | formList.add(visitUser); |
| | | } |
| | | |
| | | body.setForm(formList); |
| | | oa.setBody(body); |
| | | msg.setOa(oa); |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | /* public OapiMessageCorpconversationAsyncsendV2Request.Msg getCarUseNoticeMsg(CarUseBook carUseBook,String title){ |
| | | OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg(); |
| | | msg.setMsgtype("oa"); |
| | | OapiMessageCorpconversationAsyncsendV2Request.OA oa = new OapiMessageCorpconversationAsyncsendV2Request.OA(); |
| | | oa.setMessageUrl(""); |
| | | OapiMessageCorpconversationAsyncsendV2Request.Head head = new OapiMessageCorpconversationAsyncsendV2Request.Head(); |
| | | head.setText(title); |
| | | head.setBgcolor("#279BAA"); |
| | | oa.setHead(head); |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Body body = new OapiMessageCorpconversationAsyncsendV2Request.Body(); |
| | | body.setTitle("公务用车"); |
| | | List<OapiMessageCorpconversationAsyncsendV2Request.Form> formList = new ArrayList<>(); |
| | | |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form startDate = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | startDate.setKey("开始时间"); |
| | | startDate.setValue(DateUtil.formatDate(carUseBook.getStartTime(),"MM-dd HH:mm")); |
| | | formList.add(startDate); |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form endDate = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | endDate.setKey("结束时间"); |
| | | endDate.setValue(DateUtil.formatDate(carUseBook.getEndTime(),"MM-dd HH:mm")); |
| | | formList.add(endDate); |
| | | |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form userNum = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | userNum.setKey("乘车人数"); |
| | | userNum.setValue(DateUtil.formatDate(carUseBook.getEndTime(),"MM-dd HH:mm")); |
| | | formList.add(userNum); |
| | | |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form inReason = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | inReason.setKey("来访事由"); |
| | | inReason.setValue(visits.getReason()); |
| | | formList.add(inReason); |
| | | |
| | | if(StringUtils.isNotBlank(visits.getCarNos())){ |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form carNos = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | carNos.setKey("随访车辆"); |
| | | carNos.setValue(visits.getCarNos()); |
| | | formList.add(visitUser); |
| | | } |
| | | |
| | | body.setForm(formList); |
| | | oa.setBody(body); |
| | | msg.setOa(oa); |
| | | |
| | | return msg; |
| | | }*/ |
| | | |
| | | } |