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; /** *

* 收货人信息表 服务实现类 *

* * @author * @since 2022-07-04 */ @Service public class ReceiverInfoServiceImpl extends ServiceImpl implements IReceiverInfoService { @Override public ReceiverInfo getDefaultByUserId(Long userId){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(ReceiverInfo::getUserId,userId); queryWrapper.lambda().eq(ReceiverInfo::getSetDefault,1); List 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 getListByUserId(Long userId) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(ReceiverInfo::getUserId,userId); return this.list(queryWrapper); } }