| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package com.fdkankan.ucenter.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.fdkankan.common.constant.ErrorCode;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.ucenter.entity.ReceiverInfo;
- import com.fdkankan.ucenter.mapper.IReceiverInfoMapper;
- import com.fdkankan.ucenter.service.IReceiverInfoService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.ucenter.vo.request.ShipAddressParam;
- import org.springframework.stereotype.Service;
- import java.util.List;
- /**
- * <p>
- * 收货人信息表 服务实现类
- * </p>
- *
- * @author
- * @since 2022-07-04
- */
- @Service
- public class ReceiverInfoServiceImpl extends ServiceImpl<IReceiverInfoMapper, ReceiverInfo> implements IReceiverInfoService {
- @Override
- public ReceiverInfo getDefaultByUserId(Long userId){
- QueryWrapper<ReceiverInfo> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(ReceiverInfo::getUserId,userId);
- queryWrapper.lambda().eq(ReceiverInfo::getSetDefault,1);
- List<ReceiverInfo> list = this.list(queryWrapper);
- if(list == null || list.size()<=0){
- return null;
- }
- return list.get(0);
- }
- @Override
- public void saveByParam(ShipAddressParam param, Long userId) {
- ReceiverInfo defaultEntity = getDefaultByUserId(userId);
- ReceiverInfo receiverInfoEntity = new ReceiverInfo();
- receiverInfoEntity.setSetDefault(0);
- if(defaultEntity == null){
- receiverInfoEntity.setSetDefault(1);
- }
- receiverInfoEntity.setUserId(userId);
- receiverInfoEntity.setShipAreaPath(param.getShipAreaPath());
- receiverInfoEntity.setShipAddress(param.getShipAddress());
- receiverInfoEntity.setShipName(param.getShipName());
- receiverInfoEntity.setShipMobile(param.getShipMobile());
- this.save(receiverInfoEntity);
- }
- @Override
- public void updateDefaultAddress(ShipAddressParam param, Long userId) {
- if(param.getSetDefault() != null && param.getSetDefault() == 1){
- ReceiverInfo defaultEntity = this.getDefaultByUserId(userId);
- if(defaultEntity != null && defaultEntity.getId().intValue() != param.getId().intValue()){
- defaultEntity.setSetDefault(0);
- if(!this.updateById(defaultEntity)){
- throw new BusinessException(ErrorCode.ERROR_MSG);
- }
- }
- }
- ReceiverInfo receiverInfoEntity = this.getById(param.getId());
- if(param.getSetDefault() != null){
- receiverInfoEntity.setSetDefault(param.getSetDefault());
- }
- receiverInfoEntity.setShipAreaPath(param.getShipAreaPath());
- receiverInfoEntity.setShipAddress(param.getShipAddress());
- receiverInfoEntity.setShipName(param.getShipName());
- receiverInfoEntity.setShipMobile(param.getShipMobile());
- this.updateById(receiverInfoEntity);
- }
- @Override
- public List<ReceiverInfo> getListByUserId(Long userId) {
- QueryWrapper<ReceiverInfo> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(ReceiverInfo::getUserId,userId);
- return this.list(queryWrapper);
- }
- }
|