buhuazhen
5 天以前 24820701b09281e03edf2e22db62edab7f4da53b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.ruoyi.projectManagement.service.impl.handle;
 
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.projectManagement.dto.ShippingAddressDto;
import com.ruoyi.projectManagement.mapper.ShippingAddressMapper;
import com.ruoyi.projectManagement.pojo.ShippingAddress;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
 
/**
 * @author buhuazhen
 * @date 2026/3/9
 * @email 3038525872@qq.com
 */
@Component
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class,readOnly = true)
public class ShippingAddressHandleService {
 
    private final ShippingAddressMapper shippingAddressMapper;
 
    @Transactional(rollbackFor = Exception.class)
    public void save(@Nullable Long infoId,@NotNull ShippingAddressDto shippingAddressDto){
        ShippingAddress shippingAddress = BeanUtil.copyProperties(shippingAddressDto, ShippingAddress.class);
        shippingAddress.setProjectManagementInfoId(infoId);
        if (shippingAddressDto.getId() == null) {
            shippingAddressMapper.insert(shippingAddress);
        }else {
            shippingAddressMapper.updateById(shippingAddress);
        }
    }
 
 
    public ShippingAddressDto getByInfoId(@NotNull Long id) {
        LambdaQueryWrapper<ShippingAddress> queryWrapper = new LambdaQueryWrapper<ShippingAddress>();
        queryWrapper.eq(ShippingAddress::getProjectManagementInfoId, id);
        queryWrapper.eq(ShippingAddress::getIsDelete, 0);
        queryWrapper.last("limit 1");
        ShippingAddress shippingAddress = shippingAddressMapper.selectOne(queryWrapper);
        return BeanUtil.copyProperties(shippingAddress, ShippingAddressDto.class);
    }
}