Browse Source

苏州帝威电梯工程技术有限公司对接监管平台,发送保养数据

别傲 5 years ago
parent
commit
e2a529efab
15 changed files with 756 additions and 5 deletions
  1. 120 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/common/http/BasicHttpClient.java
  2. 68 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/common/http/HttpBasic.java
  3. 136 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/common/http/HttpClient.java
  4. 6 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/mapper/MaintenanceOptionMapper.java
  5. 9 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/mapper/MaintenanceRecordMapper.java
  6. 16 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/BeginMission.java
  7. 41 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/GetMission.java
  8. 25 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/ItemContent.java
  9. 43 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/MaintenanceTask.java
  10. 22 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/MissionContent.java
  11. 34 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/RecordContent.java
  12. 16 0
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/ThirdPartyInterfaceResponse.java
  13. 196 5
      lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/service/MaintenanceRecordService.java
  14. 5 0
      lift-business-service/src/main/resources/application.properties
  15. 19 0
      lift-business-service/src/main/resources/mapper/maintenance/MaintenanceRecordMapper.xml

+ 120 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/common/http/BasicHttpClient.java

@@ -0,0 +1,120 @@
+package cn.com.ty.lift.business.common.http;
+
+import cn.com.ty.lift.business.framework.BusinessBasicException;
+import cn.hutool.core.date.DateUtil;
+import com.ning.http.client.*;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.*;
+
+/**
+ * @Author xp-zhao@logictech.cn
+ * @CreateOn 2016/06/29^ 13:32
+ */
+@Slf4j
+public class BasicHttpClient extends HttpBasic {
+
+    public static final Map<String, Object> formHeaders = new HashMap<String, Object>() {{
+        put("Content-Type", "application/x-www-form-urlencoded");
+    }};
+
+    public static final Map<String, Object> jsonHeaders = new HashMap<String, Object>() {{
+        put("Content-Type", "application/json");
+    }};
+
+    public static Response sends(final String method, final String url, final Map<String, Object> params, final Map<String, Object> headers) throws RuntimeException {
+        try (AsyncHttpClient c = new AsyncHttpClient()) {
+            AsyncHttpClient.BoundRequestBuilder accept;
+            if (Objects.equals(method.toUpperCase(), GET)) {
+                accept = c.prepareGet(url);
+                accept.addQueryParams(new ArrayList<Param>() {{
+                    if (null != params)
+                        for (Map.Entry<String, Object> _entry : params.entrySet())
+                            add(new Param(_entry.getKey(), Objects.toString(_entry.getValue())));
+                }});
+            } else {
+                accept = c.preparePost(url);
+                if (null != params)
+                    if (headers != null && !Objects.equals(headers.get("Content-Type"), "application/json"))
+                        accept.setBody(("time=" + DateUtil.now() + buildParameters(params)));
+                    else {
+                        accept.setBody(gson.toJson(params));
+                    }
+            }
+            //set headers
+            if (null != headers) {
+                for (Map.Entry<String, Object> _entry : headers.entrySet())
+                    accept.setHeader(_entry.getKey(), Objects.toString(_entry.getValue()));
+            }
+            //set charset utf-8
+            accept.setBodyEncoding("UTF-8");
+
+            return accept.execute(new AsyncCompletionHandler<Response>() {
+                @Override
+                public Response onCompleted(Response response) throws Exception {
+                    return response;
+                }
+
+                @Override
+                public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
+                    return super.onBodyPartReceived(content);
+                }
+
+                @Override
+                public STATE onStatusReceived(HttpResponseStatus status) throws Exception {
+                    return super.onStatusReceived(status);
+                }
+
+                @Override
+                public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception {
+                    return super.onHeadersReceived(headers);
+                }
+
+                @Override
+                public void onThrowable(Throwable t) {
+                    super.onThrowable(t);
+                }
+
+                /**
+                 * Invoked when the content (a {@link File}, {@link String} or {@link FileInputStream} has been fully
+                 * written on the I/O socket.
+                 *
+                 * @return a {@link STATE} telling to CONTINUE or ABORT the current processing.
+                 */
+                @Override
+                public STATE onHeaderWriteCompleted() {
+                    return super.onHeaderWriteCompleted();
+                }
+
+                /**
+                 * Invoked when the content (a {@link File}, {@link String} or {@link FileInputStream} has been fully
+                 * written on the I/O socket.
+                 *
+                 * @return a {@link STATE} telling to CONTINUE or ABORT the current processing.
+                 */
+                @Override
+                public STATE onContentWriteCompleted() {
+                    return super.onContentWriteCompleted();
+                }
+
+                /**
+                 * Invoked when the I/O operation associated with the {@link Request} body as been progressed.
+                 *
+                 * @param amount  The amount of bytes to transfer.
+                 * @param current The amount of bytes transferred
+                 * @param total   The total number of bytes transferred
+                 * @return a {@link STATE} telling to CONTINUE or ABORT the current processing.
+                 */
+                @Override
+                public STATE onContentWriteProgress(long amount, long current, long total) {
+                    return super.onContentWriteProgress(amount, current, total);
+                }
+            }).get();
+        } catch (Exception e) {
+            log.error("httpClient执行请求出现错误,错误描述" + e, e);
+            throw new BusinessBasicException(e);
+        }
+    }
+}

