From 2b80ec2ea965f3ac34ac164d8ed1ec8a00d40f87 Mon Sep 17 00:00:00 2001
From: luliqiang <kidgrow>
Date: Wed, 16 Dec 2020 16:40:13 +0800
Subject: [PATCH] 增加合作商信息和合作商客户信息管理功能

---
 kidgrow-business/kidgrow-opration-center/kidgrow-opration-center-biz/src/main/java/com/kidgrow/oprationcenter/service/impl/PartnerDockingInfoServiceImpl.java |  218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 218 insertions(+), 0 deletions(-)

diff --git a/kidgrow-business/kidgrow-opration-center/kidgrow-opration-center-biz/src/main/java/com/kidgrow/oprationcenter/service/impl/PartnerDockingInfoServiceImpl.java b/kidgrow-business/kidgrow-opration-center/kidgrow-opration-center-biz/src/main/java/com/kidgrow/oprationcenter/service/impl/PartnerDockingInfoServiceImpl.java
index e33678b..d7e673b 100644
--- a/kidgrow-business/kidgrow-opration-center/kidgrow-opration-center-biz/src/main/java/com/kidgrow/oprationcenter/service/impl/PartnerDockingInfoServiceImpl.java
+++ b/kidgrow-business/kidgrow-opration-center/kidgrow-opration-center-biz/src/main/java/com/kidgrow/oprationcenter/service/impl/PartnerDockingInfoServiceImpl.java
@@ -1,15 +1,33 @@
 package com.kidgrow.oprationcenter.service.impl;
 
+import cn.hutool.core.date.DateTime;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.kidgrow.common.model.PageResult;
+import com.kidgrow.common.model.ResultBody;
 import com.kidgrow.common.service.impl.SuperServiceImpl;
 import com.kidgrow.oprationcenter.mapper.PartnerDockingInfoMapper;
 import com.kidgrow.oprationcenter.model.PartnerDockingInfo;
+import com.kidgrow.oprationcenter.model.PartnerInfo;
 import com.kidgrow.oprationcenter.service.IPartnerDockingInfoService;
+import com.kidgrow.oprationcenter.service.IPartnerInfoService;
+import com.kidgrow.usercenter.feign.SysDepartmentService;
+import com.kidgrow.usercenter.feign.SysDoctorService;
+import com.kidgrow.usercenter.feign.SysHospitalService;
+import com.kidgrow.usercenter.model.SysDoctor;
+import com.kidgrow.usercenter.model.SysHospital;
+import io.undertow.util.FileUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.MapUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
 import org.springframework.stereotype.Service;
