@ -39,6 +39,7 @@ import com.engine.organization.util.*;
import com.engine.organization.util.coderule.CodeRuleUtil ;
import com.engine.organization.util.db.MapperProxyFactory ;
import com.engine.organization.util.detach.DetachUtil ;
import com.engine.organization.util.excel.ExcelUtil ;
import com.engine.organization.util.page.Column ;
import com.engine.organization.util.page.PageInfo ;
import com.engine.organization.util.page.PageUtil ;
@ -46,6 +47,8 @@ import com.engine.organization.util.tree.SearchTreeUtil;
import com.google.common.collect.Lists ;
import org.apache.commons.collections4.CollectionUtils ;
import org.apache.commons.lang.StringUtils ;
import org.apache.poi.xssf.usermodel.XSSFWorkbook ;
import weaver.common.DateUtil ;
import weaver.conn.RecordSet ;
import weaver.general.StringUtil ;
import weaver.general.Util ;
@ -173,6 +176,22 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
@Override
public Long saveBaseForm ( Map < String , Object > params ) {
HasRightUtil . hasRight ( user , RIGHT_NAME , false ) ;
/ *
* 汉 桑 部 门 需 求 二 开 , 添 加 部 门 启 用 日 期 、 封 存 日 期 校 验
* 启 用 日 期 、 封 存 日 期 必 须 大 于 等 于 当 前 日 期 ;
* 启 用 日 期 小 于 封 存 日 期 ;
* /
String enableDate = Util . null2String ( params . get ( "qyrq" ) ) ;
String disableDate = Util . null2String ( params . get ( "fcrq" ) ) ;
String currentDate = DateUtil . getCurrentDate ( ) ;
OrganizationAssert . notBlank ( enableDate , "启用日期必填" ) ;
OrganizationAssert . isTrue ( DateUtil . compDate ( currentDate , enableDate ) > = 0 , "启用日期需大于等于当前日期" ) ;
if ( StringUtils . isNotBlank ( disableDate ) ) {
OrganizationAssert . isTrue ( DateUtil . compDate ( enableDate , disableDate ) > 0 , "启用日期需小于封存日期" ) ;
}
Map < String , Object > syncMap = new OrganizationSyncEc ( user , LogModuleNameEnum . DEPARTMENT , OperateTypeEnum . ADD , params ) . sync ( ) ;
String ecCompanyID = Util . null2String ( syncMap . get ( "id" ) ) ;
OrganizationAssert . isTrue ( StringUtils . isNotBlank ( ecCompanyID ) , syncMap . get ( "message" ) . toString ( ) ) ;
@ -206,6 +225,27 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
}
OrganizationAssert . isFalse ( disableIds . contains ( Integer . parseInt ( supDepId ) ) , "上级部门不能选择部门本身及其下级部门" ) ;
}
// 汉桑需求二开,启用日期、封存日期校验
String enableDate = Util . null2String ( params . get ( "qyrq" ) ) ;
String disableDate = Util . null2String ( params . get ( "fcrq" ) ) ;
String currentDate = DateUtil . getCurrentDate ( ) ;
OrganizationAssert . notBlank ( enableDate , "启用日期必填" ) ;
String oldEnableDate = "" ;
RecordSet rs = new RecordSet ( ) ;
rs . executeQuery ( "select qyrq,fcrq from hrmdepartmentdefined where deptid = ?" , ecDepartmentId ) ;
if ( rs . next ( ) ) {
oldEnableDate = rs . getString ( "qyrq" ) ;
}
if ( ! oldEnableDate . equals ( enableDate ) ) {
OrganizationAssert . isTrue ( DateUtil . compDate ( currentDate , enableDate ) > = 0 , "启用日期需大于等于当前日期" ) ;
}
if ( StringUtils . isNotBlank ( disableDate ) ) {
OrganizationAssert . isTrue ( DateUtil . compDate ( enableDate , disableDate ) > 0 , "启用日期需小于封存日期" ) ;
}
new OrganizationSyncEc ( user , LogModuleNameEnum . DEPARTMENT , OperateTypeEnum . UPDATE , params ) . sync ( ) ;
return ( long ) ecDepartmentId ;
@ -658,6 +698,58 @@ public class DepartmentServiceImpl extends Service implements DepartmentService
return 1 ;
}
@Override
public XSSFWorkbook departmentExport ( ) {
String orderSql = PageInfoSortUtil . getSortSql ( "" , " showorder " ) ;
List < DepartmentPO > allList = getDepartmentMapper ( ) . listAll ( orderSql ) ;
Map < Integer , DepartmentPO > poMaps = allList . stream ( ) . collect ( Collectors . toMap ( DepartmentPO : : getId , item - > item ) ) ;
List < DepartmentListDTO > dtoList = allList . stream ( ) . map ( e - >
DepartmentListDTO
. builder ( )
. id ( e . getId ( ) )
. departmentMark ( e . getDepartmentMark ( ) )
. departmentName ( e . getDepartmentName ( ) )
. departmentCode ( e . getDepartmentCode ( ) )
. subCompanyName ( 0 = = e . getSubCompanyId1 ( ) ? "" : MapperProxyFactory . getProxy ( CompMapper . class ) . listById ( e . getSubCompanyId1 ( ) ) . getSubCompanyName ( ) )
. supDepName ( null = = poMaps . get ( e . getSupDepId ( ) ) ? "" : poMaps . get ( e . getSupDepId ( ) ) . getDepartmentName ( ) )
. bmfzr ( DepartmentBO . getEmployeeNameById ( e . getId ( ) ) )
. canceled ( null = = e . getCanceled ( ) ? 0 : e . getCanceled ( ) )
. build ( ) ) . collect ( Collectors . toList ( ) ) ;
// 1.工作簿名称
String sheetName = HrmI18nUtil . getI18nLabel ( 85368 , "部门档案数据" ) ;
// 2.表头(后面动态获取)
List < List < Object > > excelSheetData = new ArrayList < > ( ) ;
String [ ] header = {
HrmI18nUtil . getI18nLabel ( - 93270 , "部门名称" ) ,
HrmI18nUtil . getI18nLabel ( - 93272 , "编号" ) ,
HrmI18nUtil . getI18nLabel ( - 93274 , "部门简称" ) ,
HrmI18nUtil . getI18nLabel ( - 93275 , "所属分部" ) ,
HrmI18nUtil . getI18nLabel ( - 93278 , "上级部门" ) ,
HrmI18nUtil . getI18nLabel ( - 93279 , "部门负责人" ) ,
HrmI18nUtil . getI18nLabel ( - 93280 , "启用状态" )
} ;
excelSheetData . add ( Arrays . asList ( header ) ) ;
//数据
List < List < Object > > rows = new LinkedList < > ( ) ;
for ( DepartmentListDTO vo : dtoList ) {
List < Object > row = new LinkedList < > ( ) ;
row . add ( vo . getDepartmentCode ( ) ) ;
row . add ( vo . getDepartmentName ( ) ) ;
row . add ( vo . getDepartmentMark ( ) ) ;
row . add ( vo . getSubCompanyName ( ) ) ;
row . add ( vo . getSupDepName ( ) ) ;
row . add ( vo . getBmfzr ( ) ) ;
row . add ( vo . getCanceled ( ) = = 0 ? "启用" : "未启用" ) ;
rows . add ( row ) ;
}
excelSheetData . addAll ( rows ) ;
return ExcelUtil . genWorkbookV2 ( excelSheetData , sheetName ) ;
}
/ * *
* 获 取 所 有 子 部 门 id
*