|
@@ -0,0 +1,234 @@
|
|
|
|
+//
|
|
|
|
+// Source code recreated from a .class file by IntelliJ IDEA
|
|
|
|
+// (powered by FernFlower decompiler)
|
|
|
|
+//
|
|
|
|
+
|
|
|
|
+package com.kingdee.shr.compensation.app;
|
|
|
|
+
|
|
|
|
+import com.kingdee.bos.BOSException;
|
|
|
|
+import com.kingdee.bos.Context;
|
|
|
|
+import com.kingdee.eas.common.EASBizException;
|
|
|
|
+import com.kingdee.eas.util.app.DbUtil;
|
|
|
|
+import com.kingdee.jdbc.rowset.IRowSet;
|
|
|
|
+import com.kingdee.shr.compensation.util.CmpStrUtil;
|
|
|
|
+import com.kingdee.util.DateTimeUtils;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.sql.SQLException;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.Period;
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import org.apache.log4j.Logger;
|
|
|
|
+
|
|
|
|
+public class RetMoneyFacadeControllerBean extends AbstractRetMoneyFacadeControllerBean {
|
|
|
|
+ private static Logger logger = Logger.getLogger("com.kingdee.shr.compensation.app.RetMoneyFacadeControllerBean");
|
|
|
|
+
|
|
|
|
+ public RetMoneyFacadeControllerBean() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void _retMoney(Context ctx) throws BOSException, EASBizException {
|
|
|
|
+ String sql = "/*dialect*/ SELECT FMONEY ,FID ,FPERSONID ,FCMPITEMID,FEFFECTDAY ,FLEFFECTDAY,CFTraceability,CFRetroactiveDate,foldfixadjustsalaryid FROM T_HR_SFixAdjustSalary where sysdate between FEFFECTDAY and FLEFFECTDAY and CFTraceability='Yes' and (CFIsRet is null or CFIsRet=0)";
|
|
|
|
+ HashSet list = new HashSet();
|
|
|
|
+ logger.error("sql" + sql);
|
|
|
|
+ IRowSet rs = DbUtil.executeQuery(ctx, sql);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ BigDecimal money;
|
|
|
|
+ for(; rs.next(); logger.error("end mainid ==============" + money)) {
|
|
|
|
+ BigDecimal sumMoney = BigDecimal.ZERO;
|
|
|
|
+ money = rs.getBigDecimal("FMONEY");
|
|
|
|
+ logger.error("statrt mainid ==============" + money);
|
|
|
|
+ Date cfretroactivedate = rs.getDate("cfretroactivedate");
|
|
|
|
+ logger.error("cfretroactivedate " + DateTimeUtils.format(cfretroactivedate));
|
|
|
|
+ String personid = rs.getString("FPERSONID");
|
|
|
|
+ logger.error("personid " + personid);
|
|
|
|
+ String cmpitemid = rs.getString("FCMPITEMID");
|
|
|
|
+ Date mainEffectday = rs.getDate("FEFFECTDAY");
|
|
|
|
+ Date mainLeffectday = rs.getDate("FLEFFECTDAY");
|
|
|
|
+ String mainleftdayYearMonth = DateTimeUtils.format(mainEffectday, "yyyy-MM");
|
|
|
|
+ logger.error("mainleftdayYearMonth " + mainleftdayYearMonth);
|
|
|
|
+ String oldfixadjustsalaryid = rs.getString("foldfixadjustsalaryid");
|
|
|
|
+ String id = rs.getString("fid");
|
|
|
|
+ String detialSql = "/*dialect*/ select FEFFECTDAY ,FLEFFECTDAY,FMONEY,fid from T_HR_SFixAdjustSalary where FCMPITEMID='" + cmpitemid + "' " + " and fid ='" + oldfixadjustsalaryid + "' and FPERSONID='" + personid + "' " + " and (CFIsRet is null or CFIsRet=0) order by FEFFECTDAY asc ";
|
|
|
|
+ logger.error("detial sql " + detialSql);
|
|
|
|
+ list.add(id);
|
|
|
|
+ IRowSet dettaiRs = DbUtil.executeQuery(ctx, detialSql);
|
|
|
|
+ logger.error("cfretroactivedate " + cfretroactivedate);
|
|
|
|
+ String detialid;
|
|
|
|
+ if (dettaiRs != null && dettaiRs.size() > 0) {
|
|
|
|
+ while(dettaiRs.next()) {
|
|
|
|
+ detialid = dettaiRs.getString("fid");
|
|
|
|
+ logger.error("start detialid================================= " + dettaiRs.getString("fid"));
|
|
|
|
+ BigDecimal detailMony = dettaiRs.getBigDecimal("FMONEY");
|
|
|
|
+ logger.error("dettaiRs:retMoney " + detailMony);
|
|
|
|
+ BigDecimal retMoney = money.subtract(dettaiRs.getBigDecimal("FMONEY"));
|
|
|
|
+ logger.error("retMoney " + retMoney);
|
|
|
|
+ Date effectday = dettaiRs.getDate("FEFFECTDAY");
|
|
|
|
+ Date leffectday = dettaiRs.getDate("FLEFFECTDAY");
|
|
|
|
+ logger.error("detial_effectday " + DateTimeUtils.format(effectday));
|
|
|
|
+ logger.error("detial_leffectday " + DateTimeUtils.format(leffectday));
|
|
|
|
+ logger.error("detial_leffectday_before " + cfretroactivedate.before(effectday));
|
|
|
|
+ HashSet<String> monthSet = null;
|
|
|
|
+ int months = 0;
|
|
|
|
+ String beginYearMonth;
|
|
|
|
+ String endYearMonth;
|
|
|
|
+ int detiailbeginday;
|
|
|
|
+ Date lastDate;
|
|
|
|
+ int days;
|
|
|
|
+ BigDecimal arrMoney;
|
|
|
|
+ long cntdays;
|
|
|
|
+
|
|
|
|
+ if (cfretroactivedate.before(effectday)) {
|
|
|
|
+ beginYearMonth = DateTimeUtils.format(effectday, "yyyy-MM");
|
|
|
|
+ logger.error("beginYearMonth" + beginYearMonth);
|
|
|
|
+ endYearMonth = DateTimeUtils.format(leffectday, "yyyy-MM");
|
|
|
|
+ logger.error("endYearMonth" + endYearMonth);
|
|
|
|
+ monthSet = getMonthBetweenDate(effectday, leffectday);
|
|
|
|
+ logger.error("monthSet" + monthSet);
|
|
|
|
+ months = this.getAllMonth(effectday, leffectday);
|
|
|
|
+ logger.error("detial_months " + months);
|
|
|
|
+ detiailbeginday = DateTimeUtils.getDay(effectday);
|
|
|
|
+ logger.error("detiailbeginday " + detiailbeginday);
|
|
|
|
+ lastDate = this.getlengthOfMonth(effectday);
|
|
|
|
+ if (detiailbeginday != 1) {
|
|
|
|
+ days = DateTimeUtils.getDay(lastDate);
|
|
|
|
+ logger.error("detial_all_days " + days);
|
|
|
|
+ arrMoney = retMoney.divide(new BigDecimal(days), 5).setScale(2);
|
|
|
|
+ logger.error("detial_arrMoney " + arrMoney);
|
|
|
|
+ cntdays = this.getDaysBetweenDates(effectday, (Date)(lastDate.after(leffectday) ? leffectday : lastDate)) + 1L;
|
|
|
|
+ logger.error("detial_cntdays " + cntdays);
|
|
|
|
+ sumMoney = sumMoney.add(arrMoney.multiply(new BigDecimal(cntdays)));
|
|
|
|
+ logger.error("detial_sumMoney " + sumMoney);
|
|
|
|
+ monthSet.remove(beginYearMonth);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (mainleftdayYearMonth.equals(endYearMonth)) {
|
|
|
|
+ monthSet.remove(endYearMonth);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ months = this.getAllMonth(cfretroactivedate, leffectday);
|
|
|
|
+ beginYearMonth = DateTimeUtils.format(cfretroactivedate, "yyyy-MM");
|
|
|
|
+ logger.error("beginYearMonth" + beginYearMonth);
|
|
|
|
+ endYearMonth = DateTimeUtils.format(leffectday, "yyyy-MM");
|
|
|
|
+ logger.error("endYearMonth" + endYearMonth);
|
|
|
|
+ monthSet = getMonthBetweenDate(cfretroactivedate, leffectday);
|
|
|
|
+ logger.error("monthSet" + monthSet);
|
|
|
|
+ logger.error("detial_months " + months);
|
|
|
|
+ detiailbeginday = DateTimeUtils.getDay(cfretroactivedate);
|
|
|
|
+ logger.error("detiailbeginday " + detiailbeginday);
|
|
|
|
+ lastDate = this.getlengthOfMonth(cfretroactivedate);
|
|
|
|
+ if (detiailbeginday != 1) {
|
|
|
|
+ days = DateTimeUtils.getDay(lastDate);
|
|
|
|
+ logger.error("detial_all_days " + days);
|
|
|
|
+ arrMoney = retMoney.divide(new BigDecimal(days), 5).setScale(2);
|
|
|
|
+ logger.error("arrMoney " + arrMoney);
|
|
|
|
+ cntdays = this.getDaysBetweenDates(cfretroactivedate, (Date)(lastDate.after(leffectday) ? leffectday : lastDate)) + 1L;
|
|
|
|
+ logger.error("detial_cntdays " + cntdays);
|
|
|
|
+ sumMoney = sumMoney.add(arrMoney.multiply(new BigDecimal(cntdays)));
|
|
|
|
+ logger.error("detial_sumMoney " + sumMoney);
|
|
|
|
+ monthSet.remove(endYearMonth);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (mainleftdayYearMonth.equals(endYearMonth)) {
|
|
|
|
+ monthSet.remove(endYearMonth);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ logger.error("monthSet ret " + monthSet);
|
|
|
|
+ if (monthSet.size() > 0) {
|
|
|
|
+ sumMoney = sumMoney.add(retMoney.multiply(new BigDecimal(monthSet.size())));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ logger.error("sumMoney " + sumMoney);
|
|
|
|
+ list.add(detialid);
|
|
|
|
+ logger.error("end detialid================================= " + dettaiRs.getString("fid"));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ logger.error("没有调薪历史都是0");
|
|
|
|
+ sumMoney = BigDecimal.ZERO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ detialid = "select * from CT_CUS_PersonPayForm where CFPersonID ='" + personid + "' and CFAdjustSalary='" + id + "' ";
|
|
|
|
+ logger.error("exiSql sql " + detialid);
|
|
|
|
+ IRowSet extRs = DbUtil.executeQuery(ctx, detialid);
|
|
|
|
+ String insertSql;
|
|
|
|
+ if (extRs != null && extRs.size() > 0) {
|
|
|
|
+ insertSql = "update CT_CUS_PersonPayForm set CFRetMoney=" + sumMoney.setScale(2, 5) + " where CFAdjustSalary='" + id + "' ";
|
|
|
|
+ logger.error("updateSql " + insertSql);
|
|
|
|
+ DbUtil.execute(ctx, insertSql);
|
|
|
|
+ } else {
|
|
|
|
+ insertSql = " /*dialect*/ insert into CT_CUS_PersonPayForm(fid,CFPersonID,CFMonth,CFRetMoney,cfadjustsalary) values(newbosid('5FB9A7AC'),'" + personid + "',to_date('" + DateTimeUtils.format(mainEffectday) + "','yyyy-MM-dd')" + "," + sumMoney.setScale(2, 5) + ",'" + id + "')";
|
|
|
|
+ logger.error("insertSql " + insertSql);
|
|
|
|
+ DbUtil.execute(ctx, insertSql);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String idStr = CmpStrUtil.convertListToString(list.toArray());
|
|
|
|
+ logger.error("insqlInstance idStr " + CmpStrUtil.convertListToString(list.toArray()));
|
|
|
|
+ String updateAdjustSalarySql = "update T_HR_SFixAdjustSalary set cfisret=1 where fid in ( " + idStr + ") ";
|
|
|
|
+ logger.error("updateAdjustSalarySql" + updateAdjustSalarySql);
|
|
|
|
+ DbUtil.execute(ctx, updateAdjustSalarySql);
|
|
|
|
+ } catch (SQLException var32) {
|
|
|
|
+ var32.printStackTrace();
|
|
|
|
+ throw new BOSException("回算出错");
|
|
|
|
+ } catch (ParseException var33) {
|
|
|
|
+ var33.printStackTrace();
|
|
|
|
+ throw new BOSException("回算出错");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public int getALlDays(int year, int month) {
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.set(year, month, 1);
|
|
|
|
+ int daysInMonth = calendar.getActualMaximum(5);
|
|
|
|
+ return daysInMonth;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public int getAllMonth(Date beginDate, Date endDate) {
|
|
|
|
+ LocalDate startDatetmp = LocalDate.of(DateTimeUtils.getYear(beginDate), DateTimeUtils.getMonth(beginDate), DateTimeUtils.getDay(beginDate));
|
|
|
|
+ LocalDate endDatetmp = LocalDate.of(DateTimeUtils.getYear(endDate), DateTimeUtils.getMonth(endDate), DateTimeUtils.getDay(endDate));
|
|
|
|
+ logger.error("startDatetmp" + startDatetmp);
|
|
|
|
+ logger.error("endDatetmp" + endDatetmp);
|
|
|
|
+ Period period = Period.between(startDatetmp, endDatetmp);
|
|
|
|
+ logger.error("period" + period);
|
|
|
|
+ int months = period.getMonths();
|
|
|
|
+ logger.error("months" + months);
|
|
|
|
+ return months;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Date getlengthOfMonth(Date date) throws ParseException {
|
|
|
|
+ logger.error("getlengthOfMonth—date" + date);
|
|
|
|
+ LocalDate currentDate = LocalDate.of(DateTimeUtils.getYear(date), DateTimeUtils.getMonth(date), DateTimeUtils.getDay(date));
|
|
|
|
+ logger.error("getlengthOfMonth—date" + currentDate);
|
|
|
|
+ int lastDay = currentDate.lengthOfMonth();
|
|
|
|
+ logger.error("getlengthOfMonth—lastDay" + lastDay);
|
|
|
|
+ String tempDate = DateTimeUtils.getYear(date) + "-" + DateTimeUtils.getMonth(date) + "-" + lastDay;
|
|
|
|
+ logger.error("getlengthOfMonth—tempDate" + tempDate);
|
|
|
|
+ return DateTimeUtils.parseDate(tempDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public long getDaysBetweenDates(Date start, Date end) {
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ cal.setTime(start);
|
|
|
|
+ long startTime = cal.getTimeInMillis();
|
|
|
|
+ cal.setTime(end);
|
|
|
|
+ long endTime = cal.getTimeInMillis();
|
|
|
|
+ long diff = Math.abs(endTime - startTime);
|
|
|
|
+ return diff / 86400000L;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static HashSet<String> getMonthBetweenDate(Date startTime, Date endTime) {
|
|
|
|
+ HashSet<String> list = new HashSet();
|
|
|
|
+
|
|
|
|
+ for(Calendar calendar = Calendar.getInstance(); startTime.getTime() <= endTime.getTime(); startTime = calendar.getTime()) {
|
|
|
|
+ logger.error("getMonthBetweenDate—tempDate" + DateTimeUtils.format(startTime, "yyyy-MM"));
|
|
|
|
+ list.add(DateTimeUtils.format(startTime, "yyyy-MM"));
|
|
|
|
+ calendar.setTime(startTime);
|
|
|
|
+ calendar.add(2, 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+}
|