Quellcode durchsuchen

Merge remote-tracking branch 'origin/20210223' into 20210223

wangyangyang vor 3 Jahren
Ursprung
Commit
d500a7a580
25 geänderte Dateien mit 711 neuen und 34 gelöschten Zeilen
  1. 50 0
      common/src/main/java/com/huaxu/util/MD5Util.java
  2. 4 2
      readme.md
  3. 4 2
      sms_water/src/main/java/com/huaxu/controller/MonitorInfoController.java
  4. 10 0
      sms_water/src/main/java/com/huaxu/controller/OnlineMonitorController.java
  5. 6 0
      sms_water/src/main/java/com/huaxu/dao/OnlineMonitorMapper.java
  6. 2 1
      sms_water/src/main/java/com/huaxu/dto/AlarmDetailsDto.java
  7. 2 0
      sms_water/src/main/java/com/huaxu/dto/MonitorDataDto.java
  8. 4 1
      sms_water/src/main/java/com/huaxu/dto/OnlineDataDto.java
  9. 10 0
      sms_water/src/main/java/com/huaxu/entity/AlarmSetting.java
  10. 5 0
      sms_water/src/main/java/com/huaxu/service/OnlineMonitorService.java
  11. 18 0
      sms_water/src/main/java/com/huaxu/service/impl/OnlineMonitorImpl.java
  12. 3 2
      sms_water/src/main/resources/mapper/AlarmDetailMapper.xml
  13. 2 0
      sms_water/src/main/resources/mapper/AlarmSettingMapper.xml
  14. 38 25
      sms_water/src/main/resources/mapper/OnlineMonitorMapper.xml
  15. 31 0
      user_auth/src/main/java/com/huaxu/config/SsoConfig.java
  16. 43 0
      user_auth/src/main/java/com/huaxu/controller/ThirdPartyLoginController.java
  17. 2 0
      user_auth/src/main/java/com/huaxu/dao/UserMapper.java
  18. 19 0
      user_auth/src/main/java/com/huaxu/dto/thirdparty/LoginQueryDto.java
  19. 24 0
      user_auth/src/main/java/com/huaxu/dto/thirdparty/XieDingResultDto.java
  20. 12 0
      user_auth/src/main/java/com/huaxu/entity/User.java
  21. 15 0
      user_auth/src/main/java/com/huaxu/service/ThirdPartyLoginService.java
  22. 79 0
      user_auth/src/main/java/com/huaxu/service/impl/thirdparty/XiedingLoginServiceImpl.java
  23. 320 0
      user_auth/src/main/java/com/huaxu/util/HttpClientPoolUtil.java
  24. 4 1
      user_auth/src/main/resources/application-dev.properties
  25. 4 0
      user_auth/src/main/resources/mapper/UserMapper.xml

+ 50 - 0
common/src/main/java/com/huaxu/util/MD5Util.java

@@ -0,0 +1,50 @@
+package com.huaxu.util;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class MD5Util {
+
+    public static String digest(String inbuf) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            md.update(inbuf.getBytes());
+            byte b[] = md.digest();
+            int i;
+            StringBuffer buf = new StringBuffer("");
+            for (int offset = 0; offset < b.length; offset++) {
+                i = b[offset];
+                if (i < 0) {
+                    i += 256;
+                }
+                if (i < 16) {
+                    buf.append("0");
+                }
+                buf.append(Integer.toHexString(i));
+            }
+            return buf.toString();
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public static String[] chars = new String[]{"a", "b", "c", "d", "e", "f",
+        "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
+        "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
+        "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
+        "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
+        "W", "X", "Y", "Z"};
+
+    //根据加密后的MD5生成8位字符串
+    public static String generateShort(String str) {
+        StringBuffer shortBuffer = new StringBuffer();
+        String digStr = digest(str);
+        for (int i = 0; i < 8; i++) {
+            String newStr = digStr.substring(i * 4, i * 4 + 4);
+            int x = Integer.parseInt(newStr, 16);
+            shortBuffer.append(chars[x % 0x3E]);
+        }
+        return shortBuffer.toString();
+    }
+}

+ 4 - 2
readme.md

@@ -2,8 +2,10 @@
 ## 更新内容(数据库)
 
 ### sms_monitor_info 添加字段type
-1、ALTER TABLE sms_monitor_info ADD TYPE int
-2、
+1、ALTER TABLE sms_monitor_info ADD TYPE int;
+### sms_alarm_setting 添加字段START_TIME、END_TIME
+1、ALTER TABLE sms_alarm_setting ADD START_TIME varchar(20) null COMMENT '报警设置开始时间',
+  				ADD END_TIME varchar(20) null COMMENT '报警设置结束时间';
 
 
 ## uims数据库

+ 4 - 2
sms_water/src/main/java/com/huaxu/controller/MonitorInfoController.java