+ 68 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/common/http/HttpBasic.java

@@ -0,0 +1,68 @@
+package cn.com.ty.lift.business.common.http;
+
+import com.google.gson.Gson;
+
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @Author xp-zhao@logictech.cn
+ * @CreateOn 2016/11/01^ 16:34
+ * @Remark Http公共底层类
+ */
+public class HttpBasic {
+
+    public static final Gson gson = new Gson();
+
+    public static final String GET = "GET";
+
+    public static final String POST = "POST";
+
+    //application/x-www-form-urlencoded
+    public static String contentType = "application/json;charset=utf-8";
+
+    public static String getContentType() {
+        return contentType;
+    }
+
+    /**
+     * @Author xp-zhao@logictech.cn
+     * @CreateOn 2016/8/31 12:48
+     * @Remark Map转换成URL参数拼接格式
+     */
+    public static String buildParameters(Map<String, Object> map) {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("&");
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            try {
+                if (entry.getValue() instanceof String[]) buffer.append(entry.getKey() + "=" + URLEncoder.encode(((String[]) entry.getValue())[0], "UTF-8"));
+                else buffer.append(entry.getKey() + "=" + URLEncoder.encode(entry.getValue().toString(), "UTF-8") + "");
+            } catch (Exception e) {
+                continue;
+            }
+            buffer.append("&");
+        }
+        return buffer.toString().replaceAll("&$", "");
+    }
+
+
+    /**
+     * @Author xp-zhao@logictech.cn
+     * @CreateOn 2016/8/31 12:49
+     * @Remark 转换Map<String,Object>为Map<String,String>
+     */
+    public static Map<String, String> convertMapValueObject2String(Map<String, ?> convert) {
+        Map<String, String> newMap = new HashMap<>();
+        if (convert != null)
+            for (Map.Entry<String, ?> entry : convert.entrySet()) {
+                if (entry.getValue() instanceof String) {
+                    newMap.put(entry.getKey(), (String) entry.getValue());
+                } else newMap.put(entry.getKey(), Objects.toString(entry.getValue()));
+            }
+        return newMap;
+
+    }
+
+}

+ 136 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/common/http/HttpClient.java

