Browse Source

1.用户登录跟UAS同步

heqinwei 7 years ago
parent
commit
b8f697627d

+ 6 - 0
pom.xml

@@ -61,6 +61,12 @@
       <version>3.1.0</version>
     </dependency>
 
+    <dependency>
+      <groupId>com.github.kevinsawicki</groupId>
+      <artifactId>http-request</artifactId>
+      <version>5.6</version>
+    </dependency>
+
     <!--dao -->
       <dependency>
           <groupId>org.mybatis.spring.boot</groupId>

+ 2 - 2
src/main/java/com/controller/user/UserController.java

@@ -24,9 +24,9 @@ public class UserController {
      */
     @RequestMapping("/login")
     public RepEntity login(@RequestBody LoginInfo body){
-//        String url = "http://10.1.1.168:8099/ERP/common/login.action?username=u0783&password=1111qqqq&language=undefined&sob=N_USOFTSYS";
-
+//        userService.login(body);
         return userService.login(body);
+//        return new RepEntity(RepCode.success);
     }
 
     /*

+ 6 - 6
src/main/java/com/dao/chart/ChartsConfigMapper.java

@@ -22,7 +22,7 @@ public interface ChartsConfigMapper {
             "VALUES (#{chartId},#{chartName},#{chartType}, #{dataId}, #{chartConfig}, #{groupBy}, #{accessAuthority}, #{updateAuthority}, #{chartsGroup}," +
             "#{describes},#{style}, #{createBy},to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'),  #{chartOption}, #{createId}, #{fetchConfig})" )
 //    @Options(useGeneratedKeys=false, keyProperty = "chartId",keyColumn = "id")
-    @SelectKey(before=true,keyProperty="chartId",resultType=Integer.class,statement="SELECT charts_squence.nextval from dual",keyColumn = "id")
+    @SelectKey(before=true,keyProperty="chartId",resultType=Integer.class,statement="SELECT bi_charts_sequence.nextval from dual",keyColumn = "id")
     void insertCharts(ChartConfig chartConfig);
 
     @Delete("<script>" +
@@ -63,7 +63,7 @@ public interface ChartsConfigMapper {
             "          select bo1.BO_ST_ID from bi_db_object bo1 " +
             "            where bo1.BO_TYPE = '0' and bo1.BO_OB_ID in ( select BR_USER_GROUP from BI_USER_REL_GROUPS where BR_USER_ID=#{id} ) " +
             "            or bo1.bo_type = '1' and bo1.bo_ob_id = #{id}" +
-            "        )" +
+            "        ) and bs1.BS_DB_ID = bc.BD_DATA_ID" +
             "    ) > 0 then '1'" +
             "    when bc.CREATE_ID = #{id} and bc.BD_DATA_ID not in (select id from bi_data_connectors where create_id=#{id}) and (" +
             "      select count(1) from BI_DB_STRATEGYS bs2 " +
@@ -71,7 +71,7 @@ public interface ChartsConfigMapper {
             "          select bo2.BO_ST_ID from bi_db_object bo2 " +
             "            where bo2.BO_TYPE = '0' and bo2.BO_OB_ID in ( select BR_USER_GROUP from BI_USER_REL_GROUPS where BR_USER_ID=#{id} ) " +
             "            or bo2.bo_type = '1' and bo2.bo_ob_id = #{id}" +
-            "        )" +
+            "        ) and bs2.BS_DB_ID = bc.BD_DATA_ID" +
             "    ) = 0 then '0' " +
             "    when bc.CREATE_ID != #{id} and bc.BD_DATA_ID in (select bdc1.id " +
             " from bi_data_connectors bdc1 where bdc1.create_id=bc.CREATE_ID) then '1'" +
@@ -84,7 +84,7 @@ public interface ChartsConfigMapper {
             "          select bo2.BO_ST_ID from bi_db_object bo2 " +
             "            where bo2.BO_TYPE = '0' and bo2.BO_OB_ID in ( select BR_USER_GROUP from BI_USER_REL_GROUPS where BR_USER_ID=bc.CREATE_ID ) " +
             "            or bo2.bo_type = '1' and bo2.bo_ob_id = bc.CREATE_ID" +
-            "        )" +
+            "        ) and bs2.BS_DB_ID = bc.BD_DATA_ID" +
             "    ) > 0 then '1'" +
             "    when bc.CREATE_ID != #{id} and bc.BD_DATA_ID not in (select bdc3.id " +
             " from bi_data_connectors bdc3 where bdc3.create_id=bc.CREATE_ID) and (" +
@@ -93,7 +93,7 @@ public interface ChartsConfigMapper {
             "          select bo2.BO_ST_ID from bi_db_object bo2 " +
             "            where bo2.BO_TYPE = '0' and bo2.BO_OB_ID in ( select BR_USER_GROUP from BI_USER_REL_GROUPS where BR_USER_ID=bc.CREATE_ID ) " +
             "            or bo2.bo_type = '1' and bo2.bo_ob_id = bc.CREATE_ID" +
-            "        )" +
+            "        ) and bs2.BS_DB_ID = bc.BD_DATA_ID" +
             "    ) = 0 then '0'" +
             "    else null end authority, case when bc.BD_DATA_ID not in(select id from bi_data_connectors) then '1' else '0' end dbStatus, bc.id as chartId, bc.chart_name as chartName, bc.chart_type as chartType, bc.create_by as createBy, bc.create_date as createDate" +
             "    ,bc.bc_filters as filters, bc.CHART_DESCRIBES as describes, bc.bc_charts_group as chartsGroup, bc.bc_charts_option as chartOption ,bc.bd_data_id as dataId,bd.data_name as dataName, bc.create_id as createId  " +
@@ -172,7 +172,7 @@ public interface ChartsConfigMapper {
     */
     @Insert("insert into bi_charts_group(bc_id, bc_group_name, bc_index, bc_father_id, create_date)" +
             "values(#{id}, #{groupName}, #{groupIndex}, #{fatherId}, to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'))")
-    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_charts_group_squence.nextval from dual",keyColumn = "bc_id")
+    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT BI_CHARTS_GROUP_SEQUENCE.nextval from dual",keyColumn = "bc_id")
     void setChartsGroup(GroupInfo group);
 
     /*

+ 7 - 0
src/main/java/com/dao/chart/ShowChartsMapper.java

@@ -121,6 +121,13 @@ public interface ShowChartsMapper {
                         @Param("operation") String operation, @Param("screen") String screen);
 
     /*
+   总体未分组
+    */
+    @Select("select ${operation}(${columnName}) from ${tableName} ${screen}")
+    Double getColumnData(@Param("tableName") String tableName, @Param("columnName") String columnName,
+                        @Param("operation") String operation, @Param("screen") String screen);
+
+    /*
     取主键名称
      */
     @Select("select column_name from user_cons_columns where table_name = #{tableName} and constraint_name = #{tableKey}")

+ 2 - 2
src/main/java/com/dao/dashboard/DashboardsMapper.java

@@ -20,7 +20,7 @@ public interface DashboardsMapper {
             "bi_dashboards(id, bd_name,bd_note,CONFIGURATION,create_by,create_date, BD_THUMBNAIL,relation_columns, create_id)" +
             "values(#{id}, #{bdName},#{bdNote},#{bdConfiguration},#{createBy}," +
             "to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'), #{thumbnail},#{relationColumns}, #{createId})")
-    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT bi_dashboards_squence.nextval from dual",keyColumn = "id")
+    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT BI_DASHBOARDS_SEQUENCE.nextval from dual",keyColumn = "id")
     void setDashboards(Dashboards dashboards);
 
     /*
@@ -100,7 +100,7 @@ public interface DashboardsMapper {
      */
     @Insert("insert into bi_dashboards_object(bo_id, bo_da_id, bo_type, bo_ob_id) values" +
             "(#{id}, #{daId}, #{objectType}, #{obId})")
-    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_dashboards_object_squence.nextval from dual",keyColumn = "bo_id")
+    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT BI_DASHBOARDS_OBJECT_SEQUENCE.nextval from dual",keyColumn = "bo_id")
     void addObject(@Param("daId") int daId, @Param("objectType") String objectType, @Param("obId") int obId);
 
     /*

+ 3 - 3
src/main/java/com/dao/dataSource/DataConnectorMapper.java

@@ -63,7 +63,7 @@ public interface DataConnectorMapper {
      */
     @Insert("INSERT INTO bi_data_connectors(id,data_name,data_note,data_tag,con_type,LOAD_OBJECT,DB_CONFIG,columns_config,used_number,create_by,create_date, table_name, BD_GROUP, create_id) " +
             "VALUES (#{dataId},#{dataName}, #{note}, #{dataTag}, #{type}, #{loadObject}, #{dbConfig},#{columnConfig}, #{usedNumber},#{createBy}, to_date(#{createDate},'YYYY-MM-DD hh24:mi:ss'), #{tableName}, #{connectorGroup},#{createId})")
-    @SelectKey(before=true,keyProperty="dataId",resultType=int.class,statement="SELECT BI_DASHBOARDS_squence.nextval from dual",keyColumn = "id")
+    @SelectKey(before=true,keyProperty="dataId",resultType=int.class,statement="SELECT bi_data_connectors_sequence.nextval from dual",keyColumn = "id")
     void insertDataConnector(DataConnector dataConnector);
 
     /*
@@ -111,7 +111,7 @@ public interface DataConnectorMapper {
      */
     @Insert("insert into BI_DATABASES(id,ADDRASS, CREATE_DATE, DATABASE_TYPE, DATA_NAME, bases_NAME, PASS_WORD, PORT, USER_NAME, note)" +
             "values(#{id},#{addrass}, to_date(#{createDate},'YYYY-MM-DD hh24:mi:ss'), #{databaseType}, #{dataName}, #{name}, #{passWord}, #{port}, #{userName}, #{note})")
-    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_databases_squence.nextval from dual",keyColumn = "id")
+    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT BI_DATABASES_SEQUENCE.nextval from dual",keyColumn = "id")
     void inputDataBases(Databases databases);
 
     /*
@@ -182,7 +182,7 @@ public interface DataConnectorMapper {
      */
     @Insert("insert into bi_base_group_by(bb_id, bb_group_name, bb_index, bb_father_id, create_date)" +
             "values(#{id}, #{groupName}, #{groupIndex}, #{fatherId}, to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'))")
-    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_base_group_by_squence.nextval from dual",keyColumn = "bb_id")
+    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT BI_BASE_GROUP_BY_SEQUENCE.nextval from dual",keyColumn = "bb_id")
     void setConnectorGroup(GroupInfo group);
 
     /*

+ 2 - 2
src/main/java/com/dao/strategy/StrategysBdMapper.java

@@ -17,7 +17,7 @@ public interface StrategysBdMapper {
     @Insert("insert into bi_db_strategys(bs_id, bs_db_id, bs_rule,rule_str, bs_name, is_open, create_date) values" +
             "(#{id}, #{tarId}, #{rule}, #{ruleStr}, #{name}, #{isOpen}, " +
             "to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'))")
-    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_db_strategys_squence.nextval from dual",keyColumn = "bs_id")
+    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT BI_DB_STRATEGYS_SEQUENCE.nextval from dual",keyColumn = "bs_id")
     void addStrategys(Strategys strategys);
 
     /*
@@ -87,7 +87,7 @@ public interface StrategysBdMapper {
      */
     @Insert("insert into bi_db_object(bo_id, bo_st_id, bo_type, bo_ob_id) values" +
             "(#{id}, #{stId}, #{objectType}, #{obId})")
-    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_db_object_squence.nextval from dual",keyColumn = "bo_id")
+    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT BI_DB_OBJECT_SEQUENCE.nextval from dual",keyColumn = "bo_id")
     void addObject(@Param("stId") int stId, @Param("objectType") String objectType, @Param("obId") int obId);
 
 

+ 1 - 1
src/main/java/com/dao/strategy/StrategysChartMapper.java

@@ -87,7 +87,7 @@ public interface StrategysChartMapper {
      */
     @Insert("insert into bi_chart_object(bo_id, bo_st_id, bo_type, bo_ob_id) values" +
             "(#{id}, #{stId}, #{objectType}, #{obId})")
-    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_chart_object_squence.nextval from dual",keyColumn = "bo_id")
+    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT BI_CHART_OBJECT_SEQUENCE.nextval from dual",keyColumn = "bo_id")
     void addObject(@Param("stId") int stId, @Param("objectType") String objectType, @Param("obId") int obId);
 
 

+ 1 - 1
src/main/java/com/dao/user/RecordMapper.java

@@ -18,7 +18,7 @@ public interface RecordMapper {
      */
     @Insert("insert into bi_record(bre_id, bre_type, bre_user_id, re_date, item_id) " +
             "values(#{id}, #{type}, #{userId}, to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'), #{itemId})")
-    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT bi_record_squence.nextval from dual",keyColumn = "bre_id")
+    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT BI_RECORD_SEQUENCE.nextval from dual",keyColumn = "bre_id")
     void inputRecord(@Param("type") String type, @Param("userId") int userId, @Param("itemId") int itemId);
 
     /*

+ 38 - 2
src/main/java/com/dao/user/UserMapper.java

@@ -11,6 +11,36 @@ import java.util.List;
 @Repository
 public interface UserMapper {
 
+    /*
+    新增一条用户数据
+     */
+    @Insert("insert into bi_users(bu_id, bu_name, BU_POST, USER_NAME, PASS_WORD, BU_DEPARTMENT, CREATE_DATE) values" +
+            "(#{id}, #{name}, #{post}, #{userName}, #{passWord}, #{department}, to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'))")
+    @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_users_sequence.nextval from dual",keyColumn = "bu_id")
+    void addUser(User user);
+
+    /*
+    更新用户数据
+     */
+    @Update("<script>" +
+            "UPDATE bi_users set" +
+            "USER_NAME = #{userName}" +
+            "<if test=\"passWord != null\"> , PASS_WORD = #{passWord} </if>" +
+            " <if test=\"name != null\"> , bu_name = #{name} </if>" +
+            " <if test=\"post != null\"> , BU_POST = #{post} </if>" +
+            " <if test=\"department != null\"> , BU_DEPARTMENT = #{department} </if>" +
+            " ,updata_date = to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss')" +
+            "  where bc_id = #{id}" +
+            " </script>")
+    void updateUser(User user);
+
+    /*
+    查询uas用户信息
+     */
+    @Select("select EM_DEFAULTHSNAME as department, EM_DEPART as post, EM_NAME as name, em_password as passWord," +
+            " em_mobile as phone, em_code as userName from EMPLOYEE where ${column} = #{userName}")
+    User getUserMess(@Param("userName") String userName, @Param("column") String column);
+
     /*
     获取用户信息
      */
@@ -19,6 +49,12 @@ public interface UserMapper {
             "from bi_users where user_name = #{userName}")
     User getLogin(String userName);
 
+    /*
+    查询bi系统是否存在该用户
+     */
+    @Select("select bu_name as name from bi_users where user_name = #{userName}")
+    String getUserName(String userName);
+
     /*
     通过ID获取名称
      */
@@ -51,7 +87,7 @@ public interface UserMapper {
      */
     @Insert("insert into bi_user_groups(bg_id, bg_name, bg_note, create_date) values(#{id}, #{userGroupName}, #{userGroupNote}, " +
             "to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'))")
-    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT bi_user_groups_squence.nextval from dual",keyColumn = "bg_id")
+    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT BI_USER_GROUPS_SEQUENCE.nextval from dual",keyColumn = "bg_id")
     void insUserGroup(UserGroup userGroup);
 
     /*
@@ -90,7 +126,7 @@ public interface UserMapper {
     添加用户到用户组
      */
     @Insert("insert into bi_user_rel_groups(br_id, br_user_id, br_user_group) values(#{id}, #{userId}, #{userGroupId})")
-    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT bi_user_rel_groups_squence.nextval from dual",keyColumn = "br_id")
+    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT BI_USER_REL_GROUPS_SEQUENCE.nextval from dual",keyColumn = "br_id")
 //    void setUserInto(@Param("userId") int userId, @Param("userGroupId") int userGroupId);
     void setUserInto(@Param("userId") int userId, @Param("userGroupId") int userGroupId);
 

+ 30 - 0
src/main/java/com/model/bo/LoginResult.java

@@ -0,0 +1,30 @@
+package com.model.bo;
+
+public class LoginResult {
+    private String em_name;
+    private String success;
+
+    public String getEm_name() {
+        return em_name;
+    }
+
+    public void setEm_name(String em_name) {
+        this.em_name = em_name;
+    }
+
+    public String getSuccess() {
+        return success;
+    }
+
+    public void setSuccess(String success) {
+        this.success = success;
+    }
+
+    @Override
+    public String toString() {
+        return "LoginResult{" +
+                "em_name='" + em_name + '\'' +
+                ", success='" + success + '\'' +
+                '}';
+    }
+}

+ 9 - 0
src/main/java/com/model/po/User.java

@@ -10,9 +10,18 @@ public class User {
     private String department;
     private String post;
     private String role;
+    private String phone;
     private Date createDate;
     private Date updateDate;
 
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+
     public int getId() {
         return id;
     }

+ 1 - 0
src/main/java/com/model/vo/configVo/PopulationInfo.java

@@ -11,6 +11,7 @@ public class PopulationInfo {
     private List<String> groupByList;
     private List<Screen> filters;
 
+
     public int getId() {
         return id;
     }

+ 2 - 2
src/main/java/com/server/chart/ShowPopulationService.java

@@ -1,5 +1,6 @@
 package com.server.chart;
 
+import com.config.BasesSource.DynamicDataSourceContextHolder;
 import com.dao.chart.ChartsConfigMapper;
 import com.dao.chart.ShowChartsMapper;
 import com.model.bo.ChartsColumnConfig;
@@ -9,7 +10,6 @@ import com.model.pojo.RepCode;
 import com.model.pojo.RepEntity;
 import com.model.vo.configVo.PopulationInfo;
 import com.model.vo.dataVo.PopAndIndDataInfo;
-import com.config.BasesSource.DynamicDataSourceContextHolder;
 import com.util.ScreenUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -106,7 +106,7 @@ public class ShowPopulationService {
                 } else if ("PERCENT".equals(operator)) {
                     value = 1.00;
                 } else {
-                    value = showChartsMapper.getColumnDev(tableName, columnName, operator, screenStr);
+                    value = showChartsMapper.getColumnData(tableName, columnName, operator, screenStr);
                 }
                 targetData.put(operator, value);
             }

+ 49 - 65
src/main/java/com/server/user/UserService.java

@@ -10,6 +10,7 @@ import com.model.pojo.RepEntity;
 import com.model.vo.configVo.LoginInfo;
 import com.model.vo.configVo.UserGroupInfo;
 import com.model.vo.configVo.UserGroupSetInfo;
+import com.util.EncryUtil;
 import com.util.JwtTokenUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -29,6 +30,54 @@ public class UserService {
     ObjectMapper objectMapper;
 
     public RepEntity login(LoginInfo loginInfo){
+        String userName = loginInfo.getUserName();
+        String pws = loginInfo.getPassWord();
+
+        if ("".equals(userName) || "".equals(pws)){
+            return new RepEntity(RepCode.NoUser);
+        }
+
+        String column = "em_mobile";
+        //查询uas系统中的用户信息
+        User user = userMapper.getUserMess(userName, column);
+        //判断登录模式
+        if(user == null){
+            column = "em_code";
+            user = userMapper.getUserMess(userName, column);
+            if (user == null){
+                return new RepEntity(RepCode.NoUser);
+            }
+        }
+
+        String password = user.getPassWord();
+
+        String pw = EncryUtil.decryptPassword(password);
+
+        if (!pws.equals(pw)){
+            return new RepEntity(RepCode.NoUser);
+        }
+
+        System.out.println("user:" + user);
+        user.setPassWord(pw);
+        user.setUserName(userName);
+        //判断uas系统的用户是否再bi中存在
+        String name = userMapper.getUserName(userName);
+        if (name == null){
+            //不存在则插入
+            userMapper.addUser(user);
+        }else {
+            //存在则更新
+            userMapper.updateUser(user);
+        }
+
+        TokenData tokenData = jwtTokenUtil.createToke(user);
+        tokenData.setUser(user);
+        userMapper.updateToken(tokenData.getToken(),user.getId());
+        return new RepEntity(RepCode.success, tokenData);
+    }
+
+
+    public RepEntity login1(LoginInfo loginInfo){
         String userName = loginInfo.getUserName();
         User user = userMapper.getLogin(userName);
         System.out.println("user:" + user);
@@ -47,71 +96,6 @@ public class UserService {
         return new RepEntity(RepCode.success, tokenData);
     }
 
-    /*
-    测试连接到uas
-     */
-//    public void login(String url){
-//        String result="";
-//        BufferedReader in = null;// 读取响应输入流
-//        StringBuffer sb = new StringBuffer();// 存储参数
-//        String params = "";// 编码之后的参数
-//        try {
-//            // 创建URL对象
-//            java.net.URL connURL = new java.net.URL(url);
-//            // 打开URL连接
-//            java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL
-//                    .openConnection();
-//
-//            // 设置通用属性
-//            httpConn.setRequestProperty("Accept", "*/*");
-//            httpConn.setRequestProperty("Connection", "Keep-Alive");
-//            httpConn.setRequestProperty("User-Agent",
-//                    "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
-//            // 建立实际的连接
-//            httpConn.connect();
-//            // 响应头部获取
-//            Map<String, List<String>> headers = httpConn.getHeaderFields();
-//
-//            //获取session
-//            String session_value = httpConn.getHeaderField("Set-Cookie");
-//            String[] sessionId = session_value.split(";");
-//            System.out.println(sessionId[0]);
-//            System.out.println("Session Value = " + session_value);
-//
-//
-//            // 遍历所有的响应头字段
-//            for (String key : headers.keySet()) {
-//                System.out.println(key + "\t:\t" + headers.get(key));
-//            }
-//            // 定义BufferedReader输入流来读取URL的响应,并设置编码方式
-//            in = new BufferedReader(new InputStreamReader(httpConn
-//                    .getInputStream(), "UTF-8"));
-//            String line;
-//            // 读取返回的内容
-//            while ((line = in.readLine()) != null) {
-//                result += line;
-//            }
-//            System.out.println("result:" + result);
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }finally{
-//            try {
-//                if (in != null) {
-//                    in.close();
-//                }
-//            } catch (IOException ex) {
-//                ex.printStackTrace();
-//            }
-//    }
-//}
-
-    /*
-    test2
-     */
-//    public void login(String url){
-//        HttpRequest request = HttpRequest.get(url);
-//    }
-
 
     /*
     查询用户列表

+ 124 - 0
src/main/java/com/util/DesUtil.java

@@ -0,0 +1,124 @@
+package com.util;
+
+import org.springframework.stereotype.Component;
+
+import javax.crypto.Cipher;
+import java.security.Key;
+import java.security.Security;
+import java.util.Random;
+
+@Component
+public class DesUtil {
+	  private Cipher encryptCipher = null;
+
+
+	  private Cipher decryptCipher = null;
+	  private String key;
+
+	  
+	  public static String byteArr2HexStr(byte[] arrB) throws Exception {
+	    int iLen = arrB.length;
+	    StringBuffer sb = new StringBuffer(iLen * 2);
+	    for (int i = 0; i < iLen; i++) {
+	      int intTmp = arrB[i];
+	      while (intTmp < 0) {
+	        intTmp = intTmp + 256;
+	      }
+	      if (intTmp < 16) {
+	        sb.append("0");
+	      }
+	      sb.append(Integer.toString(intTmp, 16));
+	    }
+	    return sb.toString();
+	  }
+
+	public String getKey() {
+		return key;
+	}
+
+	public void setKey(String key) {
+		this.key = key;
+	}
+
+	  public static byte[] hexStr2ByteArr(String strIn) throws Exception {
+	    byte[] arrB = strIn.getBytes();
+	    int iLen = arrB.length;
+
+	    byte[] arrOut = new byte[iLen / 2];
+	    for (int i = 0; i < iLen; i = i + 2) {
+	      String strTmp = new String(arrB, i, 2);
+	      arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
+	    }
+	    return arrOut;
+	  } 
+
+	  public DesUtil() throws Exception {
+		   super();
+		  }
+
+	  public DesUtil(String strKey) throws Exception {
+	    Security.addProvider(new com.sun.crypto.provider.SunJCE());
+	    Key key = getKey(strKey.getBytes());
+
+	    encryptCipher = Cipher.getInstance("DES");
+	    encryptCipher.init(Cipher.ENCRYPT_MODE, key);
+
+	    decryptCipher = Cipher.getInstance("DES");
+	    decryptCipher.init(Cipher.DECRYPT_MODE, key);
+	  }
+
+
+	  public byte[] encrypt(byte[] arrB) throws Exception {
+	    return encryptCipher.doFinal(arrB);
+	  }
+
+
+	  public String encrypt(String strIn) throws Exception {
+	    return byteArr2HexStr(encrypt(strIn.getBytes()));
+	  }
+
+
+	  public byte[] decrypt(byte[] arrB) throws Exception {
+	    return decryptCipher.doFinal(arrB);
+	  }
+
+
+	  public String decrypt(String strIn) throws Exception {
+	    return new String(decrypt(hexStr2ByteArr(strIn)));
+	  }
+
+
+	  private Key getKey(byte[] arrBTmp) throws Exception {
+	    byte[] arrB = new byte[8];
+	    for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
+	      arrB[i] = arrBTmp[i];
+	    }
+
+	    // ???????   
+	    Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
+
+	    return key;
+	  }
+	  public static String randomString(int length) {
+		  Random randGen = null;
+		  char[] numbersAndLetters = null;
+	         if (length < 1) {
+	             return null;
+	         }
+	         if (randGen == null) {
+	                randGen = new Random();
+	                numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" +
+	                   "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
+	                  //numbersAndLetters = ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
+	                 }
+	         char [] randBuffer = new char[length];
+	         for (int i=0; i<randBuffer.length; i++) {
+	             randBuffer[i] = numbersAndLetters[randGen.nextInt(71)];
+	         }
+	         return new String(randBuffer);
+	  }
+	
+
+
+}
+

+ 70 - 0
src/main/java/com/util/EncryUtil.java

@@ -0,0 +1,70 @@
+package com.util;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class EncryUtil {
+	//人员资料 密码  des加密默认key
+	private final static String key = "96878265";
+	
+	/**
+	 * 获取加密工具类DesUtil
+	 * @return
+	 * @throws Exception
+	 */
+	private static DesUtil getDesUtil() throws Exception{
+		return new DesUtil(key);
+	}
+	
+	/**
+	 * 给密码加盐
+	 * @param password 密码
+	 * @param mobile 手机号
+	 * @return
+	 */
+	private static String setPasswordSalt(String password,String mobile){
+		return mobile+"{"+password+"}";
+	}
+	
+	/**
+	 * 获取密码
+	 * @param password
+	 * @return
+	 */
+	private static String removePasswordSalt(String password){
+		return password.substring(password.indexOf("{")+1, password.length()-1);
+	}
+	/**
+	 * 对密码进行加密
+	 * @param password 密码
+	 * @param mobile   手机号
+	 * @return 加密后的密码
+	 * @throws Exception
+	 */
+	public static String encryptPassword(String password,String mobile){
+		try {
+			return getDesUtil().encrypt(setPasswordSalt(password,mobile));
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return password;
+	}
+	
+	/**
+	 * 对密码进行解密
+	 * @param password 加密的密码
+	 * @return 明文密码
+	 * @throws Exception
+	 */
+	public  static String decryptPassword(String password){
+		try {
+			String pass = getDesUtil().decrypt(password);
+			System.out.println(pass);
+			return removePasswordSalt(pass);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return password;
+	}
+
+}