diff --git a/home-service/src/main/java/com/cxx/home/controller/CarEventController.java b/home-service/src/main/java/com/cxx/home/controller/CarEventController.java new file mode 100644 index 0000000..0829bcb --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/controller/CarEventController.java @@ -0,0 +1,49 @@ +package com.cxx.home.controller; + +import com.cxx.common.ReadView; +import com.cxx.common.WriteView; +import com.cxx.home.dto.CarEventDto; +import com.cxx.home.service.CarEventService; +import com.cxx.home.vo.CarQueryVo; +import com.fasterxml.jackson.annotation.JsonView; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/car") +@Tag(name = "汽车事件") +public class CarEventController { + @Resource + private CarEventService carEventService; + + @Operation(summary = "新增汽车事件") + @PostMapping("") + public Boolean addCarEvent(@RequestBody @JsonView(WriteView.class) @Validated CarEventDto dto) { + return carEventService.addCarEvent(dto); + } + + @Operation(summary = "更新汽车事件") + @PutMapping("/{id}") + public Boolean updateCarEvent(@PathVariable("id") long id, + @RequestBody @JsonView(WriteView.class) @Validated CarEventDto dto) { + return carEventService.updateCarEvent(id, dto); + } + + @Operation(summary = "删除汽车事件") + @DeleteMapping("/{id}") + public Boolean deleteCarEvent(@PathVariable("id") long id) { + return carEventService.deleteCarEvent(id); + } + + @Operation(summary = "查询所有汽车事件") + @GetMapping("") + public @JsonView(ReadView.class) List queryCarEventList(CarQueryVo query) { + return carEventService.queryCarEventList(query); + } +} + \ No newline at end of file diff --git a/home-service/src/main/java/com/cxx/home/converter/CarEventConverter.java b/home-service/src/main/java/com/cxx/home/converter/CarEventConverter.java new file mode 100644 index 0000000..8bee405 --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/converter/CarEventConverter.java @@ -0,0 +1,18 @@ +package com.cxx.home.converter; + +import com.cxx.home.dto.CarEventDto; +import com.cxx.home.entity.CarEvent; +import org.mapstruct.Mapper; + +import java.util.List; + +@Mapper(componentModel = "spring") +public interface CarEventConverter { + CarEvent toEntity(CarEventDto dto); + + List toEntities(List dto); + + CarEventDto toDto(CarEvent entities); + + List toDtos(List entities); +} diff --git a/home-service/src/main/java/com/cxx/home/dao/CarEventDao.java b/home-service/src/main/java/com/cxx/home/dao/CarEventDao.java new file mode 100644 index 0000000..d973128 --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/dao/CarEventDao.java @@ -0,0 +1,13 @@ +package com.cxx.home.dao; + +import com.cxx.home.dto.CarEventDto; +import com.cxx.home.vo.CarQueryVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface CarEventDao { + List queryCarEventList(@Param("query") CarQueryVo queryVo); +} diff --git a/home-service/src/main/java/com/cxx/home/dto/CarEventDto.java b/home-service/src/main/java/com/cxx/home/dto/CarEventDto.java new file mode 100644 index 0000000..1f7de4a --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/dto/CarEventDto.java @@ -0,0 +1,53 @@ +package com.cxx.home.dto; + +import com.cxx.common.PlainView; +import com.cxx.common.ReadView; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonView; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.PositiveOrZero; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDate; + +@Getter +@Setter +@JsonView(PlainView.class) +public class CarEventDto { + @Schema(description = "id") + @JsonView(ReadView.class) + private Long id; + + @Schema(description = "名称") + @NotBlank(message = "汽车名称不能为空") + private String name; + + @Schema(description = "类型") + private String type; + + @Schema(description = "日期") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private LocalDate date; + + @Schema(description = "当前里程") + @PositiveOrZero(message = "里程必须大于等于0") + private Integer mileage; + + @Schema(description = "cost") + @PositiveOrZero(message = "花费必须大于等于0") + private Integer cost; + + @Schema(description = "地点") + private String location; + + @Schema(description = "描述") + private String description; + + @Schema(description = "图片路径") + private String imageUrl; + + @Schema(description = "备注") + private String remark; +} diff --git a/home-service/src/main/java/com/cxx/home/entity/CarEvent.java b/home-service/src/main/java/com/cxx/home/entity/CarEvent.java new file mode 100644 index 0000000..a45aeda --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/entity/CarEvent.java @@ -0,0 +1,41 @@ +package com.cxx.home.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cxx.framework.data.AbstractEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDate; + +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("car_event") +public class CarEvent extends AbstractEntity { + @TableField(value = "name") + private String name; + + @TableField("type") + private String type; + + @TableField("date") + private LocalDate date; + + @TableField("mileage") + private Integer mileage; + + @TableField("cost") + private Integer cost; + + @TableField("location") + private String location; + + @TableField("description") + private String description; + + @TableField("image_url") + private String imageUrl; + + @TableField("remark") + private String remark; +} diff --git a/home-service/src/main/java/com/cxx/home/mapper/CarEventMapper.java b/home-service/src/main/java/com/cxx/home/mapper/CarEventMapper.java new file mode 100644 index 0000000..7d3db05 --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/mapper/CarEventMapper.java @@ -0,0 +1,9 @@ +package com.cxx.home.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.cxx.home.entity.CarEvent; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface CarEventMapper extends BaseMapper { +} \ No newline at end of file diff --git a/home-service/src/main/java/com/cxx/home/service/CarEventService.java b/home-service/src/main/java/com/cxx/home/service/CarEventService.java new file mode 100644 index 0000000..5e37f91 --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/service/CarEventService.java @@ -0,0 +1,17 @@ +package com.cxx.home.service; + + +import com.cxx.home.dto.CarEventDto; +import com.cxx.home.vo.CarQueryVo; + +import java.util.List; + +public interface CarEventService { + Boolean addCarEvent(CarEventDto dto); + + Boolean updateCarEvent(Long id, CarEventDto dto); + + Boolean deleteCarEvent(Long id); + + List queryCarEventList(CarQueryVo query); +} diff --git a/home-service/src/main/java/com/cxx/home/service/ProductService.java b/home-service/src/main/java/com/cxx/home/service/ProductService.java index eca3315..de0c86e 100644 --- a/home-service/src/main/java/com/cxx/home/service/ProductService.java +++ b/home-service/src/main/java/com/cxx/home/service/ProductService.java @@ -7,9 +7,9 @@ import com.cxx.home.vo.ProductQueryVo; import java.util.List; public interface ProductService { - Boolean addProduct(ProductDto productDto); + Boolean addProduct(ProductDto dto); - Boolean updateProduct(Long id, ProductDto productDto); + Boolean updateProduct(Long id, ProductDto dto); Boolean deleteProduct(Long id); diff --git a/home-service/src/main/java/com/cxx/home/service/impl/CarEventServiceImpl.java b/home-service/src/main/java/com/cxx/home/service/impl/CarEventServiceImpl.java new file mode 100644 index 0000000..fb6dab4 --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/service/impl/CarEventServiceImpl.java @@ -0,0 +1,56 @@ +package com.cxx.home.service.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.cxx.home.converter.CarEventConverter; +import com.cxx.home.dao.CarEventDao; +import com.cxx.home.dto.CarEventDto; +import com.cxx.home.entity.CarEvent; +import com.cxx.home.mapper.CarEventMapper; +import com.cxx.home.service.CarEventService; +import com.cxx.home.vo.CarQueryVo; +import jakarta.annotation.Resource; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +public class CarEventServiceImpl implements CarEventService { + @Resource + private CarEventMapper carEventMapper; + + @Resource + private CarEventConverter carEventConverter; + + @Resource + private CarEventDao carEventDao; + + @Override + @Transactional + public Boolean addCarEvent(CarEventDto dto) { + CarEvent carEvent = new CarEvent(); + BeanUtils.copyProperties(dto, carEvent); + return carEventMapper.insert(carEvent) == 1; + } + + @Override + @Transactional + public Boolean updateCarEvent(Long id, CarEventDto dto) { + CarEvent carEvent = new CarEvent(); + BeanUtils.copyProperties(dto, carEvent); + carEvent.setId(id); + return carEventMapper.updateById(carEvent) == 1; + } + + @Override + @Transactional + public Boolean deleteCarEvent(Long id) { + return carEventMapper.deleteById(id) == 1; + } + + @Override + public List queryCarEventList(CarQueryVo query) { + return carEventDao.queryCarEventList(query); + } +} diff --git a/home-service/src/main/java/com/cxx/home/vo/AwardQueryVo.java b/home-service/src/main/java/com/cxx/home/vo/AwardQueryVo.java index 4fe10fb..b5eab5a 100644 --- a/home-service/src/main/java/com/cxx/home/vo/AwardQueryVo.java +++ b/home-service/src/main/java/com/cxx/home/vo/AwardQueryVo.java @@ -1,4 +1,3 @@ - package com.cxx.home.vo; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/home-service/src/main/java/com/cxx/home/vo/CarQueryVo.java b/home-service/src/main/java/com/cxx/home/vo/CarQueryVo.java new file mode 100644 index 0000000..0ad82a8 --- /dev/null +++ b/home-service/src/main/java/com/cxx/home/vo/CarQueryVo.java @@ -0,0 +1,12 @@ +package com.cxx.home.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CarQueryVo { + @Schema(description = "事件类别") + private String type; +} \ No newline at end of file diff --git a/home-service/src/main/java/com/cxx/home/vo/FoodQueryVo.java b/home-service/src/main/java/com/cxx/home/vo/FoodQueryVo.java index e4f6bd8..cca351b 100644 --- a/home-service/src/main/java/com/cxx/home/vo/FoodQueryVo.java +++ b/home-service/src/main/java/com/cxx/home/vo/FoodQueryVo.java @@ -1,4 +1,3 @@ - package com.cxx.home.vo; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/home-service/src/main/java/com/cxx/home/vo/PasswordQueryVo.java b/home-service/src/main/java/com/cxx/home/vo/PasswordQueryVo.java index 1d10ee5..816c4c4 100644 --- a/home-service/src/main/java/com/cxx/home/vo/PasswordQueryVo.java +++ b/home-service/src/main/java/com/cxx/home/vo/PasswordQueryVo.java @@ -1,4 +1,3 @@ - package com.cxx.home.vo; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/home-service/src/main/java/com/cxx/home/vo/ProductQueryVo.java b/home-service/src/main/java/com/cxx/home/vo/ProductQueryVo.java index aa88cf8..4cc92a8 100644 --- a/home-service/src/main/java/com/cxx/home/vo/ProductQueryVo.java +++ b/home-service/src/main/java/com/cxx/home/vo/ProductQueryVo.java @@ -1,4 +1,3 @@ - package com.cxx.home.vo; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/home-service/src/main/java/com/cxx/home/vo/TravelQueryVo.java b/home-service/src/main/java/com/cxx/home/vo/TravelQueryVo.java index f168739..e2c0da7 100644 --- a/home-service/src/main/java/com/cxx/home/vo/TravelQueryVo.java +++ b/home-service/src/main/java/com/cxx/home/vo/TravelQueryVo.java @@ -1,4 +1,3 @@ - package com.cxx.home.vo; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/home-service/src/main/resources/mapper/CarEventMapper.xml b/home-service/src/main/resources/mapper/CarEventMapper.xml new file mode 100644 index 0000000..f1ef52a --- /dev/null +++ b/home-service/src/main/resources/mapper/CarEventMapper.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/home-service/src/main/resources/mapper/ProductMapper.xml b/home-service/src/main/resources/mapper/ProductMapper.xml index fdb4fc2..3777c64 100644 --- a/home-service/src/main/resources/mapper/ProductMapper.xml +++ b/home-service/src/main/resources/mapper/ProductMapper.xml @@ -3,15 +3,15 @@