mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package com.panzhihua.serviceapi.biz.impl;
 
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.panzhihua.common.api.LcReturnObject;
import com.panzhihua.common.enums.LocalEventToLangChaoEventTypeEnum;
import com.panzhihua.common.model.dtos.api.EventFile;
import com.panzhihua.common.model.dtos.api.EventInfo;
import com.panzhihua.common.model.dtos.api.PartiesBody;
import com.panzhihua.common.model.vos.BcDictionaryVO;
import com.panzhihua.common.model.vos.DictionaryVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.grid.EventDetailsVO;
import com.panzhihua.common.model.vos.grid.EventGridDataDetailsVO;
import com.panzhihua.common.model.vos.grid.EventResourceVO;
import com.panzhihua.common.service.api.ApiServiceFeign;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.service.grid.GridService;
import com.panzhihua.common.utlis.DateUtils;
import com.panzhihua.common.utlis.Snowflake;
import com.panzhihua.serviceapi.ServiceApiApplication;
import com.panzhihua.serviceapi.biz.LcApiService;
import com.panzhihua.serviceapi.model.dto.GridMemberPageListDTO;
import com.panzhihua.serviceapi.model.dto.LcGridData;
 
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
 
@Slf4j
@SpringBootTest(classes = ServiceApiApplication.class)
class LcApiServiceImplTest {
 
    @Autowired
    private LcApiService lcApiService;
 
    @Resource
    private GridService gridService;
 
    @Resource
    private ApiServiceFeign ApiServiceFeign;
 
    @Autowired
    private CommunityService communityService;
 
    @Test
    void saveTokenFromRemoteRequest() {
        String result = lcApiService.saveTokenFromRemoteRequest("18080799023", "123456");
        log.info(JSONObject.toJSONString(result));
    }
 
    @Test
    void getAllEventTypeList() {
        String result = lcApiService.getAllEventTypeList();
        log.info(result);
    }
 
    @Test
    void automationUploadEventAndFile() {
        lcApiService.automationUploadEventAndFile();
    }
 
    @Test
    void submitEventRegister() {
        EventInfo eventInfo = new EventInfo();
        eventInfo.setGridId("8c86b8b467194270b6b066b9c32e3b9b");
        eventInfo.setGridName("金沙社区网格1");
        eventInfo.setCaseTypeCode("04e0506d78884d218050a4c89a2e34c3");
        eventInfo.setCaseTypeName("18080799023");
        eventInfo.setHappenTime(String.valueOf(DateUtils.getCurrentDataLong()));
        eventInfo.setHappenAddress("四川省攀枝花市");
        eventInfo.setLongitude("116.397128");
        eventInfo.setLatitude("39.916527");
        eventInfo.setCaseDescription("描述");
        eventInfo.setCaseRecordTime(String.valueOf(DateUtils.getCurrentDataLong()));
        eventInfo.setHandleType("REPORT");
        eventInfo.setHandleDescription("处理描述");
        String dataID = String.valueOf(RandomUtil.randomLong(20));
        log.info("random:" + dataID);
        eventInfo.setDataId(dataID);
        eventInfo.setUserId("3e318dbeddc048328933d8b4ca759a36");
        eventInfo.setHandleTime(String.valueOf(DateUtils.getCurrentDataLong()));
        eventInfo.setCaseName("测试标题17");
        List<PartiesBody> partiesBody = new ArrayList<>();
        PartiesBody partiesBody1 = new PartiesBody();
        partiesBody1.setPartyName("测试见证人");
        partiesBody1.setPartyPhone("17345623565");
        partiesBody.add(partiesBody1);
        eventInfo.setPartiesBody(partiesBody);
        String result = lcApiService.submitEventRegister(eventInfo);
        log.info(result);
    }
 
    @Test
    void submitEventRelationFile() throws URISyntaxException {
        EventFile eventFile = new EventFile();
        eventFile.setDataId("1111116");
        eventFile.setFiles("http://image.panzhihua.nhys.cdnhxx.com//idcard/4f843ad2d756456e900d5f24b419aa7c.mp4");
        eventFile.setType("mp4");
        eventFile.setModule("event");
        eventFile.setFileName("4f843ad2d756456e900d5f24b419aa7c.mp4");
        R result = lcApiService.submitEventOrVisitRecordRelationFile(eventFile);
        log.info(JSONObject.toJSONString(result));
    }
 
