New file |
| | |
| | | package com.ruoyi.jianguan.mongodb.service.impl; |
| | | |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.integration.api.model.BmsInformation; |
| | | import com.ruoyi.integration.api.model.ChargingHandshake; |
| | | import com.ruoyi.jianguan.constant.IotConstant; |
| | | import com.ruoyi.jianguan.mongodb.service.ChargingHandshakeService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @Service |
| | | public class ChargingHandshakeServiceImpl implements ChargingHandshakeService { |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | @Override |
| | | public int create(ChargingHandshake chargingHandshake) { |
| | | mongoTemplate.save(chargingHandshake); |
| | | return IotConstant.SUCCESS; |
| | | } |
| | | |
| | | @Override |
| | | public ChargingHandshake findById(String id) { |
| | | return mongoTemplate.findById(id, ChargingHandshake.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<ChargingHandshake> findAll() { |
| | | return mongoTemplate.findAll(ChargingHandshake.class); |
| | | } |
| | | |
| | | @Override |
| | | public ChargingHandshake getDataByOrderCode(String code) { |
| | | List<ChargingHandshake> charging_gun_code = mongoTemplate.find(new Query().addCriteria(Criteria.where("transaction_serial_number").is(code)), ChargingHandshake.class); |
| | | return charging_gun_code.size() > 0 ? charging_gun_code.get(0) : null; |
| | | } |
| | | |
| | | @Override |
| | | public List<ChargingHandshake> getRangeTimeData(Date startTime, Date endTime) { |
| | | Query query = new Query(); |
| | | // 根据时间范围查询 |
| | | if (Objects.nonNull(startTime) && Objects.nonNull(endTime)) { |
| | | query.addCriteria(Criteria.where("create_time").gte(startTime).lte(endTime)); |
| | | } |
| | | List<ChargingHandshake> list = mongoTemplate.find( |
| | | query.with(Sort.by(Sort.Order.desc("create_time"))) |
| | | , ChargingHandshake.class); |
| | | return list; |
| | | } |
| | | } |