Skip to content

Commit e1f0087

Browse files
author
liujun
committed
完成品牌和分类
1 parent f721c5f commit e1f0087

File tree

16 files changed

+11751
-11364
lines changed

16 files changed

+11751
-11364
lines changed
Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,78 @@
11
package biz.llmall.commodity.model.service.impl;
22
import biz.llmall.commodity.model.service.IWebLogAspect;
3+
import com.google.gson.Gson;
4+
import com.inamik.text.tables.GridTable;
5+
import com.inamik.text.tables.SimpleTable;
6+
import com.inamik.text.tables.grid.Border;
7+
import com.inamik.text.tables.grid.Util;
38
import lombok.extern.slf4j.Slf4j;
49
import org.aspectj.lang.JoinPoint;
5-
import org.aspectj.lang.annotation.Aspect;
6-
import org.aspectj.lang.annotation.Before;
7-
import org.aspectj.lang.annotation.Pointcut;
10+
import org.aspectj.lang.annotation.*;
811
import org.springframework.stereotype.Component;
12+
import org.springframework.web.context.request.RequestContextHolder;
13+
import org.springframework.web.context.request.ServletRequestAttributes;
14+
15+
import javax.servlet.http.HttpServletRequest;
16+
import java.util.Arrays;
17+
18+
import static com.inamik.text.tables.Cell.Functions.LEFT_ALIGN;
19+
import static com.inamik.text.tables.Cell.Functions.VERTICAL_CENTER;
920

1021
@Aspect
1122
@Component
1223
@Slf4j
1324
public class WebLogAspect implements IWebLogAspect {
14-
1525
private ThreadLocal<Long> startTimestamp = new ThreadLocal<>();
26+
private ThreadLocal<SimpleTable> simpleTableThreadLocal = new ThreadLocal<>();
1627

1728
@Pointcut("execution(* biz.llmall.commodity.controller..*.*(..))")
18-
private void webLog(){}
19-
29+
private void webLog() {
30+
}
2031

2132
@Override
2233
@Before("webLog()")
2334
public void beforeRequest(JoinPoint joinPoint) {
2435
startTimestamp.set(System.currentTimeMillis());
25-
36+
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
37+
HttpServletRequest request = attributes.getRequest();
38+
int height = 5;
39+
int width = 10;
40+
SimpleTable simpleTable = SimpleTable.of()
41+
.nextRow()
42+
.nextCell().addLine("Request URL")
43+
.nextCell().addLine("HTTP Method")
44+
.nextCell().addLine("Remote IP")
45+
.nextCell().addLine("Class Name")
46+
.nextCell().addLine("Method Name")
47+
.nextCell().addLine("Method Args")
48+
.applyToCell(VERTICAL_CENTER.withHeight(height))
49+
.applyToCell(LEFT_ALIGN.withWidth(width))
50+
.nextRow()
51+
.nextCell().addLine(request.getRequestURL().toString())
52+
.nextCell().addLine(request.getMethod())
53+
.nextCell().addLine(request.getRemoteHost())
54+
.nextCell().addLine(joinPoint.getSignature().getDeclaringTypeName())
55+
.nextCell().addLine(joinPoint.getSignature().getName())
56+
.nextCell().addLine(Arrays.toString(joinPoint.getArgs()))
57+
.applyToCell(VERTICAL_CENTER.withHeight(height))
58+
.applyToCell(LEFT_ALIGN.withWidth(width));
59+
simpleTableThreadLocal.set(simpleTable);
2660
}
2761

2862
@Override
63+
@AfterReturning(returning = "ret", pointcut = "webLog()")
2964
public void afterReturning(Object ret) {
65+
SimpleTable simpleTable = simpleTableThreadLocal.get();
66+
GridTable gridTable = simpleTable.toGrid();
67+
gridTable = Border.of(Border.Chars.of('+', '-', '|')).apply(gridTable);
68+
Util.print(gridTable);
69+
log.debug("Response: " + new Gson().toJson(ret));
70+
log.debug("Elapsed Time: " + (System.currentTimeMillis() - startTimestamp.get()));
3071
}
3172

3273
@Override
74+
@AfterThrowing(pointcut = "webLog()", throwing = "ex")
3375
public void afterException(Exception ex) {
76+
log.debug(new Gson().toJson(ex));
3477
}
3578
}

