|
@@ -0,0 +1,95 @@
|
|
|
+package com.zfjg.system.common.listener;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.zfjg.common.core.web.domain.AjaxResult;
|
|
|
+import com.zfjg.system.api.domain.SysUser;
|
|
|
+import com.zfjg.system.common.event.SysUserEvent;
|
|
|
+import com.zfjg.system.common.event.SysUserStatusHisToEvent;
|
|
|
+import com.zfjg.system.config.Constant;
|
|
|
+import com.zfjg.system.domain.to.SysUserStatusHisTo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.event.EventListener;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class SysUserStatusHisToListener extends PushDataEventListener<SysUserStatusHisTo, SysUserStatusHisToEvent>{
|
|
|
+
|
|
|
+ @Resource(name = "requestTemplate")
|
|
|
+ private RestTemplate requestTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 两江执法监督基础路由
|
|
|
+ */
|
|
|
+ @Value("${data.sync.lj}")
|
|
|
+ private String LJ_ZFJD_BASE_URL;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getModuleName() {
|
|
|
+ return "用户操作记录";
|
|
|
+ }
|
|
|
+
|
|
|
+ @EventListener(SysUserStatusHisToEvent.class)
|
|
|
+ public void updateData(SysUserStatusHisToEvent event) {
|
|
|
+ this.dealEvent(event);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行插入数据操作
|
|
|
+ *
|
|
|
+ * @param entity 数据实体
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ protected void doInsert(SysUserStatusHisTo entity) {
|
|
|
+ request("/sys_user_status_his", entity, checkIsLjData(entity.getEnforceOrgId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private HttpHeaders auth(HttpHeaders requestHeaders) {
|
|
|
+ requestHeaders.set("Content-type", "application/json; charset=utf-8");
|
|
|
+ return requestHeaders;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用请求处理
|
|
|
+ * @param apiUrl
|
|
|
+ * @param data
|
|
|
+ */
|
|
|
+ private void request(String apiUrl, Object data, boolean isPush) {
|
|
|
+ if (!isPush) {
|
|
|
+ log.warn("{} 不符合要求不进行推送:{}", apiUrl, JSON.toJSONString(data));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String requestUrl = LJ_ZFJD_BASE_URL + "/api/manage/accept/v1" + apiUrl;
|
|
|
+ log.info("开始推送{}: {}", apiUrl, JSON.toJSONString(data));
|
|
|
+ HttpEntity<Object> httpEntity = new HttpEntity<>(data, auth(new HttpHeaders()));
|
|
|
+ ResponseEntity<AjaxResult> exchange = requestTemplate.exchange(requestUrl, HttpMethod.POST, httpEntity, AjaxResult.class);
|
|
|
+ AjaxResult body = exchange.getBody();
|
|
|
+ if (exchange.getStatusCode().is2xxSuccessful() && Objects.nonNull(body) && body.isSuccess()) {
|
|
|
+ log.error("{}推送成功:{}", apiUrl, body.get(AjaxResult.MSG_TAG));
|
|
|
+ } else if (Objects.nonNull(body)) {
|
|
|
+ log.error("{}推送失败:{}", apiUrl, body.get(AjaxResult.MSG_TAG));
|
|
|
+ } else {
|
|
|
+ log.error("请求 {} 失败 状态码:{}", apiUrl, exchange.getStatusCodeValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查数据权限是否为两江
|
|
|
+ * @param enforceOrgId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean checkIsLjData(String enforceOrgId) {
|
|
|
+ return Constant.NEED_PUSH_DATA_ORG_ID.equals(enforceOrgId);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|