#处理excel文件导入到系统表

feature-LeeD-20221025
WangJie 3 years ago
parent 1b64d49b9a
commit 427e0a1a36

@ -0,0 +1,145 @@
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Objects" %>
<%@ page import="weaver.interfaces.util.ReadExcel" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.HashMap" %>
<%--
User: wangj
Design Ideas
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
ReadExcel r = new ReadExcel();
RecordSet rs = new RecordSet();
int scount = 0;
int fcount = 0;
List<Map<String, String>> lists = r.readExcel("/whalecloud/cos", "organization.xlsx", 0, 0, 0);
if (Objects.nonNull(lists)) {
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
// m.forEach((key, value) -> {
// System.out.println(key + ":" + value);
// });
int ORG_LEVEL = Util.getIntValue(m.get("org_level"));
String ORG_ID = m.get("org_id");
String ORG_TYPE = m.get("org_type");
String PARENT_ORG_ID = m.get("parent_org_id");
String ORG_CODE = m.get("org_code");
String ORG_NAME = m.get("org_name");
//状态正常
String canceled = "";
//一级部门
if (ORG_LEVEL == 1) {
String subcompany = "59";
String supdepid = "0";
boolean flag = insertDepartment(ORG_NAME, ORG_CODE, canceled, subcompany, supdepid, ORG_ID);
if (flag) {
scount++;
} else {
fcount++;
}
}
//下及部门
if (ORG_LEVEL > 1) {
Map<String, String> map = new HashMap<>();
map = getSubcompanyid1(lists, PARENT_ORG_ID);
String subcompany = map.get("subcompanyid1");
String supdepid = map.get("supdepid");
boolean flag = insertDepartment(ORG_NAME, ORG_CODE, canceled, subcompany, supdepid, ORG_ID);
if (flag) {
scount++;
} else {
fcount++;
}
}
}
}
out.print("success:" + scount + ",false:" + fcount);
%>
<%!
private String getSubcompanyid(List<Map<String, String>> lists, String id) {
RecordSet rs = new RecordSet();
String Subcompanyid = "";
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String ORG_ID = m.get("org_id");
String ORG_NAME = m.get("org_name");
String ORG_CODE = m.get("org_code");
String PARENT_ORG_ID = m.get("parent_org_id");
if (ORG_ID.equals(id)) {
rs.execute("select id from hrmsubcompany where SUBCOMPANYCODE = '" + ORG_CODE + "'");
while (rs.next()) {
Subcompanyid = Util.null2String(rs.getString("id"));
}
}
}
return Subcompanyid;
}
%>
<%!
private Map<String, String> getSubcompanyid1(List<Map<String, String>> lists, String id) {
Map<String, String> res = new HashMap<>();
RecordSet rs = new RecordSet();
String subcompanyid1 = "";
String supdepid = "";
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String ORG_ID = m.get("org_id");
String ORG_CODE = m.get("org_code");
if (ORG_ID.equals(id)) {
rs.execute("select id,subcompanyid1 from hrmdepartment where departmentcode = '" + ORG_CODE + "'");
while (rs.next()) {
supdepid = Util.null2String(rs.getString("id"));
subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
res.put("supdepid", supdepid);
res.put("subcompanyid1", subcompanyid1);
}
}
}
return res;
}
%>
<%!
private boolean insertDepartment(String ORG_NAME, String ORG_CODE, String canceled, String subcompanyid1, String supdepid, String ORG_ID) {
RecordSet rs = new RecordSet();
boolean isexist = false;
boolean flag = false;
String sql = "select count(1) as sl from hrmdepartment where departmentcode = ?";
rs.executeQuery(sql,ORG_CODE);
while (rs.next()){
if(Util.getIntValue(rs.getString("sl"))>0){
isexist = true;
}
}
if(isexist){
String deptUpdateSql = " update hrmdepartment set departmentmark=?,departmentname=?,canceled=?," +
" subcompanyid1=?,showorder=?, supdepid=? where departmentcode=? ";
flag = rs.executeUpdate(deptUpdateSql,new Object[]{ORG_NAME,ORG_NAME,canceled,subcompanyid1,ORG_ID,supdepid,ORG_CODE});
}else{
String deptInsertSql = " insert into hrmdepartment(departmentmark,departmentname,departmentcode," +
" canceled,subcompanyid1,supdepid,showorder) values(?,?,?,?,?,?,?) ";
flag = rs.executeUpdate(deptInsertSql, new Object[]{ORG_NAME, ORG_NAME, ORG_CODE, canceled, subcompanyid1, supdepid, ORG_ID});
}
return flag;
}
%>