    @Test
    void submitEventRegisterJobTest() {
        log.info("定时向浪潮服务器提交网格事件登记开始");
        R<EventDetailsVO> event = gridService.eventDetails(4545676L);
        EventDetailsVO eventInfoVo = event.getData();
        EventInfo eventInfo = new EventInfo();
        String lcGrid = gridService.getLcGridIdByLocal(eventInfoVo.getGridId());
        String lcGridUserId = gridService.getLcUserIdByLocalUserId(eventInfoVo.getGridMemberId().toString());
        eventInfo.setGridId(lcGrid);
        R grid = gridService.eventGridDataDetails(eventInfoVo.getGridId());
        EventGridDataDetailsVO gridData = (EventGridDataDetailsVO)grid.getData();
        eventInfo.setGridName(gridData.getGridName());
        eventInfo.setCaseTypeCode(LocalEventToLangChaoEventTypeEnum.getCodeByName(eventInfoVo.getEventType()));
        String caseTypeName = LocalEventToLangChaoEventTypeEnum.getEventNameByCode(eventInfoVo.getEventType());
        eventInfo.setCaseTypeName(caseTypeName);
        eventInfo.setHappenTime(String.valueOf(eventInfoVo.getHappenTime().getTime()));
        eventInfo.setHappenAddress(eventInfoVo.getHappenAddress());
        String[] data = eventInfoVo.getHappentLatLng().split(",");
        eventInfo.setLongitude(data[0]);
        eventInfo.setLatitude(data[1]);
        eventInfo.setCaseDescription(eventInfoVo.getEventDes());
        eventInfo.setCaseRecordTime(String.valueOf(eventInfoVo.getCreateAt().getTime()));
        eventInfo.setHandleType("REPORT");
        eventInfo.setHandleDescription(eventInfoVo.getProcessDesc());
        eventInfo.setDataId(eventInfoVo.getId().toString());
        // 获取系统网格员映射的浪潮网格员对于的用户ID
        eventInfo.setUserId(lcGridUserId);
        eventInfo.setHandleTime(String.valueOf(eventInfoVo.getHappenTime().getTime()));
        eventInfo.setCaseName(gridData.getGridName().concat(caseTypeName).concat(eventInfoVo.getEventTitle()));
        lcApiService.submitEventRegister(eventInfo);
        log.info("定时向浪潮服务器提交网格事件登记结束");
        log.info("开始上传附件图片信息");
        List<EventResourceVO> picsList = eventInfoVo.getPics();
        picsList.forEach(eventResourceVO -> {
            EventFile eventFile = new EventFile();
            eventFile.setDataId(eventInfoVo.getId().toString());
            eventFile.setFiles(eventResourceVO.getUrl());
            eventFile.setType("png");
            eventFile.setModule("event");
            eventFile.setFileName(eventResourceVO.getResourceName());
            lcApiService.submitEventOrVisitRecordRelationFile(eventFile);
        });
        List<EventResourceVO> audiosList = eventInfoVo.getAudios();
        audiosList.forEach(eventResourceVO -> {
            EventFile eventFile = new EventFile();
            eventFile.setDataId(eventInfoVo.getId().toString());
            eventFile.setFiles(eventResourceVO.getUrl());
            eventFile.setType("mp3");
            eventFile.setModule("event");
            eventFile.setFileName(eventResourceVO.getResourceName());
            lcApiService.submitEventOrVisitRecordRelationFile(eventFile);
        });
        List<EventResourceVO> videoList = eventInfoVo.getVideos();
        videoList.forEach(eventResourceVO -> {
            EventFile eventFile = new EventFile();
            eventFile.setDataId(eventInfoVo.getId().toString());
            eventFile.setFiles(eventResourceVO.getUrl());
            eventFile.setType("mp4");
            eventFile.setModule("event");
            eventFile.setFileName(eventResourceVO.getResourceName());
            lcApiService.submitEventOrVisitRecordRelationFile(eventFile);
        });
        log.info("结束上传附件图片信息");
    }
 
