提交 306331f2 作者: 谭志磊

style: 车辆字典类型来访信息注释、代码修改,excel工具类代码格式优化

上级 038eaa6b
...@@ -27,7 +27,7 @@ public class CarParam { ...@@ -27,7 +27,7 @@ public class CarParam {
@Pattern(regexp = RegEx.CARNUM, message = "车牌号码格式不正确") @Pattern(regexp = RegEx.CARNUM, message = "车牌号码格式不正确")
String carNum; String carNum;
@ApiModelProperty(value = "车辆类型", example = "轿车") @ApiModelProperty(value = "车辆类型", example = "1")
String carType; String carType;
@ApiModelProperty(value = "司机名称", example = "张三", required = true) @ApiModelProperty(value = "司机名称", example = "张三", required = true)
......
...@@ -71,7 +71,7 @@ public interface CarService { ...@@ -71,7 +71,7 @@ public interface CarService {
* @param carParam CarParam * @param carParam CarParam
* @return 车辆来访信息分页数据 * @return 车辆来访信息分页数据
*/ */
Result<PageVo<CarVo>> PageCarInfo(CarQueryParam carParam, PageParam param); Result<PageVo<CarVo>> pageCarInfo(CarQueryParam carParam, PageParam param);
/** /**
* 导出excel * 导出excel
......
...@@ -52,7 +52,7 @@ public class CarServiceImpl implements CarService { ...@@ -52,7 +52,7 @@ public class CarServiceImpl implements CarService {
} }
Car car = Car Car car = Car
.builder() .builder()
.labelCardStatus("未发卡") .labelCardStatus("1")
.carNum(carParam.getCarNum()) .carNum(carParam.getCarNum())
.carType(carParam.getCarType()) .carType(carParam.getCarType())
.driverMobile(carParam.getDriverMobile()) .driverMobile(carParam.getDriverMobile())
...@@ -101,7 +101,7 @@ public class CarServiceImpl implements CarService { ...@@ -101,7 +101,7 @@ public class CarServiceImpl implements CarService {
return Result.no(Status.NOT_FOUND); return Result.no(Status.NOT_FOUND);
} }
Car car = optional.get(); Car car = optional.get();
car.setLabelCardStatus("已收卡"); car.setLabelCardStatus("3");
car.setCardRecTime(LocalDateTime.now()); car.setCardRecTime(LocalDateTime.now());
Car carReuslt = carRepository.saveAndFlush(car); Car carReuslt = carRepository.saveAndFlush(car);
return Result.ok(carReuslt.getId()); return Result.ok(carReuslt.getId());
...@@ -114,7 +114,7 @@ public class CarServiceImpl implements CarService { ...@@ -114,7 +114,7 @@ public class CarServiceImpl implements CarService {
return Result.no(Status.NOT_FOUND); return Result.no(Status.NOT_FOUND);
} }
Car car = optional.get(); Car car = optional.get();
car.setLabelCardStatus("使用中"); car.setLabelCardStatus("2");
car.setCardSendTime(LocalDateTime.now()); car.setCardSendTime(LocalDateTime.now());
car.setLabelCard(labelCard); car.setLabelCard(labelCard);
Car carReuslt = carRepository.saveAndFlush(car); Car carReuslt = carRepository.saveAndFlush(car);
...@@ -130,7 +130,7 @@ public class CarServiceImpl implements CarService { ...@@ -130,7 +130,7 @@ public class CarServiceImpl implements CarService {
//正在使用中的信息无法删除 //正在使用中的信息无法删除
Car entity = optional.get(); Car entity = optional.get();
if (entity.getLabelCardStatus().equals("使用中")) { if ("使用中".equals(entity.getLabelCardStatus())) {
return Result.no(Status.BAD_REQUEST, "标签卡使用中,信息无法删除"); return Result.no(Status.BAD_REQUEST, "标签卡使用中,信息无法删除");
} }
carRepository.delete(entity); carRepository.delete(entity);
...@@ -151,7 +151,7 @@ public class CarServiceImpl implements CarService { ...@@ -151,7 +151,7 @@ public class CarServiceImpl implements CarService {
} }
@Override @Override
public Result<PageVo<CarVo>> PageCarInfo(CarQueryParam carParam, PageParam param) { public Result<PageVo<CarVo>> pageCarInfo(CarQueryParam carParam, PageParam param) {
Page<Car> all = carRepository.findAll(condition(carParam), PageParam.toPageable(param)); Page<Car> all = carRepository.findAll(condition(carParam), PageParam.toPageable(param));
List<CarVo> data = all List<CarVo> data = all
.get() .get()
......
...@@ -36,8 +36,9 @@ public interface DictService { ...@@ -36,8 +36,9 @@ public interface DictService {
/** /**
* 从缓存中获取字典 * 从缓存中获取字典
* @param dictType *
* @return * @param dictType 字典类型
* @return 字典数据集合
*/ */
Result<ArrayList<Dict>> selectDict(String dictType); Result<ArrayList<Dict>> selectDict(String dictType);
...@@ -84,7 +85,7 @@ public interface DictService { ...@@ -84,7 +85,7 @@ public interface DictService {
/** /**
* 是否该类型字典已有该字典值 * 是否该类型字典已有该字典值
* *
* @param dictType String * @param dictType String
* @param dictValue String * @param dictValue String
* @return 是否存在 * @return 是否存在
*/ */
......
/* (C) 2022 YiRing, Inc. */ /* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.dict; package com.yiring.app.service.dict;
import com.yiring.app.param.dict.DictTypeParam;
import com.yiring.app.param.dict.DictTypeQueryParam;
import com.yiring.common.core.Result;
import com.yiring.common.dict.DictType;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
/** /**
* @author tzl * @author tzl
* 2022/4/14 14:10 * 2022/4/14 14:10
*/ */
public interface DictTypeService { public interface DictTypeService {
/** // /**
* 根据条件分页查询字典类型 // * 根据条件分页查询字典类型
* // *
* @param dictTypeQueryParam DictTypeQueryParam // * @param dictTypeQueryParam DictTypeQueryParam
* @return 字典类型分页信息 // * @return 字典类型分页信息
*/ // */
Result<PageVo<DictType>> pageDictTypeInfo(DictTypeQueryParam dictTypeQueryParam, PageParam param); // Result<PageVo<DictType>> pageDictTypeInfo(DictTypeQueryParam dictTypeQueryParam, PageParam param);
//
Result<DictType> getDictTypeInfo(Long id); // Result<DictType> getDictTypeInfo(Long id);
//
Result<String> delecteById(Long id); // Result<String> delecteById(Long id);
//
Result<String> saveDictTypeInfo(DictTypeParam dictTypeParam); // Result<String> saveDictTypeInfo(DictTypeParam dictTypeParam);
//
Result<String> updateDictTypeInfo(DictTypeParam dictTypeParam, IdParam idParam); // Result<String> updateDictTypeInfo(DictTypeParam dictTypeParam, IdParam idParam);
//
boolean has(String param); // boolean has(String param);
} }
/* (C) 2022 YiRing, Inc. */ /* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.dict.impl; package com.yiring.app.service.dict.impl;
import com.yiring.app.param.dict.DictTypeParam;
import com.yiring.app.param.dict.DictTypeQueryParam;
import com.yiring.app.service.dict.DictTypeService; import com.yiring.app.service.dict.DictTypeService;
import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import com.yiring.common.dict.Dict;
import com.yiring.common.dict.DictRepository;
import com.yiring.common.dict.DictType;
import com.yiring.common.dict.DictTypeRepository;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.util.DictUtils;
import com.yiring.common.util.StrUtils;
import com.yiring.common.vo.PageVo;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
...@@ -34,110 +13,110 @@ import org.springframework.stereotype.Service; ...@@ -34,110 +13,110 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
public class DictTypeServiceImpl implements DictTypeService { public class DictTypeServiceImpl implements DictTypeService {
//
@Resource // @Resource
DictTypeRepository dictTypeRepository; // DictTypeRepository dictTypeRepository;
//
@Resource // @Resource
DictRepository dictRepository; // DictRepository dictRepository;
//
@Override // @Override
public Result<PageVo<DictType>> pageDictTypeInfo(DictTypeQueryParam dictTypeQueryParam, PageParam param) { // public Result<PageVo<DictType>> pageDictTypeInfo(DictTypeQueryParam dictTypeQueryParam, PageParam param) {
Page<DictType> all = dictTypeRepository.findAll(condition(dictTypeQueryParam), PageParam.toPageable(param)); // Page<DictType> all = dictTypeRepository.findAll(condition(dictTypeQueryParam), PageParam.toPageable(param));
List<DictType> data = all // List<DictType> data = all
.get() // .get()
.map(car -> { // .map(car -> {
DictType vo = new DictType(); // DictType vo = new DictType();
BeanUtils.copyProperties(car, vo); // BeanUtils.copyProperties(car, vo);
return vo; // return vo;
}) // })
.collect(Collectors.toList()); // .collect(Collectors.toList());
PageVo<DictType> vo = PageVo.build(data, all.getTotalElements()); // PageVo<DictType> vo = PageVo.build(data, all.getTotalElements());
return Result.ok(vo); // return Result.ok(vo);
} // }
//
@Override // @Override
public Result<DictType> getDictTypeInfo(Long id) { // public Result<DictType> getDictTypeInfo(Long id) {
return Result.ok(dictTypeRepository.getById(id)); // return Result.ok(dictTypeRepository.getById(id));
} // }
//
@Override // @Override
public Result<String> delecteById(Long id) { // public Result<String> delecteById(Long id) {
Optional<DictType> optional = dictTypeRepository.findById(id); // Optional<DictType> optional = dictTypeRepository.findById(id);
if (optional.isEmpty()) { // if (optional.isEmpty()) {
return Result.no(Status.NOT_FOUND); // return Result.no(Status.NOT_FOUND);
} // }
DictType entity = optional.get(); // DictType entity = optional.get();
List<Dict> byDictType1 = dictRepository.findByDictType(entity.getDictType()); // List<Dict> byDictType1 = dictRepository.findByDictType(entity.getDictType());
if (byDictType1.size() > 0) { // if (byDictType1.size() > 0) {
return Result.no(Status.BAD_REQUEST, "该类型下有字典数据,无法删除"); // return Result.no(Status.BAD_REQUEST, "该类型下有字典数据,无法删除");
} // }
//
dictTypeRepository.delete(entity); // dictTypeRepository.delete(entity);
//移除该类型缓存 // //移除该类型缓存
DictUtils.removeDictCache(entity.getDictType()); // DictUtils.removeDictCache(entity.getDictType());
return Result.ok(); // return Result.ok();
} // }
//
@Override // @Override
public Result<String> saveDictTypeInfo(DictTypeParam dictTypeParam) { // public Result<String> saveDictTypeInfo(DictTypeParam dictTypeParam) {
if (has(dictTypeParam.getDictType())) { // if (has(dictTypeParam.getDictType())) {
return Result.no(Status.BAD_REQUEST, "字典类型已存在"); // return Result.no(Status.BAD_REQUEST, "字典类型已存在");
} // }
DictType dictType = DictType.builder().createTime(LocalDateTime.now()).build(); // DictType dictType = DictType.builder().createTime(LocalDateTime.now()).build();
BeanUtils.copyProperties(dictTypeParam, dictType); // BeanUtils.copyProperties(dictTypeParam, dictType);
dictTypeRepository.saveAndFlush(dictType); // dictTypeRepository.saveAndFlush(dictType);
//添加空缓存 // //添加空缓存
DictUtils.setDictCache(dictType.getDictType(), null); // DictUtils.setDictCache(dictType.getDictType(), null);
return Result.ok(); // return Result.ok();
} // }
//
@Override // @Override
public Result<String> updateDictTypeInfo(DictTypeParam dictTypeParam, IdParam idParam) { // public Result<String> updateDictTypeInfo(DictTypeParam dictTypeParam, IdParam idParam) {
Optional<DictType> optional = dictTypeRepository.findById(idParam.getId()); // Optional<DictType> optional = dictTypeRepository.findById(idParam.getId());
if (optional.isEmpty()) { // if (optional.isEmpty()) {
return Result.no(Status.NOT_FOUND); // return Result.no(Status.NOT_FOUND);
} // }
DictType dictType = optional.get(); // DictType dictType = optional.get();
if (!dictType.getDictType().equals(dictTypeParam.getDictType())) { // if (!dictType.getDictType().equals(dictTypeParam.getDictType())) {
//在修改字典类型时 // //在修改字典类型时
if (has(dictTypeParam.getDictType())) { // if (has(dictTypeParam.getDictType())) {
return Result.no(Status.BAD_REQUEST, "字典类型已存在"); // return Result.no(Status.BAD_REQUEST, "字典类型已存在");
} // }
//将该字典类型下的字典数据一并修改 // //将该字典类型下的字典数据一并修改
dictRepository.updateDictType(dictTypeParam.getDictType(), dictType.getDictType()); // dictRepository.updateDictType(dictTypeParam.getDictType(), dictType.getDictType());
//移除之前的缓存 // //移除之前的缓存
DictUtils.removeDictCache(dictType.getDictType()); // DictUtils.removeDictCache(dictType.getDictType());
} // }
BeanUtils.copyProperties(dictTypeParam, dictType); // BeanUtils.copyProperties(dictTypeParam, dictType);
dictTypeRepository.saveAndFlush(dictType); // dictTypeRepository.saveAndFlush(dictType);
//查询该字典类型下的字典值数据 // //查询该字典类型下的字典值数据
List<Dict> byDictType = dictRepository.findByDictType(dictType.getDictType()); // List<Dict> byDictType = dictRepository.findByDictType(dictType.getDictType());
//添加新缓存 // //添加新缓存
DictUtils.setDictCache(dictType.getDictType(), byDictType); // DictUtils.setDictCache(dictType.getDictType(), byDictType);
return Result.ok(); // return Result.ok();
} // }
//
@Override // @Override
public boolean has(String param) { // public boolean has(String param) {
DictType dictType = DictType.builder().dictType(param).build(); // DictType dictType = DictType.builder().dictType(param).build();
return dictTypeRepository.count(Example.of(dictType)) > 0; // return dictTypeRepository.count(Example.of(dictType)) > 0;
} // }
//
public Specification<DictType> condition(DictTypeQueryParam dictTypeQueryParam) { // public Specification<DictType> condition(DictTypeQueryParam dictTypeQueryParam) {
return (root, query, criteriaBuilder) -> { // return (root, query, criteriaBuilder) -> {
List<Predicate> list = new ArrayList<>(); // List<Predicate> list = new ArrayList<>();
if (StrUtils.isNotBlank(dictTypeQueryParam.getDictName())) { // if (StrUtils.isNotBlank(dictTypeQueryParam.getDictName())) {
list.add( // list.add(
criteriaBuilder.like( // criteriaBuilder.like(
root.get("dictType").as(String.class), // root.get("dictType").as(String.class),
"%" + dictTypeQueryParam.getDictName() + "%" // "%" + dictTypeQueryParam.getDictName() + "%"
) // )
); // );
} // }
Predicate[] predicates = new Predicate[list.size()]; // Predicate[] predicates = new Predicate[list.size()];
query.where(list.toArray(predicates)); // query.where(list.toArray(predicates));
return criteriaBuilder.and(list.toArray(predicates)); // return criteriaBuilder.and(list.toArray(predicates));
}; // };
} // }
} }
...@@ -79,9 +79,9 @@ public class CarController { ...@@ -79,9 +79,9 @@ public class CarController {
} }
@ApiOperation(value = "查看车辆来访信息(分页)") @ApiOperation(value = "查看车辆来访信息(分页)")
@GetMapping("PageCarInfo") @GetMapping("pageCarInfo")
public Result<PageVo<CarVo>> PageCarInfo(@Valid CarQueryParam carParam, @Valid PageParam param) { public Result<PageVo<CarVo>> pageCarInfo(@Valid CarQueryParam carParam, @Valid PageParam param) {
return carService.PageCarInfo(carParam, param); return carService.pageCarInfo(carParam, param);
} }
@ApiOperation(value = "导出车辆来访信息") @ApiOperation(value = "导出车辆来访信息")
......
...@@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
/** /**
* 字典数据控制器 * 字典数据控制器
*
* @author tzl * @author tzl
* 2022/4/13 17:10 * 2022/4/13 17:10
*/ */
......
/* (C) 2022 YiRing, Inc. */ /* (C) 2022 YiRing, Inc. */
package com.yiring.app.web.dict; package com.yiring.app.web.dict;
import com.yiring.app.param.dict.DictTypeParam;
import com.yiring.app.param.dict.DictTypeQueryParam;
import com.yiring.app.service.dict.DictTypeService;
import com.yiring.common.core.Result;
import com.yiring.common.dict.DictType;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* 字典类型控制器 * 字典类型控制器
*
* @author tzl * @author tzl
* 2022/4/14 15:14 * 2022/4/14 15:14
*/ */
@Slf4j @Slf4j
@Validated @Validated
@Api(tags = "DictType") @Api(tags = "DictType")
@RestController @RestController
@RequestMapping("/DictType/") @RequestMapping("/DictType/")
public class DictTypeController { public class DictTypeController {
//
@Resource // @Resource
DictTypeService dictTypeService; // DictTypeService dictTypeService;
//
@ApiOperation(value = "新增字典类型信息") // @ApiOperation(value = "新增字典类型信息")
@PostMapping("saveDictTypeInfo") // @PostMapping("saveDictTypeInfo")
public Result<String> saveDictTypeInfo(@Valid DictTypeParam dictTypeParam) { // public Result<String> saveDictTypeInfo(@Valid DictTypeParam dictTypeParam) {
return dictTypeService.saveDictTypeInfo(dictTypeParam); // return dictTypeService.saveDictTypeInfo(dictTypeParam);
} // }
//
@ApiOperation(value = "修改字典类型信息") // @ApiOperation(value = "修改字典类型信息")
@PostMapping("updateDictTypeInfo") // @PostMapping("updateDictTypeInfo")
public Result<String> updateDictTypeInfo(@Valid DictTypeParam dictTypeParam, @Valid IdParam idParam) { // public Result<String> updateDictTypeInfo(@Valid DictTypeParam dictTypeParam, @Valid IdParam idParam) {
return dictTypeService.updateDictTypeInfo(dictTypeParam, idParam); // return dictTypeService.updateDictTypeInfo(dictTypeParam, idParam);
} // }
//
@ApiOperation(value = "删除字典类型信息") // @ApiOperation(value = "删除字典类型信息")
@PostMapping("delecteById") // @PostMapping("delecteById")
public Result<String> delecteById(@Valid IdParam idParam) { // public Result<String> delecteById(@Valid IdParam idParam) {
return dictTypeService.delecteById(idParam.getId()); // return dictTypeService.delecteById(idParam.getId());
} // }
//
@ApiOperation(value = "查看字典类型信息(分页)") // @ApiOperation(value = "查看字典类型信息(分页)")
@GetMapping("pageDictTypeInfo") // @GetMapping("pageDictTypeInfo")
public Result<PageVo<DictType>> pageDictInfo(@Valid DictTypeQueryParam queryParam, @Valid PageParam param) { // public Result<PageVo<DictType>> pageDictInfo(@Valid DictTypeQueryParam queryParam, @Valid PageParam param) {
return dictTypeService.pageDictTypeInfo(queryParam, param); // return dictTypeService.pageDictTypeInfo(queryParam, param);
} // }
//
@ApiOperation(value = "查看字典类型信息详情") // @ApiOperation(value = "查看字典类型信息详情")
@GetMapping("getDictTypeInfo") // @GetMapping("getDictTypeInfo")
public Result<DictType> getDictTypeInfo(@Valid IdParam idParam) { // public Result<DictType> getDictTypeInfo(@Valid IdParam idParam) {
return dictTypeService.getDictTypeInfo(idParam.getId()); // return dictTypeService.getDictTypeInfo(idParam.getId());
} // }
} }
...@@ -12,7 +12,6 @@ import com.yiring.common.util.date.DateUtils; ...@@ -12,7 +12,6 @@ import com.yiring.common.util.date.DateUtils;
import com.yiring.common.util.file.FileTypeUtils; import com.yiring.common.util.file.FileTypeUtils;
import com.yiring.common.util.file.ImageUtils; import com.yiring.common.util.file.ImageUtils;
import com.yiring.common.util.reflect.ReflectUtils; import com.yiring.common.util.reflect.ReflectUtils;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
...@@ -362,10 +361,10 @@ public class ExcelUtils<T> { ...@@ -362,10 +361,10 @@ public class ExcelUtils<T> {
public void exportExcel(HttpServletResponse response) { public void exportExcel(HttpServletResponse response) {
try { try {
writeSheet(); writeSheet();
// wb.write(response.getOutputStream()); wb.write(response.getOutputStream());
FileOutputStream fos = new FileOutputStream("D:/a.xls"); // FileOutputStream fos = new FileOutputStream("D:/a.xls");
wb.write(fos); // wb.write(fos);
fos.close(); // fos.close();
} catch (Exception e) { } catch (Exception e) {
log.error("导出Excel异常{}", e.getMessage()); log.error("导出Excel异常{}", e.getMessage());
} finally { } finally {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论