@@ -0,0 +1,136 @@
+package cn.com.ty.lift.business.common.http;
+
+import cn.com.ty.lift.business.framework.BusinessBasicException;
+import com.ning.http.client.Response;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Created by xp-zhao@logictech.cn
+ * Create on 16/2/19^ 上午10:24
+ * Remark Http request class , if parameters set values, data will't send
+ */
+@Slf4j
+public class HttpClient extends BasicHttpClient {
+
+    private Response response;
+
+    private BusinessBasicException businessException;
+
+    public HttpClient() {
+    }
+
+    public static HttpClient getInstance() {
+        HttpClient HttpClient = new HttpClient();
+        HttpClient.businessException = new BusinessBasicException();
+        return HttpClient;
+    }
+
+    public static HttpClient getInstance(BusinessBasicException exception) {
+        HttpClient HttpClient = new HttpClient();
+        HttpClient.businessException = exception;
+        return HttpClient;
+    }
+
+    /**
+     * @see HttpClient#send(String, String, Map, Map)
+     */
+    public HttpClient send(final String method, final String url, final Map<String, Object> params) {
+        send(GET, url, params, formHeaders);
+        return this;
+    }
+
+    /**
+     * @see HttpClient#send(String, String, Map, Map)
+     */
+    public HttpClient send(final String url, final Map<String, Object> params) {
+        send(POST, url, params, formHeaders);
+        return this;
+    }
+
+    /**
+     * @see HttpClient#sends(String, String, Map, Map)
+     */
+    public HttpClient send(final String url, final Map<String, Object> params, final Map<String, Object> headers) {
+        send(POST, url, params, headers);
+        return this;
+    }
+
+    /**
+     * @see BasicHttpClient#sends(String, String, Map, Map)
+     */
+    public HttpClient send(final String method, final String url, final Map<String, Object> params, final Map<String, Object> headers) {
+        //write info log4j
+        log.info("method:" + method + "\n" + "url:" + url + "\n" + "parameter:" + params + "\n" + "headers" + headers + "\n");
+        try {
+            response = super.sends(method, url, params, headers);
+            checkResponse();
+        } catch (Exception ex) {
+            businessException.msg = ex.toString();
+            throw businessException;
+        }
+        return this;
+    }
+
+    public void checkResponse() throws IOException {
+        if (response == null) {
+            log.error("response is null\n");
+            businessException.msg = "返回response为null";
+            throw businessException;
+        }
+
+        if (!Objects.equals(response.getStatusCode(), 200)) {
+            log.error("response status:" + response.getStatusCode() + "\n");
+            businessException = businessException.getExceptionType(getStatus());
+            //扩展异常错误提示信息
+            //businessException.msg = "返回状态码错误:" + response.getStatusCode();
+            businessException.msg = response.getResponseBody();
+            throw businessException;
+        }
+
+        //write response message to file
+        log.info("response:\n" + response.getResponseBody());
+    }
+
+    public <T extends Serializable> T convert(Class<T> clazz) {
+        try {
+            return gson.fromJson(getResponseBody(), clazz);
+        } catch (Exception e) {
+            log.error("json2Bean失败,错误信息:" + e, e);
+            businessException = businessException.getExceptionType(500);
+            businessException.msg = "json解析错误" + e;
+            throw businessException;
+        }
+    }
+
+    public <T extends Serializable> T convert(final Type clazz) {
+        try {
+            return gson.fromJson(getResponseBody(), clazz);
+        } catch (Exception e) {
+            log.error("json2Bean失败,错误信息:" + e, e);
+            businessException = businessException.getExceptionType(500);
+            businessException.msg = "json解析错误";
+            throw businessException;
+        }
+    }
+
+    public String getResponseBody() {
+        try {
+            return response.getResponseBody();
+        } catch (Exception e) {
+            log.error("获取ResponseBody错误:" + e);
+            businessException = businessException.getExceptionType(getStatus());
+            businessException.msg = "获取ResponseBody错误:" + e;
+            throw businessException;
+        }
+    }
+
+    public Integer getStatus() {
+        return response.getStatusCode();
+    }
+}

+ 6 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/mapper/MaintenanceOptionMapper.java

