Explorar o código

feat:“优化花型修改接口“

soobin hai 1 ano
pai
achega
1018aafc5a

+ 52 - 15
src/main/java/com/szwl/controller/IndexController.java

@@ -100,6 +100,9 @@ public class IndexController {
     @Resource
     TLocationCheckService locationCheckService;
 
+    @Autowired
+    TGoodsDataService goodsDataService;
+
     private static final String appid = "07784f5fedb508046c841b391005b7de";
 
     @ApiOperation(value = "心跳")
@@ -692,6 +695,34 @@ public class IndexController {
     }
 
     /**
+     * 添加商品
+     * @param id
+     * @param machineType
+     * @param number
+     */
+    private void saveProduct(Long id, String machineType, Integer number) {
+        LambdaQueryWrapper<TGoodsData> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(TGoodsData::getNumber, number);
+        wrapper.eq(TGoodsData::getMachineType, machineType);
+        TGoodsData goodsData = goodsDataService.getOne(wrapper);
+        String goods = goodsData.getGoods();
+        String[] str = goods.split(",");
+
+        for (int i = 0; i < str.length; i++) {
+            TProduct product = new TProduct();
+            product.setCreateDate(new Date());
+            product.setModifyDate(new Date());
+            product.setEquipmentId(id);
+            String[] split = str[i].split("-");
+            product.setProductName(split[0]);
+            product.setNo(split[1]);
+            product.setRmbPrice(BigDecimal.ZERO);
+            product.setCodePrice(BigDecimal.ZERO);
+            productService.save(product);
+        }
+    }
+
+    /**
      * 添加棉花糖产品
      *
      * @param id
@@ -945,22 +976,28 @@ public class IndexController {
             for (TProduct product : productList) {
                 productService.removeById(product.getId());
             }
-            //创建花型
-            if (number.equals("18")) {
-                saveProduct(id);
-            }
-            if (number.equals("22")) {
-                saveProductMG22(id);
-            }
-            if (number.equals("26")) {
-                saveProductMG26(id);
-            }
-            if (number.equals("30")) {
-                saveProductMG1(id);
-            }
-            if (number.equals("42")) {
-                saveProductMG42(id);
+            // 机器类型
+            String machineType = equipment.getMachineType();
+            if(StringUtils.isEmpty(equipment.getMachineType())) {
+                machineType = "0";
             }
+            //创建花型
+            saveProduct(id, machineType, Integer.parseInt(number));
+//            if (number.equals("18")) {
+//                saveProduct(id);
+//            }
+//            if (number.equals("22")) {
+//                saveProductMG22(id);
+//            }
+//            if (number.equals("26")) {
+//                saveProductMG26(id);
+//            }
+//            if (number.equals("30")) {
+//                saveProductMG1(id);
+//            }
+//            if (number.equals("42")) {
+//                saveProductMG42(id);
+//            }
             return "success";
         } else {
             return "error";

+ 56 - 0
src/main/java/com/szwl/controller/TGoodsDataController.java

@@ -0,0 +1,56 @@
+package com.szwl.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.szwl.model.bo.R;
+import com.szwl.model.bo.ResponseModel;
+import com.szwl.model.entity.TGoodsData;
+import com.szwl.service.TGoodsDataService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ * 商品数据表 前端控制器
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-19
+ */
+@RestController
+@RequestMapping("/tGoodsData")
+public class TGoodsDataController {
+
+    @Autowired
+    private TGoodsDataService goodsDataService;
+
+    @ApiOperation(value = "添加商品数据")
+    @PostMapping("/addGoodsData")
+    public ResponseModel<?> addGoodsData(@RequestBody TGoodsData goodsData){
+        goodsData.setCreateDate(new Date());
+        goodsData.setModifyDate(new Date());
+        goodsDataService.save(goodsData);
+        return R.ok();
+    }
+
+    @ApiOperation(value = "获取商品数目种类")
+    @GetMapping("/getGoodsNumber")
+    public ResponseModel<?> getGoodsNumber(String machineType){
+        LambdaQueryWrapper<TGoodsData> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(TGoodsData::getMachineType, machineType);
+        queryWrapper.orderByAsc(TGoodsData::getNumber);
+        List<TGoodsData> list = goodsDataService.list(queryWrapper);
+        ArrayList<Integer> numberList = new ArrayList<>();
+        for (TGoodsData tGoodsData : list) {
+          numberList.add(tGoodsData.getNumber());
+        }
+        return R.ok(numberList);
+    }
+
+}
+

+ 16 - 0
src/main/java/com/szwl/mapper/TGoodsDataMapper.java

@@ -0,0 +1,16 @@
+package com.szwl.mapper;
+
+import com.szwl.model.entity.TGoodsData;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 商品数据表 Mapper 接口
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-19
+ */
+public interface TGoodsDataMapper extends BaseMapper<TGoodsData> {
+
+}

+ 21 - 0
src/main/java/com/szwl/mapper/xml/TGoodsDataMapper.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.szwl.mapper.TGoodsDataMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.szwl.model.entity.TGoodsData">
+        <id column="id" property="id" />
+        <result column="create_date" property="createDate" />
+        <result column="modify_date" property="modifyDate" />
+        <result column="number" property="number" />
+        <result column="machine_type" property="machineType" />
+        <result column="goods" property="goods" />
+        <result column="remark" property="remark" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, create_date, modify_date, number, machine_type, goods, remark
+    </sql>
+
+</mapper>

+ 49 - 0
src/main/java/com/szwl/model/entity/TGoodsData.java

@@ -0,0 +1,49 @@
+package com.szwl.model.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 商品数据表
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-19
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="TGoodsData对象", description="商品数据表")
+public class TGoodsData implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createDate;
+
+    @ApiModelProperty(value = "修改时间")
+    private Date modifyDate;
+
+    @ApiModelProperty(value = "商品数")
+    private Integer number;
+
+    @ApiModelProperty(value = "设备类型,0:棉花糖,1:爆米花,2:冰淇淋")
+    private String machineType;
+
+    @ApiModelProperty(value = "商品内容")
+    private String goods;
+
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+
+}

+ 16 - 0
src/main/java/com/szwl/service/TGoodsDataService.java

@@ -0,0 +1,16 @@
+package com.szwl.service;
+
+import com.szwl.model.entity.TGoodsData;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ * 商品数据表 服务类
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-19
+ */
+public interface TGoodsDataService extends IService<TGoodsData> {
+
+}

+ 20 - 0
src/main/java/com/szwl/service/impl/TGoodsDataServiceImpl.java

@@ -0,0 +1,20 @@
+package com.szwl.service.impl;
+
+import com.szwl.model.entity.TGoodsData;
+import com.szwl.mapper.TGoodsDataMapper;
+import com.szwl.service.TGoodsDataService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 商品数据表 服务实现类
+ * </p>
+ *
+ * @author wuhs
+ * @since 2024-01-19
+ */
+@Service
+public class TGoodsDataServiceImpl extends ServiceImpl<TGoodsDataMapper, TGoodsData> implements TGoodsDataService {
+
+}