1a4c983f by 李仁豪

[feat] 店铺增删改查接口

1 parent 7cec7e07
...@@ -3,11 +3,21 @@ package com.ql.backend.ploycenter.application.impl; ...@@ -3,11 +3,21 @@ package com.ql.backend.ploycenter.application.impl;
3 import com.ql.backend.core.interfaces.vo.PageVO; 3 import com.ql.backend.core.interfaces.vo.PageVO;
4 import com.ql.backend.ploycenter.application.ShopService; 4 import com.ql.backend.ploycenter.application.ShopService;
5 import com.ql.backend.ploycenter.domain.condition.ShopCondition; 5 import com.ql.backend.ploycenter.domain.condition.ShopCondition;
6 import com.ql.backend.ploycenter.domain.po.ShopPO;
7 import com.ql.backend.ploycenter.infrastructure.converter.mapper.ShopConverter;
8 import com.ql.backend.ploycenter.infrastructure.persistence.dao.ShopDao;
6 import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest; 9 import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest;
7 import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest; 10 import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest;
8 import com.ql.backend.ploycenter.interfaces.vo.ShopVO; 11 import com.ql.backend.ploycenter.interfaces.vo.ShopVO;
9 import lombok.extern.slf4j.Slf4j; 12 import lombok.extern.slf4j.Slf4j;
10 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.util.ObjectUtils;
16
17 import javax.annotation.Resource;
18 import java.util.Date;
19 import java.util.List;
20 import java.util.UUID;
11 21
12 /** 22 /**
13 * @author lirenhao 23 * @author lirenhao
...@@ -17,26 +27,56 @@ import org.springframework.stereotype.Service; ...@@ -17,26 +27,56 @@ import org.springframework.stereotype.Service;
17 @Service 27 @Service
18 public class ShopServiceImpl implements ShopService { 28 public class ShopServiceImpl implements ShopService {
19 29
30 @Resource
31 private ShopDao shopDao;
32
20 @Override 33 @Override
34 @Transactional
21 public String createShop(ShopCreateRequest request) { 35 public String createShop(ShopCreateRequest request) {
22 /* todo 创建店铺 */ 36 ShopPO po = ShopConverter.INSTANCE.convertRequest2Po(request);
23 return null; 37 po.setShopId(UUID.randomUUID().toString());
38 po.setGmtCreated(new Date());
39 po.setGmtModified(new Date());
40 po.setIsDeleted(Boolean.FALSE);
41 shopDao.save(po);
42
43 if (!ObjectUtils.isEmpty(request.getBindPloyId())) {
44 /* todo 绑定策略 */
45 }
46
47 return po.getShopId();
24 } 48 }
25 49
26 @Override 50 @Override
51 @Transactional
27 public void updateShop(String id, ShopUpdateRequest request) { 52 public void updateShop(String id, ShopUpdateRequest request) {
28 /* todo 更新店铺信息 */ 53 ShopPO po = ShopConverter.INSTANCE.convertRequest2Po(request);
54 po.setShopId(id);
55 po.setGmtModified(new Date());
56 shopDao.updateById(po);
57
58 if (!ObjectUtils.isEmpty(request.getBindPloyId())) {
59 /* todo 绑定策略 */
60 }
29 } 61 }
30 62
31 @Override 63 @Override
32 public PageVO<ShopVO> findShop(ShopCondition condition) { 64 public PageVO<ShopVO> findShop(ShopCondition condition) {
33 /* todo 查询店铺列表 */ 65 long total = shopDao.countByCondition(condition);
34 return null; 66 List<ShopPO> list = shopDao.listByCondition(condition);
67 return PageVO.<ShopVO>builder()
68 .page(condition.getPage())
69 .size(condition.getSize())
70 .total(total)
71 .list(ShopConverter.INSTANCE.convertPo2Vo(list))
72 .build();
35 } 73 }
36 74
37 @Override 75 @Override
38 public ShopVO getShop(String id) { 76 public ShopVO getShop(String id) {
39 /* todo 查询店铺详情 */ 77 ShopPO po = shopDao.getShopById(id);
40 return null; 78 ShopVO vo = ShopConverter.INSTANCE.convertPo2Vo(po);
79 /* todo 查询策略详情, 并查询绑定的店铺信息 */
80 return vo;
41 } 81 }
42 } 82 }
......
1 package com.ql.backend.ploycenter.common.dto;
2
3 import lombok.AllArgsConstructor;
4 import lombok.Builder;
5 import lombok.Data;
6 import lombok.NoArgsConstructor;
7
8 /**
9 * @author lirenhao
10 * date: 2022/9/14 15:33
11 */
12 @Data
13 @Builder
14 @NoArgsConstructor
15 @AllArgsConstructor
16 public class ShopDTO {
17
18 private String shopId;
19 }
1 package com.ql.backend.ploycenter.infrastructure.converter.mapper;
2
3 import com.ql.backend.ploycenter.common.dto.ShopDTO;
4 import com.ql.backend.ploycenter.domain.po.ShopPO;
5 import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest;
6 import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest;
7 import com.ql.backend.ploycenter.interfaces.vo.ShopVO;
8 import org.mapstruct.Mapper;
9 import org.mapstruct.NullValueCheckStrategy;
10 import org.mapstruct.NullValuePropertyMappingStrategy;
11 import org.mapstruct.ReportingPolicy;
12 import org.mapstruct.factory.Mappers;
13
14 import java.util.List;
15
16 /**
17 * @author lirenhao
18 * date: 2022/9/5 17:45
19 */
20 @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE,
21 nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
22 nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
23 public interface ShopConverter extends CommonConverter<ShopPO, ShopDTO, ShopVO> {
24
25 ShopConverter INSTANCE = Mappers.getMapper(ShopConverter.class);
26
27 ShopPO convertRequest2Po(ShopCreateRequest request);
28
29 ShopPO convertRequest2Po(ShopUpdateRequest request);
30
31 List<ShopVO> convertPo2Vo(List<ShopPO> pos);
32
33 ShopVO convertPo2Vo(ShopPO po);
34 }
1 package com.ql.backend.ploycenter.infrastructure.persistence.dao;
2
3 import com.baomidou.mybatisplus.extension.service.IService;
4 import com.ql.backend.ploycenter.domain.condition.ShopCondition;
5 import com.ql.backend.ploycenter.domain.po.ShopPO;
6
7 import java.util.List;
8
9 /**
10 * @author lirenhao
11 * date: 2022/9/14 15:29
12 */
13 public interface ShopDao extends IService<ShopPO> {
14
15 ShopPO getShopById(String id);
16
17 long countByCondition(ShopCondition condition);
18
19 List<ShopPO> listByCondition(ShopCondition condition);
20 }
1 package com.ql.backend.ploycenter.infrastructure.persistence.dao.impl;
2
3 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5 import com.ql.backend.ploycenter.domain.condition.ShopCondition;
6 import com.ql.backend.ploycenter.domain.po.ShopPO;
7 import com.ql.backend.ploycenter.infrastructure.persistence.dao.ShopDao;
8 import com.ql.backend.ploycenter.infrastructure.persistence.mapper.ShopMapper;
9 import org.springframework.stereotype.Service;
10
11 import java.util.List;
12
13 /**
14 * @author lirenhao
15 * date: 2022/9/14 15:30
16 */
17 @Service
18 public class ShopDaoImpl extends ServiceImpl<ShopMapper, ShopPO> implements ShopDao {
19 @Override
20 public ShopPO getShopById(String id) {
21 LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
22 wrapper.eq(ShopPO::getShopId, id);
23 return this.baseMapper.selectOne(wrapper);
24 }
25
26 @Override
27 public long countByCondition(ShopCondition condition) {
28 LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
29 return count(wrapper);
30 }
31
32 @Override
33 public List<ShopPO> listByCondition(ShopCondition condition) {
34 LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
35 wrapper.last("LIMIT " + (condition.getPage() * condition.getSize()) + ", " + condition.getSize());
36 return this.list(wrapper);
37 }
38 }
1 package com.ql.backend.ploycenter.infrastructure.persistence.mapper;
2
3 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 import com.ql.backend.ploycenter.domain.po.ShopPO;
5
6 /**
7 * @author lirenhao
8 * date: 2022/9/14 15:29
9 */
10 public interface ShopMapper extends BaseMapper<ShopPO> {
11 }
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!