@@ -170,10 +170,12 @@ public class MonitorInfoController {
                             }
                         }
                         //判断是否报警
-                        if (mapAlarm.containsKey(item.getAttributeId().intValue()))
+                        if (mapAlarm.containsKey(item.getAttributeId().intValue())){
                             item.setIsAlarm(1);
-                        else
+                            item.setMonitorValue(item.getMonitorValue()+"("+mapAlarm.get(item.getAttributeId().intValue()).getAlarmRange()+")");
+                        }else{
                             item.setIsAlarm(0);
+                        }
                     }
                 }
             }

+ 10 - 0
sms_water/src/main/java/com/huaxu/controller/OnlineMonitorController.java

@@ -313,4 +313,14 @@ public class OnlineMonitorController {
         List<OnlineDataDto> result = onlineMonitorService.selectPipeNetList(onlineDataDto);
         return new AjaxMessage<>(ResultStatus.OK, result);
     }
+    @RequestMapping(value="selectStateCount" , method = RequestMethod.GET)
+    @ApiOperation(value = "查询场景实时状态数量")
+    public AjaxMessage<List<Map<String, Object>>> selectStatusCount(
+            @ApiParam(value = "一级场景类型名称", required = true) @RequestParam String sceneTypeName){
+        OnlineDataDto onlineDataDto=new OnlineDataDto();
+        onlineDataDto.setSceneTypeName(sceneTypeName);
+        onlineDataDto.setFlag(1);
+        onlineDataDto.setSceneIds(sceneService.findByParentIdsLike(null));
+        return new AjaxMessage<>(ResultStatus.OK, onlineMonitorService.selectStateCount(onlineDataDto));
+    }
 }

+ 6 - 0
sms_water/src/main/java/com/huaxu/dao/OnlineMonitorMapper.java

@@ -118,4 +118,10 @@ public interface OnlineMonitorMapper {
      * @return
      */
     List<SceneDeviceDto> selectSceneDevice(SceneDeviceQueryDto sceneDeviceQueryDto);
+
+    /**
+     * 查询场景实时状态数量
+     * @return
+     */
+    List<Map<String, Object>> selectStateCount(OnlineDataDto onlineDataDto);
 }

+ 2 - 1
sms_water/src/main/java/com/huaxu/dto/AlarmDetailsDto.java

@@ -78,5 +78,6 @@ public class AlarmDetailsDto extends AlarmDetailsEntity {
     @JsonIgnore
     private Integer days;
 
-
+    @ApiModelProperty(value = "报警范围")
+    private String alarmRange;
 }

+ 2 - 0
sms_water/src/main/java/com/huaxu/dto/MonitorDataDto.java

@@ -47,4 +47,6 @@ public class MonitorDataDto implements Serializable {
     @ApiModelProperty(value = "离线日报表昨日最新值",hidden = true)
     @JsonIgnore
     private Double latestValue;
+    @ApiModelProperty(value = "报警范围")
+    private String alarmRange;
 }

+ 4 - 1
sms_water/src/main/java/com/huaxu/dto/OnlineDataDto.java

@@ -67,7 +67,7 @@ public class OnlineDataDto {
     @ApiModelProperty("水位")
     private MonitorDataDto waterLevel;
 
-    @ApiModelProperty("压力")
+    @ApiModelProperty("压力、出口压力")
     private MonitorDataDto pressure;
 
     @ApiModelProperty("余氯")
@@ -140,4 +140,7 @@ public class OnlineDataDto {
     @ApiModelProperty(value ="公司id",hidden = true)
     @JsonIgnore
     private Integer companyOrgId;
+
+    @ApiModelProperty("进口压力")
+    private MonitorDataDto importPressure;
 }

+ 10 - 0
sms_water/src/main/java/com/huaxu/entity/AlarmSetting.java

@@ -113,4 +113,14 @@ public class AlarmSetting implements Serializable {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
     @ApiModelProperty(value = "更新时间")
     private Date dateUpdate;
+    /**
+     * 报警设置开始时间
+     */
+    @ApiModelProperty(value = "报警设置开始时间")
+    private String startTime;
+    /**
+     * 报警设置结束时间
+     */
+    @ApiModelProperty(value = "报警设置结束时间")
+    private String endTime;
 }

+ 5 - 0
sms_water/src/main/java/com/huaxu/service/OnlineMonitorService.java

@@ -111,4 +111,9 @@ public interface OnlineMonitorService {
      * @return
      */
     List<OnlineDataDto> selectPipeNetList(OnlineDataDto onlineDataDto);
+    /**
+     * 查询场景实时状态数量
+     * @return
+     */
+    List<Map<String, Object>> selectStateCount(OnlineDataDto onlineDataDto);
 }

+ 18 - 0
sms_water/src/main/java/com/huaxu/service/impl/OnlineMonitorImpl.java

@@ -777,6 +777,9 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
                                     case "18"://电导率
                                         monDataCol.setConductivity(monitorData);
                                         break;
+                                    case "20"://进口压力
+                                        monDataCol.setImportPressure(monitorData);
+                                        break;
                                 }
                             }
                         }
