票务api插入到mongodb中

This commit is contained in:
XinWei 2024-07-23 17:34:31 +08:00
parent 145b7e7a30
commit 1b7f9b73d7
14 changed files with 129 additions and 3 deletions

View File

@ -18,8 +18,6 @@ public class SecurityConfiguration {
@Override @Override
public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
// TODO 暂时放行所有用于测试
registry.antMatchers("/**").permitAll();
// Swagger 接口文档 // Swagger 接口文档
registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据 registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据
.antMatchers("/swagger-ui.html").permitAll(); // Swagger UI .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI

View File

@ -31,4 +31,7 @@ public interface TicketCheckTicketApi {
@PostMapping(PREFIX + "/create") @PostMapping(PREFIX + "/create")
@Operation(summary = "插入检票记录") @Operation(summary = "插入检票记录")
public CommonResult<Long> createCheckTicket(@Valid @RequestBody CheckTicketSaveReqDTO checkTicketSaveReqDTO); public CommonResult<Long> createCheckTicket(@Valid @RequestBody CheckTicketSaveReqDTO checkTicketSaveReqDTO);
@PostMapping(PREFIX + "/createByMongoDB")
@Operation(summary = "插入MongoDB检票记录")
public CommonResult<String> createCheckTicketByMongoDB(@RequestBody CheckTicketSaveReqDTO checkTicketSaveReqDTO);
} }

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.ticket.api.saledata; package cn.iocoder.yudao.module.ticket.api.saledata;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.ticket.api.checkticket.dto.CheckTicketSaveReqDTO;
import cn.iocoder.yudao.module.ticket.api.saledata.dto.SaleDataSaveReqDTO; import cn.iocoder.yudao.module.ticket.api.saledata.dto.SaleDataSaveReqDTO;
import cn.iocoder.yudao.module.ticket.enums.ApiConstants; import cn.iocoder.yudao.module.ticket.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -68,4 +69,7 @@ public interface TicketSaleDataApi {
@PostMapping(PREFIX + "/create") @PostMapping(PREFIX + "/create")
@Operation(summary = "插入售票记录") @Operation(summary = "插入售票记录")
public CommonResult<Long> createSaleData(@Valid @RequestBody SaleDataSaveReqDTO saleDataSaveReqDTO); public CommonResult<Long> createSaleData(@Valid @RequestBody SaleDataSaveReqDTO saleDataSaveReqDTO);
@PostMapping(PREFIX + "/createByMongoDB")
@Operation(summary = "插入MongoDB检票记录")
public CommonResult<String> createSaleDataByMongoDB(@RequestBody SaleDataSaveReqDTO saleDataSaveReqDTO);
} }

View File

@ -26,6 +26,11 @@
<artifactId>ludu-module-ticketing-api</artifactId> <artifactId>ludu-module-ticketing-api</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<!-- mongodb -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- Spring Cloud 基础 --> <!-- Spring Cloud 基础 -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>

View File

@ -36,4 +36,12 @@ public class TicketCheckTicketApiImpl implements TicketCheckTicketApi{
public CommonResult<Long> createCheckTicket(CheckTicketSaveReqDTO checkTicketSaveReqDTO) { public CommonResult<Long> createCheckTicket(CheckTicketSaveReqDTO checkTicketSaveReqDTO) {
return success(checkTicketService.createCheckTicket(BeanUtils.toBean(checkTicketSaveReqDTO, CheckTicketSaveReqVO.class))); return success(checkTicketService.createCheckTicket(BeanUtils.toBean(checkTicketSaveReqDTO, CheckTicketSaveReqVO.class)));
} }
@Override
public CommonResult<String> createCheckTicketByMongoDB(CheckTicketSaveReqDTO checkTicketSaveReqDTO) {
return success(checkTicketService.createCheckTicketByMongoDB(checkTicketSaveReqDTO));
}
} }

View File

