diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/admin/asset/vo/AssetRespVO.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/admin/asset/vo/AssetRespVO.java index 4e3481fff..19e0d3ab5 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/admin/asset/vo/AssetRespVO.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/admin/asset/vo/AssetRespVO.java @@ -14,7 +14,7 @@ public class AssetRespVO { @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30538") @ExcelProperty("ID") - private Long id; + private String id; @Schema(description = "数据ID", example = "15059") @ExcelProperty("数据ID") diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/asset/AssetServiceImpl.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/asset/AssetServiceImpl.java index f0839fbd6..1efcb77f1 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/asset/AssetServiceImpl.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/asset/AssetServiceImpl.java @@ -1,17 +1,16 @@ package cn.iocoder.yudao.module.datacenter.service.asset; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.datacenter.controller.admin.asset.vo.AssetRespVO; import cn.iocoder.yudao.module.datacenter.dal.dataobject.asset.Asset; import cn.iocoder.yudao.module.datacenter.dal.mongodb.asset.AssetRepository; import com.baomidou.dynamic.datasource.annotation.Slave; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** @@ -52,7 +51,7 @@ public class AssetServiceImpl implements AssetService { map.put("手持机", String.valueOf(assetTypeCounts[2])); List>mapList=new ArrayList<>(); for (Map.Entry stringStringEntry : map.entrySet()) { - Map map1=new LinkedHashMap(); + Map map1=new LinkedHashMap<>(); map1.put("assettype",stringStringEntry.getKey()); map1.put("count",stringStringEntry.getValue()); mapList.add(map1); @@ -64,13 +63,7 @@ public class AssetServiceImpl implements AssetService { public List nameAsset(String assettypename) { List assetRespVOList = new ArrayList<>(); for (Asset assetDO : assetRepository.findAllByAssettypename(assettypename)) { - AssetRespVO assetRespVO = new AssetRespVO(); - assetRespVO.setId(Long.valueOf(assetDO.getId())); - assetRespVO.setDataId(assetDO.getDataId()); - assetRespVO.setAssetname(assetDO.getAssetname()); - assetRespVO.setAssettype(assetDO.getAssettype()); - assetRespVO.setAssettypename(assetDO.getAssettypename()); - assetRespVO.setIsOnline(assetDO.getIsOnline()); + AssetRespVO assetRespVO = BeanUtils.toBean(assetDO, AssetRespVO.class); if (assetDO.getLastFeedbackTime() != null) { assetRespVO.setLastfeedbacktime(assetDO.getLastFeedbackTime()); } diff --git a/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/java/cn/iocoder/yudao/module/ticket/service/checkticket/CheckTicketServiceImpl.java b/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/java/cn/iocoder/yudao/module/ticket/service/checkticket/CheckTicketServiceImpl.java index a6e3b3f18..efc8ae10b 100644 --- a/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/java/cn/iocoder/yudao/module/ticket/service/checkticket/CheckTicketServiceImpl.java +++ b/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/java/cn/iocoder/yudao/module/ticket/service/checkticket/CheckTicketServiceImpl.java @@ -9,6 +9,9 @@ import cn.iocoder.yudao.module.ticket.dal.mongodb.checkticket.CheckTicketReposit import com.baomidou.dynamic.datasource.annotation.Slave; import com.mongodb.MongoException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.data.mongodb.repository.Query; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -23,13 +26,11 @@ import cn.iocoder.yudao.module.ticket.dal.mysql.checkticket.CheckTicketMapper; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.ticket.enums.ErrorCodeConstants.*; +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact; /** * 检票 Service 实现类 @@ -47,6 +48,7 @@ public class CheckTicketServiceImpl implements CheckTicketService { @Override public Long createCheckTicket(CheckTicketSaveReqVO createReqVO) { + if (isExistDataId(createReqVO.getDataId())) return 0L; // 插入 CheckTicketDO checkTicket = BeanUtils.toBean(createReqVO, CheckTicketDO.class); checkTicketMapper.insert(checkTicket); @@ -71,6 +73,10 @@ public class CheckTicketServiceImpl implements CheckTicketService { checkTicketMapper.deleteById(id); } + private Boolean isExistDataId(String dataId) { + return checkTicketMapper.selectOne("data_id", dataId) != null; + } + private void validateCheckTicketExists(Long id) { if (checkTicketMapper.selectById(id) == null) { throw exception(CHECK_TICKET_NOT_EXISTS); @@ -125,12 +131,21 @@ public class CheckTicketServiceImpl implements CheckTicketService { public String createCheckTicketByMongoDB(CheckTicketSaveReqDTO checkTicketSaveReqDTO) { CheckTicket checkTicket = BeanUtils.toBean(checkTicketSaveReqDTO, CheckTicket.class); try { - // 执行插入操作 - checkTicketRepository.insert(checkTicket); - return "添加成功"; - } catch (MongoException e){ - return "Mongo数据库写入异常"; + checkTicketRepository.findOne(Example.of(checkTicket, ExampleMatcher.matching(). + withIgnorePaths("_id").withMatcher("dataId", exact()))); + return "重复数据"; + } catch (NoSuchElementException e) { + try { + // 执行插入操作 + checkTicketRepository.insert(checkTicket); + return "添加成功"; + } catch (MongoException e2) { + return "Mongo数据库写入异常"; + } } + + + } } \ No newline at end of file