@ -0,0 +1,133 @@
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Objects" %>
<%@ page import="weaver.interfaces.util.ReadExcel" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.apache.commons.codec.digest.DigestUtils" %>
<%@ page import="weaver.general.TimeUtil" %>
<%--
User: wangj
Design Ideas
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
ReadExcel r = new ReadExcel();
RecordSet rs = new RecordSet();
int scount = 0;
int fcount = 0;
List<Map<String, String>> deptlists = r.readExcel("/whalecloud/cos", "organization.xlsx", 0, 0, 0);
List<Map<String, String>> hrmlists = r.readExcel("/whalecloud/cos", "staff.xlsx", 0, 0, 0);
if (Objects.nonNull(hrmlists)) {
for (int i = 0; i < hrmlists.size(); i++) {
Map<String, String> h = hrmlists.get(i);
//部门id
String ORG_ID = Util.null2String(h.get("org_id"));
String STAFF_CODE = Util.null2String(h.get("staff_code"));
String pwd = "1";
String creator = "1";
String jobTitleId = "464";
String password = DigestUtils.md5Hex(pwd).toUpperCase(); //MD5加密
String STAFF_NAME = Util.null2String(h.get("staff_name"));
Map<String,String> res = getSubcompanyid1(deptlists,ORG_ID);
String deptId = Util.null2String(res.get("deptid"));
String subcompanyid1 = Util.null2String(res.get("subcompanyid1"));
if("".equals(deptId)) continue;
String E_MAIL = Util.null2String(h.get("e_mail"));
String MOBILE_PHONE = Util.null2String(h.get("mobile_phone"));
String STATUS_CD = Util.null2String(h.get("status_cd"));
String status = "1";
if("1100".equals(STATUS_CD) || "1200".equals(STATUS_CD) || "1300".equals(STATUS_CD)){
status = "5";
}
String STAFF_ID = Util.null2String(h.get("staff_id"));
String systemlanguage = "8" ;
String currentDate = TimeUtil.getCurrentDateString();//当前日期
String currentDateTime = TimeUtil.getCurrentTimeString(); //当前时间
String locationid = "2" ;
String seclevel = "20" ;
String createrid = "1" ;
String lastmodid = "1" ;
boolean flag = insertHrmresource( STAFF_CODE, password, STAFF_NAME, deptId, subcompanyid1, creator, E_MAIL, MOBILE_PHONE, jobTitleId, status,
STAFF_ID, systemlanguage, currentDate, currentDateTime, locationid, seclevel, createrid, lastmodid);
if(flag){
scount++;
}else{
fcount++;
}
}
}
out.print("success:" + scount + ",false:" + fcount);
%>
<%!
private Map<String, String> getSubcompanyid1(List<Map<String, String>> lists, String id) {
Map<String, String> res = new HashMap<>();
RecordSet rs = new RecordSet();
String subcompanyid1 = "";
String deptid = "";
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String ORG_ID = m.get("org_id");
String ORG_CODE = m.get("org_code");
if (ORG_ID.equals(id)) {
rs.execute("select id,subcompanyid1 from hrmdepartment where departmentcode = '" + ORG_CODE + "'");
while (rs.next()) {
deptid = Util.null2String(rs.getString("id"));
subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
res.put("deptid", deptid);
res.put("subcompanyid1", subcompanyid1);
}
}
}
return res;
}
%>
<%!
private boolean insertHrmresource(String STAFF_CODE,String password,String STAFF_NAME,String deptId,String subcompanyid1,String creator,String E_MAIL,String MOBILE_PHONE,String jobTitleId,String status,
String STAFF_ID,String systemlanguage,String currentDate,String currentDateTime,String locationid,String seclevel,String createrid,String lastmodid) {
RecordSet rs = new RecordSet();
boolean flag = false;
String loginid = "";
String sql = " select loginid from hrmresource where workcode=?" ;
rs.executeQuery(sql,new Object[]{STAFF_CODE});
if(rs.next()){
loginid = Util.null2String(rs.getString("loginid"));
}
if(!"".equals(loginid)){
String userUpdateSql = " update hrmresource set lastname=?,departmentid=?,subcompanyid1=?," +
" creater=?,email=?,mobile=?,jobtitle=?,status=?,dsporder=?,lastmoddate=?,modified=? where workcode=? ";
flag = rs.executeUpdate(userUpdateSql,new Object[]{STAFF_NAME,deptId,subcompanyid1,creator,E_MAIL,
MOBILE_PHONE,jobTitleId,status,STAFF_ID,currentDate,currentDateTime,STAFF_CODE});
}else{
rs.executeProc("HrmResourceMaxId_Get", "");
rs.next();
String id = "" + rs.getInt(1);
String userInsertSql = " insert into hrmresource(id,loginid,password,workcode,lastname,departmentid,subcompanyid1," +
"creater,email,mobile,jobtitle,status,dsporder,systemlanguage,createdate,lastmoddate,created,modified," +
"locationid,seclevel,createrid,lastmodid) " +
" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
flag = rs.executeUpdate(userInsertSql,new Object[]{id,STAFF_CODE,password,STAFF_CODE,STAFF_NAME,deptId,subcompanyid1,
creator,E_MAIL,MOBILE_PHONE,jobTitleId,status,STAFF_ID,systemlanguage,currentDate,currentDate,currentDateTime,currentDateTime,
locationid,seclevel,createrid,lastmodid});
}
return flag;
}
%>

