|
@@ -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();
|