@@ -853,4 +856,19 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
         }
         return result;
     }
+    /**
+     * 查询场景实时状态数量
+     * @return
+     */
+    @Override
+    public List<Map<String, Object>> selectStateCount(OnlineDataDto onlineDataDto)
+    {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        onlineDataDto.setTenantId(loginUser.getTenantId());
+        onlineDataDto.setProgramItems(loginUser.getProgramItemList());
+        onlineDataDto.setUserType(loginUser.getType());
+        //1是公司,2是公司及以下,3部门,4部门及以下,5自定义
+        onlineDataDto.setPermissonType(loginUser.getPermissonType());
+        return onlineMonitorMapper.selectStateCount(onlineDataDto);
+    }
 }

+ 3 - 2
sms_water/src/main/resources/mapper/AlarmDetailMapper.xml

@@ -34,7 +34,7 @@
             ,d.POINT_X as "pointX"
             ,d.POINT_Y as "pointY"
             ,ast.id as "alarmSettingId"
-            ,ast.ALARM_CONDITION +" " +ast.ALARM_VALUE as "alermRule"
+            /*,ast.ALARM_CONDITION +" " +ast.ALARM_VALUE as "alermRule"*/
             ,concat(ifnull(ast.ALARM_CONDITION,''),ifnull(ast.ALARM_VALUE,'')) as "alermRule"
             ,att.UNIT as "unit"
     </sql>
@@ -675,8 +675,9 @@
 
     <select id="selectByDeviceId" resultType="com.huaxu.dto.AlarmDetailsDto">
         select
-        <include refid="Base_Column_List"/>
+        <include refid="Base_Column_List"/>,concat(b.alarm_condition,cast(b.alarm_value as char)+0) alarmRange
         from sms_alarm_details a
+        left join sms_alarm_setting b on a.alarm_setting_id=b.id and b.status = 1 and b.alarm_condition!='='
         <include refid="alarmDetailJoins"/>
         where a.`STATUS` = 1
         and a.DEVICE_ID=#{deviceId} and a.state=1

+ 2 - 0
sms_water/src/main/resources/mapper/AlarmSettingMapper.xml

@@ -22,6 +22,8 @@
         <result property="dateCreate" column="date_create" jdbcType="TIMESTAMP"/>
         <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
         <result property="dateUpdate" column="date_update" jdbcType="TIMESTAMP"/>
+        <result property="startTime" column="start_time" jdbcType="VARCHAR"/>
+        <result property="endTime" column="end_time" jdbcType="VARCHAR"/>
     </resultMap>
 
     <!-- 基本字段 -->

+ 38 - 25
sms_water/src/main/resources/mapper/OnlineMonitorMapper.xml

@@ -3,25 +3,6 @@
 <mapper namespace="com.huaxu.dao.OnlineMonitorMapper">
     <!-- 结果集 -->
     <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="monitorDataMap">
-        <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
-        <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
-        <result property="sceneTypeName" column="scene_type_name" jdbcType="VARCHAR"/>
-        <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
-        <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
-        <result property="address" column="address" jdbcType="VARCHAR"/>
-        <result property="sceneState" column="scene_state" jdbcType="INTEGER"/>
-        <collection property="MonitorDataEntities" ofType="com.huaxu.dto.MonitorDataDto" javaType="list">
-            <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
-            <result property="attributeId" column="attribute_id" jdbcType="INTEGER"/>
-            <result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
-            <result property="unit" column="unit" jdbcType="VARCHAR"/>
-            <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
-            <result property="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
-            <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
-            <result property="latestValue" column="latest_value" jdbcType="VARCHAR"/>
-        </collection>
-    </resultMap>
-    <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="monitorDataMap2">
         <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
         <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
         <result property="sceneTypeName" column="scene_type_name" jdbcType="VARCHAR"/>
@@ -39,6 +20,7 @@
             <result property="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
             <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
             <result property="latestValue" column="latest_value" jdbcType="VARCHAR"/>
+            <result property="alarmRange" column="alarm_range" jdbcType="VARCHAR"/>
         </collection>
     </resultMap>
     <!-- 设备结果集 -->
@@ -60,6 +42,7 @@
             <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
             <result property="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
             <result property="latestValue" column="latest_value" jdbcType="VARCHAR"/>
+            <result property="alarmRange" column="alarm_range" jdbcType="VARCHAR"/>
         </collection>
     </resultMap>
     <!-- 管网图层设备结果集 -->
