|
|
@@ -2,11 +2,13 @@ package beans.datateam;
|
|
|
|
|
|
import beans.datacontrllog.DataContrlLog;
|
|
|
import beans.department.Department;
|
|
|
+import beans.salearea.SaleArea;
|
|
|
import beans.user.User;
|
|
|
import common.BaseClass;
|
|
|
import common.Controller;
|
|
|
import common.YosException;
|
|
|
import common.data.*;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashSet;
|
|
|
@@ -371,22 +373,22 @@ public class DataTeam {
|
|
|
break;
|
|
|
}
|
|
|
case 3: {
|
|
|
- ArrayList<Long> subUserIds = User.getSubUserIds(controller);
|
|
|
+ ArrayList<Long> subUserIds = getSubAreaUserIds(controller);
|
|
|
if (subUserIds.size() == 0) {
|
|
|
str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select ownerid from sys_datateam where siteid='" + siteid + "' and isleader=1 and userid in ('') and ownertable='" + ownertable + "' )";
|
|
|
} else {
|
|
|
- str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select ownerid from sys_datateam where siteid='" + siteid + "' and isleader=1 and userid in " + getSubUserIds2(controller) + " and ownertable='" + ownertable + "' )";
|
|
|
+ str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select ownerid from sys_datateam where siteid='" + siteid + "' and isleader=1 and userid in " + subUserIds + " and ownertable='" + ownertable + "' )";
|
|
|
|
|
|
}
|
|
|
str = str.replace("[", "(").replace("]", ")");
|
|
|
break;
|
|
|
}
|
|
|
case 4: {
|
|
|
- ArrayList<Long> subUserIds = User.getSubUserIds(controller);
|
|
|
+ ArrayList<Long> subUserIds = getSubAreaUserIds(controller);
|
|
|
if (subUserIds.size() == 0) {
|
|
|
str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select ownerid from sys_datateam where siteid='" + siteid + "' and isleader=0 and userid in ('') and ownertable='" + ownertable + "' )";
|
|
|
} else {
|
|
|
- str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select ownerid from sys_datateam where siteid='" + siteid + "' and isleader=0 and userid in " + getSubUserIds2(controller) + " and ownertable='" + ownertable + "' )";
|
|
|
+ str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select ownerid from sys_datateam where siteid='" + siteid + "' and isleader=0 and userid in " + subUserIds + " and ownertable='" + ownertable + "' )";
|
|
|
}
|
|
|
str = str.replace("[", "(").replace("]", ")");
|
|
|
break;
|
|
|
@@ -413,11 +415,11 @@ public class DataTeam {
|
|
|
}
|
|
|
//我下属创建的
|
|
|
case 9: {
|
|
|
- ArrayList<Long> subUserIds = User.getSubUserIds(controller);
|
|
|
+ ArrayList<Long> subUserIds = getSubAreaUserIds(controller);
|
|
|
if (subUserIds.size() == 0) {
|
|
|
- str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select "+controller.getuniquecolumnname(ownertable)+" from "+ownertable+" where siteid='" + siteid + "' and createuserid in ('') )";
|
|
|
+ str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select " + controller.getuniquecolumnname(ownertable) + " from " + ownertable + " where siteid='" + siteid + "' and createuserid in ('') )";
|
|
|
} else {
|
|
|
- str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select "+controller.getuniquecolumnname(ownertable)+" from "+ownertable+" where siteid='" + siteid + "' and createuserid in "+getSubUserIds2(controller)+" )";
|
|
|
+ str = alias + "." + controller.getuniquecolumnname(ownertable) + " in(select " + controller.getuniquecolumnname(ownertable) + " from " + ownertable + " where siteid='" + siteid + "' and createuserid in " + subUserIds + " )";
|
|
|
}
|
|
|
str = str.replace("[", "(").replace("]", ")");
|
|
|
break;
|
|
|
@@ -428,60 +430,6 @@ public class DataTeam {
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 数据快速过滤
|
|
|
- *
|
|
|
- * @param controller
|
|
|
- * @param ownertable 数据表名
|
|
|
- * @param alias 数据表别名
|
|
|
- * @param type 1:我负责的;2:我参与的;3:我下属负责的;4:我下属参与的;5:我创建的;
|
|
|
- * @throws YosException
|
|
|
- */
|
|
|
- public static String getDataWhereStr(Controller controller, String ownertable, String alias, int type, ArrayList<Long> userids, ArrayList<Long> subUserIds) throws YosException {
|
|
|
- String str = " 1=1 ";
|
|
|
-
|
|
|
- switch (type) {
|
|
|
- case 1: {
|
|
|
- str = " exists(select sys_datateamid from sys_datateam where siteid='" + controller.siteid + "' and isleader=1 and userid in" + userids + " and ownertable='" + ownertable + "' and ownerid=" + alias + "." + controller.getuniquecolumnname(ownertable) + " )";
|
|
|
- str = str.replace("[", "(").replace("]", ")");
|
|
|
- break;
|
|
|
- }
|
|
|
- case 2: {
|
|
|
- str = " exists(select sys_datateamid from sys_datateam where siteid='" + controller.siteid + "' and ((isleader=0 and userid in" + userids + ") or (isleader=1 and userid in (select createuserid from sys_userteam where siteid='" + controller.siteid + "' and userid in " + userids + " and isproxy = 1))) and ownertable='" + ownertable + "' and ownerid=" + alias + "." + controller.getuniquecolumnname(ownertable) + " )";
|
|
|
- str = str.replace("[", "(").replace("]", ")");
|
|
|
- break;
|
|
|
- }
|
|
|
- case 3: {
|
|
|
- if (subUserIds.size() == 0) {
|
|
|
- str = " exists(select sys_datateamid from sys_datateam where siteid='" + controller.siteid + "' and isleader=1 and userid in ('') and ownertable='" + ownertable + "' and ownerid=" + alias + "." + controller.getuniquecolumnname(ownertable) + " )";
|
|
|
- } else {
|
|
|
- str = " exists(select sys_datateamid from sys_datateam where siteid='" + controller.siteid + "' and isleader=1 and userid in " + subUserIds + " and ownertable='" + ownertable + "' and ownerid=" + alias + "." + controller.getuniquecolumnname(ownertable) + " )";
|
|
|
-
|
|
|
- }
|
|
|
- str = str.replace("[", "(").replace("]", ")");
|
|
|
- break;
|
|
|
- }
|
|
|
- case 4: {
|
|
|
- if (subUserIds.size() == 0) {
|
|
|
- str = " exists(select sys_datateamid from sys_datateam where siteid='" + controller.siteid + "' and isleader=0 and userid in ('') and ownertable='" + ownertable + "' and ownerid=" + alias + "." + controller.getuniquecolumnname(ownertable) + " )";
|
|
|
- } else {
|
|
|
- str = " exists(select sys_datateamid from sys_datateam where siteid='" + controller.siteid + "' and isleader=0 and userid in " + subUserIds + " and ownertable='" + ownertable + "' and ownerid=" + alias + "." + controller.getuniquecolumnname(ownertable) + " )";
|
|
|
- }
|
|
|
- str = str.replace("[", "(").replace("]", ")");
|
|
|
- break;
|
|
|
- }
|
|
|
- case 5: {
|
|
|
- str = alias + ".createuserid in" + userids + " ";
|
|
|
- str = str.replace("[", "(").replace("]", ")");
|
|
|
- break;
|
|
|
- }
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- return str;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 添加我的团队里的所有成员
|
|
|
*
|
|
|
@@ -800,29 +748,19 @@ public class DataTeam {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static ArrayList<Long> getSubUserIds2(Controller controller) throws YosException {
|
|
|
+ public static ArrayList<Long> getSubAreaUserIds(Controller controller) throws YosException {
|
|
|
ArrayList<Long> userids = new ArrayList<>();
|
|
|
- if (controller.departmentid > 0) {
|
|
|
- ArrayList<Long> departmentids = Department.getSubDepartmentIds(controller, controller.departmentid);
|
|
|
- if (controller.isleader) {
|
|
|
- departmentids.add(controller.departmentid);
|
|
|
- }
|
|
|
- SQLFactory sqlFactory = new SQLFactory("sql:select userid from sys_hr where siteid='" + controller.siteid + "' and departmentid in $departmentid$ ");
|
|
|
- sqlFactory.addParameter_in("departmentid", departmentids);
|
|
|
- userids.addAll(sqlFactory.runSqlQuery(controller.dbConnect).toArrayList("userid", new ArrayList<>()));
|
|
|
- /*
|
|
|
- 汇报对象是自己的
|
|
|
- */
|
|
|
- userids.addAll(controller.dbConnect.runSqlQuery("select userid from sys_hr where siteid='" + controller.siteid + "' and reporthrid=" + controller.hrid).toArrayList("userid", new ArrayList<>()));
|
|
|
-
|
|
|
- //排除本部门其他负责人
|
|
|
- for (Long id : Department.getLeaderUserids(controller)) {
|
|
|
- if (id != controller.userid) {
|
|
|
- userids.remove(id);
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (controller.sys_enterpriseid > 0 && controller.isleader) {
|
|
|
- userids.addAll(controller.dbConnect.runSqlQuery("select userid from sys_enterprise_hr where siteid='" + controller.siteid + "' and sys_enterpriseid=" + controller.sys_enterpriseid).toArrayList("userid", new ArrayList<>()));
|
|
|
+
|
|
|
+ String sql = "SELECT t1.sa_saleareaid from sys_enterprise_tradefield t1 " +
|
|
|
+ "inner join sys_hr t2 ON t2.hrid=t1.hrid and t2.siteid=t1.siteid " +
|
|
|
+ "WHERE t1.siteid='" + controller.siteid + "' and t2.userid='" + controller.userid + "' ";
|
|
|
+ ArrayList<Long> sa_saleareaids = controller.dbConnect.runSqlQuery(sql).toArrayList("sa_saleareaid", new ArrayList<>());
|
|
|
+ sa_saleareaids.add(-1L);
|
|
|
+ sa_saleareaids = SaleArea.getSubSaleAreaIds(controller, sa_saleareaids);
|
|
|
+ if (sa_saleareaids.size() > 0) {
|
|
|
+ userids.addAll(controller.dbConnect.runSqlQuery("SELECT DISTINCT t2.userid from sa_salearea_hr t1 " +
|
|
|
+ "inner join sys_hr t2 ON t2.hrid=t1.hrid and t2.siteid=t1.siteid " +
|
|
|
+ "WHERE t1.siteid='" + controller.siteid + "' and t1.sa_saleareaid in(" + StringUtils.join(sa_saleareaids, ",") + ") and t2.userid>0").toArrayList("userid", new ArrayList<>()));
|
|
|
}
|
|
|
userids.remove(controller.userid);
|
|
|
return userids;
|