@ -0,0 +1,104 @@
<%@ page import="weaver.interfaces.util.ReadExcel" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="weaver.backup.fkcustomer.FkCustomerBrowserDef" %>
<%--
User: wangj
Design Ideas
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
ReadExcel r = new ReadExcel();
RecordSet rs = new RecordSet();
int scount = 0;
int fcount = 0;
String creater = "1";
String created = TimeUtil.getCurrentTimeString();
String modified = TimeUtil.getCurrentTimeString();
String modifier = "1";
List<Map<String, String>> deptlists = r.readExcel("/whalecloud/cos", "organization.xlsx", 0, 0, 0);
List<Map<String, String>> lists = r.readExcel("/whalecloud/cos", "system_post.xlsx", 0, 0, 0);
if (Objects.nonNull(lists)) {
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String SYS_POST_CODE = Util.null2String(m.get("SYS_POST_CODE"));
String SYS_POST_NAME = Util.null2String(m.get("SYS_POST_NAME"));
String IS_SYNC = Util.null2String(m.get("IS_SYNC"));
if (!"YES".equals(IS_SYNC)) {
continue;
}
String allname = "~`~`7 " + SYS_POST_NAME + "`~`8 " + SYS_POST_NAME + "`~`~";
String ORG_ID = Util.null2String(m.get("ORG_ID"));
Map<String, String> res = getSubcompanyid1(deptlists, ORG_ID);
String deptid = Util.null2String(res.get("deptid"));
boolean flag = insertPost(allname, creater, created, modified, modifier, SYS_POST_CODE, deptid);
if (flag) {
scount++;
} else {
fcount++;
}
}
}
out.print("success:" + scount + ",false:" + fcount);
%>
<%!
private boolean insertPost(String allname, String creater, String created, String modified, String modifier, String sysPostCode, String departmentId) {
RecordSet rs = new RecordSet();
boolean iflag = false;
String groupsid = "803";
String jobactivitiesid = "233";
String uuid = UUID.randomUUID().toString();
String id = "";
String sql = "select id from hrmjobtitles where jobtitlecode = ?";
rs.executeQuery(sql,new Object[]{sysPostCode});
while (rs.next()){
id = Util.null2String(rs.getString("id"));
}
if(!"".equals(id)){
String updateHrmjobactivitiesSl = "update hrmjobtitles set jobtitlemark=?,jobtitlename=?,modified=?,modifier=? where id=?";
iflag = rs.executeUpdate(updateHrmjobactivitiesSl,allname,allname,modified,modifier,id);
}else{
uuid = UUID.randomUUID().toString();
String insertHrmjobactivitiesSql = " insert into hrmjobtitles(jobtitlemark,jobtitlename,jobactivityid,jobdepartmentid,jobtitlecode,created,creater,modified,modifier,uuid) values(?,?,?,?,?,?,?,?,?,?)";
iflag = rs.executeUpdate(insertHrmjobactivitiesSql, new Object[]{allname, allname, jobactivitiesid, departmentId, sysPostCode, created, creater, modified, modifier, uuid});
}
return iflag;
}
%>
<%!
private Map<String, String> getSubcompanyid1(List<Map<String, String>> lists, String id) {
Map<String, String> res = new HashMap<>();
RecordSet rs = new RecordSet();
String subcompanyid1 = "";
String deptid = "";
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String ORG_ID = m.get("ORG_ID");
String ORG_CODE = m.get("org_code");
if (ORG_ID.equals(id)) {
rs.execute("select id,subcompanyid1 from hrmdepartment where departmentcode = '" + ORG_CODE + "'");
while (rs.next()) {
deptid = Util.null2String(rs.getString("id"));
subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
res.put("deptid", deptid);
res.put("subcompanyid1", subcompanyid1);
}
}
}
return res;
}
%>

