You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.4 KiB
Java
69 lines
2.4 KiB
Java
package com.gszc.service.impl;
|
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
import com.gszc.entity.ReceiveAddress;
|
|
import com.gszc.mapper.ReceiveAddressMapper;
|
|
import com.gszc.service.IReceiveAddressService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* <p>
|
|
* 服务实现类
|
|
* </p>
|
|
*
|
|
* @author ky
|
|
* @since 2020-04-27
|
|
*/
|
|
@Service
|
|
public class ReceiveAddressServiceImpl extends ServiceImpl<ReceiveAddressMapper, ReceiveAddress> implements IReceiveAddressService {
|
|
|
|
@Autowired
|
|
ReceiveAddressMapper receiveAddressMapper;
|
|
|
|
public void addAddress(ReceiveAddress receiveAddress){
|
|
String uuid = UUID.randomUUID().toString();
|
|
receiveAddress.setId(uuid);
|
|
receiveAddress.setCreateDate(new Date());
|
|
receiveAddress.setModifyDate(new Date());
|
|
if(receiveAddress.getIsDefault()){
|
|
String miniUserId = receiveAddress.getMiniUserId();
|
|
ReceiveAddress other = new ReceiveAddress();
|
|
other.setIsDefault(false);
|
|
receiveAddressMapper.update(other,new EntityWrapper<ReceiveAddress>().eq("mini_user_id", miniUserId));
|
|
}
|
|
receiveAddressMapper.insert(receiveAddress);
|
|
}
|
|
|
|
public void updateAddress(ReceiveAddress receiveAddress){
|
|
receiveAddress.setModifyDate(new Date());
|
|
if(receiveAddress.getIsDefault()){
|
|
String miniUserId = receiveAddress.getMiniUserId();
|
|
ReceiveAddress other = new ReceiveAddress();
|
|
other.setIsDefault(false);
|
|
receiveAddressMapper.update(other,new EntityWrapper<ReceiveAddress>().eq("mini_user_id", miniUserId));
|
|
}
|
|
receiveAddressMapper.updateById(receiveAddress);
|
|
}
|
|
|
|
public void deleteAddress(String receiveAddressId){
|
|
receiveAddressMapper.deleteById(receiveAddressId);
|
|
}
|
|
|
|
public List<ReceiveAddress> addressList(String userId){
|
|
List<ReceiveAddress> receiveAddressList = receiveAddressMapper.selectList(new EntityWrapper<ReceiveAddress>().eq("mini_user_id", userId));
|
|
return receiveAddressList;
|
|
}
|
|
|
|
public ReceiveAddress addressDetail(String receiveAddressId){
|
|
ReceiveAddress receiveAddress = receiveAddressMapper.selectById(receiveAddressId);
|
|
return receiveAddress;
|
|
}
|
|
}
|