AtsOverTimeBillUtils.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. package com.kingdee.shr.ats.web.util;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  5. import com.kingdee.bos.util.BOSUuid;
  6. import com.kingdee.eas.basedata.person.PersonFactory;
  7. import com.kingdee.eas.basedata.person.PersonInfo;
  8. import com.kingdee.eas.common.EASBizException;
  9. import com.kingdee.eas.hr.ats.AtsFileBizException;
  10. import com.kingdee.eas.hr.ats.AtsOTBizException;
  11. import com.kingdee.eas.hr.ats.AtsOverTimeBillEntryCollection;
  12. import com.kingdee.eas.hr.ats.AtsOverTimeBillEntryInfo;
  13. import com.kingdee.eas.hr.ats.AtsOverTimeBillInfo;
  14. import com.kingdee.eas.hr.ats.AtsOverTimeBillResEnum;
  15. import com.kingdee.eas.hr.ats.AtsShiftInfo;
  16. import com.kingdee.eas.hr.ats.AtsUtil;
  17. import com.kingdee.eas.hr.ats.AttencePolicyInfo;
  18. import com.kingdee.eas.hr.ats.AttendanceFileHISInfo;
  19. import com.kingdee.eas.hr.ats.AttendanceFileInfo;
  20. import com.kingdee.eas.hr.ats.DayTypeEnum;
  21. import com.kingdee.eas.hr.ats.OverTimeCompensCollection;
  22. import com.kingdee.eas.hr.ats.OverTimeCompensFactory;
  23. import com.kingdee.eas.hr.ats.OverTimeCompensInfo;
  24. import com.kingdee.eas.hr.ats.OverTimeTypeFactory;
  25. import com.kingdee.eas.hr.ats.OverTimeTypeInfo;
  26. import com.kingdee.eas.hr.ats.ScheduleShiftInfo;
  27. import com.kingdee.eas.hr.ats.WorkCalendarItemCollection;
  28. import com.kingdee.eas.hr.ats.WorkCalendarItemFactory;
  29. import com.kingdee.eas.hr.ats.decimalPlace.util.DecimalPlaceUtil;
  30. import com.kingdee.eas.hr.ats.util.AtsDateUtils;
  31. import com.kingdee.eas.hr.ats.util.AtsScheduleShiftUtil;
  32. import com.kingdee.eas.hr.ats.util.common.MLUtile;
  33. import com.kingdee.shr.ats.bill.util.AtsOverTimeBillHelper;
  34. import com.kingdee.shr.ats.bill.util.FillSignCardHelper;
  35. import com.kingdee.shr.ats.service.common.AtsWebBizException;
  36. import com.kingdee.shr.ats.service.move.ot.OverTimeBillOsfProcessor;
  37. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  38. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  39. import java.math.BigDecimal;
  40. import java.sql.SQLException;
  41. import java.sql.Timestamp;
  42. import java.text.SimpleDateFormat;
  43. import java.util.Date;
  44. import java.util.HashMap;
  45. import java.util.Iterator;
  46. import java.util.List;
  47. import java.util.Map;
  48. import java.util.Map.Entry;
  49. import org.apache.axis.utils.StringUtils;
  50. import org.apache.log4j.Logger;
  51. public class AtsOverTimeBillUtils {
  52. private static Logger logger = Logger.getLogger("com.kingdee.shr.ats.web.util.AtsOverTimeBillUtils");
  53. public Map<String, Object> getDateTypeIsSame(Context ctx, String personId, List<Date> otDateList)
  54. throws BOSException {
  55. Map<String, Object> res = new HashMap();
  56. boolean flag = true;
  57. DayTypeEnum oldDayType = null;
  58. for (int index = 0; index < otDateList.size(); ++index) {
  59. String otDate = AtsDateUtils.dateLongToString((Date) otDateList.get(index));
  60. DayTypeEnum dayType = this.getDayType(ctx, personId, otDate);
  61. res.put(otDate, dayType);
  62. if (flag && oldDayType != null && oldDayType.getValue() != dayType.getValue()) {
  63. flag = false;
  64. }
  65. oldDayType = dayType;
  66. }
  67. res.put(OverTimeBillOsfProcessor.IS_SANE_DAY, flag);
  68. return res;
  69. }
  70. public DayTypeEnum getDayType(Context ctx, String personId, String otDate) {
  71. if (personId != null && !"".equals(personId) && otDate != null && !"".equals(otDate)) {
  72. try {
  73. ScheduleShiftInfo scheduleShiftInfo = AtsScheduleShiftUtil.getScheduleShiftByPriority(ctx, personId,
  74. otDate);
  75. if (null != scheduleShiftInfo) {
  76. DayTypeEnum dayTypeEnum = scheduleShiftInfo.getDayType();
  77. return dayTypeEnum;
  78. }
  79. Date otDatee = AtsDateUtils.stringToShortDate(otDate);
  80. AttendanceFileHISInfo hisInfo = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx, otDatee,
  81. personId);
  82. if (hisInfo != null && hisInfo.getCalendar() != null) {
  83. WorkCalendarItemCollection itemColl = WorkCalendarItemFactory.getLocalInstance(ctx)
  84. .getWorkCalendarItemCollection(" where date='" + otDate + "' and calendarGroup.id='"
  85. + hisInfo.getCalendar().getId().toString() + "'");
  86. if (itemColl != null && itemColl.size() > 0) {
  87. return itemColl.get(0).getDayType();
  88. }
  89. }
  90. } catch (Exception var8) {
  91. var8.printStackTrace();
  92. }
  93. }
  94. return null;
  95. }
  96. public Map<String, Object> getOverTimeTypeMap(Context ctx, String personId, String otDate) {
  97. Map<String, Object> res = new HashMap();
  98. OverTimeTypeInfo overTimeType = this.getOverTimeType(ctx, personId, otDate);
  99. if (overTimeType != null && overTimeType.getId() != null) {
  100. res.put("otTypeValue", overTimeType.getId().toString());
  101. res.put("otTypeText", overTimeType.getName());
  102. return res;
  103. } else {
  104. return res;
  105. }
  106. }
  107. public Map<String, Object> doGetOverTimeTypeAndOtCompens(Context ctx, String personId, String otDate)
  108. throws BOSException {
  109. if (otDate.length() == 19) {
  110. otDate = otDate.substring(0, 10);
  111. }
  112. Map<String, Object> res = this.getOverTimeTypeMap(ctx, personId, otDate);
  113. if (res.get("otTypeValue") == null) {
  114. return res;
  115. } else {
  116. String overTimeId = (String) res.get("otTypeValue");
  117. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  118. Date otdates = null;
  119. try {
  120. otdates = sdf.parse(otDate);
  121. } catch (Exception var9) {
  122. var9.printStackTrace();
  123. }
  124. OverTimeCompensInfo defaultcompens = this.getdefautAndOtOTCompens(ctx, personId, overTimeId, otdates);
  125. res.put("compensInfo", defaultcompens);
  126. return res;
  127. }
  128. }
  129. public OverTimeTypeInfo getOverTimeType(Context ctx, String personId, String otDate) {
  130. OverTimeTypeInfo overTimeTypeInfo = null;
  131. if (personId != null && !"".equals(personId) && otDate != null && !"".equals(otDate)) {
  132. try {
  133. ScheduleShiftInfo scheduleShiftInfo = AtsScheduleShiftUtil.getScheduleShiftByPriority(ctx, personId,
  134. otDate);
  135. if (null != scheduleShiftInfo) {
  136. DayTypeEnum dayTypeEnum = scheduleShiftInfo.getDayType();
  137. int dayType = dayTypeEnum.getValue();
  138. overTimeTypeInfo = this.getOverTimeType(ctx, dayType);
  139. } else {
  140. Date otDatee = AtsDateUtils.stringToShortDate(otDate);
  141. AttendanceFileHISInfo hisInfo = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx,
  142. otDatee, personId);
  143. if (hisInfo != null && hisInfo.getCalendar() != null) {
  144. WorkCalendarItemCollection itemColl = WorkCalendarItemFactory.getLocalInstance(ctx)
  145. .getWorkCalendarItemCollection(" where date='" + otDate + "' and calendarGroup.id='"
  146. + hisInfo.getCalendar().getId().toString() + "'");
  147. if (itemColl != null && itemColl.size() > 0) {
  148. int dayType = itemColl.get(0).getDayType().getValue();
  149. overTimeTypeInfo = this.getOverTimeType(ctx, dayType);
  150. }
  151. }
  152. }
  153. } catch (Exception var10) {
  154. var10.printStackTrace();
  155. }
  156. }
  157. return overTimeTypeInfo;
  158. }
  159. private OverTimeTypeInfo getOverTimeType(Context ctx, int dayType) {
  160. OverTimeTypeInfo overTimeType = new OverTimeTypeInfo();
  161. String overTimeName;
  162. if (dayType == 1) {
  163. overTimeType.setId(BOSUuid.read("zr+ur5D4RA+2bdVZ2VPqp46C/nU="));
  164. overTimeName = this.getOverTimeName(ctx, "zr+ur5D4RA+2bdVZ2VPqp46C/nU=");
  165. overTimeType.setName(
  166. overTimeName == null ? MLUtile.getRes(AtsOverTimeBillResEnum.WorkOnHoliday, ctx) : overTimeName);
  167. } else if (dayType == 2) {
  168. overTimeType.setId(BOSUuid.read("sRWUOt7sRpOY0TCo6NMqGY6C/nU="));
  169. overTimeName = this.getOverTimeName(ctx, "sRWUOt7sRpOY0TCo6NMqGY6C/nU=");
  170. overTimeType.setName(
  171. overTimeName == null ? MLUtile.getRes(AtsOverTimeBillResEnum.WorkOnHoliday, ctx) : overTimeName);
  172. } else {
  173. overTimeType.setId(BOSUuid.read("rBy0u1YgQ9C1OxcM85mxyY6C/nU="));
  174. overTimeName = this.getOverTimeName(ctx, "rBy0u1YgQ9C1OxcM85mxyY6C/nU=");
  175. overTimeType.setName(
  176. overTimeName == null ? MLUtile.getRes(AtsOverTimeBillResEnum.WorkOnHoliday, ctx) : overTimeName);
  177. }
  178. return overTimeType;
  179. }
  180. private String getOverTimeName(Context ctx, String id) {
  181. String name = null;
  182. try {
  183. name = OverTimeTypeFactory.getLocalInstance(ctx).getOverTimeTypeInfo(new ObjectUuidPK(id)).getName();
  184. } catch (Exception var5) {
  185. var5.printStackTrace();
  186. }
  187. return name;
  188. }
  189. public OverTimeCompensInfo getdefautAndOtOTCompens(Context ctx, String personId, String otTypeId, Date otDate)
  190. throws BOSException {
  191. OverTimeCompensInfo defaultCompensInfo = null;
  192. AttendanceFileHISInfo fileCol = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx, otDate, personId);
  193. OverTimeCompensInfo defaultotCompens = null;
  194. if ("rBy0u1YgQ9C1OxcM85mxyY6C/nU=".equals(otTypeId)) {
  195. defaultotCompens = fileCol.getAttencePolicy().getDefaultotCompens1();
  196. } else if ("zr+ur5D4RA+2bdVZ2VPqp46C/nU=".equals(otTypeId)) {
  197. defaultotCompens = fileCol.getAttencePolicy().getDefaultotCompens2();
  198. } else if ("sRWUOt7sRpOY0TCo6NMqGY6C/nU=".equals(otTypeId)) {
  199. defaultotCompens = fileCol.getAttencePolicy().getDefaultotCompens3();
  200. } else {
  201. defaultotCompens = OverTimeCompensFactory.getLocalInstance(ctx).getOverTimeCompensCollection().get(0);
  202. }
  203. String defaultId = defaultotCompens == null ? "" : defaultotCompens.getId().toString();
  204. if (!StringUtils.isEmpty(defaultId)) {
  205. try {
  206. defaultCompensInfo = OverTimeCompensFactory.getLocalInstance(ctx)
  207. .getOverTimeCompensInfo(new ObjectUuidPK(defaultId));
  208. if (defaultCompensInfo.getState().getValue() != 1) {
  209. return null;
  210. }
  211. } catch (EASBizException var10) {
  212. var10.printStackTrace();
  213. }
  214. }
  215. return defaultCompensInfo;
  216. }
  217. public String getOTCompensByOTType(Context ctx, String personId, String otTypeId, String hrOrgUnit, Date otdate)
  218. throws SHRWebException, BOSException {
  219. PersonInfo person = null;
  220. try {
  221. person = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(personId));
  222. } catch (EASBizException var14) {
  223. throw new ShrWebBizException(
  224. new AtsFileBizException(AtsFileBizException.FETCHPINFOERROR, new Object[]{personId}));
  225. }
  226. AttendanceFileHISInfo fileCol = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx, otdate, personId);
  227. if (fileCol != null && fileCol.size() != 0) {
  228. AttencePolicyInfo policyInfo = fileCol.getAttencePolicy();
  229. if (policyInfo == null) {
  230. throw new ShrWebBizException(
  231. new AtsFileBizException(AtsFileBizException.NOATTPOLICY, new Object[]{person.getName()}));
  232. } else if (policyInfo.getOtCompens1() != null && policyInfo.getOtCompens2() != null
  233. && policyInfo.getOtCompens3() != null) {
  234. String otCompens = "";
  235. if ("rBy0u1YgQ9C1OxcM85mxyY6C/nU=".equals(otTypeId)) {
  236. otCompens = fileCol.getAttencePolicy().getOtCompens1().toString();
  237. } else if ("zr+ur5D4RA+2bdVZ2VPqp46C/nU=".equals(otTypeId)) {
  238. otCompens = fileCol.getAttencePolicy().getOtCompens2().toString();
  239. } else if ("sRWUOt7sRpOY0TCo6NMqGY6C/nU=".equals(otTypeId)) {
  240. otCompens = fileCol.getAttencePolicy().getOtCompens3().toString();
  241. }
  242. String enableotCompens;
  243. OverTimeCompensCollection otCompensCollection;
  244. String[] otCompensId;
  245. int i;
  246. if (!StringUtils.isEmpty(otCompens)) {
  247. enableotCompens = "";
  248. new OverTimeCompensCollection();
  249. otCompensId = otCompens.split(",");
  250. otCompensCollection = OverTimeCompensFactory.getLocalInstance(ctx).getOverTimeCompensCollection(
  251. "where id in (" + AtsUtil.getStrFromStringArr(otCompensId) + ") and state = 1");
  252. for (i = 0; i < otCompensCollection.size(); ++i) {
  253. enableotCompens = enableotCompens + otCompensCollection.get(i).getId().toString();
  254. if (i < otCompensCollection.size() - 1) {
  255. enableotCompens = enableotCompens + ",";
  256. }
  257. }
  258. if (!StringUtils.isEmpty(enableotCompens)) {
  259. return enableotCompens;
  260. }
  261. } else {
  262. enableotCompens = "";
  263. new OverTimeCompensCollection();
  264. otCompensId = otCompens.split(",");
  265. otCompensCollection = OverTimeCompensFactory.getLocalInstance(ctx).getOverTimeCompensCollection(
  266. "where id in (SELECT fbaseinfoID from T_ATS_AtsOTCompensAvailable where fhrorguseid = '"
  267. + hrOrgUnit + "' ) and state = 1");
  268. for (i = 0; i < otCompensCollection.size(); ++i) {
  269. enableotCompens = enableotCompens + otCompensCollection.get(i).getId().toString();
  270. if (i < otCompensCollection.size() - 1) {
  271. enableotCompens = enableotCompens + ",";
  272. }
  273. }
  274. if (!StringUtils.isEmpty(enableotCompens)) {
  275. return enableotCompens;
  276. }
  277. }
  278. return otCompens;
  279. } else {
  280. throw new ShrWebBizException(
  281. new AtsFileBizException(AtsFileBizException.NOOTCOMPENSTYPE, new Object[]{person.getName()}));
  282. }
  283. } else {
  284. throw new ShrWebBizException(
  285. new AtsFileBizException(AtsFileBizException.NOTEXISTEFFECTATTFILE, new Object[]{person.getName()}));
  286. }
  287. }
  288. public void calApplyOTTime(Context ctx, AtsOverTimeBillInfo billInfo) {
  289. try {
  290. if (billInfo == null) {
  291. return;
  292. }
  293. AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
  294. if (entries == null || entries.size() == 0) {
  295. return;
  296. }
  297. AtsOverTimeBillEntryInfo entryInfo = null;
  298. Timestamp startTime = null;
  299. Timestamp endTime = null;
  300. long l = 0L;
  301. double divide = 0.0D;
  302. int decimalPlaceSystem = DecimalPlaceUtil.getDecimalPlaceSystem(ctx);
  303. for (int index = 0; index < entries.size(); ++index) {
  304. entryInfo = entries.get(index);
  305. startTime = entryInfo.getStartTime();
  306. endTime = entryInfo.getEndTime();
  307. int restTime = entryInfo.getRestTime();
  308. l = endTime.getTime() - startTime.getTime() - (long) (restTime * 60 * 1000);
  309. // if (l > 0L) {
  310. // divide = AtsDateUtils.divide((double) l, 3600000.0D, decimalPlaceSystem, 6);
  311. // entryInfo.setApplyOTTime(BigDecimal.valueOf(divide));
  312. // entryInfo.setRealOTTime(entryInfo.getApplyOTTime());
  313. // }
  314. //2024 核子基因
  315. if (l > 0L) {
  316. divide = AtsDateUtils.divide((double) l, 3600000.0D, decimalPlaceSystem, 6);
  317. double flooredValue = Math.floor(divide);
  318. entryInfo.setApplyOTTime(BigDecimal.valueOf(flooredValue));
  319. entryInfo.setRealOTTime(entryInfo.getApplyOTTime());
  320. }
  321. }
  322. } catch (Exception var14) {
  323. logger.error(var14);
  324. }
  325. }
  326. public void setEntryAdminOrgAndPosition(Context ctx, AtsOverTimeBillInfo billInfo) throws SHRWebException {
  327. if (null != billInfo.getEntries()) {
  328. String hrOrgUnitId = billInfo.getHrOrgUnit().getId().toString();
  329. for (int i = 0; i < billInfo.getEntries().size(); ++i) {
  330. try {
  331. AttendanceFileHISInfo hisInfo = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx,
  332. billInfo.getEntries().get(i).getOtDate(),
  333. billInfo.getEntries().get(i).getPerson().getId().toString());
  334. if (hisInfo == null) {
  335. throw new ShrWebBizException(AtsWebUtils.overtime_noFile_msg);
  336. }
  337. if (!hrOrgUnitId.equals(hisInfo.getHrOrgUnit().getId().toString())) {
  338. String attDateStr = AtsDateUtils.dateShortToString(billInfo.getEntries().get(i).getOtDate());
  339. throw new AtsWebBizException(new AtsOTBizException(AtsOTBizException.NOMATCHHRORGORDATE,
  340. new Object[]{hisInfo.getProposer().getName(), hisInfo.getProposer().getNumber(),
  341. attDateStr, hisInfo.getHrOrgUnit().getDisplayName(),
  342. AtsDateUtils.dateShortToString(hisInfo.getEFFDT()),
  343. AtsDateUtils.dateShortToString(hisInfo.getLEFFDT())}));
  344. }
  345. billInfo.getEntries().get(i).setAdminOrgUnit(hisInfo.getAdminOrgUnit());
  346. billInfo.getEntries().get(i).setPosition(hisInfo.getPosition());
  347. } catch (BOSException var7) {
  348. throw new SHRWebException(var7.getMessage());
  349. }
  350. }
  351. }
  352. }
  353. public Map<String, Object> doIsOTCompensEffective(Context ctx, String OTCompenId)
  354. throws EASBizException, BOSException, SQLException {
  355. AtsOverTimeBillHelper aoh = new AtsOverTimeBillHelper();
  356. boolean resFlag = aoh.isOTCompensEffect(ctx, OTCompenId);
  357. Map<String, Object> res = new HashMap();
  358. res.put("resFlag", resFlag);
  359. return res;
  360. }
  361. public ScheduleShiftInfo getMyScheduleTime(Context ctx, String personId, String date) {
  362. List<ScheduleShiftInfo> scheduleTime = this.getScheduleTime(ctx, personId, date, date);
  363. return scheduleTime != null && scheduleTime.size() != 0 ? (ScheduleShiftInfo) scheduleTime.get(0) : null;
  364. }
  365. public List<ScheduleShiftInfo> getScheduleTime(Context ctx, String personId, String preDate, String nextDate) {
  366. List<ScheduleShiftInfo> scheduleShiftInfoList = AtsScheduleShiftUtil.getScheduleShiftListByPriority(ctx,
  367. personId, preDate, nextDate);
  368. if (scheduleShiftInfoList != null && scheduleShiftInfoList.size() > 0) {
  369. return scheduleShiftInfoList;
  370. } else {
  371. Map<String, AttendanceFileInfo> attendanceFiles = AtsScheduleShiftUtil.getAttendanceFileInfoByPersonIds(ctx,
  372. personId, preDate, nextDate);
  373. if (attendanceFiles != null && attendanceFiles.size() != 0) {
  374. Map<String, AtsShiftInfo> atsShiftInfoMap = AtsScheduleShiftUtil
  375. .getScheduleShiftListByAttendanceFile(ctx, attendanceFiles);
  376. if (atsShiftInfoMap.size() == 0) {
  377. return scheduleShiftInfoList;
  378. } else {
  379. Map<String, ScheduleShiftInfo> scheduleShiftByAtsShift = AtsScheduleShiftUtil
  380. .getScheduleShiftByAtsShift(ctx, attendanceFiles, atsShiftInfoMap);
  381. Iterator iterator = scheduleShiftByAtsShift.entrySet().iterator();
  382. while (iterator.hasNext()) {
  383. scheduleShiftInfoList.add( (ScheduleShiftInfo) ((Entry) iterator.next()).getValue());
  384. }
  385. return scheduleShiftInfoList;
  386. }
  387. } else {
  388. return scheduleShiftInfoList;
  389. }
  390. }
  391. }
  392. }