UserNewWagePayrollServiceImpl.java 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149
  1. package cn.com.lzt.userwage.service.impl;
  2. import java.math.BigDecimal;
  3. import java.text.DateFormat;
  4. import java.text.ParseException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ArrayList;
  7. import java.util.Calendar;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10. import java.util.HashSet;
  11. import java.util.List;
  12. import java.util.Map;
  13. import java.util.Set;
  14. import java.util.TreeSet;
  15. import org.apache.commons.lang.time.DurationFormatUtils;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.hibernate.transform.Transformers;
  18. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  19. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  20. import org.jeecgframework.core.constant.Globals;
  21. import org.jeecgframework.core.util.MyBeanUtils;
  22. import org.jeecgframework.core.util.oConvertUtils;
  23. import org.jeecgframework.minidao.pojo.MiniDaoPage;
  24. import org.jeecgframework.web.system.dto.TSDepartDto;
  25. import org.jeecgframework.web.system.pojo.base.TSUserOrgDto;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import com.alibaba.fastjson.JSONObject;
  30. import cn.com.lzt.arrangedutyoperate.entity.ArrangeDutyOperateEntity;
  31. import cn.com.lzt.basewagestrategy.entity.TBusBaseWagestrategyEntity;
  32. import cn.com.lzt.calendar.entity.CalendarEntity;
  33. import cn.com.lzt.certificatesubsidy.entity.CertificateSubsidyEntity;
  34. import cn.com.lzt.comagesubsidy.entity.ComageSubsidyEntity;
  35. import cn.com.lzt.duties.entity.DutiesEntity;
  36. import cn.com.lzt.dutyfeestrategy.entity.DutyfeeStrategyEntity;
  37. import cn.com.lzt.jiaojinsubsidy.entity.JiaojinSubsidyStrategyEntity;
  38. import cn.com.lzt.mealssubsidy.entity.MealsSubsidyEntity;
  39. import cn.com.lzt.megathermalsubsidy.entity.MegathermalSubsidyEntity;
  40. import cn.com.lzt.othersubsidy.entity.OtherSubsidyEntity;
  41. import cn.com.lzt.otherworksubsidy.entity.OtherworkSubsidyEntity;
  42. import cn.com.lzt.overtimepaystrategy.entity.OvertimepayStrategyEntity;
  43. import cn.com.lzt.overtimestats.dto.OvertimeDto;
  44. import cn.com.lzt.personnelbasearchivesmanage.dao.PersonnelBaseArchivesManageDao;
  45. import cn.com.lzt.personnelbasearchivesmanage.dto.PersonnelBaseArchivesManageOutDto;
  46. import cn.com.lzt.projectrating.dao.ProjectRatingMinidaoDao;
  47. import cn.com.lzt.projectrating.dto.ProjectRatingDto;
  48. import cn.com.lzt.providentfundstrategy.entity.ProvidentFundStrategyEntity;
  49. import cn.com.lzt.socialsecuritystrategy.entity.SocialSecurityStrategyEntity;
  50. import cn.com.lzt.talentsubsidy.dao.UserTalentSubsidyMiniDao;
  51. import cn.com.lzt.talentsubsidy.dto.UserTalentSubsidyDto;
  52. import cn.com.lzt.trafficsubsidy.entity.TrafficSubsidyEntity;
  53. import cn.com.lzt.useractiviti.overtime.service.TBusActivitiOvertimeServiceI;
  54. import cn.com.lzt.userattendancedetail.dto.AttendanceDetailJsonObj;
  55. import cn.com.lzt.userattendancedetail.dto.AttendanceTotalJsonObj;
  56. import cn.com.lzt.userattendancedetail.entity.UserAttendanceDetailEntity;
  57. import cn.com.lzt.userattendancedetail.service.UserAttendanceDetailServiceI;
  58. import cn.com.lzt.userattendancetotal.entity.UserAttendanceTotalEntity;
  59. import cn.com.lzt.userattendancetotal.service.UserAttendanceTotalServiceI;
  60. import cn.com.lzt.usercertificate.entity.UserCertificateEntity;
  61. import cn.com.lzt.userotherwork.entity.UserOtherworkEntity;
  62. import cn.com.lzt.userwage.dao.UserWageMinidaoDao;
  63. import cn.com.lzt.userwage.dto.YearMonthDay;
  64. import cn.com.lzt.userwage.entity.UserNewWageEntity;
  65. import cn.com.lzt.userwage.service.UserNewWagePayrollServiceI;
  66. import cn.com.lzt.userwage.service.UserNewWageServiceI;
  67. import cn.com.lzt.userwagestrategy.entity.UserNewWagestrategyEntity;
  68. import cn.com.lzt.userwagestrategyhistory.entity.UserWagestrategyHistoryEntity;
  69. import cn.com.lzt.wagestrategy.dao.WagestrategyMiniDao;
  70. import cn.com.lzt.wagestrategy.dto.WagestrategyDto;
  71. /**
  72. * 工资核算
  73. *
  74. * @author Administrator
  75. *
  76. */
  77. @Service("userNewWagePayrollService")
  78. @Transactional
  79. public class UserNewWagePayrollServiceImpl extends CommonServiceImpl implements UserNewWagePayrollServiceI {
  80. @Autowired
  81. private UserNewWageServiceI userWageServiceI;
  82. @Autowired
  83. private UserAttendanceTotalServiceI userAttendanceTotalService;
  84. @Autowired
  85. private UserAttendanceDetailServiceI userAttendanceDetailService;
  86. @Autowired
  87. private UserWageMinidaoDao userWageMinidaoDao;
  88. @Autowired
  89. private WagestrategyMiniDao wagestrategyMiniDao;
  90. @Autowired
  91. PersonnelBaseArchivesManageDao personnelBaseArchivesManageDao;
  92. @Autowired
  93. UserTalentSubsidyMiniDao userTalentSubsidyMiniDao;
  94. @Autowired
  95. private TBusActivitiOvertimeServiceI overtimeService;
  96. @Autowired
  97. private ProjectRatingMinidaoDao projectRationgDao;
  98. /**
  99. * type 0.定时任务 1.手动审核所有 2.手动审核部分
  100. *
  101. * @throws Exception
  102. */
  103. @Override
  104. public void userPayroll(List<UserNewWagestrategyEntity> userWagestrategyEntity, String moth, String type) throws Exception {
  105. List<UserNewWageEntity> userWageList = null;
  106. // List<UserWagestrategyHistoryEntity> uwhList = null;
  107. List<UserNewWageEntity> userWageList1 = null;
  108. HashMap<String, HashMap<String, Object>> hm_cache = new HashMap<>();
  109. userWageList = new ArrayList<UserNewWageEntity>();
  110. // uwhList = new ArrayList<UserWagestrategyHistoryEntity>();
  111. // List<UserWagestrategyHistoryEntity> uwhList1 = null;
  112. userWagestrategyEntity = filterRepeatUserWagestrategy(userWagestrategyEntity);
  113. boolean isCacheAll = true;
  114. if (!"0".equals(type)) {
  115. if ("1".equals(type)) {
  116. StringBuffer hql = new StringBuffer("from UserNewWageEntity where monthly = :monthly");
  117. userWageList1 = this.getSession().createQuery(hql.toString()).setParameter("monthly", moth).list();
  118. } else {
  119. List<String> userid = new ArrayList<String>();
  120. for (UserNewWagestrategyEntity userWages : userWagestrategyEntity) {
  121. userid.add(userWages.getUserid());
  122. }
  123. StringBuffer hql = new StringBuffer("from UserNewWageEntity where userid in (:userid) and monthly = :monthly");
  124. userWageList1 = this.getSession().createQuery(hql.toString()).setParameterList("userid", userid).setParameter("monthly", moth).list();
  125. isCacheAll = false; // 个人核算不用缓存
  126. }
  127. } else {
  128. moth = getMonthlys(); // getMonthlys();//"2017-09";//"2017-10"; //
  129. StringBuffer hql = new StringBuffer("from UserNewWageEntity where monthly = :monthly");
  130. userWageList1 = this.getSession().createQuery(hql.toString()).setParameter("monthly", moth).list();
  131. }
  132. UserNewWageEntity uw = null;
  133. UserWagestrategyHistoryEntity uwh = null;
  134. StringBuffer hql = new StringBuffer("from MealsSubsidyEntity where deleteFlag = 0 and status = 0");
  135. List<MealsSubsidyEntity> meslList = this.getSession().createQuery(hql.toString()).list();
  136. for (UserNewWagestrategyEntity us : userWagestrategyEntity) {
  137. PersonnelBaseArchivesManageOutDto per = getPersonnelDto(hm_cache, isCacheAll, us);
  138. if (isValidWagePerson(per, moth)) {
  139. uwh = initUserWagestrategyHistoryEntity(moth, us);
  140. uw = initUserNewWagestrategyEntity(moth, hm_cache, us);
  141. UserAttendanceTotalEntity uat = getUserAttendanceTotalEntity(moth, hm_cache, isCacheAll, us);
  142. if (isCompleteMonthWage(us, per)) {
  143. uw = calcCompleteMonthWage(moth, hm_cache, isCacheAll, uw, meslList, us, per, uat);
  144. } else {
  145. uw = calEntryOrLeaveWage(isCacheAll, hm_cache, uw, us, uat, moth, per, meslList);
  146. }
  147. if (uw.getActualMoney() != null && uw.getActualMoney().intValue() < 0) {
  148. uw.setActualMoney(BigDecimal.ZERO);
  149. }
  150. // 记录月度员工工资策略历史记录表
  151. userWageList.add(uw);
  152. // uwhList.add(historyUW(uwh, us));
  153. }
  154. }
  155. if (!"0".equals(type)) {
  156. // if (!uwhList1.isEmpty()) {
  157. // for (UserWagestrategyHistoryEntity u : uwhList) {
  158. // boolean temp = true;
  159. // for (UserWagestrategyHistoryEntity userWage1 : uwhList1) {
  160. // if (u.getUserid().equals(userWage1.getUserid())) {
  161. // MyBeanUtils.copyBeanNotNull2Bean(u, userWage1);
  162. // saveOrUpdate(userWage1);
  163. // temp = false;
  164. // }
  165. // }
  166. //
  167. // if (temp) {
  168. // saveOrUpdate(u);
  169. // }
  170. // }
  171. // } else {
  172. // this.batchSave(uwhList);
  173. // }
  174. if (!userWageList1.isEmpty()) {
  175. for (UserNewWageEntity uge : userWageList) {
  176. boolean temp = true;
  177. for (UserNewWageEntity uwEntity : userWageList1) {
  178. if (uge.getUserid().equals(uwEntity.getUserid())) {
  179. // 重新核算后留下已调整的部分
  180. refillAdjustedAttributes(uge, uwEntity);
  181. saveOrUpdate(uwEntity);
  182. temp = false;
  183. }
  184. }
  185. if (temp) {
  186. saveOrUpdate(uge);
  187. }
  188. }
  189. } else {
  190. this.batchSave(userWageList);
  191. }
  192. } else {
  193. deleteAllEntitie(userWageList1);
  194. //deleteAllEntitie(uwhList1);
  195. this.batchSave(userWageList);
  196. // this.batchSave(uwhList);
  197. }
  198. hm_cache.clear();
  199. }
  200. private UserAttendanceTotalEntity getUserAttendanceTotalEntity(String moth, HashMap<String, HashMap<String, Object>> hm_cache, boolean isCacheAll, UserNewWagestrategyEntity us) {
  201. List<UserAttendanceTotalEntity> uatList = getUserAttendanceTotalEntityList(moth, hm_cache, isCacheAll, us);
  202. UserAttendanceTotalEntity uat = null;
  203. if (uatList == null || uatList.isEmpty()) {
  204. uat = new UserAttendanceTotalEntity();
  205. } else {
  206. uat = uatList.get(0);
  207. }
  208. return uat;
  209. }
  210. private UserNewWageEntity initUserNewWagestrategyEntity(String moth, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us) {
  211. UserNewWageEntity uw;
  212. uw = new UserNewWageEntity();
  213. uw.setUserid(us.getUserid());
  214. uw.setBelongUnitid(us.getBelongUnitid());
  215. // 存入项目(或部门)id
  216. uw.setPjtId(getBybelongId(hm_cache, us.getUserid()));
  217. // 保存上个月度
  218. uw.setMonthly(moth);
  219. return uw;
  220. }
  221. private UserWagestrategyHistoryEntity initUserWagestrategyHistoryEntity(String moth, UserNewWagestrategyEntity us) {
  222. UserWagestrategyHistoryEntity uwh;
  223. uwh = new UserWagestrategyHistoryEntity();
  224. uwh.setBelongUnitid(us.getBelongUnitid());
  225. uwh.setUserid(us.getUserid());
  226. uwh.setStrategyMonth(moth);
  227. return uwh;
  228. }
  229. private void refillAdjustedAttributes(UserNewWageEntity uge, UserNewWageEntity uwEntity) throws Exception {
  230. BigDecimal bufa = uwEntity.getReissue();
  231. BigDecimal jiangjin = uwEntity.getBonus();
  232. BigDecimal otherKouchu = uwEntity.getOtherDebit();
  233. BigDecimal gaowen = uwEntity.getMegathermalSubsidy();
  234. BigDecimal jiaojinbutie = uwEntity.getPaymentSubsidy();
  235. String descrip = uwEntity.getRemark();
  236. String status = uwEntity.getStatus();
  237. MyBeanUtils.copyBeanNotNull2Bean(uge, uwEntity);
  238. uwEntity.setStatus(status);
  239. uwEntity.setReissue(bufa);
  240. uwEntity.setBonus(jiangjin);
  241. uwEntity.setOtherDebit(otherKouchu);
  242. uwEntity.setRemark(descrip);
  243. uwEntity.setMegathermalSubsidy(gaowen);
  244. uwEntity.setPaymentSubsidy(jiaojinbutie);
  245. // 手动核算的时候需要重新计算实发工资
  246. uwEntity.recalculatePreTaxMoney();
  247. uwEntity.recalculateActualMoney();
  248. uwEntity.recalculateComCost();
  249. }
  250. private UserNewWageEntity calcCompleteMonthWage(String moth, HashMap<String, HashMap<String, Object>> hm_cache, boolean isCacheAll, UserNewWageEntity uw, List<MealsSubsidyEntity> meslList, UserNewWagestrategyEntity us,
  251. PersonnelBaseArchivesManageOutDto per, UserAttendanceTotalEntity uat) throws ParseException {
  252. // 查询基本工资
  253. uw = basicWagePartCalculation(isCacheAll, hm_cache, us, uw, per);
  254. // 人才津贴计算
  255. uw = talentCalculation(isCacheAll, hm_cache, us, uw, per);
  256. // 司龄津贴计算
  257. uw = comyearCalculation(hm_cache, us, uw, per);
  258. // 其它工作补贴
  259. uw = otherworkCalculation(isCacheAll, hm_cache, us, uw, per);
  260. //项目监管绩效和项目现场绩效
  261. uw = projectAllowanceCalculation(isCacheAll, hm_cache, us, uw, per);
  262. // 查询所有设定策略信息
  263. uw = selectStrategy(isCacheAll, hm_cache, us, uw, per);
  264. // 餐费补助
  265. uw = mealsCalculation(isCacheAll, hm_cache, uat, us, uw, meslList);
  266. // 工资扣除项
  267. uw = deductionCalculation(uat, us, uw, per, true);
  268. // 公积金和社保
  269. uw = socialSecurityProvidentFund(isCacheAll, hm_cache, uat, us, uw, per);
  270. // 加班费
  271. uw = overtimeCalculation(isCacheAll, hm_cache, uat, us, uw, moth, per);
  272. uw.setStatus(Globals.ARRANGESTATUS_0.toString());
  273. uw.setTaxMoney(new BigDecimal(0));
  274. if (us.getDeductPay() != null && us.getDeductPay().doubleValue() > 0) {
  275. uw.setOtherDebit(us.getDeductPay());
  276. }
  277. // 代扣款
  278. if (us.getDaikouFee() != null && us.getDaikouFee().doubleValue() > 0) {
  279. uw.setDaikouDebit(us.getDaikouFee());
  280. }
  281. if (uw.getOtherDebit() == null) {
  282. uw.setOtherDebit(BigDecimal.ZERO);
  283. }
  284. if (uw.getDaikouDebit() == null) {
  285. uw.setDaikouDebit(BigDecimal.ZERO);
  286. }
  287. if (uw.getBonus() == null) {
  288. uw.setBonus(BigDecimal.ZERO);
  289. }
  290. if (uw.getFakuan() == null) {
  291. uw.setFakuan(BigDecimal.ZERO);
  292. }
  293. uw.recalculatePreTaxMoney();
  294. uw.recalculateActualMoney();
  295. uw.recalculateComCost();
  296. uw.setReissue(new BigDecimal(0));
  297. // 判断该员工当月是否被调动过
  298. if ("1".equals(uat.getIfmoved())) {
  299. List<UserAttendanceDetailEntity> uadeList = this.getSession().createSQLQuery("select * from t_bus_user_attendance_detail where attendance_id = '" + uat.getId() + "' and borrowspid = 1")
  300. .addEntity(UserAttendanceDetailEntity.class).list();
  301. if (!uadeList.isEmpty() && uadeList.size() > 0) {
  302. for (UserAttendanceDetailEntity u : uadeList) {
  303. uw.setReissue(uw.getReissue().add(u.getDayPay()));
  304. }
  305. }
  306. }
  307. return uw;
  308. }
  309. /**
  310. * @param isCacheAll
  311. * @param hm_cache
  312. * @param us
  313. * @param uw
  314. * @param per
  315. * @return
  316. */
  317. private UserNewWageEntity otherworkCalculation(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
  318. BigDecimal otherworksub = getOtherworkSubsidyMoneyWithCache(hm_cache, per.getUserId());
  319. if(otherworksub != null) {
  320. uw.setOtherworkSubsidy(otherworksub);
  321. }else {
  322. uw.setOtherworkSubsidy(BigDecimal.ZERO);
  323. }
  324. return uw;
  325. }
  326. /**
  327. * 计算项目工资和月度奖金,都按照比例分
  328. * @param isCacheAll
  329. * @param hm_cache
  330. * @param us
  331. * @param uw
  332. * @param per
  333. * @return
  334. */
  335. private UserNewWageEntity projectAllowanceCalculation(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
  336. String userid = us.getUserid();
  337. String years = uw.getMonthly().split("-")[0];
  338. HashSet<ProjectRatingDto> projectratingdtoList = getProjectRatingDtosWithCache(hm_cache, years, userid);
  339. BigDecimal jianguanValue = BigDecimal.ZERO;
  340. BigDecimal xianchangValue = BigDecimal.ZERO;
  341. BigDecimal projactPerform = BigDecimal.ZERO;
  342. uw.setJianguanBonus(jianguanValue);
  343. uw.setXianchangBonus(xianchangValue);
  344. uw.setProjectPerformance(projactPerform);
  345. if(projectratingdtoList != null) {
  346. for(ProjectRatingDto pdto : projectratingdtoList) {
  347. BigDecimal jianguanweight = pdto.getJianguanWeight();
  348. if(jianguanweight == null) {
  349. jianguanweight = BigDecimal.ZERO;
  350. }
  351. double jiaguanRate = jianguanweight.doubleValue()/100;
  352. BigDecimal projectwage = pdto.getProjectWage();
  353. BigDecimal bonus = pdto.getBonus();
  354. if(projectwage == null) {
  355. projectwage = BigDecimal.ZERO;
  356. }
  357. if(bonus == null) {
  358. bonus = BigDecimal.ZERO;
  359. }
  360. if(userid.equals(pdto.getJianguanLeader())) {
  361. jianguanValue = jianguanValue.add(projectwage.multiply(new BigDecimal(jiaguanRate)).setScale(2, BigDecimal.ROUND_HALF_UP));
  362. projactPerform = projactPerform.add(bonus.multiply(new BigDecimal(jiaguanRate)).setScale(2, BigDecimal.ROUND_HALF_UP));
  363. }
  364. if(userid.equals(pdto.getXianchangLeader())) {
  365. if(org.apache.commons.lang.StringUtils.isNotEmpty(pdto.getJianguanLeader())){
  366. xianchangValue = xianchangValue.add(projectwage.multiply(new BigDecimal(1-jiaguanRate)).setScale(2, BigDecimal.ROUND_HALF_UP));
  367. projactPerform = projactPerform.add(bonus.multiply(new BigDecimal(1-jiaguanRate)).setScale(2, BigDecimal.ROUND_HALF_UP));
  368. }else {
  369. // 没有兼管经理,拿100%绩效
  370. xianchangValue = xianchangValue.add(projectwage.multiply(new BigDecimal(1.0)).setScale(2, BigDecimal.ROUND_HALF_UP));
  371. projactPerform = projactPerform.add(bonus.multiply(new BigDecimal(1.0)).setScale(2, BigDecimal.ROUND_HALF_UP));
  372. }
  373. }
  374. }
  375. uw.setJianguanBonus(jianguanValue);
  376. uw.setXianchangBonus(xianchangValue);
  377. uw.setProjectPerformance(projactPerform);
  378. }
  379. return uw;
  380. }
  381. private HashSet<ProjectRatingDto> getProjectRatingDtosWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String years, String userid) {
  382. HashMap<String, Object> hm = hm_cache.get("getProjectAllowanceWithCache");
  383. if (hm == null) {
  384. hm = new HashMap<>();
  385. hm_cache.put("getProjectAllowanceWithCache", hm);
  386. MiniDaoPage<ProjectRatingDto> entitiesPrjMiniDaoPage = projectRationgDao.getAllEntitiesNopage(years);
  387. for(ProjectRatingDto pj : entitiesPrjMiniDaoPage.getResults()) {
  388. if(pj.getJianguanLeader() != null) {
  389. if(hm.containsKey(pj.getJianguanLeader())){
  390. HashSet<ProjectRatingDto> list = (HashSet<ProjectRatingDto>)hm.get(pj.getJianguanLeader());
  391. list.add(pj);
  392. }else {
  393. HashSet<ProjectRatingDto> list = new HashSet<>();
  394. list.add(pj);
  395. hm.put(pj.getJianguanLeader(), list);
  396. }
  397. }
  398. if(pj.getXianchangLeader() != null) {
  399. if(hm.containsKey(pj.getXianchangLeader())){
  400. HashSet<ProjectRatingDto> list = (HashSet<ProjectRatingDto>)hm.get(pj.getXianchangLeader());
  401. list.add(pj);
  402. }else {
  403. HashSet<ProjectRatingDto> list = new HashSet<>();
  404. list.add(pj);
  405. hm.put(pj.getXianchangLeader(), list);
  406. }
  407. }
  408. }
  409. }
  410. return (HashSet<ProjectRatingDto>) hm.get(userid);
  411. }
  412. /**
  413. * @param hm_cache
  414. * @param userid
  415. * @return
  416. */
  417. private BigDecimal getOtherworkSubsidyMoneyWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
  418. HashMap<String, Object> hm = hm_cache.get("getOtherworkSubsidyMoneyWithCache");
  419. if (hm == null) {
  420. hm = new HashMap<>();
  421. hm_cache.put("getOtherworkSubsidyMoneyWithCache", hm);
  422. StringBuffer str_user_otherwork = new StringBuffer();
  423. str_user_otherwork.append("select * from t_bus_user_otherwork where delete_flag = 0");
  424. List<UserOtherworkEntity> entitiesUserOtherworkEntity = this.getSession().createSQLQuery(str_user_otherwork.toString())
  425. .addEntity(UserOtherworkEntity.class).list();
  426. String str_subsidy = "select * from t_bus_otherwork_subsidy where delete_flag = 0 and status=0";
  427. List<OtherworkSubsidyEntity> subList = this.getSession().createSQLQuery(str_subsidy).addEntity(OtherworkSubsidyEntity.class).list();
  428. HashMap<String, OtherworkSubsidyEntity> subMap = new HashMap<>();
  429. for (OtherworkSubsidyEntity sub : subList) {
  430. subMap.put(sub.getId(), sub);
  431. }
  432. for (UserOtherworkEntity user_otherwork_Entity : entitiesUserOtherworkEntity) {
  433. String userInEntity = user_otherwork_Entity.getUserid();
  434. String OtherworkSubInEntity = user_otherwork_Entity.getOtherworkSubsidy();
  435. OtherworkSubsidyEntity subEntity = subMap.get(OtherworkSubInEntity);
  436. BigDecimal subMoney = BigDecimal.ZERO;
  437. if (subEntity != null && subEntity.getMoney() != null) {
  438. subMoney = subEntity.getMoney();
  439. }
  440. if (hm.containsKey(userInEntity)) {
  441. BigDecimal old = BigDecimal.ZERO;
  442. if ((BigDecimal) hm.get(userInEntity) != null) {
  443. old = (BigDecimal) hm.get(userInEntity);
  444. }
  445. hm.put(userInEntity, subMoney.add(old));
  446. } else {
  447. if (subMoney == null) {
  448. subMoney = BigDecimal.ZERO;
  449. }
  450. hm.put(userInEntity, subMoney);
  451. }
  452. }
  453. }
  454. return (BigDecimal) hm.get(userid);
  455. }
  456. /**
  457. * 司龄计算
  458. * @param hm_cache
  459. * @param us
  460. * @param uw
  461. * @param per
  462. * @return
  463. */
  464. private UserNewWageEntity comyearCalculation(HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
  465. int comage = getComAge(per);
  466. ComageSubsidyEntity comageSub = getComageSubsidyEntityWithCache(hm_cache);
  467. BigDecimal comsub = BigDecimal.ZERO;
  468. uw.setComyearAllowance(comsub);
  469. if(comage >= comageSub.getMinYears()) {
  470. comsub=comsub.add(comageSub.getMin());
  471. comsub=comsub.add(comageSub.getIncrease().multiply(new BigDecimal(comage).subtract(new BigDecimal(comageSub.getMinYears()))));
  472. if(comsub.compareTo(comageSub.getMax()) < 0) {
  473. uw.setComyearAllowance(comsub);
  474. }else {
  475. uw.setComyearAllowance(comageSub.getMax());
  476. }
  477. }
  478. return uw;
  479. }
  480. /**
  481. * @param hm_cache
  482. * @return
  483. */
  484. private ComageSubsidyEntity getComageSubsidyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache) {
  485. HashMap<String, Object> hm = hm_cache.get("getComageSubsidyEntityWithCache");
  486. if (hm == null) {
  487. hm = new HashMap<>();
  488. hm_cache.put("getComageSubsidyEntityWithCache", hm);
  489. CriteriaQuery specialcq = new CriteriaQuery(ComageSubsidyEntity.class);
  490. List<ComageSubsidyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  491. hm.put("ALL", entitiesFromDB.get(0));
  492. }
  493. return (ComageSubsidyEntity)hm.get("ALL");
  494. }
  495. /**
  496. * @param per
  497. * @return
  498. */
  499. private int getComAge(PersonnelBaseArchivesManageOutDto per) {
  500. if(per != null && per.getContractStime() != null) {
  501. Calendar contractStime = Calendar.getInstance();
  502. Calendar endtime = Calendar.getInstance();
  503. contractStime.setTime(per.getContractStime());
  504. endtime.setTime(new Date());
  505. endtime.set(Calendar.DAY_OF_MONTH, 1); //截至当月1日,如果是上个月最后一天之前入职,则可算出满n年
  506. String y = DurationFormatUtils.formatPeriod(contractStime.getTime().getTime(), endtime.getTime().getTime(), "y");
  507. return Integer.parseInt(y);
  508. }
  509. return 0;
  510. }
  511. /**
  512. * @param isCacheAll
  513. * @param hm_cache
  514. * @param us
  515. * @param uw
  516. * @param per
  517. * @return
  518. */
  519. private UserNewWageEntity talentCalculation(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
  520. BigDecimal talentAll = BigDecimal.ZERO;
  521. // 初始是0
  522. uw.setTalentAllowance(talentAll);
  523. List<UserTalentSubsidyDto> talentDtos = getUserTalentSubsidyDtosWithCache(isCacheAll, hm_cache, us, uw, per);
  524. if(talentDtos != null && talentDtos.size()>0) {
  525. for(UserTalentSubsidyDto dto : talentDtos) {
  526. if(dto.getMoney() != null) {
  527. talentAll = talentAll.add(dto.getMoney());
  528. }
  529. }
  530. uw.setTalentAllowance(talentAll);
  531. }
  532. return uw;
  533. }
  534. /**
  535. * @param isCacheAll
  536. * @param hm_cache
  537. * @param us
  538. * @param uw
  539. * @param per
  540. * @return
  541. */
  542. private List<UserTalentSubsidyDto> getUserTalentSubsidyDtosWithCache(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw,
  543. PersonnelBaseArchivesManageOutDto per) {
  544. HashMap<String, Object> hm = hm_cache.get("getUserTalentSubsidyDtosWithCache");
  545. if (hm == null) {
  546. hm = new HashMap<>();
  547. hm_cache.put("getUserTalentSubsidyDtosWithCache", hm);
  548. List<UserTalentSubsidyDto> entitiesFromDB = userTalentSubsidyMiniDao.getAllEntities(isCacheAll?null:per.getUserId()).getResults();
  549. for (UserTalentSubsidyDto entity : entitiesFromDB) {
  550. String userInEntity = entity.getUserid();
  551. if (hm.containsKey(userInEntity)) {
  552. List<UserTalentSubsidyDto> entitylist = (List<UserTalentSubsidyDto>) hm.get(userInEntity);
  553. entitylist.add(entity);
  554. } else {
  555. List<UserTalentSubsidyDto> newlist = new ArrayList<>();
  556. newlist.add(entity);
  557. hm.put(userInEntity, newlist);
  558. }
  559. }
  560. }
  561. List<UserTalentSubsidyDto> dtoInDB = (List<UserTalentSubsidyDto>) hm.get(per.getUserId());
  562. // 把人员信息里的教育背景关联上,暂时先不关联。
  563. joinEducationInfo(dtoInDB);
  564. return dtoInDB;
  565. }
  566. /**
  567. * @param dtoInDB
  568. */
  569. private void joinEducationInfo(List<UserTalentSubsidyDto> dtoInDB) {
  570. }
  571. private List<UserAttendanceTotalEntity> getUserAttendanceTotalEntityList(String moth, HashMap<String, HashMap<String, Object>> hm_cache, boolean isCacheUsed, UserNewWagestrategyEntity us) {
  572. List<UserAttendanceTotalEntity> uatList = null;
  573. if (isCacheUsed) {
  574. uatList = getUserAttendanceTotalEntityWithCache(hm_cache, us.getUserid(), moth);
  575. } else {
  576. uatList = userAttendanceTotalService.getByuserid(us.getUserid(), moth);
  577. }
  578. return uatList;
  579. }
  580. private PersonnelBaseArchivesManageOutDto getPersonnelDto(HashMap<String, HashMap<String, Object>> hm_cache, boolean isCacheUsed, UserNewWagestrategyEntity us) {
  581. PersonnelBaseArchivesManageOutDto per = null;
  582. if (isCacheUsed) {
  583. per = getPersonnelBaseArchivesManageEntityWithCache(hm_cache, us.getUserid());
  584. } else {
  585. MiniDaoPage<PersonnelBaseArchivesManageOutDto> minPage = personnelBaseArchivesManageDao.getEntityByUserId(us.getUserid());
  586. per = minPage.getResults().get(0);
  587. }
  588. return per;
  589. }
  590. /**
  591. * 去重
  592. *
  593. * @param userWagestrategyEntity
  594. * @return
  595. */
  596. private List<UserNewWagestrategyEntity> filterRepeatUserWagestrategy(List<UserNewWagestrategyEntity> userWagestrategyEntity) {
  597. HashMap<String, UserNewWagestrategyEntity> hm_userid = new HashMap<>();
  598. if (userWagestrategyEntity != null) {
  599. for (UserNewWagestrategyEntity entity : userWagestrategyEntity) {
  600. hm_userid.put(entity.getUserid(), entity);
  601. }
  602. }
  603. return new ArrayList<UserNewWagestrategyEntity>(hm_userid.values());
  604. }
  605. /**
  606. * @param userid
  607. * @param moth
  608. * @return
  609. */
  610. private List<UserAttendanceTotalEntity> getUserAttendanceTotalEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid, String moth) {
  611. HashMap<String, Object> hm = hm_cache.get("getUserAttendanceTotalEntityWithCache");
  612. if (hm == null) {
  613. hm = new HashMap<>();
  614. hm_cache.put("getUserAttendanceTotalEntityWithCache", hm);
  615. CriteriaQuery specialcq = new CriteriaQuery(UserAttendanceTotalEntity.class);
  616. specialcq.eq("yearmonth", moth);
  617. specialcq.add();
  618. List<UserAttendanceTotalEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  619. for (UserAttendanceTotalEntity entity : entitiesFromDB) {
  620. String userInEntity = entity.getUserId();
  621. if (hm.containsKey(userInEntity)) {
  622. List<UserAttendanceTotalEntity> entitylist = (List<UserAttendanceTotalEntity>) hm.get(userInEntity);
  623. entitylist.add(entity);
  624. } else {
  625. List<UserAttendanceTotalEntity> newlist = new ArrayList<>();
  626. newlist.add(entity);
  627. hm.put(userInEntity, newlist);
  628. }
  629. }
  630. }
  631. return (List<UserAttendanceTotalEntity>) hm.get(userid);
  632. }
  633. /**
  634. * @param hm_cache
  635. * @param userid
  636. * @return
  637. */
  638. private PersonnelBaseArchivesManageOutDto getPersonnelBaseArchivesManageEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
  639. HashMap<String, Object> hm = hm_cache.get("getPersonnelBaseArchivesManageEntityWithCache");
  640. if (hm == null) {
  641. hm = new HashMap<>();
  642. hm_cache.put("getPersonnelBaseArchivesManageEntityWithCache", hm);
  643. MiniDaoPage<PersonnelBaseArchivesManageOutDto> minPage = personnelBaseArchivesManageDao.getAllEntities();
  644. List<PersonnelBaseArchivesManageOutDto> entitiesFromDB = minPage.getResults();
  645. for (PersonnelBaseArchivesManageOutDto entity : entitiesFromDB) {
  646. hm.put(entity.getUserId(), entity);
  647. }
  648. }
  649. return (PersonnelBaseArchivesManageOutDto) hm.get(userid);
  650. }
  651. /**
  652. * 判断当前人是否应该计算工资
  653. *
  654. * @param per
  655. * @param moth
  656. * @return
  657. * @throws ParseException
  658. */
  659. private boolean isValidWagePerson(PersonnelBaseArchivesManageOutDto per, String moth) throws ParseException {
  660. if (per == null) {
  661. return false;
  662. }
  663. if (Globals.JOBSTATUS_0.equals(per.getPositionStatus())) {
  664. return false;
  665. }
  666. // if("0000000061459498016145f3f01407cd".equals(per.getUserid())) {
  667. // System.out.println("0000000061459498016145f3f01407cd");
  668. // }
  669. String moth1 = "";
  670. String[] mothArray = moth.split("-");
  671. moth1 = mothArray[0] + "-" + "0" + (Integer.valueOf(mothArray[1])) + "-01 00:00:00";
  672. Date leaveDate = per.getLeaveDate();
  673. DateFormat df_leave_limit = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  674. Calendar Cal_leave_limit = Calendar.getInstance();
  675. Cal_leave_limit.setTime(df_leave_limit.parse(moth1));
  676. if (leaveDate != null && leaveDate.getTime() <= Cal_leave_limit.getTimeInMillis()) {
  677. // 如果离职时间点早于或等于工资结算月1号,不算入工资表中 zy20180420
  678. return false;
  679. }
  680. // //合同开始时间是否在工资计算之内
  681. Date contractStime = per.getContractStime();
  682. // 下个月起始,在这个节点之后入职的,不计入工资表
  683. Calendar cal_contract_limit = Calendar.getInstance();
  684. DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  685. cal_contract_limit.setTime(df.parse(moth1));
  686. cal_contract_limit.add(Calendar.MONTH, 1);
  687. if (contractStime == null || contractStime.getTime() >= cal_contract_limit.getTimeInMillis()) {
  688. return false;
  689. }
  690. return true;
  691. }
  692. /**
  693. * 通过人查询所属项目
  694. *
  695. * @param hm_cache
  696. * @param userid
  697. * @return
  698. */
  699. private String getBybelongId(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
  700. String temp = "";
  701. TSUserOrgDto uo = getTSUserOrgWithCache(hm_cache, userid);
  702. TSDepartDto tsDepart = getTSDepartWithCache(hm_cache, uo.getOrg_id());
  703. TSDepartDto parentDepartDto = getTSDepartWithCache(hm_cache, tsDepart.getParentdepartid());
  704. if ("1".equals(tsDepart.getOrg_type()) || "3".equals(tsDepart.getOrg_type()) || "4".equals(tsDepart.getOrg_type()) || "5".equals(tsDepart.getOrg_type())) {
  705. temp = tsDepart.getId();
  706. } else if ("2".equals(tsDepart.getOrg_type()) && "1".equals(parentDepartDto.getOrg_type())) {
  707. temp = tsDepart.getId();
  708. } else {
  709. temp = selectById(hm_cache, tsDepart.getId());
  710. }
  711. return temp;
  712. }
  713. /**
  714. * @param hm_cache
  715. * @param userid
  716. * @return
  717. */
  718. private TSUserOrgDto getTSUserOrgWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
  719. HashMap<String, Object> hm = hm_cache.get("getTSUserOrgWithCache");
  720. if (hm == null) {
  721. hm = new HashMap<>();
  722. hm_cache.put("getTSUserOrgWithCache", hm);
  723. List<TSUserOrgDto> entitiesFromDB = this.getSession().createSQLQuery("select * from t_s_user_org where ifpluralism = 0 and status=0").addScalar("id").addScalar("user_id").addScalar("org_id")
  724. .addScalar("ifpluralism").setResultTransformer(Transformers.aliasToBean(TSUserOrgDto.class)).list();
  725. for (TSUserOrgDto entity : entitiesFromDB) {
  726. hm.put(entity.getUser_id(), entity);
  727. }
  728. }
  729. return (TSUserOrgDto) hm.get(userid);
  730. }
  731. /**
  732. * @param hm_cache
  733. * @param userid
  734. * @return
  735. */
  736. private TSDepartDto getTSDepartWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String departid) {
  737. HashMap<String, Object> hm = hm_cache.get("getTSDepartWithCache");
  738. if (hm == null) {
  739. hm = new HashMap<>();
  740. hm_cache.put("getTSDepartWithCache", hm);
  741. List<TSDepartDto> entitiesFromDB = this.getSession().createSQLQuery("select * from t_s_depart where status=0").addScalar("id").addScalar("parentdepartid").addScalar("org_type").addScalar("departname")
  742. .setResultTransformer(Transformers.aliasToBean(TSDepartDto.class)).list();
  743. for (TSDepartDto entity : entitiesFromDB) {
  744. hm.put(entity.getId(), entity);
  745. }
  746. }
  747. return (TSDepartDto) hm.get(departid);
  748. }
  749. private String selectById(HashMap<String, HashMap<String, Object>> hm_cache, String id) {
  750. String temp = "";
  751. TSDepartDto tsDepart = getTSDepartWithCache(hm_cache, id);
  752. if ("3".equals(tsDepart.getOrg_type()) || "5".equals(tsDepart.getOrg_type())) {
  753. temp = tsDepart.getId();
  754. } else {
  755. if (tsDepart.getParentdepartid() != null) {
  756. selectById(hm_cache, tsDepart.getParentdepartid());
  757. temp = tsDepart.getParentdepartid();
  758. }
  759. }
  760. return temp;
  761. }
  762. /**
  763. * 获得stime日期距离当月第一天的天数
  764. *
  765. * @param stime
  766. * 减数
  767. * @return
  768. * @throws ParseException
  769. */
  770. private static int dateDiff1(Date stime) throws ParseException {
  771. Calendar cal = Calendar.getInstance();
  772. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  773. cal.setTime(format.parse(format.format(stime)));
  774. // 得到上个月的第一天
  775. Calendar cal_1 = Calendar.getInstance();// 获取当前日期
  776. cal_1.add(Calendar.MONTH, -1);
  777. cal_1.set(Calendar.DAY_OF_MONTH, 1);
  778. // return DateUtils.dateDiff('d', cal, cal_1);
  779. return daysBetween(format.parse(format.format(cal_1.getTime())), cal.getTime()) - 1;
  780. }
  781. /**
  782. * 相差的天数
  783. *
  784. * @param date1
  785. * 开始时间
  786. * @param date2
  787. * 结束时间
  788. * @return
  789. */
  790. public static int daysBetween(Date date1, Date date2) {
  791. Calendar cal = Calendar.getInstance();
  792. cal.setTime(date1);
  793. long time1 = cal.getTimeInMillis();
  794. cal.setTime(date2);
  795. long time2 = cal.getTimeInMillis();
  796. long between_days = (time2 - time1) / (1000 * 3600 * 24);
  797. return Integer.parseInt(String.valueOf(between_days)) + 1;
  798. }
  799. public static void main(String[] args) throws ParseException {
  800. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  801. System.out.println(dateDiff1(sdf.parse("2017-12-10")));
  802. }
  803. /**
  804. * 获取某月的天数
  805. *
  806. * @param date
  807. * @return
  808. * @throws ParseException
  809. */
  810. private static int getDaysOfMonth(String date) throws ParseException {
  811. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  812. Calendar calendar = Calendar.getInstance();
  813. calendar.setTime(format.parse(date));
  814. return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
  815. }
  816. /**
  817. * 获得stime日期距离当月最后一天的天数
  818. *
  819. * @param stime
  820. * 减数
  821. * @return
  822. * @throws ParseException
  823. */
  824. private static int dateDiff2(Date stime, Date etime) throws ParseException {
  825. Calendar cal_1 = Calendar.getInstance();
  826. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  827. cal_1.setTime(format.parse(format.format(stime)));
  828. Calendar cale = Calendar.getInstance();
  829. if (etime != null) {
  830. cale.setTime(format.parse(format.format(etime)));
  831. } else {
  832. cale.set(Calendar.DAY_OF_MONTH, 0);// 设置为1号,当前日期既为本月第一天
  833. }
  834. // return DateUtils.dateDiff('d', cale, cal_1);
  835. return daysBetween(cal_1.getTime(), format.parse(format.format(cale.getTime())));
  836. }
  837. @SuppressWarnings("unchecked")
  838. private int dateDiff3(Date stime, Date etime) throws ParseException {
  839. int temp = 0;
  840. if (stime == null) {
  841. Calendar calendar = Calendar.getInstance();
  842. calendar.add(Calendar.MONTH, -1);
  843. calendar.set(Calendar.DAY_OF_MONTH, 1);
  844. stime = calendar.getTime();
  845. }
  846. if (etime == null) {
  847. Calendar calendar = Calendar.getInstance();
  848. calendar.set(Calendar.DAY_OF_MONTH, 1);
  849. calendar.add(Calendar.DATE, -1);
  850. etime = calendar.getTime();
  851. }
  852. StringBuffer str = new StringBuffer();
  853. str.append("select * from t_bus_calendar where ymd_date >= '" + stime + "' and ymd_date <= '" + etime + "' and dtype != 2");
  854. List<CalendarEntity> usList = this.getSession().createSQLQuery(str.toString()).addEntity(CalendarEntity.class).list();
  855. if (!usList.isEmpty()) {
  856. temp = usList.size();
  857. }
  858. return temp;
  859. }
  860. /**
  861. * 核算入职或离职当月的工资 在职天数:是除了星期六日外的工作日,不考虑节假日 在12月2日确定 得到入职时间的年月和上个月的年月,进行比较,是否是上个月入职
  862. * 如果不相等,说明非上个月入职,工资按照基本工资的80%进行计算
  863. * 如果相等,说明是上个月入职,则(基本工资+所有的补贴)/(21.75*8)*实际考勤时长,并且需单独计算工资
  864. *
  865. * @param hm_cache
  866. * @param uw
  867. * @param us
  868. * @param uat
  869. * @param meslList
  870. * 所有餐补
  871. * @return
  872. * @throws ParseException
  873. */
  874. private UserNewWageEntity calEntryOrLeaveWage(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, UserAttendanceTotalEntity uat, String month,
  875. PersonnelBaseArchivesManageOutDto per, List<MealsSubsidyEntity> meslList) throws ParseException {
  876. entryOrLeavePartlyWageCalculation(isCacheUsed, hm_cache, uw, us, uat, per);
  877. // 司龄津贴计算
  878. uw = comyearCalculation(hm_cache, us, uw, per);
  879. // 查询基本策略设定值
  880. uw = selectStrategy(isCacheUsed, hm_cache, us, uw, per);
  881. // 加班费计算
  882. uw = overtimeCalculation(isCacheUsed, hm_cache, uat, us, uw, month, per);
  883. // 餐补
  884. uw = mealsCalculation(isCacheUsed, hm_cache, uat, us, uw, meslList);
  885. // 缺勤病假扣事假扣
  886. uw = deductionCalculation(uat, us, uw, per, false);
  887. // 公积金和社保计算
  888. uw.setSocialSecurityDebit(new BigDecimal(0));
  889. uw.setComSocialSecurityDebit(BigDecimal.ZERO);
  890. uw.setProvidentFundDebit(new BigDecimal(0));
  891. uw.setComProvidentFundDebit(BigDecimal.ZERO);
  892. uw.setPaymentSubsidy(new BigDecimal(0));
  893. if (per.getLeaveDate() != null) {
  894. if (!equals(per.getContractStime(), per.getLeaveDate())) {
  895. Calendar calendar1 = Calendar.getInstance();
  896. calendar1.setTime(per.getLeaveDate());
  897. int month1 = calendar1.get(Calendar.DAY_OF_MONTH);
  898. if (month1 > 15) {
  899. uw = aloneCalculation(isCacheUsed, hm_cache, uw, us, per);
  900. }
  901. }
  902. } else {
  903. Calendar calendar1 = Calendar.getInstance();
  904. calendar1.setTime(per.getContractStime());
  905. int month1 = calendar1.get(Calendar.DAY_OF_MONTH);
  906. if (month1 < 16) {
  907. uw = aloneCalculation(isCacheUsed, hm_cache, uw, us, per);
  908. }
  909. }
  910. uw.setStatus(Globals.ARRANGESTATUS_0.toString());
  911. uw.setTaxMoney(new BigDecimal(0));
  912. if (us.getDeductPay() != null && us.getDeductPay().intValue() > 0) {
  913. uw.setOtherDebit(new BigDecimal(us.getDeductPay().toString()));
  914. }
  915. // 代扣款
  916. if (us.getDaikouFee() != null && us.getDaikouFee().doubleValue() > 0) {
  917. uw.setDaikouDebit(us.getDaikouFee());
  918. }
  919. if (uw.getOtherDebit() == null) {
  920. uw.setOtherDebit(BigDecimal.ZERO);
  921. }
  922. if (uw.getDaikouDebit() == null) {
  923. uw.setDaikouDebit(BigDecimal.ZERO);
  924. }
  925. if (uw.getBonus() == null) {
  926. uw.setBonus(BigDecimal.ZERO);
  927. }
  928. uw.recalculatePreTaxMoney();
  929. uw.recalculateActualMoney();
  930. uw.recalculateComCost();
  931. uw.setReissue(new BigDecimal(0));
  932. return uw;
  933. }
  934. private void entryOrLeavePartlyWageCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, UserAttendanceTotalEntity uat,
  935. PersonnelBaseArchivesManageOutDto per) throws ParseException {
  936. // 实际出勤时长
  937. BigDecimal shichang = new BigDecimal(0);
  938. if (uat.getActualAttendanceDate() != null) {
  939. shichang = uat.getActualAttendanceDate().divide(new BigDecimal(60), 3, BigDecimal.ROUND_HALF_UP);
  940. }
  941. //初始化
  942. uw.setBasicWage(new BigDecimal(0));
  943. uw.setDutiesAllowance(new BigDecimal(0));
  944. uw.setPostAllowance(new BigDecimal(0));
  945. uw.setDutieslevelAllowance(new BigDecimal(0));
  946. uw.setTalentAllowance(new BigDecimal(0));
  947. uw.setOtherworkSubsidy(new BigDecimal(0));
  948. uw.setJianguanBonus(new BigDecimal(0));
  949. uw.setXianchangBonus(new BigDecimal(0));
  950. uw.setProjectPerformance(new BigDecimal(0));
  951. if(shichang.compareTo(BigDecimal.ZERO) > 0) {
  952. // 查询基本工资
  953. uw = basicWagePartCalculation(isCacheUsed, hm_cache, us, uw, per);
  954. // 人才津贴计算
  955. uw = talentCalculation(isCacheUsed, hm_cache, us, uw, per);
  956. // 其它工作补贴
  957. uw = otherworkCalculation(isCacheUsed, hm_cache, us, uw, per);
  958. //项目监管绩效和项目现场绩效
  959. uw = projectAllowanceCalculation(isCacheUsed, hm_cache, us, uw, per);
  960. }
  961. // 基本工资和职务津贴
  962. if (StringUtils.isNotEmpty(us.getDutiesid())) {
  963. WagestrategyDto wa = getWagestrategyDto(isCacheUsed, hm_cache, per);
  964. BigDecimal basicWage = getBasicWage(isCacheUsed, hm_cache, per, us,wa);
  965. // 需要区分是管理层还是一线员工
  966. if (wa != null) {
  967. // 判断是管理层还是一线员工
  968. if (Globals.MANAGETYPE_2.toString().equals(per.getManagerType())) {
  969. calCommonEmployeeNotMonthlyWage(uw, shichang);
  970. } else {
  971. // 管理层:基本工资 = 基本工资/(21.75)*在职天数*80%
  972. if (per.getLeaveDate() != null) {
  973. calLeavedManagePersonWage(uw, per, basicWage);
  974. } else {
  975. calEntryManagePersonWage(uw, per, wa, basicWage);
  976. }
  977. }
  978. uw.setDutiesAllowance(wa.getSubsidy());
  979. }
  980. }
  981. }
  982. /**
  983. * 一线员工未达满月工资计算
  984. * @param uw
  985. * @param shichang
  986. */
  987. private void calCommonEmployeeNotMonthlyWage(UserNewWageEntity uw, BigDecimal shichang) {
  988. // 一线员工:基本工资 = 基本工资/(21.75*8)*实际出勤时长
  989. BigDecimal actAttendTimeRate = shichang.divide(new BigDecimal(21.75), 3, BigDecimal.ROUND_HALF_UP).divide(new BigDecimal(8), 3, BigDecimal.ROUND_HALF_UP);
  990. // 判断是否超过满月情况下的数字
  991. if (actAttendTimeRate.compareTo(BigDecimal.ONE) < 0) {
  992. uw.setBasicWage(uw.getBasicWage().multiply(actAttendTimeRate));
  993. uw.setDutiesAllowance(uw.getDutiesAllowance().multiply(actAttendTimeRate));
  994. uw.setPostAllowance(uw.getPostAllowance().multiply(actAttendTimeRate));
  995. uw.setDutieslevelAllowance(uw.getDutieslevelAllowance().multiply(actAttendTimeRate));
  996. uw.setTalentAllowance(uw.getTalentAllowance().multiply(actAttendTimeRate));
  997. uw.setOtherworkSubsidy(uw.getOtherworkSubsidy().multiply(actAttendTimeRate));
  998. uw.setJianguanBonus(uw.getJianguanBonus().multiply(actAttendTimeRate));
  999. uw.setXianchangBonus(uw.getXianchangBonus().multiply(actAttendTimeRate));
  1000. uw.setProjectPerformance(uw.getProjectPerformance().multiply(actAttendTimeRate));
  1001. }
  1002. }
  1003. /**
  1004. * 管理层新入职工资计算
  1005. * @param uw
  1006. * @param per
  1007. * @param wa
  1008. * @param basicWage
  1009. * @throws ParseException
  1010. */
  1011. private void calEntryManagePersonWage(UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per, WagestrategyDto wa, BigDecimal basicWage) throws ParseException {
  1012. // 管理层:基本工资 = 基本工资/当月天数*在职自然日天数*80%
  1013. if (per.getCorrectionDate() != null) {
  1014. if (equals(per.getCorrectionDate(), per.getContractStime())) {
  1015. // 基本工资
  1016. uw.setBasicWage(CalCorrectAndEntryInSameMonth(basicWage, per));
  1017. // 职务津贴
  1018. uw.setDutiesAllowance(CalCorrectAndEntryInSameMonth(uw.getDutiesAllowance(), per));
  1019. //岗位津贴
  1020. uw.setPostAllowance(CalCorrectAndEntryInSameMonth(uw.getPostAllowance(), per));
  1021. //等级津贴
  1022. uw.setDutieslevelAllowance(CalCorrectAndEntryInSameMonth(uw.getDutieslevelAllowance(), per));
  1023. //人才津贴
  1024. uw.setTalentAllowance(CalCorrectAndEntryInSameMonth(uw.getTalentAllowance(), per));
  1025. //其它工作补贴
  1026. uw.setOtherworkSubsidy(CalCorrectAndEntryInSameMonth(uw.getOtherworkSubsidy(), per));
  1027. //兼管
  1028. uw.setJianguanBonus(CalCorrectAndEntryInSameMonth(uw.getJianguanBonus(), per));
  1029. //现场
  1030. uw.setXianchangBonus(CalCorrectAndEntryInSameMonth(uw.getXianchangBonus(), per));
  1031. uw.setProjectPerformance(CalCorrectAndEntryInSameMonth(uw.getProjectPerformance(), per));
  1032. } else {
  1033. //入职和转正不在同一个月份
  1034. uw.setBasicWage(basicWage.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1035. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
  1036. uw.setDutiesAllowance(uw.getDutiesAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1037. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
  1038. uw.setPostAllowance(uw.getPostAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1039. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
  1040. uw.setDutieslevelAllowance(uw.getDutieslevelAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1041. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
  1042. uw.setTalentAllowance(uw.getTalentAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1043. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
  1044. uw.setOtherworkSubsidy(uw.getOtherworkSubsidy().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1045. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
  1046. uw.setJianguanBonus(uw.getJianguanBonus().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1047. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
  1048. uw.setXianchangBonus(uw.getXianchangBonus().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1049. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
  1050. }
  1051. } else {
  1052. uw.setBasicWage(basicWage.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
  1053. .multiply(new BigDecimal(0.8)));
  1054. uw.setDutiesAllowance(uw.getDutiesAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
  1055. .multiply(new BigDecimal(0.8)));
  1056. uw.setPostAllowance(uw.getPostAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
  1057. .multiply(new BigDecimal(0.8)));
  1058. uw.setDutieslevelAllowance(uw.getDutieslevelAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
  1059. .multiply(new BigDecimal(0.8)));
  1060. uw.setTalentAllowance(uw.getTalentAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
  1061. .multiply(new BigDecimal(0.8)));
  1062. uw.setOtherworkSubsidy(uw.getOtherworkSubsidy().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
  1063. .multiply(new BigDecimal(0.8)));
  1064. uw.setJianguanBonus(uw.getJianguanBonus().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
  1065. .multiply(new BigDecimal(0.8)));
  1066. uw.setXianchangBonus(uw.getXianchangBonus().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
  1067. .multiply(new BigDecimal(0.8)));
  1068. }
  1069. }
  1070. /**计算入职月份转正的工资
  1071. * @param dutieslevelAllowance
  1072. * @param per
  1073. * @return
  1074. * @throws ParseException
  1075. */
  1076. private BigDecimal CalCorrectAndEntryInSameMonth(BigDecimal allowanceComplete, PersonnelBaseArchivesManageOutDto per) throws ParseException {
  1077. BigDecimal level = allowanceComplete.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1078. .multiply(new BigDecimal(daysBetween(per.getContractStime(), per.getCorrectionDate()) - 1)).multiply(new BigDecimal(0.8));
  1079. level = level.add(level.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1080. .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))));
  1081. return level;
  1082. }
  1083. /**
  1084. * 管理层离职工资计算
  1085. * @param uw
  1086. * @param per
  1087. * @param basicWage
  1088. * @throws ParseException
  1089. */
  1090. private void calLeavedManagePersonWage(UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per, BigDecimal basicWage) throws ParseException {
  1091. uw.setBasicWage(calLeavedWageValue(per, basicWage));
  1092. uw.setDutiesAllowance(calLeavedWageValue(per, uw.getDutiesAllowance()));
  1093. uw.setPostAllowance(calLeavedWageValue(per, uw.getPostAllowance()));
  1094. uw.setDutieslevelAllowance(calLeavedWageValue(per, uw.getDutieslevelAllowance()));
  1095. uw.setTalentAllowance(calLeavedWageValue(per, uw.getTalentAllowance()));
  1096. uw.setOtherworkSubsidy(calLeavedWageValue(per, uw.getOtherworkSubsidy()));
  1097. uw.setJianguanBonus(calLeavedWageValue(per, uw.getJianguanBonus()));
  1098. uw.setXianchangBonus(calLeavedWageValue(per, uw.getXianchangBonus()));
  1099. uw.setProjectPerformance(calLeavedWageValue(per, uw.getProjectPerformance()));
  1100. }
  1101. private BigDecimal calLeavedWageValue(PersonnelBaseArchivesManageOutDto per, BigDecimal origValue) throws ParseException {
  1102. BigDecimal value = origValue;
  1103. if (per.getCorrectionDate() != null) {
  1104. // 判断转正时间和离职时间是否在同一个月
  1105. if (equals(per.getCorrectionDate(), per.getLeaveDate())) {
  1106. // 管理层:基本工资/当月天数*80%*试用期自然日天数+ 基本工资/当月天数*转正后自然日天数
  1107. if (equals(per.getCorrectionDate(), per.getContractStime())) {
  1108. value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
  1109. .multiply(new BigDecimal(daysBetween(per.getContractStime(), per.getCorrectionDate()) - 1));
  1110. value = value.add(value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1111. .multiply(new BigDecimal(daysBetween(per.getCorrectionDate(), per.getLeaveDate()))));
  1112. } else {
  1113. value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
  1114. .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate())));
  1115. value = value.add(origValue.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1116. .multiply(new BigDecimal(daysBetween(per.getCorrectionDate(), per.getLeaveDate()))));
  1117. }
  1118. } else {
  1119. // 管理层:基本工资/当月天数*在职自然日天数
  1120. value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff1(per.getLeaveDate())));
  1121. }
  1122. } else {
  1123. // 管理层:基本工资/当月天数*在职自然日天数*80%
  1124. if (equals(per.getLeaveDate(), per.getContractStime())) {
  1125. value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1126. .multiply(new BigDecimal(daysBetween(per.getContractStime(), per.getLeaveDate()))).multiply(new BigDecimal(0.8));
  1127. } else {
  1128. value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff1(per.getLeaveDate()) + 1))
  1129. .multiply(new BigDecimal(0.8));
  1130. }
  1131. }
  1132. return value;
  1133. }
  1134. /**
  1135. * 同月入职、转正、离职---奇葩
  1136. * @param per
  1137. * @param value
  1138. * @return
  1139. * @throws ParseException
  1140. */
  1141. private BigDecimal calCorrAndLeaveAndEntryInSameMonth(PersonnelBaseArchivesManageOutDto per, BigDecimal value) throws ParseException {
  1142. value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
  1143. .multiply(new BigDecimal(daysBetween(per.getContractStime(), per.getCorrectionDate()) - 1));
  1144. value = value.add(value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
  1145. .multiply(new BigDecimal(daysBetween(per.getCorrectionDate(), per.getLeaveDate()))));
  1146. return value;
  1147. }
  1148. /**
  1149. * 公积金修改
  1150. *
  1151. * @param hm_cache
  1152. * @param uw
  1153. * @param us
  1154. * @param per
  1155. * @return
  1156. */
  1157. private UserNewWageEntity aloneCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) {
  1158. StringBuffer str = new StringBuffer();
  1159. String st = " and status = 0 and delete_flag = 0";
  1160. // 社保扣除
  1161. if (StringUtils.isNotEmpty(us.getSocialSecurityStrategyid())) {
  1162. str.delete(0, str.length());
  1163. str.append("select * from t_bus_social_security_strategy where id = '" + us.getSocialSecurityStrategyid() + "'");
  1164. str.insert(str.length(), st);
  1165. SocialSecurityStrategyEntity social = null;
  1166. if (isCacheUsed) {
  1167. social = getSocialSecurityStrategyEntityWithCache(hm_cache, us.getSocialSecurityStrategyid());
  1168. } else {
  1169. List<SocialSecurityStrategyEntity> socialList = this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list();
  1170. if (socialList != null && socialList.size() > 0) {
  1171. social = socialList.get(0);
  1172. }
  1173. }
  1174. if (social != null) {
  1175. // 设置社保单位
  1176. uw.setSocialSecurityId(social.getId());
  1177. uw.setSocialSecurityUnit(social.getSocialSecurityUnit());
  1178. if (Globals.SOCIAL_SECURITY_STRATEGY_HUZHOU.equals(social.getId())) {
  1179. huzhouSocialSecurityCalcu(uw, social);
  1180. } else {
  1181. normalSocialSecurityCalcu(uw, social);
  1182. }
  1183. }
  1184. } else {
  1185. uw.setSocialSecurityDebit(new BigDecimal(0));
  1186. }
  1187. // 公积金扣除
  1188. if (StringUtils.isNotEmpty(us.getProvidentFundStrategyid())) {
  1189. ProvidentFundStrategyEntity perobident = getProvidentFundStrategyEntityWithCache(hm_cache, us.getProvidentFundStrategyid());
  1190. if (perobident != null) {
  1191. ProvidentFundStrategyEntity meal = perobident;
  1192. uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio().multiply(new BigDecimal(0.01))).setScale(0, BigDecimal.ROUND_HALF_UP));
  1193. uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio().multiply(new BigDecimal(0.01))).setScale(0, BigDecimal.ROUND_HALF_UP));
  1194. }
  1195. } else {
  1196. uw.setProvidentFundDebit(new BigDecimal(0));
  1197. }
  1198. // 缴金补贴
  1199. String jiaojin_subsidy = us.getJiaojinSubsidyid();
  1200. // zy20180428 如果工资策略里没有设定缴金补贴,则按照原始缴扣进行补贴.否则按照工资策略补贴
  1201. if (jiaojin_subsidy == null) {
  1202. uw.setPaymentSubsidy(uw.getSocialSecurityDebit().add(uw.getProvidentFundDebit()));
  1203. } else {
  1204. uw.setPaymentSubsidy(BigDecimal.ZERO);
  1205. BigDecimal jiaonjinMoney = getJiaoJinSubsidyMoney(isCacheUsed, hm_cache, uw, us, per);
  1206. if(jiaonjinMoney != null) {
  1207. uw.setPaymentSubsidy(jiaonjinMoney);
  1208. }
  1209. }
  1210. return uw;
  1211. }
  1212. /**
  1213. * @param uw
  1214. * @param social
  1215. */
  1216. private void huzhouSocialSecurityCalcu(UserNewWageEntity uw, SocialSecurityStrategyEntity social) {
  1217. BigDecimal perInsu = BigDecimal.ZERO;
  1218. perInsu = perInsu.add(social.getPersonalBasicRetireInsu().multiply(new BigDecimal(0.01)));
  1219. perInsu = perInsu.add(social.getPersionalBasicMedicalInsu().multiply(new BigDecimal(0.01)));
  1220. perInsu = perInsu.add(social.getPersonalUnemploymentInsu().multiply(new BigDecimal(0.01)));
  1221. BigDecimal perResult = BigDecimal.ZERO;
  1222. perResult = social.getBasePay().multiply(perInsu);
  1223. uw.setSocialSecurityDebit(perResult.setScale(1, BigDecimal.ROUND_HALF_UP));
  1224. BigDecimal comInsu = BigDecimal.ZERO;
  1225. BigDecimal comResult = BigDecimal.ZERO;
  1226. comInsu = comInsu.add(social.getCompanyBasicRetireInsu().multiply(new BigDecimal(0.01)));
  1227. comInsu = comInsu.add(social.getCompanyBasicMedicalInsu().multiply(new BigDecimal(0.01)));
  1228. comInsu = comInsu.add(social.getCompanyUnemploymentInsu().multiply(new BigDecimal(0.01)));
  1229. comInsu = comInsu.add(social.getCompanyInjuryInsu().multiply(new BigDecimal(0.01)));
  1230. comInsu = comInsu.add(social.getCompanyMaternityInsu().multiply(new BigDecimal(0.01)));
  1231. comResult = comInsu.multiply(social.getBasePay());
  1232. uw.setComSocialSecurityDebit(comResult.setScale(2, BigDecimal.ROUND_HALF_UP));
  1233. }
  1234. private void normalSocialSecurityCalcu(UserNewWageEntity uw, SocialSecurityStrategyEntity meal) {
  1235. /**
  1236. * 社保个人金额: 中间各项目计算结果:直接进位,保留1位小数; 合计:直接进位,保留1位小数;
  1237. */
  1238. uw.setSocialSecurityDebit(new BigDecimal(0));
  1239. uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersonalBasicRetireInsu().multiply(new BigDecimal(0.01))).setScale(1, BigDecimal.ROUND_UP)));
  1240. uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersionalBasicMedicalInsu().multiply(new BigDecimal(0.01))).setScale(1, BigDecimal.ROUND_UP)));
  1241. uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersonalUnemploymentInsu().multiply(new BigDecimal(0.01))).setScale(1, BigDecimal.ROUND_UP)));
  1242. uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().setScale(1, BigDecimal.ROUND_UP));
  1243. /**
  1244. * 社保单位金额: 中间各项目计算结果:四舍五入,保留4位小数; 合计:四舍五入,保留4位小数;
  1245. */
  1246. uw.setComSocialSecurityDebit(new BigDecimal(0));
  1247. uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyBasicRetireInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
  1248. uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyBasicMedicalInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
  1249. uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyUnemploymentInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
  1250. uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyInjuryInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
  1251. uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyMaternityInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
  1252. uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().setScale(2, BigDecimal.ROUND_HALF_UP));
  1253. }
  1254. /**
  1255. * 得到当前年月
  1256. *
  1257. * @return
  1258. */
  1259. private String getMonthlys() {
  1260. Calendar cal = Calendar.getInstance();
  1261. int year = cal.get(Calendar.YEAR);
  1262. int month = cal.get(Calendar.MONTH);
  1263. if (month < 10) {
  1264. if (month == 0) {
  1265. year = year - 1;
  1266. month = 12;
  1267. } else {
  1268. // month = Integer.valueOf(0+""+month);
  1269. return year + "-" + 0 + "" + month;
  1270. }
  1271. }
  1272. return year + "-" + month;
  1273. }
  1274. /**
  1275. * ----------------------------废弃的方法 by zhijia.wang--------------------------
  1276. * 判断上个月是否为入职或离职
  1277. *
  1278. * @param us
  1279. * @return
  1280. * @throws ParseException
  1281. */
  1282. /*
  1283. * private boolean entryOrLeave(UserNewWagestrategyEntity
  1284. * us,PersonnelBaseArchivesManageOutDto per) throws ParseException{ boolean
  1285. * isOrNot = true; if(per.getContractStime() != null){ Calendar
  1286. * cal_1=Calendar.getInstance(); SimpleDateFormat format = new
  1287. * SimpleDateFormat("yyyy-MM-dd"); Date stime = per.getContractStime();
  1288. * cal_1.setTime(format.parse(format.format(stime)));
  1289. *
  1290. * int year = cal_1.get(Calendar.YEAR); int month = cal_1.get(Calendar.MONTH)+1;
  1291. *
  1292. * Calendar cal_2 = Calendar.getInstance();//获取当前日期 cal_2.add(Calendar.MONTH,
  1293. * -1); cal_2.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
  1294. *
  1295. * int year1 = cal_2.get(Calendar.YEAR); int month1 =
  1296. * cal_2.get(Calendar.MONTH)+1; if(year == year1 && month == month1){ isOrNot =
  1297. * false; return isOrNot;
  1298. *
  1299. * } }
  1300. *
  1301. * //离职同入职原理相同 if(per.getLeaveDate() != null){ Calendar
  1302. * cal_1=Calendar.getInstance(); SimpleDateFormat format = new
  1303. * SimpleDateFormat("yyyy-MM-dd"); Date stime = per.getLeaveDate();
  1304. * cal_1.setTime(format.parse(format.format(stime)));
  1305. *
  1306. * int year = cal_1.get(Calendar.YEAR); int month = cal_1.get(Calendar.MONTH)+1;
  1307. *
  1308. * Calendar cal_2 = Calendar.getInstance();//获取当前日期 cal_2.add(Calendar.MONTH,
  1309. * -1); cal_2.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
  1310. *
  1311. * int year1 = cal_2.get(Calendar.YEAR); int month1 =
  1312. * cal_2.get(Calendar.MONTH)+1; if(year == year1 && month == month1){ isOrNot =
  1313. * false; return isOrNot; } }
  1314. *
  1315. * return isOrNot; }
  1316. */
  1317. /**
  1318. * 判断是否当月入职或离职或者如果当月入职或离职,是否干满一个整月
  1319. *
  1320. * @author zhijia.wang
  1321. * @date 2018-03-09 14:55:20
  1322. * @param us
  1323. * @return
  1324. * @throws ParseException
  1325. */
  1326. private boolean isCompleteMonthWage(UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) throws ParseException {
  1327. YearMonthDay entryDate = getEntryDate(per.getContractStime());
  1328. YearMonthDay leaveDate = getLeaveDate(per.getLeaveDate());
  1329. // 工资月月初时间
  1330. Calendar cal_1 = Calendar.getInstance();// 获取当前日期
  1331. cal_1.add(Calendar.MONTH, -1);// 设置为上个月(工资月)
  1332. cal_1.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号
  1333. int year = cal_1.get(Calendar.YEAR);
  1334. int month = cal_1.get(Calendar.MONTH) + 1;
  1335. // int firstday = cal_1.get(Calendar.DATE);
  1336. // 工资月月末时间
  1337. Calendar cal_2 = Calendar.getInstance();// 获取当前日期
  1338. cal_2.add(Calendar.MONTH, -1);// 设置为上个月(工资月)
  1339. cal_2.set(Calendar.DATE, cal_2.getActualMaximum(Calendar.DATE));// 设置为最后一天
  1340. int year2 = cal_1.get(Calendar.YEAR);
  1341. int month2 = cal_1.get(Calendar.MONTH) + 1;
  1342. int lastday = cal_2.get(Calendar.DATE);
  1343. // 判断离职
  1344. if (leaveDate != null) {
  1345. int leave_year = leaveDate.getYear();
  1346. int leave_month = leaveDate.getMonth();
  1347. int leave_day = leaveDate.getDay();
  1348. if (year == leave_year && month == leave_month) {
  1349. if (leave_day != lastday) {// 如果不是最后一天离职
  1350. return false;
  1351. }
  1352. }
  1353. }
  1354. // 判断入职
  1355. if (entryDate != null) {
  1356. int enrty_year = entryDate.getYear();
  1357. int enrty_month = entryDate.getMonth();
  1358. int enrty_day = entryDate.getDay();
  1359. if (year == enrty_year && month == enrty_month) {
  1360. if (enrty_day == 1) {// 如果是1号入职
  1361. // 判断离职
  1362. if (leaveDate != null) {
  1363. int leave_year = leaveDate.getYear();
  1364. int leave_month = leaveDate.getMonth();
  1365. int leave_day = leaveDate.getDay();
  1366. if (year == leave_year && month == leave_month) {
  1367. if (leave_day != lastday) {// 如果不是最后一天离职
  1368. return false;
  1369. }
  1370. }
  1371. }
  1372. } else {
  1373. return false;
  1374. }
  1375. }
  1376. }
  1377. return true;
  1378. }
  1379. // 获取入职日期
  1380. private YearMonthDay getEntryDate(Date contractStime) throws ParseException {
  1381. if (contractStime != null) {
  1382. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1383. Calendar cal_1 = Calendar.getInstance();// 获取当前日期
  1384. cal_1.setTime(sdf.parse(sdf.format(contractStime)));
  1385. int year = cal_1.get(Calendar.YEAR);
  1386. int month = cal_1.get(Calendar.MONTH) + 1;
  1387. int day = cal_1.get(Calendar.DATE);
  1388. return new YearMonthDay(year, month, day);
  1389. }
  1390. return null;
  1391. }
  1392. // 获取离职日期
  1393. private YearMonthDay getLeaveDate(Date leaveDate) throws ParseException {
  1394. if (leaveDate != null) {
  1395. Calendar cal_1 = Calendar.getInstance();// 获取当前日期
  1396. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1397. cal_1.setTime(sdf.parse(sdf.format(leaveDate)));
  1398. int year = cal_1.get(Calendar.YEAR);
  1399. int month = cal_1.get(Calendar.MONTH) + 1;
  1400. int day = cal_1.get(Calendar.DATE);
  1401. return new YearMonthDay(year, month, day);
  1402. }
  1403. return null;
  1404. }
  1405. /**
  1406. * 判断是否在同一年并且同一个月
  1407. *
  1408. * @param date1
  1409. * @param date2
  1410. * @return
  1411. */
  1412. private static boolean equals(Date date1, Date date2) {
  1413. Calendar calendar1 = Calendar.getInstance();
  1414. calendar1.setTime(date1);
  1415. Calendar calendar2 = Calendar.getInstance();
  1416. calendar2.setTime(date2);
  1417. return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH);
  1418. }
  1419. /**
  1420. * 判断是否为上个月转正
  1421. *
  1422. * @param us
  1423. * @return
  1424. * @throws ParseException
  1425. */
  1426. private boolean isCorrection(PersonnelBaseArchivesManageOutDto per) throws ParseException {
  1427. boolean isOrNot = true;
  1428. if (per.getCorrectionDate() != null) {
  1429. Calendar cal_1 = Calendar.getInstance();
  1430. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  1431. Date stime = per.getCorrectionDate();
  1432. cal_1.setTime(format.parse(format.format(stime)));
  1433. int year = cal_1.get(Calendar.YEAR);
  1434. int month = cal_1.get(Calendar.MONTH) + 1;
  1435. Calendar cal_2 = Calendar.getInstance();// 获取当前日期
  1436. cal_2.add(Calendar.MONTH, -1);
  1437. cal_2.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
  1438. int year1 = cal_2.get(Calendar.YEAR);
  1439. int month1 = cal_2.get(Calendar.MONTH) + 1;
  1440. if (year == year1 && month == month1) {
  1441. isOrNot = false;
  1442. return isOrNot;
  1443. }
  1444. }
  1445. return isOrNot;
  1446. }
  1447. /**
  1448. * 查询基本工资
  1449. *
  1450. * @param isCacheUsed
  1451. * @param hm_cache
  1452. * @param idString
  1453. * @param uw
  1454. * @return
  1455. * @throws ParseException
  1456. */
  1457. private UserNewWageEntity basicWagePartCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per)
  1458. throws ParseException {
  1459. uw.setBasicWage(new BigDecimal(0));
  1460. uw.setDutiesAllowance(new BigDecimal(0));
  1461. uw.setPostAllowance(new BigDecimal(0));
  1462. uw.setDutieslevelAllowance(new BigDecimal(0));
  1463. WagestrategyDto wa = getWagestrategyDto(isCacheUsed, hm_cache, per);
  1464. if (wa != null) {
  1465. if (wa != null) {
  1466. uw.setDutiesid(wa.getId());
  1467. // 判断转正日期是否在上个月,如果在,
  1468. // 本月应发基本工资 = 基本工资 - 本月应扣除试用期工资【基本工资/21.75*20%*试用期天数(自然日)】
  1469. // 如果不在,就为基本工资
  1470. if (Globals.MANAGETYPE_2.toString().equals(per.getManagerType())) {
  1471. uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa));
  1472. uw.setDutiesAllowance(wa.getSubsidy());
  1473. uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa));
  1474. uw.setPostAllowance(wa.getPostMoney());
  1475. } else {
  1476. if(per.getCorrectionDate() == null) {
  1477. uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa));
  1478. uw.setDutiesAllowance(wa.getSubsidy());
  1479. uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa));
  1480. uw.setPostAllowance(wa.getPostMoney());
  1481. }
  1482. // 是否上个月转正
  1483. else if (isCorrection(per)) {
  1484. if (Globals.JOBSTATUS_1.equals(per.getPositionStatus())) {
  1485. uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa).multiply(new BigDecimal(0.8)));
  1486. uw.setDutiesAllowance(wa.getSubsidy().multiply(new BigDecimal(0.8)));
  1487. uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa).multiply(new BigDecimal(0.8)));
  1488. uw.setPostAllowance(wa.getPostMoney().multiply(new BigDecimal(0.8)));
  1489. } else {
  1490. uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa));
  1491. uw.setDutiesAllowance(wa.getSubsidy());
  1492. uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa));
  1493. uw.setPostAllowance(wa.getPostMoney());
  1494. }
  1495. } else {
  1496. uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa).divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
  1497. .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate()))));
  1498. uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa)
  1499. .add(getBasicWage(isCacheUsed, hm_cache, per, us,wa).divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null)))));
  1500. uw.setDutiesAllowance(wa.getSubsidy().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
  1501. .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate()))));
  1502. uw.setDutiesAllowance(uw.getDutiesAllowance()
  1503. .add(wa.getSubsidy().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null)))));
  1504. uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa).divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
  1505. .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate()))));
  1506. uw.setDutieslevelAllowance(uw.getDutiesAllowance()
  1507. .add(wa.getPostMoney().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null)))));
  1508. uw.setPostAllowance(wa.getPostMoney().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
  1509. .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate()))));
  1510. uw.setPostAllowance(uw.getPostAllowance()
  1511. .add(wa.getPostMoney().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null)))));
  1512. }
  1513. }
  1514. }
  1515. }
  1516. return uw;
  1517. }
  1518. private WagestrategyDto getWagestrategyDto(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, PersonnelBaseArchivesManageOutDto per) {
  1519. List<WagestrategyDto> perobident = getWagestrategyEntityWithCache(isCacheUsed, hm_cache, per.getDutiesId());
  1520. if (perobident != null) {
  1521. int resultlevel = -1;
  1522. WagestrategyDto resultdto = null;
  1523. for (WagestrategyDto dto : perobident) {
  1524. int level = -1;
  1525. if (dto.getProject() == null && dto.getZone() == null) {
  1526. level = 0;
  1527. } else if (dto.getZone() != null) {
  1528. level = 1;
  1529. } else if (dto.getProject() != null) {
  1530. level = 2;
  1531. }
  1532. if (level > resultlevel) {
  1533. resultdto = dto;
  1534. }
  1535. }
  1536. return resultdto;
  1537. }
  1538. return null;
  1539. }
  1540. /**
  1541. * @param hm_cache
  1542. * @param isCacheUsed
  1543. * @param per
  1544. * @param wa
  1545. * @return
  1546. */
  1547. private BigDecimal getBasicWage(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache
  1548. , PersonnelBaseArchivesManageOutDto per, UserNewWagestrategyEntity us, WagestrategyDto wa) {
  1549. HashMap<String, Object> hm = hm_cache.get("getBasicWage");
  1550. if (hm == null) {
  1551. hm = new HashMap<>();
  1552. hm_cache.put("getBasicWage", hm);
  1553. StringBuffer str = new StringBuffer();
  1554. str.append("select * from t_bus_base_wagestrategy where 1=1");
  1555. List<TBusBaseWagestrategyEntity> entitiesFromDB = this.getSession().createSQLQuery(str.toString()).addEntity(TBusBaseWagestrategyEntity.class).list();
  1556. for (TBusBaseWagestrategyEntity entity : entitiesFromDB) {
  1557. String userInEntity = entity.getZone();
  1558. hm.put(userInEntity, entity);
  1559. }
  1560. }
  1561. TBusBaseWagestrategyEntity resultEntity = null;
  1562. if(per.getZoneId() != null && hm.containsKey(per.getZoneId())) {
  1563. resultEntity = (TBusBaseWagestrategyEntity)hm.get(per.getZoneId());
  1564. }else {
  1565. resultEntity = (TBusBaseWagestrategyEntity)hm.get(null);
  1566. if(resultEntity == null) {
  1567. resultEntity = (TBusBaseWagestrategyEntity)hm.get("");
  1568. }
  1569. }
  1570. BigDecimal result = resultEntity.getMoney();
  1571. if(result == null) {
  1572. result = BigDecimal.ZERO;
  1573. }
  1574. if(wa.getBasicWage() != null) {
  1575. if(result.compareTo(wa.getBasicWage()) > 0) {
  1576. return wa.getBasicWage();
  1577. }
  1578. }
  1579. return result;
  1580. }
  1581. /**
  1582. * @param per
  1583. * @param wa
  1584. * @return
  1585. */
  1586. private BigDecimal getDutieslevelAllowance(PersonnelBaseArchivesManageOutDto per, WagestrategyDto wa) {
  1587. if ("1".equals(per.getDutieslevel())) {
  1588. return wa.getLevelonesubsidy();
  1589. }
  1590. if ("2".equals(per.getDutieslevel())) {
  1591. return wa.getLeveltwosubsidy();
  1592. }
  1593. if ("3".equals(per.getDutieslevel())) {
  1594. return wa.getLevelthreesubsidy();
  1595. }
  1596. return BigDecimal.ZERO;
  1597. }
  1598. /**
  1599. * @param isCacheAll true:缓存所有,否则缓存个别
  1600. * @param hm_cache
  1601. * @param belongDutiesid
  1602. * @return
  1603. */
  1604. private List<WagestrategyDto> getWagestrategyEntityWithCache(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, String belongDutiesid) {
  1605. HashMap<String, Object> hm = hm_cache.get("getWagestrategyEntityWithCache");
  1606. if (hm == null) {
  1607. hm = new HashMap<>();
  1608. hm_cache.put("getWagestrategyEntityWithCache", hm);
  1609. MiniDaoPage<WagestrategyDto> entitiesFromDB = null;
  1610. if(isCacheAll) {
  1611. entitiesFromDB = wagestrategyMiniDao.getAllEntities();
  1612. }else {
  1613. entitiesFromDB = wagestrategyMiniDao.getEntitiesByDutiesId(belongDutiesid);
  1614. }
  1615. for (WagestrategyDto entity : entitiesFromDB.getResults()) {
  1616. String userInEntity = entity.getDutiesId();
  1617. if (hm.containsKey(userInEntity)) {
  1618. List<WagestrategyDto> entitylist = (List<WagestrategyDto>) hm.get(userInEntity);
  1619. entitylist.add(entity);
  1620. } else {
  1621. List<WagestrategyDto> newlist = new ArrayList<>();
  1622. newlist.add(entity);
  1623. hm.put(userInEntity, newlist);
  1624. }
  1625. }
  1626. }
  1627. return (List<WagestrategyDto>) hm.get(belongDutiesid);
  1628. }
  1629. /**
  1630. * 查询基本策略设定值
  1631. *
  1632. * @param isCacheUsed
  1633. * @param us
  1634. * @param uw
  1635. * @param per
  1636. * @return
  1637. */
  1638. private UserNewWageEntity selectStrategy(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
  1639. BigDecimal certificateSubsidyMoney = getCertificateSubsidyMoneyWithCache(hm_cache, uw.getUserid());
  1640. uw.setCertificateSubsidy(BigDecimal.ZERO);
  1641. if (certificateSubsidyMoney != null) {
  1642. uw.setCertificateSubsidy(certificateSubsidyMoney);
  1643. }
  1644. // 交通补贴
  1645. BigDecimal trafficSub = getTrafficSubsidyMoney(hm_cache, us,per);
  1646. uw.setTrafficSubsidy(BigDecimal.ZERO);
  1647. if (trafficSub != null) {
  1648. uw.setTrafficSubsidy(trafficSub);
  1649. }
  1650. // 高温补贴
  1651. if (StringUtils.isNotEmpty(us.getMegathermalSubsidyid())) {
  1652. // str.delete(0,str.length());
  1653. // str.append("select * from t_bus_megathermal_subsidy where id
  1654. // ='"+us.getMegathermalSubsidyid()+"'");
  1655. // str.insert(str.length(), st);
  1656. // List<MegathermalSubsidyEntity> trafficSubsidyList =
  1657. // this.getSession().createSQLQuery(str.toString()).addEntity(MegathermalSubsidyEntity.class).list();
  1658. MegathermalSubsidyEntity trafficSubsidyList = getMegathermalSubsidyEntityWithCache(hm_cache, us.getMegathermalSubsidyid());
  1659. // List<MegathermalSubsidyEntity> trafficSubsidyList =
  1660. // this.findListbySql(str.toString());
  1661. if (oConvertUtils.isNotEmpty(trafficSubsidyList)) {
  1662. uw.setMegathermalSubsidy(trafficSubsidyList.getSubsidyMoney());
  1663. }
  1664. } else {
  1665. uw.setMegathermalSubsidy(new BigDecimal(0));
  1666. }
  1667. // 独生子女费
  1668. if (us.getOnlychildPay() != null && us.getOnlychildPay().intValue() > 0) {
  1669. uw.setOnlyChildCost(us.getOnlychildPay());
  1670. } else {
  1671. uw.setOnlyChildCost(new BigDecimal(0));
  1672. }
  1673. // 其他补贴
  1674. /*
  1675. * if(StringUtils.isNotEmpty(us.getOtherSubsidyid())){ //
  1676. * str.delete(0,str.length()); //
  1677. * str.append("select * from t_bus_other_subsidy where id ='"+us.
  1678. * getOtherSubsidyid()+"'"); // str.insert(str.length(), st); //
  1679. * List<OtherSubsidyEntity> trafficSubsidyList =
  1680. * this.getSession().createSQLQuery(str.toString()).addEntity(OtherSubsidyEntity
  1681. * .class).list(); //List<OtherSubsidyEntity> trafficSubsidyList =
  1682. * this.findListbySql(str.toString()); OtherSubsidyEntity trafficSubsidyList =
  1683. * getOtherSubsidyEntityWithCache(hm_cache,us.getOtherSubsidyid());
  1684. * if(oConvertUtils.isNotEmpty(trafficSubsidyList)){ if(us.getAppendPay() !=
  1685. * null && us.getAppendPay().intValue() > 0 ){
  1686. * uw.setOtherSubsidy(us.getAppendPay().add(trafficSubsidyList.getSubsidyMoney()
  1687. * )); }else{ uw.setOtherSubsidy(trafficSubsidyList.getSubsidyMoney()); } }
  1688. * }else{ if(us.getAppendPay() != null && us.getAppendPay().intValue() > 0 ){
  1689. * uw.setOtherSubsidy(us.getAppendPay()); }else{ uw.setOtherSubsidy(new
  1690. * BigDecimal(0)); } }
  1691. */
  1692. return uw;
  1693. }
  1694. /**
  1695. * @param hm_cache
  1696. * @param userid
  1697. * @return
  1698. */
  1699. private BigDecimal getTrafficSubsidyMoney(HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) {
  1700. if(us.getTrafficSubsidyid() != null ) {
  1701. return us.getTrafficSubsidyid();
  1702. }
  1703. WagestrategyDto companyLevelWagestrategy = getCompanyLevelWagestrategy(hm_cache, us, per);
  1704. if(companyLevelWagestrategy != null) {
  1705. return companyLevelWagestrategy.getTrafficsubsidy();
  1706. }
  1707. return null;
  1708. }
  1709. /**
  1710. * @param hm_cache
  1711. * @param us
  1712. * @param per
  1713. * @return
  1714. */
  1715. private WagestrategyDto getCompanyLevelWagestrategy(HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) {
  1716. List<WagestrategyDto> dtos = getWagestrategyEntityWithCache(true, hm_cache, per.getDutiesId());
  1717. if(dtos != null && dtos.size() >0) {
  1718. for(WagestrategyDto d : dtos) {
  1719. if(d.getZone() == null && d.getProject() == null) {
  1720. return d;
  1721. }
  1722. }
  1723. }
  1724. return null;
  1725. }
  1726. /**
  1727. * @param hm_cache
  1728. * @param otherSubsidyid
  1729. * @return
  1730. */
  1731. private OtherSubsidyEntity getOtherSubsidyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String otherSubsidyid) {
  1732. HashMap<String, Object> hm = hm_cache.get("getOtherSubsidyEntityWithCache");
  1733. if (hm == null) {
  1734. hm = new HashMap<>();
  1735. hm_cache.put("getOtherSubsidyEntityWithCache", hm);
  1736. CriteriaQuery specialcq = new CriteriaQuery(OtherSubsidyEntity.class);
  1737. specialcq.eq("deleteFlag", "0");
  1738. specialcq.add();
  1739. specialcq.eq("status", "0");
  1740. specialcq.add();
  1741. List<OtherSubsidyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  1742. for (OtherSubsidyEntity entity : entitiesFromDB) {
  1743. hm.put(entity.getId(), entity);
  1744. }
  1745. }
  1746. return (OtherSubsidyEntity) hm.get(otherSubsidyid);
  1747. }
  1748. /**
  1749. * @param hm_cache
  1750. * @param megathermalSubsidyid
  1751. * @return
  1752. */
  1753. private MegathermalSubsidyEntity getMegathermalSubsidyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String megathermalSubsidyid) {
  1754. // TODO Auto-generated method stub
  1755. HashMap<String, Object> hm = hm_cache.get("getMegathermalSubsidyEntityWithCache");
  1756. if (hm == null) {
  1757. hm = new HashMap<>();
  1758. hm_cache.put("getMegathermalSubsidyEntityWithCache", hm);
  1759. CriteriaQuery specialcq = new CriteriaQuery(MegathermalSubsidyEntity.class);
  1760. specialcq.eq("deleteFlag", "0");
  1761. specialcq.add();
  1762. specialcq.eq("status", "0");
  1763. specialcq.add();
  1764. List<MegathermalSubsidyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  1765. for (MegathermalSubsidyEntity entity : entitiesFromDB) {
  1766. hm.put(entity.getId(), entity);
  1767. }
  1768. }
  1769. return (MegathermalSubsidyEntity) hm.get(megathermalSubsidyid);
  1770. }
  1771. /**
  1772. * @param string
  1773. * @param hm_cache
  1774. * @param trafficSubsidyid
  1775. * @return
  1776. */
  1777. private TrafficSubsidyEntity getTrafficSubsidyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String trafficSubsidyid) {
  1778. // TODO Auto-generated method stub
  1779. // str.delete(0,str.length());
  1780. // str.append("select * from t_bus_traffic_subsidy where id
  1781. // ='"+us.getTrafficSubsidyid()+"'");
  1782. // str.insert(str.length(), st);
  1783. // List<TrafficSubsidyEntity> trafficSubsidyList =
  1784. // this.getSession().createSQLQuery(str.toString()).addEntity(TrafficSubsidyEntity.class).list();
  1785. HashMap<String, Object> hm = hm_cache.get("getTrafficSubsidyEntityWithCache");
  1786. if (hm == null) {
  1787. hm = new HashMap<>();
  1788. hm_cache.put("getTrafficSubsidyEntityWithCache", hm);
  1789. CriteriaQuery specialcq = new CriteriaQuery(TrafficSubsidyEntity.class);
  1790. specialcq.eq("deleteFlag", "0");
  1791. specialcq.add();
  1792. specialcq.eq("status", "0");
  1793. specialcq.add();
  1794. List<TrafficSubsidyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  1795. for (TrafficSubsidyEntity entity : entitiesFromDB) {
  1796. hm.put(entity.getId(), entity);
  1797. }
  1798. }
  1799. return (TrafficSubsidyEntity) hm.get(trafficSubsidyid);
  1800. }
  1801. /**
  1802. * @param hm_cache
  1803. * @param userid
  1804. * @return
  1805. */
  1806. private BigDecimal getCertificateSubsidyMoneyWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
  1807. // StringBuffer str = new StringBuffer();
  1808. // String st = "and status = 0 and delete_flag = 0";
  1809. //
  1810. // String certiSql = "select * from t_bus_certificate_subsidy where id in
  1811. // (select certificateid from t_bus_user_certificate where
  1812. // userid='"+uw.getUserid()+"' and delete_flag = 0) and status = 0 and
  1813. // delete_flag = 0";
  1814. // List<CertificateSubsidyEntity> usList =
  1815. // this.getSession().createSQLQuery(certiSql).addEntity(CertificateSubsidyEntity.class).list();
  1816. // BigDecimal bigDecimal = new BigDecimal(0);
  1817. HashMap<String, Object> hm = hm_cache.get("getCertificateSubsidyEntityWithCache");
  1818. if (hm == null) {
  1819. hm = new HashMap<>();
  1820. hm_cache.put("getCertificateSubsidyEntityWithCache", hm);
  1821. StringBuffer str_certificate = new StringBuffer();
  1822. str_certificate.append("select * from t_bus_user_certificate where delete_flag = 0");
  1823. List<UserCertificateEntity> entitiesUserCertificateEntity = this.getSession().createSQLQuery(str_certificate.toString()).addEntity(UserCertificateEntity.class).list();
  1824. String str_subsidy = "select * from t_bus_certificate_subsidy where delete_flag = 0 and status=0";
  1825. List<CertificateSubsidyEntity> subList = this.getSession().createSQLQuery(str_subsidy).addEntity(CertificateSubsidyEntity.class).list();
  1826. HashMap<String, CertificateSubsidyEntity> subMap = new HashMap<>();
  1827. for (CertificateSubsidyEntity sub : subList) {
  1828. subMap.put(sub.getId(), sub);
  1829. }
  1830. for (UserCertificateEntity certificateEntity : entitiesUserCertificateEntity) {
  1831. String userInEntity = certificateEntity.getUserid();
  1832. String certInEntity = certificateEntity.getCertificateid();
  1833. CertificateSubsidyEntity subEntity = subMap.get(certInEntity);
  1834. BigDecimal subMoney = BigDecimal.ZERO;
  1835. if (subEntity != null && subEntity.getSubsidyMoney() != null) {
  1836. subMoney = subEntity.getSubsidyMoney();
  1837. }
  1838. if (hm.containsKey(userInEntity)) {
  1839. BigDecimal old = BigDecimal.ZERO;
  1840. if ((BigDecimal) hm.get(userInEntity) != null) {
  1841. old = (BigDecimal) hm.get(userInEntity);
  1842. }
  1843. hm.put(userInEntity, subMoney.add(old));
  1844. } else {
  1845. if (subMoney == null) {
  1846. subMoney = BigDecimal.ZERO;
  1847. }
  1848. hm.put(userInEntity, subMoney);
  1849. }
  1850. }
  1851. }
  1852. return (BigDecimal) hm.get(userid);
  1853. }
  1854. /**
  1855. * 将从数据库中读取的字符串信息转化成实体类
  1856. *
  1857. * @author hualong.zhao
  1858. * @date 2017-11-29
  1859. * @param jsonobjString
  1860. * @return
  1861. */
  1862. private AttendanceDetailJsonObj getJsonObjFromString(String jsonobjString) {
  1863. AttendanceDetailJsonObj jsonObj = new AttendanceDetailJsonObj();
  1864. if (oConvertUtils.isNotEmpty(jsonobjString)) {
  1865. try {
  1866. jsonObj = (JSONObject.parseObject(jsonobjString)).toJavaObject(AttendanceDetailJsonObj.class);
  1867. } catch (Exception e) {
  1868. }
  1869. }
  1870. return jsonObj;
  1871. }
  1872. /**
  1873. * 餐费补助
  1874. *
  1875. * @param hm_cache
  1876. * @param us
  1877. * @param uw
  1878. * @return
  1879. */
  1880. private UserNewWageEntity mealsCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw,
  1881. List<MealsSubsidyEntity> meslList) {
  1882. uw.setMealsSubsidyDay(new BigDecimal(0));
  1883. uw.setMealsSubsidyNight(new BigDecimal(0));
  1884. uw.setMealsSubsidy(new BigDecimal(0));
  1885. if (uat != null) {
  1886. if ("0".equals(us.getStrategyType())) {
  1887. uw.setMealsSubsidy(new BigDecimal(0));
  1888. // 每月固定餐补
  1889. if (StringUtils.isNotEmpty(us.getFixedmealsSubsidyid())) {
  1890. for (MealsSubsidyEntity mse : meslList) {
  1891. if (us.getFixedmealsSubsidyid().equals(mse.getId())) {
  1892. uw.setMealsSubsidy(uw.getMealsSubsidy().add(mse.getSubsidyMoney()));
  1893. }
  1894. if (uat.getExtraOvertime() != null && uat.getExtraOvertime().intValue() > 0 && StringUtils.isNotEmpty(us.getNofixedmealsSubsidyid())) {
  1895. if (us.getNofixedmealsSubsidyid().equals(mse.getId())) {
  1896. uw.setMealsSubsidy(uw.getMealsSubsidy().add(mse.getSubsidyMoney()).multiply(new BigDecimal(uat.getExtraOvertime())));
  1897. }
  1898. }
  1899. }
  1900. uw.setMealsSubsidyDay(new BigDecimal(0));
  1901. uw.setMealsSubsidyNight(new BigDecimal(0));
  1902. }
  1903. } else {
  1904. // 根据考勤记录及时餐补
  1905. calcMealSubsidyMoneyByAttendanceTotal(isCacheUsed, hm_cache, uat, uw, meslList);
  1906. BigDecimal big = new BigDecimal(0);
  1907. for (MealsSubsidyEntity mse : meslList) {
  1908. if (uat.getExtraOvertime() != null && uat.getExtraOvertime().intValue() > 0 && StringUtils.isNotEmpty(us.getNofixedmealsSubsidyid())) {
  1909. if (us.getNofixedmealsSubsidyid().equals(mse.getId())) {
  1910. big = mse.getSubsidyMoney().multiply(new BigDecimal(uat.getExtraOvertime()));
  1911. }
  1912. }
  1913. }
  1914. uw.setMealsSubsidy(uw.getMealsSubsidy().add(big));
  1915. }
  1916. }
  1917. //适配加班申请中的餐费部分
  1918. OvertimeDto overtimedto = getSpecialOvertimeSumEntityWithCache(hm_cache, us.getUserid(), uat.getYearmonth());
  1919. if(overtimedto != null) {
  1920. BigDecimal mealFee = overtimedto.getMealFee();
  1921. if(mealFee != null) {
  1922. BigDecimal mealSub = uw.getMealsSubsidy();
  1923. if(mealSub != null) {
  1924. mealSub = mealSub.add(mealFee);
  1925. uw.setMealsSubsidy(mealSub);
  1926. }
  1927. }
  1928. }
  1929. // 餐费补助 end
  1930. return uw;
  1931. }
  1932. private OvertimeDto getSpecialOvertimeSumEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache,
  1933. String userid, String yearmonth) {
  1934. HashMap<String, Object> hm = hm_cache.get("getSpecialOvertimeEntityWithCache");
  1935. if(hm == null) {
  1936. hm = new HashMap<>();
  1937. hm_cache.put("getSpecialOvertimeEntityWithCache", hm);
  1938. OvertimeDto dtoIn = new OvertimeDto();
  1939. dtoIn.setYearMonth(yearmonth);
  1940. List<OvertimeDto> overtimeDtos = overtimeService.getOverTimeFees(dtoIn);
  1941. if(overtimeDtos != null && overtimeDtos.size()>0) {
  1942. for(OvertimeDto dtoDb : overtimeDtos) {
  1943. String userInEntity = dtoDb.getUserid();
  1944. BigDecimal overtimeFee = BigDecimal.ZERO;
  1945. BigDecimal mealFee = BigDecimal.ZERO;
  1946. if(dtoDb != null && dtoDb.getOvertimeFee() != null) {
  1947. overtimeFee = dtoDb.getOvertimeFee();
  1948. }
  1949. if(dtoDb != null && dtoDb.getMealFee() != null) {
  1950. mealFee = dtoDb.getMealFee();
  1951. }
  1952. if(hm.containsKey(userInEntity)) {
  1953. if(hm.get(userInEntity) != null ) {
  1954. OvertimeDto oldDto = (OvertimeDto)hm.get(userInEntity);
  1955. BigDecimal oldDtoovertimeFee = oldDto.getOvertimeFee() == null ? BigDecimal.ZERO : oldDto.getOvertimeFee();
  1956. BigDecimal oldDtomealFee = oldDto.getMealFee() == null ? BigDecimal.ZERO : oldDto.getMealFee();
  1957. oldDto.setOvertimeFee(overtimeFee.add(oldDtoovertimeFee));
  1958. oldDto.setMealFee(oldDtomealFee.add(oldDtomealFee));
  1959. hm.put(userInEntity, oldDto);
  1960. }
  1961. }else {
  1962. if(overtimeFee == null) {
  1963. overtimeFee = BigDecimal.ZERO;
  1964. }
  1965. if(mealFee == null) {
  1966. mealFee = BigDecimal.ZERO;
  1967. }
  1968. OvertimeDto newDto = new OvertimeDto();
  1969. newDto.setOvertimeFee(overtimeFee);
  1970. newDto.setMealFee(mealFee);
  1971. hm.put(userInEntity, newDto);
  1972. }
  1973. }
  1974. }
  1975. }
  1976. return (OvertimeDto)hm.get(userid);
  1977. }
  1978. private void calcMealSubsidyMoneyByAttendanceTotal(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat, UserNewWageEntity uw, List<MealsSubsidyEntity> meslList) {
  1979. List<UserAttendanceDetailEntity> adeList = null;
  1980. if (isCacheUsed) {
  1981. adeList = getUserAttendanceDetailEntityWithCache(hm_cache, uat);
  1982. } else {
  1983. adeList = findByProperty(UserAttendanceDetailEntity.class, "attendanceId", uat.getId());
  1984. }
  1985. if (adeList != null && !adeList.isEmpty()) {
  1986. for (UserAttendanceDetailEntity ade : adeList) {
  1987. AttendanceDetailJsonObj jsonObj = getJsonObjFromString(oConvertUtils.getString(ade.getJsonObj()));
  1988. for (MealsSubsidyEntity mse : meslList) {
  1989. // 夜班白班津贴
  1990. if (jsonObj.getDayShiftSubsidy() != null && jsonObj.getDayShiftSubsidy().intValue() > 0) {
  1991. if (mse.getId().equals(jsonObj.getDayShiftSubsidyId())) {
  1992. uw.setMealsSubsidyDay(uw.getMealsSubsidyDay().add(mse.getSubsidyMoney().multiply(new BigDecimal(jsonObj.getDayShiftSubsidy()))));
  1993. }
  1994. }
  1995. // 夜班夜班津贴
  1996. if (jsonObj.getNightShiftSubsidy() != null && jsonObj.getNightShiftSubsidy().intValue() > 0) {
  1997. if (mse.getId().equals(jsonObj.getNightShiftSubsidyId())) {
  1998. uw.setMealsSubsidyNight(uw.getMealsSubsidyNight().add(mse.getSubsidyMoney().multiply(new BigDecimal(jsonObj.getNightShiftSubsidy()))));
  1999. }
  2000. }
  2001. // 日班
  2002. if (jsonObj.getDayShift() != null && jsonObj.getDayShift().intValue() > 0) {
  2003. if (mse.getId().equals(jsonObj.getDayShiftId())) {
  2004. uw.setMealsSubsidy(uw.getMealsSubsidy().add(mse.getSubsidyMoney().multiply(new BigDecimal(jsonObj.getDayShift()))));
  2005. }
  2006. }
  2007. // 常班
  2008. if (jsonObj.getRegularShift() != null && jsonObj.getRegularShift().intValue() > 0) {
  2009. if (mse.getId().equals(jsonObj.getRegularShiftId())) {
  2010. uw.setMealsSubsidy(uw.getMealsSubsidy().add(mse.getSubsidyMoney().multiply(new BigDecimal(jsonObj.getRegularShift()))));
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. /**
  2018. * @param hm_cache
  2019. * @param id
  2020. * @return
  2021. */
  2022. private List<UserAttendanceDetailEntity> getUserAttendanceDetailEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat) {
  2023. // TODO Auto-generated method stub
  2024. // findByProperty(UserAttendanceDetailEntity.class, "attendanceId",
  2025. // uat.getId());
  2026. HashMap<String, Object> hm = hm_cache.get("getUserAttendanceDetailEntityWithCache");
  2027. String month = uat.getYearmonth();
  2028. List<UserAttendanceDetailEntity> list = null;
  2029. if (hm == null) {
  2030. hm = new HashMap<>();
  2031. hm_cache.put("getUserAttendanceDetailEntityWithCache", hm);
  2032. String hql = "from UserAttendanceDetailEntity where ymd_date like '" + month + "%'";
  2033. List<UserAttendanceDetailEntity> entitiesFromDB = findHql(hql);
  2034. for (UserAttendanceDetailEntity entity : entitiesFromDB) {
  2035. String userInEntity = entity.getAttendanceId();
  2036. if (hm.containsKey(userInEntity)) {
  2037. List<UserAttendanceDetailEntity> entitylist = (List<UserAttendanceDetailEntity>) hm.get(userInEntity);
  2038. entitylist.add(entity);
  2039. } else {
  2040. List<UserAttendanceDetailEntity> newlist = new ArrayList<>();
  2041. newlist.add(entity);
  2042. hm.put(userInEntity, newlist);
  2043. }
  2044. }
  2045. }
  2046. return (List<UserAttendanceDetailEntity>) hm.get(uat.getId());
  2047. }
  2048. public AttendanceTotalJsonObj getTotalJsonObjFromString(String jsonobjString) {
  2049. AttendanceTotalJsonObj jsonObj = new AttendanceTotalJsonObj();
  2050. if (oConvertUtils.isNotEmpty(jsonobjString)) {
  2051. try {
  2052. jsonObj = (JSONObject.parseObject(jsonobjString)).toJavaObject(AttendanceTotalJsonObj.class);
  2053. } catch (Exception e) {
  2054. }
  2055. }
  2056. return jsonObj;
  2057. }
  2058. /**
  2059. * 工资扣除事项
  2060. *
  2061. * @param uat
  2062. * @param us
  2063. * @param uw
  2064. * @param flag
  2065. * 是否考勤扣:true扣除,false不扣除
  2066. * @return
  2067. */
  2068. private UserNewWageEntity deductionCalculation(UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per, boolean flag) {
  2069. if (uat == null) {
  2070. uw.setSickLeaveDebit(new BigDecimal(0));
  2071. uw.setThingLeaveDebit(new BigDecimal(0));
  2072. uw.setAbsenceDebit(new BigDecimal(0));
  2073. } else {
  2074. if (Globals.MANAGETYPE_2.toString().equals(per.getManagerType())) {
  2075. // 按照合同年限来扣除病假 zy20180417
  2076. calcuSickLeaveDebit(uat, uw, per);
  2077. // if(jsonObj != null && jsonObj.getSickLeavetotalmins() != null &&
  2078. // jsonObj.getSickLeavetotalmins().intValue() != 0){
  2079. //
  2080. // //病假时长由分钟转小时
  2081. // BigDecimal bigs = jsonObj.getSickLeavetotalmins().divide(new
  2082. // BigDecimal(60),3,BigDecimal.ROUND_HALF_UP);
  2083. // //协议员工扣除全部费用
  2084. // if(Globals.STAFFTYPE_1.toString().equals(per.getUserType())){
  2085. // uw.setSickLeaveDebit((Globals.BASE_PAY.divide(new
  2086. // BigDecimal(21.75*8),3,BigDecimal.ROUND_HALF_UP).multiply(bigs)));
  2087. // }else{
  2088. // BigDecimal bigDecimal = new BigDecimal(0);
  2089. // int sicleave = bigs.divide(new
  2090. // BigDecimal(8),3,BigDecimal.ROUND_HALF_UP).intValue();
  2091. // BigDecimal baseBigDecimal = uw.getBasicWage().divide(new
  2092. // BigDecimal(8*21.75),3,BigDecimal.ROUND_HALF_UP).multiply(bigs);
  2093. // if(sicleave < 2){
  2094. // bigDecimal = baseBigDecimal.multiply(new BigDecimal(0.4));
  2095. // }else if(sicleave >= 2 && sicleave < 4){
  2096. // bigDecimal = baseBigDecimal.multiply(new BigDecimal(0.3));
  2097. // }else if(sicleave >= 4){
  2098. // bigDecimal = baseBigDecimal.multiply(new BigDecimal(0.2));
  2099. // }
  2100. // //一线员工扣除的金额不能高于最低工资的20%
  2101. // uw.setSickLeaveDebit((bigDecimal.intValue() >= Globals.BASE_PAY.multiply(new
  2102. // BigDecimal(0.2)).intValue())?Globals.BASE_PAY.multiply(new
  2103. // BigDecimal(0.2)):bigDecimal);
  2104. // }
  2105. // }else{
  2106. // uw.setSickLeaveDebit(new BigDecimal(0));
  2107. // }
  2108. // 事假扣
  2109. if (flag) {
  2110. if (uat.getThingLeave() != null && uat.getThingLeave().intValue() != 0) {
  2111. if (uat.getTimeoutOvertimeDuration().compareTo(BigDecimal.ZERO) >= 0) {
  2112. // 超时加班工时大于等于零=实际工时已经扣除了事假时长,故不再扣除事假扣
  2113. uw.setThingLeaveDebit(new BigDecimal(0));
  2114. } else {
  2115. // 超时工时小于零,说明超时工时不够抵扣事假。那么不扣超时加班费,但是要扣事假扣除和缺勤扣除
  2116. uw.setThingLeaveDebit((uw.getBasicWage().divide(new BigDecimal(21.75 * 8), 3, BigDecimal.ROUND_HALF_UP)).multiply(uat.getThingLeave().divide(new BigDecimal(60), 3, BigDecimal.ROUND_HALF_UP)));
  2117. }
  2118. } else {
  2119. uw.setThingLeaveDebit(new BigDecimal(0));
  2120. }
  2121. } else {
  2122. uw.setThingLeaveDebit(new BigDecimal(0));
  2123. }
  2124. // 缺勤扣
  2125. if (flag) {
  2126. if (uat.getAbsenteeismAmount() != null && uat.getAbsenteeismAmount().intValue() != 0) {
  2127. if (uat.getTimeoutOvertimeDuration().compareTo(BigDecimal.ZERO) >= 0) {
  2128. // 超时加班工时大于等于零=实际工时已经扣除了缺勤时长,故不再扣除缺勤扣
  2129. uw.setAbsenceDebit(new BigDecimal(0));
  2130. } else {
  2131. // 超时工时小于零,说明超时工时不够抵扣缺勤。那么不扣超时加班费,但是要扣事假扣除和缺勤扣除
  2132. uw.setAbsenceDebit(
  2133. (uw.getBasicWage().divide(new BigDecimal(21.75 * 8), 3, BigDecimal.ROUND_HALF_UP)).multiply(uat.getAbsenteeismAmount()).divide(new BigDecimal(60), 3, BigDecimal.ROUND_HALF_UP));
  2134. }
  2135. } else {
  2136. uw.setAbsenceDebit(new BigDecimal(0));
  2137. }
  2138. } else {
  2139. uw.setAbsenceDebit(new BigDecimal(0));
  2140. }
  2141. } else {
  2142. uw.setSickLeaveDebit(new BigDecimal(0));
  2143. uw.setThingLeaveDebit(new BigDecimal(0));
  2144. uw.setAbsenceDebit(new BigDecimal(0));
  2145. }
  2146. }
  2147. /*
  2148. * //社保扣除 if(StringUtils.isNotEmpty(us.getSocialSecurityStrategyid())){
  2149. * str.delete(0,str.length());
  2150. * str.append("select * from t_bus_social_security_strategy where id = '"+us.
  2151. * getSocialSecurityStrategyid()+"'"); str.insert(str.length(), st);
  2152. * List<SocialSecurityStrategyEntity> social =
  2153. * this.getSession().createSQLQuery(str.toString()).addEntity(
  2154. * SocialSecurityStrategyEntity.class).list();
  2155. * //List<SocialSecurityStrategyEntity> social = findListbySql(str.toString());
  2156. * if(!social.isEmpty() && social.size() > 0){ SocialSecurityStrategyEntity meal
  2157. * = social.get(0); //multiply(meal.getPersonalBasicRetireInsu().add(meal.
  2158. * getPersionalBasicMedicalInsu().add(meal.getPersonalUnemploymentInsu()))).
  2159. * multiply(new BigDecimal(0.01))
  2160. *//**
  2161. * 社保个人金额: 中间各项目计算结果:四舍五入,保留1位小数; 合计:四舍五入,保留1位小数;
  2162. */
  2163. /*
  2164. * uw.setSocialSecurityDebit(new BigDecimal(0));
  2165. * uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().
  2166. * multiply(meal.getPersonalBasicRetireInsu().multiply(new
  2167. * BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_HALF_UP)));
  2168. * uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().
  2169. * multiply(meal.getPersionalBasicMedicalInsu().multiply(new
  2170. * BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_HALF_UP)));
  2171. * uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().
  2172. * multiply(meal.getPersonalUnemploymentInsu().multiply(new
  2173. * BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_HALF_UP)));
  2174. *//**
  2175. * 社保单位金额: 中间各项目计算结果:四舍五入,保留4位小数; 合计:四舍五入,保留4位小数;
  2176. *//*
  2177. * uw.setComSocialSecurityDebit(new BigDecimal(0));
  2178. * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
  2179. * getBasePay().multiply(meal.getCompanyBasicRetireInsu().multiply(new
  2180. * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
  2181. * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
  2182. * getBasePay().multiply(meal.getCompanyBasicMedicalInsu().multiply(new
  2183. * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
  2184. * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
  2185. * getBasePay().multiply(meal.getCompanyUnemploymentInsu().multiply(new
  2186. * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
  2187. * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
  2188. * getBasePay().multiply(meal.getCompanyInjuryInsu().multiply(new
  2189. * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
  2190. * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
  2191. * getBasePay().multiply(meal.getCompanyMaternityInsu().multiply(new
  2192. * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
  2193. *
  2194. * uw.setComSocialSecurityDebit(meal.getBasePay().multiply(meal.
  2195. * getCompanyBasicRetireInsu().add(meal.getCompanyBasicMedicalInsu())
  2196. * .add(meal.getCompanyUnemploymentInsu()).add(meal.getCompanyInjuryInsu()).add(
  2197. * meal.getCompanyMaternityInsu())).multiply(new BigDecimal(0.01))); }else{
  2198. * uw.setSocialSecurityDebit(new BigDecimal(0)); } }else{
  2199. * uw.setSocialSecurityDebit(new BigDecimal(0)); } //公积金扣除
  2200. * if(StringUtils.isNotEmpty(us.getProvidentFundStrategyid())){
  2201. * str.delete(0,str.length());
  2202. * str.append("select * from t_bus_provident_fund_strategy where id = '"+us.
  2203. * getProvidentFundStrategyid()+"'"); str.insert(str.length(), st);
  2204. * List<ProvidentFundStrategyEntity> perobident =
  2205. * this.getSession().createSQLQuery(str.toString()).addEntity(
  2206. * ProvidentFundStrategyEntity.class).list();
  2207. * //List<ProvidentFundStrategyEntity> perobident =
  2208. * findListbySql(str.toString()); if(!perobident.isEmpty() && perobident.size()
  2209. * > 0){ ProvidentFundStrategyEntity meal = perobident.get(0);
  2210. * //uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio()
  2211. * .multiply(new BigDecimal(0.01))));
  2212. * uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio().
  2213. * multiply(new BigDecimal(0.01))).setScale(0,BigDecimal.ROUND_HALF_UP));
  2214. * //uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio
  2215. * ().multiply(new BigDecimal(0.01))));
  2216. * uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio()
  2217. * .multiply(new BigDecimal(0.01))).setScale(0,BigDecimal.ROUND_HALF_UP));
  2218. * }else{ uw.setProvidentFundDebit(new BigDecimal(0)); } }else{
  2219. * uw.setProvidentFundDebit(new BigDecimal(0)); } //缴金补贴
  2220. * if(Globals.MANAGETYPE_2.toString().equals(per.getManagerType())){
  2221. * uw.setPaymentSubsidy(uw.getSocialSecurityDebit().add(uw.getProvidentFundDebit
  2222. * ())); }else{ uw.setPaymentSubsidy(new BigDecimal(0)); }
  2223. */
  2224. return uw;
  2225. }
  2226. /**
  2227. * 按照合同年限来扣除病假 zy20180417
  2228. *
  2229. * @param uat
  2230. * @param uw
  2231. * @param per
  2232. */
  2233. private void calcuSickLeaveDebit(UserAttendanceTotalEntity uat, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
  2234. AttendanceTotalJsonObj jsonObj = getTotalJsonObjFromString(uat.getJsonObj());
  2235. // 病假扣
  2236. // 按照合同年限来扣除病假 zy20180417
  2237. if (jsonObj != null && jsonObj.getSickLeavetotalmins() != null && jsonObj.getSickLeavetotalmins().intValue() != 0) {
  2238. BigDecimal sickDebit = BigDecimal.ZERO;
  2239. BigDecimal multiRate = BigDecimal.ZERO;
  2240. // 获取工作年限
  2241. int workYear = getWorkYears(per);
  2242. // 获取员工基本工资
  2243. BigDecimal basewage = uw.getBasicWage();
  2244. // 病假时长由分钟转小时
  2245. BigDecimal bigs = jsonObj.getSickLeavetotalmins().divide(new BigDecimal(60), 3, BigDecimal.ROUND_HALF_UP);
  2246. multiRate = basewage.divide(new BigDecimal(21.75 * 8), 3, BigDecimal.ROUND_HALF_UP).multiply(bigs);
  2247. // 协议员工扣除全部费用
  2248. if (Globals.STAFFTYPE_1.toString().equals(per.getUserType())) {
  2249. uw.setSickLeaveDebit(multiRate);
  2250. } else {
  2251. if (workYear < 2) {
  2252. sickDebit = multiRate.multiply(new BigDecimal(0.4));
  2253. } else if (workYear >= 2 && workYear < 4) {
  2254. sickDebit = multiRate.multiply(new BigDecimal(0.3));
  2255. } else if (workYear >= 4 && workYear < 10) {
  2256. sickDebit = multiRate.multiply(new BigDecimal(0.2));
  2257. } else if (workYear >= 10) {
  2258. sickDebit = BigDecimal.ZERO;
  2259. }
  2260. // 一线员工扣除的金额不能高于最低工资的20%
  2261. BigDecimal limit = basewage.multiply(new BigDecimal(0.2));
  2262. if (sickDebit.compareTo(limit) <= 0) {
  2263. uw.setSickLeaveDebit(sickDebit);
  2264. } else {
  2265. uw.setSickLeaveDebit(limit);
  2266. }
  2267. }
  2268. } else {
  2269. uw.setSickLeaveDebit(new BigDecimal(0));
  2270. }
  2271. }
  2272. /**
  2273. * 返回工作年限
  2274. *
  2275. * @param per
  2276. * @return
  2277. */
  2278. private int getWorkYears(PersonnelBaseArchivesManageOutDto per) {
  2279. try {
  2280. Date startDate = per.getContractStime();
  2281. Calendar startCalendar = Calendar.getInstance();
  2282. Calendar endCalendar = Calendar.getInstance();
  2283. startCalendar.setTime(startDate);
  2284. if (endCalendar.compareTo(startCalendar) < 0) {
  2285. return 0;
  2286. }
  2287. int day = endCalendar.get(Calendar.DAY_OF_MONTH) - startCalendar.get(Calendar.DAY_OF_MONTH);
  2288. int month = endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
  2289. int year = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
  2290. if (day < 0) {
  2291. month--;
  2292. }
  2293. if (month < 0) {
  2294. month += 12;
  2295. year--;
  2296. }
  2297. if (year > 0) {
  2298. return year;
  2299. }
  2300. } catch (Exception e) {
  2301. }
  2302. return 0;
  2303. }
  2304. // private UserNewWageEntity comCost(UserAttendanceTotalEntity uat
  2305. // ,UserNewWagestrategyEntity us,UserNewWageEntity
  2306. // uw,PersonnelBaseArchivesManageOutDto per){
  2307. // BigDecimal result = BigDecimal.ZERO;
  2308. // if(uw.getPreTaxMone() != null) {
  2309. // result = result.add(uw.getPreTaxMone());
  2310. // }
  2311. // if(uw.getComSocialSecurityDebit() != null) {
  2312. // result = result.add(uw.getComSocialSecurityDebit());
  2313. // }
  2314. // if(uw.getComProvidentFundDebit() != null) {
  2315. // result = result.add(uw.getComProvidentFundDebit());
  2316. // }
  2317. // return uw;
  2318. // }
  2319. /**
  2320. * 查询社保和公积金
  2321. *
  2322. * @param hm_cache
  2323. * @param uat
  2324. * @param us
  2325. * @param uw
  2326. * @param per
  2327. * @return
  2328. */
  2329. private UserNewWageEntity socialSecurityProvidentFund(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw,
  2330. PersonnelBaseArchivesManageOutDto per) {
  2331. StringBuffer str = new StringBuffer();
  2332. String st = " and status = 0 and delete_flag = 0";
  2333. // 社保扣除
  2334. if (StringUtils.isNotEmpty(us.getSocialSecurityStrategyid())) {
  2335. str.delete(0, str.length());
  2336. str.append("select * from t_bus_social_security_strategy where id = '" + us.getSocialSecurityStrategyid() + "'");
  2337. str.insert(str.length(), st);
  2338. // List<SocialSecurityStrategyEntity> social =
  2339. // this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list();
  2340. // List<SocialSecurityStrategyEntity> social = findListbySql(str.toString());
  2341. SocialSecurityStrategyEntity social = null;
  2342. if (isCacheUsed) {
  2343. social = getSocialSecurityStrategyEntityWithCache(hm_cache, us.getSocialSecurityStrategyid());
  2344. } else {
  2345. List<SocialSecurityStrategyEntity> socialList = this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list();
  2346. if (socialList != null && socialList.size() > 0) {
  2347. social = socialList.get(0);
  2348. }
  2349. }
  2350. if (social != null) {
  2351. SocialSecurityStrategyEntity meal = social;
  2352. uw.setSocialSecurityId(meal.getId());
  2353. uw.setSocialSecurityUnit(meal.getSocialSecurityUnit());
  2354. // multiply(meal.getPersonalBasicRetireInsu().add(meal.getPersionalBasicMedicalInsu().add(meal.getPersonalUnemploymentInsu()))).multiply(new
  2355. // BigDecimal(0.01))
  2356. if (Globals.SOCIAL_SECURITY_STRATEGY_HUZHOU.equals(social.getId())) {
  2357. huzhouSocialSecurityCalcu(uw, social);
  2358. } else {
  2359. normalSocialSecurityCalcu(uw, social);
  2360. }
  2361. // /**
  2362. // * 社保个人金额:
  2363. // 中间各项目计算结果:直接进位,保留1位小数;
  2364. // 合计:直接进位,保留1位小数;
  2365. // */
  2366. // uw.setSocialSecurityDebit(new BigDecimal(0));
  2367. // uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersonalBasicRetireInsu().multiply(new
  2368. // BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_UP)));
  2369. // uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersionalBasicMedicalInsu().multiply(new
  2370. // BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_UP)));
  2371. // uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersonalUnemploymentInsu().multiply(new
  2372. // BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_UP)));
  2373. // //合计值保留一位
  2374. // uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().setScale(1,BigDecimal.ROUND_UP));
  2375. // /**
  2376. // * 社保单位金额:
  2377. // * 中间各项目计算结果:四舍五入,保留3位小数;
  2378. // * 合计:四舍五入,保留2位小数;
  2379. // */
  2380. // uw.setComSocialSecurityDebit(new BigDecimal(0));
  2381. // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyBasicRetireInsu().multiply(new
  2382. // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
  2383. // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyBasicMedicalInsu().multiply(new
  2384. // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
  2385. // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyUnemploymentInsu().multiply(new
  2386. // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
  2387. // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyInjuryInsu().multiply(new
  2388. // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
  2389. // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyMaternityInsu().multiply(new
  2390. // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
  2391. // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().setScale(2,BigDecimal.ROUND_HALF_UP));
  2392. /*
  2393. * uw.setComSocialSecurityDebit(meal.getBasePay().multiply(meal.
  2394. * getCompanyBasicRetireInsu().add(meal.getCompanyBasicMedicalInsu())
  2395. * .add(meal.getCompanyUnemploymentInsu()).add(meal.getCompanyInjuryInsu()).add(
  2396. * meal.getCompanyMaternityInsu())).multiply(new BigDecimal(0.01)));
  2397. */
  2398. } else {
  2399. uw.setSocialSecurityDebit(new BigDecimal(0));
  2400. uw.setComSocialSecurityDebit(new BigDecimal(0));
  2401. }
  2402. } else {
  2403. uw.setSocialSecurityDebit(new BigDecimal(0));
  2404. uw.setComSocialSecurityDebit(new BigDecimal(0));
  2405. }
  2406. // 公积金扣除
  2407. if (StringUtils.isNotEmpty(us.getProvidentFundStrategyid())) {
  2408. ProvidentFundStrategyEntity perobident = null;
  2409. if (isCacheUsed) {
  2410. perobident = getProvidentFundStrategyEntityWithCache(hm_cache, us.getProvidentFundStrategyid());
  2411. } else {
  2412. str.delete(0, str.length());
  2413. str.append("select * from t_bus_provident_fund_strategy where id = '" + us.getProvidentFundStrategyid() + "'");
  2414. str.insert(str.length(), st);
  2415. List<ProvidentFundStrategyEntity> perobidentList = this.getSession().createSQLQuery(str.toString()).addEntity(ProvidentFundStrategyEntity.class).list();
  2416. if (perobidentList != null && perobidentList.size() > 0) {
  2417. perobident = perobidentList.get(0);
  2418. }
  2419. }
  2420. if (perobident != null) {
  2421. ProvidentFundStrategyEntity meal = perobident;
  2422. // uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio().multiply(new
  2423. // BigDecimal(0.01))));
  2424. uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio().multiply(new BigDecimal(0.01))).setScale(0, BigDecimal.ROUND_HALF_UP));
  2425. // uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio().multiply(new
  2426. // BigDecimal(0.01))));
  2427. uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio().multiply(new BigDecimal(0.01))).setScale(0, BigDecimal.ROUND_HALF_UP));
  2428. } else {
  2429. uw.setProvidentFundDebit(new BigDecimal(0));
  2430. uw.setComProvidentFundDebit(new BigDecimal(0));
  2431. }
  2432. } else {
  2433. uw.setProvidentFundDebit(new BigDecimal(0));
  2434. uw.setComProvidentFundDebit(new BigDecimal(0));
  2435. }
  2436. // 缴金补贴
  2437. java.lang.String jiaojin_subsidy = us.getJiaojinSubsidyid();
  2438. // zy20180428 如果工资策略里没有设定缴金补贴,则按照原始缴扣进行补贴.否则按照工资策略补贴
  2439. if (jiaojin_subsidy == null) {
  2440. uw.setPaymentSubsidy(uw.getSocialSecurityDebit().add(uw.getProvidentFundDebit()));
  2441. } else {
  2442. uw.setPaymentSubsidy(BigDecimal.ZERO);
  2443. BigDecimal jiaonjinMoney = getJiaoJinSubsidyMoney(isCacheUsed, hm_cache, uw, us, per);
  2444. if(jiaonjinMoney != null) {
  2445. uw.setPaymentSubsidy(jiaonjinMoney);
  2446. }
  2447. }
  2448. return uw;
  2449. }
  2450. /**
  2451. * @param isCacheUsed
  2452. * @param hm_cache
  2453. * @param uw
  2454. * @param us
  2455. * @param per
  2456. * @return
  2457. */
  2458. private BigDecimal getJiaoJinSubsidyMoney(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) {
  2459. if(Globals.JIAOJIN_DEFAULT_SUBSIDY_ID.equals(us.getJiaojinSubsidyid())) {
  2460. return uw.getProvidentFundDebit().add(uw.getSocialSecurityDebit());
  2461. }
  2462. if(Globals.JIAOJIN_NO_SUBSIDY_ID.equals(us.getJiaojinSubsidyid())) {
  2463. return BigDecimal.ZERO;
  2464. }
  2465. JiaojinSubsidyStrategyEntity jiaojinEntity = getJiaojinEntityWithCache(hm_cache, us.getJiaojinSubsidyid());
  2466. if(jiaojinEntity != null) {
  2467. return jiaojinEntity.getMoney();
  2468. }
  2469. return BigDecimal.ZERO;
  2470. }
  2471. /**
  2472. * @param hm_cache
  2473. * @param jiaojinSubsidyid
  2474. * @return
  2475. */
  2476. private JiaojinSubsidyStrategyEntity getJiaojinEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String jiaojinSubsidyid) {
  2477. HashMap<String, Object> hm = hm_cache.get("getJiaojinEntityWithCache");
  2478. if (hm == null) {
  2479. hm = new HashMap<>();
  2480. hm_cache.put("getJiaojinEntityWithCache", hm);
  2481. CriteriaQuery specialcq = new CriteriaQuery(JiaojinSubsidyStrategyEntity.class);
  2482. List<JiaojinSubsidyStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  2483. for (JiaojinSubsidyStrategyEntity entity : entitiesFromDB) {
  2484. hm.put(entity.getId(), entity);
  2485. }
  2486. }
  2487. return (JiaojinSubsidyStrategyEntity) hm.get(jiaojinSubsidyid);
  2488. }
  2489. /**
  2490. * @param hm_cache
  2491. * @param providentFundStrategyid
  2492. * @return
  2493. */
  2494. private ProvidentFundStrategyEntity getProvidentFundStrategyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String providentFundStrategyid) {
  2495. HashMap<String, Object> hm = hm_cache.get("getProvidentFundStrategyEntityWithCache");
  2496. if (hm == null) {
  2497. hm = new HashMap<>();
  2498. hm_cache.put("getProvidentFundStrategyEntityWithCache", hm);
  2499. CriteriaQuery specialcq = new CriteriaQuery(ProvidentFundStrategyEntity.class);
  2500. specialcq.eq("deleteFlag", "0");
  2501. specialcq.add();
  2502. specialcq.eq("status", "0");
  2503. specialcq.add();
  2504. List<ProvidentFundStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  2505. for (ProvidentFundStrategyEntity entity : entitiesFromDB) {
  2506. hm.put(entity.getId(), entity);
  2507. }
  2508. }
  2509. return (ProvidentFundStrategyEntity) hm.get(providentFundStrategyid);
  2510. }
  2511. /**
  2512. * @param hm_cache
  2513. * @param socialSecurityStrategyid
  2514. * @return
  2515. */
  2516. private SocialSecurityStrategyEntity getSocialSecurityStrategyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String socialSecurityStrategyid) {
  2517. HashMap<String, Object> hm = hm_cache.get("getSocialSecurityStrategyEntityWithCache");
  2518. if (hm == null) {
  2519. hm = new HashMap<>();
  2520. hm_cache.put("getSocialSecurityStrategyEntityWithCache", hm);
  2521. CriteriaQuery specialcq = new CriteriaQuery(SocialSecurityStrategyEntity.class);
  2522. specialcq.eq("deleteFlag", "0");
  2523. specialcq.add();
  2524. specialcq.eq("status", "0");
  2525. specialcq.add();
  2526. List<SocialSecurityStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  2527. for (SocialSecurityStrategyEntity entity : entitiesFromDB) {
  2528. hm.put(entity.getId(), entity);
  2529. }
  2530. }
  2531. return (SocialSecurityStrategyEntity) hm.get(socialSecurityStrategyid);
  2532. }
  2533. /**
  2534. * 加班统计
  2535. *
  2536. * @param hm_cache
  2537. * @param uat
  2538. * @param us
  2539. * @param uw
  2540. * @return
  2541. */
  2542. private UserNewWageEntity overtimeCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw, String month,
  2543. PersonnelBaseArchivesManageOutDto per) {
  2544. StringBuffer str = new StringBuffer();
  2545. String st = " and status = 0 and delete_flag = 0";
  2546. if (uat == null) {
  2547. uw.setOvertimepayTimeout(new BigDecimal(0.00));
  2548. uw.setOvertimepayFixed(new BigDecimal(0));
  2549. uw.setDuty(new BigDecimal(0));
  2550. uw.setSpecialOvertime(new BigDecimal(0));
  2551. } else {
  2552. // if("ff808081645a0e3d0164d097628a07f3".equals(uat.getUserId())) {
  2553. // System.out.println("wu");
  2554. // }
  2555. // 超时加班费
  2556. if (uat.getTimeoutOvertimeDuration() != null && uat.getTimeoutOvertimeDuration().intValue() > 0) {
  2557. ArrangeDutyOperateEntity arrange = getArrangeDutyOperateEntityWithCache(hm_cache, month, us.getUserid());
  2558. if (arrange == null || arrange.getRunway().contains("jijiabanfei")) {
  2559. // 轮转方式为空,默认给加班费
  2560. OvertimepayStrategyEntity overtimepaystrate = null;
  2561. if (isCacheUsed) {
  2562. overtimepaystrate = getOvertimepayStrategyEntityWithCache(hm_cache, us.getOvertimepayStrategyid());
  2563. } else {
  2564. str.delete(0, str.length());
  2565. str.append("select * from t_bus_overtimepay_strategy where id = '" + us.getOvertimepayStrategyid() + "'");
  2566. str.insert(str.length(), st);
  2567. List<OvertimepayStrategyEntity> overtimepaystrateList = this.getSession().createSQLQuery(str.toString()).addEntity(OvertimepayStrategyEntity.class).list();
  2568. if (overtimepaystrateList != null && overtimepaystrateList.size() > 0) {
  2569. overtimepaystrate = overtimepaystrateList.get(0);
  2570. }
  2571. }
  2572. if (overtimepaystrate != null) {
  2573. uw.setOvertimepayTimeout((uw.getBasicWage().divide(new BigDecimal(21.75), 2, BigDecimal.ROUND_HALF_UP).divide(new BigDecimal(8), 2, BigDecimal.ROUND_HALF_UP))
  2574. .multiply(overtimepaystrate.getMultiple()).multiply(uat.getTimeoutOvertimeDuration().divide(new BigDecimal(60), 2, BigDecimal.ROUND_HALF_UP)));
  2575. } else {
  2576. uw.setOvertimepayTimeout(new BigDecimal(0.00));
  2577. }
  2578. } else {
  2579. uw.setOvertimepayTimeout(new BigDecimal(0.00));
  2580. }
  2581. } else {
  2582. uw.setOvertimepayTimeout(new BigDecimal(0.00));
  2583. }
  2584. // 国家法定加班费
  2585. // 两部分:一部分是国定超时加班,另一部分是国定值班,国定值班费在值班费的代码里计算 zy20180416
  2586. if (uat.getNationalOvertimeDuration() != null && uat.getNationalOvertimeDuration().intValue() > 0) {
  2587. WagestrategyDto wa = getWagestrategyDto(isCacheUsed, hm_cache, per);
  2588. if (wa != null) {
  2589. if (per != null && "2".equals(per.getManagerType())) {
  2590. uw.setOvertimepayFixed((wa.getBasicWage().divide(new BigDecimal(21.75), 3, BigDecimal.ROUND_HALF_UP).divide(new BigDecimal(8), 3, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(3))
  2591. .multiply(uat.getNationalOvertimeDuration().divide(new BigDecimal(60), 3, BigDecimal.ROUND_HALF_UP)));
  2592. } else {
  2593. uw.setOvertimepayFixed(new BigDecimal(0));
  2594. }
  2595. }
  2596. } else {
  2597. uw.setOvertimepayFixed(new BigDecimal(0));
  2598. }
  2599. // 值班费 duty_duration
  2600. if (uat.getDutyDuration() != null && StringUtils.isNotEmpty(us.getDutyStrategyid())) {
  2601. // str.delete(0,str.length());
  2602. // str.append("select * from t_bus_dutyfee_strategy where id =
  2603. // '"+us.getDutyStrategyid()+"'");
  2604. // str.insert(str.length(), st);
  2605. // List<DutyfeeStrategyEntity> mealList =
  2606. // this.getSession().createSQLQuery(str.toString()).addEntity(DutyfeeStrategyEntity.class).list();
  2607. DutyfeeStrategyEntity dutyfee = null;
  2608. if (isCacheUsed) {
  2609. dutyfee = getDutyfeeStrategyEntityWithCache(hm_cache, us.getDutyStrategyid());
  2610. } else {
  2611. str.delete(0, str.length());
  2612. str.append("select * from t_bus_dutyfee_strategy where id = '" + us.getDutyStrategyid() + "'");
  2613. str.insert(str.length(), st);
  2614. List<DutyfeeStrategyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(DutyfeeStrategyEntity.class).list();
  2615. if (mealList != null && mealList.size() > 0) {
  2616. dutyfee = mealList.get(0);
  2617. }
  2618. }
  2619. // List<DutyfeeStrategyEntity> mealList = findListbySql(str.toString());
  2620. if (dutyfee != null) {
  2621. DutyfeeStrategyEntity meal = dutyfee;
  2622. uw.setDuty(uat.getDutyDuration().multiply(meal.getMoney()));
  2623. // 把国定值班费算到国定加班zyzy20180416
  2624. BigDecimal nationaltimeoutPay = uw.getOvertimepayFixed(); // 已有的国定超时加班费
  2625. BigDecimal nationaldutyPay = meal.getMoney().multiply(new BigDecimal(3)).multiply(uat.getNationalDutyDuration()); // 3倍普通值班费*国定值班天数
  2626. uw.setOvertimepayFixed(nationaltimeoutPay.add(nationaldutyPay)); // 两部分都赋值到国定加班费里
  2627. } else {
  2628. uw.setDuty(new BigDecimal(0));
  2629. }
  2630. } else {
  2631. uw.setDuty(new BigDecimal(0));
  2632. }
  2633. // 适配新的加班申请 2019-12-05
  2634. OvertimeDto overtimedto = getSpecialOvertimeSumEntityWithCache(hm_cache, per.getUserId(), month);
  2635. if(overtimedto != null) {
  2636. uw.setSpecialOvertime(overtimedto.getOvertimeFee() == null ? BigDecimal.ZERO : overtimedto.getOvertimeFee());
  2637. }else {
  2638. uw.setSpecialOvertime(new BigDecimal(0));
  2639. }
  2640. }
  2641. return uw;
  2642. }
  2643. /**
  2644. * @param hm_cache
  2645. * @param month
  2646. * @param userid
  2647. * @return
  2648. */
  2649. private ArrangeDutyOperateEntity getArrangeDutyOperateEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String month, String userid) {
  2650. // this.getSession().createSQLQuery("select * from t_bus_arrangeduty_operate
  2651. // where userid like '%"+us.getUserid()+"%' and yearmonth =
  2652. // '"+month+"'").addEntity(ArrangeDutyOperateEntity.class).list();
  2653. HashMap<String, Object> hm = hm_cache.get("getArrangeDutyOperateEntityWithCache");
  2654. if (hm == null) {
  2655. hm = new HashMap<>();
  2656. hm_cache.put("getArrangeDutyOperateEntityWithCache", hm);
  2657. List<ArrangeDutyOperateEntity> entitiesFromDB = this.getSession().createSQLQuery("select * from t_bus_arrangeduty_operate where yearmonth = '" + month + "'").addEntity(ArrangeDutyOperateEntity.class).list();
  2658. hm.put("ALL", entitiesFromDB);
  2659. }
  2660. List<ArrangeDutyOperateEntity> entitiesFromDB = (List<ArrangeDutyOperateEntity>) hm.get("ALL");
  2661. if (entitiesFromDB != null && entitiesFromDB.size() > 0) {
  2662. for (ArrangeDutyOperateEntity entity : entitiesFromDB) {
  2663. if (entity != null) {
  2664. String userids = entity.getUserid();
  2665. if (userids.indexOf(userid) > -1) {
  2666. return entity;
  2667. }
  2668. }
  2669. }
  2670. }
  2671. return null;
  2672. }
  2673. /**
  2674. * @param hm_cache
  2675. * @param dutyStrategyid
  2676. * @return
  2677. */
  2678. private DutyfeeStrategyEntity getDutyfeeStrategyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String dutyStrategyid) {
  2679. HashMap<String, Object> hm = hm_cache.get("getDutyfeeStrategyEntityWithCache");
  2680. if (hm == null) {
  2681. hm = new HashMap<>();
  2682. hm_cache.put("getDutyfeeStrategyEntityWithCache", hm);
  2683. CriteriaQuery specialcq = new CriteriaQuery(DutyfeeStrategyEntity.class);
  2684. specialcq.eq("deleteFlag", "0");
  2685. specialcq.add();
  2686. specialcq.eq("status", "0");
  2687. specialcq.add();
  2688. List<DutyfeeStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  2689. for (DutyfeeStrategyEntity entity : entitiesFromDB) {
  2690. hm.put(entity.getId(), entity);
  2691. }
  2692. }
  2693. return (DutyfeeStrategyEntity) hm.get(dutyStrategyid);
  2694. }
  2695. /**
  2696. * @param hm_cache
  2697. * @param overtimepayStrategyid
  2698. * @return
  2699. */
  2700. private OvertimepayStrategyEntity getOvertimepayStrategyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String overtimepayStrategyid) {
  2701. // TODO Auto-generated method stub
  2702. HashMap<String, Object> hm = hm_cache.get("getOvertimepayStrategyEntityWithCache");
  2703. if (hm == null) {
  2704. hm = new HashMap<>();
  2705. hm_cache.put("getOvertimepayStrategyEntityWithCache", hm);
  2706. CriteriaQuery specialcq = new CriteriaQuery(OvertimepayStrategyEntity.class);
  2707. specialcq.eq("deleteFlag", "0");
  2708. specialcq.add();
  2709. specialcq.eq("status", "0");
  2710. specialcq.add();
  2711. List<OvertimepayStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
  2712. for (OvertimepayStrategyEntity entity : entitiesFromDB) {
  2713. hm.put(entity.getId(), entity);
  2714. }
  2715. }
  2716. return (OvertimepayStrategyEntity) hm.get(overtimepayStrategyid);
  2717. }
  2718. /**
  2719. * 查询保存员工工资策略设定历史表
  2720. *
  2721. * @param uwh
  2722. * @param us
  2723. * @return
  2724. */
  2725. private UserWagestrategyHistoryEntity historyUW(UserWagestrategyHistoryEntity uwh, UserNewWagestrategyEntity us) {
  2726. StringBuffer str = new StringBuffer();
  2727. String st = " and status = 0 and delete_flag = 0";
  2728. // 职务
  2729. if (StringUtils.isNotEmpty(us.getDutiesid())) {
  2730. DutiesEntity dut = get(DutiesEntity.class, us.getDutiesid());
  2731. uwh.setDutiesName(dut.getDutiesName());
  2732. }
  2733. // 证书补贴
  2734. if (StringUtils.isNotEmpty(us.getCertificateSubsidyid())) {
  2735. String[] certificteStrings = us.getCertificateSubsidyid().split(",");
  2736. StringBuffer buffer = new StringBuffer();
  2737. for (int i = 0; i < certificteStrings.length; i++) {
  2738. str.delete(0, str.length());
  2739. str.append("select * from t_bus_certificate_subsidy where id = '" + certificteStrings[i] + "'");
  2740. str.insert(str.length(), st);
  2741. List<CertificateSubsidyEntity> usList = this.getSession().createSQLQuery(str.toString()).addEntity(CertificateSubsidyEntity.class).list();
  2742. // List<CertificateSubsidyEntity> usList = findListbySql(str.toString());
  2743. if (!usList.isEmpty()) {
  2744. CertificateSubsidyEntity cer = usList.get(0);
  2745. if (i == 0) {
  2746. buffer.append(cer.getCertificateName() + "-" + cer.getSubsidyMoney() + "元");
  2747. } else {
  2748. buffer.append("," + cer.getCertificateName() + "-" + cer.getSubsidyMoney() + "元");
  2749. }
  2750. }
  2751. }
  2752. uwh.setCertificateSubsidyDesc(buffer.toString());
  2753. }
  2754. // 交通补贴
  2755. // if (StringUtils.isNotEmpty(us.getTrafficSubsidyid())) {
  2756. // str.delete(0, str.length());
  2757. // str.append("select * from t_bus_traffic_subsidy where id ='" + us.getTrafficSubsidyid() + "'");
  2758. // str.insert(str.length(), st);
  2759. // List<TrafficSubsidyEntity> trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(TrafficSubsidyEntity.class).list();
  2760. // // List<TrafficSubsidyEntity> trafficSubsidyList =
  2761. // // this.findListbySql(str.toString());
  2762. // if (oConvertUtils.isNotEmpty(trafficSubsidyList)) {
  2763. // uwh.setTrafficSubsidyDesc(trafficSubsidyList.get(0).getSubsidyName() + "-" + trafficSubsidyList.get(0).getSubsidyMoney() + "元");
  2764. // }
  2765. // }
  2766. // 高温补贴
  2767. if (StringUtils.isNotEmpty(us.getMegathermalSubsidyid())) {
  2768. str.delete(0, str.length());
  2769. str.append("select * from t_bus_megathermal_subsidy where id ='" + us.getMegathermalSubsidyid() + "'");
  2770. str.insert(str.length(), st);
  2771. List<MegathermalSubsidyEntity> trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(MegathermalSubsidyEntity.class).list();
  2772. // List<MegathermalSubsidyEntity> trafficSubsidyList =
  2773. // this.findListbySql(str.toString());
  2774. if (oConvertUtils.isNotEmpty(trafficSubsidyList)) {
  2775. uwh.setMegathermalSubsidyDesc(trafficSubsidyList.get(0).getSubsidyName() + "-" + trafficSubsidyList.get(0).getSubsidyMoney() + "元");
  2776. }
  2777. }
  2778. // 独生子女费
  2779. if (us.getOnlychildPay() != null) {
  2780. uwh.setOnlychildPay(us.getOnlychildPay());
  2781. }
  2782. // 其他补贴
  2783. if (StringUtils.isNotEmpty(us.getOtherSubsidyid())) {
  2784. str.delete(0, str.length());
  2785. str.append("select * from t_bus_other_subsidy where id ='" + us.getOtherSubsidyid() + "'");
  2786. str.insert(str.length(), st);
  2787. List<OtherSubsidyEntity> trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(OtherSubsidyEntity.class).list();
  2788. // List<OtherSubsidyEntity> trafficSubsidyList =
  2789. // this.findListbySql(str.toString());
  2790. if (oConvertUtils.isNotEmpty(trafficSubsidyList)) {
  2791. uwh.setOtherSubsidyDesc(trafficSubsidyList.get(0).getSubsidyName() + "-" + trafficSubsidyList.get(0).getSubsidyMoney() + "元");
  2792. }
  2793. }
  2794. // 餐补方式 0.每月固定 1.每月班次
  2795. uwh.setStrategyType(us.getStrategyType());
  2796. // 额外加班
  2797. if (StringUtils.isNotEmpty(us.getNofixedmealsSubsidyid())) {
  2798. str.delete(0, str.length());
  2799. str.append("select * from t_bus_meals_subsidy where id = '" + us.getNofixedmealsSubsidyid() + "'");
  2800. str.insert(str.length(), st);
  2801. List<MealsSubsidyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(MealsSubsidyEntity.class).list();
  2802. // List<MealsSubsidyEntity> mealList = findListbySql(str.toString());
  2803. if (!mealList.isEmpty() && mealList.size() > 0) {
  2804. MealsSubsidyEntity meal = mealList.get(0);
  2805. uwh.setNofixedmealsSubsidyDesc(meal.getSubsidyName() + "-" + meal.getSubsidyMoney() + "元");
  2806. }
  2807. }
  2808. // 每月固定餐补
  2809. if (StringUtils.isNotEmpty(us.getFixedmealsSubsidyid())) {
  2810. str.delete(0, str.length());
  2811. str.append("select * from t_bus_meals_subsidy where id = '" + us.getFixedmealsSubsidyid() + "'");
  2812. str.insert(str.length(), st);
  2813. List<MealsSubsidyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(MealsSubsidyEntity.class).list();
  2814. // List<MealsSubsidyEntity> mealList = findListbySql(str.toString());
  2815. if (!mealList.isEmpty() && mealList.size() > 0) {
  2816. MealsSubsidyEntity meal = mealList.get(0);
  2817. uwh.setFixedmealsSubsidyDesc(meal.getSubsidyName() + "-" + meal.getSubsidyMoney() + "元");
  2818. }
  2819. }
  2820. // 加班
  2821. if (StringUtils.isNotEmpty(us.getOvertimepayStrategyid())) {
  2822. str.delete(0, str.length());
  2823. str.append("select * from t_bus_overtimepay_strategy where id = '" + us.getOvertimepayStrategyid() + "'");
  2824. str.insert(str.length(), st);
  2825. List<OvertimepayStrategyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(OvertimepayStrategyEntity.class).list();
  2826. // List<OvertimepayStrategyEntity> mealList = findListbySql(str.toString());
  2827. if (!mealList.isEmpty() && mealList.size() > 0) {
  2828. OvertimepayStrategyEntity meal = mealList.get(0);
  2829. uwh.setOvertimepayStrategyDesc(meal.getStrategyName() + "-" + meal.getMultiple() + "倍");
  2830. }
  2831. }
  2832. // 值班
  2833. if (StringUtils.isNotEmpty(us.getDutyStrategyid())) {
  2834. str.delete(0, str.length());
  2835. str.append("select * from t_bus_dutyfee_strategy where id = '" + us.getDutyStrategyid() + "'");
  2836. str.insert(str.length(), st);
  2837. List<DutyfeeStrategyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(DutyfeeStrategyEntity.class).list();
  2838. // List<DutyfeeStrategyEntity> mealList = findListbySql(str.toString());
  2839. if (!mealList.isEmpty() && mealList.size() > 0) {
  2840. DutyfeeStrategyEntity meal = mealList.get(0);
  2841. uwh.setDutyStrategyDesc(meal.getStrategyName() + "-" + meal.getMoney() + "元");
  2842. }
  2843. }
  2844. // 社保
  2845. if (StringUtils.isNotEmpty(us.getSocialSecurityStrategyid())) {
  2846. str.delete(0, str.length());
  2847. str.append("select * from t_bus_social_security_strategy where id = '" + us.getSocialSecurityStrategyid() + "'");
  2848. str.insert(str.length(), st);
  2849. List<SocialSecurityStrategyEntity> social = this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list();
  2850. // List<SocialSecurityStrategyEntity> social = findListbySql(str.toString());
  2851. if (!social.isEmpty() && social.size() > 0) {
  2852. SocialSecurityStrategyEntity meal = social.get(0);
  2853. uwh.setSocialSecurityStrategyDesc(meal.getSocialSecurityUnit());
  2854. // 保存社保各个参数
  2855. if (meal.getCompanyInjuryInsu() != null) {
  2856. uwh.setCompanyInjuryInsu(meal.getCompanyInjuryInsu());
  2857. }
  2858. if (meal.getCompanyMaternityInsu() != null) {
  2859. uwh.setCompanyMaternityInsu(meal.getCompanyMaternityInsu());
  2860. }
  2861. if (meal.getPersionalBasicMedicalInsu() != null) {
  2862. uwh.setPersionalBasicMedicalInsu(meal.getPersionalBasicMedicalInsu());
  2863. }
  2864. if (meal.getCompanyBasicRetireInsu() != null) {
  2865. uwh.setCompanyBasicRetireInsu(meal.getCompanyBasicRetireInsu());
  2866. }
  2867. if (meal.getBasePay() != null) {
  2868. uwh.setSocialSecurityBasePay(meal.getBasePay());
  2869. }
  2870. if (meal.getPersonalUnemploymentInsu() != null) {
  2871. uwh.setPersonalUnemploymentInsu(meal.getPersonalUnemploymentInsu());
  2872. }
  2873. if (meal.getCompanyBasicMedicalInsu() != null) {
  2874. uwh.setCompanyBasicMedicalInsu(meal.getCompanyBasicMedicalInsu());
  2875. }
  2876. if (meal.getCompanyUnemploymentInsu() != null) {
  2877. uwh.setCompanyUnemploymentInsu(meal.getCompanyUnemploymentInsu());
  2878. }
  2879. if (meal.getPersonalBasicRetireInsu() != null) {
  2880. uwh.setPersonalBasicRetireInsu(meal.getPersonalBasicRetireInsu());
  2881. }
  2882. }
  2883. }
  2884. // 公积金
  2885. if (StringUtils.isNotEmpty(us.getProvidentFundStrategyid())) {
  2886. str.delete(0, str.length());
  2887. str.append("select * from t_bus_provident_fund_strategy where id = '" + us.getProvidentFundStrategyid() + "'");
  2888. str.insert(str.length(), st);
  2889. List<ProvidentFundStrategyEntity> perobident = this.getSession().createSQLQuery(str.toString()).addEntity(ProvidentFundStrategyEntity.class).list();
  2890. // List<ProvidentFundStrategyEntity> perobident = findListbySql(str.toString());
  2891. if (!perobident.isEmpty() && perobident.size() > 0) {
  2892. ProvidentFundStrategyEntity meal = perobident.get(0);
  2893. uwh.setProvidentFundStrategyDesc(meal.getProvidentFundName());
  2894. // 保存公积金各个参数
  2895. if (meal.getPersonalRatio() != null) {
  2896. uwh.setPersonalRatio(meal.getPersonalRatio());
  2897. }
  2898. if (meal.getBasePay() != null) {
  2899. uwh.setProvidentFundBasePay(meal.getBasePay());
  2900. }
  2901. if (meal.getCompanyRatio() != null) {
  2902. uwh.setCompanyRatio(meal.getCompanyRatio());
  2903. }
  2904. }
  2905. }
  2906. // 追加调整
  2907. if (us.getAppendPay() != null) {
  2908. uwh.setAppendPay(us.getAppendPay());
  2909. }
  2910. // 扣除调整
  2911. if (us.getDeductPay() != null) {
  2912. uwh.setDeductPay(us.getDeductPay());
  2913. }
  2914. // 扣除调整
  2915. if (us.getDaikouFee() != null) {
  2916. uwh.setDaikouFee(us.getDaikouFee());
  2917. }
  2918. return uwh;
  2919. }
  2920. @Override
  2921. public Map<String, String> isDuties(String userid) {
  2922. return userWageMinidaoDao.isDuties(userid);
  2923. }
  2924. @Override
  2925. public void userPayrollOverride() throws Exception {
  2926. StringBuffer hql = new StringBuffer("from UserNewWagestrategyEntity");
  2927. List<UserNewWagestrategyEntity> userWagestrategyEntity = this.getSession().createQuery(hql.toString()).list();
  2928. userPayroll(userWagestrategyEntity, null, "0");
  2929. }
  2930. }