Excel实战解析之项目进度图(excel做进度图)
487
2022-05-28
文章目录
概述
Service接口
Service接口实现类
单元测试
Github地址
概述
在完成了 Dao层的部分之后,顺其自然的我们来到了Service层,需要调用Dao层提供的操作数据库的方法。
主要步骤如下:
1. 如用户上传了缩略图,则将原有的缩略图删除(磁盘上删除),并更新tb_product表的img_addr字段,否则不做任何处理。
2. 如果用户上传了新的商品详情图片,则将原有的属于该productId下的全部的商品详情图删除(磁盘上删除),同时删除productId对应的tb_product_img中的全部数据。
3. 更新tb_product的信息
Service接口
新增两个接口如下:
/** * * * @Title: queryProductById * * @Description: 根据productId查询product * * @param productId * * @return: Product */ Product queryProductById(long productId); /** * * * @Title: modifyProduct * * @Description: TODO * * @param product * 产品信息 * @param imageHolder * 产品缩略图的封装信息 * @param prodImgDetailList * 产品详情图片的封装信息 * @throws ProductOperationException * * @return: ProductExecution */ ProductExecution modifyProduct(Product product, ImageHolder imageHolder, List
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Service接口实现类
/** * 注意事务控制@Transactional */ @Override @Transactional public ProductExecution modifyProduct(Product product, ImageHolder imageHolder, List
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
单元测试
@Test public void testModifyProduct() throws Exception { // 注意表中的外键关系,确保这些数据在对应的表中的存在 ProductCategory productCategory = new ProductCategory(); productCategory.setProductCategoryId(36L); // 注意表中的外键关系,确保这些数据在对应的表中的存在 Shop shop = new Shop(); shop.setShopId(5L); // 构造Product Product product = new Product(); product.setProductName("offical_product"); product.setProductDesc("product offical desc"); product.setNormalPrice("100"); product.setPromotionPrice("80"); product.setPriority(66); product.setLastEditTime(new Date()); product.setProductCategory(productCategory); product.setShop(shop); product.setProductId(7L); // 构造 商品图片 File productFile = new File("D:/o2o/1.jpg"); InputStream ins = new FileInputStream(productFile); ImageHolder imageHolder = new ImageHolder(ins, productFile.getName()); // 构造商品详情图片 List
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
SQL日志如下:
JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@6f63b475] will be managed by Spring ==> Preparing: SELECT p.product_id, p.product_name, p.product_desc, p.img_addr, p.normal_price, p.promotion_price, p.priority, p.create_time, p.last_edit_time, p.enable_status, p.product_category_id, p.shop_id, pm.product_img_id, pm.img_addr, pm.img_desc, pm.priority, pm.create_time FROM tb_product p LEFT JOIN tb_product_img pm ON p.product_id =pm.product_id WHERE p.product_id = ? ORDER BY pm.priority DESC ==> Parameters: 7(Long) <== Columns: product_id, product_name, product_desc, img_addr, normal_price, promotion_price, priority, create_time, last_edit_time, enable_status, product_category_id, shop_id, product_img_id, img_addr, img_desc, priority, create_time <== Row: 7, 香飘飘, test添加商品, \upload\item\shopImage\5\2018062911342810920.png, 5, 3.5, 99, 2018-06-29 11:34:28.0, 2018-06-29 11:34:28.0, 1, 36, 5, 11, \upload\item\shopImage\5\20180629113433657450.jpg, null, null, 2018-06-29 11:34:37.0 <== Row: 7, 香飘飘, test添加商品, \upload\item\shopImage\5\2018062911342810920.png, 5, 3.5, 99, 2018-06-29 11:34:28.0, 2018-06-29 11:34:28.0, 1, 36, 5, 13, \upload\item\shopImage\5\20180629113434424572.jpg, null, null, 2018-06-29 11:34:37.0 <== Row: 7, 香飘飘, test添加商品, \upload\item\shopImage\5\2018062911342810920.png, 5, 3.5, 99, 2018-06-29 11:34:28.0, 2018-06-29 11:34:28.0, 1, 36, 5, 12, \upload\item\shopImage\5\20180629113433541021.jpg, null, null, 2018-06-29 11:34:37.0 <== Total: 3 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280] from current transaction ==> Preparing: SELECT product_img_id, img_addr, img_desc, priority, create_time, product_id FROM tb_product_img WHERE product_id=? ORDER BY product_img_id ==> Parameters: 7(Long) <== Columns: product_img_id, img_addr, img_desc, priority, create_time, product_id <== Row: 11, \upload\item\shopImage\5\20180629113433657450.jpg, null, null, 2018-06-29 11:34:37.0, 7 <== Row: 12, \upload\item\shopImage\5\20180629113433541021.jpg, null, null, 2018-06-29 11:34:37.0, 7 <== Row: 13, \upload\item\shopImage\5\20180629113434424572.jpg, null, null, 2018-06-29 11:34:37.0, 7 <== Total: 3 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280] from current transaction ==> Preparing: DELETE FROM tb_product_img WHERE product_id = ? ==> Parameters: 7(Long) <== Updates: 3 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280] from current transaction ==> Preparing: INSERT INTO tb_product_img ( img_addr, img_desc, priority, create_time, product_id ) VALUES ( ?, ?, ?, ?, ? ) , ( ?, ?, ?, ?, ? ) ==> Parameters: \upload\item\shopImage\5\20180701003247930380.jpg(String), null, null, 2018-07-01 00:32:48.299(Timestamp), 7(Long), \upload\item\shopImage\5\20180701003247961681.jpg(String), null, null, 2018-07-01 00:32:48.299(Timestamp), 7(Long) <== Updates: 2 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280] from current transaction ==> Preparing: UPDATE tb_product SET product_name = ?, product_desc = ?, img_addr = ?, normal_price = ?, promotion_price = ?, priority = ?, last_edit_time = ?, product_category_id = ? WHERE product_id = ? AND shop_id=? ==> Parameters: offical_product(String), product offical desc(String), \upload\item\shopImage\5\2018070100324625530.jpg(String), 100(String), 80(String), 66(Integer), 2018-07-01 00:32:45.683(Timestamp), 36(Long), 7(Long), 5(Long) <== Updates: 1 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@64a40280]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
检查数据库记录和磁盘上的文件,正确,单元测试通过。
Github地址
代码地址: https://github.com/yangshangwei/o2o
单元测试
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。