feat(foundations):新增区域服务 1.价格更新 2.状态更改 3.草稿删除 4.热门设置 的功能
This commit is contained in:
parent
99b7fd6aca
commit
1db850a6cf
@ -6,11 +6,14 @@ import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
|
|||||||
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
|
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
|
||||||
import com.jzo2o.foundations.service.IServeService;
|
import com.jzo2o.foundations.service.IServeService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,4 +39,60 @@ public class ServeController {
|
|||||||
public void add(@RequestBody List<ServeUpsertReqDTO> serveItems) {
|
public void add(@RequestBody List<ServeUpsertReqDTO> serveItems) {
|
||||||
serveService.addBatch(serveItems);
|
serveService.addBatch(serveItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
@ApiOperation("更新区域下的服务的价格")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
|
||||||
|
@ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
|
||||||
|
})
|
||||||
|
public void updatePrice(@PathVariable("id") Long id,
|
||||||
|
@RequestParam("price") BigDecimal price) {
|
||||||
|
serveService.updatePrice(id, price);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/onSale/{id}")
|
||||||
|
@ApiOperation("区域服务上架")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
|
||||||
|
})
|
||||||
|
public void onSale(@PathVariable("id") Long id) {
|
||||||
|
serveService.updateOnSale(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/offSale/{id}")
|
||||||
|
@ApiOperation("区域服务上架")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
|
||||||
|
})
|
||||||
|
public void offSale(@PathVariable("id") Long id) {
|
||||||
|
serveService.updateOffSale(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
@ApiOperation("删除区域下的服务")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
|
||||||
|
})
|
||||||
|
public void delete(@PathVariable("id") Long id) {
|
||||||
|
serveService.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/onHot/{id}")
|
||||||
|
@ApiOperation("设置区域服务热门")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
|
||||||
|
})
|
||||||
|
public void onHot(@PathVariable("id") Long id) {
|
||||||
|
serveService.updateOnHot(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/offHot/{id}")
|
||||||
|
@ApiOperation("设置区域服务热门")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
|
||||||
|
})
|
||||||
|
public void offHot(@PathVariable("id") Long id) {
|
||||||
|
serveService.updateOffHot(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package com.jzo2o.foundations.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 热门状态枚举类
|
||||||
|
* @author JIAN
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum HotStatusEnum {
|
||||||
|
ON_HOT(1, "热门状态"),
|
||||||
|
OFF_HOT(0, "非热门状态");
|
||||||
|
private final int status;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
public boolean equals(Integer status) {
|
||||||
|
return this.status == status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(HotStatusEnum hotStatusEnum) {
|
||||||
|
return hotStatusEnum != null && hotStatusEnum.status == this.getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@ import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
|
|||||||
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
|
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
|
||||||
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
|
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,4 +26,34 @@ public interface IServeService extends IService<Serve> {
|
|||||||
* @param serveItems 服务项集合
|
* @param serveItems 服务项集合
|
||||||
*/
|
*/
|
||||||
void addBatch(List<ServeUpsertReqDTO> serveItems);
|
void addBatch(List<ServeUpsertReqDTO> serveItems);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新指定服务id的价格
|
||||||
|
*/
|
||||||
|
Serve updatePrice(Long id, BigDecimal price);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置指定服务上架
|
||||||
|
*/
|
||||||
|
Serve updateOnSale(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置指定的服务下架
|
||||||
|
*/
|
||||||
|
Serve updateOffSale(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除指定的服务
|
||||||
|
*/
|
||||||
|
void deleteById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置指定服务热门
|
||||||
|
*/
|
||||||
|
Serve updateOnHot(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消指定服务热门
|
||||||
|
*/
|
||||||
|
Serve updateOffHot(Long id);
|
||||||
}
|
}
|
||||||
@ -1,11 +1,13 @@
|
|||||||
package com.jzo2o.foundations.service.impl;
|
package com.jzo2o.foundations.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.jzo2o.common.expcetions.CommonException;
|
||||||
import com.jzo2o.common.expcetions.ForbiddenOperationException;
|
import com.jzo2o.common.expcetions.ForbiddenOperationException;
|
||||||
import com.jzo2o.common.model.PageResult;
|
import com.jzo2o.common.model.PageResult;
|
||||||
import com.jzo2o.common.utils.BeanUtils;
|
import com.jzo2o.common.utils.BeanUtils;
|
||||||
import com.jzo2o.common.utils.ObjectUtils;
|
import com.jzo2o.common.utils.ObjectUtils;
|
||||||
import com.jzo2o.foundations.enums.FoundationStatusEnum;
|
import com.jzo2o.foundations.enums.FoundationStatusEnum;
|
||||||
|
import com.jzo2o.foundations.enums.HotStatusEnum;
|
||||||
import com.jzo2o.foundations.mapper.RegionMapper;
|
import com.jzo2o.foundations.mapper.RegionMapper;
|
||||||
import com.jzo2o.foundations.mapper.ServeItemMapper;
|
import com.jzo2o.foundations.mapper.ServeItemMapper;
|
||||||
import com.jzo2o.foundations.mapper.ServeMapper;
|
import com.jzo2o.foundations.mapper.ServeMapper;
|
||||||
@ -20,6 +22,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,6 +67,142 @@ public class ServeServiceImpl extends ServiceImpl<ServeMapper, Serve> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id获取服务不存在则抛出异常
|
||||||
|
* @throws ForbiddenOperationException 拒绝异常
|
||||||
|
*/
|
||||||
|
private Serve getServeByIdIfExist(Long id) throws ForbiddenOperationException {
|
||||||
|
Serve serve = baseMapper.selectById(id);
|
||||||
|
if (ObjectUtils.isEmpty(serve)) {
|
||||||
|
throw new ForbiddenOperationException("所选服务不存在");
|
||||||
|
}
|
||||||
|
return serve;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Serve updatePrice(Long id, BigDecimal price) {
|
||||||
|
// 区域服务检验
|
||||||
|
Serve serve = getServeByIdIfExist(id);
|
||||||
|
|
||||||
|
if (!lambdaUpdate()
|
||||||
|
.eq(Serve::getId, id)
|
||||||
|
.set(Serve::getPrice, price)
|
||||||
|
.update()) {
|
||||||
|
throw new CommonException("价格更新失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
serve.setPrice(price);
|
||||||
|
return serve;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Serve updateOnSale(Long id) {
|
||||||
|
// 区域服务检验
|
||||||
|
Serve serve = getServeByIdIfExist(id);
|
||||||
|
|
||||||
|
Integer saleStatus = serve.getSaleStatus();
|
||||||
|
if (!ObjectUtils.equal(saleStatus, FoundationStatusEnum.INIT.getStatus())
|
||||||
|
&& !ObjectUtils.equal(saleStatus, FoundationStatusEnum.DISABLE.getStatus())) {
|
||||||
|
throw new ForbiddenOperationException("草稿或下架状态才能上架");
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer activeStatus = serveItemMapper.selectById(serve.getServeItemId()).getActiveStatus();
|
||||||
|
if (!ObjectUtils.equal(activeStatus, FoundationStatusEnum.ENABLE.getStatus())) {
|
||||||
|
throw new ForbiddenOperationException("对应的服务项未启用不能上架");
|
||||||
|
}
|
||||||
|
|
||||||
|
int enableStatus = FoundationStatusEnum.ENABLE.getStatus();
|
||||||
|
if (!lambdaUpdate()
|
||||||
|
.eq(Serve::getId, id)
|
||||||
|
.set(Serve::getSaleStatus, enableStatus)
|
||||||
|
.update()) {
|
||||||
|
throw new CommonException("状态更新失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
serve.setSaleStatus(enableStatus);
|
||||||
|
return serve;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Serve updateOffSale(Long id) {
|
||||||
|
// 区域服务检验
|
||||||
|
Serve serve = getServeByIdIfExist(id);
|
||||||
|
|
||||||
|
Integer saleStatus = serve.getSaleStatus();
|
||||||
|
if (!ObjectUtils.equal(saleStatus, FoundationStatusEnum.ENABLE.getStatus())) {
|
||||||
|
throw new ForbiddenOperationException("服务为上架状态才能下架");
|
||||||
|
}
|
||||||
|
|
||||||
|
int disableStatus = FoundationStatusEnum.DISABLE.getStatus();
|
||||||
|
if (!lambdaUpdate()
|
||||||
|
.eq(Serve::getId, id)
|
||||||
|
.set(Serve::getSaleStatus, disableStatus)
|
||||||
|
.update()) {
|
||||||
|
throw new CommonException("状态更新失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
serve.setSaleStatus(disableStatus);
|
||||||
|
return serve;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteById(Long id) {
|
||||||
|
Serve serve = getServeByIdIfExist(id);
|
||||||
|
|
||||||
|
Integer saleStatus = serve.getSaleStatus();
|
||||||
|
if (!ObjectUtils.equal(saleStatus, FoundationStatusEnum.INIT.getStatus())) {
|
||||||
|
throw new ForbiddenOperationException("服务为草稿状态才能删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
baseMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Serve updateOnHot(Long id) {
|
||||||
|
Serve serve = getServeByIdIfExist(id);
|
||||||
|
|
||||||
|
if (serve.getIsHot() != HotStatusEnum.OFF_HOT.getStatus()) {
|
||||||
|
throw new RuntimeException("请勿重复设置热门");
|
||||||
|
}
|
||||||
|
|
||||||
|
int hotStatus = HotStatusEnum.ON_HOT.getStatus();
|
||||||
|
if (!lambdaUpdate()
|
||||||
|
.eq(Serve::getId, id)
|
||||||
|
.set(Serve::getIsHot, hotStatus)
|
||||||
|
.update()) {
|
||||||
|
throw new CommonException("热门状态更新失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
serve.setIsHot(hotStatus);
|
||||||
|
return serve;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Serve updateOffHot(Long id) {
|
||||||
|
Serve serve = getServeByIdIfExist(id);
|
||||||
|
|
||||||
|
if (serve.getIsHot() != HotStatusEnum.ON_HOT.getStatus()) {
|
||||||
|
throw new RuntimeException("请勿重复取消热门");
|
||||||
|
}
|
||||||
|
|
||||||
|
int hotStatus = HotStatusEnum.OFF_HOT.getStatus();
|
||||||
|
if (!lambdaUpdate()
|
||||||
|
.eq(Serve::getId, id)
|
||||||
|
.set(Serve::getIsHot, hotStatus)
|
||||||
|
.update()) {
|
||||||
|
throw new CommonException("热门状态更新失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
serve.setIsHot(hotStatus);
|
||||||
|
return serve;
|
||||||
|
}
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ServeItemMapper serveItemMapper;
|
private ServeItemMapper serveItemMapper;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user