@@ -2,6 +2,9 @@ package cn.com.ty.lift.business.maintenance.dao.mapper;
 
 import cn.com.ty.lift.business.maintenance.dao.entity.MaintenanceOption;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 /**
  * MyBatis Mapper 接口 - 表:maintenance_option
@@ -10,4 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface MaintenanceOptionMapper extends BaseMapper<MaintenanceOption> {
 
+    @Select("SELECT id,content,item FROM maintenance_option")
+    List<MaintenanceOption> getOptionList();
+
 }

+ 9 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/mapper/MaintenanceRecordMapper.java

@@ -1,6 +1,7 @@
 package cn.com.ty.lift.business.maintenance.dao.mapper;
 
 
+import cn.com.ty.lift.business.maintenance.dao.third.MaintenanceTask;
 import cn.com.ty.lift.business.maintenance.dao.entity.MaintenanceRecord;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.MaintenanceCount;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest;
@@ -70,6 +71,14 @@ public interface MaintenanceRecordMapper extends BaseMapper<MaintenanceRecord> {
 
     IPage<MtRecordResponse> pageByLift(IPage<MtRecordResponse> page, @Param("cond") MtRecordRequest request);
 
+    MaintenanceTask queryMaintenanceTask(@Param("mtCompanyId") Long mtCompanyId,@Param("liftId") Long liftId);
+
+    @Select("SELECT img_url FROM mt_record_img WHERE mt_record_id = #{recordId}")
+    List<String> getMaintenanceRecordUrl(Long recordId);
+
+    @Select("SELECT code FROM lift_certificate WHERE owner_id = #{workerId1}")
+    String getCardId(Long workerId1);
+
     @Select("SELECT value FROM global_set WHERE code = 'workLift' AND company_id = #{mtCompanyId}")
     String getGlobalSet(Long mtCompanyId);
 

+ 16 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/BeginMission.java

@@ -0,0 +1,16 @@
+package cn.com.ty.lift.business.maintenance.dao.third;
+
+import lombok.Data;
+
+/**
+ * @author bieao
+ * @date 2020/5/19
+ * @description 开始维保
+ */
+@Data
+public class BeginMission {
+
+    private String part;
+
+    private String item;
+}

+ 41 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/GetMission.java

@@ -0,0 +1,41 @@
+package cn.com.ty.lift.business.maintenance.dao.third;
+
+import lombok.Data;
+
+/**
+ * @author bieao
+ * @date 2020/5/18
+ * @description 任务单
+ */
+@Data
+public class GetMission {
+
+    /**
+     * 任务单id
+     */
+    private String RwdId;
+
+    /**
+     * 电梯设备代码
+     */
+    private String DevCode;
+
+    /**
+     * 设备地址
+     */
+    private String DevAddress;
+    /**
+     * 电梯设备简称
+     */
+    private String DevName;
+
+    /**
+     * 维保开始时间
+     */
+    private String WbStartTime;
+
+    /**
+     * 维保截止时间
+     */
+    private String WbEndTime;
+}

+ 25 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/ItemContent.java

@@ -0,0 +1,25 @@
+package cn.com.ty.lift.business.maintenance.dao.third;
+
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author bieao
+ * @date 2020/5/16
+ * @description
+ */
+@Data
+public class ItemContent {
+
+    /**
+     * 维保检查项
+     */
+    private List<Map<String,String>> WbItems;
+
+    /**
+     * 维保拍照记录
+     */
+    private List<RecordContent> Records;
+}

+ 43 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/MaintenanceTask.java

@@ -0,0 +1,43 @@
+package cn.com.ty.lift.business.maintenance.dao.third;
+
+import lombok.Data;
+
+/**
+ * @author bieao
+ * @date 2020/5/16
+ * @description 维保任务记录
+ */
+@Data
+public class MaintenanceTask {
+
+    /**
+     * 任务单Id
+     */
+    private Long id;
+
+    /**
+     * 作业类型 半月,季度,半年,年度
+     */
+    private String type;
+
+    /**
+     * 实际维保人操作证ID
+     */
+    private String code;
+
+    /**
+     * 维保项
+     */
+    private String maintenanceOption;
+
+    /**
+     * 维保建议
+     */
+    private String maintenanceAdvice;
+
+    /**
+     * 维保签名
+     */
+    private String signatureImg1;
+
+}

+ 22 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/MissionContent.java

@@ -0,0 +1,22 @@
+package cn.com.ty.lift.business.maintenance.dao.third;
+
+import lombok.Data;
+
+/**
+ * @author bieao
+ * @date 2020/5/18
+ * @description 获取任务单入参
+ */
+@Data
+public class MissionContent {
+
+    /**
+     * 电梯设备代码
+     */
+    private String DevCode;
+
+    /**
+     * 操作证编号
+     */
+    private String CardNoList;
+}

+ 34 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/RecordContent.java

