文件上传https
This commit is contained in:
parent
43694013d7
commit
a7bac83116
|
@ -8,6 +8,8 @@ import com.cultural.heritage.common.ResultUtils;
|
|||
import com.cultural.heritage.constant.UserConstant;
|
||||
import com.cultural.heritage.exception.BusinessException;
|
||||
import com.cultural.heritage.model.entity.Festival;
|
||||
import com.cultural.heritage.model.entity.Good;
|
||||
import com.cultural.heritage.service.good.GoodService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -28,6 +30,10 @@ import java.util.List;
|
|||
public class FestivalController {
|
||||
|
||||
|
||||
@Resource
|
||||
private GoodService goodService;
|
||||
|
||||
|
||||
@Resource(name = "festivalRedisTemplate")
|
||||
private RedisTemplate<String, Festival> redisTemplate;
|
||||
|
||||
|
@ -54,10 +60,54 @@ public class FestivalController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Web端管理员更新节日项的URL
|
||||
* @param festival 节日更新信息
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "Web端管理员更新节日项的URL", description = "参数:节日更新信息,权限:管理员(admin, boss),方法名:updateFestivalElement")
|
||||
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
|
||||
public BaseResponse<Boolean> updateFestivalElement(@RequestBody Festival festival) {
|
||||
if (festival == null || StringUtils.isAnyBlank(festival.getName(), festival.getUrl())) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在参数为空");
|
||||
}
|
||||
// 获取 Redis 中所有的节日数据
|
||||
List<Festival> festivalList = redisTemplate.opsForList().range(FESTIVAL_KEY, 0, -1);
|
||||
if (festivalList == null || festivalList.isEmpty()) {
|
||||
throw new BusinessException(ErrorCode.OPERATION_ERROR, "节日列表为空");
|
||||
}
|
||||
|
||||
// 遍历查找匹配的节日
|
||||
for (Festival fes : festivalList) {
|
||||
if (fes.getName().equals(festival.getName())) {
|
||||
// 更新节日图片 URL
|
||||
fes.setUrl(festival.getUrl()); // 假设 Festival 类有一个 setImageUrl() 方法
|
||||
// 更新 Redis 中的数据
|
||||
redisTemplate.opsForList().set(FESTIVAL_KEY, festivalList.indexOf(fes), fes); // 使用索引更新
|
||||
// 更新商品的节日名称
|
||||
List<Good> goodList = goodService.list();
|
||||
for (Good good : goodList) {
|
||||
String festivalName = good.getFestivalName();
|
||||
String name = festivalName.split(";")[0];
|
||||
if (festival.getName().equals(name)) {
|
||||
good.setFestivalName(good.getFestivalName() + ";" + festival.getUrl());
|
||||
}
|
||||
}
|
||||
goodService.updateBatchById(goodList);
|
||||
return ResultUtils.success(true); // 返回更新成功
|
||||
}
|
||||
}
|
||||
throw new BusinessException(ErrorCode.OPERATION_ERROR, "该节日项不存在");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Web端管理员根据节日名称获取URL
|
||||
* @param festivalName 节日名称
|
||||
* @return 当前节日的url
|
||||
*/
|
||||
@GetMapping("/getUrl")
|
||||
@Operation(summary = "Web端管理员根据节日名称获取URL", description = "参数:节日名称,权限:管理员(admin, boss),方法名:getFestivalUrl")
|
||||
|
|
|
@ -95,6 +95,10 @@ public class GoodController {
|
|||
private CommonService commonService;
|
||||
|
||||
|
||||
@Resource
|
||||
private FestivalService festivalService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端校验常规类商品立即购买
|
||||
|
@ -290,11 +294,11 @@ public class GoodController {
|
|||
List<TimePeriod> timePeriodList = commonService.findByFieldInTargetField(appointmentDateList, timePeriodService, AppointmentDate::getId, "appointmentDateId");
|
||||
|
||||
// 删除预约时间段表中与该商品关联的记录
|
||||
boolean remove = timePeriodService.removeBatchByIds(timePeriodList);
|
||||
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "服务类商品预约时间段删除失败");
|
||||
timePeriodService.removeBatchByIds(timePeriodList);
|
||||
// ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "服务类商品预约时间段删除失败");
|
||||
// 删除预约日期表中与该商品关联的记录
|
||||
boolean isSuccess = appointmentDateService.removeBatchByIds(appointmentDateList);
|
||||
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR, "服务类商品预约日期删除失败");
|
||||
appointmentDateService.removeBatchByIds(appointmentDateList);
|
||||
// ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR, "服务类商品预约日期删除失败");
|
||||
// 删除商品表中的服务类商品
|
||||
boolean result = goodService.removeById(id);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "服务类商品删除失败");
|
||||
|
@ -333,11 +337,11 @@ public class GoodController {
|
|||
// 获取预约时间段列表
|
||||
List<TimePeriod> timePeriodList = commonService.findByFieldInTargetField(appointmentDateList, timePeriodService, AppointmentDate::getId, "appointmentDateId");
|
||||
//删除预约时间段表中与该商品关联的记录
|
||||
boolean success = timePeriodService.removeBatchByIds(timePeriodList);
|
||||
ThrowUtils.throwIf(!success, ErrorCode.OPERATION_ERROR, "服务类商品预约时间段删除失败");
|
||||
timePeriodService.removeBatchByIds(timePeriodList);
|
||||
// ThrowUtils.throwIf(!success, ErrorCode.OPERATION_ERROR, "服务类商品预约时间段删除失败");
|
||||
// 删除预约日期表中与该商品关联的记录
|
||||
boolean remove = appointmentDateService.removeBatchByIds(appointmentDateList);
|
||||
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "服务类商品预约日期删除失败");
|
||||
appointmentDateService.removeBatchByIds(appointmentDateList);
|
||||
// ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "服务类商品预约日期删除失败");
|
||||
// 删除商品表中的服务类商品
|
||||
boolean result = goodService.removeBatchByIds(ids);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "服务类商品删除失败");
|
||||
|
@ -372,10 +376,15 @@ public class GoodController {
|
|||
BigDecimal resourcePrice = resourceGood.getPrice();
|
||||
Good good = new Good();
|
||||
BeanUtils.copyProperties(goodUpdateRequest, good);
|
||||
// 校验
|
||||
if (!resourceGood.getFestivalName().equals(good.getFestivalName())) {
|
||||
String url = festivalService.getUrlByFestivalName(good.getFestivalName());
|
||||
if (url == null) good.setFestivalName("无");
|
||||
else good.setFestivalName(good.getFestivalName() + ";" + url);
|
||||
}
|
||||
// 校验
|
||||
goodService.validGood(good, true);
|
||||
boolean result = goodService.updateById(good);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "实体类商品更新失败");
|
||||
// 如果更新了商品的价格,就需要更新购物车中的小计
|
||||
Long id = good.getId();
|
||||
BigDecimal targetPrice = good.getPrice();
|
||||
|
@ -836,10 +845,10 @@ public class GoodController {
|
|||
List<TimePeriod> timePeriodList = commonService.findByFieldInTargetField(appointmentDateList, timePeriodService, AppointmentDate::getId, "appointmentDateId");
|
||||
// 删除预约时间段表中与该商品关联的记录
|
||||
boolean remove = timePeriodService.removeBatchByIds(timePeriodList);
|
||||
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "服务类商品预约时间段删除失败");
|
||||
// ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "服务类商品预约时间段删除失败");
|
||||
// 删除预约日期表中与该商品关联的记录
|
||||
boolean isSuccess = appointmentDateService.removeBatchByIds(appointmentDateList);
|
||||
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR, "服务类商品预约日期删除失败");
|
||||
// ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR, "服务类商品预约日期删除失败");
|
||||
// 删除服务类商品待处理记录
|
||||
QueryWrapper<PendingServiceGood> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("goodId", id);
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -128,6 +129,7 @@ public class WeChatController {
|
|||
public BaseResponse<List<OfficialAccountArticleVO>> queryAllArticle() {
|
||||
List<OfficialAccountArticle> officialAccountArticleList = weChatOfficialAccountService.list();
|
||||
List<OfficialAccountArticleVO> officialAccountArticleVOS = commonService.convertList(officialAccountArticleList, OfficialAccountArticleVO.class);
|
||||
Collections.reverse(officialAccountArticleVOS);
|
||||
return ResultUtils.success(officialAccountArticleVOS);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package com.cultural.heritage.service.good;
|
||||
|
||||
public interface FestivalService {
|
||||
|
||||
/**
|
||||
* 根据节日名称获取URL
|
||||
*/
|
||||
String getUrlByFestivalName(String festivalName);
|
||||
}
|
|
@ -75,4 +75,5 @@ public interface GoodService extends IService<Good> {
|
|||
* 校验服务类商品预约参数
|
||||
*/
|
||||
void validServiceGoodBookingParameter(BuySingleServiceGoodVerifyRequest buySingleServiceGoodVerifyRequest);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.cultural.heritage.service.good.impl;
|
||||
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.exception.BusinessException;
|
||||
import com.cultural.heritage.model.entity.Festival;
|
||||
import com.cultural.heritage.service.good.FestivalService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FestivalServiceImpl implements FestivalService {
|
||||
|
||||
|
||||
@Resource(name = "festivalRedisTemplate")
|
||||
private RedisTemplate<String, Festival> redisTemplate;
|
||||
|
||||
|
||||
// 节日集合的键
|
||||
private static final String FESTIVAL_KEY = "festivalList";
|
||||
|
||||
|
||||
/**
|
||||
* 根据节日名称获取URL
|
||||
*/
|
||||
@Override
|
||||
public String getUrlByFestivalName(String festivalName) {
|
||||
// 获取 Redis 中所有的节日数据
|
||||
List<Festival> festivalList = redisTemplate.opsForList().range(FESTIVAL_KEY, 0, -1);
|
||||
if (festivalList == null || festivalList.isEmpty()) {
|
||||
throw new BusinessException(ErrorCode.OPERATION_ERROR, "节日列表为空");
|
||||
}
|
||||
|
||||
// 遍历查找匹配的节日
|
||||
for (Festival festival : festivalList) {
|
||||
if (festival.getName().equals(festivalName)) {
|
||||
return festival.getUrl(); // 返回对应的 URL
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user