BonusCycleBusDepProjectAssPersonnelDetailControllerBean.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package com.kingdee.eas.custom.projectbonus.app;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.dao.IObjectPK;
  5. import com.kingdee.bos.dao.IObjectValue;
  6. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  7. import com.kingdee.bos.metadata.data.SortType;
  8. import com.kingdee.bos.metadata.entity.*;
  9. import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
  10. import com.kingdee.eas.basedata.person.PersonInfo;
  11. import com.kingdee.eas.common.EASBizException;
  12. import com.kingdee.eas.custom.projectbonus.BonusCycleBusDepProjectAssPersonnelDetailInfo;
  13. import com.kingdee.eas.custom.projectbonus.BonusCycleBusDepProjectInfo;
  14. import com.kingdee.eas.custom.projectbonus.bizEnum.BusDepProjectStateEnum;
  15. import com.kingdee.eas.hr.emp.*;
  16. import com.kingdee.eas.hr.org.IJobGrade;
  17. import com.kingdee.eas.hr.org.JobGradeFactory;
  18. import com.kingdee.eas.hr.org.JobGradeInfo;
  19. import com.kingdee.util.DateTimeUtils;
  20. import com.kingdee.util.StringUtils;
  21. import org.apache.log4j.Logger;
  22. import java.math.BigDecimal;
  23. import java.math.RoundingMode;
  24. import java.util.Date;
  25. public class BonusCycleBusDepProjectAssPersonnelDetailControllerBean
  26. extends AbstractBonusCycleBusDepProjectAssPersonnelDetailControllerBean {
  27. private static Logger logger =
  28. Logger.getLogger(BonusCycleBusDepProjectAssPersonnelDetailControllerBean.class);
  29. /**
  30. * 保存
  31. *
  32. * @param ctx
  33. * @param model
  34. * @return
  35. * @throws BOSException
  36. * @throws EASBizException
  37. */
  38. @Override
  39. protected IObjectPK _save(Context ctx,
  40. IObjectValue model) throws BOSException, EASBizException {
  41. BonusCycleBusDepProjectAssPersonnelDetailInfo info =
  42. (BonusCycleBusDepProjectAssPersonnelDetailInfo) model;
  43. PersonInfo personInfo = info.getPerson();
  44. //职级系数
  45. BigDecimal rankCoefficient = null;
  46. if (personInfo != null) {
  47. String personId = personInfo.getId().toString();
  48. //职位
  49. PersonPositionInfo personPositionInfo = PersonPositionFactory.getLocalInstance(ctx).getPersonPositionInfo("where person.id = '" + personId + "'");
  50. info.setPosition(personPositionInfo.getPrimaryPosition());
  51. //职等信息
  52. JobGradeInfo jobGrade = info.getGrade();
  53. if (jobGrade == null) {
  54. jobGrade = getJobGradeInfo(ctx, personId);
  55. if (jobGrade != null) {
  56. rankCoefficient = jobGrade.getBigDecimal("coefficient");
  57. }
  58. info.setGrade(jobGrade);
  59. } else {
  60. IJobGrade iJobGrade = JobGradeFactory.getLocalInstance(ctx);
  61. jobGrade = iJobGrade.getJobGradeInfo(new ObjectUuidPK(jobGrade.getId()));
  62. rankCoefficient = jobGrade.getBigDecimal("coefficient");
  63. }
  64. } else {
  65. throw new BOSException("分配人员不能为空!");
  66. }
  67. //奖金期限起算日期
  68. Date bonusStartingDate = info.getBonusStartingDate();
  69. //奖金期限截止日期
  70. Date bonusDueDate = info.getBonusDueDate();
  71. if (bonusDueDate != null && bonusStartingDate != null) {
  72. if (bonusStartingDate.compareTo(bonusDueDate) >= 0) {
  73. throw new BOSException("奖金期限截止日期 不得早于或等于 奖金期限起算日期");
  74. }
  75. //出勤率 = (奖金期限截止日期-奖金期限起算日期)/180
  76. double day = DateTimeUtils.dateDiff(bonusStartingDate, bonusDueDate) / 86400000.0 / 180.0 * 100;
  77. if (day <= 0) {
  78. throw new BOSException("出勤率[" + day + "]不能小于等于0!");
  79. }
  80. BigDecimal attendanceRate = new BigDecimal(String.valueOf(day)).setScale(0, RoundingMode.HALF_UP);
  81. info.setAttendanceRate(attendanceRate);
  82. }
  83. //Q1绩效系数
  84. BigDecimal performanceCoeffQ1 = info.getPerformanceCoeffQ1();
  85. //Q2绩效系数
  86. BigDecimal performanceCoeffQ2 = info.getPerformanceCoeffQ2();
  87. if (performanceCoeffQ1 != null && performanceCoeffQ2 != null) {
  88. //个人考核系数
  89. BigDecimal assessmentCoeff = performanceCoeffQ1.add(performanceCoeffQ2).divide(BigDecimal.valueOf(2)).setScale(2, RoundingMode.HALF_UP);
  90. info.setAssessmentCoeff(assessmentCoeff);
  91. }
  92. //职能系数
  93. BigDecimal functionCoefficient = info.getFunctionCoefficient();
  94. //精力投入系数
  95. BigDecimal energyInputCoeff = info.getEnergyInputCoeff();
  96. //出勤率
  97. BigDecimal attendanceRate = info.getAttendanceRate();
  98. //个人考核系数
  99. BigDecimal assessmentCoeff = info.getAssessmentCoeff();
  100. if (functionCoefficient != null && energyInputCoeff != null
  101. && rankCoefficient != null && attendanceRate != null && assessmentCoeff != null) {
  102. //职能系数 * 精力投入系数 * 出勤率 * 职级系数 * 个人考核系数
  103. BigDecimal cumulative = functionCoefficient.multiply(energyInputCoeff)
  104. .multiply(attendanceRate).multiply(rankCoefficient).multiply(assessmentCoeff).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
  105. info.setCumulative(cumulative);
  106. }
  107. BigDecimal initialProportion = info.getInitialProportion();
  108. if (initialProportion.compareTo(BigDecimal.ZERO) < 0 || initialProportion.compareTo(BigDecimal.ONE) > 0) {
  109. throw new BOSException("个人初始比例只能在[0,1]之间");
  110. }
  111. return super._save(ctx, model);
  112. }
  113. /**
  114. * 通过员工id查询员工职层职等信息,返回职等信息
  115. *
  116. * @param ctx
  117. * @param personId
  118. * @return
  119. * @throws BOSException
  120. */
  121. private JobGradeInfo getJobGradeInfo(Context ctx, String personId) throws BOSException {
  122. IEmpPostRank iEmpPostRank = EmpPostRankFactory.getLocalInstance(ctx);
  123. SelectorItemCollection sic = new SelectorItemCollection();
  124. sic.add("jobGrade.*");
  125. FilterInfo filterInfo = new FilterInfo();
  126. FilterItemCollection filterItems = filterInfo.getFilterItems();
  127. filterItems.add(new FilterItemInfo("person", personId));
  128. filterItems.add(new FilterItemInfo("isLatest", 1));
  129. SorterItemCollection sortItems = new SorterItemCollection();
  130. SorterItemInfo leffdtSortItem = new SorterItemInfo("LEFFDT");
  131. leffdtSortItem.setSortType(SortType.DESCEND);
  132. sortItems.add(leffdtSortItem);
  133. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, sortItems);
  134. EmpPostRankCollection empPostRankCols = iEmpPostRank.getEmpPostRankCollection(entityViewInfo);
  135. if (empPostRankCols.size() > 0) {
  136. EmpPostRankInfo empPostRankInfo = empPostRankCols.get(0);
  137. return empPostRankInfo.getJobGrade();
  138. }
  139. return null;
  140. }
  141. /**
  142. * 更新部分
  143. *
  144. * @param ctx
  145. * @param model
  146. * @param sic
  147. * @throws BOSException
  148. * @throws EASBizException
  149. */
  150. @Override
  151. protected void _updatePartial(Context ctx, IObjectValue model,
  152. SelectorItemCollection sic) throws BOSException, EASBizException {
  153. BonusCycleBusDepProjectAssPersonnelDetailInfo info = (BonusCycleBusDepProjectAssPersonnelDetailInfo) model;
  154. String id = info.getId().toString();
  155. if (StringUtils.isEmpty(id)) {
  156. throw new BOSException("分配明细表id不能为空!");
  157. }
  158. for (int i = 0; i < sic.size(); i++) {
  159. String propertyName = sic.get(i).getPropertyName();
  160. if ("person".equals(propertyName)) {
  161. //如果更新分配人员信息,需要同步更新职位、职等和职级系数
  162. Object person = info.get("person");
  163. sic.add("position");
  164. sic.add("grade");
  165. if (person != null) {
  166. String personId = null;
  167. if (person instanceof String) {
  168. personId = (String) person;
  169. } else {
  170. PersonInfo personInfo = (PersonInfo) person;
  171. personId = personInfo.getId().toString();
  172. }
  173. //职位
  174. PersonPositionInfo personPositionInfo = PersonPositionFactory.getLocalInstance(ctx).getPersonPositionInfo("where person.id = '" + personId + "'");
  175. info.setPosition(personPositionInfo.getPrimaryPosition());
  176. //职等信息
  177. JobGradeInfo jobGrade = getJobGradeInfo(ctx, personId);
  178. info.setGrade(jobGrade);
  179. } else {
  180. throw new BOSException("分配人员不能为空!");
  181. }
  182. } else if ("initialProportion".equals(propertyName) && info.getInitialProportion() != null) {
  183. BigDecimal initialProportion = info.getInitialProportion();
  184. if (initialProportion.compareTo(BigDecimal.ZERO) < 0 || initialProportion.compareTo(BigDecimal.ONE) > 0) {
  185. throw new BOSException("个人初始比例只能在[0,1]之间");
  186. }
  187. }
  188. }
  189. super._updatePartial(ctx, model, sic);
  190. }
  191. /**
  192. * 删除
  193. *
  194. * @param ctx
  195. * @param pk
  196. * @throws BOSException
  197. * @throws EASBizException
  198. */
  199. @Override
  200. protected void _delete(Context ctx, IObjectPK pk) throws BOSException, EASBizException {
  201. SelectorItemCollection sic = new SelectorItemCollection();
  202. sic.add("parent.state");
  203. sic.add("parent.project.name");
  204. sic.add("parent.busDep.name");
  205. BonusCycleBusDepProjectAssPersonnelDetailInfo info =
  206. (BonusCycleBusDepProjectAssPersonnelDetailInfo) getValue(ctx, pk, sic);
  207. BonusCycleBusDepProjectInfo parent = info.getParent();
  208. BusDepProjectStateEnum state = parent.getState();
  209. if (!BusDepProjectStateEnum.ENABLE.equals(state)) {
  210. throw new BOSException(getBusDepMsg(parent) + "非启用状态,不允许删除该项目下的人员数据!");
  211. }
  212. super._delete(ctx, pk);
  213. }
  214. private String getBusDepMsg(BonusCycleBusDepProjectInfo info) {
  215. AdminOrgUnitInfo project = info.getProject();
  216. if (project != null) {
  217. String projectProject = project.getName();
  218. return "项目[" + projectProject + "]";
  219. } else {
  220. String busdepName = info.getBusDep().getName();
  221. return "事业部[" + busdepName + "]";
  222. }
  223. }
  224. }