1a4c983f by 李仁豪

[feat] 店铺增删改查接口

1 parent 7cec7e07
......@@ -3,11 +3,21 @@ package com.ql.backend.ploycenter.application.impl;
import com.ql.backend.core.interfaces.vo.PageVO;
import com.ql.backend.ploycenter.application.ShopService;
import com.ql.backend.ploycenter.domain.condition.ShopCondition;
import com.ql.backend.ploycenter.domain.po.ShopPO;
import com.ql.backend.ploycenter.infrastructure.converter.mapper.ShopConverter;
import com.ql.backend.ploycenter.infrastructure.persistence.dao.ShopDao;
import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest;
import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest;
import com.ql.backend.ploycenter.interfaces.vo.ShopVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* @author lirenhao
......@@ -17,26 +27,56 @@ import org.springframework.stereotype.Service;
@Service
public class ShopServiceImpl implements ShopService {
@Resource
private ShopDao shopDao;
@Override
@Transactional
public String createShop(ShopCreateRequest request) {
/* todo 创建店铺 */
return null;
ShopPO po = ShopConverter.INSTANCE.convertRequest2Po(request);
po.setShopId(UUID.randomUUID().toString());
po.setGmtCreated(new Date());
po.setGmtModified(new Date());
po.setIsDeleted(Boolean.FALSE);
shopDao.save(po);
if (!ObjectUtils.isEmpty(request.getBindPloyId())) {
/* todo 绑定策略 */
}
return po.getShopId();
}
@Override
@Transactional
public void updateShop(String id, ShopUpdateRequest request) {
/* todo 更新店铺信息 */
ShopPO po = ShopConverter.INSTANCE.convertRequest2Po(request);
po.setShopId(id);
po.setGmtModified(new Date());
shopDao.updateById(po);
if (!ObjectUtils.isEmpty(request.getBindPloyId())) {
/* todo 绑定策略 */
}
}
@Override
public PageVO<ShopVO> findShop(ShopCondition condition) {
/* todo 查询店铺列表 */
return null;
long total = shopDao.countByCondition(condition);
List<ShopPO> list = shopDao.listByCondition(condition);
return PageVO.<ShopVO>builder()
.page(condition.getPage())
.size(condition.getSize())
.total(total)
.list(ShopConverter.INSTANCE.convertPo2Vo(list))
.build();
}
@Override
public ShopVO getShop(String id) {
/* todo 查询店铺详情 */
return null;
ShopPO po = shopDao.getShopById(id);
ShopVO vo = ShopConverter.INSTANCE.convertPo2Vo(po);
/* todo 查询策略详情, 并查询绑定的店铺信息 */
return vo;
}
}
......
package com.ql.backend.ploycenter.common.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author lirenhao
* date: 2022/9/14 15:33
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ShopDTO {
private String shopId;
}
package com.ql.backend.ploycenter.infrastructure.converter.mapper;
import com.ql.backend.ploycenter.common.dto.ShopDTO;
import com.ql.backend.ploycenter.domain.po.ShopPO;
import com.ql.backend.ploycenter.interfaces.request.ShopCreateRequest;
import com.ql.backend.ploycenter.interfaces.request.ShopUpdateRequest;
import com.ql.backend.ploycenter.interfaces.vo.ShopVO;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @author lirenhao
* date: 2022/9/5 17:45
*/
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE,
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface ShopConverter extends CommonConverter<ShopPO, ShopDTO, ShopVO> {
ShopConverter INSTANCE = Mappers.getMapper(ShopConverter.class);
ShopPO convertRequest2Po(ShopCreateRequest request);
ShopPO convertRequest2Po(ShopUpdateRequest request);
List<ShopVO> convertPo2Vo(List<ShopPO> pos);
ShopVO convertPo2Vo(ShopPO po);
}
package com.ql.backend.ploycenter.infrastructure.persistence.dao;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ql.backend.ploycenter.domain.condition.ShopCondition;
import com.ql.backend.ploycenter.domain.po.ShopPO;
import java.util.List;
/**
* @author lirenhao
* date: 2022/9/14 15:29
*/
public interface ShopDao extends IService<ShopPO> {
ShopPO getShopById(String id);
long countByCondition(ShopCondition condition);
List<ShopPO> listByCondition(ShopCondition condition);
}
package com.ql.backend.ploycenter.infrastructure.persistence.dao.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ql.backend.ploycenter.domain.condition.ShopCondition;
import com.ql.backend.ploycenter.domain.po.ShopPO;
import com.ql.backend.ploycenter.infrastructure.persistence.dao.ShopDao;
import com.ql.backend.ploycenter.infrastructure.persistence.mapper.ShopMapper;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author lirenhao
* date: 2022/9/14 15:30
*/
@Service
public class ShopDaoImpl extends ServiceImpl<ShopMapper, ShopPO> implements ShopDao {
@Override
public ShopPO getShopById(String id) {
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopPO::getShopId, id);
return this.baseMapper.selectOne(wrapper);
}
@Override
public long countByCondition(ShopCondition condition) {
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
return count(wrapper);
}
@Override
public List<ShopPO> listByCondition(ShopCondition condition) {
LambdaQueryWrapper<ShopPO> wrapper = new LambdaQueryWrapper<>();
wrapper.last("LIMIT " + (condition.getPage() * condition.getSize()) + ", " + condition.getSize());
return this.list(wrapper);
}
}
package com.ql.backend.ploycenter.infrastructure.persistence.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ql.backend.ploycenter.domain.po.ShopPO;
/**
* @author lirenhao
* date: 2022/9/14 15:29
*/
public interface ShopMapper extends BaseMapper<ShopPO> {
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!