@ -101,4 +101,9 @@ public class TicketSaleDataApiImpl implements TicketSaleDataApi{
public CommonResult<Long> createSaleData(@Valid @RequestBody SaleDataSaveReqDTO saleDataSaveReqDTO) { public CommonResult<Long> createSaleData(@Valid @RequestBody SaleDataSaveReqDTO saleDataSaveReqDTO) {
return success(saleDataService.createSaleData(BeanUtils.toBean(saleDataSaveReqDTO, SaleDataSaveReqVO.class))); return success(saleDataService.createSaleData(BeanUtils.toBean(saleDataSaveReqDTO, SaleDataSaveReqVO.class)));
} }
@Override
public CommonResult<String> createSaleDataByMongoDB(SaleDataSaveReqDTO saleDataSaveReqDTO) {
return success(saleDataService.createSaleDataByMongoDB(saleDataSaveReqDTO));
}
} }

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.ticket.dal.dataobject.checkticket;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;
@Document("checkticket")
@Data
public class CheckTicket {
private String id;
private String dataId;
private String checkstation;
private String checkstationname;
private String ticket;
private String checkticketdate;
private String checktickettime;
private Integer personcount;
private String sdshipping;
private String salepropetyvaluename;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.ticket.dal.dataobject.saledata;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;
import java.math.BigDecimal;
@Document("saledata")
@Data
public class SaleData {
private String id;
private String dataId;
private String sdno;
private String transactiontypeno;
private String sddate;
private String sdtime;
private BigDecimal amount;
private Integer quantity;
private String certificatetype;
private String certificateno;
private String itemtype;
private String itemtypename;
private String item;
private String itemname;
private String productbatchno;
private String salepropetyvaluename;
}

View File

@ -0,0 +1,10 @@
package cn.iocoder.yudao.module.ticket.dal.mongodb.checkticket;
import cn.iocoder.yudao.module.ticket.dal.dataobject.checkticket.CheckTicket;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface CheckTicketRepository extends MongoRepository<CheckTicket,String> {
}

View File

@ -0,0 +1,11 @@
package cn.iocoder.yudao.module.ticket.dal.mongodb.saledata;
import cn.iocoder.yudao.module.ticket.dal.dataobject.saledata.SaleData;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface SaleDataRepository extends MongoRepository<SaleData,String> {
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.ticket.service.checkticket;
import javax.validation.*; import javax.validation.*;
import cn.iocoder.yudao.module.ticket.api.checkticket.dto.CheckTicketSaveReqDTO;
import cn.iocoder.yudao.module.ticket.controller.admin.checkticket.vo.vo.CheckTicketPageReqVO; import cn.iocoder.yudao.module.ticket.controller.admin.checkticket.vo.vo.CheckTicketPageReqVO;
import cn.iocoder.yudao.module.ticket.controller.admin.checkticket.vo.vo.CheckTicketSaveReqVO; import cn.iocoder.yudao.module.ticket.controller.admin.checkticket.vo.vo.CheckTicketSaveReqVO;
import cn.iocoder.yudao.module.ticket.dal.dataobject.checkticket.CheckTicketDO; import cn.iocoder.yudao.module.ticket.dal.dataobject.checkticket.CheckTicketDO;
@ -70,4 +71,6 @@ public interface CheckTicketService {
* @return long 检票人数 * @return long 检票人数
*/ */
public long checkTicketTotal(String day); public long checkTicketTotal(String day);
String createCheckTicketByMongoDB(CheckTicketSaveReqDTO checkTicketSaveReqDTO);
} }

View File

@ -1,8 +1,12 @@
package cn.iocoder.yudao.module.ticket.service.checkticket; package cn.iocoder.yudao.module.ticket.service.checkticket;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ticket.api.checkticket.dto.CheckTicketSaveReqDTO;
import cn.iocoder.yudao.module.ticket.controller.admin.checkticket.vo.vo.CheckTicketPageReqVO; import cn.iocoder.yudao.module.ticket.controller.admin.checkticket.vo.vo.CheckTicketPageReqVO;
import cn.iocoder.yudao.module.ticket.controller.admin.checkticket.vo.vo.CheckTicketSaveReqVO; import cn.iocoder.yudao.module.ticket.controller.admin.checkticket.vo.vo.CheckTicketSaveReqVO;
import cn.iocoder.yudao.module.ticket.dal.dataobject.checkticket.CheckTicket;
import cn.iocoder.yudao.module.ticket.dal.mongodb.checkticket.CheckTicketRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -36,6 +40,8 @@ public class CheckTicketServiceImpl implements CheckTicketService {
@Resource @Resource
private CheckTicketMapper checkTicketMapper; private CheckTicketMapper checkTicketMapper;
@Resource
private CheckTicketRepository checkTicketRepository;
@Override @Override
public Long createCheckTicket(CheckTicketSaveReqVO createReqVO) { public Long createCheckTicket(CheckTicketSaveReqVO createReqVO) {
@ -109,4 +115,14 @@ public class CheckTicketServiceImpl implements CheckTicketService {
return checkTicketMapper.selectCount(wrapperX); return checkTicketMapper.selectCount(wrapperX);
} }
@Override
public String createCheckTicketByMongoDB(CheckTicketSaveReqDTO checkTicketSaveReqDTO) {
CheckTicket checkTicket = BeanUtils.toBean(checkTicketSaveReqDTO, CheckTicket.class);
// TODO 插入失败会自动抛出异常需要对异常进行处理
// DuplicateKeyException当插入的文档违反唯一索引约束时会抛出此异常
// MongoWriteException在写入操作中发生的其他错误例如文档格式不正确或数据库连接问题
checkTicketRepository.insert(checkTicket);
return "添加成功";
}
} }

View File

@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.ticket.service.saledata;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import javax.validation.*; import javax.validation.*;
import cn.iocoder.yudao.module.ticket.api.saledata.dto.SaleDataSaveReqDTO;
import cn.iocoder.yudao.module.ticket.controller.admin.saledata.vo.*; import cn.iocoder.yudao.module.ticket.controller.admin.saledata.vo.*;
import cn.iocoder.yudao.module.ticket.dal.dataobject.saledata.SaleDataDO; import cn.iocoder.yudao.module.ticket.dal.dataobject.saledata.SaleDataDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -130,4 +132,6 @@ public interface SaleDataService {
* @return java.math.BigDecimal * @return java.math.BigDecimal
*/ */
BigDecimal findyearJun(List<SaleDataDO> list); BigDecimal findyearJun(List<SaleDataDO> list);
String createSaleDataByMongoDB(SaleDataSaveReqDTO saleDataSaveReqDTO);
} }

