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 users = new ArrayList<>(); users.add(username); List userIds = new ArrayList<>(); List userList = memberMapper.selectList(new QueryWrapper().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().lambda() .eq(Notices::getType, Constants.noticesObjectType.hknotice) .in(Notices::getUserId, userIds)); } Date date = new Date(); List 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> response = HKService.getTodoListPage(param); if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); } BaseListPageResponse 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 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",JSONObject.toJSONString(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 userList) { if(userList!=null ){ for(Member u :userList){ if(StringUtils.equals(u.getPhone(),userId)){ return u; } } } return null; } }