Helius
2021-06-29 d95f158b9dfa0149e74bc60a0c5a386dbbdad484
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import com.xzx.gc.GcUserApplication;
import com.xzx.gc.entity.AddressInfo;
import com.xzx.gc.entity.OrderDetailInfo;
import com.xzx.gc.entity.OrderInfo;
import com.xzx.gc.entity.UserTargetInfo;
import com.xzx.gc.user.mapper.*;
import com.xzx.gc.user.service.AddressService;
import com.xzx.gc.user.service.UserService;
import com.xzx.gc.user.service.UserTargetInfoService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import tk.mybatis.mapper.entity.Example;
 
import java.util.ArrayList;
import java.util.List;
 
 
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {GcUserApplication.class})
@ActiveProfiles("fix")
public class FixTest {
 
    @Autowired
    private UserTargetInfoService userTargetInfoService;
 
 
    @Autowired
    private UserTargetInfoMapper userTargetInfoMapper;
 
 
    @Autowired
    private UserService userService;
 
 
    @Autowired
    private AddressService addressService;
 
    @Autowired
    private AddressMapper addressMapper;
 
    @Autowired
    private OrderMapper orderMapper;
 
    @Autowired
    private OrderDetailMapper orderDetailMapper;
 
    @Autowired
    private OrderDetailBatchMapper orderDetailBatchMapper;
 
 
    @Test
    public void fixtaeget(){
        //修复意向客户的地址问题
        Example example=new Example(UserTargetInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("regsterType",3);
        criteria.andIsNull("provinceId");
        List<UserTargetInfo> userTargetInfo1 = userTargetInfoMapper.selectByExample(example);
        for (UserTargetInfo userTargetInfo : userTargetInfo1) {
            String mobile = userTargetInfo.getMobile();
            AddressInfo addressInfo=new AddressInfo();
            addressInfo.setDelFlag("0");
            addressInfo.setFlag("1");
            addressInfo.setMobilePhone(mobile);
            AddressInfo addressInfo1 = addressMapper.selectOne(addressInfo);
            if(addressInfo1!=null){
                userTargetInfoService.updateTargetUserAddr(addressInfo1);
            }
        }
        System.out.println("修复了"+userTargetInfo1.size()+"条记录");
    }
 
 
    @Test
    public void fixOrderAdd(){
        //修复订单地址id
        Example example=new Example(OrderDetailInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIsNull("addressId");
        List<OrderDetailInfo> orderDetailInfos = orderDetailMapper.selectByExample(example);
 
        List<OrderDetailInfo> list=new ArrayList<>();
        for (OrderDetailInfo orderDetailInfo : orderDetailInfos) {
            OrderDetailInfo detailInfo=new OrderDetailInfo();
            String orderId = orderDetailInfo.getOrderId();
            OrderInfo orderInfo = orderMapper.selectByPrimaryKey(orderId);
            String createUserId = orderInfo.getCreateUserId();
 
            Long addressId;
            AddressInfo addressInfo=new AddressInfo();
            addressInfo.setUserId(createUserId);
            addressInfo.setFlag("1");
            addressInfo.setDelFlag("0");
            AddressInfo addressInfo1 = addressMapper.selectOne(addressInfo);
            if(addressInfo1!=null){
                addressId=addressInfo1.getAddressId();
            }else {
                //找删除的数据里最新的那条
                Example example1=new Example(AddressInfo.class);
                Example.Criteria criteria1 = example1.createCriteria();
                criteria1.andEqualTo("userId",createUserId);
                criteria1.andEqualTo("flag","1");
                example1.orderBy("createTime").desc();
                List<AddressInfo> addressInfos = addressMapper.selectByExample(example1);
                addressId=addressInfos.get(0).getAddressId();
            }
 
            detailInfo.setOrderId(orderDetailInfo.getOrderId());
            detailInfo.setAddressId(addressId);
            list.add(detailInfo);
        }
 
        orderDetailBatchMapper.updateBatchByPrimaryKeySelective(list);
    }
 
}