Browse Source

java完结1

0714Star 9 months ago
parent
commit
8b36588389

BIN
imges/七星瓢虫.jpg


+ 59 - 2
springboot/src/main/java/com/example/controller/OrdersController.java

@@ -1,13 +1,22 @@
 package com.example.controller;
 
-import cn.hutool.core.date.LocalDateTimeUtil;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.example.common.Result;
 import com.example.common.enums.OrderStatus;
 import com.example.entity.Orders;
+import com.example.entity.Product;
+import com.example.entity.SaleStatement;
 import com.example.service.OrdersService;
+import com.example.service.SaleStatementService;
 import com.github.pagehelper.PageInfo;
 import org.springframework.web.bind.annotation.*;
+
 import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 
 /**
@@ -19,7 +28,8 @@ public class OrdersController {
 
     @Resource
     private OrdersService ordersService;
-
+    @Resource
+    private SaleStatementService saleStatementService;
     /**
      * 获取店铺未完成的订单个数
      * @param shopId
@@ -50,6 +60,53 @@ public class OrdersController {
     public Result setOrdersArrived(@RequestBody Orders orders){
         orders.setOrderState(String.valueOf(OrderStatus.ARRIVED));
         ordersService.updateById(orders);
+        Orders dbOrders = ordersService.selectById(orders.getId());
+        // 添加到报表信息中去
+
+        // 构建报表信息
+//        List<Product> orderProductsLists = dbOrders.getOrderProductsLists(); // 新加入的产品
+//        String jsonString1 = JSON.toJSONString(orderProductsLists);  // 将对象转换成json格式数据
+//        JSONArray jsonObject = JSON.parseArray(jsonString1); // 在转回去
+//        List<Product> orderProductsListsTrue = JSON.parseObject(jsonObject.getString("list"), Product.class); // 这样就可以了
+        List<Product> orderProductsLists = dbOrders.getOrderProductsLists(); // 获取产品列表
+// 将产品列表转换为 JSON 字符串
+        String jsonString = JSON.toJSONString(orderProductsLists);
+// 将 JSON 字符串解析为 JSONArray
+        JSONArray jsonArray = JSON.parseArray(jsonString);
+// 创建一个用于存储 Product 对象的列表
+        List<Product> orderProductsListsTrue = new ArrayList<>();
+// 遍历 JSONArray,将每个元素转换为 Product 对象并添加到新的列表中
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONObject jsonObject = jsonArray.getJSONObject(i);
+            Product product = jsonObject.toJavaObject(Product.class);
+            orderProductsListsTrue.add(product);
+        }
+
+// 现在 orderProductsListsTrue 就是包含正确类型的 Product 对象的列表
+
+        orderProductsListsTrue.forEach(productMap -> {
+            Product product = (Product) productMap; // 进行类型转换
+            LinkedHashMap<String ,Object> t = new LinkedHashMap<>();
+            SaleStatement saleStatement = new SaleStatement();
+            saleStatement.setProductId(product.getId());
+            saleStatement.setShopId(dbOrders.getStoreId());
+            saleStatement.setAmount(product.getAmount());
+            saleStatement.setCount(product.getCount());
+            saleStatement.setTimeOver(DateUtil.now());
+            saleStatementService.add(saleStatement);
+        });
+        // 一种产品一个报表
+//        orderProductsLists.forEach(productMap -> {
+//            Product product = (Product) productMap; // 进行类型转换
+//            SaleStatement saleStatement = new SaleStatement();
+//            saleStatement.setProductId(product.getId());
+//            saleStatement.setShopId(orders.getStoreId());
+//            saleStatement.setAmount(product.getAmount());
+//            saleStatement.setCount(product.getCount());
+//            saleStatement.setTimeOver(DateUtil.now());
+//            saleStatementService.add(saleStatement);
+//        });
+
         return Result.success(ordersService.selectById(orders.getId()));
     }
 

+ 1 - 0
springboot/src/main/java/com/example/entity/Orders.java

@@ -2,6 +2,7 @@ package com.example.entity;
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONUtil;
+import lombok.Builder;
 import lombok.Data;
 
 import java.io.Serializable;

+ 4 - 1
springboot/src/main/java/com/example/entity/Product.java

@@ -1,5 +1,6 @@
 package com.example.entity;
 
+import lombok.Builder;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -32,6 +33,8 @@ public class Product implements Serializable {
     /** 数量 */
     // 帮助属性
     private Integer count ;
-    /* 店铺id*/
+    /** 店铺id*/
     private Integer storeId;
+    /** 报表存放的单件总金额*/
+    private BigDecimal amount;
 }

+ 1 - 1
springboot/src/main/java/com/example/service/OrdersService.java

