| | |
| | | package com.oying.modules.sh.service.impl; |
| | | |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.sh.domain.UserAddress; |
| | | import com.oying.utils.FileUtil; |
| | | import com.oying.utils.SecurityUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.oying.utils.PageUtil; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | |
| | | import com.oying.utils.PageResult; |
| | | |
| | | /** |
| | | * @description 服务实现 |
| | | * @author lixin |
| | | * @date 2025-06-11 |
| | | **/ |
| | | * @author lixin |
| | | * @description 服务实现 |
| | | * @date 2025-06-11 |
| | | **/ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements UserAddressService { |
| | |
| | | private final UserAddressMapper userAddressMapper; |
| | | |
| | | @Override |
| | | public PageResult<UserAddress> queryAll(UserAddressQueryCriteria criteria, Page<Object> page){ |
| | | public PageResult<UserAddress> queryAll(UserAddressQueryCriteria criteria, Page<Object> page) { |
| | | return PageUtil.toPage(userAddressMapper.findAll(criteria, page)); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserAddress> queryAll(UserAddressQueryCriteria criteria){ |
| | | public List<UserAddress> queryAll(UserAddressQueryCriteria criteria) { |
| | | return userAddressMapper.findAll(criteria); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserAddress> queryUserAddress() { |
| | | UserAddressQueryCriteria criteria = new UserAddressQueryCriteria(); |
| | | criteria.setUserId(SecurityUtils.getCurrentUserId()); |
| | | return queryAll(criteria); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void create(UserAddress resources) { |
| | | if (resources.getIsDefault()) { |
| | | userAddressMapper.isDefault(resources.getUserId()); |
| | | } |
| | | userAddressMapper.insert(resources); |
| | | } |
| | | |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(UserAddress resources) { |
| | | UserAddress userAddress = getById(resources.getAddressId()); |
| | | if (!userAddress.getUserId().equals(SecurityUtils.getCurrentUserId())) { |
| | | throw new BadRequestException("不能修改他人资料"); |
| | | } |
| | | if (resources.getIsDefault()) { |
| | | userAddressMapper.isDefault(resources.getUserId()); |
| | | } |
| | | userAddress.copy(resources); |
| | | userAddressMapper.updateById(userAddress); |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteAll(List<Long> ids) { |
| | | for (Long id : ids) { |
| | | UserAddress userAddress = getById(id); |
| | | if (!userAddress.getUserId().equals(SecurityUtils.getCurrentUserId())) { |
| | | throw new BadRequestException("不能删除他人资料"); |
| | | } |
| | | } |
| | | userAddressMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (UserAddress userAddress : all) { |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("用户id", userAddress.getUserId()); |
| | | map.put("收货人", userAddress.getReceiverName()); |
| | | map.put("收货人电话", userAddress.getReceiverPhone()); |
| | | map.put("省份", userAddress.getProvince()); |
| | | map.put("城市", userAddress.getCity()); |
| | | map.put("区县", userAddress.getDistrict()); |
| | | map.put("街道", userAddress.getStreet()); |
| | | map.put("短地址", userAddress.getShortAddress()); |
| | | map.put("详细地址", userAddress.getDetail()); |
| | | map.put("经度", userAddress.getLongitude()); |
| | | map.put("纬度", userAddress.getLatitude()); |
| | | map.put("是否默认", userAddress.getIsDefault()); |
| | | map.put("标签(家、公司等)", userAddress.getTag()); |
| | | map.put("是否默认", userAddress.getIsDefault() ? "是" : "否"); |
| | | map.put("标签", userAddress.getTag()); |
| | | map.put("创建人", userAddress.getCreateBy()); |
| | | map.put("创建时间", userAddress.getCreateTime()); |
| | | map.put("修改者", userAddress.getUpdateBy()); |