@@ -0,0 +1,34 @@
+package cn.com.ty.lift.business.maintenance.dao.third;
+
+import cn.hutool.core.util.StrUtil;
+import lombok.Data;
+
+/**
+ * @author bieao
+ * @date 2020/5/16
+ * @description
+ */
+@Data
+public class RecordContent {
+
+    public RecordContent() {
+        MaterialName = StrUtil.EMPTY;
+        MaterialUrl = StrUtil.EMPTY;
+        Partname = StrUtil.EMPTY;
+    }
+
+    /**
+     * 资料名称
+     */
+    private String MaterialName;
+
+    /**
+     * 资料地址(照片地址)
+     */
+    private String MaterialUrl;
+
+    /**
+     * 拍照部位名称
+     */
+    private String Partname;
+}

+ 16 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/third/ThirdPartyInterfaceResponse.java

@@ -0,0 +1,16 @@
+package cn.com.ty.lift.business.maintenance.dao.third;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ThirdPartyInterfaceResponse<T> implements Serializable {
+    /**
+     * 提交成功返回true,失败false
+     */
+    private boolean status;
+    private String message;
+    private int code;
+    private T data;
+}

+ 196 - 5
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/service/MaintenanceRecordService.java

@@ -1,20 +1,21 @@
 package cn.com.ty.lift.business.maintenance.service;
 
+import cn.com.ty.lift.business.common.http.BasicHttpClient;
+import cn.com.ty.lift.business.common.http.HttpClient;
 import cn.com.ty.lift.business.evaluation.dao.entity.Evaluation;
 import cn.com.ty.lift.business.evaluation.service.EvaluationService;
 import cn.com.ty.lift.business.framework.util.MessageUtils;
 import cn.com.ty.lift.business.library.dao.entity.Lift;
 import cn.com.ty.lift.business.library.service.LiftService;
-import cn.com.ty.lift.business.maintenance.dao.entity.MaintenancePlan;
-import cn.com.ty.lift.business.maintenance.dao.entity.MaintenanceRecord;
-import cn.com.ty.lift.business.maintenance.dao.entity.MtRecordCost;
-import cn.com.ty.lift.business.maintenance.dao.entity.MtRecordImg;
+import cn.com.ty.lift.business.maintenance.dao.entity.*;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceRecordDetailResponse;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceRecordResponse;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.MtRecordResponse;
+import cn.com.ty.lift.business.maintenance.dao.mapper.MaintenanceOptionMapper;
 import cn.com.ty.lift.business.maintenance.dao.mapper.MaintenanceRecordMapper;
+import cn.com.ty.lift.business.maintenance.dao.third.*;
 import cn.com.ty.lift.business.project.dao.entity.Project;
 import cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance;
 import cn.com.ty.lift.business.project.service.ProjectLiftRelevanceService;
@@ -32,9 +33,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.reflect.TypeToken;
 import com.google.gson.Gson;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
@@ -63,8 +67,10 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
     private EvaluationService evaluationService;
     private ProjectService projectService;
     private ProjectLiftRelevanceService projectLiftRelevanceService;
-
+    private MaintenanceOptionMapper maintenanceOptionMapper;
     private Gson gson;
