| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.common.model.dtos.shop.ComShopAddressDTO; |
| | | import com.panzhihua.common.model.dtos.shop.PageComShopAddressDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import com.panzhihua.service_community.dao.ComShopUserAddressDAO; |
| | | import com.panzhihua.service_community.model.dos.ComShopUserAddressDO; |
| | | import com.panzhihua.service_community.service.ComShopUserAddressService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * @auther lyq |
| | |
| | | @Service |
| | | public class ComShopUserAddressServiceImpl extends ServiceImpl<ComShopUserAddressDAO, ComShopUserAddressDO> implements ComShopUserAddressService { |
| | | |
| | | /** |
| | | * 查询用户收获地址列表 |
| | | * @param comShopAddressDTO 请求参数 |
| | | * @return 用户收货地址列表 |
| | | */ |
| | | @Override |
| | | public R shopUserAddressList(PageComShopAddressDTO comShopAddressDTO){ |
| | | Page page = new Page<>(comShopAddressDTO.getPageNum(),comShopAddressDTO.getPageSize()); |
| | | return R.ok(this.baseMapper.pageUserAddressList(page,comShopAddressDTO.getUserId())); |
| | | } |
| | | |
| | | /** |
| | | * 用户添加收货地址 |
| | | * @param comShopAddressDTO 请求参数 |
| | | * @return 添加结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R shopAddUserAddress(ComShopAddressDTO comShopAddressDTO){ |
| | | ComShopUserAddressDO userAddressDO = new ComShopUserAddressDO(); |
| | | BeanUtils.copyProperties(comShopAddressDTO,userAddressDO); |
| | | |
| | | //如果新增的地址为默认地址,需要修改原来的默认地址为不默认 |
| | | if(userAddressDO.getIsDefault().equals(ComShopUserAddressDO.isDefault.yes)){ |
| | | ComShopUserAddressDO oldUserAddressDO = this.baseMapper.selectOne(new QueryWrapper<ComShopUserAddressDO>() |
| | | .eq("user_id",comShopAddressDTO.getUserId()).eq("is_default",ComShopUserAddressDO.isDefault.yes)); |
| | | if(oldUserAddressDO != null){ |
| | | oldUserAddressDO.setIsDefault(ComShopUserAddressDO.isDefault.no); |
| | | this.baseMapper.updateById(oldUserAddressDO); |
| | | } |
| | | } |
| | | |
| | | if(this.baseMapper.insert(userAddressDO) > 0){ |
| | | return R.ok(); |
| | | }else{ |
| | | return R.fail("添加收货地址失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 用户修改收货地址 |
| | | * @param comShopAddressDTO 请求参数 |
| | | * @return 修改结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R shopEditUserAddress(ComShopAddressDTO comShopAddressDTO){ |
| | | |
| | | //查询用户收货地址 |
| | | ComShopUserAddressDO userAddressDO = this.baseMapper.selectById(comShopAddressDTO.getAddressId()); |
| | | if(userAddressDO == null){ |
| | | return R.fail("未查询到用户收货地址信息"); |
| | | } |
| | | |
| | | BeanUtils.copyProperties(comShopAddressDTO,userAddressDO); |
| | | //如果要修改的地址为默认地址,需要修改原来的默认地址为不默认 |
| | | if(comShopAddressDTO.getIsDefault().equals(ComShopUserAddressDO.isDefault.yes)){ |
| | | ComShopUserAddressDO oldUserAddressDO = this.baseMapper.selectOne(new QueryWrapper<ComShopUserAddressDO>() |
| | | .eq("user_id",comShopAddressDTO.getUserId()).eq("is_default",ComShopUserAddressDO.isDefault.yes)); |
| | | if(oldUserAddressDO != null){ |
| | | //判断当前要修改的默认地址是否本来就是默认地址 |
| | | if(!oldUserAddressDO.getId().equals(userAddressDO.getId())){ |
| | | oldUserAddressDO.setIsDefault(ComShopUserAddressDO.isDefault.no); |
| | | this.baseMapper.updateById(oldUserAddressDO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(this.baseMapper.updateById(userAddressDO) > 0){ |
| | | return R.ok(); |
| | | }else{ |
| | | return R.fail("添加收货地址失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 用户删除收货地址 |
| | | * @param addressId 收货地址id |
| | | * @return 删除结果 |
| | | */ |
| | | public R shopDelUserAddress(Long addressId){ |
| | | //查询用户收货地址 |
| | | ComShopUserAddressDO userAddressDO = this.baseMapper.selectById(addressId); |
| | | if(userAddressDO == null){ |
| | | return R.fail("未查询到用户收货地址信息"); |
| | | } |
| | | if(this.baseMapper.deleteById(addressId) > 0){ |
| | | return R.ok(); |
| | | }else{ |
| | | return R.fail("删除收货地址失败"); |
| | | } |
| | | } |
| | | |
| | | } |