    @Test
    void getGridListByAreaId() {
        // jhRxqEQp 代表西区
        List<LcGridData> list = lcApiService.getGridTreeByAreaId("jhRxqEQp");
        String pretty = JSONArray.toJSONString(list, SerializerFeature.PrettyFormat,
            SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
        log.info(pretty);
    }
 
    @Test
    void getGridDataListByAreaId() {
        // jhRxqEQp 代表西区
        List<LcGridData> list = lcApiService.getGridDataListByAreaId("2Fxq97CC");
        String pretty = JSONArray.toJSONString(list, SerializerFeature.PrettyFormat,
            SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
        log.info(pretty);
    }
 
    @Test
    void requestLcFlowPersonVisitRecord() {}
 
    @Test
    void automationUploadVisitRecord() {
        lcApiService.automationUploadVisitRecord();
    }
 
    @Test
    void getGridMemberListByAreaIdOrName() {
        List<GridMemberPageListDTO> data = lcApiService.getGridMemberListByAreaIdOrName("jhRxqEQp", "", 1L, 20L);
        // log.info(data);
    }
 
    @Test
    void downloadDiction() {
        // 获取字典全部大类
        HttpRequest request = HttpUtil.createPost("http://171.217.92.33:53301/dict/getTypeTree");
        request.cookie(
            "SESSION=ZTQ1ZGRmZjktNWU1MC00ZjEyLWJhOGItNDdjZjlmODc1MjQy; UISESSIONMEMBER=C6FE0698B29832B18CBAEB71CCD3A2BA");
        HttpResponse result = request.execute();
        List<DictionData> remoteData = JSONArray.parseArray(result.body(), DictionData.class);
        remoteData.forEach(dictionData -> {
            DictionaryVO dictionaryVO = new DictionaryVO();
            long parentzId = Snowflake.getId();
            dictionaryVO.setId(parentzId);
            dictionaryVO.setDictName(dictionData.getName());
            dictionaryVO.setDictKey(dictionData.getValue());
            dictionaryVO.setLevelIndex(1);
            dictionaryVO.setParentId(0L);
            communityService.insertDiction(dictionaryVO);
            // 获取二级字典项
            dictionData.getChildren().forEach(children -> {
                DictionaryVO dictionaryChiVO = new DictionaryVO();
                long erparentzId = Snowflake.getId();
                dictionaryChiVO.setId(erparentzId);
                dictionaryChiVO.setDictName(children.getName());
                dictionaryChiVO.setDictKey(children.getValue());
                dictionaryChiVO.setLevelIndex(2);
                dictionaryChiVO.setParentId(dictionaryVO.getId());
                communityService.insertDiction(dictionaryChiVO);
                // 获取字典全部值
                HttpRequest requestDictionValue =
                    HttpUtil.createPost("http://171.217.92.33:53301/dict/getDictByTypeCodeAndParentId?typeCode="
                        + children.getId() + "&parentId=0");
                requestDictionValue.cookie(
                    "SESSION=ZTQ1ZGRmZjktNWU1MC00ZjEyLWJhOGItNDdjZjlmODc1MjQy; UISESSIONMEMBER=C6FE0698B29832B18CBAEB71CCD3A2BA");
                HttpResponse childResult = requestDictionValue.execute();
                LcReturnObject remoteDataChild = JSONObject.parseObject(childResult.body(), LcReturnObject.class);
                List<DictionValueData> dictionValueData =
                    JSONArray.parseArray(remoteDataChild.getData(), DictionValueData.class);
                dictionValueData.forEach(dictionValueData1 -> {
                    BcDictionaryVO dictionaryItemVO = new BcDictionaryVO();
                    dictionaryItemVO.setDictName(dictionValueData1.getDictName());
                    dictionaryItemVO.setDictValue(dictionValueData1.getDictCode());
                    dictionaryItemVO.setCode("");
                    dictionaryItemVO.setDictId(erparentzId);
                    communityService.insertDictionItem(dictionaryItemVO);
                });
                // String pretty = JSONArray.toJSONString(dictionValueData, SerializerFeature.PrettyFormat,
                // SerializerFeature.WriteMapNullValue,
                // SerializerFeature.WriteDateUseDateFormat);
                // log.info(pretty);
            });
        });
    }
}