@@ -68,7 +68,7 @@ public class OrdersService {
         orders.setTransCode(IdUtil.getSnowflakeNextIdStr()); // 随机创建一个交易单号
         orders.setTimeOrder(DateUtil.now()); // 创建订单时间
 
-        // 如果是外卖:这个是预计送达时间 ,如果是自提 这个是预计可取餐时间
+        // 预计送达时间
         orders.setTimePre(String.valueOf(DateUtil.offsetSecond(DateUtil.dateSecond(),11))); //预计送达时间
 
         ordersMapper.insert(orders);

+ 1 - 10
springboot/src/main/java/com/example/typeHandler/JsonTypeHandler.java

@@ -7,17 +7,8 @@ package com.example.typeHandler;
  * @time 2024-05-02 9:25
  * @Description
  */
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.ibatis.type.BaseTypeHandler;
-import org.apache.ibatis.type.JdbcType;
 
-import java.io.IOException;
-import java.sql.CallableStatement;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.ibatis.type.BaseTypeHandler;
 import org.apache.ibatis.type.JdbcType;

+ 5 - 5
springboot/src/main/java/com/example/utils/generate/CodeGenerator.java

@@ -32,15 +32,15 @@ public class CodeGenerator {
      * 主类  生成代码
      */
     public static void main(String[] args) {
-        String tableName = "orders";
+        String tableName = "product_type";
         // 生成Entity
-//        EntityGenerator.generate(tableName);
+        EntityGenerator.generate(tableName);
         // 生成Mapper #
-//        MapperGenerator.generate(tableName);
+        MapperGenerator.generate(tableName);
         // 生成Service #
-//        ServiceGenerator.generate(tableName);
+        ServiceGenerator.generate(tableName);
         // 生成Controller #
-//        ControllerGenerator.generate(tableName);
+        ControllerGenerator.generate(tableName);
         // 生成Vue
         VueGenerator.generate(tableName);
     }

+ 54 - 4
springboot/src/main/resources/mapper/OrdersMapper.xml

@@ -43,10 +43,50 @@
             <id property="id" column="product_id"/>
             <result property="productName" column="product_name"/>
             <result property="count" column="count"/>
+            <result property="amount" column="amount"/>
         </collection>
     </resultMap>
-<!--    javaType="list"  ofType="com.example.entity.Product"-->
-    <select id="selectAll" resultMap="ForProductList">
+
+    <resultMap id="pdList" type="com.example.entity.Orders">
+        <id property="id" column="id"/>
+        <result property="bidPay" column="bid_pay"/>
+        <result property="originPay" column="origin_pay"/>
+        <result property="userId" column="user_id"/>
+        <result property="addressId" column="address_id"/>
+        <result property="timePre" column="time_pre"/>
+        <result property="timeOrder" column="time_order"/>
+        <result property="orderState" column="order_state"/>
+        <result property="transCode" column="trans_code"/>
+        <result property="orderRemark" column="order_remark"/>
+        <result property="storeId" column="store_id"/>
+
+        <result property="orderProductsLists" javaType="com.example.entity.Product" column="order_products_lists"  typeHandler="com.example.typeHandler.JsonTypeHandler"/>
+
+        <association property="user" javaType="com.example.entity.User">
+            <id property="id" column="user_id"/>
+            <result property="username" column="username"/>
+            <result property="role" column="role"/>
+            <result property="phone" column="phone"/>
+            <result property="name" column="name"/>
+            <result property="sex" column="sex"/>
+            <result property="openid" column="openid"/>
+        </association>
+
+        <association property="address" javaType="com.example.entity.Address">
+            <id property="id" column="address_id"/>
+            <result property="userId" column="user_id"/>
+            <result property="address" column="address"/>
+            <result property="doorNo" column="door_no"/>
+            <result property="phone" column="phone"/>
+            <result property="recipientName" column="recipient_name"/>
+        </association>
+
+
+
+
+    </resultMap>
+
+    <select id="selectAll" resultMap="pdList">
         select
             orders.*,address.*,user.*,
             orders.order_products_lists,
@@ -71,7 +111,17 @@
         order by orders.id desc
     </select>
 
-    <select id="selectById" resultMap="ForProductList">
+
+<!--    <select id="selectById" resultMap="ForProductList">-->
+<!--        select-->
+<!--            orders.*,address.*,user.*,-->
+<!--            address.id as addressId, user.id as userId-->
+<!--        from orders-->
+<!--                 left join address on address.id = orders.address_id-->
+<!--                 left join user on user.id = orders.user_id-->
+<!--        where orders.id = #{id}-->
+<!--    </select>-->
+    <select id="selectById" resultMap="pdList">
         select
             orders.*,address.*,user.*,
             address.id as addressId, user.id as userId
@@ -85,7 +135,7 @@
         from orders
         where
         store_id = #{storeId}
-        and order_state!="已完成"
+        and order_state="待送达"
     </select>
 
     <delete id="deleteById">

+ 0 - 1
springboot/src/main/resources/mapper/ProductTypeMapper.xml

@@ -14,7 +14,6 @@
 <!--        <id property="productIds" column="product_ids" jdbcType="VARCHAR" typeHandler="com.example.typeHandler.ArrayIntegerTypeHadnler"/>-->
 <!--        <association property="address" javaType="com.example.entity.Address">-->
 <!--            <id property="id" column="address_id"/>-->
-
 <!--        </association>-->
 <!--        <association property="user" javaType="com.example.entity.User">-->
 <!--            <id property="id" column="user_id"/>-->

+ 47 - 1
springboot/src/main/resources/mapper/StoreMapper.xml

@@ -46,6 +46,52 @@
         </collection>
         <collection property="productTypes" javaType="list" ofType="com.example.entity.ProductType">
             <!-- 这里使用 productTypeName 作为 id -->
+            <id property="id" column="productId"/>
+            <id property="productTypeName" column="productTypeName"/>
+        </collection>
+    </resultMap>
+
+<!--    获取商店数据  -->
+    <resultMap id="storeAllDataWithType" type="com.example.entity.Store">
+        <id property="id" column="id"></id>
+        <result property="storeName" column="store_name"/>
+        <result property="productState" column="product_state"/>
+        <result property="productName" column="product_name"/>
+        <result property="productBidPrice" column="product_bid_price"/>
+        <result property="productSellPrice" column="product_sell_price"/>
+        <result property="productTypeIds" column="product_type_ids" jdbcType="VARCHAR" typeHandler="com.example.typeHandler.ArrayIntegerTypeHadnler" />
+        <result property="storePicUrl" column="store_pic_url"/>
+        <result property="addressIds" column="address_id"/>
+        <result property="productsIds" column="products_ids" jdbcType="VARCHAR" typeHandler="com.example.typeHandler.ArrayIntegerTypeHadnler"/>
+        <result property="ownerId" column="owner_id" />
+        <!--        店铺老板信息-->
+        <association property="adminstore" javaType="com.example.entity.Adminstore">
+            <result property="username" column="username" />
+            <result property="name" column="name" />
+            <result property="phone" column="phone" />
+            <result property="email" column="email" />
+        </association>
+        <!--    地址表-->
+        <association property="address" javaType="com.example.entity.Address">
+            <id property="id" column="address_id"/>
+            <id property="userId" column="user_id"/>
+            <id property="address" column="address"/>
+            <id property="doorNo" column="door_no"/>
+            <id property="phone" column="phone"/>
+            <id property="recipientName" column="recipient_name"/>
+        </association>
+        <!--         产品List-->
+        <collection property="products" javaType="list" ofType="com.example.entity.Product">
+            <id property="id" column="productId"/>
+            <result property="productState" column="product_state"/>
+            <result property="productName" column="product_name"/>
+            <result property="productIcons" column="product_icons"/>
+            <result property="productSellPrice" column="product_sell_price"/>
+            <result property="productBidPrice" column="product_bid_price"/>
+        </collection>
+        <collection property="productTypes" javaType="list" ofType="com.example.entity.ProductType">
+            <!-- 这里使用 productTypeName 作为 id -->
+<!--            <id property="id" column="productId"/>-->
             <id property="productTypeName" column="productTypeName"/>
         </collection>
     </resultMap>
@@ -83,7 +129,7 @@
 <!--                <if test="id!=null" >and store.id = #{id}</if>-->
 <!--            </where>-->
 <!--        </select>-->
-    <select id="selectAll" resultMap="storeWithType">
+    <select id="selectAll" resultMap="storeAllDataWithType">
         select
         store.*, product.*,address.*,adminstore.*,
         adminstore.id as adminstoreId ,

+ 163 - 0
vue/src/views/manager/ShopManager/Productype.vue

@@ -0,0 +1,163 @@
+<template>
+  <div>
+    <div class="search">
+      <el-input placeholder="请输入关键字查询" style="width: 200px" v-model="username"></el-input>
+      <el-button type="info" plain style="margin-left: 10px" @click="load(1)">查询</el-button>
+      <el-button type="warning" plain style="margin-left: 10px" @click="reset">重置</el-button>
+    </div>
+
+    <div class="operation">
+      <el-button type="primary" plain @click="handleAdd">新增</el-button>
+      <el-button type="danger" plain @click="delBatch">批量删除</el-button>
+    </div>
+
+    <div class="table">
+      <el-table :data="tableData" strip @selection-change="handleSelectionChange">
+        <el-table-column type="selection" width="55" align="center"></el-table-column>
+        <el-table-column prop="id" label="序号" width="70" align="center" sortable></el-table-column>
+        <el-table-column prop="productTypeName" label="产品类型名称"></el-table-column>
+        <el-table-column label="操作" align="center" width="180">
+          <template v-slot="scope">
+            <el-button size="mini" type="primary" plain @click="handleEdit(scope.row)">编辑</el-button>
+            <el-button size="mini" type="danger" plain @click="del(scope.row.id)">删除</el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+
+      <div class="pagination">
+        <el-pagination
+            background
+            @current-change="handleCurrentChange"
+            :current-page="pageNum"
+            :page-sizes="[5, 10, 20]"
+            :page-size="pageSize"
+            layout="total, prev, pager, next"
+            :total="total">
+        </el-pagination>
+      </div>
+    </div>
+
+    <el-dialog title="" :visible.sync="fromVisible" width="40%" :close-on-click-modal="false" destroy-on-close>
+      <el-form :model="form" label-width="100px" style="padding-right: 50px" :rules="rules" ref="formRef">
+        <el-form-item label="产品类型名称" prop="productTypeName">
+          <el-input v-model="form.productTypeName" placeholder="产品类型名称"></el-input>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="fromVisible = false">取 消</el-button>
+        <el-button type="primary" @click="save">确 定</el-button>
+      </div>
+    </el-dialog>
+
+
+  </div>
+</template>
+<script>
+export default {
+  name: "Productype",
+  data() {
+    return {
+      tableData: [],  // 所有的数据
+      pageNum: 1,   // 当前的页码
+      pageSize: 10,  // 每页显示的个数
+      total: 0,
+      username: null,
+      fromVisible: false,
+      form: {},
+      user: JSON.parse(localStorage.getItem('xm-user') || '{}'),
+      rules: {
+      },
+      ids: []
+    }
+  },
+  created() {
+    this.load(1)
+  },
+  methods: {
+    handleAdd() {   // 新增数据
+      this.form = {}  // 新增数据的时候清空数据
+      this.fromVisible = true   // 打开弹窗
+    },
+    handleEdit(row) {   // 编辑数据
+      this.form = JSON.parse(JSON.stringify(row))  // 给form对象赋值  注意要深拷贝数据
+      this.fromVisible = true   // 打开弹窗
+    },
+    save() {   // 保存按钮触发的逻辑  它会触发新增或者更新
+      this.$refs.formRef.validate((valid) => {
+        if (valid) {
+          this.$request({
+            url: this.form.id ? '/productype/update' : '/productype/add',
+            method: this.form.id ? 'PUT' : 'POST',
+            data: this.form
+          }).then(res => {
+            if (res.code === '200') {  // 表示成功保存
+              this.$message.success('保存成功')
+              this.load(1)
+              this.fromVisible = false
+            } else {
+              this.$message.error(res.msg)  // 弹出错误的信息
+            }
+          })
+        }
+      })
+    },
+    del(id) {   // 单个删除
+      this.$confirm('您确定删除吗?', '确认删除', {type: "warning"}).then(response => {
+        this.$request.delete('/productype/delete/' + id).then(res => {
+          if (res.code === '200') {   // 表示操作成功
+            this.$message.success('操作成功')
+            this.load(1)
+          } else {
+            this.$message.error(res.msg)  // 弹出错误的信息
+          }
+        })
+      }).catch(() => {
+      })
+    },
+    handleSelectionChange(rows) {   // 当前选中的所有的行数据
+      this.ids = rows.map(v => v.id)
+    },
+    delBatch() {   // 批量删除
+      if (!this.ids.length) {
+        this.$message.warning('请选择数据')
+        return
+      }
+      this.$confirm('您确定批量删除这些数据吗?', '确认删除', {type: "warning"}).then(response => {
+        this.$request.delete('/productype/delete/batch', {data: this.ids}).then(res => {
+          if (res.code === '200') {   // 表示操作成功
+            this.$message.success('操作成功')
+            this.load(1)
+          } else {
+            this.$message.error(res.msg)  // 弹出错误的信息
+          }
+        })
+      }).catch(() => {
+      })
+    },
+    load(pageNum) {  // 分页查询
+      if (pageNum) this.pageNum = pageNum
+      this.$request.get('/productype/selectPage', {
+        params: {
+          pageNum: this.pageNum,
+          pageSize: this.pageSize,
+          username: this.username,
+        }
+      }).then(res => {
+        this.tableData = res.data?.list
+        this.total = res.data?.total
+      })
+    },
+    reset() {
+      this.username = null
+      this.load(1)
+    },
+    handleCurrentChange(pageNum) {
+      this.load(pageNum)
+    },
+  }
+}
+</script>
+
+<style scoped>
+
+</style>