| | |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.haikang.model.HKConstants; |
| | | import com.doumee.core.haikang.model.param.BaseResponse; |
| | | import com.doumee.core.haikang.model.param.request.AcsDeviceListRequest; |
| | | import com.doumee.core.haikang.model.param.request.CarChargeAddRequest; |
| | | import com.doumee.core.haikang.model.param.request.CarChargeDelRequest; |
| | | import com.doumee.core.haikang.model.param.request.ParkListRequest; |
| | | import com.doumee.core.haikang.model.param.respose.AcsDeviceInfoResponse; |
| | | import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse; |
| | | import com.doumee.core.haikang.model.param.respose.ParkListResponse; |
| | | import com.doumee.core.haikang.service.HKService; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.dao.business.DeviceMapper; |
| | | import com.doumee.dao.business.ParksMapper; |
| | | import com.doumee.dao.business.model.Device; |
| | | import com.doumee.dao.business.model.Parks; |
| | | import com.doumee.dao.business.join.ParkBookJoinMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | |
| | | @Autowired |
| | | private ParksMapper parksMapper; |
| | | @Autowired |
| | | private ParkBookJoinMapper parkBookMapper; |
| | | @Override |
| | | public void syncParkBookData() { |
| | | if(Constants.DEALING_HK_PARKBOOK){ |
| | | return ; |
| | | } |
| | | Constants.DEALING_HK_PARKBOOK =true; |
| | | try { |
| | | //查询所有需要同步的数据 |
| | | List<ParkBook> list =getDealList (); |
| | | if(list ==null || list.size()==0){ |
| | | return; |
| | | } |
| | | Date date = new Date(); |
| | | //先出所有需要取消包期的数据记录 |
| | | for(ParkBook c : list) { |
| | | if(Constants.equalsObject(c.getIsdeleted(),Constants.ONE)){ |
| | | //如果取消预约,则进行取消包期 |
| | | if(StringUtils.isNotBlank(c.getParkHkId()) |
| | | && StringUtils.isNotBlank(c.getCarCode())){ |
| | | boolean result = cancelParkBookHk(c); |
| | | c.setHkStatus(result?Constants.ONE:Constants.TWO); |
| | | }else{ |
| | | c.setHkStatus(Constants.TWO);//下发失败 |
| | | } |
| | | c.setHkDate(date); |
| | | parkBookMapper.updateById(c); |
| | | } |
| | | } |
| | | //处理所有需要包期的车辆数据记录 |
| | | for(ParkBook c : list) { |
| | | if(Constants.equalsObject(c.getIsdeleted(),Constants.ONE)) { |
| | | //删除的已处理,跳过处理 |
| | | continue; |
| | | } |
| | | //数据不合法,直接提示下发失败 |
| | | if(StringUtils.isNotBlank(c.getParkHkId()) |
| | | && StringUtils.isNotBlank(c.getCarCode())){ |
| | | boolean result = addParkBookHk(c); |
| | | c.setHkStatus(result?Constants.ONE:Constants.TWO); |
| | | }else{ |
| | | c.setHkStatus(Constants.TWO); |
| | | } |
| | | c.setHkDate(date); |
| | | parkBookMapper.updateById(c); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | Constants.DEALING_HK_PARKBOOK =false; |
| | | } |
| | | |
| | | } |
| | | |
| | | private boolean addParkBookHk(ParkBook c) { |
| | | CarChargeAddRequest param = new CarChargeAddRequest(); |
| | | param.setPlateNo(c.getCarCode()); |
| | | param.setParkSyscode(c.getParkHkId()); |
| | | param.setStartTime(DateUtil.getISO8601Timestamp(c.getStartTime())); |
| | | param.setEndTime(DateUtil.getISO8601Timestamp(c.getEndTime())); |
| | | BaseResponse response = HKService.carChargeAddtion(param); |
| | | if(response!=null |
| | | && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)){ |
| | | return true; |
| | | }else{ |
| | | return false; |
| | | } |
| | | } |
| | | private boolean cancelParkBookHk(ParkBook c) { |
| | | CarChargeDelRequest param = new CarChargeDelRequest(); |
| | | param.setPlateNo(c.getCarCode()); |
| | | param.setParkSyscode(c.getParkHkId()); |
| | | BaseResponse response = HKService.carChargeDeletion(param); |
| | | if(response!=null |
| | | && StringUtils.equals(response.getCode(),HKConstants.RESPONSE_SUCCEE)){ |
| | | return true; |
| | | }else{ |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | private List<ParkBook> getDealList() { |
| | | MPJLambdaWrapper<ParkBook> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(ParkBook.class); |
| | | queryWrapper.selectAs(Parks::getHkId,ParkBook::getParkHkId); |
| | | queryWrapper.leftJoin(Parks.class,Parks::getId,ParkBook::getParkId); |
| | | queryWrapper.selectAs(Device::getHkId,Empower::getDeviceIndexCode); |
| | | List<ParkBook> list = parkBookMapper.selectJoinList(ParkBook.class,queryWrapper); |
| | | return list; |
| | | } |
| | | /** |
| | | * 同步海康停车库数据 |
| | | * @param param |
| | |
| | | @Override |
| | | // @Async |
| | | public String syncHkParks(ParkListRequest param){ |
| | | List<Parks> deleteList = new ArrayList<>(); |
| | | List<Parks> addList = new ArrayList<>(); |
| | | List<Parks> editList = new ArrayList<>(); |
| | | Date date = new Date(); |
| | | //查询全部当前数据 |
| | | List<Parks> allList = parksMapper.selectList(null); |
| | | if(Constants.DEALING_HK_SYNCPRIVILEGE){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "同步任务正在执行哦,请稍后查看结果!") ; |
| | | } |
| | | Constants.DEALING_HK_SYNCPRIVILEGE =true; |
| | | try { |
| | | List<Parks> deleteList = new ArrayList<>(); |
| | | List<Parks> addList = new ArrayList<>(); |
| | | List<Parks> editList = new ArrayList<>(); |
| | | Date date = new Date(); |
| | | //查询全部当前数据 |
| | | List<Parks> allList = parksMapper.selectList(null); |
| | | //分页遍历循环查询所有门禁设备数据 |
| | | param = new ParkListRequest(); |
| | | BaseResponse<List<ParkListResponse>> response = HKService.parkList(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | List<ParkListResponse> allHkList = response.getData(); |
| | | // 获取增删改数据集合 |
| | | getDataChangeList(allList,allHkList,addList,editList,deleteList,date); |
| | | if(deleteList.size()>0){ |
| | | //逻辑删除 |
| | | for(Parks d : deleteList){ |
| | | parksMapper.updateById(d); |
| | | param = new ParkListRequest(); |
| | | BaseResponse<List<ParkListResponse>> response = HKService.parkList(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | } |
| | | if(addList.size()>0){ |
| | | parksMapper.insertBatchSomeColumn(addList); |
| | | } |
| | | if(editList.size()>0){ |
| | | for(Parks d : editList){ |
| | | parksMapper.updateById(d); |
| | | List<ParkListResponse> allHkList = response.getData(); |
| | | // 获取增删改数据集合 |
| | | getDataChangeList(allList,allHkList,addList,editList,deleteList,date); |
| | | if(deleteList.size()>0){ |
| | | //逻辑删除 |
| | | for(Parks d : deleteList){ |
| | | parksMapper.updateById(d); |
| | | } |
| | | } |
| | | if(addList.size()>0){ |
| | | parksMapper.insertBatchSomeColumn(addList); |
| | | } |
| | | if(editList.size()>0){ |
| | | for(Parks d : editList){ |
| | | parksMapper.updateById(d); |
| | | } |
| | | } |
| | | return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条"; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "同步失败!"); |
| | | }finally { |
| | | Constants.DEALING_HK_SYNCPRIVILEGE =false; |
| | | } |
| | | return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条"; |
| | | } |
| | | private void getDataChangeList(List<Parks> allList, List<ParkListResponse> allHkList, List<Parks> addList, List<Parks> editList,List<Parks> deleteList, Date date) { |
| | | if(allHkList!=null && allHkList.size()>0){ |
| | |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setName(device.getParkName()); |
| | | model.setHkDate(date); |
| | | model.setCreateDate(DateUtil.StringToDate2(device.getCreateTime())); |
| | | model.setEditDate(DateUtil.StringToDate2(device.getUpdateTime())); |
| | | model.setCreateDate(DateUtil.getISO8601DateByStr(device.getCreateTime())); |
| | | model.setEditDate(DateUtil.getISO8601DateByStr(device.getUpdateTime())); |
| | | model.setHkId(device.getParkIndexCode()); |
| | | model.setHkStatus(Constants.ONE); |
| | | model.setStatus(Constants.ONE); |
| | | return model; |
| | | } |
| | | |