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.
weaver-ningbojinghua/src/weaver/interfaces/nbjh/action/UpdateResourceAction.java

430 lines
16 KiB
Java

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.

package weaver.interfaces.nbjh.action;
import org.apache.commons.lang3.StringUtils;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.*;
import java.util.*;
public class UpdateResourceAction implements Action {
@Override
public String execute(RequestInfo requestInfo) {
User user = requestInfo.getRequestManager().getUser();
MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
Property[] properties = mainTableInfo.getProperty();
// 流程主表数据
Map<String, String> mainData = new HashMap<>();
for (Property property : properties) {
mainData.put(property.getName(), property.getValue());
}
// 获取身份证号
String sfzh = mainData.get("sfzh");
// 姓名
String xm = mainData.get("xm");
RecordSet rs = new RecordSet();
// 根据身份证号/姓名获取获取员工ID
String resourceId = "";
if (StringUtils.isNotBlank(sfzh)) {
rs.executeQuery("select id from hrmresource where certificatenum = ?", sfzh);
if (rs.next()) {
resourceId = rs.getString("id");
}
if (StringUtils.isBlank(resourceId)) {
requestInfo.getRequestManager().setMessagecontent("当前身份证号未匹配到员工信息,请确认信息填写是否正确");
return FAILURE_AND_CONTINUE;
}
} else {
rs.executeQuery("select id from hrmresource where lastname = ?", xm);
if (rs.next()) {
resourceId = rs.getString("id");
}
if (StringUtils.isBlank(resourceId)) {
requestInfo.getRequestManager().setMessagecontent("当前姓名未匹配到人员信息,请确认信息填写是否正确");
return FAILURE_AND_CONTINUE;
}
}
BaseBean baseBean = new BaseBean();
baseBean.writeLog("UpdateResourceAction,开始更新主表照片字段人员ID===" + resourceId);
// 更新主表照片字段
String zp1 = mainData.get("zp1");
baseBean.writeLog("zp1====" + zp1);
String imageFileId = null;
if (StringUtils.isNotBlank(zp1)) {
String docId = zp1.split(",")[0];
baseBean.writeLog("docId====" + docId);
rs.executeQuery("select imagefileid from docimagefile where docid = ? ", docId);
if (rs.next()) {
imageFileId = rs.getString("imagefileid");
}
}
baseBean.writeLog("imageFileId====" + imageFileId);
if (StringUtils.isNotBlank(imageFileId)) {
rs.executeUpdate("update hrmresource set resourceimageid = ? where id = ? ", imageFileId, resourceId);
} else {
// 更新照片为null
rs.executeUpdate("update hrmresource set resourceimageid = null where id = ? ", resourceId);
}
baseBean.writeLog("UpdateResourceAction,更新主表照片字段结束");
String resourceimageid;
rs.executeQuery("select resourceimageid from hrmresource where id = ? ", resourceId);
if (rs.next()) {
resourceimageid = rs.getString("resourceimageid");
baseBean.writeLog("resourceimageid====" + resourceimageid);
} else {
baseBean.writeLog("resourceimageid,未查询到数据");
}
DetailTableInfo detailTableInfo = requestInfo.getDetailTableInfo();
// 学习履历
List<Map<String, String>> eduDetailDataList = getDetailDataList(detailTableInfo, 0);
// 工作履历
List<Map<String, String>> workDetailDataList = getDetailDataList(detailTableInfo, 1);
// 家庭主要成员
List<Map<String, String>> familyDetailDataList = getDetailDataList(detailTableInfo, 2);
// 插入明细表数据,插入前先删除原有数据
String formModeId = getModeIdByTableName("uf_xxll");
if (StringUtils.isNotBlank(formModeId)) {
rs.executeUpdate("delete from uf_xxll where xm = ? ", resourceId);
for (Map<String, String> detailMap : eduDetailDataList) {
Map<String, String> dataMap = new HashMap<>();
String uuid = UUID.randomUUID().toString();
dataMap.put("modeuuid", uuid);
dataMap.put("formmodeid", formModeId);
buildModeInsertFields(dataMap, user.getUID());
dataMap.put("xm", resourceId);
dataMap.put("xx", detailMap.get("xx"));
dataMap.put("zy", detailMap.get("zy"));
dataMap.put("ksrq", detailMap.get("ksrq"));
dataMap.put("jsrq", detailMap.get("jsrq"));
dataMap.put("bz", detailMap.get("bz"));
insertDetailData(dataMap, "uf_xxll");
refreshRight(uuid, "uf_xxll", formModeId, user.getUID());
}
}
formModeId = getModeIdByTableName("uf_gzll");
if (StringUtils.isNotBlank(formModeId)) {
rs.executeUpdate("delete from uf_gzll where xm = ? ", resourceId);
for (Map<String, String> detailMap : workDetailDataList) {
Map<String, String> dataMap = new HashMap<>();
String uuid = UUID.randomUUID().toString();
dataMap.put("modeuuid", uuid);
dataMap.put("formmodeid", formModeId);
buildModeInsertFields(dataMap, user.getUID());
dataMap.put("xm", resourceId);
dataMap.put("gzdw", detailMap.get("gzdw"));
dataMap.put("ksrq", detailMap.get("ksrq"));
dataMap.put("jsrq", detailMap.get("jsrq"));
dataMap.put("zw", detailMap.get("zw"));
dataMap.put("lzyy", detailMap.get("lzyy"));
dataMap.put("zmr", detailMap.get("zmr"));
insertDetailData(dataMap, "uf_gzll");
refreshRight(uuid, "uf_gzll", formModeId, user.getUID());
}
}
formModeId = getModeIdByTableName("uf_jtzycy");
if (StringUtils.isNotBlank(formModeId)) {
rs.executeUpdate("delete from uf_jtzycy where ygxm = ? ", resourceId);
for (Map<String, String> detailMap : familyDetailDataList) {
Map<String, String> dataMap = new HashMap<>();
String uuid = UUID.randomUUID().toString();
dataMap.put("modeuuid", uuid);
dataMap.put("formmodeid", formModeId);
buildModeInsertFields(dataMap, user.getUID());
dataMap.put("ygxm", resourceId);
dataMap.put("xm", detailMap.get("xm"));
dataMap.put("nl", detailMap.get("nl"));
dataMap.put("ybrgx", detailMap.get("ybrgx"));
dataMap.put("zy", detailMap.get("zy"));
dataMap.put("zz", detailMap.get("zz"));
insertDetailData(dataMap, "uf_jtzycy");
refreshRight(uuid, "uf_jtzycy", formModeId, user.getUID());
}
}
return SUCCESS;
}
/**
* 构建人员主表数据集合
*
* @param mainData
* @return
*/
private Map<String, String> buildResourceMap(Map<String, String> mainData) {
Map<String, String> resourceMap = new HashMap<>();
// 申请职位
resourceMap.put("jobtitle", mainData.get("sqzw"));
// 姓名
resourceMap.put("lastname", mainData.get("xm"));
// 性别
resourceMap.put("sex", mainData.get("xb"));
// 出生日期
resourceMap.put("birthday", mainData.get("csrq"));
// 身份证号
resourceMap.put("certificatenum", mainData.get("sfzh"));
// 民族
resourceMap.put("folk", mainData.get("mz"));
// 籍贯
resourceMap.put("nativeplace", mainData.get("jg"));
// 联系电话
resourceMap.put("mobile", mainData.get("lxdh"));
// 政治面貌
resourceMap.put("policy", mainData.get("zzmm"));
// 参加工作时间
resourceMap.put("workstartdate", mainData.get("cjgzsj"));
// 部门
String bm = mainData.get("bm");
resourceMap.put("departmentid", bm);
// 分部
String subcompanyid1 = new DepartmentComInfo().getSubcompanyid1(bm);
resourceMap.put("subcompanyid1", subcompanyid1);
// 入职日期
resourceMap.put("companystartdate", mainData.get("rzrq"));
// 照片
resourceMap.put("resourceimageid", mainData.get("zp"));
// 学历
resourceMap.put("educationlevel", mainData.get("xl"));
// 婚姻状况
resourceMap.put("maritalstatus", mainData.get("hyzk"));
// 办公地点
resourceMap.put("workroom", mainData.get("bgdd"));
// 状态
resourceMap.put("status", mainData.get("zt"));
// 试用期结束日期
resourceMap.put("probationenddate", mainData.get("syqjsrq"));
return resourceMap;
}
private Map<String, Map<String, String>> buildCustomMap(Map<String, String> mainData, String status) {
Map<String, Map<String, String>> dataMap = new HashMap<>();
// 1
Map<String, String> custom1Map = new HashMap<>();
// 3
Map<String, String> custom3Map = new HashMap<>();
// 毕业院校
custom1Map.put("field7", mainData.get("byyx"));
// 专业
custom1Map.put("field8", mainData.get("zy"));
// 户口类型
custom1Map.put("field9", mainData.get("hklx"));
// 职称
custom1Map.put("field10", mainData.get("zc"));
// 特长
custom1Map.put("field11", mainData.get("tc"));
// 出生地
custom1Map.put("field17", mainData.get("csd"));
// 现户口所在地
custom1Map.put("field13", mainData.get("xhkszd"));
// 现联系地址
custom1Map.put("field15", mainData.get("xlxdz"));
// 试用期限
custom3Map.put("field20", mainData.get("syqx"));
// 血型
custom1Map.put("field22", mainData.get("xx"));
// 准驾车险
custom1Map.put("field23", mainData.get("zjcx"));
// 紧急联系人电话
custom1Map.put("field16", mainData.get("jjlxrdh"));
// 身高
custom1Map.put("field14", mainData.get("sg"));
if ("0".equals(status)) {
// 试用职等档次
custom3Map.put("field21", mainData.get("syzddc"));
} else if ("1".equals(status)) {
// 正式职等档次
custom3Map.put("field21", mainData.get("zszddc"));
}
dataMap.put("1", custom1Map);
dataMap.put("3", custom3Map);
return dataMap;
}
/**
* 获取指定下标的明细表数据集合
*
* @param detailTableInfo
* @param detailIndex
* @return
*/
private List<Map<String, String>> getDetailDataList(DetailTableInfo detailTableInfo, int detailIndex) {
List<Map<String, String>> detailDataList = new ArrayList<>();
DetailTable detailTable = detailTableInfo.getDetailTable(detailIndex);
Row[] rows = detailTable.getRow();
for (Row row : rows) {
Map<String, String> detailDataMap = new HashMap<>();
Cell[] cells = row.getCell();
for (Cell cell : cells) {
detailDataMap.put(cell.getName(), cell.getValue());
}
detailDataList.add(detailDataMap);
}
return detailDataList;
}
/**
* 更新数据
*
* @param dataMap
*/
public static void updateHrmDataById(Map<String, String> dataMap, String id) {
List<String> fieldList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
dataMap.forEach((key, value) -> {
fieldList.add(key + " = ? ");
if (StringUtils.isBlank(value)) {
dataList.add(null);
} else {
dataList.add(value);
}
});
dataList.add(id);
String updateSql = "update hrmresource set " + StringUtils.join(fieldList, ",") + " where id = ? ";
RecordSet rs = new RecordSet();
rs.executeUpdate(updateSql, dataList);
if (StringUtils.isNotBlank(rs.getExceptionMsg())) {
throw new RuntimeException(rs.getExceptionMsg());
}
}
/**
* 更新人员自定义字段信息
*
* @param dataMap
* @param id
* @param scopeId
*/
public static void updateCusDataById(Map<String, String> dataMap, String id, String scopeId) {
List<String> fieldList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
dataMap.forEach((key, value) -> {
fieldList.add(key + " = ? ");
// 兼容SqlServer数据库Text字段类型不为null
if (StringUtils.isBlank(value) && !"field21".equals(key)) {
dataList.add(null);
} else {
dataList.add(value);
}
});
dataList.add(id);
dataList.add(scopeId);
String updateSql = "update cus_fielddata set " + StringUtils.join(fieldList, ",") + " where id = ? and scope ='HrmCustomFieldByInfoType' and scopeid = ? ";
RecordSet rs = new RecordSet();
rs.executeUpdate(updateSql, dataList);
if (StringUtils.isNotBlank(rs.getExceptionMsg())) {
throw new RuntimeException(rs.getExceptionMsg());
}
}
/**
* 插入明细表数据
*
* @param dataMap
* @param tableName
*/
public static void insertDetailData(Map<String, String> dataMap, String tableName) {
List<String> fieldList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
List<String> paramList = new ArrayList<>();
dataMap.forEach((key, value) -> {
if (StringUtils.isNotBlank(value)) {
fieldList.add(key);
dataList.add(value);
paramList.add("?");
}
});
String insertSql = " insert into " + tableName + "(" + StringUtils.join(fieldList, ",") + ") values (" + StringUtils.join(paramList, ",") + ")";
RecordSet rs = new RecordSet();
rs.executeUpdate(insertSql, dataList);
if (StringUtils.isNotBlank(rs.getExceptionMsg())) {
throw new RuntimeException(rs.getExceptionMsg());
}
}
/**
* 建模表数据权限重构
*
* @param uuid
* @param modeTable
* @param formModeId
*/
private String refreshRight(String uuid, String modeTable, String formModeId, int creator) {
RecordSet rs = new RecordSet();
rs.executeQuery("select id from " + modeTable + " where modeuuid='" + uuid + "'");
if (rs.next()) {
//建模数据的id
int bid = Util.getIntValue(rs.getString("id"));
ModeRightInfo modeRightInfo = new ModeRightInfo();
modeRightInfo.setNewRight(true);
//新建的时候添加共享
modeRightInfo.editModeDataShare(creator, Integer.parseInt(formModeId), bid);
return String.valueOf(bid);
}
return "";
}
/**
* 构建建模表基本数据
*
* @param mainDataMap 参数集合
*/
private void buildModeInsertFields(Map<String, String> mainDataMap, int userId) {
String dateTime = DateUtil.getFullDate();
String[] dateSplit = dateTime.split(" ");
mainDataMap.put("modedatacreater", String.valueOf(userId));
mainDataMap.put("modedatacreatedate", dateSplit[0]);
mainDataMap.put("modedatacreatetime", dateSplit[1]);
mainDataMap.put("modedatacreatertype", "0");
}
/**
* 根据建模表名,获取建模ID
*
* @param modeTable
* @return
*/
private String getModeIdByTableName(String modeTable) {
String formModeId = "-1";
RecordSet rs = new RecordSet();
rs.executeQuery("select id from modeinfo where formid =( select id from workflow_bill where tablename = ? ) order by id", modeTable);
if (rs.next()) {
formModeId = rs.getString("id");
}
return formModeId;
}
}