部门导入、日志记录
This commit is contained in:
parent
c23127acc2
commit
fc8aaf7729
|
|
@ -37,7 +37,7 @@ public interface ExtendInfoMapper {
|
|||
|
||||
int updateExtendGroupId(@Param("groupId") Long groupId, @Param("ids") Collection<Long> ids);
|
||||
|
||||
ExtendInfoPO getInfoByGroupAndLabelName(@Param("extendType") Long extendType, @Param("labelName") String labelName);
|
||||
ExtendInfoPO getInfoByExtendAndLabelName(@Param("extendType") Long extendType, @Param("labelName") String labelName);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getInfoByGroupAndLabelName" resultMap="BaseResultMap">
|
||||
<select id="getInfoByExtendAndLabelName" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="baseColumns"/>
|
||||
from jcl_field_extendinfo t
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.engine.organization.mapper.jclimport;
|
||||
|
||||
import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
|
|
@ -10,4 +11,6 @@ import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO;
|
|||
public interface JclImportHistoryDetailMapper {
|
||||
|
||||
void insertHistoryDetail(JclImportHistoryDetailPO historyDetailPO);
|
||||
|
||||
int countRows(@Param("status") String status, @Param("pId") String pId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@
|
|||
, t.operate_detail
|
||||
, t.related_name
|
||||
</sql>
|
||||
<insert id="insertHistoryDetail" parameterType="com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO" keyProperty="id"
|
||||
<insert id="insertHistoryDetail"
|
||||
parameterType="com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO" keyProperty="id"
|
||||
keyColumn="id" useGeneratedKeys="true">
|
||||
INSERT INTO jcl_import_history_detail
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
|
@ -59,4 +60,10 @@
|
|||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countRows" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from jcl_import_history_detail
|
||||
where status = #{status}
|
||||
and pid = #{pId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -55,6 +55,12 @@ public interface ImportCommonService {
|
|||
*/
|
||||
Map<String, Object> saveImport(Map<String, Object> params);
|
||||
|
||||
Map<String, Object> getImportProcessLog(Map<String, Object> params);
|
||||
/**
|
||||
* 导入日志详情列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getImportResult(Map<String, Object> params);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
private static final Long GROUP_ID = 2L;
|
||||
|
||||
|
||||
private DepartmentMapper getDepartmentMapper() {
|
||||
private static DepartmentMapper getDepartmentMapper() {
|
||||
return MapperProxyFactory.getProxy(DepartmentMapper.class);
|
||||
}
|
||||
|
||||
|
|
@ -594,7 +594,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
private String repeatDetermine(String deptNo) {
|
||||
public static String repeatDetermine(String deptNo) {
|
||||
CodeRulePO codeRuleByType = MapperProxyFactory.getProxy(CodeRuleMapper.class).getCodeRuleByType(RuleCodeType.DEPARTMENT.getValue());
|
||||
if (StringUtils.isNotBlank(deptNo)) {
|
||||
deptNo = CodeRuleUtil.generateCode(RuleCodeType.DEPARTMENT, deptNo);
|
||||
|
|
@ -613,7 +613,7 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
private String autoCreateCompanyNo() {
|
||||
private static String autoCreateCompanyNo() {
|
||||
String generateCode = CodeRuleUtil.generateCode(RuleCodeType.DEPARTMENT, "");
|
||||
List<DepartmentPO> list = getDepartmentMapper().listByNo(Util.null2String(generateCode));
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
|
|
|
|||
|
|
@ -162,6 +162,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
break;
|
||||
case "department":
|
||||
extendType = "2";
|
||||
exculdeFields.add("parent_dept");
|
||||
tableName = "JCL_ORG_DEPT";
|
||||
break;
|
||||
case "jobtitle":
|
||||
|
|
@ -238,6 +239,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
returnMap.put("pId", companyImport(operateType, excelFile, 1L));
|
||||
break;
|
||||
case "department":
|
||||
returnMap.put("pId", departmentImport(operateType, excelFile, 2L));
|
||||
break;
|
||||
case "jobtitle":
|
||||
break;
|
||||
|
|
@ -255,17 +257,20 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getImportProcessLog(Map<String, Object> params) {
|
||||
public Map<String, Object> getImportResult(Map<String, Object> params) {
|
||||
String pId = (String) params.get("pId");
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
// 刷新引用状态
|
||||
OrganizationWeaTable<JclImportHistoryDetailVO> table = new OrganizationWeaTable<>(user, JclImportHistoryDetailVO.class);
|
||||
String sqlWhere = " where pId = '" + pId + "'";
|
||||
String sqlWhere = " where status = '0' and pId = '" + pId + "'";
|
||||
table.setSqlwhere(sqlWhere);
|
||||
WeaResultMsg result = new WeaResultMsg(false);
|
||||
result.putAll(table.makeDataResult());
|
||||
result.success();
|
||||
resultMap.putAll(result.getResultMap());
|
||||
resultMap.put("importStatus", "over");
|
||||
resultMap.put("succnum", MapperProxyFactory.getProxy(JclImportHistoryDetailMapper.class).countRows("1", pId));
|
||||
resultMap.put("failnum", MapperProxyFactory.getProxy(JclImportHistoryDetailMapper.class).countRows("0", pId));
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
|
@ -498,13 +503,12 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
String cellValue = getCellValue(cell).trim();
|
||||
if (i == 0) {
|
||||
// 首行 初始化字段信息
|
||||
ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByGroupAndLabelName(extendType, cellValue);
|
||||
ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(extendType, cellValue);
|
||||
extendInfoPOS.add(extendInfoPO);
|
||||
} else {
|
||||
ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex);
|
||||
// 数据校验
|
||||
if (infoPO.getIsrequired() == 1 && StringUtils.isBlank(cellValue)) {
|
||||
// TODO 记录日志
|
||||
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "为必填项");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
|
|
@ -521,7 +525,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
continue nextRow;
|
||||
}
|
||||
if (StringUtils.isNotBlank(cellValue) && StringUtils.isBlank(Util.null2String(reallyValue))) {
|
||||
// TODO 记录日志
|
||||
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "数据转换失败,未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
|
|
@ -533,7 +536,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
String[] split = cellValue.split(">");
|
||||
if (split.length > 1) {
|
||||
if (split.length > 8) {
|
||||
// TODO 记录日志
|
||||
historyDetailPO.setOperateDetail("分部层级不能大于10");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
|
|
@ -542,7 +544,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
for (int index = split.length - 2; index >= 0; index--) {
|
||||
parentCompanyId = MapperProxyFactory.getProxy(CompMapper.class).getIdByNameAndPid(split[index], parentCompanyId == null ? 0 : parentCompanyId);
|
||||
if (null == parentCompanyId) {
|
||||
// TODO 记录日志
|
||||
historyDetailPO.setOperateDetail(split[index] + "分部未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
|
|
@ -583,7 +584,7 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
// 查询对应ID
|
||||
if (StringUtils.isNotBlank(compNo)) {
|
||||
if (companyId == null) {
|
||||
historyDetailPO.setOperateDetail(companyName + ":未找到对应数据");
|
||||
historyDetailPO.setOperateDetail("未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
}
|
||||
|
|
@ -608,6 +609,194 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
|
|||
return importHistoryId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入部门
|
||||
*
|
||||
* @param operateType
|
||||
* @param excelFile
|
||||
* @param extendType
|
||||
* @return
|
||||
*/
|
||||
private Long departmentImport(String operateType, String excelFile, Long extendType) {
|
||||
Long importHistoryId = saveImportLog("department", operateType);
|
||||
JclImportHistoryDetailPO historyDetailPO;
|
||||
|
||||
ImageFileManager manager = new ImageFileManager();
|
||||
manager.getImageFileInfoById(Util.getIntValue(excelFile));
|
||||
XSSFWorkbook workbook;
|
||||
try {
|
||||
workbook = new XSSFWorkbook(manager.getInputStream());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 当前sheet
|
||||
XSSFSheet sheetAt = workbook.getSheetAt(0);
|
||||
int lastRow = sheetAt.getLastRowNum();
|
||||
List<ExtendInfoPO> extendInfoPOS = new ArrayList<>();
|
||||
OrganizationAssert.isTrue(lastRow > 1, "导入数据为空");
|
||||
|
||||
|
||||
// 遍历每一行数据
|
||||
nextRow:
|
||||
for (int i = 0; i <= lastRow; i++) {
|
||||
historyDetailPO = new JclImportHistoryDetailPO();
|
||||
historyDetailPO.setPid(importHistoryId);
|
||||
XSSFRow row = sheetAt.getRow(i);
|
||||
// 组装待处理数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
Long parentCompanyId = null;
|
||||
Long parentDepartmentId = null;
|
||||
String departmentName = "";
|
||||
|
||||
historyDetailPO.setRowNums(String.valueOf(i + 1));
|
||||
for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) {
|
||||
XSSFCell cell = row.getCell((short) cellIndex);
|
||||
if (cell == null) {
|
||||
continue;
|
||||
}
|
||||
String cellValue = getCellValue(cell).trim();
|
||||
if (i == 0) {
|
||||
// 首行 初始化字段信息
|
||||
ExtendInfoPO extendInfoPO = getExtendInfoMapper().getInfoByExtendAndLabelName(extendType, cellValue);
|
||||
extendInfoPOS.add(extendInfoPO);
|
||||
} else {
|
||||
ExtendInfoPO infoPO = extendInfoPOS.get(cellIndex);
|
||||
// 数据校验
|
||||
if (infoPO.getIsrequired() == 1 && StringUtils.isBlank(cellValue)) {
|
||||
// TODO 记录日志
|
||||
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "为必填项");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
|
||||
Object reallyValue;
|
||||
try {
|
||||
reallyValue = getReallyValue(infoPO, cellValue);
|
||||
} catch (Exception e) {
|
||||
historyDetailPO.setOperateDetail(cellValue + "转换失败");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
if (StringUtils.isNotBlank(cellValue) && StringUtils.isBlank(Util.null2String(reallyValue))) {
|
||||
// TODO 记录日志
|
||||
historyDetailPO.setOperateDetail(infoPO.getFieldNameDesc() + "数据转换失败,未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
map.put(infoPO.getFieldName(), reallyValue);
|
||||
// 上级分部
|
||||
if ("parent_comp".equals(infoPO.getFieldName())) {
|
||||
String[] split = cellValue.split(">");
|
||||
if (split.length > 1) {
|
||||
if (split.length > 8) {
|
||||
historyDetailPO.setOperateDetail("分部层级不能大于10");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
for (int index = split.length - 1; index >= 0; index--) {
|
||||
parentCompanyId = MapperProxyFactory.getProxy(CompMapper.class).getIdByNameAndPid(split[index], parentDepartmentId == null ? 0 : parentDepartmentId);
|
||||
if (null == parentDepartmentId) {
|
||||
historyDetailPO.setOperateDetail(cellValue + "分部未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 部门名称、上级部门
|
||||
if ("dept_name".equals(infoPO.getFieldName())) {
|
||||
if (null == parentCompanyId) {
|
||||
historyDetailPO.setOperateDetail(cellValue + "所属分部未找到");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
historyDetailPO.setRelatedName(cellValue);
|
||||
String[] split = cellValue.split(">");
|
||||
if (split.length > 1) {
|
||||
if (split.length > 8) {
|
||||
historyDetailPO.setOperateDetail("部门层级不能大于10");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
for (int index = split.length - 2; index >= 0; index--) {
|
||||
parentDepartmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(split[index], parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
|
||||
if (null == parentDepartmentId) {
|
||||
historyDetailPO.setOperateDetail(split[index] + "部门未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put("parent_comp", parentCompanyId);
|
||||
map.put("parent_dept", parentDepartmentId);
|
||||
departmentName = split[split.length - 1];
|
||||
map.put("dept_name", departmentName);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 校验、数据交互
|
||||
if (i == 0) {
|
||||
continue;
|
||||
}
|
||||
// TODO
|
||||
String deptNo = (String) map.get("dept_no");
|
||||
Long departmentId = MapperProxyFactory.getProxy(DepartmentMapper.class).getIdByNameAndPid(departmentName, parentCompanyId, parentDepartmentId == null ? 0 : parentDepartmentId);
|
||||
if ("add".equals(operateType)) {
|
||||
if (departmentId != null) {
|
||||
historyDetailPO.setOperateDetail("数据已存在");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
continue nextRow;
|
||||
}
|
||||
// 自动编号
|
||||
deptNo = DepartmentServiceImpl.repeatDetermine(deptNo);
|
||||
map.put("dept_no", deptNo);
|
||||
map.put("creator", user.getUID());
|
||||
map.put("delete_type", 0);
|
||||
map.put("create_time", new Date());
|
||||
MapperProxyFactory.getProxy(ExtMapper.class).insertExt(ExtendInfoParams.builder().tableName("JCL_ORG_DEPT").params(map).build());
|
||||
historyDetailPO.setOperateDetail("添加成功");
|
||||
historyDetailPO.setStatus("1");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
} else if ("update".equals(operateType)) {
|
||||
// 查询对应ID
|
||||
if (StringUtils.isNotBlank(deptNo)) {
|
||||
if (departmentId == null) {
|
||||
historyDetailPO.setOperateDetail("未找到对应数据");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
}
|
||||
if (checkRepeatNo(deptNo, extendType, departmentId)) {
|
||||
map.put("update_time", new Date());
|
||||
MapperProxyFactory.getProxy(ExtMapper.class).updateExt(ExtendInfoParams.builder().id(departmentId).tableName("JCL_ORG_DEPT").params(map).build());
|
||||
historyDetailPO.setOperateDetail("更新成功");
|
||||
historyDetailPO.setStatus("1");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail(deptNo + "编号已存在");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
}
|
||||
} else {
|
||||
historyDetailPO.setOperateDetail("编号为空,更新失败");
|
||||
historyDetailPO.setStatus("0");
|
||||
saveImportDetailLog(historyDetailPO);
|
||||
}
|
||||
}
|
||||
}
|
||||
return importHistoryId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取表格文本内容
|
||||
*
|
||||
|
|
|
|||
|
|
@ -87,13 +87,13 @@ public class ImportCommonController {
|
|||
|
||||
|
||||
@GET
|
||||
@Path("/getImportProcessLog")
|
||||
@Path("/getImportResult")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult getImportProcessLog(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
public ReturnResult getImportResult(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
Map<String, Object> map = ParamUtil.request2Map(request);
|
||||
return ReturnResult.successed(getImportCommonWrapper(user).getImportProcessLog(map));
|
||||
return ReturnResult.successed(getImportCommonWrapper(user).getImportResult(map));
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class ImportCommonWrapper extends Service {
|
|||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getImportProcessLog(Map<String, Object> params) {
|
||||
return getImportCommonService(user).getImportProcessLog(params);
|
||||
public Map<String, Object> getImportResult(Map<String, Object> params) {
|
||||
return getImportCommonService(user).getImportResult(params);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue