UserPayrollServiceImpl.java 135 KB

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