Commit 1b5b760f by 章家宝

feat:新增拍场接口改未统一返回值

1 parent fc818a19
...@@ -139,7 +139,7 @@ public class AuctionController { ...@@ -139,7 +139,7 @@ public class AuctionController {
* @return * @return
*/ */
@PostMapping("addAuction") @PostMapping("addAuction")
public Auction addAuction(@Valid @RequestBody Auction auction, Authentication authentication) throws FieldException { public BaseResp<Boolean> addAuction(@Valid @RequestBody Auction auction, Authentication authentication) throws FieldException {
User user = (User) authentication.getPrincipal(); User user = (User) authentication.getPrincipal();
return auctionService.addAuction(auction, user); return auctionService.addAuction(auction, user);
} }
...@@ -151,7 +151,7 @@ public class AuctionController { ...@@ -151,7 +151,7 @@ public class AuctionController {
* @return * @return
*/ */
@PostMapping("updateAuction") @PostMapping("updateAuction")
public Auction updateAuction(@Valid @RequestBody Auction auction) throws FieldException { public BaseResp<Boolean> updateAuction(@Valid @RequestBody Auction auction) throws FieldException {
return auctionService.updateAuction(auction); return auctionService.updateAuction(auction);
} }
......
...@@ -133,18 +133,21 @@ public class AuctionService extends AbstractAuctionService { ...@@ -133,18 +133,21 @@ public class AuctionService extends AbstractAuctionService {
* @return 拍卖场次实例对象 * @return 拍卖场次实例对象
*/ */
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public synchronized Auction addAuction(Auction auction, User user) throws FieldException { public synchronized BaseResp<Boolean> addAuction(Auction auction, User user) throws FieldException {
List<AuctionVehicle> auctionVehicles = auction.getAuctionVehicles(); List<AuctionVehicle> auctionVehicles = auction.getAuctionVehicles();
if (CollectionUtils.isEmpty(auctionVehicles)) { if (CollectionUtils.isEmpty(auctionVehicles)) {
throw new FieldException("sourceNos", "拍场下没有车辆信息,请先添加车辆信息"); return BaseResp.fail("拍场下没有车辆信息,请先添加车辆信息");
} }
List<Integer> vehicleIds = auctionVehicles.stream().map(p -> p.getVehicle().getVehicleId()).toList(); List<Integer> vehicleIds = auctionVehicles.stream().map(p -> p.getVehicle().getVehicleId()).toList();
List<String> sourceNos = vehicleDao.findBySourceNoVehicleStateNot(vehicleIds, Vehicle.VehicleState.PRICED); List<String> sourceNos = vehicleDao.findBySourceNoVehicleStateNot(vehicleIds, Vehicle.VehicleState.PRICED);
if (!CollectionUtils.isEmpty(sourceNos)) { if (!CollectionUtils.isEmpty(sourceNos)) {
String join = String.join(",", sourceNos); String join = String.join(",", sourceNos);
throw new FieldException("sourceNos", sourceNos, "车源号:" + join + "的车辆状态不是待关联拍卖状态,请重新选择车辆"); return BaseResp.fail("车源号:" + join + "的车辆状态不是待关联拍卖状态,请重新选择车辆");
}
BaseResp baseResp = checkAuctionConfig(auction, auctionVehicles);
if (!baseResp.isSuccess()) {
return baseResp;
} }
checkAuctionConfig(auction, auctionVehicles);
auction.setAccessScope(CollectionUtils.isEmpty(auction.getAccountTags()) ? Auction.AccessScope.GLOBAL : Auction.AccessScope.TAGS); auction.setAccessScope(CollectionUtils.isEmpty(auction.getAccountTags()) ? Auction.AccessScope.GLOBAL : Auction.AccessScope.TAGS);
if (!CollectionUtils.isEmpty(auction.getAccountTags())) { if (!CollectionUtils.isEmpty(auction.getAccountTags())) {
auction.setAccountTags(new HashSet<>(accountTagDao.findByEntityIds(auction.getAccountTags()))); auction.setAccountTags(new HashSet<>(accountTagDao.findByEntityIds(auction.getAccountTags())));
...@@ -164,13 +167,13 @@ public class AuctionService extends AbstractAuctionService { ...@@ -164,13 +167,13 @@ public class AuctionService extends AbstractAuctionService {
// 发送通知消息 // 发送通知消息
sendNoticeMessage(NoticeTemplate.TemplateType.AUCTION_AUDIT, Map.of(NoticeField.AUCTION_NAME, auctionDb.getAuctionName(), NoticeField.AUCTION_START_TIME, DateTimeUtils.DATE_TIME_NO_SECOND_FORMATTER.format(auctionDb.getAuctionStartTime()), NoticeField.VEHICLE_COUNT, auctionDb.getVehicleCount(), NoticeField.AUCTION_USER_NAME, user.getRealName(), NoticeField.AUCTION_CREATE_TIME, DateTimeUtils.DATE_TIME_NO_SECOND_FORMATTER.format(auctionDb.getCreateTime()))); sendNoticeMessage(NoticeTemplate.TemplateType.AUCTION_AUDIT, Map.of(NoticeField.AUCTION_NAME, auctionDb.getAuctionName(), NoticeField.AUCTION_START_TIME, DateTimeUtils.DATE_TIME_NO_SECOND_FORMATTER.format(auctionDb.getAuctionStartTime()), NoticeField.VEHICLE_COUNT, auctionDb.getVehicleCount(), NoticeField.AUCTION_USER_NAME, user.getRealName(), NoticeField.AUCTION_CREATE_TIME, DateTimeUtils.DATE_TIME_NO_SECOND_FORMATTER.format(auctionDb.getCreateTime())));
return auctionDb; return BaseResp.success(true);
} }
/** /**
* 检查拍场配置 * 检查拍场配置
*/ */
private static void checkAuctionConfig(Auction auction, List<AuctionVehicle> auctionVehicles) throws FieldException { private static BaseResp<Boolean> checkAuctionConfig(Auction auction, List<AuctionVehicle> auctionVehicles) throws FieldException {
if (auction.getAuctionType() == AuctionType.LIGHT && auction.getAuctionMode() == 2) { if (auction.getAuctionType() == AuctionType.LIGHT && auction.getAuctionMode() == 2) {
// 明拍, 轮询出价 // 明拍, 轮询出价
// 获取所有拍卖车辆的最低保留价 // 获取所有拍卖车辆的最低保留价
...@@ -181,17 +184,17 @@ public class AuctionService extends AbstractAuctionService { ...@@ -181,17 +184,17 @@ public class AuctionService extends AbstractAuctionService {
} }
String extraJson = auction.getExtraJson(); String extraJson = auction.getExtraJson();
if (StringUtils.isBlank(extraJson)) { if (StringUtils.isBlank(extraJson)) {
throw new FieldException("extraJson", "请填写轮询出价参数"); return BaseResp.fail("请填写轮询出价参数");
} }
LightPollingBidConfigDTO dto = LightPollingBidConfigDTO.fromJson(extraJson); LightPollingBidConfigDTO dto = LightPollingBidConfigDTO.fromJson(extraJson);
if (!dto.isValid()) { if (!dto.isValid()) {
log.info("轮询出价配置错误{}", extraJson); log.info("轮询出价配置错误{}", extraJson);
throw new FieldException("extraJson", "明拍竞价配置错误"); return BaseResp.fail("明拍竞价配置错误");
} }
Integer nearReservePriceThreshold = dto.getNearReservePriceThreshold(); Integer nearReservePriceThreshold = dto.getNearReservePriceThreshold();
if (nearReservePriceThreshold < 0 || nearReservePriceThreshold > minReservePrice) { if (nearReservePriceThreshold < 0 || nearReservePriceThreshold > minReservePrice) {
log.info("nearReservePriceThreshold:{} < minReservePrice:{}", nearReservePriceThreshold, minReservePrice); log.info("nearReservePriceThreshold:{} < minReservePrice:{}", nearReservePriceThreshold, minReservePrice);
throw new FieldException("extraJson", "设定的保留价提醒阈值:最小0,最大不超过当前拍场中车辆的最低价保留价"); return BaseResp.fail("设定的保留价提醒阈值:最小0,最大不超过当前拍场中车辆的最低价保留价");
} }
// 重置延时:最小值为0,最大值小于等于拍卖持续时间。 // 重置延时:最小值为0,最大值小于等于拍卖持续时间。
Integer resetDelay = dto.getResetDelay(); Integer resetDelay = dto.getResetDelay();
...@@ -200,9 +203,10 @@ public class AuctionService extends AbstractAuctionService { ...@@ -200,9 +203,10 @@ public class AuctionService extends AbstractAuctionService {
long secondsDiff = duration.getSeconds(); long secondsDiff = duration.getSeconds();
if (resetDelay < 0 || resetDelay > secondsDiff) { if (resetDelay < 0 || resetDelay > secondsDiff) {
log.info("重置延时:最小0,最大小于等于拍卖持续时间 resetDelay:{} < 0 or > secondsDiff:{}", resetDelay, secondsDiff); log.info("重置延时:最小0,最大小于等于拍卖持续时间 resetDelay:{} < 0 or > secondsDiff:{}", resetDelay, secondsDiff);
throw new FieldException("extraJson", "重置延时:最小0,最大小于等于拍卖持续时间"); return BaseResp.fail("重置延时:最小0,最大小于等于拍卖持续时间");
} }
} }
return BaseResp.success(true);
} }
/** /**
...@@ -212,15 +216,18 @@ public class AuctionService extends AbstractAuctionService { ...@@ -212,15 +216,18 @@ public class AuctionService extends AbstractAuctionService {
* @return 拍卖场次实例对象 * @return 拍卖场次实例对象
*/ */
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public synchronized Auction updateAuction(Auction auction) throws FieldException { public synchronized BaseResp<Boolean> updateAuction(Auction auction) throws FieldException {
List<AuctionVehicle> auctionVehicles = auction.getAuctionVehicles(); List<AuctionVehicle> auctionVehicles = auction.getAuctionVehicles();
if (CollectionUtils.isEmpty(auctionVehicles)) { if (CollectionUtils.isEmpty(auctionVehicles)) {
throw new FieldException("sourceNos", "拍场下没有车辆信息,请先添加车辆信息"); return BaseResp.fail("拍场下没有车辆信息,请先添加车辆信息");
} }
if (auction.getAuctionMode() != 2) { if (auction.getAuctionMode() != 2) {
auction.setExtraJson(null); auction.setExtraJson(null);
} }
checkAuctionConfig(auction, auctionVehicles); BaseResp baseResp = checkAuctionConfig(auction, auctionVehicles);
if (!baseResp.isSuccess()) {
return baseResp;
}
Auction auctionDb = auctionDao.updateById(auction, Auction_.auctionName, Auction_.user, Auction_.previewStartTime, Auction_.auctionStartTime, Auction_.auctionEndTime, Auction_.deposit, Auction_.auctionType, Auction_.beforeEndMinute, Auction_.delayMinute, Auction_.cities, Auction_.remark, Auction_.extraJson, Auction_.auctionMode); Auction auctionDb = auctionDao.updateById(auction, Auction_.auctionName, Auction_.user, Auction_.previewStartTime, Auction_.auctionStartTime, Auction_.auctionEndTime, Auction_.deposit, Auction_.auctionType, Auction_.beforeEndMinute, Auction_.delayMinute, Auction_.cities, Auction_.remark, Auction_.extraJson, Auction_.auctionMode);
auctionDb.setAuctionDate(auctionDb.getAuctionStartTime().toLocalDate()); auctionDb.setAuctionDate(auctionDb.getAuctionStartTime().toLocalDate());
...@@ -240,7 +247,7 @@ public class AuctionService extends AbstractAuctionService { ...@@ -240,7 +247,7 @@ public class AuctionService extends AbstractAuctionService {
List<String> sourceNos = vehicleDao.findBySourceNoVehicleStateNot(vehicleIds, Vehicle.VehicleState.PRICED); List<String> sourceNos = vehicleDao.findBySourceNoVehicleStateNot(vehicleIds, Vehicle.VehicleState.PRICED);
if (!CollectionUtils.isEmpty(sourceNos)) { if (!CollectionUtils.isEmpty(sourceNos)) {
String join = String.join(",", sourceNos); String join = String.join(",", sourceNos);
throw new FieldException("sourceNos", sourceNos, "车源号:" + join + "的车辆状态不是待关联拍卖状态,请重新选择车辆"); return BaseResp.fail("车源号:" + join + "的车辆状态不是待关联拍卖状态,请重新选择车辆");
} }
} }
for (AuctionVehicle auctionVehicle : auctionVehicles) { for (AuctionVehicle auctionVehicle : auctionVehicles) {
...@@ -269,7 +276,7 @@ public class AuctionService extends AbstractAuctionService { ...@@ -269,7 +276,7 @@ public class AuctionService extends AbstractAuctionService {
auctionVehicleDao.deleteAll(auctionVehicleDbs); auctionVehicleDao.deleteAll(auctionVehicleDbs);
} }
auctionDb.setAuditState(AuditState.UNAUDITED); auctionDb.setAuditState(AuditState.UNAUDITED);
return auctionDb; return BaseResp.success(true);
} }
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!