@ -0,0 +1,144 @@
<%@ page import="weaver.interfaces.util.ReadExcel" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="weaver.backup.fkcustomer.FkCustomerBrowserDef" %>
<%--
User: wangj
Design Ideas
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
ReadExcel r = new ReadExcel();
RecordSet rs = new RecordSet();
int scount = 0;
int fcount = 0;
String creater = "1";
String created = TimeUtil.getCurrentTimeString();
String modified = TimeUtil.getCurrentTimeString();
String modifier = "1";
List<Map<String, String>> deptlists = r.readExcel("/whalecloud/cos", "organization.xlsx", 0, 0, 0);
List<Map<String, String>> postlists = r.readExcel("/whalecloud/cos", "system_post.xlsx", 0, 0, 0);
List<Map<String, String>> lists = r.readExcel("/whalecloud/cos", "system_user_post.xlsx", 0, 0, 0);
List<Map<String, String>> hrmlists = r.readExcel("/whalecloud/cos", "staff.xlsx", 0, 0, 0);
if (Objects.nonNull(lists)) {
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String ORG_ID = Util.null2String(m.get("org_id"));
Map<String,String> deptres = getSubcompanyid1(deptlists,ORG_ID);
String postCode = Util.null2String(m.get("sys_post_code"));
String userCode =Util.null2String(m.get("staff_code"));
String departmentId = Util.null2String(deptres.get("deptid"));
boolean flag = insertPostUser(postCode, departmentId, userCode);
if (flag) {
scount++;
} else {
fcount++;
}
}
}
out.print("success:" + scount + ",false:" + fcount);
%>
<%!
private boolean insertPostUser(String postCode, String departmentId,String userCode) {
RecordSet rs = new RecordSet();
boolean flag = false;
String jobtitlesId = "";
String userId = "";
String currentDateTime = TimeUtil.getCurrentTimeString(); //当前时间
String updateStaff = "1";
String queryRoleIdSql = " select id from hrmjobtitles where jobtitlecode= ?";
rs.executeQuery(queryRoleIdSql, postCode);
if (rs.next()) {
jobtitlesId = rs.getString("id");
}
if("".equals(jobtitlesId)){
jobtitlesId = "464";
}
String sql = "select id from hrmresource where loginid = ?";
rs.executeQuery(sql,userCode);
while (rs.next()) {
userId = Util.null2String(rs.getString("id"));
}
if (!"".equals(userId) && !"".equals(jobtitlesId)) {
String updateUserJobSql = "update hrmresource set jobtitle=?,modified=?,modifier=? where id=?";
flag = rs.executeUpdate(updateUserJobSql, jobtitlesId, currentDateTime, updateStaff, userId);
}
return flag;
}
%>
<%!
private String getUserCode(List<Map<String, String>> lists, String id) {
String code = "";
RecordSet rs = new RecordSet();
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String STAFF_ID = Util.null2String(m.get("staff_id"));
String STAFF_CODE = Util.null2String(m.get("staff_code"));
if (STAFF_ID.equals(id)) {
code= STAFF_CODE;
}
}
return code;
}
%>
<%!
private Map<String, String> getSubcompanyid1(List<Map<String, String>> lists, String id) {
Map<String, String> res = new HashMap<>();
RecordSet rs = new RecordSet();
String subcompanyid1 = "";
String deptid = "";
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String ORG_ID = m.get("org_id");
String ORG_CODE = m.get("org_code");
if (ORG_ID.equals(id)) {
rs.execute("select id,subcompanyid1 from hrmdepartment where departmentcode = '" + ORG_CODE + "'");
while (rs.next()) {
deptid = Util.null2String(rs.getString("id"));
subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
res.put("deptid", deptid);
res.put("subcompanyid1", subcompanyid1);
}
}
}
return res;
}
%>
<%!
private String getPostCode(List<Map<String, String>> lists, String id) {
String postcode = "";
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String SYS_POST_CODE = Util.null2String(m.get("sys_post_code"));
String SYS_POST_ID = Util.null2String(m.get("sys_post_id"));
if (SYS_POST_ID.equals(id)) {
postcode = SYS_POST_CODE;
break;
}
}
return postcode;
}
%>

