|
|
@@ -1,23 +1,18 @@
|
|
|
package common.crm;
|
|
|
|
|
|
-import beans.user.User;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.beust.ah.A;
|
|
|
import common.AccessToken;
|
|
|
import common.BaseClass;
|
|
|
import common.ReturnObject_Err;
|
|
|
import common.YosException;
|
|
|
-import common.data.QuerySQL;
|
|
|
-import common.data.Row;
|
|
|
-import common.data.Rows;
|
|
|
-import common.data.SQLFactory;
|
|
|
+import common.data.*;
|
|
|
import common.data.db.DBConnect;
|
|
|
+import common.password.UserPassword;
|
|
|
import common.restful.Basic;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import jakarta.servlet.http.HttpSession;
|
|
|
-import org.glassfish.grizzly.utils.ArraySet;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
@@ -28,8 +23,7 @@ import utility.tools.WebRequest;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("/rest/sso")
|
|
|
@@ -76,9 +70,10 @@ public class sso extends Basic {
|
|
|
String errmsg = "";
|
|
|
HashMap<String, Object> params = new HashMap<>();
|
|
|
params.put("username", accountno);
|
|
|
- params.put("last_login_session", inputpassword);
|
|
|
- Rows rows = new DBConnect("CRM").runSqlQuery("select hrid from sys_user_info where username=$username$ and last_login_session=$last_login_session$", params);
|
|
|
+ params.put("sessionid", inputpassword);
|
|
|
+ Rows rows = new DBConnect("CRM").runSqlQuery("select hrid from e_order_loginkey where DATE(logindate) = CURDATE() and username=$username$ and sessionid=$sessionid$", params);
|
|
|
if (rows.isNotEmpty()) {
|
|
|
+ new DBConnect("CRM").runSqlUpdate("delete from e_order_loginkey where DATE(logindate) < CURDATE()");
|
|
|
accountno = rows.get(0).getString("hrid");
|
|
|
Rows users = connect.runSqlQuery("select userid,status,failedlogins from sys_users where accountno='" + accountno + "'");
|
|
|
if (users.isNotEmpty()) {
|
|
|
@@ -93,7 +88,7 @@ public class sso extends Basic {
|
|
|
}
|
|
|
} else {
|
|
|
//账号不存在,则查询crm账号,并在E-订单中创建并授权
|
|
|
- Rows br_hrRows = new DBConnect("CRM").runSqlQuery("select fagent_num,phone,name from br_hr where hrid='" + accountno + "'");
|
|
|
+ Rows br_hrRows = new DBConnect("CRM").runSqlQuery("select fagent_num,phone,name from br_hr where hrid='" + accountno + "' and fagent_num!='meida'");
|
|
|
if (br_hrRows.isNotEmpty()) {
|
|
|
String fagent_num = br_hrRows.get(0).getString("fagent_num");
|
|
|
String phone = br_hrRows.get(0).getString("phone");
|
|
|
@@ -102,47 +97,7 @@ public class sso extends Basic {
|
|
|
Rows sa_agentsRows = connect.runSqlQuery("select * from sa_agents where agentnum='" + fagent_num + "' and siteid='MD'");
|
|
|
if (sa_agentsRows.isNotEmpty()) {
|
|
|
long sys_enterpriseid = sa_agentsRows.get(0).getLong("sys_enterpriseid");
|
|
|
-
|
|
|
- Rows crm_roles = new DBConnect("CRM").runSqlQuery("select t1.uid,t1.hrid,t2.role_id,t3.role,t3.description,t3.sys from sys_user_info t1\n" +
|
|
|
- "inner join sys_user_role t2 on t1.uid=t2.uid\n" +
|
|
|
- "inner join sys_role t3 on t2.role_id=t3.id\n" +
|
|
|
- "where hrid='" + accountno + "'");
|
|
|
- ArrayList<Long> roleids = new ArrayList<>();
|
|
|
-
|
|
|
- HashMap<String, Long> roleidMapping = new HashMap<>();
|
|
|
- roleidMapping.put("agentBoss", 4097L);//经销商主账号权限组
|
|
|
- roleidMapping.put("agentAssistant", 1L);//站点老板助理
|
|
|
- roleidMapping.put("agentRemodelBoss", 1L);//家装老板
|
|
|
- roleidMapping.put("agentRemodelAssistant", 1L);//家装老板助理
|
|
|
- roleidMapping.put("shpjsb", 1L);//售后配件申报
|
|
|
- roleidMapping.put("assigner", 1L);//工单派单员
|
|
|
- roleidMapping.put("shopManager", 1L);//店长
|
|
|
- roleidMapping.put("shopGuide", 1L);//导购
|
|
|
- roleidMapping.put("salesman", 1L);//业务员
|
|
|
- roleidMapping.put("designer", 1L);//设计师
|
|
|
- roleidMapping.put("financialStaff", 1L);//财务人员
|
|
|
- roleidMapping.put("warehouseKeeper", 1L);//仓管
|
|
|
- roleidMapping.put("serviceStaff", 1L);//客服人员
|
|
|
- roleidMapping.put("installer", 1L);//安装师傅
|
|
|
- roleidMapping.put("marketoffice", 1L);//营销办公室(总公司)
|
|
|
- roleidMapping.put("agentRoleOnline", 1L);//电商站点(总公司)
|
|
|
- roleidMapping.put("headAfterSales", 1L);//售后服务部(总公司)
|
|
|
- roleidMapping.put("regionalManager", 1L);//区域/大区经理
|
|
|
- roleidMapping.put("agentOnlineBoss", 1L);//网销老板
|
|
|
- roleidMapping.put("agentOnlineAssistant", 1L);//网销老板助理
|
|
|
- for (Row crm_role : crm_roles) {
|
|
|
- String role = crm_role.getString("role");
|
|
|
- if (roleidMapping.containsKey(role)) {
|
|
|
- roleids.add(roleidMapping.get(role));
|
|
|
- }
|
|
|
- }
|
|
|
- long[] roleidArray = new long[roleids.size()];
|
|
|
- for (int i = 0; i < roleids.size(); i++) {
|
|
|
- roleidArray[i] = roleids.get(i);
|
|
|
- }
|
|
|
- long userid = User.createUser(connect, "MD", sys_enterpriseid, accountno, name, phone, false, "", 21, roleidArray, "crm同步");
|
|
|
-
|
|
|
- passwordVerificationPassed = true;
|
|
|
+ passwordVerificationPassed = createAgentUser(connect, sys_enterpriseid, accountno, name, phone);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -193,9 +148,93 @@ public class sso extends Basic {
|
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("code", 0);
|
|
|
object.put("status", 0);
|
|
|
- object.put("msg", errmsg.isEmpty() ? "用户名或密码错误" : errmsg);
|
|
|
- this.createLoginLog(RequestContent, request, false, new JSONArray(), errmsg.isEmpty() ? "用户名或密码错误" : errmsg);
|
|
|
+ object.put("msg", errmsg.isEmpty() ? "登录验证已失效,请重新登录CRM!" : errmsg);
|
|
|
+ this.createLoginLog(RequestContent, request, false, new JSONArray(), errmsg.isEmpty() ? "登录验证已失效,请重新登录CRM!" : errmsg);
|
|
|
return object;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private boolean createAgentUser(DBConnect dbConnect, long sys_enterpriseid, String accountno, String name, String phonenumber) {
|
|
|
+ try {
|
|
|
+ HashMap<String, Long> roleidMapping = new HashMap<>();
|
|
|
+ roleidMapping.put("agentBoss", 4097L);//经销商主账号权限组
|
|
|
+ roleidMapping.put("agentAssistant", 4098L);//站点老板助理
|
|
|
+ roleidMapping.put("agentRemodelBoss", 4097L);//家装老板
|
|
|
+ roleidMapping.put("agentRemodelAssistant", 4098L);//家装老板助理
|
|
|
+ roleidMapping.put("agentOnlineBoss", 4097L);//网销老板
|
|
|
+ roleidMapping.put("agentOnlineAssistant", 4098L);//网销老板助理
|
|
|
+ roleidMapping.put("shpjsb", 5210L);//售后配件申报
|
|
|
+ roleidMapping.put("assigner", 5211L);//工单派单员
|
|
|
+ roleidMapping.put("serviceStaff", 5211L);//客服人员
|
|
|
+ roleidMapping.put("installer", 5206L);//安装师傅
|
|
|
+
|
|
|
+// roleidMapping.put("shopManager", 1L);//店长
|
|
|
+// roleidMapping.put("shopGuide", 1L);//导购
|
|
|
+// roleidMapping.put("salesman", 1L);//业务员
|
|
|
+// roleidMapping.put("designer", 1L);//设计师
|
|
|
+// roleidMapping.put("financialStaff", 1L);//财务人员
|
|
|
+// roleidMapping.put("warehouseKeeper", 1L);//仓管
|
|
|
+// roleidMapping.put("marketoffice", 1L);//营销办公室(总公司)
|
|
|
+// roleidMapping.put("agentRoleOnline", 1L);//电商站点(总公司)
|
|
|
+// roleidMapping.put("headAfterSales", 1L);//售后服务部(总公司)
|
|
|
+// roleidMapping.put("regionalManager", 1L);//区域/大区经理
|
|
|
+
|
|
|
+
|
|
|
+ Rows crm_roles = new DBConnect("CRM").runSqlQuery("select t1.uid,t1.hrid,t2.role_id,t3.role,t3.description,t3.sys from sys_user_info t1\n" + "inner join sys_user_role t2 on t1.uid=t2.uid\n" + "inner join sys_role t3 on t2.role_id=t3.id\n" + "where hrid='" + accountno + "'");
|
|
|
+ ArrayList<Long> roleids = new ArrayList<>();
|
|
|
+ for (Row crm_role : crm_roles) {
|
|
|
+ String role = crm_role.getString("role");
|
|
|
+ if (roleidMapping.containsKey(role)) {
|
|
|
+ roleids.add(roleidMapping.get(role));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!roleids.isEmpty()) {
|
|
|
+ String siteid = "MD";
|
|
|
+ SQLDump sqlDump = new SQLDump();
|
|
|
+ long userid = (new BaseClass()).createTableID("sys_users");
|
|
|
+ InsertSQL adduser = SQLFactory.createInsertSQL(dbConnect, "sys_users");
|
|
|
+ adduser.setValue("userid", userid);
|
|
|
+ adduser.setValue("name", name);
|
|
|
+ adduser.setValue("phonenumber", phonenumber);
|
|
|
+ adduser.setValue("status", "ACTIVE");
|
|
|
+ adduser.setValue("accountno", accountno);
|
|
|
+ adduser.setValue("remarks", "crm同步");
|
|
|
+ adduser.setValue("failedlogins", 0);
|
|
|
+ adduser.setValue("password", UserPassword.create(UUID.randomUUID().toString()));
|
|
|
+ sqlDump.add(adduser);
|
|
|
+
|
|
|
+ InsertSQL addusersite = SQLFactory.createInsertSQL(dbConnect, "sys_usersite");
|
|
|
+ addusersite.setValue("siteid", siteid);
|
|
|
+ addusersite.setValue("userid", userid);
|
|
|
+ addusersite.setValue("usertype", 22);
|
|
|
+ sqlDump.add(addusersite);
|
|
|
+
|
|
|
+ for (long roleid : roleids) {
|
|
|
+ InsertSQL adduserrole = SQLFactory.createInsertSQL(dbConnect, "sys_userrole");
|
|
|
+ adduserrole.setValue("userid", userid);
|
|
|
+ adduserrole.setValue("roleid", roleid);
|
|
|
+ adduserrole.setValue("siteid", siteid);
|
|
|
+ sqlDump.add(adduserrole);
|
|
|
+ }
|
|
|
+
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(dbConnect, "sys_enterprise_hr");
|
|
|
+ insertSQL.setValue("siteid", siteid);
|
|
|
+ insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ insertSQL.setValue("userid", userid);
|
|
|
+ insertSQL.setValue("isleader", false);
|
|
|
+ insertSQL.setValue("phonenumber", phonenumber);
|
|
|
+ insertSQL.setValue("name", name);
|
|
|
+ insertSQL.setValue("remarks", "crm同步");
|
|
|
+ insertSQL.setValue("changeuserid", userid);
|
|
|
+ sqlDump.add(insertSQL);
|
|
|
+ sqlDump.commit(dbConnect);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|