|
|
@@ -0,0 +1,217 @@
|
|
|
+package org.dromara.server.consume.business;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.server.common.constant.DefaultConstants;
|
|
|
+import org.dromara.server.consume.cache.TokenManager;
|
|
|
+import org.dromara.server.consume.domain.vo.XfTermVo;
|
|
|
+import org.dromara.server.consume.domain.vo.yc.RoomInfo;
|
|
|
+import org.dromara.server.consume.domain.vo.yc.SettlementAccount;
|
|
|
+import org.dromara.server.consume.domain.vo.yc.TermInfo;
|
|
|
+import org.dromara.server.consume.domain.vo.yc.TermToken;
|
|
|
+import org.dromara.server.consume.service.IXfTermService;
|
|
|
+import org.dromara.system.api.RemoteUserService;
|
|
|
+import org.dromara.system.api.domain.vo.RemoteUserVo;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName TermBusiness
|
|
|
+ * @Description TODO
|
|
|
+ * @Author luoyibo
|
|
|
+ * @Date 2024-12-18 08:50
|
|
|
+ * @Version 1.0
|
|
|
+ * @since jdk17
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class TermBusiness {
|
|
|
+ private static final Object locker = new Object();
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteUserService remoteUserService;
|
|
|
+ private final IXfTermService termService;
|
|
|
+ private final TokenManager tokenManager;
|
|
|
+
|
|
|
+ private static final ConcurrentHashMap<Integer, Long> lastCheckModify = new ConcurrentHashMap<>();
|
|
|
+ private static final ConcurrentHashMap<Integer, Long> lastModify = new ConcurrentHashMap<>();
|
|
|
+ private static final ConcurrentHashMap<Integer, Long> lastCheckBlack = new ConcurrentHashMap<>();
|
|
|
+ private static final ConcurrentHashMap<Integer, Long> lastBlack = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ public R<TermToken> getTermToken(Long termNo, String admin, String pwd) {
|
|
|
+ XfTermVo termVo = termService.queryVoOneByNo(termNo);
|
|
|
+ if (ObjectUtil.isEmpty(termVo)) {
|
|
|
+ return R.fail(MessageFormat.format("机号为[{0}]的设备不存在", termNo), null);
|
|
|
+ }
|
|
|
+ RemoteUserVo userVo = remoteUserService.selectUserVoByUserName(admin);
|
|
|
+ if (ObjectUtil.isEmpty(userVo)) {
|
|
|
+ return R.fail(MessageFormat.format("用户为[{0}]的用户不存在", admin), null);
|
|
|
+ }
|
|
|
+ TermToken termToken = null;
|
|
|
+ synchronized (locker) {
|
|
|
+ String strTermNo = String.valueOf(termNo);
|
|
|
+ termToken = tokenManager.getTermToken().get(strTermNo);
|
|
|
+ if (ObjectUtil.isEmpty(termToken)) {
|
|
|
+ LocalDateTime ldt = LocalDateTime.of(2000, 1, 1, 0, 0, 0);
|
|
|
+ Date minDate = Date.from(ldt.toInstant(ZoneOffset.of("+8")));
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime expireTime = now.plusHours(2);
|
|
|
+ termToken = new TermToken(strTermNo, UUID.randomUUID().toString(), admin, new Date(), minDate,
|
|
|
+ Date.from(expireTime.toInstant(ZoneOffset.of("+8"))));
|
|
|
+
|
|
|
+ tokenManager.getTermToken().put(strTermNo, termToken);
|
|
|
+ } else {
|
|
|
+ if (termToken.getExpireTime().getTime() < new Date().getTime()) {
|
|
|
+ LocalDateTime ldt = LocalDateTime.of(2000, 1, 1, 0, 0, 0);
|
|
|
+ Date minDate = Date.from(ldt.toInstant(ZoneOffset.of("+8")));
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime expireTime = now.plusHours(2);
|
|
|
+ Date expireDate = Date.from(expireTime.toInstant(ZoneOffset.of("+8")));
|
|
|
+
|
|
|
+ termToken.setAdmin(admin);
|
|
|
+ termToken.setToken(UUID.randomUUID().toString());
|
|
|
+ termToken.setDateTime(new Date());
|
|
|
+ termToken.setAuthTime(minDate);
|
|
|
+ termToken.setExpireTime(expireDate);
|
|
|
+ } else {
|
|
|
+ termToken.setAdmin(admin);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok(MessageFormat.format("获取token成功,设备编号[{0}],账号[{1}]", termNo, admin), termToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ public R<TermInfo> getTermInfoByTermNo(Long termNo) {
|
|
|
+ XfTermVo termVo = termService.queryVoOneByNo(termNo);
|
|
|
+ if (ObjectUtil.isEmpty(termVo)) {
|
|
|
+ return R.fail(MessageFormat.format("机号为[{0}]的设备不存在", termNo), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ TermInfo termInfo = this.convertToYc(termVo);
|
|
|
+
|
|
|
+ return R.ok(termInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ public R<Map<String, Object>> checkTermTime(Integer termNo) {
|
|
|
+ XfTermVo termVo = termService.queryVoOneByNo(Long.valueOf(termNo));
|
|
|
+ if (ObjectUtil.isEmpty(termVo)) {
|
|
|
+ return R.fail(MessageFormat.format("机号为[{0}]的设备不存在", termNo), null);
|
|
|
+ }
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ if (!lastCheckModify.containsKey(termNo)) {
|
|
|
+ lastCheckModify.put(termNo, 0L);
|
|
|
+ }
|
|
|
+ Date nowDate = new Date();
|
|
|
+ long currentTime = nowDate.getTime();
|
|
|
+ if (currentTime > lastCheckModify.get(termNo)) {
|
|
|
+ lastCheckModify.put(termNo, currentTime + 1000 * 60);
|
|
|
+ }
|
|
|
+ resultMap.put("time", DateUtil.format(nowDate, DefaultConstants.DATE_TIME_FORMAT));
|
|
|
+ resultMap.put("type", "");
|
|
|
+ resultMap.put("data", termVo == null ? "" : termVo.getTermName());
|
|
|
+
|
|
|
+ return R.ok(resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ private TermInfo convertToYc(XfTermVo termVo) {
|
|
|
+ TermInfo termInfo = new TermInfo();
|
|
|
+ termInfo.setTermId(termVo.getTermId().toString());
|
|
|
+ termInfo.setTermNo(termVo.getTermNo().intValue());
|
|
|
+ termInfo.setTermName(termVo.getTermName());
|
|
|
+ termInfo.setTermType(termVo.getTermType());
|
|
|
+ termInfo.setConsumeType("4");
|
|
|
+ termInfo.setRoomId(termVo.getRoomId().toString());
|
|
|
+ termInfo.setAccountId(termVo.getAccountId().toString());
|
|
|
+ termInfo.setWorkStationId(termVo.getStationId() == null ? null : termVo.getStationId().toString());
|
|
|
+ termInfo.setUseType(termVo.getUseType());
|
|
|
+ termInfo.setCardTypeId(termVo.getCardType());
|
|
|
+ termInfo.setOperateMode(!termVo.getOpenMode().equals("0"));
|
|
|
+ termInfo.setWorkModeId(termVo.getWorkMode());
|
|
|
+ termInfo.setTermDescript(termVo.getRemark());
|
|
|
+ termInfo.setTermRecordId(termVo.getRecordId());
|
|
|
+ termInfo.setRecordUpTime(termVo.getUploadTime());
|
|
|
+ termInfo.setBlackListDownTime(termVo.getBlackDownTime());
|
|
|
+ termInfo.setMaxMoney(termVo.getSingleMoney());
|
|
|
+ termInfo.setMaxCardMoney(termVo.getMaxCardMoney());
|
|
|
+ termInfo.setEachMealMoney(termVo.getConstantValue());
|
|
|
+ termInfo.setRation0(termVo.getRationZero());
|
|
|
+ termInfo.setRation1(termVo.getRationOne());
|
|
|
+ termInfo.setRation2(termVo.getRationTwo());
|
|
|
+ termInfo.setRation3(termVo.getRationThree());
|
|
|
+ termInfo.setRation4(termVo.getRationFour());
|
|
|
+ termInfo.setRation5(termVo.getRationFive());
|
|
|
+ termInfo.setRation6(termVo.getRationSix());
|
|
|
+ termInfo.setRation7(termVo.getRationSeven());
|
|
|
+ termInfo.setRation8(termVo.getRationEight());
|
|
|
+ termInfo.setRation9(termVo.getRationNine());
|
|
|
+ termInfo.setTimesQuota(termVo.getDayCount());
|
|
|
+ termInfo.setValueQuota(termVo.getDayMoney());
|
|
|
+ termInfo.setMealTimesQuota(termVo.getMealCount());
|
|
|
+ termInfo.setDejeunerValue(termVo.getBreakfastMoney());
|
|
|
+ termInfo.setLunchValue(termVo.getLunchMoney());
|
|
|
+ termInfo.setSupperValue(termVo.getSupperMoney());
|
|
|
+ termInfo.setNightValue(termVo.getNightMoney());
|
|
|
+ termInfo.setDejeunerBegin(termVo.getBreakfastBegin().intValue());
|
|
|
+ termInfo.setDejeunerEnd(termVo.getBreakfastEnd().intValue());
|
|
|
+ termInfo.setLunchBegin(termVo.getLunchBegin().intValue());
|
|
|
+ termInfo.setLunchEnd(termVo.getLunchEnd().intValue());
|
|
|
+ termInfo.setSupperBegin(termVo.getSupperBegin().intValue());
|
|
|
+ termInfo.setSupperEnd(termVo.getSupperEnd().intValue());
|
|
|
+ termInfo.setNightMealBegin(termVo.getNightBegin().intValue());
|
|
|
+ termInfo.setNightMealEnd(termVo.getNightEnd().intValue());
|
|
|
+ termInfo.setTermIP(termVo.getTermIp());
|
|
|
+ termInfo.setTermMAC(termVo.getTermMac());
|
|
|
+ termInfo.setTermPort(termVo.getCommPort().toString());
|
|
|
+ termInfo.setUseTermOfValidity(termVo.getTermValidity().equals("1"));
|
|
|
+ termInfo.setPosParam(null);
|
|
|
+ termInfo.setRateParam(null);
|
|
|
+ termInfo.setAdvParam(null);
|
|
|
+ termInfo.setGatewayIp(termVo.getGatewayIp());
|
|
|
+ termInfo.setServerIp(termVo.getServerIp());
|
|
|
+ termInfo.setServerPort(termVo.getServerPort().toString());
|
|
|
+ termInfo.setMask(termVo.getMask());
|
|
|
+ termInfo.setQrCode(termVo.getQrCode());
|
|
|
+ termInfo.setIsAutoDownParameter(termVo.getAutoDown().equals("Y"));
|
|
|
+ termInfo.setLastCheckTime(termVo.getLastCheck());
|
|
|
+ termInfo.setOutLineMin(termVo.getOfflineTime().intValue());
|
|
|
+ termInfo.setAvailableInterval(termVo.getSwipeInterval());
|
|
|
+ termInfo.setRebootTime(termVo.getRebootTime());
|
|
|
+ termInfo.setTimeout(termVo.getTimeout().intValue());
|
|
|
+ termInfo.setBeatInterval(termVo.getBeatInterval().intValue());
|
|
|
+ // termInfo.setAllowOfflineTime();
|
|
|
+ termInfo.setRoomName(termVo.getRoomName());
|
|
|
+ // termInfo.setCreateTime();
|
|
|
+ // termInfo.setCreateUser();
|
|
|
+ // termInfo.setIsDelete();
|
|
|
+ // termInfo.setOrderIndex();
|
|
|
+ // termInfo.setUpdateTime();
|
|
|
+ // termInfo.setUpdateUser();
|
|
|
+ termInfo.setVersion(0);
|
|
|
+
|
|
|
+ RoomInfo roomInfo = new RoomInfo();
|
|
|
+ roomInfo.setAreaID(termVo.getRoomId().toString());
|
|
|
+ roomInfo.setAreaName(termVo.getRoomName());
|
|
|
+ termInfo.setArea(roomInfo);
|
|
|
+
|
|
|
+ SettlementAccount account = new SettlementAccount();
|
|
|
+ account.setAccountID(termVo.getAccountId().toString());
|
|
|
+ account.setAccountName(termVo.getAccountName());
|
|
|
+ termInfo.setAccount(account);
|
|
|
+
|
|
|
+ return termInfo;
|
|
|
+ }
|
|
|
+}
|