View File

@ -2,7 +2,11 @@ package cn.iocoder.yudao.module.ticket.service.saledata;
import cn.iocoder.yudao.framework.common.util.ticket.IdCardUtil; import cn.iocoder.yudao.framework.common.util.ticket.IdCardUtil;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ticket.api.saledata.dto.SaleDataSaveReqDTO;
import cn.iocoder.yudao.module.ticket.dal.dataobject.saledata.SaleData;
import cn.iocoder.yudao.module.ticket.dal.mongodb.saledata.SaleDataRepository;
import kotlin.jvm.internal.Lambda; import kotlin.jvm.internal.Lambda;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -33,7 +37,8 @@ import static cn.iocoder.yudao.module.ticket.enums.ErrorCodeConstants.*;
@Service @Service
@Validated @Validated
public class SaleDataServiceImpl implements SaleDataService { public class SaleDataServiceImpl implements SaleDataService {
@Resource
private SaleDataRepository saleDataRepository;
@Resource @Resource
private SaleDataMapper saleDataMapper; private SaleDataMapper saleDataMapper;
@ -427,5 +432,12 @@ public class SaleDataServiceImpl implements SaleDataService {
return total; return total;
} }
@Override
public String createSaleDataByMongoDB(SaleDataSaveReqDTO saleDataSaveReqDTO) {
SaleData saleData = BeanUtils.toBean(saleDataSaveReqDTO, SaleData.class);
saleDataRepository.insert(saleData);
return "添加成功";
}
} }