| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package restcontroller.webmanage.users;
- import common.Controller;
- import common.YosException;
- import common.data.SQLFactory;
- import java.util.ArrayList;
- public class CreateUserFactory {
- String name;
- String phonenumber;
- String remarks;
- ArrayList<String> sqlist;
- Controller controller;
- long newuserid;
- String accountno;
- int usertype;
- Long[] roleids;
- public CreateUserFactory(Controller controller, String accountno, String name, String phonenumber, int usertype, Long[] roleids, String remarks) throws YosException {
- this.name = name;
- this.phonenumber = phonenumber;
- this.remarks = remarks;
- this.controller = controller;
- this.sqlist = new ArrayList<>();
- this.usertype = usertype;
- this.roleids = roleids;
- this.newuserid = controller.createTableID("sys_users");
- this.accountno = accountno;
- }
- public CreateUserFactory(Controller controller, String name, String phonenumber, int usertype, Long[] roleids, String remarks) throws YosException {
- this.name = name;
- this.phonenumber = phonenumber;
- this.remarks = remarks;
- this.controller = controller;
- this.sqlist = new ArrayList<>();
- this.usertype = usertype;
- this.roleids = roleids;
- do {
- /*
- 创建用户id及登陆账号。如果生成的账号已存在,则生成新的直至不重复为止
- */
- this.newuserid = controller.createTableID("sys_users");
- this.accountno = controller.makeFillCode(6, this.newuserid);
- } while (controller.dbConnect.runSqlQuery("select * from sys_users where accountno='" + this.accountno + "'").isNotEmpty());
- }
- public ArrayList<String> getSQL() throws YosException {
- String password_default = controller.dbConnect.runSqlQuery(0, "select password_default from sys_site_parameter where siteid='" + controller.siteid + "'").getString("password_default");
- SQLFactory addusersql = new SQLFactory(this, "账号新增");
- addusersql.addParameter("userid", newuserid);
- addusersql.addParameter("name", name);
- addusersql.addParameter("password", password_default);
- addusersql.addParameter("createby", controller.username);
- addusersql.addParameter("phonenumber", phonenumber);
- addusersql.addParameter("accountno", accountno);
- addusersql.addParameter("remarks", remarks);
- sqlist.add(addusersql.getSQL());
- SQLFactory addusersitesql = new SQLFactory(this, "账号站点添加");
- addusersitesql.addParameter("usersiteid", controller.createTableID("sys_usersite"));
- addusersitesql.addParameter("userid", newuserid);
- addusersitesql.addParameter("usertype", usertype);
- addusersitesql.addParameter("siteid", controller.siteid);
- addusersitesql.addParameter("createby", controller.username);
- sqlist.add(addusersitesql.getSQL());
- for (long roleid : roleids) {
- SQLFactory sqlFactory = new SQLFactory(this, "账号角色添加");
- sqlFactory.addParameter("userid", newuserid);
- sqlFactory.addParameter("userroleid", controller.createTableID("sys_userrole"));
- sqlFactory.addParameter("roleid", roleid);//新用户默认角色
- sqlFactory.addParameter("createby", controller.username);
- sqlist.add(sqlFactory.getSQL());
- }
- return sqlist;
- }
- public long getUserid() {
- return newuserid;
- }
- }
|