提交 306331f2 作者: 谭志磊

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

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