+    @Autowired
+    private Environment env;
 
     /**
      * @param request 公司id和电梯id
@@ -261,6 +267,165 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
         return RestResponse.success(record.getId(), MessageUtils.get("msg.add.success"));
     }
 
+    /**
+     * @param params 获取任务单入参
+     * @return GetMission 任务单信息
+     * @description 获取任务单
+     * @date 2020/5/18 2:51 下午
+     */
+    public GetMission getMission(Map<String, Object> params) {
+        log.info("调用第三方接口获取任务单");
+        String url = env.getProperty("get.mission");
+        ThirdPartyInterfaceResponse<GetMission> response = HttpClient.getInstance().send(url, params, BasicHttpClient.jsonHeaders)
+                .convert(new TypeToken<ThirdPartyInterfaceResponse<GetMission>>() {
+                }.getType());
+        GetMission getMission = null;
+        try {
+            if (Objects.nonNull(response)) {
+                if (Objects.equals(0, response.getCode())) {
+                    getMission = response.getData();
+                }
+            }
+        } catch (Exception e) {
+            log.error("获取任务单数据失败", e);
+        }
+        log.info("结束调用第三方任务单接口");
+        return getMission;
+    }
+
+    /**
+     * @param params RwdId 开始维保入参
+     * @return List<BeginMission> 需要维保的项
+     * @description 开始维保
+     * @date 2020/5/19 2:41 下午
+     */
+    public List<BeginMission> beginMaintenance(Map<String, Object> params, String rwdId) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("RwdId", rwdId);
+        params.put("Content", map);
+        String url = env.getProperty("begin.maintenance");
+        log.info("调用第三方接口开始维保任务");
+        ThirdPartyInterfaceResponse<List<BeginMission>> response = HttpClient.getInstance().send(url, params, BasicHttpClient.jsonHeaders)
+                .convert(new TypeToken<ThirdPartyInterfaceResponse<List<BeginMission>>>() {
+                }.getType());
+        List<BeginMission> missions = null;
+        try {
+            if (Objects.nonNull(response)) {
+                if (Objects.equals(0, response.getCode())) {
+                    missions = response.getData();
+                }
+            }
+        } catch (Exception e) {
+            log.error("开始维保任务失败", e);
+        }
+        log.info("结束调用第三方开始维保任务接口");
+        return missions;
+    }
+
+    /**
+     * @param params RwdId,token,account 完成维保入参
+     * @param mtCompanyId 公司ID
+     * @description 完成维保
+     * @date 2020/5/19 4:01 下午
+     */
+    public void endMaintenance(Map<String, Object> params, Long mtCompanyId, Long recordId, String rwdId, Long liftId) {
+        //查询维保记录
+        MaintenanceTask task = baseMapper.queryMaintenanceTask(mtCompanyId, liftId);
+        params.remove("Content");
+        params.put("RwdId", rwdId);
+        //需物业配合事项
+        params.put("Items", "");
+        //维保报告
+        params.put("Report", task.getMaintenanceAdvice());
+        //作业类型
+        params.put("OpeateType", task.getType());
+        //实际维保人操作证ID
+        params.put("CardId", task.getCode());
+        //媒体类型
+        params.put("MdeiaType", "照片");
+        //获取维保图片地址
+        List<String> urlList = baseMapper.getMaintenanceRecordUrl(task.getId());
+        List<RecordContent> Records = new ArrayList<>();
+        for (String s : urlList) {
+            RecordContent recordContent = new RecordContent();
+            recordContent.setMaterialUrl(s);
+            Records.add(recordContent);
+        }
+        //封装维保项数据
+        MaintenanceRecord record = getById(recordId);
+        List<MaintenanceOption> optionList = maintenanceOptionMapper.getOptionList();
+        List<Map<String, String>> returnList = new ArrayList<>();
+        if (Objects.nonNull(record)) {
+            String option = record.getMaintenanceOption();
+            String[] split = option.split(",");
+            for (String s : split) {
+                for (MaintenanceOption entry : optionList) {
+                    String[] split1 = s.split(":");
+                    if (split1.length > 1) {
+                        String id = split1[0];
+                        String result = split1[1];
+                        String optionId = Objects.toString(entry.getId());
+                        if (id.equals(optionId)) {
+                            Map<String, String> paramMap = new HashMap<>();
+                            paramMap.put("CkItem", entry.getItem());
+                            paramMap.put("CkContent", entry.getContent());
+                            paramMap.put("Ckresult", result.equals("0") ? "无此项" : (result.equals("1") ? "正常" : "需修理"));
+                            returnList.add(paramMap);
+                        }
+                    }
+                }
+            }
+        }
+        ItemContent content = new ItemContent();
+        content.setWbItems(returnList);
+        content.setRecords(Records);
+        params.put("Content", content);
+
+        String url = env.getProperty("end.maintenance");
+
+        log.info("调用第三方接口完成维保任务");
+        ThirdPartyInterfaceResponse response = HttpClient.getInstance().send(url, params, BasicHttpClient.jsonHeaders)
+                .convert(new TypeToken<ThirdPartyInterfaceResponse>() {
+                }.getType());
+        try {
+            if (Objects.nonNull(response)) {
+                if (Objects.equals(0, response.getCode())) {
+                    log.info("维保记录提交成功");
+                }
+            }
+        } catch (Exception e) {
+            log.error("完成维保任务失败", e);
+        }
+        log.info("结束调用第三方完成维保任务接口");
+    }
+
+    /**
+     * @param params RwdId,token,account 提交维保记录入参
+     * @param mtCompanyId 公司ID
+     * @description 提交维保记录
+     * @date 2020/5/19 2:55 下午
+     */
+    public void commitMaintenanceRecord(Map<String, Object> params, Long mtCompanyId, Long recordId, Long liftId) {
+        //获取任务单
+        GetMission mission = getMission(params);
+        if (Objects.isNull(mission)) {
+            log.warn("获取任务单失败");
+            //TODO 回补机制待完善
+        } else {
+            String rwdId = mission.getRwdId();
+            //开始维保任务
+            List<BeginMission> missions = beginMaintenance(params, rwdId);
+            if (Objects.isNull(missions)) {
+                log.warn("开始维保任务失败");
+            } else {
+                if (CollUtil.isNotEmpty(missions)) {
+                    //结束维保任务,提交保养记录
+                    endMaintenance(params, mtCompanyId, recordId, rwdId, liftId);
+                }
+            }
+        }
+    }
+
     /**
      * @param request 保养信息
      * @return 是否成功
@@ -300,6 +465,32 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
             image.setMtRecordId(record.getId());
             imageList.add(image);
         });
+        Long mtCompanyId = request.getMtCompanyId();
+        //苏州帝威电梯工程技术有限公司 - 发送维保记录数据
+        if (Objects.equals(1001102109977L, mtCompanyId)) {
+            String registrationCode = StrUtil.EMPTY;
+            Long liftId = oldRecord.getLiftId();
+            Optional<Lift> optional = liftService.getOne(null, liftId);
+            if (optional.isPresent()){
+                Lift lift = optional.get();
+                registrationCode = lift.getRegistrationCode();
+            }
+            Long recordId = record.getId();
+            //获取维保人员ID
+            Long workerId1 = oldRecord.getWorkerId1();
+            //查询维保人员操作证
+            String cardId = baseMapper.getCardId(workerId1);
+            MissionContent content = new MissionContent();
+            content.setDevCode(registrationCode);
+            content.setCardNoList(cardId);
+
+            Map<String, Object> params = new HashMap<>();
+            params.put("token", env.getProperty("token"));
+            params.put("account", env.getProperty("account"));
+            params.put("Content", content);
+            //提交维保记录
+            commitMaintenanceRecord(params, mtCompanyId, recordId, liftId);
+        }
         boolean ret = mtRecordImgService.saveBatch(imageList, imageList.size());
         if (!ret) {
             rollback();

+ 5 - 0
lift-business-service/src/main/resources/application.properties

@@ -0,0 +1,5 @@
+token=7c295af2665c32680
+account=\u82CF\u5DDE\u5E1D\u5A01\u7535\u68AF\u5DE5\u7A0B\u6280\u672F\u6709\u9650\u516C\u53F8
+get.mission=http://wxqts.nsccwx.cn:7001/MaintainanceMission/GetMission
+begin.maintenance=http://wxqts.nsccwx.cn:7001/MaintainanceMission/BeginMaintainance
+end.maintenance=http://wxqts.nsccwx.cn:7001/MaintainanceMission/EndMaintainance

+ 19 - 0
lift-business-service/src/main/resources/mapper/maintenance/MaintenanceRecordMapper.xml

@@ -350,4 +350,23 @@
             </if>
         </where>
     </select>
+
+    <select id="queryMaintenanceTask" parameterType="java.lang.Long" resultType="cn.com.ty.lift.business.maintenance.dao.third.MaintenanceTask">
+        SELECT mr.id,
+               CASE mr.type
+                   WHEN '1' THEN '半月'
+                   WHEN '2' THEN '季度'
+                   WHEN '3' THEN '半年'
+                   WHEN '4' THEN '全年'
+                   END AS type,
+               lc.code,
+               mr.maintenance_option,
+               mr.signature_img1,
+               mr.maintenance_advice
+        FROM maintenance_record mr
+                 LEFT JOIN lift_certificate lc ON mr.worker_id1 = lc.owner_id
+        WHERE mr.mt_company_id = #{mtCompanyId}
+          AND mr.lift_id = #{liftId}
+          AND plan_date = current_date()
+    </select>
 </mapper>