@@ -80,6 +63,7 @@
                 <result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
                 <result property="unit" column="unit" jdbcType="VARCHAR"/>
                 <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
+                <result property="alarmRange" column="alarm_range" jdbcType="VARCHAR"/>
             </collection>
         </collection>
     </resultMap>
@@ -97,7 +81,8 @@
         t9.unit ,
         case when t5.attribute_id is  null then null when t6.id is null then 0 else 1 end is_alarm,
         t5.parm_type attribute_type,
-        if (t5.device_id is null, null, t4.device_code) device_code
+        if (t5.device_id is null, null, t4.device_code) device_code,
+        concat(t11.alarm_condition,cast(t11.alarm_value as char)+0) alarm_range
     </sql>
 
     <sql id="sceneDeviceJoins">
@@ -114,6 +99,7 @@
         left join sms_device_attribute t9 on t5.attribute_id=t9.id and t9.status = 1
         left join sms_alarm_details t6 on t6.scene_id=t2.scene_id and t6.device_id=t2.device_id
                   and t6.attribute_id=t5.attribute_id and t6.status = 1 and t6.state=1
+        left join sms_alarm_setting t11 on t6.alarm_setting_id=t11.id and t11.status = 1 and t11.alarm_condition!='='
     </sql>
 
     <sql id="sceneAlarmJoins">
@@ -223,7 +209,7 @@
         order by alalmCount desc
     </select>
     <!--查询地图悬浮数据-->
-    <select id="selectMapSuspension" resultMap="monitorDataMap2">
+    <select id="selectMapSuspension" resultMap="monitorDataMap">
         select
         <include refid="Base_Column_List"/>
         <if test="flag == null or flag ==0">
@@ -365,7 +351,7 @@
             and t5.parm_type in(3,4,5,6)
         </if>
         <if test="type == 2 ">
-            and t5.parm_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
+            and t5.parm_type in(2,3,4,5,6,7,8,9,10,11,12,13,14,20)
         </if>
         <if test="type == 5 ">
             and t5.parm_type in(3,4,12,13,14)
@@ -455,7 +441,7 @@
     <!--查询设备地图参数数据-->
     <select id="selectDeviceMapParam" resultMap="deviceDataMap">
         select distinct t1.id device_id,t1.device_code,t1.device_name,t1.point_x,point_y,t1.address,t2.attribute_id, ifnull(t2.remark, t3.`name`) attribute_name,t3.unit,
-         t2.seq,case when t2.attribute_id is  null then null when t6.id is null then 0 else 1 end is_alarm
+         t2.seq,case when t2.attribute_id is  null then null when t6.id is null then 0 else 1 end is_alarm,concat(t11.alarm_condition,cast(t11.alarm_value as char)+0) alarm_range
         <if test="flag == null or flag ==0">
             ,if (t4.alarm_count>0, 1, 0) device_state
         </if>
@@ -477,6 +463,7 @@
             from sms_alarm_details a1 where a1.device_id= #{deviceId} and a1.`status` = 1 and a1.state = 1
         )t4 on t4.device_id=t1.id
         left join sms_alarm_details t6 on t6.device_id=t1.id and t6.attribute_id=t2.attribute_id and t6.status = 1 and t6.state=1
+        left join sms_alarm_setting t11 on t6.alarm_setting_id=t11.id and t11.status = 1 and t11.alarm_condition!='='
         where t1. status = 1 and t1. enable_state = 1 and t1.id= #{deviceId}
         order by t2.seq
     </select>
@@ -647,8 +634,8 @@
     </select>
     <!--查询管网地图图层及设备-->
     <select id="selectPipeNetLayer" resultMap="layerMap">
-        select t4.id scene_id,t4.scene_name,t5.scene_type_name,t6.id device_id,t6.device_code,t6.device_name,t6.point_x,t6.point_y,t6.address
-        ,t8.attribute_id ,ifnull(t8.remark, t9.`name`) attribute_name,t9.unit,case when t8.attribute_id is  null then null when t10.id is null then 0 else 1 end is_alarm
+        select t4.id scene_id,t4.scene_name,t5.scene_type_name,t6.id device_id,t6.device_code,t6.device_name,t6.point_x,t6.point_y,t6.address,concat(t11.alarm_condition,cast(t11.alarm_value as char)+0) alarm_range
+        ,t8.attribute_id ,ifnull(t8.remark, t9.`name`) attribute_name,t9.unit,case when t8.attribute_id is null then null when t10.id is null then 0 else 1 end is_alarm
         <if test="flag == null or flag ==0">
             ,if (t7.alarm_count>0, 1, 0) device_state
         </if>
