You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
haojing/interface/hjkj/updateDepartMentCode.jsp

146 lines
5.2 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.dito.util.ReadExcel" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.Objects" %>
<%--
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;
}
%>