Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -184,4 +184,6 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode DISHES_RAW_NOT_EXISTS = new ErrorCode(1_002_035_002, "菜品原材料不存在");
|
||||
// ========== 门店 流水 1_002_036_002 ==========
|
||||
ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_002_035_002, "营业统计不存在");
|
||||
// ========== 门店 流水 1_002_037_002 ==========
|
||||
ErrorCode DEVUCE_NOT_EXISTS = new ErrorCode(1_002_035_002, "设备不存在");
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.dishes;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dishes.vo.DishesPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dishes.vo.DishesRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dishes.vo.DishesSaveReqVO;
|
||||
|
@ -57,4 +57,12 @@ public class DishesRespVO {
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "门店编号")
|
||||
private Long carteenId;
|
||||
|
||||
@Schema(description = "总价格")
|
||||
private BigDecimal dishesSumPrice;
|
||||
|
||||
@Schema(description = "菜品总重量")
|
||||
private BigDecimal dishesNumber;
|
||||
}
|
@ -53,4 +53,8 @@ public class DishesSaveReqVO {
|
||||
@Schema(description = "菜品类型", example = "1")
|
||||
private String dishecType;
|
||||
|
||||
@Schema(description = "总价格", example = "1")
|
||||
private BigDecimal dishesSumPrice;
|
||||
@Schema(description = "菜品总重量", example = "1")
|
||||
private BigDecimal dishesNumber;
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package cn.iocoder.yudao.module.system.controller.app.devuce;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dishes.vo.DishesRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevuceSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dishes.DishesDO;
|
||||
import cn.iocoder.yudao.module.system.service.devuce.DevuceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
|
||||
|
||||
@Tag(name = "管理后台 - 设备")
|
||||
@RestController
|
||||
@RequestMapping("/t/devuce")
|
||||
@Validated
|
||||
@PermitAll
|
||||
public class DevuceController {
|
||||
|
||||
@Resource
|
||||
private DevuceService devuceService;
|
||||
|
||||
// @PostMapping("/create")
|
||||
// @Operation(summary = "创建设备")
|
||||
// public CommonResult<Long> createDevuce(@Valid @RequestBody DevuceSaveReqVO createReqVO) {
|
||||
// return success(devuceService.createDevuce(createReqVO));
|
||||
// }
|
||||
/**
|
||||
* @Description: 进行解绑与绑定操作
|
||||
* @Author: qjq
|
||||
* @Date: 2024/4/7 15:23
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新设备")
|
||||
public CommonResult<Boolean> updateDevuce(@Valid @RequestBody DevuceSaveReqVO updateReqVO) {
|
||||
devuceService.updateDevuce(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
// @DeleteMapping("/delete")
|
||||
// @Operation(summary = "删除设备")
|
||||
// @Parameter(name = "id", description = "编号", required = true)
|
||||
// @PreAuthorize("@ss.hasPermission('t:devuce:delete')")
|
||||
// public CommonResult<Boolean> deleteDevuce(@RequestParam("id") Long id) {
|
||||
// devuceService.deleteDevuce(id);
|
||||
// return success(true);
|
||||
// }
|
||||
|
||||
// @GetMapping("/get")
|
||||
// @Operation(summary = "获得设备")
|
||||
// @Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
// public CommonResult<DevuceRespVO> getDevuce(@RequestParam("id") Long id) {
|
||||
// DevuceDO devuce = devuceService.getDevuce(id);
|
||||
// return success(BeanUtils.toBean(devuce, DevuceRespVO.class));
|
||||
// }
|
||||
@GetMapping("/dishes/list")
|
||||
@Operation(summary = "获得菜品列表")
|
||||
public CommonResult<List<DishesRespVO>> getDishesList(@RequestParam("carteenId") Long carteenId) {
|
||||
List<DishesDO> dishesList = devuceService.getDishesList(carteenId);
|
||||
return success(BeanUtils.toBean(dishesList, DishesRespVO.class));
|
||||
}
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得绑定的菜品")
|
||||
public CommonResult<DishesRespVO> getDevuceList(@RequestParam("sn")String sn) {
|
||||
DishesDO devuceList = devuceService.getDevuceList(sn);
|
||||
return success(BeanUtils.toBean(devuceList, DishesRespVO.class));
|
||||
}
|
||||
// @GetMapping("/page")
|
||||
// @Operation(summary = "获得设备分页")
|
||||
// public CommonResult<PageResult<DevuceRespVO>> getDevucePage(@Valid DevucePageReqVO pageReqVO) {
|
||||
// PageResult<DevuceDO> pageResult = devuceService.getDevucePage(pageReqVO);
|
||||
// return success(BeanUtils.toBean(pageResult, DevuceRespVO.class));
|
||||
// }
|
||||
|
||||
// @GetMapping("/export-excel")
|
||||
// @Operation(summary = "导出设备 Excel")
|
||||
// @PreAuthorize("@ss.hasPermission('t:devuce:export')")
|
||||
// @OperateLog(type = EXPORT)
|
||||
// public void exportDevuceExcel(@Valid DevucePageReqVO pageReqVO,
|
||||
// HttpServletResponse response) throws IOException {
|
||||
// pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
// List<DevuceDO> list = devuceService.getDevucePage(pageReqVO).getList();
|
||||
// // 导出 Excel
|
||||
// ExcelUtils.write(response, "设备.xls", "数据", DevuceRespVO.class,
|
||||
// BeanUtils.toBean(list, DevuceRespVO.class));
|
||||
// }
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package cn.iocoder.yudao.module.system.controller.app.devuce.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 设备分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class DevucePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "设备SN码")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(description = "菜品id", example = "17970")
|
||||
private Long dishesId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "是否绑定")
|
||||
private Boolean bind;
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.system.controller.app.devuce.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 设备 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class DevuceRespVO {
|
||||
|
||||
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11545")
|
||||
@ExcelProperty("设备编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "设备SN码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("设备SN码")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(description = "菜品id", example = "17970")
|
||||
@ExcelProperty("菜品id")
|
||||
private Long dishesId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "是否绑定", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("是否绑定")
|
||||
private Boolean bind;
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.system.controller.app.devuce.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 设备新增/修改 Request VO")
|
||||
@Data
|
||||
public class DevuceSaveReqVO {
|
||||
|
||||
@Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11545")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "设备SN码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "设备SN码不能为空")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(description = "菜品id", example = "17970")
|
||||
private Long dishesId;
|
||||
|
||||
@Schema(description = "是否绑定", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否绑定不能为空")
|
||||
private Boolean bind;
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.devuce;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 设备 DO
|
||||
*
|
||||
* @author 开发账号
|
||||
*/
|
||||
@TableName("t_devuce")
|
||||
@KeySequence("t_devuce_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DevuceDO extends BaseDO {
|
||||
public static final Integer BIND=1;
|
||||
public static final Integer LAPSE=0;
|
||||
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 设备SN码
|
||||
*/
|
||||
private String deviceSn;
|
||||
/**
|
||||
* 菜品id
|
||||
*/
|
||||
private Long dishesId;
|
||||
/**
|
||||
* 是否绑定
|
||||
*/
|
||||
private Boolean bind;
|
||||
|
||||
}
|
@ -71,4 +71,12 @@ public class DishesDO extends BaseDO {
|
||||
* 门店编号
|
||||
*/
|
||||
private Long carteenId;
|
||||
/**
|
||||
* 总价格
|
||||
*/
|
||||
private BigDecimal dishesSumPrice;
|
||||
/**
|
||||
* 菜品总重量
|
||||
*/
|
||||
private BigDecimal dishesNumber;
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.devuce;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevucePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.devuce.DevuceDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 设备 Mapper
|
||||
*
|
||||
* @author 开发账号
|
||||
*/
|
||||
@Mapper
|
||||
public interface DevuceMapper extends BaseMapperX<DevuceDO> {
|
||||
|
||||
default PageResult<DevuceDO> selectPage(DevucePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<DevuceDO>()
|
||||
.eqIfPresent(DevuceDO::getDeviceSn, reqVO.getDeviceSn())
|
||||
.eqIfPresent(DevuceDO::getDishesId, reqVO.getDishesId())
|
||||
.betweenIfPresent(DevuceDO::getCreateTime, reqVO.getCreateTime())
|
||||
.eqIfPresent(DevuceDO::getBind, reqVO.getBind())
|
||||
.orderByDesc(DevuceDO::getId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package cn.iocoder.yudao.module.system.service.devuce;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevucePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevuceSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.devuce.DevuceDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dishes.DishesDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备 Service 接口
|
||||
*
|
||||
* @author 开发账号
|
||||
*/
|
||||
public interface DevuceService {
|
||||
|
||||
/**
|
||||
* 创建设备
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createDevuce(@Valid DevuceSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新设备
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDevuce(@Valid DevuceSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDevuce(Long id);
|
||||
|
||||
/**
|
||||
* 获得设备
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 设备
|
||||
*/
|
||||
DevuceDO getDevuce(Long id);
|
||||
|
||||
/**
|
||||
* 获得设备分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 设备分页
|
||||
*/
|
||||
PageResult<DevuceDO> getDevucePage(DevucePageReqVO pageReqVO);
|
||||
DishesDO getDevuceList(String sn);
|
||||
List<DishesDO> getDishesList(Long carteenId);
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package cn.iocoder.yudao.module.system.service.devuce;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevucePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevuceSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.devuce.DevuceDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dishes.DishesDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.devuce.DevuceMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dishes.DishesMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 设备 Service 实现类
|
||||
*
|
||||
* @author 开发账号
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class DevuceServiceImpl implements DevuceService {
|
||||
|
||||
@Resource
|
||||
private DevuceMapper devuceMapper;
|
||||
@Resource
|
||||
private DishesMapper dishesMapper;
|
||||
|
||||
@Override
|
||||
public Long createDevuce(DevuceSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
DevuceDO devuce = BeanUtils.toBean(createReqVO, DevuceDO.class);
|
||||
devuceMapper.insert(devuce);
|
||||
// 返回
|
||||
return devuce.getId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateDevuce(DevuceSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
if (devuceMapper.selectOne(new LambdaQueryWrapperX<DevuceDO>()
|
||||
.eqIfPresent(DevuceDO::getDeviceSn,updateReqVO.getDeviceSn())) == null) {
|
||||
createDevuce(updateReqVO);
|
||||
}else{
|
||||
devuceMapper.update(new LambdaUpdateWrapper<DevuceDO>()
|
||||
.set(DevuceDO::getBind,updateReqVO.getBind())
|
||||
.set(DevuceDO::getDeleted,Boolean.TRUE)
|
||||
.eq(DevuceDO::getDeviceSn,updateReqVO.getDeviceSn()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDevuce(Long id) {
|
||||
// 校验存在
|
||||
validateDevuceExists(id);
|
||||
// 删除
|
||||
devuceMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateDevuceExists(Long id) {
|
||||
if (devuceMapper.selectById(id) == null) {
|
||||
throw exception(ErrorCodeConstants.DEVUCE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DevuceDO getDevuce(Long id) {
|
||||
return devuceMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DevuceDO> getDevucePage(DevucePageReqVO pageReqVO) {
|
||||
return devuceMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DishesDO getDevuceList(String sn) {
|
||||
//获取当前设备绑定的菜品id
|
||||
DevuceDO devuceDO = devuceMapper.selectOne(new LambdaQueryWrapperX<DevuceDO>()
|
||||
.eq(DevuceDO::getDeviceSn, sn));
|
||||
if(ObjUtil.isEmpty(devuceDO)){
|
||||
return null;
|
||||
}else{
|
||||
//获取菜品信息
|
||||
return dishesMapper.selectOne(new LambdaQueryWrapperX<DishesDO>()
|
||||
.eqIfPresent(DishesDO::getId, devuceDO.getDishesId()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DishesDO> getDishesList(Long carteenId) {
|
||||
//获取已绑定的菜品id
|
||||
List<Long> collect = devuceMapper.selectList(new LambdaQueryWrapperX<DevuceDO>()
|
||||
.eq(DevuceDO::getBind, DevuceDO.BIND))
|
||||
.stream()
|
||||
.map(DevuceDO::getDishesId).collect(Collectors.toList());
|
||||
|
||||
return dishesMapper.selectList(new LambdaQueryWrapperX<DishesDO>()
|
||||
.notIn(DishesDO::getId, collect));
|
||||
}
|
||||
}
|
@ -1,22 +1,19 @@
|
||||
package cn.iocoder.yudao.module.system.service.dishes;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dishes.vo.DishesPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dishes.vo.DishesSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dishes.DishesDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dishes.DishesMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
|
||||
import com.xingyuv.captcha.util.Base64Utils;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
|
||||
import java.util.Base64;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
@ -37,6 +34,16 @@ public class DishesServiceImpl implements DishesService {
|
||||
// 插入
|
||||
DishesDO dishes = BeanUtils.toBean(createReqVO, DishesDO.class);
|
||||
dishes.setDeleted(Boolean.FALSE);
|
||||
//计算每g多少钱
|
||||
BigDecimal dishesSumPrice = createReqVO.getDishesSumPrice();
|
||||
BigDecimal dishesNumber = createReqVO.getDishesNumber();
|
||||
BigDecimal div = NumberUtil.div(dishesSumPrice, dishesNumber, 2);
|
||||
//避免计算出每克价格约 为0
|
||||
if(div.floatValue() <= 0.00f){
|
||||
dishes.setDishesBasePrice(new BigDecimal("0.01"));
|
||||
}else{
|
||||
dishes.setDishesBasePrice(div);
|
||||
}
|
||||
dishesMapper.insert(dishes);
|
||||
// 返回
|
||||
return dishes.getId();
|
||||
|
Reference in New Issue
Block a user