@@ -671,6 +658,7 @@
         left join sms_device_parm t8 on t8.scene_id = t2.scene_id and t8.device_id=t2.device_id and t8. status = 1 and t8.is_suspension = 1
         left join sms_device_attribute t9 on t8.attribute_id=t9.id and t9.status = 1
         left join sms_alarm_details t10 on t10.scene_id=t2.scene_id and t10.device_id=t2.device_id and t10.attribute_id=t8.attribute_id and t10.status = 1 and t10.state=1
+        left join sms_alarm_setting t11 on t10.alarm_setting_id=t11.id and t11.status = 1 and t11.alarm_condition!='='
         where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1 and t3.scene_type_name = '管网'
         <choose>
             <when test="sceneTypeName != null and sceneTypeName !=''">
@@ -828,4 +816,29 @@
         </if>
         order by t4.scene_name,t8.seq
     </select>
+    <!--查询场景实时状态数量-->
+    <select id="selectStateCount" resultType="java.util.Map">
+        select sceneState,count(1) sceneCount
+        from(
+            select case when t7.offline_alarm_count=t10.setting_device_count then 2
+                    when t7.alarm_count>0 or t7.offline_alarm_count>0 then 1 else 0 end sceneState
+            from sms_scene t1
+            inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
+            <include refid="sceneAlarmJoins"/>
+            where t1.parent_scene_id = 0 and t1. status = 1 and t1. enable_state = 1
+            <if test="sceneTypeName != null and sceneTypeName != ''">
+                and t3.scene_type_name = #{sceneTypeName}
+            </if>
+            <if test="sceneIds != null and sceneIds.size() > 0">
+                and t1.id  in
+                <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="sceneIds == null or sceneIds.size() == 0">
+                and t1.id is null
+            </if>
+        )tab1
+        group by sceneState
+    </select>
 </mapper>

+ 31 - 0
user_auth/src/main/java/com/huaxu/config/SsoConfig.java

@@ -0,0 +1,31 @@
+package com.huaxu.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
+
+/**
+ * @ClassName SsoConfig
+ * @Description: 单点登录相关配置
+ * @Author lihui
+ * @Date 2021/4/9
+ * @Version V1.0
+ **/
+@Data
+@Configuration
+@Component
+public class SsoConfig {
+
+    // 根据账户获取密码
+    @Value("${sso.xieding.get.pwd.url}")
+    private String pwdUrl;
+
+    // 绑定单点登陆用户
+    @Value("${sso.xieding.bind.single.url}")
+    private String bindSingleUrl;
+
+    // 获取token
+    @Value("${sso.xieding.get.token.url}")
+    private String tokenUrl;
+}

+ 43 - 0
user_auth/src/main/java/com/huaxu/controller/ThirdPartyLoginController.java

@@ -0,0 +1,43 @@
+package com.huaxu.controller;
+
+
+import com.huaxu.dto.thirdparty.LoginQueryDto;
+import com.huaxu.exception.ServiceException;
+import com.huaxu.model.AjaxMessage;
+import com.huaxu.model.ResultStatus;
+import com.huaxu.service.ThirdPartyLoginService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * @ClassName ThirdPartyLoginController
+ * @Description: 第三方登录登录业务处理
+ * @Author lihui
+ * @Date 2021/4/7
+ * @Version V1.0
+ **/
+@RestController
+@RequestMapping("/third/party/login")
+@Api(tags = "第三方登录")
+public class ThirdPartyLoginController {
+
+    @Autowired
+    private ThirdPartyLoginService xiedingLoginService;
+
+    @RequestMapping(value = "/getXieDingToken", method = RequestMethod.POST)
+    @ApiOperation(value = "获取协鼎登录的token")
+    public AjaxMessage<String> getXieDingToken(@ApiParam(value = "获取token信息", required = true) @RequestBody LoginQueryDto queryDto) {
+       try {
+           return new AjaxMessage<>(ResultStatus.OK, xiedingLoginService.getToken(queryDto));
+        } catch (ServiceException e) {
+           return new AjaxMessage<>(e.getStatus(), e.getMessage(), null);
+        }
+    }
+}

+ 2 - 0
user_auth/src/main/java/com/huaxu/dao/UserMapper.java

@@ -112,4 +112,6 @@ public interface UserMapper {
     String getAppSecret(String appId);
 
     void updateUniqueUserID(@Param("id")Integer id, @Param("uid") String uid);
+
+    User findThirdPartytLoginInfo(String tenantId, String phone);
 }

+ 19 - 0
user_auth/src/main/java/com/huaxu/dto/thirdparty/LoginQueryDto.java

@@ -0,0 +1,19 @@
+package com.huaxu.dto.thirdparty;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+
+/**
+ * @ClassName LoginQueryDto
+ * @Description: 第三方登录查询实体
+ * @Author lihui
+ * @Date 2021/4/7
+ * @Version V1.0
+ **/
+@Data
+public class LoginQueryDto {
+
+    @ApiModelProperty(value="菜单ID")
+    private int menuId;
+}