@ -0,0 +1,68 @@
<%@ page import="weaver.interfaces.util.ReadExcel" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="weaver.backup.fkcustomer.FkCustomerBrowserDef" %>
<%--
User: wangj
Design Ideas
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
ReadExcel r = new ReadExcel();
int scount = 0;
int fcount = 0;
List<Map<String, String>> lists = r.readExcel("/whalecloud/cos", "system_roles.xlsx", 0, 0, 0);
if (Objects.nonNull(lists)) {
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String SYS_ROLE_CODE = Util.null2String(m.get("SYS_ROLE_CODE"));
String SYS_ROLE_NAME = Util.null2String(m.get("SYS_ROLE_NAME"));
String IS_SYNC = Util.null2String(m.get("IS_SYNC"));
if(!"YES".equals(IS_SYNC)){
continue;
}
boolean flag = insertRole(SYS_ROLE_CODE, SYS_ROLE_NAME);
if (flag) {
scount++;
} else {
fcount++;
}
}
}
out.print("success:" + scount + ",false:" + fcount);
%>
<%!
private boolean insertRole(String sysRoleCode, String sysRoleName) {
boolean flag = false;
RecordSet rs = new RecordSet();
String rolesmark = "~`~`7 " + sysRoleName + "`~`8 " + sysRoleName + "`~`9 " + sysRoleName + "`~`~";
String rolesname = "~`~`7 " + sysRoleName + "`~`8 " + sysRoleName + "`~`9 " + sysRoleName + "`~`~";
String type = "0";
String subcompanyid = "0";
String uuid = UUID.randomUUID().toString();
String queryRoleSql = "select id from hrmroles where ecology_pinyin_search=?";
rs.executeQuery(queryRoleSql, sysRoleCode);
String id = "";
if (rs.next()) {
id = rs.getString("id");
}
if ("".equals(id)) {
String insertHrmrolesSql = " insert into hrmroles(rolesmark,rolesname,type,subcompanyid,ecology_pinyin_search,uuid) values(?,?,?,?,?,?)";
flag = rs.executeUpdate(insertHrmrolesSql, new Object[]{rolesmark, rolesname, type, subcompanyid, sysRoleCode, uuid});
} else {
String updateHrmrolesSql = " update hrmroles set rolesmark=?,rolesname=? where id=?";
flag = rs.executeUpdate(updateHrmrolesSql, sysRoleName, sysRoleName, id);
}
return flag;
}
%>

