From 7158b0710a16bba047ff756af88316b10c56812b Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 14 Mar 2019 15:31:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=9A=E5=8A=A1=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ecloud_controller.rb | 40 +++++++++++++------ app/models/ecloud_log.rb | 2 +- app/models/ecloud_user.rb | 2 +- app/models/ecloud_user_para.rb | 3 ++ ...20190314065338_add_userid_to_ecloud_log.rb | 6 +++ ...90314065601_add_applyno_to_ecloud_users.rb | 7 ++++ ...20190314070159_create_ecloud_user_paras.rb | 11 +++++ spec/factories/ecloud_user_paras.rb | 7 ++++ spec/models/ecloud_user_para_spec.rb | 5 +++ 9 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 app/models/ecloud_user_para.rb create mode 100644 db/migrate/20190314065338_add_userid_to_ecloud_log.rb create mode 100644 db/migrate/20190314065601_add_applyno_to_ecloud_users.rb create mode 100644 db/migrate/20190314070159_create_ecloud_user_paras.rb create mode 100644 spec/factories/ecloud_user_paras.rb create mode 100644 spec/models/ecloud_user_para_spec.rb diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index 9fd4a8b8..49f28076 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -170,20 +170,33 @@ class EcloudController < ApplicationController # 用户业务开通与变更接口 # 授权statu为1,取消授权status为0 + # opttype: 操作类型0:开通;1:变更; + def ps_new - begin - user_params = params['users'] - user_params.each do |user_param| - EcloudUser.create!(custid: params['custid'], opttype: user_param['opttype'], userid: user_param['userid'], - username: user_param['username'], useralias: user_param['useralias'], - mobile: user_param['mobile'], email: user_param['email'], begintime: user_param['begintime'].to_s, - endtime: user_param['endtime'].to_s, status: 1) + ActiveRecord::Base.transaction do + begin + user_params = params['users'] + user_params.each do |user_param| + if user_param['opttype'] == 0 # 开通 + EcloudUser.create!(custid: params['custid'], opttype: user_param['opttype'], userid: user_param['userid'], + username: user_param['username'], useralias: user_param['useralias'], + mobile: user_param['mobile'], email: user_param['email'], begintime: user_param['begintime'].to_s, + endtime: user_param['endtime'].to_s) + elsif user_param['opttype'] == 1 # 变更 + ecloud_user = EcloudUser.where(custid: params['custid'], userid: user_param['userid']).first + ecloud_user.update_attributes!(opttype: user_param['opttype'], username: user_param['username'], + useralias: user_param['useralias'], mobile: user_param['mobile'], email: user_param['email'], + begintime: user_param['begintime'].to_s, endtime: user_param['endtime'].to_s) + end + end + + render :json => {success: true, errmsg: ""} + # end + rescue Exception => e + logger.error(e.message) + render :json => {code: 500, msg: "#{e.message}"} + raise ActiveRecord::Rollback end - render :json => {success: true, errmsg: ""} - # end - rescue Exception => e - logger.error(e.message) - render :json => {code: 500, msg: "#{e.message}"} end end @@ -323,7 +336,8 @@ class EcloudController < ApplicationController end def save_para - EcloudLog.create(url: request.url, para_value: params, applyno: params['applyno'], custid: params['custid'], custcode: params['custcode']) + EcloudLog.create(url: request.url, para_value: params, applyno: params['applyno'], custid: params['custid'], + custcode: params['custcode'], userid: params['userid'], username: params['username']) end end diff --git a/app/models/ecloud_log.rb b/app/models/ecloud_log.rb index 4e187aa5..a1ac3636 100644 --- a/app/models/ecloud_log.rb +++ b/app/models/ecloud_log.rb @@ -1,3 +1,3 @@ class EcloudLog < ActiveRecord::Base - attr_accessible :para_value, :url, :applyno, :custid, :custcode + end diff --git a/app/models/ecloud_user.rb b/app/models/ecloud_user.rb index dd4a5584..fad6f470 100644 --- a/app/models/ecloud_user.rb +++ b/app/models/ecloud_user.rb @@ -1,3 +1,3 @@ class EcloudUser < ActiveRecord::Base - attr_accessible :begintime, :email, :endtime, :mobile, :opttype, :paras, :useralias, :userid, :username, :custid, :status, :ecloud_id + has_many :ecloud_user_paras end diff --git a/app/models/ecloud_user_para.rb b/app/models/ecloud_user_para.rb new file mode 100644 index 00000000..3f4ddc5c --- /dev/null +++ b/app/models/ecloud_user_para.rb @@ -0,0 +1,3 @@ +class EcloudUserPara < ActiveRecord::Base + belongs_to :ecloud_user +end diff --git a/db/migrate/20190314065338_add_userid_to_ecloud_log.rb b/db/migrate/20190314065338_add_userid_to_ecloud_log.rb new file mode 100644 index 00000000..a32b91e5 --- /dev/null +++ b/db/migrate/20190314065338_add_userid_to_ecloud_log.rb @@ -0,0 +1,6 @@ +class AddUseridToEcloudLog < ActiveRecord::Migration + def change + add_column :ecloud_logs, :userid, :integer + add_column :ecloud_logs, :username, :string + end +end diff --git a/db/migrate/20190314065601_add_applyno_to_ecloud_users.rb b/db/migrate/20190314065601_add_applyno_to_ecloud_users.rb new file mode 100644 index 00000000..6824c9a4 --- /dev/null +++ b/db/migrate/20190314065601_add_applyno_to_ecloud_users.rb @@ -0,0 +1,7 @@ +class AddApplynoToEcloudUsers < ActiveRecord::Migration + def change + add_column :ecloud_users, :applyno, :string + add_column :ecloud_users, :ecordercode, :string + add_column :ecloud_users, :productcode, :string + end +end diff --git a/db/migrate/20190314070159_create_ecloud_user_paras.rb b/db/migrate/20190314070159_create_ecloud_user_paras.rb new file mode 100644 index 00000000..3d090983 --- /dev/null +++ b/db/migrate/20190314070159_create_ecloud_user_paras.rb @@ -0,0 +1,11 @@ +class CreateEcloudUserParas < ActiveRecord::Migration + def change + create_table :ecloud_user_paras do |t| + t.string :key + t.string :value + t.integer :ecloud_user_id + + t.timestamps + end + end +end diff --git a/spec/factories/ecloud_user_paras.rb b/spec/factories/ecloud_user_paras.rb new file mode 100644 index 00000000..7e171cb2 --- /dev/null +++ b/spec/factories/ecloud_user_paras.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :ecloud_user_para do + key "MyString" +value "MyString" + end + +end diff --git a/spec/models/ecloud_user_para_spec.rb b/spec/models/ecloud_user_para_spec.rb new file mode 100644 index 00000000..1d551760 --- /dev/null +++ b/spec/models/ecloud_user_para_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe EcloudUserPara, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end