253 lines
10 KiB
Java
253 lines
10 KiB
Java
package com.cdzy.ebikeoperate.controller;
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.cdzy.common.enums.Code;
|
|
import com.cdzy.common.model.JsonResult;
|
|
import com.cdzy.ebikeoperate.model.dto.request.ReqEbikeComponentTypeInfoDto;
|
|
import com.cdzy.ebikeoperate.model.dto.response.EbikeAdministrationZoneDto;
|
|
import com.cdzy.ebikeoperate.model.dto.response.EbikeComponentTypeInfoDto;
|
|
import com.cdzy.ebikeoperate.model.dto.response.EbikeOperateAttachmentFileDto;
|
|
import com.cdzy.ebikeoperate.model.pojo.EbikeAdministrationZone;
|
|
import com.cdzy.ebikeoperate.model.pojo.EbikeComponentTypeInfo;
|
|
import com.cdzy.ebikeoperate.model.pojo.EbikeOperateAttachmentFile;
|
|
import com.cdzy.ebikeoperate.service.EbikeAdministrationZoneService;
|
|
import com.cdzy.ebikeoperate.service.EbikeComponentTypeInfoService;
|
|
import com.cdzy.ebikeoperate.service.EbikeOperateAttachmentFileService;
|
|
import com.cdzy.ebikeoperate.utils.MinioUtil;
|
|
import com.cdzy.ebikeoperate.utils.QRGenUtil;
|
|
import com.ebike.feign.clients.StaffFeignClient;
|
|
import com.ebike.feign.model.rsp.StaffFeign;
|
|
import com.mybatisflex.core.paginate.Page;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import java.io.InputStream;
|
|
import java.time.LocalDateTime;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* 运营系统 控制层。
|
|
* 码表、二维码、OSS文件上传等。
|
|
*
|
|
* @author dingchao
|
|
* @since 2025-03-25
|
|
*/
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("/ebikeOperateSystem")
|
|
public class EbikeOperateSystemInfoController {
|
|
|
|
@Autowired
|
|
private EbikeComponentTypeInfoService ebikeComponentTypeInfoService;
|
|
@Autowired
|
|
private EbikeAdministrationZoneService ebikeAdministrationZoneService;
|
|
@Autowired
|
|
private EbikeOperateAttachmentFileService ebikeOperateAttachmentFileService;
|
|
@Autowired
|
|
private MinioUtil minioUtil;
|
|
@Autowired
|
|
private StaffFeignClient staffFeignClient;
|
|
|
|
|
|
/**
|
|
* 保存车辆部件类型信息。
|
|
*
|
|
* @param ebikeComponentTypeInfo 车辆部件类型信息
|
|
* @return
|
|
*/
|
|
@PostMapping("saveEbikeComponentTypeInfo")
|
|
public JsonResult<?> saveEbikeComponentTypeInfo(@RequestBody EbikeComponentTypeInfo ebikeComponentTypeInfo) {
|
|
boolean result = ebikeComponentTypeInfoService.save(ebikeComponentTypeInfo);
|
|
return result ? JsonResult.success("保存车辆部件类型信息成功") : JsonResult.failed("保存车辆部件类型信息失败");
|
|
}
|
|
|
|
/**
|
|
* 获取车辆部件类型信息。
|
|
*
|
|
* @param id 车辆部件类型信息id
|
|
* @return
|
|
*/
|
|
@GetMapping("getEbikeComponentTypeInfo")
|
|
public JsonResult<?> getEbikeComponentTypeInfo(@RequestParam(name = "id") String id) {
|
|
EbikeComponentTypeInfo ebikeComponentTypeInfo = ebikeComponentTypeInfoService.getById(id);
|
|
if (ebikeComponentTypeInfo == null) {
|
|
return JsonResult.failed("车辆部件类型信息不存在");
|
|
}
|
|
EbikeComponentTypeInfoDto ebikeComponentTypeInfoDto = new EbikeComponentTypeInfoDto();
|
|
BeanUtils.copyProperties(ebikeComponentTypeInfo, ebikeComponentTypeInfoDto);
|
|
String cover = ebikeComponentTypeInfo.getCover();
|
|
if (cover != null && !cover.isEmpty()) {
|
|
String coverUrl = minioUtil.getBucketFileUrl(cover);
|
|
ebikeComponentTypeInfoDto.setCoverUrl(coverUrl);
|
|
}
|
|
return JsonResult.success(ebikeComponentTypeInfoDto);
|
|
}
|
|
|
|
/**
|
|
* 更新车辆部件类型信息。
|
|
*
|
|
* @param ebikeComponentTypeInfo 车辆部件类型信息
|
|
* @return
|
|
*/
|
|
@PostMapping("updateEbikeComponentTypeInfo")
|
|
public JsonResult<?> updateEbikeComponentTypeInfo(@RequestBody EbikeComponentTypeInfo ebikeComponentTypeInfo) {
|
|
boolean result = ebikeComponentTypeInfoService.updateById(ebikeComponentTypeInfo);
|
|
return result? JsonResult.success("更新车辆部件类型信息成功") : JsonResult.failed("更新车辆部件类型信息失败");
|
|
}
|
|
|
|
/**
|
|
* 删除车辆部件类型信息。
|
|
*
|
|
* @param id 车辆部件类型信息id
|
|
* @return
|
|
*/
|
|
@PostMapping("deleteEbikeComponentTypeInfo")
|
|
public JsonResult<?> deleteEbikeComponentTypeInfo(@RequestParam(name = "id") String id) {
|
|
EbikeComponentTypeInfo ebikeComponentTypeInfo = new EbikeComponentTypeInfo();
|
|
boolean result = ebikeComponentTypeInfoService.removeById(id);
|
|
return result? JsonResult.success("删除车辆部件类型信息成功") : JsonResult.failed("删除车辆部件类型信息失败");
|
|
}
|
|
|
|
/**
|
|
* 分页获取车辆部件类型信息
|
|
*
|
|
* @param reqEbikeComponentTypeInfoDto 查询参数
|
|
* @return 车辆部件类型信息列表
|
|
*/
|
|
@PostMapping("getEbikeComponentTypeInfoPage")
|
|
public JsonResult<?> getEbikeComponentTypeInfoList(@RequestBody ReqEbikeComponentTypeInfoDto reqEbikeComponentTypeInfoDto) {
|
|
Page<EbikeComponentTypeInfoDto> list = ebikeComponentTypeInfoService.getEbikeComponentTypeInfoPage(reqEbikeComponentTypeInfoDto);
|
|
return JsonResult.success(list);
|
|
}
|
|
|
|
/**
|
|
* 车辆部件类型列表。
|
|
*
|
|
* @return 列表
|
|
*/
|
|
@GetMapping("ebikeComponentTypeInfo")
|
|
public JsonResult<?> ebikeComponentTypeInfo() {
|
|
List<EbikeComponentTypeInfo> list = ebikeComponentTypeInfoService.list();
|
|
return JsonResult.success(list);
|
|
}
|
|
|
|
/**
|
|
* 行政区划列表。
|
|
*
|
|
* @param parent_id 父级id, 空则返回第一级列表
|
|
* @return 列表
|
|
*/
|
|
@GetMapping("ebikeAdministrationZone")
|
|
public JsonResult<?> ebikeAdministrationZone(@RequestParam(name = "parent_id", required = false) String parent_id) {
|
|
List<EbikeAdministrationZoneDto> list = ebikeAdministrationZoneService.getAdministrationZoneList(parent_id);
|
|
return JsonResult.success(list);
|
|
}
|
|
|
|
/**
|
|
* 根据行政区划id获取行政区划全称。
|
|
*
|
|
* @param zoneId 行政区划id
|
|
* @return 行政区划全称
|
|
*/
|
|
@GetMapping("ebikeAdministrationZoneFullName")
|
|
public JsonResult<?> ebikeAdministrationZoneFullName(@RequestParam(name = "zoneId") String zoneId) {
|
|
JSONObject fullName = ebikeAdministrationZoneService.getFullNameByZoneId(zoneId);
|
|
return fullName == null?JsonResult.failed("获取行政区划全称失败") :JsonResult.success(fullName);
|
|
}
|
|
|
|
/**
|
|
* 生成二维码 (png图像base64串)。
|
|
* @param content 二维码内容
|
|
* @param text 打印文字内容
|
|
* @return
|
|
*/
|
|
@PostMapping("ebikeQrCodeGenerate")
|
|
public JsonResult<?> ebikeQrGenerate(@RequestParam(name = "content") String content, @RequestParam(name = "text") String text) {
|
|
if (content == null || content.isEmpty()) {
|
|
return JsonResult.failed("二维码内容不能为空");
|
|
}
|
|
return JsonResult.success(QRGenUtil.generateQRCodeBase64(content, text));
|
|
}
|
|
|
|
/**
|
|
* 附件文件上传
|
|
*
|
|
* @param multipartFile 文件对象
|
|
* @return
|
|
*/
|
|
@PostMapping(value = "fileUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data")
|
|
public JsonResult<?> fileUpload(@RequestParam("multipartFile") MultipartFile multipartFile) {
|
|
|
|
try {
|
|
minioUtil.createBucket(MinioUtil.BUCKET_OPERATE);
|
|
InputStream inputStream = multipartFile.getInputStream();
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
String fileUniqueKey = UUID.randomUUID() + fileName.substring(fileName.lastIndexOf("."));
|
|
minioUtil.uploadFile(inputStream, MinioUtil.BUCKET_OPERATE, fileUniqueKey);
|
|
String minioFileUrl = minioUtil.getFileUrl(MinioUtil.BUCKET_OPERATE, fileUniqueKey);
|
|
EbikeOperateAttachmentFile ebikeAttachmentFile = new EbikeOperateAttachmentFile();
|
|
ebikeAttachmentFile.setFileKey(fileUniqueKey);
|
|
ebikeAttachmentFile.setFileName(fileName);
|
|
ebikeAttachmentFile.setFileType(fileName.substring(fileName.lastIndexOf(".")));
|
|
ebikeAttachmentFile.setFileSize(multipartFile.getSize());
|
|
// 获取上传人信息
|
|
String tokenValue = StpUtil.getTokenValue();
|
|
JsonResult<StaffFeign> result = staffFeignClient.getInfoByToken(tokenValue);
|
|
if (result.getCode() == Code.SUCCESS) {
|
|
StaffFeign staffFeign = result.getData();
|
|
ebikeAttachmentFile.setUploadUser(String.valueOf(staffFeign.getStaffId()));
|
|
}
|
|
ebikeOperateAttachmentFileService.save(ebikeAttachmentFile);
|
|
EbikeOperateAttachmentFileDto ebikeAttachmentFileDto = new EbikeOperateAttachmentFileDto();
|
|
BeanUtils.copyProperties(ebikeAttachmentFile, ebikeAttachmentFileDto);
|
|
ebikeAttachmentFileDto.setFileUrl(minioFileUrl);
|
|
return JsonResult.success(ebikeAttachmentFileDto);
|
|
} catch (Exception e) {
|
|
log.error("fileUpload===>{}", e.getMessage() + Arrays.toString(e.getStackTrace()));
|
|
return JsonResult.failed("上传失败");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取附件文件地址
|
|
*
|
|
* @param fileKey 附件唯一标识
|
|
* @return 附件文件url
|
|
*/
|
|
@GetMapping("getAttachmentFileUrl")
|
|
public JsonResult<?> getAttachmentFile(@RequestParam(name = "fileUniqueKey") String fileKey) {
|
|
try {
|
|
String fileUrl = minioUtil.getFileUrl(MinioUtil.BUCKET_OPERATE, fileKey);
|
|
return JsonResult.success("获取成功", fileUrl);
|
|
}catch (Exception e) {
|
|
log.error("getAttachmentFile===>{}", e.getMessage() + Arrays.toString(e.getStackTrace()));
|
|
return JsonResult.failed("获取失败");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除附件文件
|
|
*
|
|
* @param fileKey 附件唯一标识
|
|
* @return
|
|
*/
|
|
@PostMapping("deletedFile")
|
|
public JsonResult<?> deletedFile(@RequestParam(name = "fileUniqueKey") String fileKey) {
|
|
|
|
try {
|
|
minioUtil.deleteObject(MinioUtil.BUCKET_OPERATE, fileKey);
|
|
ebikeOperateAttachmentFileService.removeById(fileKey);
|
|
return JsonResult.success("删除成功");
|
|
} catch (Exception e) {
|
|
log.error("deletedFile===>{}", e.getMessage() + Arrays.toString(e.getStackTrace()));
|
|
return JsonResult.failed("删除失败");
|
|
}
|
|
}
|
|
}
|