@ -0,0 +1,124 @@
<%@ page import="weaver.interfaces.util.ReadExcel" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="weaver.backup.fkcustomer.FkCustomerBrowserDef" %>
<%@ page import="com.icbc.api.internal.apache.http.impl.cookie.S" %>
<%--
User: wangj
Design Ideas
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
ReadExcel r = new ReadExcel();
int scount = 0;
int fcount = 0;
List<Map<String, String>> rolelists = r.readExcel("/whalecloud/cos", "system_roles.xlsx", 0, 0, 0);
List<Map<String, String>> userlists = r.readExcel("/whalecloud/cos", "system_roles.xlsx", 0, 0, 0);
List<Map<String, String>> lists = r.readExcel("/whalecloud/cos", "system_user_role.xlsx", 0, 0, 0);
if (Objects.nonNull(lists)) {
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String SYS_ROLE_ID = Util.null2String(m.get("SYS_ROLE_ID"));
String SYS_USER_ID = Util.null2String(m.get("SYS_USER_ID"));
String SYS_ROLE_CODE = getRoleCode(rolelists,SYS_ROLE_ID);
String SYS_USER_CODE = getUserCode(userlists,SYS_USER_ID);
if (!"".equals(SYS_ROLE_CODE) && !"".equals(SYS_USER_CODE)) {
boolean flag = insertRoleUser(SYS_ROLE_CODE, SYS_USER_CODE);
if (flag) {
scount++;
} else {
fcount++;
}
}
}
}
out.print("success:" + scount + ",false:" + fcount);
%>
<%!
private boolean insertRoleUser(String systemUserCode, String roleCode) {
boolean flag = false;
RecordSet rs = new RecordSet();
String userId = "";
String roleId = "";
String rolelevel = "2"; //总部=2;分部=1;部门=0
String resourcetype = "1"; //1=人力资源
String sql = " select id from hrmresource where loginid=?";
rs.executeQuery(sql, new Object[]{systemUserCode});
if (rs.next()) {
userId = Util.null2String(rs.getString("id"));
}
String queryRoleIdSql = "select id from hrmroles where ecology_pinyin_search=?";
rs.executeQuery(queryRoleIdSql, roleCode);
if (rs.next()) {
roleId = rs.getString("id");
}
if (!"".equals(userId) && !"".equals(roleId)) {
//查看是否已存在角色用户关系
String releationId = "";
String ifExistSql = "select id from hrmrolemembers where roleid=? and resourceid=?";
rs.executeQuery(ifExistSql, roleId, userId);
if (rs.next()) {
releationId = rs.getString("id");
}
if (!"".equals(releationId)) {
String delHrmrolemembersSql = " delete from hrmrolemembers where id = ?";
flag = rs.executeUpdate(delHrmrolemembersSql, releationId);
} else {
String insertHrmrolemembersSql = "insert into hrmrolemembers(roleid,resourceid,rolelevel,resourcetype,uuid) values(?,?,?,?,?)";
flag = rs.executeUpdate(insertHrmrolemembersSql, roleId, userId, rolelevel, resourcetype, UUID.randomUUID().toString());
}
}
return flag;
}
%>
<%!
private String getUserCode(List<Map<String, String>> lists, String id) {
String code = "";
RecordSet rs = new RecordSet();
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String STAFF_ID = Util.null2String(m.get("STAFF_ID"));
String STAFF_CODE = Util.null2String(m.get("STAFF_CODE"));
if (STAFF_ID.equals(id)) {
code= STAFF_CODE;
}
}
return code;
}
%>
<%!
private String getRoleCode(List<Map<String, String>> lists, String id) {
String code = "";
RecordSet rs = new RecordSet();
for (int i = 0; i < lists.size(); i++) {
Map<String, String> m = lists.get(i);
String SYS_ROLE_ID = Util.null2String(m.get("SYS_ROLE_ID"));
String SYS_ROLE_CODE = Util.null2String(m.get("SYS_ROLE_CODE"));
if (SYS_ROLE_ID.equals(id)) {
code= SYS_ROLE_CODE;
}
}
return code;
}
%>

