商品订单

master
miaoqingshuai 2026-02-07 18:15:19 +08:00
parent 43ee4eedbf
commit 613300778f
16 changed files with 235 additions and 189 deletions

View File

@ -28,8 +28,9 @@ public class BrandController extends BaseController {
*/
@Anonymous
@GetMapping(value = "/getTree/{storeId}")
public AjaxResult getBrandTree(@PathVariable String storeId) {
return AjaxResult.success(brandService.getBrandTree(storeId));
public AjaxResult getBrandTree(@PathVariable String storeId,
@RequestParam(required = false) String brandName) {
return AjaxResult.success(brandService.getBrandTree(storeId,brandName));
}
/**

View File

@ -7,6 +7,8 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Classification;
import com.ruoyi.web.service.ClassIficationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -21,6 +23,8 @@ public class ClassificationController extends BaseController {
@Resource
private ClassIficationService classIficationService;
private static final Logger log = LoggerFactory.getLogger(ClassificationController.class);
/**
*
*
@ -28,8 +32,10 @@ public class ClassificationController extends BaseController {
*/
@Anonymous
@GetMapping(value = "/getTree/{storeId}")
public AjaxResult getClassIficationTree(@PathVariable String storeId) {
return AjaxResult.success(classIficationService.getIficationTree(storeId));
public AjaxResult getClassIficationTree(@PathVariable String storeId,
@RequestParam(required = false) String classificationName) {
log.info("获取商品分类树" + storeId);
return AjaxResult.success(classIficationService.getIficationTree(storeId,classificationName));
}
/**

View File

@ -5,11 +5,14 @@ import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.domain.Order;
import com.ruoyi.web.service.OrderService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
@ -23,12 +26,13 @@ public class OrderController extends BaseController {
private OrderService orderService;
/**
*
*
*/
// @PreAuthorize("@ss.hasPermi('product:list')")
// @PreAuthorize("@ss.hasPermi('mall:order:list')")
@Anonymous
@GetMapping("/list")
public AjaxResult list(Order order) {
return AjaxResult.success(orderService.selectList(order));
return AjaxResult.success( orderService.selectOrderList(order));
}
}

View File

@ -42,6 +42,7 @@ public class ProductStoreController extends BaseController {
return AjaxResult.success(productService.selectList(product));
}
/**
*
*/

View File

@ -6,6 +6,7 @@ import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* mall_order
@ -39,14 +40,14 @@ public class Order extends BaseEntity {
*/
private Integer payStatus;
/**
* id
*/
private Integer productId;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date payTime;
/**
*
*/
private List<OrderItem> orderItems;
}

View File

@ -0,0 +1,68 @@
package com.ruoyi.web.domain;
import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data;
import java.math.BigDecimal;
/**
* mall_order_item
*/
@Data
public class OrderItem extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* ID
*/
private Long id;
/**
* ID
*/
private Long orderId;
/**
* ID
*/
private Long productId;
/**
*
*/
private String productName;
/**
*
*/
private String productNo;
/**
*
*/
private String mainImage;
/**
*
*/
private String spec;
/**
*
*/
private BigDecimal unitPrice;
/**
*
*/
private Integer quantity;
/**
*
*/
private BigDecimal subtotal;
}

View File

@ -12,7 +12,7 @@ import java.util.List;
public interface ClassIficationMapper {
List<Classification> selectRootBrands(String storeId);
List<Classification> selectRootBrands(@Param("storeId") String storeId);
List<Classification> selectByParentId(@Param("parentId") Long parentId);

View File

@ -11,5 +11,6 @@ import java.util.List;
public interface OrderMapper {
List<Order> selectList(Order order);
List<Order> selectOrderList(Order order);
}

View File

@ -7,7 +7,7 @@ import java.util.List;
public interface BrandService {
// 获取品牌树(一级品牌包含子品牌)
List<Brand> getBrandTree(String storeId);
List<Brand> getBrandTree(String storeId,String brandName);
// 添加品牌
int addBrand(Brand brand);

View File

@ -6,7 +6,7 @@ import java.util.List;
public interface ClassIficationService {
List<Classification> getIficationTree(String storeId);
List<Classification> getIficationTree(String storeId,String classificationName);
int addClassification(Classification classification);

View File

@ -11,5 +11,6 @@ import java.util.List;
*/
public interface OrderService {
List<Order> selectList(Order order);
List<Order> selectOrderList(Order order);
}

View File

@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class BrandServiceImpl implements BrandService {
@ -23,13 +24,41 @@ public class BrandServiceImpl implements BrandService {
private BrandMapper brandMapper;
@Override
public List<Brand> getBrandTree(String storeId) {
public List<Brand> getBrandTree(String storeId, String brandName) {
List<Brand> rootBrands = brandMapper.selectRootBrands(storeId);
return buildTree(rootBrands);
List<Brand> brands = buildTree(rootBrands);
if (StringUtils.isEmpty(brandName)) {
return brands;
}
return brands.stream()
.filter(node -> containsName(node, brandName))
.collect(Collectors.toList());
}
/**
*
*/
private boolean containsName(Brand node, String targetName) {
// 当前节点匹配
if (targetName.equals(node.getBrandName())) {
return true;
}
// 子节点中是否有匹配的
if (node.getChildren() != null) {
return node.getChildren().stream()
.anyMatch(child -> containsName(child, targetName));
}
return false;
}
private List<Brand> buildTree(List<Brand> allList) {
List<Brand> rootList = new ArrayList<>();

View File

@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class ClassIficationServiceImpl implements ClassIficationService {
@ -22,11 +23,36 @@ public class ClassIficationServiceImpl implements ClassIficationService {
private ClassIficationMapper classIficationMapper;
@Override
public List<Classification> getIficationTree(String storeId) {
public List<Classification> getIficationTree(String storeId,String classificationName) {
List<Classification> rootBrands = classIficationMapper.selectRootBrands(storeId);
// 构建树形结构
return buildTree(rootBrands);
List<Classification> classifications = buildTree(rootBrands);
if (StringUtils.isEmpty(classificationName)) {
return classifications;
}
return classifications.stream()
.filter(node -> containsName(node, classificationName))
.collect(Collectors.toList());
}
/**
*
*/
private boolean containsName(Classification node, String targetName) {
// 当前节点匹配
if (targetName.equals(node.getClassificationName())) {
return true;
}
// 子节点中是否有匹配的
if (node.getChildren() != null) {
return node.getChildren().stream()
.anyMatch(child -> containsName(child, targetName));
}
return false;
}
/**

View File

@ -18,8 +18,9 @@ public class OrderServiceImpl implements OrderService {
@Resource
private OrderMapper orderMapper;
@Override
public List<Order> selectList(Order order) {
return orderMapper.selectList(order);
public List<Order> selectOrderList(Order order) {
return orderMapper.selectOrderList(order);
}
}

View File

@ -4,176 +4,87 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.web.mapper.OrderMapper">
<resultMap type="Order" id="MallOrderResult">
<id property="id" column="id"/>
<!-- 基础结果映射 -->
<resultMap type="Order" id="OrderResult">
<result property="id" column="id"/>
<result property="orderNo" column="order_no"/>
<result property="storeId" column="store_id"/>
<result property="payAmount" column="pay_amount"/>
<result property="payTime" column="pay_time"/>
<result property="payStatus" column="pay_status"/>
<result property="productId" column="product_id"/>
<result property="storeId" column="store_id"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="createBy" column="create_by"/>
<result property="updateBy" column="update_by"/>
</resultMap>
<sql id="selectCommodityVo">
select id,
order_no,
store_id,
pay_amount,
pay_time,
pay_status,
product_id,
create_by,
create_time,
update_by,
update_time
from mall_order
</sql>
<!-- 商品明细结果映射 -->
<resultMap type="OrderItem" id="OrderItemResult">
<result property="id" column="item_id"/>
<result property="orderId" column="order_id"/>
<result property="productId" column="product_id"/>
<result property="productName" column="product_name"/>
<result property="productNo" column="product_no"/>
<result property="mainImage" column="main_image"/>
<result property="spec" column="spec"/>
<result property="unitPrice" column="unit_price"/>
<result property="quantity" column="quantity"/>
<result property="subtotal" column="subtotal"/>
<result property="createBy" column="item_create_by"/>
<result property="createTime" column="item_create_time"/>
</resultMap>
<!-- 包含商品明细的结果映射 -->
<resultMap type="Order" id="OrderWithItemsResult" extends="OrderResult">
<!-- 一对多关联:使用嵌套结果映射 -->
<collection property="orderItems" ofType="OrderItem" resultMap="OrderItemResult"/>
</resultMap>
<select id="selectList" parameterType="Order" resultMap="MallOrderResult">
<include refid="selectCommodityVo"/>
where del_flag = '0'
</select>
<select id="checkProductCodeUnique" resultType="com.ruoyi.web.domain.Product">
<include refid="selectCommodityVo"/>
where product_bar_code=#{productBarCode} and del_flag = '0' and store_id = #{storeId}
<if test="id != null">
AND id != #{id}
<!-- 查询订单列表(包含商品明细) -->
<select id="selectOrderList" parameterType="Order" resultMap="OrderWithItemsResult">
SELECT
o.id,
o.order_no,
o.store_id,
o.pay_amount,
o.pay_time,
o.pay_status,
o.create_time,
o.update_time,
o.del_flag,
o.create_by,
o.update_by,
oi.id as item_id,
oi.order_id,
oi.product_id,
oi.product_name,
oi.product_no,
oi.main_image,
oi.spec,
oi.unit_price,
oi.quantity,
oi.subtotal,
oi.del_flag as item_del_flag,
oi.create_by as item_create_by,
oi.create_time as item_create_time
FROM mall_order o
LEFT JOIN mall_order_item oi ON o.id = oi.order_id AND oi.del_flag = '0'
<where>
o.del_flag = '0'
<if test="orderNo != null and orderNo != ''">
AND o.order_no like concat('%', #{orderNo}, '%')
</if>
limit 1
<if test="storeId != null">
AND o.store_id = #{storeId}
</if>
<if test="payStatus != null">
AND o.pay_status = #{payStatus}
</if>
</where>
ORDER BY o.create_time DESC, oi.create_time ASC
</select>
<insert id="insertProductStore" parameterType="Product">
insert into mall_product_store (
<if test="productCode != null and productCode != ''">product_code,</if>
<if test="productName != null and productName != ''">product_name,</if>
<if test="productDesc != null and productDesc != ''">product_desc,</if>
<if test="mainImage != null and mainImage != ''">main_image,</if>
<if test="storePrice != null and storePrice != ''">store_price,</if>
<if test="costPrice != null and costPrice != ''">cost_price,</if>
<if test="originalPrice != null and originalPrice != ''">original_price,</if>
<if test="storeId != null and storeId != ''">store_id,</if>
<if test="stockQuantity != null and stockQuantity != ''">stock_quantity,</if>
<if test="soldQuantity != null and soldQuantity != ''">sold_quantity,</if>
<if test="status != null and status != ''">status,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="shelfCode != null and shelfCode != ''">shelf_code,</if>
<if test="productBarCode != null and productBarCode != ''">product_bar_code,</if>
<if test="shelfLife != null and shelfLife != ''">shelf_life,</if>
<if test="productionDate != null and productionDate != ''">production_date,</if>
<if test="approaching != null">approaching,</if>
create_time
)values(
<if test="productCode != null and productCode != ''">#{productCode},</if>
<if test="productName != null and productName != ''">#{productName},</if>
<if test="productDesc != null and productDesc != ''">#{productDesc},</if>
<if test="mainImage != null and mainImage != ''">#{mainImage},</if>
<if test="storePrice != null and storePrice != ''">#{storePrice},</if>
<if test="costPrice != null and costPrice != ''">#{costPrice},</if>
<if test="originalPrice != null and originalPrice != ''">#{originalPrice},</if>
<if test="storeId != null and storeId != ''">#{storeId},</if>
<if test="stockQuantity != null and stockQuantity != ''">#{stockQuantity},</if>
<if test="soldQuantity != null and soldQuantity != ''">#{soldQuantity},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="shelfCode != null and shelfCode != ''">#{shelfCode},</if>
<if test="productBarCode != null and productBarCode != ''">#{productBarCode},</if>
<if test="shelfLife != null and shelfLife != ''">#{shelfLife},</if>
<if test="productionDate != null and productionDate != ''">#{productionDate},</if>
<if test="approaching != null">#{approaching},</if>
sysdate()
)
</insert>
<update id="updateProduct">
update mall_product_store
<set>
<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
<if test="productName != null and productName != ''">product_name = #{productName},</if>
<if test="productDesc != null and productDesc != ''">product_desc = #{productDesc},</if>
<if test="mainImage != null and mainImage != ''">main_image = #{mainImage},</if>
<if test="storePrice != null and storePrice != ''">store_price = #{storePrice},</if>
<if test="costPrice != null and costPrice != ''">cost_price = #{costPrice},</if>
<if test="stockQuantity != null and stockQuantity != ''">stock_quantity = #{stockQuantity},</if>
<if test="soldQuantity != null and soldQuantity != ''">sold_quantity = #{soldQuantity},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="shelfCode != null and shelfCode != ''">shelf_code = #{shelfCode},</if>
<if test="productBarCode != null and productBarCode != ''">product_bar_code = #{productBarCode},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="shelfLife != null">shelf_life = #{shelfLife},</if>
<if test="productionDate != null and productionDate != ''">production_date = #{productionDate},</if>
<if test="approaching != null">approaching = #{approaching},</if>
<if test="productBrand != null and productBrand != ''">product_brand = #{productBrand},</if>
<if test="classifcation != null and classifcation != ''">classifcation = #{classifcation},</if>
update_time = sysdate()
</set>
where id = #{id}
</update>
<update id="updateProductBarCode">
update mall_product_store
<set>
<if test="productCode != null and productCode != ''">product_code = #{productCode},</if>
<if test="productName != null and productName != ''">product_name = #{productName},</if>
<if test="productDesc != null and productDesc != ''">product_desc = #{productDesc},</if>
<if test="mainImage != null and mainImage != ''">main_image = #{mainImage},</if>
<if test="storePrice != null and storePrice != ''">store_price = #{storePrice},</if>
<if test="costPrice != null and costPrice != ''">cost_price = #{costPrice},</if>
<if test="stockQuantity != null and stockQuantity != ''">stock_quantity = #{stockQuantity},</if>
<if test="soldQuantity != null and soldQuantity != ''">sold_quantity = #{soldQuantity},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="shelfCode != null and shelfCode != ''">shelf_code = #{shelfCode},</if>
<if test="productBarCode != null and productBarCode != ''">product_bar_code = #{productBarCode},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="shelfLife != null">shelf_life = #{shelfLife},</if>
<if test="productionDate != null and productionDate != ''">production_date = #{productionDate},</if>
<if test="approaching != null">approaching = #{approaching},</if>
<if test="productBrand != null and productBrand != ''">product_brand = #{productBrand},</if>
<if test="classifcation != null and classifcation != ''">classifcation = #{classifcation},</if>
update_time = sysdate()
</set>
where product_bar_code = #{productBarCode}
</update>
<delete id="deleteConfigById" parameterType="Long">
delete
from sys_config
where config_id = #{configId}
</delete>
<delete id="deleteConfigByIds" parameterType="Long">
delete from sys_config where config_id in
<foreach item="configId" collection="array" open="(" separator="," close=")">
#{configId}
</foreach>
</delete>
<delete id="deleteProductById">
update mall_product_store
set del_flag = '2'
where id = #{id}
</delete>
<delete id="batchProductById">
UPDATE mall_product_store
SET del_flag = 2
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -62,18 +62,14 @@
<where>
del_flag = '0'
<if test="productBarCode != null and productBarCode != ''">
AND product_bar_code = #{productBarCode}
</if>
<if test="productName != null and productName != ''">
AND product_name like concat('%', #{productName}, '%')
AND product_bar_code like concat('%', #{productBarCode}, '%')
</if>
<if test="storeId != null">
AND store_id = #{storeId}
</if>
<!-- 库存大于0条件 -->
AND stock_quantity > 0
<if test="stockQuantity != null">
AND stock_quantity = #{stockQuantity}
</if>
<if test="status != null and status != '' ">
AND status = #{status}
</if>