Commit da33f028ea498e252beffab7402817965dc3bb47
1 parent
21afbe4d
商铺基础操作
Showing
5 changed files
with
152 additions
and
7 deletions
src/main/java/com/diligrp/xtrade/product/dao/ShopDao.java
1 | package com.diligrp.xtrade.product.dao; | 1 | package com.diligrp.xtrade.product.dao; |
2 | 2 | ||
3 | -public interface ShopDao { | 3 | +import java.util.List; |
4 | + | ||
5 | +import org.apache.ibatis.annotations.Mapper; | ||
4 | 6 | ||
7 | +import com.diligrp.xtrade.product.domain.entity.ShopDo; | ||
8 | +/** | ||
9 | + * | ||
10 | + * @ClassName: ShopDao | ||
11 | + * @Description 店铺dao | ||
12 | + * @author yangfan | ||
13 | + * @date 2020年4月21日 | ||
14 | + */ | ||
15 | +@Mapper | ||
16 | +public interface ShopDao { | ||
17 | + | ||
18 | + void insert(ShopDo shop); | ||
19 | + | ||
20 | + void update(ShopDo shop); | ||
21 | + | ||
22 | + ShopDo selectByShopId(Long shopId); | ||
23 | + | ||
24 | + List<ShopDo> selectByMerId(Long merId); | ||
5 | } | 25 | } |
src/main/java/com/diligrp/xtrade/product/domain/entity/Shop.java renamed to src/main/java/com/diligrp/xtrade/product/domain/entity/ShopDo.java
@@ -6,7 +6,7 @@ package com.diligrp.xtrade.product.domain.entity; | @@ -6,7 +6,7 @@ package com.diligrp.xtrade.product.domain.entity; | ||
6 | 6 | ||
7 | import com.diligrp.xtrade.shared.domain.BaseDo; | 7 | import com.diligrp.xtrade.shared.domain.BaseDo; |
8 | 8 | ||
9 | -public class Shop extends BaseDo { | 9 | +public class ShopDo extends BaseDo { |
10 | 10 | ||
11 | //商户id | 11 | //商户id |
12 | private Long merId; | 12 | private Long merId; |
@@ -35,10 +35,10 @@ public class Shop extends BaseDo { | @@ -35,10 +35,10 @@ public class Shop extends BaseDo { | ||
35 | //描述 | 35 | //描述 |
36 | private String description; | 36 | private String description; |
37 | 37 | ||
38 | - public Shop(){ | 38 | + public ShopDo(){ |
39 | } | 39 | } |
40 | 40 | ||
41 | - public Shop(Long shopId, Integer type){ | 41 | + public ShopDo(Long shopId, Integer type){ |
42 | this.shopId = shopId; | 42 | this.shopId = shopId; |
43 | this.type = type; | 43 | this.type = type; |
44 | } | 44 | } |
src/main/java/com/diligrp/xtrade/product/service/ShopService.java
1 | package com.diligrp.xtrade.product.service; | 1 | package com.diligrp.xtrade.product.service; |
2 | 2 | ||
3 | -public interface ShopService { | 3 | +import java.util.List; |
4 | + | ||
5 | +import com.diligrp.xtrade.product.domain.dto.ShopDto; | ||
6 | +import com.diligrp.xtrade.product.domain.entity.ShopDo; | ||
4 | 7 | ||
8 | +public interface ShopService { | ||
9 | + | ||
10 | + /** | ||
11 | + * @Title insert | ||
12 | + * @Description 保存shop | ||
13 | + * @param shop | ||
14 | + * @throws | ||
15 | + */ | ||
16 | + void insert(ShopDto shop); | ||
17 | + | ||
18 | + /** | ||
19 | + * | ||
20 | + * @Title update | ||
21 | + * @Description 修改 | ||
22 | + * @param shop | ||
23 | + * @throws | ||
24 | + */ | ||
25 | + void update(ShopDto shop); | ||
26 | + | ||
27 | + /** | ||
28 | + * | ||
29 | + * @Title selectByMerId | ||
30 | + * @Description 店铺id查询 | ||
31 | + * @param merId | ||
32 | + * @return | ||
33 | + * @throws | ||
34 | + */ | ||
35 | + ShopDo selectByShopId(Long shopId); | ||
36 | + | ||
37 | + /** | ||
38 | + * | ||
39 | + * @Title selectByMerId | ||
40 | + * @Description 根据商户id获取名下全部商铺 | ||
41 | + * @param merId | ||
42 | + * @return | ||
43 | + * @throws | ||
44 | + */ | ||
45 | + List<ShopDo> selectShopByMerId(Long merId); | ||
5 | } | 46 | } |
src/main/java/com/diligrp/xtrade/product/service/impl/ShopServiceImpl.java
1 | package com.diligrp.xtrade.product.service.impl; | 1 | package com.diligrp.xtrade.product.service.impl; |
2 | 2 | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import org.springframework.beans.BeanUtils; | ||
6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | +import org.springframework.stereotype.Service; | ||
8 | + | ||
9 | +import com.diligrp.xtrade.product.dao.ShopDao; | ||
10 | +import com.diligrp.xtrade.product.domain.dto.ShopDto; | ||
11 | +import com.diligrp.xtrade.product.domain.entity.ShopDo; | ||
3 | import com.diligrp.xtrade.product.service.ShopService; | 12 | import com.diligrp.xtrade.product.service.ShopService; |
4 | 13 | ||
14 | +@Service("shopService") | ||
5 | public class ShopServiceImpl implements ShopService { | 15 | public class ShopServiceImpl implements ShopService { |
6 | 16 | ||
17 | + @Autowired | ||
18 | + private ShopDao shopDao; | ||
19 | + | ||
20 | + @Override | ||
21 | + public void insert(ShopDto shop) { | ||
22 | + ShopDo shopDo = new ShopDo(); | ||
23 | + BeanUtils.copyProperties(shop, shopDo); | ||
24 | + shopDao.insert(shopDo); | ||
25 | + } | ||
26 | + | ||
27 | + @Override | ||
28 | + public void update(ShopDto shop) { | ||
29 | + ShopDo shopDo = new ShopDo(); | ||
30 | + BeanUtils.copyProperties(shop, shopDo); | ||
31 | + shopDao.update(shopDo); | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public ShopDo selectByShopId(Long shopId) { | ||
36 | + return shopDao.selectByShopId(shopId); | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public List<ShopDo> selectShopByMerId(Long merId) { | ||
41 | + List<ShopDo> shops = shopDao.selectByMerId(merId); | ||
42 | + return shops; | ||
43 | + } | ||
44 | + | ||
7 | } | 45 | } |
src/main/resources/mapping/com/diligrp/xtrade/product/ShopDao.xml
@@ -2,6 +2,52 @@ | @@ -2,6 +2,52 @@ | ||
2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
3 | <mapper namespace="com.diligrp.xtrade.product.dao.ShopDao"> | 3 | <mapper namespace="com.diligrp.xtrade.product.dao.ShopDao"> |
4 | 4 | ||
5 | - | ||
6 | - | 5 | + <sql id="QUERY_COLUMN_LIST"> |
6 | + <![CDATA[ | ||
7 | + `id`, `shop_id` AS shopId, `shop_name` AS shopName, `address`, `mer_id` AS merId, `type`, `status`, | ||
8 | + `main_business` AS mainBusiness, `self_shop` AS selfShop,`description`,`created_time` AS createdTime, `modified_time`AS modifiedTime | ||
9 | + ]]> | ||
10 | + </sql> | ||
11 | + <sql id="UPDATE_COLUMN_SET"> | ||
12 | + <set> | ||
13 | + <if test="shopName != null"><![CDATA[shop_name = #{shopName},]]></if> | ||
14 | + <if test="address != null"><![CDATA[address = #{address},]]></if> | ||
15 | + <if test="merId != null"><![CDATA[mer_id = #{merId},]]></if> | ||
16 | + <if test="type != null"><![CDATA[type = #{type},]]></if> | ||
17 | + <if test="status != null"><![CDATA[status = #{status},]]></if> | ||
18 | + <if test="mainBusiness != null"><![CDATA[main_business = #{mainBusiness},]]></if> | ||
19 | + <if test="selfShop != null"><![CDATA[self_shop = #{selfShop},]]></if> | ||
20 | + <if test="description != null"><![CDATA[description = #{description},]]></if> | ||
21 | + <![CDATA[modify_date = now()]]> | ||
22 | + </set> | ||
23 | + </sql> | ||
24 | + <insert id="insert" parameterType="com.diligrp.xtrade.product.domain.entity.ShopDo"> | ||
25 | + <![CDATA[ | ||
26 | + INSERT INTO `xt_shop`(`id`, `shop_id`, `shop_name`, `self_shop`, `mer_id`, `main_biz`, `type`, `status`, `address`, `description`, `created_time`, `modified_time`) | ||
27 | + VALUES (#{id}, #{shopId}, #{shopName}, #{selfShop}, #{merId}, #{mainBiz}, #{type}, #{status}, #{address}, #{description}, now(), now()); | ||
28 | + ]]> | ||
29 | + </insert> | ||
30 | + <select id="selectByShopId" parameterType="lang" resultType="com.diligrp.xtrade.product.domain.entity.ShopDo"> | ||
31 | + <![CDATA[ | ||
32 | + SELECT | ||
33 | + ]]> | ||
34 | + <include refid="QUERY_COLUMN_LIST" /> | ||
35 | + <![CDATA[ | ||
36 | + FROM `xt_shop` WHERE shop_id = #{shopId} | ||
37 | + ]]> | ||
38 | + </select> | ||
39 | + <update id="update" parameterType="com.diligrp.xtrade.product.domain.entity.ShopDo"> | ||
40 | + <![CDATA[UPDATE `xt_shop`]]> | ||
41 | + <include refid="UPDATE_COLUMN_SET" /> | ||
42 | + <![CDATA[WHERE mer_id = #{merId}]]> | ||
43 | + </update> | ||
44 | + <select id="selectByMerId" parameterType="lang" resultType="com.diligrp.xtrade.product.domain.dto.ShopDo"> | ||
45 | + <![CDATA[ | ||
46 | + SELECT | ||
47 | + ]]> | ||
48 | + <include refid="QUERY_COLUMN_LIST" /> | ||
49 | + <![CDATA[ | ||
50 | + FROM `xt_shop` WHERE mer_id = #{merId} | ||
51 | + ]]> | ||
52 | + </select> | ||
7 | </mapper> | 53 | </mapper> |
8 | \ No newline at end of file | 54 | \ No newline at end of file |