Commit 5e315704ed40b5082e64a86bbe2c66b9c6d05b29

Authored by hanshaofeng
1 parent ca86dc89ec

add import test

Showing 1 changed file with 79 additions and 0 deletions

platform-operate-api/src/main/java/com/lyms/hospitalapi/DataImportTest.java View file @ 5e31570
  1 +package com.lyms.hospitalapi;
  2 +
  3 +import com.lyms.hospitalapi.pojo.PregPatientinfo;
  4 +import com.lyms.platform.common.base.LoginContext;
  5 +import com.lyms.platform.common.utils.DateUtil;
  6 +import com.lyms.platform.common.utils.LoginUtil;
  7 +import com.lyms.platform.permission.model.Users;
  8 +import org.apache.commons.dbutils.DbUtils;
  9 +import org.apache.commons.dbutils.QueryRunner;
  10 +import org.apache.commons.dbutils.handlers.BeanListHandler;
  11 +
  12 +import java.sql.Connection;
  13 +import java.sql.DriverManager;
  14 +import java.sql.SQLException;
  15 +import java.util.List;
  16 +
  17 +/**
  18 + * Created by riecard on 2016/10/18.
  19 + */
  20 +public class DataImportTest {
  21 +
  22 + public static void main(String[] a) {
  23 + Connection localCon = makelocalConnection();
  24 + Connection onlineCon = makeonlineConnection();
  25 + QueryRunner queryRunner = new QueryRunner();
  26 + try {
  27 + List<Users> list = queryRunner.query(localCon, "select * from users", new BeanListHandler<Users>(Users.class));
  28 + if (list.size() > 0) {
  29 + for (Users users:list) {
  30 + LoginContext loginContext = LoginUtil.register(""+users.getId(),users.getPhone(),users.getAccount(),users.getPwd(),"265a841b-9bb5-434a-8c2b-e78df86fc45d","2");
  31 + if(loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4010)) {
  32 + users.setLogincenterId(loginContext.getId());
  33 + String sql = "INSERT INTO `users` (`zhiChenId`,`id`,`logincenter_id`,`type`,`org_id`,`dept_id`,`name`,`account`,`pwd`,`phone`,`publish_id`,`publish_name`,`yn`,`enable`,`modified`,`created`,`remarks`,`last_login_time`,`ks_Id`,`foreign_id`,`other_account`,`employee_id`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
  34 + // "(3,5332023,2000000000,1,242,151,'朱华','朱华','F14062C7EE0FFFC96A40898E08073D73','13996129571',867,'医院管理员',1,1,'2016-10-02 20:45:01','2016-10-02 20:45:01',NULL,NULL,NULL,NULL,NULL,NULL)";
  35 + Object[] params = {users.getZhiChenId(),users.getId(), users.getLogincenterId(), users.getType(),242,143,users.getName(),users.getAccount(),users.getPwd(),users.getPhone(),867,"医院管理员",
  36 + 1,1,users.getModified(),users.getCreated(),users.getRemarks(),users.getCreated(),null,null,null,null};
  37 + queryRunner.update(onlineCon, sql, params);
  38 + } else {
  39 + System.out.println(users.getId());
  40 + }
  41 + }
  42 +
  43 + }
  44 + } catch (SQLException e) {
  45 + e.printStackTrace();
  46 + }
  47 + }
  48 +
  49 + public static Connection makeonlineConnection() {
  50 + Connection conn = null;
  51 + try {
  52 + Class.forName("com.mysql.jdbc.Driver");
  53 + } catch (ClassNotFoundException e) {
  54 + e.printStackTrace();
  55 + }
  56 + try {
  57 + conn = DriverManager.getConnection("jdbc:mysql://119.90.43.68:3307/platform?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8", "platform", "platform123");
  58 + } catch (SQLException e) {
  59 + e.printStackTrace();
  60 + }
  61 + return conn;
  62 + }
  63 +
  64 + public static Connection makelocalConnection() {
  65 + Connection conn = null;
  66 + try {
  67 + Class.forName("com.mysql.jdbc.Driver");
  68 + } catch (ClassNotFoundException e) {
  69 + e.printStackTrace();
  70 + }
  71 + try {
  72 + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8", "root", "");
  73 + } catch (SQLException e) {
  74 + e.printStackTrace();
  75 + }
  76 + return conn;
  77 + }
  78 +
  79 +}