| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.ConcurrentReferenceHashMap; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentMap; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | } |
| | | |
| | | public ConcurrentMap<String,Integer> cacheOpenLock = new ConcurrentReferenceHashMap<>(); |
| | | |
| | | @Override |
| | | public MemberRidesDetailResponse openLock(String code,String memberId) { |
| | | if(Constants.formatIntegerNum(cacheOpenLock.get(code)) == 1){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该车辆已被锁定借用,请尝试更换其他车辆!"); |
| | | } |
| | | cacheOpenLock.put(code, 1); |
| | | try { |
| | | if(StringUtils.isBlank(code) || code.split("/").length != 2){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该站点编号不存在,请尝试更换车辆!"); |
| | | } |
| | |
| | | |
| | | memberRidesMapper.insert(memberRides); |
| | | BeanUtils.copyProperties(memberRides, memberRidesDetailResponse); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "当前车辆暂时无法使用,请稍后重试或更换其它车辆~"); |
| | | } |
| | | return memberRidesDetailResponse; |
| | | }catch (BusinessException biz){ |
| | | throw biz; |
| | | }catch (Exception biz){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR); |
| | | }finally { |
| | | cacheOpenLock.remove(code); |
| | | } |
| | | |
| | | } |
| | | |
| | | private boolean isValidePricingType(Locks locks,MemberRides memberRides ) { |