+ 24 - 0
user_auth/src/main/java/com/huaxu/dto/thirdparty/XieDingResultDto.java

@@ -0,0 +1,24 @@
+package com.huaxu.dto.thirdparty;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+
+@Data
+public class XieDingResultDto {
+
+    @ApiModelProperty(value="状态")
+    private boolean status;
+
+    @ApiModelProperty(value="消息")
+    private String  msg;
+
+    @ApiModelProperty(value="密码")
+    private String password;
+
+    @ApiModelProperty(value="singleKey")
+    private String singleKey;
+
+    @ApiModelProperty(value="token")
+    private String token;
+}

+ 12 - 0
user_auth/src/main/java/com/huaxu/entity/User.java

@@ -104,4 +104,16 @@ public class User implements Serializable {
     private String iotPhoneNumber;
     private String customerId;
 
+    @ApiModelProperty(value = "登录第三方账号")
+    private String loginAccount;
+
+    @ApiModelProperty(value = "登录第三方密钥")
+    private String loginSecretKey;
+
+    @ApiModelProperty(value = "登录第三方厂家编码")
+    private String loginCode;
+
+    @ApiModelProperty(value = "登录第三方机构编码")
+    private String loginOrgCode;
+
 }

+ 15 - 0
user_auth/src/main/java/com/huaxu/service/ThirdPartyLoginService.java

@@ -0,0 +1,15 @@
+package com.huaxu.service;
+
+import com.huaxu.dto.thirdparty.LoginQueryDto;
+
+public interface ThirdPartyLoginService {
+
+    /**
+    * @Author lihui
+    * @Description 获取登录需要的token
+    * @Date 16:39 2021/4/7
+    * @Param []
+    * @return java.lang.String
+    **/
+    String getToken(LoginQueryDto dto);
+}

+ 79 - 0
user_auth/src/main/java/com/huaxu/service/impl/thirdparty/XiedingLoginServiceImpl.java

@@ -0,0 +1,79 @@
+package com.huaxu.service.impl.thirdparty;
+
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.nacos.client.config.utils.MD5;
+import com.alibaba.nacos.common.util.Md5Utils;
+import com.huaxu.config.SsoConfig;
+import com.huaxu.dao.UserMapper;
+import com.huaxu.dto.thirdparty.LoginQueryDto;
+import com.huaxu.dto.thirdparty.XieDingResultDto;
+import com.huaxu.entity.User;
+import com.huaxu.exception.ServiceException;
+import com.huaxu.model.LoginUser;
+import com.huaxu.model.ResultStatus;
+import com.huaxu.service.ThirdPartyLoginService;
+import com.huaxu.util.HttpClientPoolUtil;
+import com.huaxu.util.MD5Util;
+import com.huaxu.util.UserUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.nio.charset.Charset;
+
+/**
+ * @ClassName XiedingLoginServiceImpl
+ * @Description: 协鼎单点登录业务处理
+ * @Author lihui
+ * @Date 2021/4/7
+ * @Version V1.0
+ **/
+@Service("xiedingLoginService")
+public class XiedingLoginServiceImpl implements ThirdPartyLoginService {
+
+
+    @Autowired
+    private SsoConfig ssoConfig;
+
+    @Autowired
+    private UserMapper userMapper;
+
+    @Override
+    public String getToken(LoginQueryDto queryDto) {
+        String httpIpPortUrl  = "http://www.xdwater365.com/yhfw/security/security";
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        User user = userMapper.findThirdPartytLoginInfo(currentUser.getTenantId(), currentUser.getPhoneNumber());
+        if (user == null || StringUtils.isEmpty(user.getLoginAccount())){
+            throw new ServiceException(ResultStatus.ERROR.getStatus(), "未设置登录账号");
+        }
+        // 登录账号、登录密钥、厂家编码、机构编码
+        String account   = user.getLoginAccount();
+        String secretKey = user.getLoginSecretKey();
+        String code      = user.getLoginCode();
+        String orgCode   = user.getLoginOrgCode();
+        Charset charset  = Charset.forName("utf-8");
+        // 1.根据账户获取密码
+        String result = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getPwdUrl(), httpIpPortUrl, account, orgCode), charset);
+        XieDingResultDto resultDto = JSONObject.parseObject(result, XieDingResultDto.class);
+        if (StringUtils.isEmpty(resultDto.getPassword())) {
+            throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMsg());
+        }
+        // 2.绑定单点登陆用户
+        result    = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getBindSingleUrl(), httpIpPortUrl, account, resultDto.getPassword(), orgCode), charset);
+        resultDto = JSONObject.parseObject(result, XieDingResultDto.class);
+        if (!resultDto.isStatus()) {
+            throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMsg());
+        }
+        // 3.获取token
+        String singleKey = resultDto.getSingleKey();
+        Long timestamp   = System.currentTimeMillis();
+        String sign      = MD5Util.digest(resultDto.getSingleKey() + timestamp + secretKey);
+        result    = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getTokenUrl(), httpIpPortUrl, singleKey, timestamp, sign, code), charset);
+        resultDto = JSONObject.parseObject(result, XieDingResultDto.class);
+        if (!resultDto.isStatus()) {
+            throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMsg());
+        }
+        return resultDto.getToken();
+    }
+
+}

