| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.doumee.service.business.impl.hksync; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.haikang.model.HKConstants; |
| | | import com.doumee.core.haikang.model.param.BaseListPageResponse; |
| | | import com.doumee.core.haikang.model.param.BaseResponse; |
| | | import com.doumee.core.haikang.model.param.request.*; |
| | | import com.doumee.core.haikang.model.param.respose.*; |
| | | import com.doumee.core.haikang.service.HKService; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.dao.business.dao.MemberMapper; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.system.join.NoticesJoinMapper; |
| | | import com.doumee.dao.system.model.Notices; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 海康访客ä¸å¡Serviceå®ç° |
| | | * @author æ±è¹è¹ |
| | | * @date 2023/11/30 15:33 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class HkSyncNoticeServiceImpl extends HkSyncBaseServiceImpl { |
| | | @Autowired |
| | | private NoticesJoinMapper noticesJoinMapper; |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | @Override |
| | | public String syncHkNotices(String username){ |
| | | if(Constants.DEALING_HK_NOTICE_LIST){ |
| | | return null; |
| | | } |
| | | Constants.DEALING_HK_NOTICE_LIST =true; |
| | | try { |
| | | List<String> users = new ArrayList<>(); |
| | | users.add(username); |
| | | |
| | | List<Integer> userIds = new ArrayList<>(); |
| | | List<Member > userList = memberMapper.selectList(new QueryWrapper<Member>().lambda() |
| | | .in(Member::getPhone,users) |
| | | .eq(Member::getType,Constants.TWO) |
| | | .eq(Member::getIsdeleted,Constants.ZERO)); |
| | | Member tu= getFromUserList(username,userList); |
| | | if(tu!=null){ |
| | | userIds.add(tu.getId()); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对ä¸èµ·ï¼æ æè´¦å·~"); |
| | | } |
| | | if(userIds.size()>0){ |
| | | //æ¸
空海康å
¨é¨çä»£åæ°æ® |
| | | noticesJoinMapper.delete(new UpdateWrapper<Notices>().lambda() |
| | | .eq(Notices::getType, Constants.noticesObjectType.hknotice) |
| | | .in(Notices::getUserId, userIds)); |
| | | } |
| | | Date date = new Date(); |
| | | List<GetTodoListResponse> allHkList = new ArrayList<>(); |
| | | boolean hasNext = true; |
| | | int curTotal = 0; |
| | | int curPage = 1; |
| | | while (hasNext){ |
| | | //å页éåå¾ªç¯æ¥è¯¢ææé¨ç¦è®¾å¤æ°æ® |
| | | GetTodoListRequest param = new GetTodoListRequest(); |
| | | // param.setComId("dfe");//æ¥å
¨é¨ç代å |
| | | param.setUserId(username); |
| | | param.setStatus(1);//åªæ¥å¾
å¤ççæ°æ® |
| | | param.setPageNo(curPage); |
| | | param.setLocaleType("zh_CN"); |
| | | param.setPageSize(100); |
| | | BaseResponse<BaseListPageResponse<GetTodoListResponse>> response = HKService.getTodoListPage(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对ä¸èµ·ï¼æµ·åº·åæ¥æ°æ®å¤±è´¥~"); |
| | | } |
| | | BaseListPageResponse<GetTodoListResponse> r = response.getData(); |
| | | curTotal += 100; |
| | | if(curTotal >= r.getTotal()){ |
| | | hasNext = false; |
| | | } |
| | | if(r.getList() == null || r.getList().size()==0){ |
| | | hasNext =false; |
| | | }else{ |
| | | allHkList.addAll(r.getList()); |
| | | } |
| | | curPage++; |
| | | } |
| | | |
| | | |
| | | if(allHkList!=null && allHkList.size()>0){ |
| | | List<Notices> list = new ArrayList<>(); |
| | | for(GetTodoListResponse data :allHkList){ |
| | | Member u = getFromUserList(data.getUserId(),userList); |
| | | if(u==null){ |
| | | continue; |
| | | } |
| | | userIds.add(u.getId()); |
| | | JSONObject param = new JSONObject(); |
| | | |
| | | param.put("componentId","dfe"); |
| | | param.put("msgType","tlnc"); |
| | | param.put("componentMenuId", data.getMenuCode()); |
| | | JSONObject c = new JSONObject(); |
| | | c.put("method","dealTlncMsg"); |
| | | c.put("argument", data); |
| | | param.put("callback",c); |
| | | Notices notices = new Notices(); |
| | | notices.setCreateDate(DateUtil.getISO8601DateByStr(data.getMsgCreateTimeIso())); |
| | | notices.setUserId(u.getId()); |
| | | notices.setStatus(Constants.ZERO); |
| | | notices.setSendacopy(Constants.ZERO); |
| | | //ä¸å¡ç¶æä¿¡æ¯ 0 =å¾
å¤ç;1=å·²åæ/å·²å¤ç;2=å·²æç»/å·²éå;3=已转交;4=å·²æ¤é |
| | | notices.setParam1(JSONObject.toJSONString(data)); |
| | | notices.setParam2(Constants.ZERO+""); |
| | | notices.setTitle(data.getMsgTitle()); |
| | | if(notices.getCreateDate() == null){ |
| | | notices.setCreateDate(date); |
| | | } |
| | | notices.setIsdeleted(Constants.ZERO); |
| | | notices.setParam4(data.getMsgCreateTimeIso()); |
| | | notices.setParam3(data.getMsgCreateTime()); |
| | | notices.setParam5(JSONObject.toJSONString(param)); |
| | | notices.setType(Constants.noticesObjectType.hknotice); |
| | | list.add(notices); |
| | | } |
| | | if(list.size()>0){ |
| | | noticesJoinMapper.insert(list);//æ¹éæå
¥è®°å½ |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | Constants.DEALING_HK_NOTICE_LIST =false; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private Member getFromUserList(String userId, List<Member> userList) { |
| | | if(userList!=null ){ |
| | | for(Member u :userList){ |
| | | if(StringUtils.equals(u.getPhone(),userId)){ |
| | | return u; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |