Search in sources :

Example 1 with FreightTemplate

use of cn.lili.modules.store.entity.dos.FreightTemplate in project lilishop by lilishop.

the class FreightTemplateServiceImpl method editFreightTemplate.

@Override
@Transactional(rollbackFor = Exception.class)
public FreightTemplateVO editFreightTemplate(FreightTemplateVO freightTemplateVO) {
    // 获取当前登录商家账号
    AuthUser tokenUser = UserContext.getCurrentUser();
    if (freightTemplateVO.getId().equals(tokenUser.getStoreId())) {
        throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
    }
    FreightTemplate freightTemplate = new FreightTemplate();
    // 复制属性
    BeanUtils.copyProperties(freightTemplateVO, freightTemplate);
    // 修改运费模板
    this.updateById(freightTemplate);
    // 删除模板子内容
    freightTemplateChildService.removeFreightTemplate(freightTemplateVO.getId());
    // 给子模板赋父模板的id
    List<FreightTemplateChild> list = new ArrayList<>();
    for (FreightTemplateChild freightTemplateChild : freightTemplateVO.getFreightTemplateChildList()) {
        freightTemplateChild.setFreightTemplateId(freightTemplate.getId());
        list.add(freightTemplateChild);
    }
    // 添加模板子内容
    freightTemplateChildService.addFreightTemplateChild(list);
    // 更新缓存
    cache.remove(CachePrefix.SHIP_TEMPLATE.getPrefix() + tokenUser.getStoreId());
    return null;
}
Also used : ServiceException(cn.lili.common.exception.ServiceException) ArrayList(java.util.ArrayList) AuthUser(cn.lili.common.security.AuthUser) FreightTemplateChild(cn.lili.modules.store.entity.dos.FreightTemplateChild) FreightTemplate(cn.lili.modules.store.entity.dos.FreightTemplate) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with FreightTemplate

use of cn.lili.modules.store.entity.dos.FreightTemplate in project lilishop by lilishop.

the class FreightTemplateServiceImpl method addFreightTemplate.

@Override
public FreightTemplateVO addFreightTemplate(FreightTemplateVO freightTemplateVO) {
    // 获取当前登录商家账号
    AuthUser tokenUser = UserContext.getCurrentUser();
    FreightTemplate freightTemplate = new FreightTemplate();
    // 设置店铺ID
    freightTemplateVO.setStoreId(tokenUser.getStoreId());
    // 复制属性
    BeanUtils.copyProperties(freightTemplateVO, freightTemplate);
    // 添加运费模板
    this.save(freightTemplate);
    // 给子模板赋父模板的id
    List<FreightTemplateChild> list = new ArrayList<>();
    // 如果子运费模板不为空则进行新增
    if (freightTemplateVO.getFreightTemplateChildList() != null) {
        for (FreightTemplateChild freightTemplateChild : freightTemplateVO.getFreightTemplateChildList()) {
            freightTemplateChild.setFreightTemplateId(freightTemplate.getId());
            list.add(freightTemplateChild);
        }
        // 添加运费模板子内容
        freightTemplateChildService.addFreightTemplateChild(list);
    }
    // 更新缓存
    cache.remove(CachePrefix.SHIP_TEMPLATE.getPrefix() + tokenUser.getStoreId());
    return freightTemplateVO;
}
Also used : ArrayList(java.util.ArrayList) AuthUser(cn.lili.common.security.AuthUser) FreightTemplateChild(cn.lili.modules.store.entity.dos.FreightTemplateChild) FreightTemplate(cn.lili.modules.store.entity.dos.FreightTemplate)

Example 3 with FreightTemplate

use of cn.lili.modules.store.entity.dos.FreightTemplate in project lilishop by lilishop.

the class FreightTemplateServiceImpl method getFreightTemplateList.