+ 320 - 0
user_auth/src/main/java/com/huaxu/util/HttpClientPoolUtil.java

@@ -0,0 +1,320 @@
+package com.huaxu.util;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.SocketTimeoutException;
+import java.nio.charset.Charset;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Slf4j
+public class HttpClientPoolUtil {
+
+    private static HttpClient httpClient = null;
+
+    public static synchronized HttpClient getHttpClient() {
+        if (httpClient == null) {
+            httpClient = createHttpClient(100, 20, 10000, 3000, 3000);
+        }
+        return httpClient;
+    }
+
+    /**
+     * 实例化HttpClient
+     */
+    public static HttpClient createHttpClient(int maxTotal, int maxPerRoute, int socketTimeout,
+        int connectTimeout,
+        int connectionRequestTimeout) {
+        RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout)
+            .setConnectTimeout(connectTimeout).setConnectionRequestTimeout(connectionRequestTimeout)
+            .build();
+        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
+        cm.setMaxTotal(maxTotal);
+        cm.setDefaultMaxPerRoute(maxPerRoute);
+        CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm)
+            .setDefaultRequestConfig(defaultRequestConfig).build();
+        return httpClient;
+    }
+
+
+    /**
+     * 发送post请求
+     *
+     * @param url 请求地址
+     * @param params 请求参数
+     * @param encoding 编码
+     */
+    public static String sendPost(String url, Map<String, String> params, Charset encoding) {
+        String resp = "";
+        HttpPost httpPost = new HttpPost(url);
+        if (params != null && params.size() > 0) {
+            List<NameValuePair> formParams = new ArrayList<NameValuePair>();
+            Iterator<Entry<String, String>> itr = params.entrySet().iterator();
+            while (itr.hasNext()) {
+                Entry<String, String> entry = itr.next();
+                formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
+            }
+            UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formParams, encoding);
+            httpPost.setEntity(postEntity);
+        }
+        CloseableHttpResponse response = null;
+        try {
+            response = (CloseableHttpResponse) getHttpClient().execute(httpPost);
+            resp = EntityUtils.toString(response.getEntity(), encoding);
+        } catch (Exception e) {
+            log.error("httpClient pool error === [" + url + "]> ", e);
+        } finally {
+            if (response != null) {
+                try {
+                    response.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return resp;
+    }
+
+    /**
+     * 发送post请求
+     *
+     * @param url 请求地址
+     * @param params 请求参数
+     * @param encoding 编码
+     */
+    public static String sendPost(String url, Map<String, String> params,
+        Map<String, String> headerMap, Charset encoding) {
+        String resp = "";
+        HttpPost httpPost = new HttpPost(url);
+
+        // 添加请求参数
+        if (isNotEmpty(params)) {
+            List<NameValuePair> formParams = new ArrayList<NameValuePair>();
+            Iterator<Entry<String, String>> itr = params.entrySet().iterator();
+            while (itr.hasNext()) {
+                Entry<String, String> entry = itr.next();
+                formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
+            }
+            UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formParams, encoding);
+            httpPost.setEntity(postEntity);
+        }
+
+        // 添加头部参数
+        if (isNotEmpty(headerMap)) {
+            Iterator<Entry<String, String>> iter = headerMap.entrySet().iterator();
+            while (iter.hasNext()) {
+                Entry<String, String> element = (Entry<String, String>) iter
+                    .next();
+                httpPost.addHeader(element.getKey(), element.getValue());
+            }
+        }
+
+        CloseableHttpResponse response = null;
+        try {
+            response = (CloseableHttpResponse) getHttpClient().execute(httpPost);
+            resp = EntityUtils.toString(response.getEntity(), encoding);
+        } catch (SocketTimeoutException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            log.error("httpClient pool error === [" + url + "]> ", e);
+        } finally {
+            if (response != null) {
+                try {
+                    response.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return resp;
+    }
+
+    /**
+     * @Description 发送post json参数
+     */
+    public static String sendPost(String url, String json, Charset encoding) {
+        String resp = "";
+        CloseableHttpResponse response = null;
+        HttpPost httpPost = new HttpPost(url);
+        if (StringUtils.isNotEmpty(json)) {
+            try {
+                StringEntity se = new StringEntity(json);
+
+                se.setContentType("text/json");
+
+                se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
+                httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
+                httpPost.addHeader("Connection", "close");
+                httpPost.setEntity(se);
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+        }
+        try {
+            response = (CloseableHttpResponse) getHttpClient().execute(httpPost);
+            resp = EntityUtils.toString(response.getEntity(), encoding);
+        } catch (Exception e) {
+            log.error("httpClient pool error === [" + url + "=" + json + "]> ", e);
+        } finally {
+            if (response != null) {
+                try {
+                    response.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return resp;
+    }
+
+    /**
+     * @Description 发送post json参数
+     */
+    public static String sendPost(String url, String json, Charset encoding, String contentType) {
+        String resp = "";
+        CloseableHttpResponse response = null;
+        HttpPost httpPost = new HttpPost(url);
+        if (StringUtils.isNotEmpty(json)) {
+            StringEntity se = new StringEntity(json, "utf-8");
+            se.setContentType("text/json");
+            if (StringUtils.isBlank(contentType)) {//默认 请求
+                httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json;charset=utf-8");
+            } else {
+                httpPost.addHeader(HTTP.CONTENT_TYPE, contentType);
+            }
+            httpPost.addHeader("Connection", "close");
+            httpPost.setEntity(se);
+        }
+        try {
+            response = (CloseableHttpResponse) getHttpClient().execute(httpPost);
+            resp = EntityUtils.toString(response.getEntity(), encoding);
+        } catch (Exception e) {
+            log.error("httpClient pool error === [" + url + "=" + json + "]> ", e);
+        } finally {
+            if (response != null) {
+                try {
+                    response.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return resp;
+    }
+
+
+    /**
+     * @Description 发送post json参数
+     */
+    public static String sendGet(String url, Charset encoding) {
+        String resp = "";
+        CloseableHttpResponse response = null;
+        HttpGet httpPost = new HttpGet(url);
+        try {
+            httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
+            httpPost.addHeader("Connection", "close");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        try {
+            response = (CloseableHttpResponse) getHttpClient().execute(httpPost);
+            resp = EntityUtils.toString(response.getEntity(), encoding);
+        } catch (Exception e) {
+            log.error("httpClient pool error === [" + url + "]> ", e);
+        } finally {
+            if (response != null) {
+                try {
+                    response.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return resp;
+    }
+
+
+    public static String sendGetReferer(String url, Charset encoding, String referer) {
+
+        String resp = "";
+
+        CloseableHttpResponse response = null;
+
+        HttpGet httpPost = new HttpGet(url);
+
+        try {
+            httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
+            httpPost.addHeader("Connection", "close");
+            httpPost.setHeader("referer", referer);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        try {
+            response = (CloseableHttpResponse) getHttpClient().execute(httpPost);
+            resp = EntityUtils.toString(response.getEntity(), encoding);
+        } catch (Exception e) {
+            log.error("httpClient pool error === [" + url + "]> ", e);
+        } finally {
+            if (response != null) {
+                try {
+                    response.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return resp;
+    }
+
+
+    private static boolean isNotEmpty(Map<String, String> headerMap) {
+        if (headerMap == null || headerMap.size() == 0) {
+            return false;
+        }
+        return true;
+    }
+
+    public static Long timeToSecond() {
+        String dateStr = "1970-1-1 08:00:00";
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long aftertime = 0;
+        try {
+            Date miDate = sdf.parse(dateStr);
+            long d1time = System.currentTimeMillis() / 1000;
+            long t1time = miDate.getTime() / 1000;
+            aftertime = d1time - t1time;
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return aftertime;
+
+    }
+
+}

+ 4 - 1
user_auth/src/main/resources/application-dev.properties

@@ -79,5 +79,8 @@ dispath.routing.key=dipathKey
 iot.url=http://localhost:8090
 
 
-
+#µ¥µãµÇ¼µÚÈý·½ÇëÇóurl
+sso.xieding.get.pwd.url=%s!getSingleLandUser.action?account=%s&orgCode=%s
+sso.xieding.bind.single.url=%s!bindingSingleLandUser.action?account=%s&password=%s&orgCode=%s
+sso.xieding.get.token.url=%s!createSingleLandToken.action?singleKey=%s&timestamp=%s&signatrue=%s&code=%s
 

+ 4 - 0
user_auth/src/main/resources/mapper/UserMapper.xml

@@ -341,4 +341,8 @@
     <update id="updateUniqueUserID">
         update uims_user set uniq_id=#{uid} where id=#{id}
     </update>
+
+    <select id="findThirdPartytLoginInfo" resultType="com.huaxu.entity.User">
+        select login_account loginAccount,login_secret_key loginSecretKey,login_code loginCode,login_org_code loginOrgCode from uims_user  where  TENANT_ID =#{tenantId} and PHONE = #{phone}
+    </select>
 </mapper>