feat:增加汽车事件模块
This commit is contained in:
@@ -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<CarEventDto> queryCarEventList(CarQueryVo query) {
|
||||
return carEventService.queryCarEventList(query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<CarEvent> toEntities(List<CarEventDto> dto);
|
||||
|
||||
CarEventDto toDto(CarEvent entities);
|
||||
|
||||
List<CarEventDto> toDtos(List<CarEvent> entities);
|
||||
}
|
||||
13
home-service/src/main/java/com/cxx/home/dao/CarEventDao.java
Normal file
13
home-service/src/main/java/com/cxx/home/dao/CarEventDao.java
Normal file
@@ -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<CarEventDto> queryCarEventList(@Param("query") CarQueryVo queryVo);
|
||||
}
|
||||
53
home-service/src/main/java/com/cxx/home/dto/CarEventDto.java
Normal file
53
home-service/src/main/java/com/cxx/home/dto/CarEventDto.java
Normal file
@@ -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;
|
||||
}
|
||||
41
home-service/src/main/java/com/cxx/home/entity/CarEvent.java
Normal file
41
home-service/src/main/java/com/cxx/home/entity/CarEvent.java
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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<CarEvent> {
|
||||
}
|
||||
@@ -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<CarEventDto> queryCarEventList(CarQueryVo query);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<CarEventDto> queryCarEventList(CarQueryVo query) {
|
||||
return carEventDao.queryCarEventList(query);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.cxx.home.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
12
home-service/src/main/java/com/cxx/home/vo/CarQueryVo.java
Normal file
12
home-service/src/main/java/com/cxx/home/vo/CarQueryVo.java
Normal file
@@ -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;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.cxx.home.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.cxx.home.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.cxx.home.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.cxx.home.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
Reference in New Issue
Block a user