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
package com.dy.pipIrrSell.clientTemp;
 
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pipIrrGlobal.pojoSe.SeClient;
import com.dy.pipIrrGlobal.pojoSe.SeClientTemp;
import com.dy.pipIrrSell.client.ClientSv;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Date;
import java.util.List;
 
/**
 * @author ZhuBaoMin
 * @date 2024-09-26 15:03
 * @LastEditTime 2024-09-26 15:03
 * @Description
 */
 
@Slf4j
@RestController
@RequestMapping(path = "client_temp")
@RequiredArgsConstructor
public class ClientTempCtrl {
    private final ClientTempSv clientTempSv;
    private final ClientSv clientSv;
 
    /**
     * 导入农户
     * @param townName
     * @return
     */
    @PostMapping(path = "import")
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> importClient(String townName){
        List<SeClientTemp> list_client = clientTempSv.getClientsByTownName(townName);
        if(list_client != null && list_client.size() > 0) {
            JSONArray array_Clients = (JSONArray) JSON.toJSON(list_client);
            for (int i = 0; i < array_Clients.size(); i++) {
                JSONObject job_client = array_Clients.getJSONObject(i);
                String town = job_client.getString("town");
                String village = job_client.getString("village");
                String name = job_client.getString("name");
                String idCard = job_client.getString("idcard");
                String phone = job_client.getString("phone");
                if(phone != null && phone.length() > 11) {
                    phone = phone.substring(0,11);
                }
                String address = job_client.getString("address");
 
                if(town.trim().equals("元马镇6号")) {
                    SeClient client = new SeClient();
                    //client.setCountyid(28L);
                    //client.setTownid(101L);
                    //client.setVillageid(6L);
                    client.setCountyid(2024090516595200202L);
                    client.setTownid(2024090517240900002L);
                    client.setVillageid(2024090517284400002L);
                    client.setBlockid(2024090517155600002L);
                    client.setDivideid(2024090517323800007L);
                    client.setName(name);
                    client.setClientnum("28101006" + String.format("%04d", i+1));
                    client.setDistrictnum(532328101006L);
                    client.setDistricttitle("元谋县元马镇清和社区居民委员会");
                    client.setPhone(phone);
                    client.setIdcard(idCard);
                    client.setTypeid(2024090516595201402L);
                    client.setAddress(address);
                    client.setOperator (2024090516595200302L);
                    client.setOperatedt(new Date());
                    client.setDisabled((byte)0);
                    client.setDeleted((byte)0);
 
                    Integer rec = clientSv.addClient(client);
                } else if(town.trim().equals("老城乡2号")) {
                    SeClient client = new SeClient();
                    //client.setCountyid(28L);
                    //client.setTownid(202L);
                    //client.setVillageid(204L);
                    client.setCountyid(2024090516595200202L);
                    client.setTownid(2024090517252600002L);
                    client.setVillageid(2024090517294000002L);
                    client.setBlockid(2024090517155600002L);
                    client.setDivideid(2024090517355700007L);
                    client.setName(name);
                    client.setClientnum("28202204" + String.format("%04d", i));
                    client.setDistrictnum(532328202204L);
                    client.setDistricttitle("元谋县老城乡挨小村民委员会");
                    client.setPhone(phone);
                    client.setIdcard(idCard);
                    client.setTypeid(2024090516595201402L);
                    client.setAddress(address);
                    client.setOperator (2024090516595200302L);
                    client.setOperatedt(new Date());
                    client.setDisabled((byte)0);
                    client.setDeleted((byte)0);
 
                    Integer rec = clientSv.addClient(client);
                }
 
                System.out.println("-----------------------------: " + i);
            }
 
        }
        return BaseResponseUtils.buildSuccess();
    }
}