diff --git a/src/main/java/com/chint/manage/controller/ManageController.java b/src/main/java/com/chint/manage/controller/ManageController.java index 7a257cac..2e5b54dd 100644 --- a/src/main/java/com/chint/manage/controller/ManageController.java +++ b/src/main/java/com/chint/manage/controller/ManageController.java @@ -1,5 +1,6 @@ package com.chint.manage.controller; +import com.chint.domain.aggregates.user.User; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; @@ -102,10 +103,9 @@ public class ManageController { } @ApiOperation("订单下载记录查询接口") - @PostMapping("/order/downloadRecord") - public Result orderDownloadRecord(){ - BaseContext.getCurrentUser(); - return null; + @PostMapping("/order/downloadRecordQuery") + public Result orderDownloadRecordQuery(){ + return Result.Success(SUCCESS,manageService.orderDownloadRecordQuery()); } } diff --git a/src/main/java/com/chint/manage/entity/OrderDownloadRecord.java b/src/main/java/com/chint/manage/entity/OrderDownloadRecord.java index 6acd24f4..8da43be1 100644 --- a/src/main/java/com/chint/manage/entity/OrderDownloadRecord.java +++ b/src/main/java/com/chint/manage/entity/OrderDownloadRecord.java @@ -1,5 +1,6 @@ package com.chint.manage.entity; +import com.chint.manage.entity.query.OrderPageQuery; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -8,6 +9,8 @@ import org.springframework.data.annotation.Id; import org.springframework.data.relational.core.mapping.Table; import java.io.Serial; +import java.io.Serializable; +import java.time.LocalDateTime; import java.util.Date; @Data @@ -15,7 +18,7 @@ import java.util.Date; @NoArgsConstructor @AllArgsConstructor @Builder -public class OrderDownloadRecord { +public class OrderDownloadRecord implements Serializable { @Serial private static final long serialVersionUID = 1L; @@ -24,11 +27,11 @@ public class OrderDownloadRecord { //文件名 private String fileName; //查询条件 - private String queryCriteria; + private OrderPageQuery queryCriteria; //执行时间 - private Date createTime; + private LocalDateTime createTime; //过期时间 - private Date expireTime; + private LocalDateTime expireTime; //员工ID private String employeeNo; //文件路径 diff --git a/src/main/java/com/chint/manage/mapper/JdbcOrderDownloadRecordRepository.java b/src/main/java/com/chint/manage/mapper/JdbcOrderDownloadRecordRepository.java index 9727f2b0..6307c5a2 100644 --- a/src/main/java/com/chint/manage/mapper/JdbcOrderDownloadRecordRepository.java +++ b/src/main/java/com/chint/manage/mapper/JdbcOrderDownloadRecordRepository.java @@ -4,6 +4,10 @@ import com.chint.manage.entity.OrderDownloadRecord; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface JdbcOrderDownloadRecordRepository extends CrudRepository { + + List findAllByEmployeeNo(String employeeNo); } diff --git a/src/main/java/com/chint/manage/service/ManageService.java b/src/main/java/com/chint/manage/service/ManageService.java index bf840dcf..b30ff4db 100644 --- a/src/main/java/com/chint/manage/service/ManageService.java +++ b/src/main/java/com/chint/manage/service/ManageService.java @@ -1,6 +1,7 @@ package com.chint.manage.service; import com.chint.infrastructure.util.PageResult; +import com.chint.manage.entity.OrderDownloadRecord; import com.chint.manage.entity.dto.ItineraryPageDto; import com.chint.manage.entity.query.ConsumptionDetailQuery; import com.chint.manage.entity.query.ItineraryPageQuery; @@ -9,6 +10,7 @@ import com.chint.manage.entity.excel.BaseExcel; import com.chint.manage.entity.excel.OrderExceedStandardExcel; import java.io.File; +import java.util.List; /** * @@ -26,4 +28,8 @@ public interface ManageService { File standardExport(StandardQuery dto); PageResult orderPageQuery(ItineraryPageQuery dto); + + void addOrderDownloadRecord(OrderDownloadRecord orderDownloadRecord); + + List orderDownloadRecordQuery(); } diff --git a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java index 34e23d31..5b07a91f 100644 --- a/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java +++ b/src/main/java/com/chint/manage/service/impl/ManageServiceImpl.java @@ -8,7 +8,9 @@ import com.chint.domain.repository.UserRepository; import com.chint.domain.service.LegDomainService; import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository; import com.chint.infrastructure.repository.jdbc.JdbcUserRepository; +import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.PageResult; +import com.chint.manage.entity.OrderDownloadRecord; import com.chint.manage.entity.OrderExceedStandard; import com.chint.manage.entity.dto.ItineraryPageDto; import com.chint.manage.entity.excel.BaseExcel; @@ -16,6 +18,7 @@ import com.chint.manage.entity.excel.OrderExceedStandardExcel; import com.chint.manage.entity.query.ConsumptionDetailQuery; import com.chint.manage.entity.query.ItineraryPageQuery; import com.chint.manage.entity.query.StandardQuery; +import com.chint.manage.mapper.JdbcOrderDownloadRecordRepository; import com.chint.manage.mapper.JdbcOrderExceedStandardRepository; import com.chint.manage.mapper.impl.JdbcConsumptionDetailRepositoryImpl; import com.chint.manage.service.ManageService; @@ -52,6 +55,8 @@ public class ManageServiceImpl implements ManageService { private JdbcRouteRepository jdbcRouteRepository; @Autowired private JdbcUserRepository jdbcUserRepository; + @Autowired + private JdbcOrderDownloadRecordRepository jdbcOrderDownloadRecordRepository; @Override public PageResult pageConsumptionDetail(ConsumptionDetailQuery dto) { @@ -110,6 +115,21 @@ public class ManageServiceImpl implements ManageService { return PageResult.totalPageNum(page.getTotalElements(), orders); } + @Override + public void addOrderDownloadRecord(OrderDownloadRecord orderDownloadRecord) { +// User user= BaseContext.getCurrentUser(); + User user=new User(); + user.setEmployeeNo("123"); + orderDownloadRecord.setEmployeeNo(user.getEmployeeNo()); + jdbcOrderDownloadRecordRepository.save(orderDownloadRecord); + } + + @Override + public List orderDownloadRecordQuery() { + User user=BaseContext.getCurrentUser(); + return jdbcOrderDownloadRecordRepository.findAllByEmployeeNo(user.getEmployeeNo()); + } + private static List getOrderExceedStandardExcels(Page page) { List orderList = page.getContent(); List excelList = new ArrayList<>(); diff --git a/src/main/java/com/chint/manage/util/DataJdbcConfig.java b/src/main/java/com/chint/manage/util/DataJdbcConfig.java new file mode 100644 index 00000000..3c45527c --- /dev/null +++ b/src/main/java/com/chint/manage/util/DataJdbcConfig.java @@ -0,0 +1,19 @@ +package com.chint.manage.util; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jdbc.core.convert.JdbcCustomConversions; + +import java.util.Arrays; + +@Configuration +public class DataJdbcConfig { + + @Bean + public JdbcCustomConversions jdbcCustomConversions() { + return new JdbcCustomConversions(Arrays.asList( + new OrderPageQueryWriteConverter(), + new OrderPageQueryReadConverter() + )); + } +} \ No newline at end of file diff --git a/src/main/java/com/chint/manage/util/OrderPageQueryReadConverter.java b/src/main/java/com/chint/manage/util/OrderPageQueryReadConverter.java new file mode 100644 index 00000000..e7faeae9 --- /dev/null +++ b/src/main/java/com/chint/manage/util/OrderPageQueryReadConverter.java @@ -0,0 +1,22 @@ +package com.chint.manage.util; + +import com.chint.manage.entity.query.OrderPageQuery; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; + +import java.io.IOException; + +@ReadingConverter +public class OrderPageQueryReadConverter implements Converter { + private final ObjectMapper objectMapper = new ObjectMapper(); + + @Override + public OrderPageQuery convert(String source) { + try { + return objectMapper.readValue(source, OrderPageQuery.class); + } catch (IOException e) { + throw new RuntimeException("Failed to convert JSON to OrderPageQuery", e); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/chint/manage/util/OrderPageQueryWriteConverter.java b/src/main/java/com/chint/manage/util/OrderPageQueryWriteConverter.java new file mode 100644 index 00000000..8950c157 --- /dev/null +++ b/src/main/java/com/chint/manage/util/OrderPageQueryWriteConverter.java @@ -0,0 +1,24 @@ +package com.chint.manage.util; + +import com.chint.manage.entity.query.OrderPageQuery; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; +import org.springframework.data.convert.WritingConverter; + +import java.io.IOException; + +@WritingConverter +public class OrderPageQueryWriteConverter implements Converter { + private final ObjectMapper objectMapper = new ObjectMapper(); + + @Override + public String convert(OrderPageQuery source) { + try { + return objectMapper.writeValueAsString(source); + } catch (JsonProcessingException e) { + throw new RuntimeException("Failed to convert OrderPageQuery to JSON", e); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/chint/ManageTest.java b/src/test/java/com/chint/ManageTest.java index 4ab051e7..619f7963 100644 --- a/src/test/java/com/chint/ManageTest.java +++ b/src/test/java/com/chint/ManageTest.java @@ -3,11 +3,13 @@ package com.chint; import com.chint.domain.aggregates.order.OrderDetail; import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository; import com.chint.infrastructure.util.PageResult; +import com.chint.manage.entity.OrderDownloadRecord; import com.chint.manage.entity.OrderExceedStandard; import com.chint.manage.entity.dto.ItineraryPageDto; import com.chint.manage.entity.excel.BaseExcel; import com.chint.manage.entity.query.ConsumptionDetailQuery; import com.chint.manage.entity.query.ItineraryPageQuery; +import com.chint.manage.entity.query.OrderPageQuery; import com.chint.manage.mapper.JdbcOrderExceedStandardRepository; import com.chint.manage.mapper.impl.JdbcConsumptionDetailRepositoryImpl; import com.chint.manage.service.ManageService; @@ -17,6 +19,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Page; import java.math.BigDecimal; +import java.util.Date; @SpringBootTest public class ManageTest { @@ -30,6 +33,21 @@ public class ManageTest { private JdbcConsumptionDetailRepositoryImpl jdbcConsumptionDetailRepository; + @Test + void recordAdd(){ + OrderPageQuery dto=new OrderPageQuery(); + dto.setOderNo("123"); + OrderDownloadRecord downloadRecord=OrderDownloadRecord.builder() + .createTime(new Date()) + .fileUrl("url") + .status("已完成") + .expireTime(new Date()) + .fileName("文件名") + .queryCriteria(dto) + .build(); + manageService.addOrderDownloadRecord(downloadRecord); + } + @Test void pageQuery(){ ItineraryPageQuery dto=new ItineraryPageQuery();