mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、广告管理完善;2、菜单来源类型 -> 归属类型;
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
package com.cf.imes.framework.common.validation;
|
||||
|
||||
import com.cf.imes.framework.common.core.IntArrayValuable;
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/8/28 15:08
|
||||
*/
|
||||
@Target({
|
||||
ElementType.FIELD
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Constraint(
|
||||
validatedBy = {InScopeValidator.class}
|
||||
)
|
||||
public @interface InScope {
|
||||
/**
|
||||
* @return 实现 EnumValuable 接口的
|
||||
*/
|
||||
Class<? extends IntArrayValuable> value();
|
||||
|
||||
String message() default "{desc}不合法";
|
||||
|
||||
String desc() default "";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.cf.imes.framework.common.validation;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.core.IntArrayValuable;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/8/28 15:11
|
||||
*/
|
||||
public class InScopeValidator implements ConstraintValidator<InScope, List<Integer>> {
|
||||
|
||||
private List<Integer> values;
|
||||
|
||||
private String desc;
|
||||
|
||||
@Override
|
||||
public void initialize(InScope annotation) {
|
||||
IntArrayValuable[] values = annotation.value().getEnumConstants();
|
||||
if (values.length == 0) {
|
||||
this.values = Collections.emptyList();
|
||||
} else {
|
||||
this.values = Arrays.stream(values[0].array()).boxed().collect(Collectors.toList());
|
||||
}
|
||||
this.desc = annotation.desc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(List<Integer> integers, ConstraintValidatorContext constraintValidatorContext) {
|
||||
// 为空时,默认不校验,即认为通过
|
||||
if (CollUtil.isEmpty(integers)) {
|
||||
return true;
|
||||
}
|
||||
if (values.containsAll(integers)) {
|
||||
return true;
|
||||
}
|
||||
// 校验不通过,自定义提示语句(因为,注解上的 value 是枚举类,无法获得枚举类的实际值)
|
||||
constraintValidatorContext.disableDefaultConstraintViolation(); // 禁用默认的 message 的值
|
||||
constraintValidatorContext.buildConstraintViolationWithTemplate(constraintValidatorContext.getDefaultConstraintMessageTemplate()
|
||||
.replace("{desc}", desc)).addConstraintViolation(); // 重新添加错误提示语句
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+8
-8
@@ -426,9 +426,9 @@ public class ErrorCodeConstants {
|
||||
public static final ErrorCode PRODUCTS_NO_DELETE = new ErrorCode(1_002_043_013, "当前产品已上架,无法删除,请下架后再删除");
|
||||
public static final ErrorCode PRODUCTS_NO_UPDATE = new ErrorCode(1_002_043_014, "当前产品已上架,无法进行修改");
|
||||
public static final ErrorCode PRODUCTS_DETAIL_NO_UPDATE = new ErrorCode(1_002_043_016, "定价规则对应的产品已上架,无法进行修改");
|
||||
public static final ErrorCode ADVERTISEMENT_START_TIME_ERROR = new ErrorCode(1_002_043_017, "广告开始时间选择有误,应等于或大于当日");
|
||||
public static final ErrorCode ADVERTISEMENT_TIME_ERROR = new ErrorCode(1_002_043_018, "时间选择有误,结束时间应大于或等于开始时间");
|
||||
public static final ErrorCode ADVERTISEMENT_NAME_IS_EXIST = new ErrorCode(1_002_043_019, "当前名称的广告已存在,请重新命名");
|
||||
public static final ErrorCode ADVERTISEMENT_START_TIME_ERROR = new ErrorCode(1_002_043_017, "投放时间错误,开始时间应等于或大于当日");
|
||||
public static final ErrorCode ADVERTISEMENT_TIME_ERROR = new ErrorCode(1_002_043_018, "投放时间错误,结束时间应大于开始时间");
|
||||
public static final ErrorCode ADVERTISEMENT_NAME_IS_EXIST = new ErrorCode(1_002_043_019, "当前广告名称已存在,请重新命名");
|
||||
public static final ErrorCode ADVERTISEMENT_NO_DELETE = new ErrorCode(1_002_043_020, "当前广告已经发布,无法删除,请结束发布后再删除");
|
||||
public static final ErrorCode ADVERTISEMENT_REPUBLISH_NO_TIME = new ErrorCode(1_002_043_021, "广告重新发布,应重新选择投放时间");
|
||||
public static final ErrorCode RECHARGE_ACTIVE_NAME_IS_EXIST = new ErrorCode(1_002_043_022, "当前赠送金活动名称已存在,请修改");
|
||||
@@ -471,11 +471,11 @@ public class ErrorCodeConstants {
|
||||
//=========== 广告相关 1-002-046-000 ============
|
||||
public static final ErrorCode ADVERTISEMENT_POSITION_NO_EXIST = new ErrorCode(1_002_046_001, "广告所选放置位置不存在");
|
||||
public static final ErrorCode ADVERTISEMENT_NO_EXIST = new ErrorCode(1_002_046_002, "广告不存在");
|
||||
public static final ErrorCode ADVERTISEMENT_STATUS_ERROR = new ErrorCode(1_002_046_003, "当前广告已经发布,无需立即发布");
|
||||
public static final ErrorCode ADVERTISEMENT_STATUS_ERROR2 = new ErrorCode(1_002_046_004, "当前广告已过结束时间,请点击重新发布");
|
||||
public static final ErrorCode ADVERTISEMENT_END_ERROR = new ErrorCode(1_002_046_005, "当前广告未发布,无需结束发布");
|
||||
public static final ErrorCode ADVERTISEMENT_END_ERROR2 = new ErrorCode(1_002_046_006, "当前广告已结束,无需立即结束");
|
||||
public static final ErrorCode ADVERTISEMENT_FAIL = new ErrorCode(1_002_046_007, "自动发布失败");
|
||||
public static final ErrorCode ADVERTISEMENT_STATUS_ENDTIME_EXPIRED = new ErrorCode(1_002_046_003, "当前广告投放结束时间已超期,请重新发布选择投放时间或重新编辑投放时间");
|
||||
public static final ErrorCode ADVERTISEMENT_FAIL = new ErrorCode(1_002_046_004, "自动发布失败");
|
||||
public static final ErrorCode ADVERTISEMENT_IMAGE_EMPTY_ERROR = new ErrorCode(1_002_046_005, "广告图片文件为空,请重新上传");
|
||||
public static final ErrorCode ADVERTISEMENT_IMAGE_UPLOAD_FAIL = new ErrorCode(1_002_046_006, "广告图片上传失败,请稍后再试");
|
||||
public static final ErrorCode ADVERTISEMENT_UPDATE_STATUS_ERROR = new ErrorCode(1_002_046_007, "当前广告已经发布,若要编辑请先结束发布");
|
||||
|
||||
|
||||
//=========== 解析器管理 1-002-044-000 ============
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.cf.imes.module.system.enums.advertisement;
|
||||
|
||||
import com.cf.imes.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 广告位置枚举
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AdvertisementPositionEnum implements IntArrayValuable {
|
||||
|
||||
WORKBENCH_CAROUSEL(1, "首页工作台轮播"),
|
||||
SYSTEMCONFIG_AMOUNTQUERY_CAROUSEL(2, "系统管理余额查询轮播"),
|
||||
BASECONFIG_FUNDSQUERY_CAROUSEL(3, "基础配置资金查询轮播");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(AdvertisementPositionEnum::getStatus).toArray();
|
||||
|
||||
/**
|
||||
* 状态值
|
||||
*/
|
||||
private final Integer status;
|
||||
/**
|
||||
* 状态名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 菜单来源类型枚举类
|
||||
* 菜单归属类型枚举类
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
|
||||
+42
-83
@@ -2,10 +2,12 @@ package com.cf.imes.module.system.controller.admin.funds.advertisement;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.common.validation.InEnum;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementPublishReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementRePublishReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementSaveReqVO;
|
||||
import com.cf.imes.module.system.enums.advertisement.AdvertisementPositionEnum;
|
||||
import com.cf.imes.module.system.service.funds.advertisement.AdvertisementService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -18,13 +20,9 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.ADVERTISEMENT_STATUS_ERROR;
|
||||
|
||||
@Tag(name = "管理后台 - 广告管理")
|
||||
@RestController
|
||||
@@ -37,7 +35,7 @@ public class AdvertisementController {
|
||||
private AdvertisementService advertisementService;
|
||||
|
||||
|
||||
@PostMapping("")
|
||||
@PutMapping("")
|
||||
@Operation(summary = "新建广告")
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:create')")
|
||||
public CommonResult<Long> createAdvertisement(@Valid @RequestBody AdvertisementSaveReqVO createReqVO) {
|
||||
@@ -45,7 +43,7 @@ public class AdvertisementController {
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("")
|
||||
@PostMapping("")
|
||||
@Operation(summary = "更新广告")
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:update')")
|
||||
public CommonResult<Boolean> updateAdvertisement(@Valid @RequestBody AdvertisementSaveReqVO reqVO) {
|
||||
@@ -53,112 +51,73 @@ public class AdvertisementController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/image")
|
||||
@Operation(summary = "上传广告图片")
|
||||
@Parameter(description = "广告图片", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:create')")
|
||||
public CommonResult<String> uploadAdImage(@RequestPart("file") MultipartFile file) {
|
||||
return success(advertisementService.uploadAdImage(file));
|
||||
}
|
||||
|
||||
@DeleteMapping("")
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除广告")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:delete')")
|
||||
public CommonResult<Boolean> deleteAdvertisement(@RequestParam("id") Long id) {
|
||||
public CommonResult<Boolean> deleteAdvertisement(@PathVariable("id") Long id) {
|
||||
advertisementService.delete(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "获得广告")
|
||||
@Operation(summary = "查询广告")
|
||||
@Parameter(name = "id", description = "广告ID", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:query')")
|
||||
public CommonResult<AdvertisementRespVO> getAdvertisement(@PathVariable("id") Long id) {
|
||||
|
||||
return success(advertisementService.get(id));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得广告分页")
|
||||
@Operation(summary = "查询广告分页")
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:query')")
|
||||
public CommonResult<PageResult<AdvertisementRespVO>> getAdvertisementPage(@Valid AdvertisementPageReqVO pageReqVO) {
|
||||
|
||||
return success(advertisementService.getPage(pageReqVO));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PutMapping("/publish")
|
||||
@Operation(summary = "发布/结束/重新发布广告")
|
||||
@Parameter(name = "id", description = "广告id", required = true)
|
||||
@Parameter(name = "status", description = "广告状态", required = true)
|
||||
@PostMapping("/publish/{id}")
|
||||
@Operation(summary = "立即发布广告")
|
||||
@Parameter(name = "id", description = "广告ID", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:update')")
|
||||
public CommonResult<Boolean> updatePublishStatus(@RequestBody AdvertisementPublishReqVO reqVO) {
|
||||
advertisementService.updatePublishStatus(reqVO);
|
||||
public CommonResult<Boolean> publish(@PathVariable Long id) {
|
||||
advertisementService.publish(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/endPublish/{id}")
|
||||
@Operation(summary = "结束发布广告")
|
||||
@Parameter(name = "id", description = "广告ID", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:update')")
|
||||
public CommonResult<Boolean> endPublish(@PathVariable Long id) {
|
||||
advertisementService.endPublish(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/republish")
|
||||
@Operation(summary = "重新发布广告")
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:update')")
|
||||
public CommonResult<Boolean> rePublish(@RequestBody AdvertisementRePublishReqVO reqVO) {
|
||||
advertisementService.republish(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/getAd")
|
||||
@Operation(summary = "根据广告位置获得广告信息")
|
||||
@GetMapping("/position/page")
|
||||
@Operation(summary = "根据广告位置获取广告信息")
|
||||
@PreAuthorize("@ss.hasPermission('base:advertisement:query')")
|
||||
public CommonResult<List<AdvertisementRespVO>> getAdvertisementByPosition(@RequestParam("id") Integer adPosition) {
|
||||
|
||||
public CommonResult<List<AdvertisementRespVO>> getAdvertisementByPosition(@RequestParam("adPosition") @InEnum(AdvertisementPositionEnum.class) Integer adPosition) {
|
||||
return success(advertisementService.getAdvertisementByPosition(adPosition));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 上传图片,支持附带 orderId 参数
|
||||
@PostMapping("/upload")
|
||||
public CommonResult<String> uploadImage(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("orderId") Long orderId) {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
// 获取原始文件名并提取扩展名
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String extension = "";
|
||||
|
||||
int dotIndex = originalFilename.lastIndexOf('.');
|
||||
if (dotIndex != -1) {
|
||||
extension = originalFilename.substring(dotIndex); // 包含“.”
|
||||
} else {
|
||||
throw exception(1,"缺少扩展名");
|
||||
}
|
||||
|
||||
// 构建新文件名: orderId + .扩展名
|
||||
String filename = orderId + extension;
|
||||
|
||||
// 确保目录存在
|
||||
File dir = new File("E:\\ceshi123\\");
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
|
||||
File dest = new File(dir, filename);
|
||||
file.transferTo(dest);
|
||||
|
||||
|
||||
// 你可以把图片信息和 orderId 一起存入数据库,这里省略
|
||||
return success("上传成功: " + filename);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
throw exception(ADVERTISEMENT_STATUS_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.cf.imes.module.system.controller.admin.funds.advertisement.vo;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Getter
|
||||
@Data
|
||||
public class AdImageFilePath {
|
||||
|
||||
@Value("${adImageFile.filepath:}")
|
||||
private String filePath;
|
||||
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class AdvertisementPageReqVO extends PageParam {
|
||||
@Schema(description = "广告位置")
|
||||
private String adPosition;
|
||||
|
||||
@Schema(description = "广告状态", example = "0全部 1未发布 2已发布 3已结束")
|
||||
@Schema(description = "广告状态,0未发布 1已发布 2已结束", example = "0")
|
||||
@AdvertisementStatus
|
||||
private Integer status;
|
||||
|
||||
|
||||
+4
-9
@@ -2,6 +2,7 @@ package com.cf.imes.module.system.controller.admin.funds.advertisement.vo;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
@@ -10,26 +11,20 @@ import java.time.LocalDate;
|
||||
@Schema(description = "广告发布状态")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
public class AdvertisementPublishReqVO {
|
||||
public class AdvertisementRePublishReqVO {
|
||||
|
||||
|
||||
@Schema(description = "广告id")
|
||||
private Long id;
|
||||
|
||||
|
||||
@Schema(description = "发布状态")
|
||||
private Integer status;
|
||||
|
||||
|
||||
@Schema(description = "是否重新发布",example = "false")
|
||||
private Boolean isRepublish;
|
||||
|
||||
|
||||
@Schema(description = "投放开始时间,重新发布时传")
|
||||
@NotNull(message = "投放开始时间不能为空")
|
||||
private LocalDate startTime;
|
||||
|
||||
|
||||
@Schema(description = "投放结束时间,重新发布时传")
|
||||
@NotNull(message = "投放结束时间不能为空")
|
||||
private LocalDate endTime;
|
||||
|
||||
|
||||
+3
-2
@@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 广告管理 Response VO")
|
||||
@Data
|
||||
@@ -18,7 +19,7 @@ public class AdvertisementRespVO {
|
||||
private String adName;
|
||||
|
||||
@Schema(description = "广告位置")
|
||||
private String adPosition;
|
||||
private List<Integer> adPosition;
|
||||
|
||||
@Schema(description = "图片路径")
|
||||
private String adImagePath;
|
||||
@@ -44,7 +45,7 @@ public class AdvertisementRespVO {
|
||||
@Schema(description = "广告顺序")
|
||||
private Short sort;
|
||||
|
||||
@Schema(description = "广告状态", example = " 0未发布 1已发布 2已结束")
|
||||
@Schema(description = "广告状态,0未发布 1已发布 2已结束", example = "0")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "操作人")
|
||||
|
||||
+6
-15
@@ -1,16 +1,17 @@
|
||||
package com.cf.imes.module.system.controller.admin.funds.advertisement.vo;
|
||||
|
||||
import com.cf.imes.framework.common.validation.InScope;
|
||||
import com.cf.imes.framework.common.validation.NumberValid;
|
||||
import com.cf.imes.module.system.validation.advertisement.AdvertisementStatus;
|
||||
import com.cf.imes.module.system.enums.advertisement.AdvertisementPositionEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
|
||||
|
||||
@@ -28,18 +29,15 @@ public class AdvertisementSaveReqVO {
|
||||
private String adName;
|
||||
|
||||
|
||||
@Schema(description = "软件标识")
|
||||
private String softwareId;
|
||||
|
||||
|
||||
@Schema(description = "广告位置,字典键值", example = "[1,2]")
|
||||
@NotNull(message = "广告位置不能为空")
|
||||
private Integer[] adPosition;
|
||||
@InScope(value = AdvertisementPositionEnum.class, desc = "广告位置")
|
||||
private List<Integer> adPosition;
|
||||
|
||||
|
||||
@Schema(description = "广告图片文件")
|
||||
@NotBlank(message = "广告图片文件不能为空")
|
||||
private MultipartFile adImageFile;
|
||||
private String adImagePath;
|
||||
|
||||
|
||||
@Schema(description = "投放开始时间")
|
||||
@@ -62,11 +60,4 @@ public class AdvertisementSaveReqVO {
|
||||
@Schema(description = "广告顺序")
|
||||
@NumberValid(name = "广告顺序")
|
||||
private Integer sort;
|
||||
|
||||
|
||||
@Schema(description = "广告状态", example = "0全部 1未发布 2已发布 3已结束")
|
||||
@AdvertisementStatus
|
||||
private Integer status;
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class InvoiceController {
|
||||
|
||||
@GetMapping("/title")
|
||||
@Operation(summary = "获取发票抬头信息")
|
||||
public CommonResult<InvoiceTitleInfo> getInvoiceTitle() {
|
||||
public CommonResult<InvoiceTitleInfo> getOrgInvoiceTitle() {
|
||||
return success(invoiceService.getInvoiceTitle());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -69,6 +69,6 @@ public class MenuRespVO {
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "菜单来源类型", example = "1")
|
||||
@Schema(description = "菜单归属类型", example = "1")
|
||||
private Integer sourceType;
|
||||
}
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ public class MenuSaveVO {
|
||||
@Schema(description = "权限功能描述")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "菜单来源类型 ,见 MenuSourceTypeValid 枚举",example = "1")
|
||||
@Schema(description = "菜单归属类型 ,见 MenuSourceTypeValid 枚举",example = "1")
|
||||
@NotNull
|
||||
@MenuSourceTypeValid
|
||||
private Integer sourceType;
|
||||
|
||||
+6
-2
@@ -1,19 +1,22 @@
|
||||
package com.cf.imes.module.system.dal.dataobject.funds.advertisement;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.cf.imes.framework.mybatis.core.type.IntegerListTypeHandler;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 广告表 product_details DO
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
@TableName("advertisement")
|
||||
@TableName(value = "advertisement", autoResultMap = true)
|
||||
@KeySequence("advertisement_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -39,7 +42,8 @@ public class AdvertisementDO extends BaseDO {
|
||||
/**
|
||||
* 广告位置
|
||||
*/
|
||||
private String adPosition;
|
||||
@TableField(value = "ad_position", typeHandler = IntegerListTypeHandler.class)
|
||||
private List<Integer> adPosition;
|
||||
/**
|
||||
* 图片路径
|
||||
*/
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ public class MenuDO extends BaseDO {
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 来源类型
|
||||
* 归属类型
|
||||
*/
|
||||
private Integer sourceType;
|
||||
}
|
||||
|
||||
+8
-1
@@ -72,7 +72,14 @@ public interface AdvertisementMapper extends BaseMapperX<AdvertisementDO> {
|
||||
void updateAdStatusIsEndPublished(@Param("now") LocalDate now,@Param("status") Integer status);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询广告位置下的广告列表
|
||||
*
|
||||
* @param adPosition
|
||||
* @param status
|
||||
* @param now
|
||||
* @return
|
||||
*/
|
||||
List<AdvertisementRespVO> selectAdList(@Param("adPosition") Integer adPosition,@Param("status") Integer status,@Param("now") LocalDate now);
|
||||
|
||||
}
|
||||
|
||||
+34
-4
@@ -3,9 +3,10 @@ package com.cf.imes.module.system.service.funds.advertisement;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementPageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementPublishReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementRePublishReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementSaveReqVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,22 +35,51 @@ public interface AdvertisementService {
|
||||
void delete(Long id);
|
||||
|
||||
/**
|
||||
* 获得广告
|
||||
* 获取广告
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
AdvertisementRespVO get(Long id);
|
||||
|
||||
/**
|
||||
* 获得广告 分页
|
||||
* 获取广告 分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
*/
|
||||
PageResult<AdvertisementRespVO> getPage(AdvertisementPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 发布广告
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void publish(Long id);
|
||||
|
||||
void updatePublishStatus(AdvertisementPublishReqVO reqVO);
|
||||
/**
|
||||
* 结束发布
|
||||
*/
|
||||
void endPublish(Long id);
|
||||
|
||||
/**
|
||||
* 重新发布
|
||||
*
|
||||
* @param reqVO
|
||||
*/
|
||||
void republish(AdvertisementRePublishReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 通过广告位置查询广告列表
|
||||
*
|
||||
* @param adPosition
|
||||
* @return
|
||||
*/
|
||||
List<AdvertisementRespVO> getAdvertisementByPosition(Integer adPosition);
|
||||
|
||||
/**
|
||||
* 上传广告图片
|
||||
*
|
||||
* @param adImageFile
|
||||
* @return
|
||||
*/
|
||||
String uploadAdImage(MultipartFile adImageFile);
|
||||
}
|
||||
|
||||
+76
-324
@@ -1,33 +1,27 @@
|
||||
package com.cf.imes.module.system.service.funds.advertisement;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.common.util.Assert.AssertUtils;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.module.infra.api.file.FileApi;
|
||||
import com.cf.imes.module.system.controller.admin.funds.advertisement.vo.*;
|
||||
import com.cf.imes.module.system.dal.dataobject.funds.advertisement.AdvertisementDO;
|
||||
import com.cf.imes.module.system.dal.mysql.funds.advertisement.AdvertisementMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.funds.advertisement.AdvertisementTaskMapper;
|
||||
import com.cf.imes.module.system.enums.advertisement.AdvertisementStatusEnum;
|
||||
import com.cf.imes.module.system.mq.producer.advertisement.AdvertisementProducer;
|
||||
import com.cf.imes.module.system.service.dict.DictDataService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@@ -44,61 +38,33 @@ import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
|
||||
@Slf4j
|
||||
public class AdvertisementServiceImpl implements AdvertisementService{
|
||||
|
||||
private static final String ADVERTISEMENT_POSITION = "advertisement_position";
|
||||
|
||||
private static final String EMPTY_STRING = new String();
|
||||
|
||||
@Value("${chenfeng.info.name}")
|
||||
private String SOFT_WARE_ID; // 获取软件标识-可修改
|
||||
|
||||
@Resource
|
||||
private DictDataService dictDataService;
|
||||
|
||||
@Resource
|
||||
private AdvertisementMapper advertisementMapper;
|
||||
|
||||
@Resource
|
||||
private AdvertisementTaskMapper advertisementTaskMapper;
|
||||
|
||||
@Resource
|
||||
private SnowflakeIdWorker3rd idWorker;
|
||||
|
||||
@Resource
|
||||
private AdvertisementProducer advertisementProducer;
|
||||
|
||||
@Resource
|
||||
private AdImageFilePath adImageFilePath;
|
||||
|
||||
|
||||
private static final String FIELD_AD_ID = "广告ID为:";
|
||||
private FileApi fileApi;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long create(AdvertisementSaveReqVO createReqVO) {
|
||||
|
||||
if(createReqVO.getStartTime().isAfter(createReqVO.getEndTime())){
|
||||
if (createReqVO.getStartTime().isAfter(createReqVO.getEndTime())) {
|
||||
|
||||
throw exception(ADVERTISEMENT_TIME_ERROR);
|
||||
}
|
||||
|
||||
AdvertisementDO aDo = advertisementMapper.selectAdByAdName(createReqVO.getAdName(),null);
|
||||
AdvertisementDO aDo = advertisementMapper.selectAdByAdName(createReqVO.getAdName(), null);
|
||||
|
||||
AssertUtils.empty(aDo,ADVERTISEMENT_NAME_IS_EXIST);
|
||||
|
||||
long id = idWorker.nextId();
|
||||
|
||||
String filePath = "";
|
||||
if(createReqVO.getAdImageFile() != null) {
|
||||
filePath = uploadAdImageFile(createReqVO.getAdImageFile(), id);
|
||||
}
|
||||
AssertUtils.empty(aDo, ADVERTISEMENT_NAME_IS_EXIST);
|
||||
|
||||
// 插入广告
|
||||
createReqVO.setId(id);
|
||||
AdvertisementDO advertisementDO = BeanUtils.toBean(createReqVO, AdvertisementDO.class)
|
||||
.setAdPosition(Arrays.toString(createReqVO.getAdPosition()))
|
||||
.setStatus(validateAdvertisementStatus(createReqVO.getStartTime()))
|
||||
.setAdImagePath(filePath)
|
||||
.setAdPosition(createReqVO.getAdPosition())
|
||||
.setStatus(AdvertisementStatusEnum.UNPUBLISHED.getStatus())
|
||||
.setSoftwareId(SOFT_WARE_ID);
|
||||
|
||||
advertisementMapper.insert(advertisementDO);
|
||||
@@ -114,59 +80,54 @@ public class AdvertisementServiceImpl implements AdvertisementService{
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(AdvertisementSaveReqVO reqVO) {
|
||||
|
||||
Long id = reqVO.getId();
|
||||
// 确认广告是否存在
|
||||
AdvertisementDO validated = validateAdvertisementExists(reqVO.getId());
|
||||
AdvertisementDO advertisementDO = validateAdvertisementExists(id);
|
||||
|
||||
AdvertisementDO aDo = advertisementMapper.selectAdByAdName(reqVO.getAdName(),reqVO.getId());
|
||||
// 发布中的广告不允许编辑
|
||||
if (advertisementDO.getStatus().equals(AdvertisementStatusEnum.PUBLISHED.getStatus())) {
|
||||
throw exception(ADVERTISEMENT_UPDATE_STATUS_ERROR);
|
||||
}
|
||||
|
||||
AssertUtils.empty(aDo,ADVERTISEMENT_NAME_IS_EXIST);
|
||||
// 广告名重复校验
|
||||
AdvertisementDO aDo = advertisementMapper.selectAdByAdName(reqVO.getAdName(), id);
|
||||
|
||||
if(reqVO.getStartTime().isAfter(reqVO.getEndTime())){
|
||||
AssertUtils.empty(aDo, ADVERTISEMENT_NAME_IS_EXIST);
|
||||
|
||||
if (reqVO.getStartTime().isAfter(reqVO.getEndTime())) {
|
||||
throw exception(ADVERTISEMENT_TIME_ERROR);
|
||||
}
|
||||
|
||||
|
||||
String adImagePath = validated.getAdImagePath();
|
||||
if(reqVO.getAdImageFile() != null) {
|
||||
adImagePath = uploadAdImageFile(reqVO.getAdImageFile(), reqVO.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 更新内容
|
||||
AdvertisementDO advertisementDO = BeanUtils.toBean(reqVO, AdvertisementDO.class)
|
||||
.setAdPosition(Arrays.toString(reqVO.getAdPosition()))
|
||||
.setStatus(validateAdvertisementStatus(reqVO.getStartTime()))
|
||||
.setAdImagePath(adImagePath)
|
||||
.setSoftwareId(SOFT_WARE_ID);
|
||||
|
||||
advertisementDO.setAdName(reqVO.getAdName())
|
||||
.setAdImagePath(reqVO.getAdImagePath())
|
||||
.setStartTime(reqVO.getStartTime())
|
||||
.setEndTime(reqVO.getEndTime())
|
||||
.setAdPosition(reqVO.getAdPosition())
|
||||
.setSort(ObjectUtil.isNull(reqVO.getSort()) ? advertisementDO.getSort() : reqVO.getSort())
|
||||
.setAdRedirectUrl(StringUtils.isEmpty(reqVO.getAdRedirectUrl()) ? advertisementDO.getAdRedirectUrl() : reqVO.getAdRedirectUrl());
|
||||
advertisementMapper.updateById(advertisementDO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
|
||||
// 确认广告是否存在
|
||||
AdvertisementDO advertisementDO = validateAdvertisementExists(id);
|
||||
|
||||
if(advertisementDO.getStatus().equals(AdvertisementStatusEnum.PUBLISHED.getStatus())){
|
||||
if (advertisementDO.getStatus().equals(AdvertisementStatusEnum.PUBLISHED.getStatus())) {
|
||||
throw exception(ADVERTISEMENT_NO_DELETE);
|
||||
}
|
||||
|
||||
// 删除广告
|
||||
advertisementMapper.deleteById(id);
|
||||
|
||||
deleteFilesById(adImageFilePath.getFilePath(),id.toString());
|
||||
|
||||
// 删除广告图片文件
|
||||
fileApi.deleteFileByPath(advertisementDO.getAdImagePath());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public AdvertisementRespVO get(Long id) {
|
||||
|
||||
@@ -174,8 +135,6 @@ public class AdvertisementServiceImpl implements AdvertisementService{
|
||||
|
||||
AdvertisementRespVO respVO = BeanUtils.toBean(advertisementDO, AdvertisementRespVO.class);
|
||||
|
||||
viewImage(respVO);
|
||||
|
||||
return respVO;
|
||||
}
|
||||
|
||||
@@ -192,83 +151,55 @@ public class AdvertisementServiceImpl implements AdvertisementService{
|
||||
|
||||
List<AdvertisementRespVO> respVOS = BeanUtils.toBean(pageResult.getList(), AdvertisementRespVO.class);
|
||||
|
||||
respVOS.forEach(f->{
|
||||
respVOS.forEach(f -> {
|
||||
f.setLaunchTime(f.getStartTime() + "~" + f.getEndTime());
|
||||
viewImage(f);
|
||||
});
|
||||
|
||||
return new PageResult<>(respVOS,pageResult.getTotal());
|
||||
return new PageResult<>(respVOS, pageResult.getTotal());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void updatePublishStatus(AdvertisementPublishReqVO reqVO) {
|
||||
|
||||
Long id = reqVO.getId();
|
||||
|
||||
Integer status = reqVO.getStatus();
|
||||
|
||||
public void publish(Long id) {
|
||||
// 校验广告存在
|
||||
AdvertisementDO advertisementDO = validateAdvertisementExists(id);
|
||||
|
||||
// 广告的开始时间
|
||||
LocalDate startTime = advertisementDO.getStartTime();
|
||||
|
||||
// 广告的结束时间
|
||||
LocalDate endTime = advertisementDO.getEndTime();
|
||||
|
||||
// 立即发布
|
||||
if (status.equals(AdvertisementStatusEnum.PUBLISHED.getStatus())) {
|
||||
|
||||
if (LocalDate.now().isAfter(startTime)) {
|
||||
throw exception(ADVERTISEMENT_STATUS_ERROR);
|
||||
}
|
||||
if (LocalDate.now().isAfter(endTime)) {
|
||||
throw exception(ADVERTISEMENT_STATUS_ERROR2);
|
||||
}
|
||||
|
||||
advertisementDO.setStatus(status);
|
||||
}
|
||||
// 结束发布
|
||||
else if (status.equals(AdvertisementStatusEnum.ENDED.getStatus())) {
|
||||
if (LocalDate.now().isBefore(startTime)) {
|
||||
throw exception(ADVERTISEMENT_END_ERROR);
|
||||
}
|
||||
if (LocalDate.now().isAfter(endTime)) {
|
||||
throw exception(ADVERTISEMENT_END_ERROR2);
|
||||
}
|
||||
|
||||
advertisementDO.setStatus(status);
|
||||
}
|
||||
// 重新发布
|
||||
else if(Boolean.TRUE.equals(reqVO.getIsRepublish())){
|
||||
|
||||
// 重新投放开始时间
|
||||
LocalDate isRepublishStartTime = Optional.ofNullable(reqVO.getStartTime()).orElseThrow(() -> new ServiceException(ADVERTISEMENT_REPUBLISH_NO_TIME));
|
||||
|
||||
// 重新投放结束时间
|
||||
LocalDate isRepublishEndTime = Optional.ofNullable(reqVO.getEndTime()).orElseThrow(() -> new ServiceException(ADVERTISEMENT_REPUBLISH_NO_TIME));
|
||||
|
||||
if(isRepublishStartTime.isAfter(isRepublishEndTime)){
|
||||
throw exception(ADVERTISEMENT_TIME_ERROR);
|
||||
}
|
||||
|
||||
validateAdvertisementStatus(isRepublishStartTime);
|
||||
|
||||
advertisementDO.setStatus(AdvertisementStatusEnum.PUBLISHED.getStatus());
|
||||
|
||||
if (LocalDate.now().isAfter(endTime)) {
|
||||
throw exception(ADVERTISEMENT_STATUS_ENDTIME_EXPIRED);
|
||||
}
|
||||
|
||||
advertisementMapper.updateById(advertisementDO);
|
||||
|
||||
|
||||
advertisementMapper.update(new LambdaUpdateWrapper<AdvertisementDO>()
|
||||
.eq(AdvertisementDO::getId, id)
|
||||
.set(AdvertisementDO::getStatus, AdvertisementStatusEnum.PUBLISHED.getStatus()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endPublish(Long id) {
|
||||
// 校验广告存在
|
||||
validateAdvertisementExists(id);
|
||||
|
||||
advertisementMapper.update(new LambdaUpdateWrapper<AdvertisementDO>()
|
||||
.eq(AdvertisementDO::getId, id)
|
||||
.set(AdvertisementDO::getStatus, AdvertisementStatusEnum.ENDED.getStatus()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void republish(AdvertisementRePublishReqVO reqVO) {
|
||||
// 校验广告存在
|
||||
Long id = reqVO.getId();
|
||||
validateAdvertisementExists(id);
|
||||
|
||||
if (reqVO.getStartTime().isAfter(reqVO.getEndTime())) {
|
||||
throw exception(ADVERTISEMENT_TIME_ERROR);
|
||||
}
|
||||
|
||||
advertisementMapper.update(new LambdaUpdateWrapper<AdvertisementDO>()
|
||||
.eq(AdvertisementDO::getId, id)
|
||||
.set(AdvertisementDO::getStatus, AdvertisementStatusEnum.PUBLISHED.getStatus()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -280,44 +211,15 @@ public class AdvertisementServiceImpl implements AdvertisementService{
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
respVOS.forEach(this::viewImage);
|
||||
|
||||
return respVOS;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 判断广告状态
|
||||
public int validateAdvertisementStatus(LocalDate startTime) {
|
||||
|
||||
// 当前时间
|
||||
LocalDate now = LocalDate.now();
|
||||
|
||||
if(now.equals(startTime)){
|
||||
// 已上架
|
||||
return AdvertisementStatusEnum.PUBLISHED.getStatus();
|
||||
|
||||
}else if(now.isAfter(startTime)){
|
||||
throw exception(ADVERTISEMENT_START_TIME_ERROR);
|
||||
|
||||
}else {
|
||||
// 未上架
|
||||
return AdvertisementStatusEnum.UNPUBLISHED.getStatus();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 校验广告是否存在
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private AdvertisementDO validateAdvertisementExists(Long id) {
|
||||
|
||||
AdvertisementDO advertisementDO = advertisementMapper.selectOne(new LambdaQueryWrapperX<AdvertisementDO>()
|
||||
@@ -329,166 +231,16 @@ public class AdvertisementServiceImpl implements AdvertisementService{
|
||||
return advertisementDO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 上传图片
|
||||
private String uploadAdImageFile(MultipartFile file,Long id){
|
||||
|
||||
@Override
|
||||
public String uploadAdImage(MultipartFile adImageFile) {
|
||||
try {
|
||||
|
||||
// 删除之前的图片
|
||||
deleteFilesById(adImageFilePath.getFilePath(),id.toString());
|
||||
|
||||
// 获取原始文件名并提取扩展名
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String extension = null;
|
||||
|
||||
int dotIndex = originalFilename.lastIndexOf('.');
|
||||
if (dotIndex != -1) {
|
||||
|
||||
extension = originalFilename.substring(dotIndex);
|
||||
if (adImageFile.isEmpty()) {
|
||||
throw exception(ADVERTISEMENT_IMAGE_EMPTY_ERROR);
|
||||
}
|
||||
|
||||
// 文件名: id + .扩展名
|
||||
String filename = id + extension;
|
||||
|
||||
// 确保目录存在
|
||||
File dir = new File(adImageFilePath.getFilePath());
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
File dest = new File(dir, filename);
|
||||
file.transferTo(dest);
|
||||
|
||||
return filename;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("图片上传失败:"+e.getMessage());
|
||||
throw exception(IMAGE_UPLOAD_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 删除图片
|
||||
public static void deleteFilesById(String directoryPath, String id) {
|
||||
File dir = new File(directoryPath);
|
||||
if (!dir.exists() || !dir.isDirectory()) {
|
||||
// 路径不存在或不是文件夹,不做处理
|
||||
return;
|
||||
}
|
||||
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (File file : files) {
|
||||
if (file.isFile()) {
|
||||
String fileName = file.getName();
|
||||
if (fileName.startsWith(id + ".")) {
|
||||
file.delete(); // 删除文件,不管结果(失败不会抛异常)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 查询图片,广告管理界面,广告位置查询,错误只写到日志,页面不显示错误
|
||||
public void viewImage(AdvertisementRespVO respVO) {
|
||||
|
||||
File dir = new File(adImageFilePath.getFilePath());
|
||||
if (!dir.exists()) {
|
||||
log.error(FIELD_AD_ID + respVO.getId() + ",的图片查询失败,其目录不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
File[] matches = dir.listFiles((d, name) -> name.startsWith(respVO.getId().toString() + "."));
|
||||
if (matches == null || matches.length == 0) {
|
||||
log.error(FIELD_AD_ID + respVO.getId() + ",的图片查询失败,未找到对应图片");
|
||||
return;
|
||||
}
|
||||
|
||||
File imageFile = matches[0];
|
||||
|
||||
try {
|
||||
|
||||
// 图片字节数据
|
||||
byte[] imageBytes = Files.readAllBytes(imageFile.toPath());
|
||||
|
||||
// 图片的文件类型
|
||||
respVO.setAdImageFileType(Files.probeContentType(imageFile.toPath()));
|
||||
|
||||
// 图片的 Base64 字符串形式
|
||||
respVO.setAdImageBase64(Base64.getEncoder().encodeToString(imageBytes));
|
||||
|
||||
return fileApi.createFile(adImageFile.getBytes());
|
||||
} catch (IOException e) {
|
||||
|
||||
log.error(FIELD_AD_ID + respVO.getId() + ",的图片读取失败," + e.getMessage());
|
||||
log.error("上传广告图片失败", e);
|
||||
throw exception(ADVERTISEMENT_IMAGE_UPLOAD_FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public ResponseEntity<byte[]> getImage(Long adId){
|
||||
|
||||
|
||||
File dir = new File(adImageFilePath.getFilePath());
|
||||
|
||||
if (!dir.exists()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
// 找到文件名以 adId 开头的文件,例如 "123.png"
|
||||
File[] matches = dir.listFiles((d, name) -> name.startsWith(adId.toString() + "."));
|
||||
|
||||
if (matches == null || matches.length == 0) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
|
||||
File imageFile = matches[0];
|
||||
|
||||
try {
|
||||
|
||||
byte[] imageBytes = Files.readAllBytes(imageFile.toPath());
|
||||
String contentType = Files.probeContentType(imageFile.toPath());
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(contentType))
|
||||
.body(imageBytes);
|
||||
} catch (IOException e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 菜单来源类型校验注解
|
||||
* 菜单归属类型校验注解
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/10/21 11:25
|
||||
@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
|
||||
validatedBy = {MenuSourceTypeValidator.class}
|
||||
)
|
||||
public @interface MenuSourceTypeValid {
|
||||
String message() default "菜单来源类型不合法";
|
||||
String message() default "菜单归属类型不合法";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* 菜单来源类型校验器
|
||||
* 菜单归属类型校验器
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/10/21 11:26
|
||||
|
||||
@@ -100,9 +100,6 @@ xxl:
|
||||
admin:
|
||||
addresses: http://127.0.0.1:9090/xxl-job-admin # 调度中心部署跟地址
|
||||
|
||||
# 广告图片文件
|
||||
adImageFile:
|
||||
filepath: E:\ceshi123\
|
||||
|
||||
--- #################### 服务保障相关配置 ####################
|
||||
|
||||
|
||||
+2
-8
@@ -29,23 +29,17 @@
|
||||
|
||||
<select id="selectAdList"
|
||||
resultType="com.cf.imes.module.system.controller.admin.funds.advertisement.vo.AdvertisementRespVO">
|
||||
|
||||
|
||||
select id,
|
||||
ad_image_path,
|
||||
sort,
|
||||
ad_redirect_url
|
||||
|
||||
from advertisement
|
||||
|
||||
where deleted = false
|
||||
and ad_image_path like concat('%', #{adPosition},'%')
|
||||
and ad_position like concat('%', #{adPosition},'%')
|
||||
and status = #{status}
|
||||
and start_time <= #{now}
|
||||
and end_time >= #{now}
|
||||
order by sort desc , update_time desc
|
||||
|
||||
|
||||
order by sort desc
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user