+import org.springframework.util.DigestUtils;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -24,6 +42,22 @@
 @Slf4j
 @Service
 public class PartnerDockingInfoServiceImpl extends SuperServiceImpl<PartnerDockingInfoMapper, PartnerDockingInfo> implements IPartnerDockingInfoService {
+
+    @Autowired
+    ResourceLoader resourceLoader;
+
+    @Autowired
+    SysHospitalService sysHospitalService;
+
+    @Autowired
+    SysDepartmentService sysDepartmentService;
+
+    @Autowired
+    SysDoctorService sysDoctorService;
+
+    @Autowired
+    IPartnerInfoService partnerInfoService;
+
     /**
      * 列表
      * @param params
@@ -45,4 +79,188 @@
     public PartnerDockingInfo findByObject(PartnerDockingInfo partnerDockingInfo){
         return baseMapper.findByObject(partnerDockingInfo);
     }
+
+
+    /**
+     * 根据对接类型版本等信息,创建客户私有云数据库脚本
+     * @param partnerDockingInfo
+     * @return
+     */
+    @Override
+    public String createSQL( PartnerDockingInfo partnerDockingInfo ){
+        // 模板SQL文
+        String dbSql = "";
+        // 医院信息SQL文
+        String hospitalSQL = "";
+        // 科室信息SQL文
+        String departmentSQL = "";
+        // 医生信息SQL文
+        String doctorSQL = "";
+        // 合作商信息SQL文
+        String partnerSQL = "";
+        // 服务器信息SQL文
+        String serverSQL= "";
+        InputStream fileImput =null;
+        try {
+            // 1、读取基础表结构SQL
+            Resource resource = resourceLoader.getResource("classpath:template//imageServer_template.sql");
+            fileImput = resource.getInputStream();  //new FileInputStream("./template/imageServer_template.sql");
+            dbSql = FileUtils.readFile(fileImput);
+
+            // 2、读取医院信息表Hospital_Info,插入SQL文中
+            Map<String,Object> hospitalMap = new HashMap<>();
+            hospitalMap.put("id",partnerDockingInfo.getHospitalId());
+            ResultBody hospitalResult = sysHospitalService.findAllByMap(hospitalMap);
+
+            if (hospitalResult.isOk()){
+                String jsonData = JSONObject.toJSONString(hospitalResult.getData());
+                List<SysHospital> hospitalLists= JSONObject.parseArray(jsonData,SysHospital.class);
+                if (hospitalLists.size()> 0) {
+                    SysHospital hospitalInfo = hospitalLists.get(0);
+                    hospitalSQL = " INSERT INTO sys_hospital  VALUES (" +
+                            hospitalInfo.getId() + ", " +
+                            "'" + hospitalInfo.getHospitalName()+ "', " +
+                            "'" + hospitalInfo.getHospitalShortName()+ "', " +
+                            "'" + hospitalInfo.getHospitalCode()+ "', " +
+                            "'" + hospitalInfo.getHospitalTypeId()+ "', " +
+                            "'" + hospitalInfo.getHospitalTypeName()+ "', " +
+                            "'" + hospitalInfo.getHospitalTel()+ "', " +
+                            "'" + hospitalInfo.getHospitalProvince()+ "', " +
+                            "'" + hospitalInfo.getHospitalCity()+ "', " +
+                            "'" + hospitalInfo.getHospitalArea()+ "', " +
+                            "'" + hospitalInfo.getAreaCode()+ "', " +
+                            "'" + hospitalInfo.getHospitalLink()+ "', " +
+                            "'" + hospitalInfo.getHospitalAdress()+ "', " +
+                            "'" + hospitalInfo.getLatitude()+ "', " +
+                            "'" + hospitalInfo.getLongitude()+ "', " +
+                            "'" + hospitalInfo.getHospitalQualifiedId()+ "', " +
+                            "'" + hospitalInfo.getHospitalQualifiedName()+ "', " +
+                            "NULL," +
+                            "NULL," +
+                            "NULL," +
+                            "'" + hospitalInfo.getHospitalAbout()+ "', " +
+                            hospitalInfo.getHospitalState() + ", " +
+                            hospitalInfo.getEnabled() + ", " +
+                            hospitalInfo.getIsDel() + ", " +
+                            hospitalInfo.getCreateUserId() + ", " +
+                            "'" + hospitalInfo.getCreateUserName()+ "', " +
+                            hospitalInfo.getUpdateUserId() + ", " +
+                            "'" + hospitalInfo.getUpdateUserName()+ "', " +
+                            "'" + hospitalInfo.getCreateTime()+ "', " +
+                            "'" + hospitalInfo.getUpdateTime()+"' " +
+                            ");\n\r";
+                }
+
+            }
+
+            // 3、读取科室信息表Department_Info,生成SQL文
+            departmentSQL = "INSERT INTO sys_department VALUES ("+
+                    +partnerDockingInfo.getDepartmentId()+ ", "+
+                    "'" + partnerDockingInfo.getDepartmentName() +"', " +
+                    "0, 1, 0, '喜高科技', 0 , '喜高科技', " +
+                    "'" + DateTime.now().toString() + "', " +
+                    "'" + DateTime.now().toString() + "', " +
+                    "6 " +
+                    ");\n\r";
+            // 4、读取医生信息表Doctor_Info,生成SQL文
+            Map<String,Object> doctorMap = new HashMap<>();
+            doctorMap.put("hospital_id",partnerDockingInfo.getHospitalId());
+            doctorMap.put("department_id",partnerDockingInfo.getDepartmentId());
+            doctorMap.put("is_admin_user",1);
+            ResultBody doctorResult = sysDoctorService.getListByMap(doctorMap);
+
+            if (doctorResult.isOk()) {
+                String jsonData = JSONObject.toJSONString(doctorResult.getData());
+                List<SysDoctor> doctorList = JSONObject.parseArray(jsonData, SysDoctor.class);
+                if (doctorList.size() > 0) {
+                    SysDoctor doctorInfo = doctorList.get(0);
+                    doctorSQL = "INSERT INTO sys_doctor VALUES(" +
+                            doctorInfo.getId() + ", " +
+                            + doctorInfo.getHospitalId() + ", " +
+                            "'" + doctorInfo.getHospitalName()+ "', " +
+                            + doctorInfo.getDepartmentId() + ", " +
+                            "'" + doctorInfo.getDepartmentName()+ "', " +
+                            "'" + doctorInfo.getDoctorName()+ "', " +
+                            "NULL, " +
+                            "'" + doctorInfo.getDoctorCcie()+ "', " +
+                            "'" + doctorInfo.getDoctorTel()+ "', " +
+                            "'" + DigestUtils.md5DigestAsHex("123456".getBytes()).replace("-","") +"', " +
+                            "'" + doctorInfo.getDoctorRankId()+ "', " +
+                            "'" + doctorInfo.getDoctorRank()+ "', " +
+                            "'" + doctorInfo.getDoctorOtherLink()+ "', " +
+                            "'" + doctorInfo.getDoctorEmail()+ "', " +
+                            "'" + doctorInfo.getDoctorAbout()+ "', " +
+                            "0, " +
+                            doctorInfo.getDoctorState()+ ", " +
+                            doctorInfo.getDoctorType()+ ", " +
+                            "0, 1, 0, '喜高科技', 0 , '喜高科技', " +
+                            "'" + DateTime.now().toString() + "', " +
+                            "'" + DateTime.now().toString() + "', " +
+                            "1" +
+                            ");\n\r";
+                }
+            }
+
+            // 5、读取合作商信息表Partner_Info,生成SQL文
+            PartnerInfo partnerInfo = partnerInfoService.getById(partnerDockingInfo.getPartnerId());
+            if (partnerInfo!= null) {
+                partnerSQL = "INSERT INTO partner_info VALUES (" +
+                        partnerInfo.getId() + ", " +
+                        "'" +partnerInfo.getPartnerName() + "', " +
+                        + partnerInfo.getPartnerType() + ", " +
+                        "'" +partnerInfo.getPartnerAddress() + "', " +
+                        "'" +partnerInfo.getPartnerProvince() + "', " +
+                        "'" +partnerInfo.getPartnerCity() + "', " +
+                        "'" +partnerInfo.getPartnerArea() + "', " +
+                        "'" +partnerInfo.getPartnerLinkMan() + "', " +
+                        "'" +partnerInfo.getPartnerLinkTelephone() + "', " +
+                        "'" +partnerInfo.getPartnerBussinessArea() + "', " +
+                        "'" +partnerInfo.getPartnerIntroduce() + "', " +
+                        "'" +partnerInfo.getPartnerUniqueCode() + "', " +
+                        + partnerInfo.getCreateUserId() + ", " +
+                        "'" +partnerInfo.getCreateUserName() + "', " +
+                        "'" +partnerInfo.getCreateTime() + "', " +
+                        + partnerInfo.getUpdateUserId() + ", " +
+                        "'" +partnerInfo.getUpdateUserName() + "', " +
+                        "'" +partnerInfo.getUpdateTime() + "'  " +
+                        ");\n\r";
+            }
+            // 6、读取服务器信息表Server_Info,生成SQL文
+            if ((partnerDockingInfo.getAccessKey() != null) && (!partnerDockingInfo.getAccessKey().isEmpty())) {
+                serverSQL = "INSERT INTO server_info VALUES(" +
+                        partnerDockingInfo.getId() + ", " +
+                        partnerDockingInfo.getPartnerId() + ", " +
+                        partnerDockingInfo.getHospitalId() + ", " +
+                        partnerDockingInfo.getDepartmentId() + ", " +
+                        "NULL, NULL, NULL, NULL, " +
+                        "'" + partnerDockingInfo.getServerMachineCode() + "', " +
+                        "NULL, NULL, " +
+                        "'" + partnerDockingInfo.getAccessKey() + "', " +
+                        "0, 1, " +
+                        partnerDockingInfo.getCreateUserId() + ", " +
+                        "'" + partnerDockingInfo.getCreateUserName() + "', " +
+                        "'" + partnerDockingInfo.getCreateTime() + "', " +
+                        partnerDockingInfo.getUpdateUserId() + ", " +
+                        "'" + partnerDockingInfo.getUpdateUserName() + "', " +
+                        "'" + partnerDockingInfo.getUpdateTime() + "', " +
+                        ");\n\r";
+            }
+            // 7、所有SQL文合并入基本的SQL中
+            dbSql += hospitalSQL + departmentSQL + doctorSQL + partnerSQL +serverSQL;
+
+        } catch (Exception e){
+            e.printStackTrace();
+        } finally {
+            try {
+                fileImput.close();
+            } catch (IOException e){
+                e.printStackTrace();
+            }
+        }
+
+
+
+
+        return  dbSql;
+    };
 }

--
Gitblit v1.8.0