CreateUserFactory.java 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package restcontroller.webmanage.users;
  2. import common.Controller;
  3. import common.YosException;
  4. import common.data.SQLFactory;
  5. import java.util.ArrayList;
  6. public class CreateUserFactory {
  7. String name;
  8. String phonenumber;
  9. String remarks;
  10. ArrayList<String> sqlist;
  11. Controller controller;
  12. long newuserid;
  13. String accountno;
  14. int usertype;
  15. Long[] roleids;
  16. public CreateUserFactory(Controller controller, String accountno, String name, String phonenumber, int usertype, Long[] roleids, String remarks) throws YosException {
  17. this.name = name;
  18. this.phonenumber = phonenumber;
  19. this.remarks = remarks;
  20. this.controller = controller;
  21. this.sqlist = new ArrayList<>();
  22. this.usertype = usertype;
  23. this.roleids = roleids;
  24. this.newuserid = controller.createTableID("sys_users");
  25. this.accountno = accountno;
  26. }
  27. public CreateUserFactory(Controller controller, String name, String phonenumber, int usertype, Long[] roleids, String remarks) throws YosException {
  28. this.name = name;
  29. this.phonenumber = phonenumber;
  30. this.remarks = remarks;
  31. this.controller = controller;
  32. this.sqlist = new ArrayList<>();
  33. this.usertype = usertype;
  34. this.roleids = roleids;
  35. do {
  36. /*
  37. 创建用户id及登陆账号。如果生成的账号已存在,则生成新的直至不重复为止
  38. */
  39. this.newuserid = controller.createTableID("sys_users");
  40. this.accountno = controller.makeFillCode(6, this.newuserid);
  41. } while (controller.dbConnect.runSqlQuery("select * from sys_users where accountno='" + this.accountno + "'").isNotEmpty());
  42. }
  43. public ArrayList<String> getSQL() throws YosException {
  44. String password_default = controller.dbConnect.runSqlQuery(0, "select password_default from sys_site_parameter where siteid='" + controller.siteid + "'").getString("password_default");
  45. SQLFactory addusersql = new SQLFactory(this, "账号新增");
  46. addusersql.addParameter("userid", newuserid);
  47. addusersql.addParameter("name", name);
  48. addusersql.addParameter("password", password_default);
  49. addusersql.addParameter("createby", controller.username);
  50. addusersql.addParameter("phonenumber", phonenumber);
  51. addusersql.addParameter("accountno", accountno);
  52. addusersql.addParameter("remarks", remarks);
  53. sqlist.add(addusersql.getSQL());
  54. SQLFactory addusersitesql = new SQLFactory(this, "账号站点添加");
  55. addusersitesql.addParameter("usersiteid", controller.createTableID("sys_usersite"));
  56. addusersitesql.addParameter("userid", newuserid);
  57. addusersitesql.addParameter("usertype", usertype);
  58. addusersitesql.addParameter("siteid", controller.siteid);
  59. addusersitesql.addParameter("createby", controller.username);
  60. sqlist.add(addusersitesql.getSQL());
  61. for (long roleid : roleids) {
  62. SQLFactory sqlFactory = new SQLFactory(this, "账号角色添加");
  63. sqlFactory.addParameter("userid", newuserid);
  64. sqlFactory.addParameter("userroleid", controller.createTableID("sys_userrole"));
  65. sqlFactory.addParameter("roleid", roleid);//新用户默认角色
  66. sqlFactory.addParameter("createby", controller.username);
  67. sqlist.add(sqlFactory.getSQL());
  68. }
  69. return sqlist;
  70. }
  71. public long getUserid() {
  72. return newuserid;
  73. }
  74. }