@ -1,12 +1,25 @@
package weaver.interfaces.aisin.cron ;
import com.engine.kq.biz.KQLeaveRulesBiz ;
import com.engine.kq.biz.KQReportBiz ;
import com.engine.kq.util.KQDurationCalculatorUtil ;
import com.engine.kq.util.KQTransMethod ;
import weaver.conn.RecordSet ;
import weaver.general.BaseBean ;
import weaver.general.TimeUtil ;
import weaver.general.Util ;
import weaver.hrm.User ;
import weaver.interfaces.aisin.cron.entity.CompensatoryLeaveDetail ;
import weaver.interfaces.aisin.cron.entity.OffLeaveDetail ;
import weaver.interfaces.schedule.BaseCronJob ;
import java.time.LocalDate ;
import java.time.YearMonth ;
import java.time.format.DateTimeFormatter ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
/ * *
* @Author liang . cheng
@ -20,12 +33,20 @@ public class KqCloseAccountUpdateCrob extends BaseCronJob {
public void execute ( ) {
RecordSet rs = new RecordSet ( ) ;
BaseBean bb = new BaseBean ( ) ;
String currentDate = TimeUtil . getCurrentDateString ( ) ;
String kqMonth = getKqMonth ( ) ;
String jsTableName = bb . getPropValue ( "aisinsecond" , "jsTableName" ) ;
String dxRuleId = bb . getPropValue ( "aisinsecond" , "dxRuleId" ) ;
rs . executeQuery ( "select fzksrq,fzjsrq from uf_atbpkqfz where fzny = ?" , kqMonth ) ;
String firstDayOfMonth = firstDayOfMonth ( kqMonth ) ;
String lastDayOfMonth = lastDayOfMonth ( kqMonth ) ;
rs . executeQuery ( "select id,fzksrq,fzjsrq from uf_atbpkqfz where fzny = ?" , kqMonth ) ;
rs . next ( ) ;
String id = Util . null2String ( rs . getString ( "id" ) ) ;
String fzksrq = Util . null2String ( rs . getString ( "fzksrq" ) ) ;
String fzjsrq = Util . null2String ( rs . getString ( "fzjsrq" ) ) ;
@ -36,7 +57,88 @@ public class KqCloseAccountUpdateCrob extends BaseCronJob {
//结束日期 更新结算完成
if ( currentDate . equals ( fzjsrq ) ) {
//更新明细表
String subcompanyid = bb . getPropValue ( "aisinsecond" , "subcompanyid" ) ;
//防止多次执行,执行前先判断是否已有考勤月明细数据
rs . executeQuery ( "select count(1) as sums from " + jsTableName + "_dt1 where mainid = ?" , id ) ;
rs . next ( ) ;
int sums = Util . getIntValue ( rs . getString ( "sums" ) ) ;
if ( sums > 0 ) {
return ;
}
//更新明细表1
List < OffLeaveDetail > offLeaveDetails = new ArrayList < > ( ) ;
KQReportBiz kqReportBiz = new KQReportBiz ( ) ;
User user = new User ( ) ;
user . setUid ( 1 ) ;
String json = String . format ( "{\"fromDate\":\"%s\",\"toDate\":\"%s\",\"subCompanyId\":\"%s\"}" , firstDayOfMonth , lastDayOfMonth , subcompanyid ) ;
Map < String , Object > params = new HashMap < String , Object > ( 2 ) { {
put ( "data" , json ) ;
} } ;
Map < String , Object > flowOverTimeDataNew = kqReportBiz . getFlowOverTimeDataNew ( params , user ) ;
rs . executeQuery ( "select id,workcode,departmentid from HrmResource where subcompanyid1 = ? and status < 4" , subcompanyid ) ;
while ( rs . next ( ) ) {
offLeaveDetails . add ( OffLeaveDetail . builder ( )
. resourceId ( Util . getIntValue ( rs . getString ( "id" ) ) )
. workcode ( Util . null2String ( rs . getString ( "workcode" ) ) )
. depetId ( Util . getIntValue ( rs . getString ( "departmentid" ) ) )
. build ( ) ) ;
}
offLeaveDetails . forEach ( e - > {
double workingDayOvertime_4leave = Util . getDoubleValue ( Util . null2String ( flowOverTimeDataNew . get ( e . getResourceId ( ) + "|workingDayOvertime_4leave" ) ) ) ;
workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave ;
double restDayOvertime_4leave = Util . getDoubleValue ( Util . null2String ( flowOverTimeDataNew . get ( e . getResourceId ( ) + "|restDayOvertime_4leave" ) ) ) ;
restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave ;
double holidayOvertime_4leave = Util . getDoubleValue ( Util . null2String ( flowOverTimeDataNew . get ( e . getResourceId ( ) + "|holidayOvertime_4leave" ) ) ) ;
holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave ;
double workingDayOvertime_nonleave = Util . getDoubleValue ( Util . null2String ( flowOverTimeDataNew . get ( e . getResourceId ( ) + "|workingDayOvertime_nonleave" ) ) ) ;
workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave ;
double restDayOvertime_nonleave = Util . getDoubleValue ( Util . null2String ( flowOverTimeDataNew . get ( e . getResourceId ( ) + "|restDayOvertime_nonleave" ) ) ) ;
restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave ;
double holidayOvertime_nonleave = Util . getDoubleValue ( Util . null2String ( flowOverTimeDataNew . get ( e . getResourceId ( ) + "|holidayOvertime_nonleave" ) ) ) ;
holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave ;
String workDayHours = KQDurationCalculatorUtil . getDurationRound ( String . valueOf ( workingDayOvertime_4leave + workingDayOvertime_nonleave ) ) ;
String restDayHours = KQDurationCalculatorUtil . getDurationRound ( String . valueOf ( restDayOvertime_4leave + restDayOvertime_nonleave ) ) ;
String holidayHours = KQDurationCalculatorUtil . getDurationRound ( String . valueOf ( holidayOvertime_4leave + holidayOvertime_nonleave ) ) ;
e . setWorkDayHours ( workDayHours ) ;
e . setRestDayHours ( restDayHours ) ;
e . setHolidayHours ( holidayHours ) ;
String salaryHours = KQDurationCalculatorUtil . getDurationRound ( String . valueOf (
1.5 * ( workingDayOvertime_4leave + workingDayOvertime_nonleave ) + 2 * ( restDayOvertime_4leave + restDayOvertime_nonleave ) + 3 * ( holidayOvertime_4leave + holidayOvertime_nonleave )
) ) ;
e . setSalaryHours ( salaryHours ) ;
} ) ;
//更新明细表2
//1.结算申请流程已归档数
List < CompensatoryLeaveDetail > csLeaveDetails = new ArrayList < > ( ) ;
rs . executeQuery ( "select ryxm,sum(bcsqjsylxss) as remain from " + jsTableName + " a \n" +
" left join workflow_requestbase b on a.requestId = b.requestid and b.currentnodetype = 3\n" +
" where a.sqrq >= '" + firstDayOfMonth + "' and a.sqrq <= '" + lastDayOfMonth + "' group by ryxm" ) ;
while ( rs . next ( ) ) {
csLeaveDetails . add ( CompensatoryLeaveDetail . builder ( )
. resourceId ( Util . getIntValue ( rs . getString ( "ryxm" ) ) )
. workflowHours ( Util . null2String ( rs . getString ( "remain" ) ) )
. build ( ) ) ;
}
csLeaveDetails . forEach ( e - > {
compensatoryLeave ( e , kqMonth ) ;
rs . executeUpdate ( "insert into " + jsTableName + "_dt2 (mainid,ygxm,yggh,zylxss,ysyxss,syxss,bysqjsdylxss) values(?,?,?,?,?,?,?)" , id ,
e . getResourceId ( ) , e . getWorkcode ( ) , e . getAllHours ( ) , e . getUseHours ( ) , e . getRemainHours ( ) , e . getWorkflowHours ( ) ) ;
} ) ;
rs . executeUpdate ( "update uf_atbpkqfz set kqjszt = 2 where fzny = ?" , kqMonth ) ;
}
@ -48,4 +150,74 @@ public class KqCloseAccountUpdateCrob extends BaseCronJob {
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( "yyyy-MM" ) ;
return previousMonthDate . format ( formatter ) ;
}
private String firstDayOfMonth ( String yearMonthStr ) {
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( "yyyy-MM" ) ;
YearMonth yearMonth = YearMonth . parse ( yearMonthStr , formatter ) ;
LocalDate firstDayOfMonth = yearMonth . atDay ( 1 ) ;
return firstDayOfMonth . format ( DateTimeFormatter . ofPattern ( "yyyy-MM-dd" ) ) ;
}
private String lastDayOfMonth ( String yearMonthStr ) {
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( "yyyy-MM" ) ;
YearMonth yearMonth = YearMonth . parse ( yearMonthStr , formatter ) ;
LocalDate lastDayOfMonth = yearMonth . atEndOfMonth ( ) ;
return lastDayOfMonth . format ( DateTimeFormatter . ofPattern ( "yyyy-MM-dd" ) ) ;
}
/ * *
* 调 休 假
* @param compensatoryLeave
* /
private void compensatoryLeave ( CompensatoryLeaveDetail compensatoryLeave , String kqMonth ) {
RecordSet rs = new RecordSet ( ) ;
BaseBean bb = new BaseBean ( ) ;
String txRuleId = bb . getPropValue ( "aisinsecond" , "txRuleId" ) ;
KQTransMethod kqTransMethod = new KQTransMethod ( ) ;
String year = kqMonth . substring ( 0 , 4 ) ;
String month = kqMonth . substring ( 5 , 7 ) ;
rs . executeQuery ( "select a.baseAmount,a.usedAmount,b.workcode from kq_balanceOfLeave a left join HrmResource b\n" +
" on a.resourceId = b.id where a.leaveRulesId = " + txRuleId + " and (a.isDelete is null or a.isDelete<>1)\n" +
" and a.belongYear = '" + year + "' and a.belongMonth = '" + month + "' and a.resourceId = ?" , compensatoryLeave . getResourceId ( ) ) ;
if ( rs . next ( ) ) {
String baseAmount = kqTransMethod . getOriginalShow ( Util . null2String ( rs . getString ( "baseAmount" ) ) ) ;
String usedAmount = kqTransMethod . getOriginalShow ( Util . null2String ( rs . getString ( "usedAmount" ) ) ) ;
compensatoryLeave . setWorkcode ( Util . null2String ( rs . getString ( "workcode" ) ) ) ;
compensatoryLeave . setAllHours ( baseAmount ) ;
compensatoryLeave . setUseHours ( usedAmount ) ;
compensatoryLeave . setRemainHours ( getRemainHours ( baseAmount , usedAmount ) ) ;
}
}
/ * *
* 倒 休 假
* /
private void flowWorkMonth ( OffLeaveDetail offLeaveDetail , String kqMonth ) {
RecordSet rs = new RecordSet ( ) ;
BaseBean bb = new BaseBean ( ) ;
String dxRuleId = bb . getPropValue ( "aisinsecond" , "dxRuleId" ) ;
KQTransMethod kqTransMethod = new KQTransMethod ( ) ;
String year = kqMonth . substring ( 0 , 4 ) ;
String month = kqMonth . substring ( 5 , 7 ) ;
/*判断该假期类型是否属于 调休 的类型(暂不支持一个请假类型下既存在"加班时长自动计入余额"的余额发放方式,又存在其他发放方式)*/
boolean isTiaoXiu = KQLeaveRulesBiz . isTiaoXiu ( dxRuleId ) ;
/*如果属于调休,需求默认是属于调休 此处增加一层判断*/
if ( isTiaoXiu ) {
}
}
private String getRemainHours ( String baseHour , String usedHour ) {
String remainHours = "0.00" ;
double baseHours = Util . getDoubleValue ( baseHour , 0.00 ) ;
double usedHours = Util . getDoubleValue ( usedHour , 0.00 ) ;
remainHours = String . format ( "%.2f" , baseHours - usedHours ) ;
return remainHours ;
}
}