@Override
public List<FreightTemplateVO> getFreightTemplateList(String storeId) {
    // 先从缓存中获取运费模板,如果有则直接返回,如果没有则查询数据后再返回
    List<FreightTemplateVO> list = (List<FreightTemplateVO>) cache.get(CachePrefix.SHIP_TEMPLATE.getPrefix() + storeId);
    if (list != null) {
        return list;
    }
    list = new ArrayList<>();
    // 查询运费模板
    LambdaQueryWrapper<FreightTemplate> lambdaQueryWrapper = Wrappers.lambdaQuery();
    lambdaQueryWrapper.eq(FreightTemplate::getStoreId, storeId);
    List<FreightTemplate> freightTemplates = this.baseMapper.selectList(lambdaQueryWrapper);
    if (!freightTemplates.isEmpty()) {
        // 如果模板不为空则查询子模板信息
        for (FreightTemplate freightTemplate : freightTemplates) {
            FreightTemplateVO freightTemplateVO = new FreightTemplateVO();
            BeanUtil.copyProperties(freightTemplate, freightTemplateVO);
            List<FreightTemplateChild> freightTemplateChildren = freightTemplateChildService.getFreightTemplateChild(freightTemplate.getId());
            if (!freightTemplateChildren.isEmpty()) {
                freightTemplateVO.setFreightTemplateChildList(freightTemplateChildren);
            }
            list.add(freightTemplateVO);
        }
    }
    cache.put(CachePrefix.SHIP_TEMPLATE.getPrefix() + storeId, list);
    return list;
}
Also used : FreightTemplateVO(cn.lili.modules.store.entity.vos.FreightTemplateVO) ArrayList(java.util.ArrayList) List(java.util.List) FreightTemplateChild(cn.lili.modules.store.entity.dos.FreightTemplateChild) FreightTemplate(cn.lili.modules.store.entity.dos.FreightTemplate)

Example 4 with FreightTemplate

use of cn.lili.modules.store.entity.dos.FreightTemplate in project lilishop by lilishop.

the class FreightTemplateServiceImpl method removeFreightTemplate.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeFreightTemplate(String id) {
    // 获取当前登录商家账号
    AuthUser tokenUser = UserContext.getCurrentUser();
    LambdaQueryWrapper<FreightTemplate> lambdaQueryWrapper = Wrappers.lambdaQuery();
    lambdaQueryWrapper.eq(FreightTemplate::getStoreId, tokenUser.getStoreId());
    lambdaQueryWrapper.eq(FreightTemplate::getId, id);
    // 如果删除成功则删除运费模板子项
    if (this.remove(lambdaQueryWrapper)) {
        cache.remove(CachePrefix.SHIP_TEMPLATE.getPrefix() + tokenUser.getStoreId());
        return freightTemplateChildService.removeFreightTemplate(id);
    }
    return false;
}
Also used : AuthUser(cn.lili.common.security.AuthUser) FreightTemplate(cn.lili.modules.store.entity.dos.FreightTemplate) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with FreightTemplate

use of cn.lili.modules.store.entity.dos.FreightTemplate in project lilishop by lilishop.

the class FreightTemplateServiceImpl method getFreightTemplate.

@Override
public FreightTemplateVO getFreightTemplate(String id) {
    FreightTemplateVO freightTemplateVO = new FreightTemplateVO();
    // 获取运费模板
    FreightTemplate freightTemplate = this.getById(id);
    if (freightTemplate != null) {
        // 复制属性
        BeanUtils.copyProperties(freightTemplate, freightTemplateVO);
        // 填写运费模板子内容
        List<FreightTemplateChild> freightTemplateChildList = freightTemplateChildService.getFreightTemplateChild(id);
        freightTemplateVO.setFreightTemplateChildList(freightTemplateChildList);
    }
    return freightTemplateVO;
}
Also used : FreightTemplateVO(cn.lili.modules.store.entity.vos.FreightTemplateVO) FreightTemplateChild(cn.lili.modules.store.entity.dos.FreightTemplateChild) FreightTemplate(cn.lili.modules.store.entity.dos.FreightTemplate)

Aggregations

FreightTemplate (cn.lili.modules.store.entity.dos.FreightTemplate)6 AuthUser (cn.lili.common.security.AuthUser)4 FreightTemplateChild (cn.lili.modules.store.entity.dos.FreightTemplateChild)4 ArrayList (java.util.ArrayList)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ServiceException (cn.lili.common.exception.ServiceException)2 FreightTemplateVO (cn.lili.modules.store.entity.vos.FreightTemplateVO)2 Goods (cn.lili.modules.goods.entity.dos.Goods)1 List (java.util.List)1