@ -0,0 +1,192 @@
package weaver.interfaces.util;
/**
*
*
* @author wangj
* @version 1.00
* @Date 2022/10/17
*/
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;
/**
* Excel
* @author wangj
* @createTime 2020-11-30 22:54:21
* @version 1.1
* @modifyLog 1.1
*
*/
public class ReadExcel {
/**
* Excel
* @author zql
* @createTime 2020-11-30 22:54:34
*
* @param filepath
* @param filename
* @param startrow 0
* @param startcol 0
* @param sheetnum 簿0
* @return
*/
public List<Map<String, String>> readExcel(String filepath, String filename, int startrow, int startcol, int sheetnum) {
List<Map<String, String>> varList = new ArrayList<Map<String, String>>();
if (filename.endsWith(".xls")) {
varList = this.readExcel2003(filepath, filename, startrow, startcol, sheetnum);
} else if (filename.endsWith(".xlsx")) {
varList = this.readExcel2007(filepath, filename, startrow, startcol, sheetnum);
} else {
System.out.println("Only excel files with XLS or XLSX suffixes are allowed to be read!");
return null;
}
return varList;
}
/**
* 2003Excel
* @author zql
* @createTime 2020-11-30 22:57:35
*
* @param filepath
* @param filename
* @param startrow 0
* @param startcol 0
* @param sheetnum 簿0
* @return
*/
public List<Map<String,String>> readExcel2003(String filepath, String filename, int startrow, int startcol, int sheetnum) {
List<Map<String, String>> varList = new ArrayList<Map<String, String>>();
try {
ZipSecureFile.setMinInflateRatio(0);
File target = new File(filepath, filename);
FileInputStream fis = new FileInputStream(target);
HSSFWorkbook wb = new HSSFWorkbook(fis);
fis.close();
// sheet 从0开始
HSSFSheet sheet = wb.getSheetAt(sheetnum);
// 取得最后一行的行号
int rowNum = sheet.getLastRowNum() + 1;
HSSFRow rowTitle = sheet.getRow(0);
// 标题行的最后一个单元格位置
int cellTitleNum = rowTitle.getLastCellNum();
String[] title = new String[cellTitleNum];
for (int i = startcol; i < cellTitleNum; i++) {
HSSFCell cell = rowTitle.getCell(Short.parseShort(String.valueOf(i)));
if (Objects.nonNull(cell)) {
cell.setCellType(CellType.STRING);
title[i] = cell.getStringCellValue();
} else {
title[i] = "";
}
}
// 行循环开始
for (int i = startrow + 1; i < rowNum; i++) {
Map<String, String> varpd = new HashMap<String, String>();
// 行
HSSFRow row = sheet.getRow(i);
// 列循环开始
for (int j = startcol; j < cellTitleNum; j++) {
HSSFCell cell = row.getCell(Short.parseShort(String.valueOf(j)));
String cellValue = "";
if (Objects.nonNull(cell)) {
// 把类型先设置为字符串类型
cell.setCellType(CellType.STRING);
cellValue = cell.getStringCellValue();
}
varpd.put(title[j], cellValue);
}
varList.add(varpd);
}
wb.close();
} catch (Exception e) {
System.out.println(e);
}
return varList;
}
/**
* 2007Excel
* @author zql
* @createTime 2020-11-30 23:23:20
*
* @param filepath
* @param filename
* @param startrow 0
* @param startcol 0
* @param sheetnum 簿0
* @return
*/
public List<Map<String,String>> readExcel2007(String filepath, String filename, int startrow, int startcol, int sheetnum) {
List<Map<String, String>> varList = new ArrayList<Map<String, String>>();
try {
ZipSecureFile.setMinInflateRatio(0);
File target = new File(filepath, filename);
InputStream ins = new FileInputStream(target);
XSSFWorkbook wb = new XSSFWorkbook(ins);
ins.close();
// 得到Excel工作表对象
XSSFSheet sheet = wb.getSheetAt(sheetnum);
// 取得最后一行的行号
int rowNum = sheet.getLastRowNum() + 1;
XSSFRow rowTitle = sheet.getRow(0);
int cellTitleNum = rowTitle.getLastCellNum();
String[] title = new String[cellTitleNum];
for (int i = startcol; i < cellTitleNum; i++) {
XSSFCell cell = rowTitle.getCell(Short.parseShort(String.valueOf(i)));
if (Objects.nonNull(cell)) {
// 把类型先设置为字符串类型
cell.setCellType(CellType.STRING);
title[i] = cell.getStringCellValue();
} else {
title[i] = "";
}
}
// 行循环开始
for (int i = startrow + 1; i < rowNum; i++) {
Map<String, String> varpd = new HashMap<String, String>();
// 得到Excel工作表的行
XSSFRow row = sheet.getRow(i);
// 列循环开始
for (int j = startcol; j < cellTitleNum; j++) {
// 得到Excel工作表指定行的单元格
XSSFCell cell = row.getCell(j);
String cellValue = "";
if (Objects.nonNull(cell)) {
// 把类型先设置为字符串类型
cell.setCellType(CellType.STRING);
cellValue = cell.getStringCellValue();
}
varpd.put(title[j], cellValue);
}
varList.add(varpd);
}
wb.close();
} catch (Exception e) {
System.out.println(e);
}
return varList;
}
}
Loading…
Cancel
Save