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.
293 lines
12 KiB
Java
293 lines
12 KiB
Java
package com.engine.dito.excel.cmd;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import weaver.conn.RecordSet;
|
|
import weaver.formmode.setup.ModeRightInfo;
|
|
import weaver.general.BaseBean;
|
|
import weaver.general.Util;
|
|
import weaver.interfaces.dito.comInfo.PropBean;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
|
|
|
|
public class ImportExcelDeptUtil {
|
|
|
|
/***
|
|
*
|
|
* @param datalists
|
|
*/
|
|
public Map<String,String> operateHrmdepartmentExcel(List<Map<String, String>> datalists)
|
|
{
|
|
int scount = 0;
|
|
int fcount = 0;
|
|
BaseBean bb = new BaseBean();
|
|
String subcompany = PropBean.getUfPropValue("excel.subcompany"); //"59";
|
|
String supdepid = PropBean.getUfPropValue("excel.supdepid"); //0;
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
String nowDateTime = sdf.format(new Date());
|
|
|
|
|
|
for (int i = 0; i < datalists.size(); i++)
|
|
{
|
|
Map<String, String> m = datalists.get(i);
|
|
m.forEach((key, value) -> {
|
|
System.out.println(key + ":" + value);
|
|
});
|
|
|
|
try{
|
|
int ORG_LEVEL = Util.getIntValue(m.get("org_level"));
|
|
String ORG_ID = m.get("org_id");
|
|
String PARENT_ORG_ID = m.get("parent_org_id");
|
|
String ORG_CODE = m.get("org_code");
|
|
String ORG_NAME = m.get("org_name");
|
|
|
|
bb.writeLog("ORG_LEVEL:"+ORG_LEVEL);
|
|
bb.writeLog("ORG_ID:"+ORG_ID);
|
|
bb.writeLog("PARENT_ORG_ID:"+PARENT_ORG_ID);
|
|
bb.writeLog("ORG_CODE:"+ORG_CODE);
|
|
bb.writeLog("ORG_NAME:"+ORG_NAME);
|
|
|
|
String STATUS_CD = m.get("status_cd");
|
|
//状态正常
|
|
String canceled = "";
|
|
//一级部门
|
|
if (ORG_LEVEL == 1)
|
|
{
|
|
if(StringUtils.isNotEmpty(subcompany) && StringUtils.isNotEmpty(supdepid))
|
|
{
|
|
boolean flag = insertDepartment(ORG_NAME, ORG_CODE, canceled, subcompany, supdepid, ORG_ID);
|
|
if(flag){
|
|
scount++;
|
|
}else{
|
|
fcount++;
|
|
|
|
Map<String,String> dataMap = new HashMap<String,String>();
|
|
dataMap.put("syndate",nowDateTime);
|
|
dataMap.put("reqmessage", JSONObject.toJSONString(m));
|
|
dataMap.put("errmessage","更新部门SQL语句执行错误");
|
|
dataMap.put("systable","organization");
|
|
recordErrorData(dataMap);
|
|
|
|
}
|
|
}else{
|
|
Map<String,String> dataMap = new HashMap<String,String>();
|
|
dataMap.put("syndate",nowDateTime);
|
|
dataMap.put("reqmessage", JSONObject.toJSONString(m));
|
|
dataMap.put("errmessage","一级部门获取上级部门及分部失败");
|
|
dataMap.put("systable","organization");
|
|
recordErrorData(dataMap);
|
|
}
|
|
}else if(ORG_LEVEL > 1){
|
|
Map<String, String> map = getSubcompanyid1(datalists, PARENT_ORG_ID);
|
|
subcompany = map.get("subcompanyid1");
|
|
supdepid = map.get("supdepid");
|
|
if(StringUtils.isNotEmpty(subcompany) && StringUtils.isNotEmpty(supdepid))
|
|
{
|
|
boolean flag = insertDepartment(ORG_NAME, ORG_CODE, canceled, subcompany, supdepid, ORG_ID);
|
|
if(flag){
|
|
scount++;
|
|
}else{
|
|
fcount++;
|
|
|
|
Map<String,String> dataMap = new HashMap<String,String>();
|
|
dataMap.put("syndate",nowDateTime);
|
|
dataMap.put("reqmessage", JSONObject.toJSONString(m));
|
|
dataMap.put("errmessage","新增部门SQL语句执行错误");
|
|
dataMap.put("systable","organization");
|
|
recordErrorData(dataMap);
|
|
|
|
}
|
|
}else{
|
|
Map<String,String> dataMap = new HashMap<String,String>();
|
|
dataMap.put("syndate",nowDateTime);
|
|
dataMap.put("reqmessage", JSONObject.toJSONString(m));
|
|
dataMap.put("errmessage","获取上级部门及分部失败");
|
|
dataMap.put("systable","organization");
|
|
recordErrorData(dataMap);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
|
|
}
|
|
}
|
|
|
|
Map<String,String> dataMap = new HashMap<String, String>();
|
|
dataMap.put("scount",scount+"");
|
|
dataMap.put("fcount",fcount+"");
|
|
return dataMap;
|
|
}
|
|
|
|
|
|
/***
|
|
*
|
|
* @param lists
|
|
* @param id
|
|
* @return
|
|
*/
|
|
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 + "'");
|
|
if(rs.next())
|
|
{
|
|
supdepid = Util.null2String(rs.getString("id"));
|
|
subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
|
|
}
|
|
}
|
|
}
|
|
|
|
res.put("supdepid", supdepid);
|
|
res.put("subcompanyid1", subcompanyid1);
|
|
return res;
|
|
}
|
|
|
|
/***
|
|
*
|
|
* @param ORG_NAME
|
|
* @param ORG_CODE
|
|
* @param canceled
|
|
* @param subcompanyid1
|
|
* @param supdepid
|
|
* @param ORG_ID
|
|
* @return
|
|
*/
|
|
private boolean insertDepartment(String ORG_NAME, String ORG_CODE, String canceled, String subcompanyid1, String supdepid, String ORG_ID) {
|
|
RecordSet rs = new RecordSet();
|
|
boolean flag = false;
|
|
BaseBean bb = new BaseBean();
|
|
try{
|
|
String deptid = "" ;
|
|
String sql = "select id from hrmdepartment where departmentcode = ? ";
|
|
rs.executeQuery(sql,ORG_CODE);
|
|
if (rs.next()){
|
|
deptid = Util.null2String(rs.getString("id"));
|
|
}
|
|
|
|
if(StringUtils.isNotEmpty(deptid))
|
|
{
|
|
String deptUpdateSql = " update hrmdepartment set departmentmark=?,departmentname=?,canceled=?," +
|
|
" subcompanyid1=?,showorder=?, supdepid=? where id = ? ";
|
|
|
|
flag = rs.executeUpdate(deptUpdateSql,new Object[]{ORG_NAME,ORG_NAME,canceled,subcompanyid1,ORG_ID,supdepid,deptid});
|
|
|
|
}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});
|
|
if(flag)
|
|
{
|
|
sql = "select id from hrmdepartment where departmentcode = ?";
|
|
rs.executeQuery(sql,ORG_CODE);
|
|
if (rs.next()){
|
|
deptid = Util.null2String(rs.getString("id"));
|
|
}
|
|
}
|
|
}
|
|
|
|
if(flag)
|
|
{
|
|
String departmentdefinedid = "" ;
|
|
sql = " select id from hrmdepartmentdefined where deptid= ?";
|
|
rs.executeQuery(sql,new Object[]{deptid});
|
|
if (rs.next()){
|
|
departmentdefinedid = Util.null2String(rs.getString("id"));
|
|
}
|
|
bb.writeLog("departmentdefinedid:"+departmentdefinedid);
|
|
if(StringUtils.isNotEmpty(departmentdefinedid)){
|
|
sql = " update hrmdepartmentdefined set orgid = ? where deptid = ?" ;
|
|
bb.writeLog("sql:"+sql);
|
|
flag = rs.executeUpdate(sql,new Object[]{ORG_ID,deptid});
|
|
}else{
|
|
sql = " insert into hrmdepartmentdefined(deptid,orgid) values(?,?) " ;
|
|
bb.writeLog("sql:"+sql);
|
|
flag = rs.executeUpdate(sql,new Object[]{deptid,ORG_ID});
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
|
|
/***
|
|
*
|
|
* @param dataMap
|
|
*/
|
|
public void recordErrorData(Map<String,String> dataMap){
|
|
|
|
String uftable = "uf_orgmq" ;
|
|
RecordSet rs = new RecordSet();
|
|
BaseBean bb = new BaseBean();
|
|
ModeRightInfo mode=new ModeRightInfo();
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");//当前时间日期
|
|
SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
|
|
|
|
int formmodeid = 0 ;
|
|
String modedatacreater = "1" ;
|
|
String modedatacreatertype = "0" ;
|
|
String modedatacreatedate = sdf1.format(new Date());
|
|
String modedatacreatetime = sdf2.format(new Date());
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
try {
|
|
|
|
String sql =" select k.id from modeinfo k \n" +
|
|
" inner join workflow_bill l on formid = l.id\n" +
|
|
" where l.tablename = ? " ;
|
|
rs.executeQuery(sql,new Object[]{uftable});
|
|
if(rs.next()){
|
|
formmodeid = Util.getIntValue(Util.null2String(rs.getString("id")));
|
|
}
|
|
|
|
String syndate = Util.null2String(dataMap.get("syndate"));
|
|
String reqmessage = Util.null2String(dataMap.get("reqmessage"));
|
|
String errmessage = Util.null2String(dataMap.get("errmessage"));
|
|
String systable = Util.null2String(dataMap.get("systable"));
|
|
|
|
int bool = 0;
|
|
sql =" insert into "+uftable+"(uuid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,syndate,reqmessage,errmessage,systable)" +
|
|
" values(?,?,?,?,?,?,?,?,?,?)" ;
|
|
boolean flag = rs.executeUpdate(sql,new Object[]{uuid,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,syndate,reqmessage,errmessage,systable});
|
|
bb.writeLog("sql;"+sql);
|
|
if(flag){
|
|
bool++;
|
|
}
|
|
bb.writeLog("bool;"+bool);
|
|
if(bool>0)
|
|
{
|
|
String dataid = "";
|
|
sql = " select * from "+uftable+" where uuid=? ";
|
|
bb.writeLog("sql:" + sql);
|
|
rs.executeQuery(sql,new Object[]{uuid});
|
|
if (rs.next()) {
|
|
dataid = Util.null2String(rs.getString("id"));
|
|
}
|
|
bb.writeLog("sql:" + sql);
|
|
bb.writeLog("dataid:" + dataid);
|
|
bb.writeLog("modeid:" + formmodeid);
|
|
if (org.apache.commons.lang.StringUtils.isNotEmpty(dataid))
|
|
{
|
|
mode.setNewRight(true);
|
|
mode.editModeDataShare(Integer.valueOf(modedatacreater), formmodeid, Integer.parseInt(dataid));
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
bb.writeLog("e:"+e);
|
|
}
|
|
}
|
|
|
|
}
|