|
@@ -0,0 +1,78 @@
|
|
|
+package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.chelvc.cloud.vehicle.client.dto.UserReceiveAddressDTO;
|
|
|
+import com.chelvc.cloud.vehicle.client.param.UserReceiveAddressModifyParam;
|
|
|
+import com.chelvc.cloud.vehicle.server.copier.UserReceiveAddressCopier;
|
|
|
+import com.chelvc.cloud.vehicle.server.dao.UserReceiveAddressMapper;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.UserReceiveAddress;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.UserReceiveAddressService;
|
|
|
+import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
+import com.chelvc.framework.common.util.AssertUtils;
|
|
|
+import lombok.NonNull;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户常用地址Service业务层处理
|
|
|
+ *
|
|
|
+ * @author liude
|
|
|
+ * @date 2024-04-29
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
+public class UserReceiveAddressServiceImpl extends ServiceImpl<UserReceiveAddressMapper, UserReceiveAddress> implements
|
|
|
+ UserReceiveAddressService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long add (@NonNull UserReceiveAddressModifyParam param){
|
|
|
+ UserReceiveAddress receiveAddress = UserReceiveAddressCopier.INSTANCE.copying(param);
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
+ receiveAddress.setCreateTime(new Date());
|
|
|
+ receiveAddress.setUpdateTime(new Date());
|
|
|
+ receiveAddress.setUserId(userId);
|
|
|
+ this.save(receiveAddress);
|
|
|
+ return receiveAddress.getId();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long update ( @NonNull Long id, @NonNull UserReceiveAddressModifyParam param){
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
+ UserReceiveAddress userReceiveAddress = AssertUtils.available(this.getById(id), "该常用地址不存在");
|
|
|
+ UserReceiveAddressCopier.INSTANCE.copying(param,userReceiveAddress);
|
|
|
+ userReceiveAddress.setUpdateTime(new Date());
|
|
|
+ if ("1".equals(param.getDefaultStatus())){
|
|
|
+ UserReceiveAddress receiveAddress = this.lambdaQuery()
|
|
|
+ .eq(UserReceiveAddress::getUserId,userId)
|
|
|
+ .eq(UserReceiveAddress::getDefaultStatus,"1")
|
|
|
+ .one();
|
|
|
+ if (null != receiveAddress){
|
|
|
+ receiveAddress.setDefaultStatus("0");
|
|
|
+ this.updateById(receiveAddress);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.updateById(userReceiveAddress);
|
|
|
+ return userReceiveAddress.getId();
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public List<UserReceiveAddressDTO> getList(){
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
+ List<UserReceiveAddress> list = this.lambdaQuery()
|
|
|
+ .eq(UserReceiveAddress::getUserId,userId)
|
|
|
+ .orderByDesc(UserReceiveAddress::getDefaultStatus)
|
|
|
+ .orderByDesc(UserReceiveAddress::getUpdateTime)
|
|
|
+ .orderByDesc(UserReceiveAddress::getCreateTime)
|
|
|
+ .list();
|
|
|
+ return UserReceiveAddressCopier.INSTANCE.copying(list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(@NonNull Long id){
|
|
|
+ AssertUtils.available(this.getById(id), "该常用地址不存在");
|
|
|
+ this.baseMapper.deleteById(id);
|
|
|
+ }
|
|
|
+}
|