/eeplat/src/com/exedosoft/plat/login/MultiAccount.java

http://eeplat.googlecode.com/ · Java · 222 lines · 149 code · 58 blank · 15 comment · 10 complexity · a72e042e641d9323915b18257c385dfe MD5 · raw file

  1. package com.exedosoft.plat.login;
  2. import com.exedosoft.plat.DAOUtil;
  3. import com.exedosoft.plat.ExedoException;
  4. import com.exedosoft.plat.bo.BOInstance;
  5. import com.exedosoft.plat.bo.BaseObject;
  6. import com.exedosoft.plat.util.DOGlobals;
  7. import com.exedosoft.plat.util.StringUtil;
  8. import com.exedosoft.safe.TenancyValues;
  9. /**
  10. * ?? account ? user ?????
  11. *
  12. * user ??????
  13. *
  14. * account ????? ??? ?????
  15. * @author weikx
  16. *
  17. */
  18. public class MultiAccount extends BaseObject {
  19. /**
  20. *
  21. */
  22. private static final long serialVersionUID = -4475309511115937205L;
  23. private String name;
  24. private String tenancyId;
  25. private String password;
  26. private String asrole;
  27. private String default_app_uid;
  28. private String creator;
  29. private String modifier;
  30. private String modifyDate;
  31. private String mVersion;
  32. public String getName() {
  33. return name;
  34. }
  35. public void setName(String name) {
  36. this.name = name;
  37. }
  38. public String getTenancyId() {
  39. return tenancyId;
  40. }
  41. public void setTenancyId(String tenancyId) {
  42. this.tenancyId = tenancyId;
  43. }
  44. public String getPassword() {
  45. return password;
  46. }
  47. public void setPassword(String password) {
  48. this.password = password;
  49. }
  50. public String getCreator() {
  51. return creator;
  52. }
  53. public void setCreator(String creator) {
  54. this.creator = creator;
  55. }
  56. public String getModifier() {
  57. return modifier;
  58. }
  59. public void setModifier(String modifier) {
  60. this.modifier = modifier;
  61. }
  62. public String getModifyDate() {
  63. return modifyDate;
  64. }
  65. public void setModifyDate(String modifyDate) {
  66. this.modifyDate = modifyDate;
  67. }
  68. public String getmVersion() {
  69. return mVersion;
  70. }
  71. public void setmVersion(String mVersion) {
  72. this.mVersion = mVersion;
  73. }
  74. public String getDefault_app_uid() {
  75. return default_app_uid;
  76. }
  77. public void setDefault_app_uid(String defaultAppUid) {
  78. default_app_uid = defaultAppUid;
  79. }
  80. public String getAsrole() {
  81. return asrole;
  82. }
  83. public void setAsrole(String asrole) {
  84. this.asrole = asrole;
  85. }
  86. public static BOInstance findAccountToBI(String userName,String pwd){
  87. MultiAccount ma = findAccount(userName,pwd);
  88. if(ma==null){
  89. return null;
  90. }
  91. BOInstance bi = new BOInstance();
  92. bi.fromObject(ma);
  93. return bi;
  94. }
  95. public static MultiAccount findAccount(String userName,String pwd){
  96. if(userName==null || pwd==null){
  97. return null;
  98. }
  99. MultiAccount ma = DAOUtil.currentDataSource("/ds_multi.xml").getBySql(
  100. MultiAccount.class, "select * from multi_account where name=? and password=?",userName,StringUtil.MD5(pwd));
  101. if(ma!=null && ma.getName()!=null){
  102. return ma;
  103. }
  104. return null;
  105. }
  106. public static MultiAccount findAccount(String userName,String pwd,String tenantId){
  107. if(userName==null || pwd==null){
  108. return null;
  109. }
  110. MultiAccount ma = DAOUtil.currentDataSource("/ds_multi.xml").getBySql(
  111. MultiAccount.class, "select * from multi_account where name=? and password=? and tenancyId=?",userName,StringUtil.MD5(pwd),tenantId);
  112. if(ma!=null && ma.getName()!=null){
  113. return ma;
  114. }
  115. return null;
  116. }
  117. public static void deleteAccount(String accountUid){
  118. System.out.println("Delete multi_account :::" + accountUid);
  119. try {
  120. DAOUtil.currentDataSource("/ds_multi.xml")
  121. .delete("delete from multi_account where objuid = ?",
  122. accountUid
  123. );
  124. } catch (ExedoException e) {
  125. // TODO Auto-generated catch block
  126. e.printStackTrace();
  127. }
  128. }
  129. public static void storeAccount(BOInstance<?> paraInstance){
  130. String objuid = paraInstance.getUid();
  131. String name = paraInstance.getValue("user_code");
  132. TenancyValues tv = DOGlobals.getInstance().getSessoinContext()
  133. .getTenancyValues();
  134. String tenancyId = paraInstance.getValue("tenancyId");
  135. if(tenancyId==null){
  136. tenancyId = tv.getTenant().getValue("name");
  137. }
  138. String password = paraInstance.getValue("password");
  139. password = StringUtil.MD5(password);
  140. String asrole = "0";
  141. String default_app_uid = "ff80808131275dcc0131275e2fdf0001";
  142. try {
  143. DAOUtil.currentDataSource("/ds_multi.xml")
  144. .store("insert into multi_account(objuid,name,tenancyid,password,asrole,default_app_uid) values(?,?,?,?,?,?)",
  145. objuid,
  146. name,
  147. tenancyId,
  148. password,
  149. asrole,
  150. default_app_uid
  151. );
  152. } catch (ExedoException e) {
  153. // TODO Auto-generated catch block
  154. e.printStackTrace();
  155. }
  156. }
  157. public static void main(String[] args) {
  158. MultiAccount ma = MultiAccount.findAccount("jlf@jlf.com", "1");
  159. System.out.println("MultiAccount:::" + ma);
  160. BOInstance bi = MultiAccount.findAccountToBI("jlf@google.com", "2");
  161. System.out.println("BOInstance:::" + bi);
  162. // System.out.println(ms);
  163. }
  164. }