llmall-commodity/src/main/resources/logback-spring.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<contextName>llmall</contextName>
44

55
<springProperty scope="context" name="log.level" source="logging.level.root" defaultValue="DEBUG"/>
6-
<springProperty scope="context" name="log.path" source="logging.path" defaultValue=""/>
6+
<springProperty scope="context" name="log.path" source="logging.path" defaultValue="target"/>
77
<springProperty scope="context" name="log.file" source="logging.file" defaultValue="llmall"/>
88

99
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

llmall-commodity/src/main/resources/mappers/BrandMapper.xml

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,78 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
33
<mapper namespace="biz.llmall.commodity.model.mapper.BrandMapper">
4-
<resultMap id="BaseResultMap" type="biz.llmall.common.entity.commodity.Brand">
4+
<resultMap id="brandBaseResultMap" type="biz.llmall.common.entity.commodity.Brand">
55
<id column="id" jdbcType="BIGINT" property="id"/>
6-
<result column="name" jdbcType="VARCHAR" property="name"/>
7-
<result column="short_name" jdbcType="VARCHAR" property="shortName"/>
6+
<result column="name" jdbcType="VARCHAR" property="brandName"/>
87
<result column="logo_lg" jdbcType="VARCHAR" property="logoLg"/>
98
<result column="logo_md" jdbcType="VARCHAR" property="logoMd"/>
109
<result column="logo_sm" jdbcType="VARCHAR" property="logoSm"/>
1110
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
1211
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
13-
<collection property="commodities" ofType="biz.llmall.common.entity.commodity.Commodity" fetchType="lazy">
14-
<id column="commodity_id" property="commodityId"/>
12+
<collection property="commodities"
13+
column="id"
14+
ofType="biz.llmall.common.entity.commodity.Commodity"
15+
select="selectCommodityByPrimaryKey">
1516
</collection>
1617
</resultMap>
17-
<sql id="Base_Column_List">
18-
id, name, short_name, logo_lg, logo_md, logo_sm, create_time, update_time
18+
<resultMap id="commodityBaseResultMap" type="biz.llmall.common.entity.commodity.Commodity">
19+
<id column="id" jdbcType="BIGINT" property="id"/>
20+
<result column="brand_id" jdbcType="BIGINT" property="brandId"/>
21+
<result column="name" jdbcType="VARCHAR" property="CommodityName"/>
22+
<result column="price" jdbcType="DECIMAL" property="price"/>
23+
<result column="category_id" jdbcType="BIGINT" property="categoryId"/>
24+
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
25+
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
26+
<collection property="commodityImages"
27+
ofType="biz.llmall.common.entity.commodity.CommodityImage"
28+
column="id"
29+
select="selectCommodityImagesByPrimaryKey"/>
30+
</resultMap>
31+
<resultMap extends="commodityBaseResultMap" id="ResultMapWithBLOBs" type="biz.llmall.common.entity.commodity.Commodity">
32+
<result column="description" jdbcType="LONGVARCHAR" property="description"/>
33+
</resultMap>
34+
<!--brand-->
35+
<sql id="Brand_Base_Column_List">
36+
id, name, logo_lg, logo_md, logo_sm, create_time, update_time
1937
</sql>
20-
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
38+
<!--commodity-->
39+
<sql id="Commodity_Base_Column_List">
40+
id, brand_id, name, price, category_id, create_time, update_time
41+
</sql>
42+
<sql id="Commodity_Blob_Column_List">
43+
description
44+
</sql>
45+
46+
<select id="selectCommodityByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
47+
select
48+
<include refid="Commodity_Base_Column_List"/>
49+
,
50+
<include refid="Commodity_Blob_Column_List"/>
51+
from commodity
52+
where brand_id = #{id,jdbcType=BIGINT}
53+
</select>
54+
55+
<!--commodity images-->
56+
<resultMap id="CommodityImageBaseResultMap" type="biz.llmall.common.entity.commodity.CommodityImage">
57+
<id column="id" jdbcType="BIGINT" property="id"/>
58+
<result column="commodity_id" jdbcType="BIGINT" property="commodityId"/>
59+
<result column="url" jdbcType="VARCHAR" property="url"/>
60+
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
61+
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
62+
</resultMap>
63+
<sql id="Commodity_Image_Base_Column_List">
64+
id, commodity_id, url, create_time, update_time
65+
</sql>
66+
<select id="selectCommodityImagesByPrimaryKey" parameterType="java.lang.Long" resultMap="CommodityImageBaseResultMap">
67+
select
68+
<include refid="Commodity_Image_Base_Column_List"/>
69+
from commodity_image
70+
where commodity_id = #{id,jdbcType=BIGINT}
71+
</select>
72+
73+
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="brandBaseResultMap">
2174
select
22-
<include refid="Base_Column_List"/>
75+
<include refid="Brand_Base_Column_List"/>
2376
from brand
2477
where id = #{id,jdbcType=BIGINT}
2578
</select>
@@ -28,7 +81,7 @@
2881
where id = #{id,jdbcType=BIGINT}
2982
</delete>
3083
<insert id="insert" parameterType="biz.llmall.common.entity.commodity.Brand">
31-
insert into brand (id, name, short_name,
84+
insert into brand (id, name,
3285
logo_lg, logo_md, logo_sm,
3386
create_time, update_time)
3487
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{shortName,jdbcType=VARCHAR},
@@ -38,17 +91,16 @@
3891
<update id="updateByPrimaryKey" parameterType="biz.llmall.common.entity.commodity.Brand">
3992
update brand
4093
set name = #{name,jdbcType=VARCHAR},
41-
short_name = #{shortName,jdbcType=VARCHAR},
4294
logo_lg = #{logoLg,jdbcType=VARCHAR},
4395
logo_md = #{logoMd,jdbcType=VARCHAR},
4496
logo_sm = #{logoSm,jdbcType=VARCHAR},
4597
create_time = #{createTime,jdbcType=TIMESTAMP},
4698
update_time = #{updateTime,jdbcType=TIMESTAMP}
4799
where id = #{id,jdbcType=BIGINT}
48100
</update>
49-
<select id="findBrands" resultMap="BaseResultMap">
101+
<select id="findBrands" resultMap="brandBaseResultMap">
50102
select
51-
<include refid="Base_Column_List"/>
103+
<include refid="Brand_Base_Column_List"/>
52104
from `brand` t1
53105
where 1=1
54106
</select>

llmall-commodity/src/main/resources/mappers/CategoryMapper.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,64 @@
77
<result column="parent_id" jdbcType="BIGINT" property="parentId"/>
88
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
99
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
10+
<collection property="commodities"
11+
column="id"
12+
ofType="biz.llmall.common.entity.commodity.Commodity"
13+
select="selectCommodityByPrimaryKey"/>
1014
</resultMap>
15+
<resultMap id="commodityBaseResultMap" type="biz.llmall.common.entity.commodity.Commodity">
16+
<id column="id" jdbcType="BIGINT" property="id"/>
17+
<result column="brand_id" jdbcType="BIGINT" property="brandId"/>
18+
<result column="name" jdbcType="VARCHAR" property="CommodityName"/>
19+
<result column="price" jdbcType="DECIMAL" property="price"/>
20+
<result column="category_id" jdbcType="BIGINT" property="categoryId"/>
21+
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
22+
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
23+
<collection property="commodityImages"
24+
ofType="biz.llmall.common.entity.commodity.CommodityImage"
25+
column="id"
26+
select="selectCommodityImagesByPrimaryKey"/>
27+
</resultMap>
28+
<resultMap extends="commodityBaseResultMap" id="ResultMapWithBLOBs" type="biz.llmall.common.entity.commodity.Commodity">
29+
<result column="description" jdbcType="LONGVARCHAR" property="description"/>
30+
</resultMap>
31+
<!--categories-->
1132
<sql id="Base_Column_List">
1233
id, name, parent_id, create_time, update_time
1334
</sql>
35+
<!--commodity-->
36+
<sql id="Commodity_Base_Column_List">
37+
id, brand_id, name, price, category_id, create_time, update_time
38+
</sql>
39+
<sql id="Commodity_Blob_Column_List">
40+
description
41+
</sql>
42+
43+
<!--commodity images-->
44+
<resultMap id="CommodityImageBaseResultMap" type="biz.llmall.common.entity.commodity.CommodityImage">
45+
<id column="id" jdbcType="BIGINT" property="id"/>
46+
<result column="commodity_id" jdbcType="BIGINT" property="commodityId"/>
47+
<result column="url" jdbcType="VARCHAR" property="url"/>
48+
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
49+
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
50+
</resultMap>
51+
<sql id="Commodity_Image_Base_Column_List">
52+
id, commodity_id, url, create_time, update_time
53+
</sql>
54+
<select id="selectCommodityImagesByPrimaryKey" parameterType="java.lang.Long" resultMap="CommodityImageBaseResultMap">
55+
select
56+
<include refid="Commodity_Image_Base_Column_List"/>
57+
from commodity_image
58+
where commodity_id = #{id,jdbcType=BIGINT}
59+
</select>
60+
<select id="selectCommodityByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
61+
select
62+
<include refid="Commodity_Base_Column_List"/>
63+
,
64+
<include refid="Commodity_Blob_Column_List"/>
65+
from commodity
66+
where brand_id = #{id,jdbcType=BIGINT}
67+
</select>
1468
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
1569
select
1670
<include refid="Base_Column_List"/>

llmall-commodity/src/main/resources/mappers/CommodityImageMapper.xml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
33
<mapper namespace="biz.llmall.commodity.model.mapper.CommodityImageMapper">
4-
<resultMap id="BaseResultMap" type="biz.llmall.common.entity.commodity.CommodityImage">
4+
<resultMap id="CommodityImageBaseResultMap" type="biz.llmall.common.entity.commodity.CommodityImage">
55
<id column="id" jdbcType="BIGINT" property="id"/>
66
<result column="commodity_id" jdbcType="BIGINT" property="commodityId"/>
77
<result column="url" jdbcType="VARCHAR" property="url"/>
88
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
99
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
10-
<association property="commodityId" javaType="biz.llmall.common.entity.commodity.Commodity">
11-
<id column="commodity_id" property="commodityId"/>
12-
</association>
1310
</resultMap>
14-
<sql id="Base_Column_List">
11+
<sql id="Commodity_Image_Base_Column_List">
1512
id, commodity_id, url, create_time, update_time
1613
</sql>
17-
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
14+
<select id="selectCommodityImagesByPrimaryKey" parameterType="java.lang.Long" resultMap="CommodityImageBaseResultMap">
1815
select
19-
<include refid="Base_Column_List"/>
16+
<include refid="Commodity_Image_Base_Column_List"/>
2017
from commodity_image
2118
where id = #{id,jdbcType=BIGINT}
2219
</select>

llmall-commodity/src/main/resources/mappers/CommodityMapper.xml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,43 @@
44
<resultMap id="BaseResultMap" type="biz.llmall.common.entity.commodity.Commodity">
55
<id column="id" jdbcType="BIGINT" property="id"/>
66
<result column="brand_id" jdbcType="BIGINT" property="brandId"/>
7-
<result column="name" jdbcType="VARCHAR" property="name"/>
7+
<result column="name" jdbcType="VARCHAR" property="CommodityName"/>
88
<result column="price" jdbcType="DECIMAL" property="price"/>
9-
<result column="cotegory_id" jdbcType="BIGINT" property="cotegoryId"/>
10-
<result column="parent_id" jdbcType="BIGINT" property="parentId"/>
9+
<result column="category_id" jdbcType="BIGINT" property="categoryId"/>
1110
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
1211
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
13-
<association property="brand" javaType="biz.llmall.common.entity.commodity.Brand" fetchType="lazy">
14-
<id column="brand_id" property="brandId"/>
15-
</association>
16-
<collection property="images"
17-
column="commodity_id"
18-
ofType="biz.llmall.common.entity.commodity.CommodityImage"
19-
fetchType="lazy">
12+
<collection
13+
property="commodityImages"
14+
column="id"
15+
ofType="biz.llmall.common.entity.commodity.CommodityImage"
16+
select="CommodityImageBaseResultMap">
2017
<id column="commodity_id" property="commodityId"/>
2118
</collection>
2219
</resultMap>
2320
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="biz.llmall.common.entity.commodity.Commodity">
2421
<result column="description" jdbcType="LONGVARCHAR" property="description"/>
2522
</resultMap>
2623
<sql id="Base_Column_List">
27-
id, brand_id, name, price, cotegory_id, parent_id, create_time, update_time
24+
id, brand_id, name, price, category_id, create_time, update_time
2825
</sql>
2926
<sql id="Blob_Column_List">
3027
description
3128
</sql>
29+
30+
<resultMap id="CommodityImageBaseResultMap" type="biz.llmall.common.entity.commodity.CommodityImage">
31+
<id column="id" jdbcType="BIGINT" property="id"/>
32+
<result column="commodity_id" jdbcType="BIGINT" property="commodityId"/>
33+
<result column="url" jdbcType="VARCHAR" property="url"/>
34+
</resultMap>
35+
<sql id="Commodity_Image_Base_Column_List">
36+
id, commodity_id, url, create_time, update_time
37+
</sql>
38+
<select id="selectCommodityImageByPrimaryKey" parameterType="java.lang.Long" resultMap="CommodityImageBaseResultMap">
39+
select
40+
<include refid="Commodity_Image_Base_Column_List"/>
41+
from commodity_image
42+
where commodity_id = #{id,jdbcType=BIGINT}
43+
</select>
3244
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
3345
select
3446
<include refid="Base_Column_List"/>
@@ -43,11 +55,11 @@
4355
</delete>
4456
<insert id="insert" parameterType="biz.llmall.common.entity.commodity.Commodity">
4557
insert into commodity (id, brand_id, name,
46-
price, cotegory_id, parent_id,
58+
price, category_id,
4759
create_time, update_time, description
4860
)
4961
values (#{id,jdbcType=BIGINT}, #{brandId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
50-
#{price,jdbcType=DECIMAL}, #{cotegoryId,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT},
62+
#{price,jdbcType=DECIMAL}, #{categoryId,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT},
5163
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{description,jdbcType=LONGVARCHAR}
5264
)
5365
</insert>
@@ -56,8 +68,7 @@
5668
set brand_id = #{brandId,jdbcType=BIGINT},
5769
name = #{name,jdbcType=VARCHAR},
5870
price = #{price,jdbcType=DECIMAL},
59-
cotegory_id = #{cotegoryId,jdbcType=BIGINT},
60-
parent_id = #{parentId,jdbcType=BIGINT},
71+
category_id = #{categoryId,jdbcType=BIGINT},
6172
create_time = #{createTime,jdbcType=TIMESTAMP},
6273
update_time = #{updateTime,jdbcType=TIMESTAMP},
6374
description = #{description,jdbcType=LONGVARCHAR}
@@ -68,8 +79,7 @@
6879
set brand_id = #{brandId,jdbcType=BIGINT},
6980
name = #{name,jdbcType=VARCHAR},
7081
price = #{price,jdbcType=DECIMAL},
71-
cotegory_id = #{cotegoryId,jdbcType=BIGINT},
72-
parent_id = #{parentId,jdbcType=BIGINT},
82+
category_id = #{categoryId,jdbcType=BIGINT},
7383
create_time = #{createTime,jdbcType=TIMESTAMP},
7484
update_time = #{updateTime,jdbcType=TIMESTAMP}
7585
where id = #{id,jdbcType=BIGINT}

0 commit comments

Comments
 (0)