| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149 |
- package cn.com.lzt.userwage.service.impl;
- import java.math.BigDecimal;
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.TreeSet;
- import org.apache.commons.lang.time.DurationFormatUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.hibernate.transform.Transformers;
- import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
- import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
- import org.jeecgframework.core.constant.Globals;
- import org.jeecgframework.core.util.MyBeanUtils;
- import org.jeecgframework.core.util.oConvertUtils;
- import org.jeecgframework.minidao.pojo.MiniDaoPage;
- import org.jeecgframework.web.system.dto.TSDepartDto;
- import org.jeecgframework.web.system.pojo.base.TSUserOrgDto;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.alibaba.fastjson.JSONObject;
- import cn.com.lzt.arrangedutyoperate.entity.ArrangeDutyOperateEntity;
- import cn.com.lzt.basewagestrategy.entity.TBusBaseWagestrategyEntity;
- import cn.com.lzt.calendar.entity.CalendarEntity;
- import cn.com.lzt.certificatesubsidy.entity.CertificateSubsidyEntity;
- import cn.com.lzt.comagesubsidy.entity.ComageSubsidyEntity;
- import cn.com.lzt.duties.entity.DutiesEntity;
- import cn.com.lzt.dutyfeestrategy.entity.DutyfeeStrategyEntity;
- import cn.com.lzt.jiaojinsubsidy.entity.JiaojinSubsidyStrategyEntity;
- import cn.com.lzt.mealssubsidy.entity.MealsSubsidyEntity;
- import cn.com.lzt.megathermalsubsidy.entity.MegathermalSubsidyEntity;
- import cn.com.lzt.othersubsidy.entity.OtherSubsidyEntity;
- import cn.com.lzt.otherworksubsidy.entity.OtherworkSubsidyEntity;
- import cn.com.lzt.overtimepaystrategy.entity.OvertimepayStrategyEntity;
- import cn.com.lzt.overtimestats.dto.OvertimeDto;
- import cn.com.lzt.personnelbasearchivesmanage.dao.PersonnelBaseArchivesManageDao;
- import cn.com.lzt.personnelbasearchivesmanage.dto.PersonnelBaseArchivesManageOutDto;
- import cn.com.lzt.projectrating.dao.ProjectRatingMinidaoDao;
- import cn.com.lzt.projectrating.dto.ProjectRatingDto;
- import cn.com.lzt.providentfundstrategy.entity.ProvidentFundStrategyEntity;
- import cn.com.lzt.socialsecuritystrategy.entity.SocialSecurityStrategyEntity;
- import cn.com.lzt.talentsubsidy.dao.UserTalentSubsidyMiniDao;
- import cn.com.lzt.talentsubsidy.dto.UserTalentSubsidyDto;
- import cn.com.lzt.trafficsubsidy.entity.TrafficSubsidyEntity;
- import cn.com.lzt.useractiviti.overtime.service.TBusActivitiOvertimeServiceI;
- import cn.com.lzt.userattendancedetail.dto.AttendanceDetailJsonObj;
- import cn.com.lzt.userattendancedetail.dto.AttendanceTotalJsonObj;
- import cn.com.lzt.userattendancedetail.entity.UserAttendanceDetailEntity;
- import cn.com.lzt.userattendancedetail.service.UserAttendanceDetailServiceI;
- import cn.com.lzt.userattendancetotal.entity.UserAttendanceTotalEntity;
- import cn.com.lzt.userattendancetotal.service.UserAttendanceTotalServiceI;
- import cn.com.lzt.usercertificate.entity.UserCertificateEntity;
- import cn.com.lzt.userotherwork.entity.UserOtherworkEntity;
- import cn.com.lzt.userwage.dao.UserWageMinidaoDao;
- import cn.com.lzt.userwage.dto.YearMonthDay;
- import cn.com.lzt.userwage.entity.UserNewWageEntity;
- import cn.com.lzt.userwage.service.UserNewWagePayrollServiceI;
- import cn.com.lzt.userwage.service.UserNewWageServiceI;
- import cn.com.lzt.userwagestrategy.entity.UserNewWagestrategyEntity;
- import cn.com.lzt.userwagestrategyhistory.entity.UserWagestrategyHistoryEntity;
- import cn.com.lzt.wagestrategy.dao.WagestrategyMiniDao;
- import cn.com.lzt.wagestrategy.dto.WagestrategyDto;
- /**
- * 工资核算
- *
- * @author Administrator
- *
- */
- @Service("userNewWagePayrollService")
- @Transactional
- public class UserNewWagePayrollServiceImpl extends CommonServiceImpl implements UserNewWagePayrollServiceI {
- @Autowired
- private UserNewWageServiceI userWageServiceI;
- @Autowired
- private UserAttendanceTotalServiceI userAttendanceTotalService;
- @Autowired
- private UserAttendanceDetailServiceI userAttendanceDetailService;
- @Autowired
- private UserWageMinidaoDao userWageMinidaoDao;
- @Autowired
- private WagestrategyMiniDao wagestrategyMiniDao;
- @Autowired
- PersonnelBaseArchivesManageDao personnelBaseArchivesManageDao;
- @Autowired
- UserTalentSubsidyMiniDao userTalentSubsidyMiniDao;
- @Autowired
- private TBusActivitiOvertimeServiceI overtimeService;
-
- @Autowired
- private ProjectRatingMinidaoDao projectRationgDao;
- /**
- * type 0.定时任务 1.手动审核所有 2.手动审核部分
- *
- * @throws Exception
- */
- @Override
- public void userPayroll(List<UserNewWagestrategyEntity> userWagestrategyEntity, String moth, String type) throws Exception {
- List<UserNewWageEntity> userWageList = null;
- // List<UserWagestrategyHistoryEntity> uwhList = null;
- List<UserNewWageEntity> userWageList1 = null;
- HashMap<String, HashMap<String, Object>> hm_cache = new HashMap<>();
- userWageList = new ArrayList<UserNewWageEntity>();
- // uwhList = new ArrayList<UserWagestrategyHistoryEntity>();
- // List<UserWagestrategyHistoryEntity> uwhList1 = null;
- userWagestrategyEntity = filterRepeatUserWagestrategy(userWagestrategyEntity);
- boolean isCacheAll = true;
- if (!"0".equals(type)) {
- if ("1".equals(type)) {
- StringBuffer hql = new StringBuffer("from UserNewWageEntity where monthly = :monthly");
- userWageList1 = this.getSession().createQuery(hql.toString()).setParameter("monthly", moth).list();
- } else {
- List<String> userid = new ArrayList<String>();
- for (UserNewWagestrategyEntity userWages : userWagestrategyEntity) {
- userid.add(userWages.getUserid());
- }
- StringBuffer hql = new StringBuffer("from UserNewWageEntity where userid in (:userid) and monthly = :monthly");
- userWageList1 = this.getSession().createQuery(hql.toString()).setParameterList("userid", userid).setParameter("monthly", moth).list();
- isCacheAll = false; // 个人核算不用缓存
- }
- } else {
- moth = getMonthlys(); // getMonthlys();//"2017-09";//"2017-10"; //
- StringBuffer hql = new StringBuffer("from UserNewWageEntity where monthly = :monthly");
- userWageList1 = this.getSession().createQuery(hql.toString()).setParameter("monthly", moth).list();
- }
- UserNewWageEntity uw = null;
- UserWagestrategyHistoryEntity uwh = null;
- StringBuffer hql = new StringBuffer("from MealsSubsidyEntity where deleteFlag = 0 and status = 0");
- List<MealsSubsidyEntity> meslList = this.getSession().createQuery(hql.toString()).list();
- for (UserNewWagestrategyEntity us : userWagestrategyEntity) {
- PersonnelBaseArchivesManageOutDto per = getPersonnelDto(hm_cache, isCacheAll, us);
- if (isValidWagePerson(per, moth)) {
-
- uwh = initUserWagestrategyHistoryEntity(moth, us);
- uw = initUserNewWagestrategyEntity(moth, hm_cache, us);
-
- UserAttendanceTotalEntity uat = getUserAttendanceTotalEntity(moth, hm_cache, isCacheAll, us);
- if (isCompleteMonthWage(us, per)) {
- uw = calcCompleteMonthWage(moth, hm_cache, isCacheAll, uw, meslList, us, per, uat);
- } else {
- uw = calEntryOrLeaveWage(isCacheAll, hm_cache, uw, us, uat, moth, per, meslList);
- }
- if (uw.getActualMoney() != null && uw.getActualMoney().intValue() < 0) {
- uw.setActualMoney(BigDecimal.ZERO);
- }
- // 记录月度员工工资策略历史记录表
- userWageList.add(uw);
- // uwhList.add(historyUW(uwh, us));
- }
- }
- if (!"0".equals(type)) {
- // if (!uwhList1.isEmpty()) {
- // for (UserWagestrategyHistoryEntity u : uwhList) {
- // boolean temp = true;
- // for (UserWagestrategyHistoryEntity userWage1 : uwhList1) {
- // if (u.getUserid().equals(userWage1.getUserid())) {
- // MyBeanUtils.copyBeanNotNull2Bean(u, userWage1);
- // saveOrUpdate(userWage1);
- // temp = false;
- // }
- // }
- //
- // if (temp) {
- // saveOrUpdate(u);
- // }
- // }
- // } else {
- // this.batchSave(uwhList);
- // }
- if (!userWageList1.isEmpty()) {
- for (UserNewWageEntity uge : userWageList) {
- boolean temp = true;
- for (UserNewWageEntity uwEntity : userWageList1) {
- if (uge.getUserid().equals(uwEntity.getUserid())) {
- // 重新核算后留下已调整的部分
- refillAdjustedAttributes(uge, uwEntity);
- saveOrUpdate(uwEntity);
- temp = false;
- }
- }
- if (temp) {
- saveOrUpdate(uge);
- }
- }
- } else {
- this.batchSave(userWageList);
- }
- } else {
- deleteAllEntitie(userWageList1);
- //deleteAllEntitie(uwhList1);
- this.batchSave(userWageList);
- // this.batchSave(uwhList);
- }
- hm_cache.clear();
- }
- private UserAttendanceTotalEntity getUserAttendanceTotalEntity(String moth, HashMap<String, HashMap<String, Object>> hm_cache, boolean isCacheAll, UserNewWagestrategyEntity us) {
- List<UserAttendanceTotalEntity> uatList = getUserAttendanceTotalEntityList(moth, hm_cache, isCacheAll, us);
- UserAttendanceTotalEntity uat = null;
- if (uatList == null || uatList.isEmpty()) {
- uat = new UserAttendanceTotalEntity();
- } else {
- uat = uatList.get(0);
- }
- return uat;
- }
- private UserNewWageEntity initUserNewWagestrategyEntity(String moth, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us) {
- UserNewWageEntity uw;
- uw = new UserNewWageEntity();
- uw.setUserid(us.getUserid());
- uw.setBelongUnitid(us.getBelongUnitid());
- // 存入项目(或部门)id
- uw.setPjtId(getBybelongId(hm_cache, us.getUserid()));
- // 保存上个月度
- uw.setMonthly(moth);
- return uw;
- }
- private UserWagestrategyHistoryEntity initUserWagestrategyHistoryEntity(String moth, UserNewWagestrategyEntity us) {
- UserWagestrategyHistoryEntity uwh;
- uwh = new UserWagestrategyHistoryEntity();
- uwh.setBelongUnitid(us.getBelongUnitid());
- uwh.setUserid(us.getUserid());
- uwh.setStrategyMonth(moth);
- return uwh;
- }
- private void refillAdjustedAttributes(UserNewWageEntity uge, UserNewWageEntity uwEntity) throws Exception {
- BigDecimal bufa = uwEntity.getReissue();
- BigDecimal jiangjin = uwEntity.getBonus();
- BigDecimal otherKouchu = uwEntity.getOtherDebit();
- BigDecimal gaowen = uwEntity.getMegathermalSubsidy();
- BigDecimal jiaojinbutie = uwEntity.getPaymentSubsidy();
- String descrip = uwEntity.getRemark();
- String status = uwEntity.getStatus();
- MyBeanUtils.copyBeanNotNull2Bean(uge, uwEntity);
- uwEntity.setStatus(status);
- uwEntity.setReissue(bufa);
- uwEntity.setBonus(jiangjin);
- uwEntity.setOtherDebit(otherKouchu);
- uwEntity.setRemark(descrip);
- uwEntity.setMegathermalSubsidy(gaowen);
- uwEntity.setPaymentSubsidy(jiaojinbutie);
- // 手动核算的时候需要重新计算实发工资
- uwEntity.recalculatePreTaxMoney();
- uwEntity.recalculateActualMoney();
- uwEntity.recalculateComCost();
- }
- private UserNewWageEntity calcCompleteMonthWage(String moth, HashMap<String, HashMap<String, Object>> hm_cache, boolean isCacheAll, UserNewWageEntity uw, List<MealsSubsidyEntity> meslList, UserNewWagestrategyEntity us,
- PersonnelBaseArchivesManageOutDto per, UserAttendanceTotalEntity uat) throws ParseException {
- // 查询基本工资
- uw = basicWagePartCalculation(isCacheAll, hm_cache, us, uw, per);
- // 人才津贴计算
- uw = talentCalculation(isCacheAll, hm_cache, us, uw, per);
- // 司龄津贴计算
- uw = comyearCalculation(hm_cache, us, uw, per);
- // 其它工作补贴
- uw = otherworkCalculation(isCacheAll, hm_cache, us, uw, per);
- //项目监管绩效和项目现场绩效
- uw = projectAllowanceCalculation(isCacheAll, hm_cache, us, uw, per);
- // 查询所有设定策略信息
- uw = selectStrategy(isCacheAll, hm_cache, us, uw, per);
- // 餐费补助
- uw = mealsCalculation(isCacheAll, hm_cache, uat, us, uw, meslList);
-
- // 工资扣除项
- uw = deductionCalculation(uat, us, uw, per, true);
- // 公积金和社保
- uw = socialSecurityProvidentFund(isCacheAll, hm_cache, uat, us, uw, per);
- // 加班费
- uw = overtimeCalculation(isCacheAll, hm_cache, uat, us, uw, moth, per);
- uw.setStatus(Globals.ARRANGESTATUS_0.toString());
- uw.setTaxMoney(new BigDecimal(0));
- if (us.getDeductPay() != null && us.getDeductPay().doubleValue() > 0) {
- uw.setOtherDebit(us.getDeductPay());
- }
- // 代扣款
- if (us.getDaikouFee() != null && us.getDaikouFee().doubleValue() > 0) {
- uw.setDaikouDebit(us.getDaikouFee());
- }
- if (uw.getOtherDebit() == null) {
- uw.setOtherDebit(BigDecimal.ZERO);
- }
- if (uw.getDaikouDebit() == null) {
- uw.setDaikouDebit(BigDecimal.ZERO);
- }
- if (uw.getBonus() == null) {
- uw.setBonus(BigDecimal.ZERO);
- }
- if (uw.getFakuan() == null) {
- uw.setFakuan(BigDecimal.ZERO);
- }
- uw.recalculatePreTaxMoney();
- uw.recalculateActualMoney();
- uw.recalculateComCost();
- uw.setReissue(new BigDecimal(0));
- // 判断该员工当月是否被调动过
- if ("1".equals(uat.getIfmoved())) {
- List<UserAttendanceDetailEntity> uadeList = this.getSession().createSQLQuery("select * from t_bus_user_attendance_detail where attendance_id = '" + uat.getId() + "' and borrowspid = 1")
- .addEntity(UserAttendanceDetailEntity.class).list();
- if (!uadeList.isEmpty() && uadeList.size() > 0) {
- for (UserAttendanceDetailEntity u : uadeList) {
- uw.setReissue(uw.getReissue().add(u.getDayPay()));
- }
- }
- }
- return uw;
- }
- /**
- * @param isCacheAll
- * @param hm_cache
- * @param us
- * @param uw
- * @param per
- * @return
- */
- private UserNewWageEntity otherworkCalculation(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
- BigDecimal otherworksub = getOtherworkSubsidyMoneyWithCache(hm_cache, per.getUserId());
- if(otherworksub != null) {
- uw.setOtherworkSubsidy(otherworksub);
- }else {
- uw.setOtherworkSubsidy(BigDecimal.ZERO);
- }
- return uw;
- }
-
- /**
- * 计算项目工资和月度奖金,都按照比例分
- * @param isCacheAll
- * @param hm_cache
- * @param us
- * @param uw
- * @param per
- * @return
- */
- private UserNewWageEntity projectAllowanceCalculation(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
- String userid = us.getUserid();
- String years = uw.getMonthly().split("-")[0];
- HashSet<ProjectRatingDto> projectratingdtoList = getProjectRatingDtosWithCache(hm_cache, years, userid);
- BigDecimal jianguanValue = BigDecimal.ZERO;
- BigDecimal xianchangValue = BigDecimal.ZERO;
- BigDecimal projactPerform = BigDecimal.ZERO;
- uw.setJianguanBonus(jianguanValue);
- uw.setXianchangBonus(xianchangValue);
- uw.setProjectPerformance(projactPerform);
- if(projectratingdtoList != null) {
- for(ProjectRatingDto pdto : projectratingdtoList) {
- BigDecimal jianguanweight = pdto.getJianguanWeight();
- if(jianguanweight == null) {
- jianguanweight = BigDecimal.ZERO;
- }
- double jiaguanRate = jianguanweight.doubleValue()/100;
- BigDecimal projectwage = pdto.getProjectWage();
- BigDecimal bonus = pdto.getBonus();
- if(projectwage == null) {
- projectwage = BigDecimal.ZERO;
- }
-
- if(bonus == null) {
- bonus = BigDecimal.ZERO;
- }
- if(userid.equals(pdto.getJianguanLeader())) {
- jianguanValue = jianguanValue.add(projectwage.multiply(new BigDecimal(jiaguanRate)).setScale(2, BigDecimal.ROUND_HALF_UP));
- projactPerform = projactPerform.add(bonus.multiply(new BigDecimal(jiaguanRate)).setScale(2, BigDecimal.ROUND_HALF_UP));
-
- }
- if(userid.equals(pdto.getXianchangLeader())) {
- if(org.apache.commons.lang.StringUtils.isNotEmpty(pdto.getJianguanLeader())){
- xianchangValue = xianchangValue.add(projectwage.multiply(new BigDecimal(1-jiaguanRate)).setScale(2, BigDecimal.ROUND_HALF_UP));
- projactPerform = projactPerform.add(bonus.multiply(new BigDecimal(1-jiaguanRate)).setScale(2, BigDecimal.ROUND_HALF_UP));
-
- }else {
- // 没有兼管经理,拿100%绩效
- xianchangValue = xianchangValue.add(projectwage.multiply(new BigDecimal(1.0)).setScale(2, BigDecimal.ROUND_HALF_UP));
- projactPerform = projactPerform.add(bonus.multiply(new BigDecimal(1.0)).setScale(2, BigDecimal.ROUND_HALF_UP));
- }
- }
- }
- uw.setJianguanBonus(jianguanValue);
- uw.setXianchangBonus(xianchangValue);
- uw.setProjectPerformance(projactPerform);
- }
- return uw;
- }
-
- private HashSet<ProjectRatingDto> getProjectRatingDtosWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String years, String userid) {
- HashMap<String, Object> hm = hm_cache.get("getProjectAllowanceWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getProjectAllowanceWithCache", hm);
- MiniDaoPage<ProjectRatingDto> entitiesPrjMiniDaoPage = projectRationgDao.getAllEntitiesNopage(years);
- for(ProjectRatingDto pj : entitiesPrjMiniDaoPage.getResults()) {
- if(pj.getJianguanLeader() != null) {
- if(hm.containsKey(pj.getJianguanLeader())){
- HashSet<ProjectRatingDto> list = (HashSet<ProjectRatingDto>)hm.get(pj.getJianguanLeader());
- list.add(pj);
- }else {
- HashSet<ProjectRatingDto> list = new HashSet<>();
- list.add(pj);
- hm.put(pj.getJianguanLeader(), list);
- }
-
- }
- if(pj.getXianchangLeader() != null) {
- if(hm.containsKey(pj.getXianchangLeader())){
- HashSet<ProjectRatingDto> list = (HashSet<ProjectRatingDto>)hm.get(pj.getXianchangLeader());
- list.add(pj);
- }else {
- HashSet<ProjectRatingDto> list = new HashSet<>();
- list.add(pj);
- hm.put(pj.getXianchangLeader(), list);
- }
- }
- }
-
- }
- return (HashSet<ProjectRatingDto>) hm.get(userid);
- }
- /**
- * @param hm_cache
- * @param userid
- * @return
- */
- private BigDecimal getOtherworkSubsidyMoneyWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
- HashMap<String, Object> hm = hm_cache.get("getOtherworkSubsidyMoneyWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getOtherworkSubsidyMoneyWithCache", hm);
- StringBuffer str_user_otherwork = new StringBuffer();
- str_user_otherwork.append("select * from t_bus_user_otherwork where delete_flag = 0");
- List<UserOtherworkEntity> entitiesUserOtherworkEntity = this.getSession().createSQLQuery(str_user_otherwork.toString())
- .addEntity(UserOtherworkEntity.class).list();
- String str_subsidy = "select * from t_bus_otherwork_subsidy where delete_flag = 0 and status=0";
- List<OtherworkSubsidyEntity> subList = this.getSession().createSQLQuery(str_subsidy).addEntity(OtherworkSubsidyEntity.class).list();
- HashMap<String, OtherworkSubsidyEntity> subMap = new HashMap<>();
- for (OtherworkSubsidyEntity sub : subList) {
- subMap.put(sub.getId(), sub);
- }
- for (UserOtherworkEntity user_otherwork_Entity : entitiesUserOtherworkEntity) {
- String userInEntity = user_otherwork_Entity.getUserid();
- String OtherworkSubInEntity = user_otherwork_Entity.getOtherworkSubsidy();
- OtherworkSubsidyEntity subEntity = subMap.get(OtherworkSubInEntity);
- BigDecimal subMoney = BigDecimal.ZERO;
- if (subEntity != null && subEntity.getMoney() != null) {
- subMoney = subEntity.getMoney();
- }
- if (hm.containsKey(userInEntity)) {
- BigDecimal old = BigDecimal.ZERO;
- if ((BigDecimal) hm.get(userInEntity) != null) {
- old = (BigDecimal) hm.get(userInEntity);
- }
- hm.put(userInEntity, subMoney.add(old));
- } else {
- if (subMoney == null) {
- subMoney = BigDecimal.ZERO;
- }
- hm.put(userInEntity, subMoney);
- }
- }
- }
- return (BigDecimal) hm.get(userid);
- }
-
-
- /**
- * 司龄计算
- * @param hm_cache
- * @param us
- * @param uw
- * @param per
- * @return
- */
- private UserNewWageEntity comyearCalculation(HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
- int comage = getComAge(per);
- ComageSubsidyEntity comageSub = getComageSubsidyEntityWithCache(hm_cache);
- BigDecimal comsub = BigDecimal.ZERO;
- uw.setComyearAllowance(comsub);
- if(comage >= comageSub.getMinYears()) {
- comsub=comsub.add(comageSub.getMin());
- comsub=comsub.add(comageSub.getIncrease().multiply(new BigDecimal(comage).subtract(new BigDecimal(comageSub.getMinYears()))));
- if(comsub.compareTo(comageSub.getMax()) < 0) {
- uw.setComyearAllowance(comsub);
- }else {
- uw.setComyearAllowance(comageSub.getMax());
- }
-
- }
- return uw;
- }
- /**
- * @param hm_cache
- * @return
- */
- private ComageSubsidyEntity getComageSubsidyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache) {
- HashMap<String, Object> hm = hm_cache.get("getComageSubsidyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getComageSubsidyEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(ComageSubsidyEntity.class);
- List<ComageSubsidyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- hm.put("ALL", entitiesFromDB.get(0));
- }
-
- return (ComageSubsidyEntity)hm.get("ALL");
- }
- /**
- * @param per
- * @return
- */
- private int getComAge(PersonnelBaseArchivesManageOutDto per) {
- if(per != null && per.getContractStime() != null) {
- Calendar contractStime = Calendar.getInstance();
- Calendar endtime = Calendar.getInstance();
- contractStime.setTime(per.getContractStime());
- endtime.setTime(new Date());
- endtime.set(Calendar.DAY_OF_MONTH, 1); //截至当月1日,如果是上个月最后一天之前入职,则可算出满n年
- String y = DurationFormatUtils.formatPeriod(contractStime.getTime().getTime(), endtime.getTime().getTime(), "y");
- return Integer.parseInt(y);
- }
- return 0;
- }
- /**
- * @param isCacheAll
- * @param hm_cache
- * @param us
- * @param uw
- * @param per
- * @return
- */
- private UserNewWageEntity talentCalculation(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
- BigDecimal talentAll = BigDecimal.ZERO;
- // 初始是0
- uw.setTalentAllowance(talentAll);
- List<UserTalentSubsidyDto> talentDtos = getUserTalentSubsidyDtosWithCache(isCacheAll, hm_cache, us, uw, per);
- if(talentDtos != null && talentDtos.size()>0) {
- for(UserTalentSubsidyDto dto : talentDtos) {
- if(dto.getMoney() != null) {
- talentAll = talentAll.add(dto.getMoney());
- }
- }
- uw.setTalentAllowance(talentAll);
- }
-
- return uw;
- }
- /**
- * @param isCacheAll
- * @param hm_cache
- * @param us
- * @param uw
- * @param per
- * @return
- */
- private List<UserTalentSubsidyDto> getUserTalentSubsidyDtosWithCache(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw,
- PersonnelBaseArchivesManageOutDto per) {
- HashMap<String, Object> hm = hm_cache.get("getUserTalentSubsidyDtosWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getUserTalentSubsidyDtosWithCache", hm);
- List<UserTalentSubsidyDto> entitiesFromDB = userTalentSubsidyMiniDao.getAllEntities(isCacheAll?null:per.getUserId()).getResults();
- for (UserTalentSubsidyDto entity : entitiesFromDB) {
- String userInEntity = entity.getUserid();
- if (hm.containsKey(userInEntity)) {
- List<UserTalentSubsidyDto> entitylist = (List<UserTalentSubsidyDto>) hm.get(userInEntity);
- entitylist.add(entity);
- } else {
- List<UserTalentSubsidyDto> newlist = new ArrayList<>();
- newlist.add(entity);
- hm.put(userInEntity, newlist);
- }
- }
- }
- List<UserTalentSubsidyDto> dtoInDB = (List<UserTalentSubsidyDto>) hm.get(per.getUserId());
- // 把人员信息里的教育背景关联上,暂时先不关联。
- joinEducationInfo(dtoInDB);
- return dtoInDB;
- }
- /**
- * @param dtoInDB
- */
- private void joinEducationInfo(List<UserTalentSubsidyDto> dtoInDB) {
-
- }
- private List<UserAttendanceTotalEntity> getUserAttendanceTotalEntityList(String moth, HashMap<String, HashMap<String, Object>> hm_cache, boolean isCacheUsed, UserNewWagestrategyEntity us) {
- List<UserAttendanceTotalEntity> uatList = null;
- if (isCacheUsed) {
- uatList = getUserAttendanceTotalEntityWithCache(hm_cache, us.getUserid(), moth);
- } else {
- uatList = userAttendanceTotalService.getByuserid(us.getUserid(), moth);
- }
- return uatList;
- }
- private PersonnelBaseArchivesManageOutDto getPersonnelDto(HashMap<String, HashMap<String, Object>> hm_cache, boolean isCacheUsed, UserNewWagestrategyEntity us) {
- PersonnelBaseArchivesManageOutDto per = null;
- if (isCacheUsed) {
- per = getPersonnelBaseArchivesManageEntityWithCache(hm_cache, us.getUserid());
- } else {
- MiniDaoPage<PersonnelBaseArchivesManageOutDto> minPage = personnelBaseArchivesManageDao.getEntityByUserId(us.getUserid());
- per = minPage.getResults().get(0);
- }
- return per;
- }
- /**
- * 去重
- *
- * @param userWagestrategyEntity
- * @return
- */
- private List<UserNewWagestrategyEntity> filterRepeatUserWagestrategy(List<UserNewWagestrategyEntity> userWagestrategyEntity) {
- HashMap<String, UserNewWagestrategyEntity> hm_userid = new HashMap<>();
- if (userWagestrategyEntity != null) {
- for (UserNewWagestrategyEntity entity : userWagestrategyEntity) {
- hm_userid.put(entity.getUserid(), entity);
- }
- }
- return new ArrayList<UserNewWagestrategyEntity>(hm_userid.values());
- }
- /**
- * @param userid
- * @param moth
- * @return
- */
- private List<UserAttendanceTotalEntity> getUserAttendanceTotalEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid, String moth) {
- HashMap<String, Object> hm = hm_cache.get("getUserAttendanceTotalEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getUserAttendanceTotalEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(UserAttendanceTotalEntity.class);
- specialcq.eq("yearmonth", moth);
- specialcq.add();
- List<UserAttendanceTotalEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (UserAttendanceTotalEntity entity : entitiesFromDB) {
- String userInEntity = entity.getUserId();
- if (hm.containsKey(userInEntity)) {
- List<UserAttendanceTotalEntity> entitylist = (List<UserAttendanceTotalEntity>) hm.get(userInEntity);
- entitylist.add(entity);
- } else {
- List<UserAttendanceTotalEntity> newlist = new ArrayList<>();
- newlist.add(entity);
- hm.put(userInEntity, newlist);
- }
- }
- }
- return (List<UserAttendanceTotalEntity>) hm.get(userid);
- }
- /**
- * @param hm_cache
- * @param userid
- * @return
- */
- private PersonnelBaseArchivesManageOutDto getPersonnelBaseArchivesManageEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
- HashMap<String, Object> hm = hm_cache.get("getPersonnelBaseArchivesManageEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getPersonnelBaseArchivesManageEntityWithCache", hm);
- MiniDaoPage<PersonnelBaseArchivesManageOutDto> minPage = personnelBaseArchivesManageDao.getAllEntities();
- List<PersonnelBaseArchivesManageOutDto> entitiesFromDB = minPage.getResults();
- for (PersonnelBaseArchivesManageOutDto entity : entitiesFromDB) {
- hm.put(entity.getUserId(), entity);
- }
- }
- return (PersonnelBaseArchivesManageOutDto) hm.get(userid);
- }
- /**
- * 判断当前人是否应该计算工资
- *
- * @param per
- * @param moth
- * @return
- * @throws ParseException
- */
- private boolean isValidWagePerson(PersonnelBaseArchivesManageOutDto per, String moth) throws ParseException {
- if (per == null) {
- return false;
- }
- if (Globals.JOBSTATUS_0.equals(per.getPositionStatus())) {
- return false;
- }
- // if("0000000061459498016145f3f01407cd".equals(per.getUserid())) {
- // System.out.println("0000000061459498016145f3f01407cd");
- // }
- String moth1 = "";
- String[] mothArray = moth.split("-");
- moth1 = mothArray[0] + "-" + "0" + (Integer.valueOf(mothArray[1])) + "-01 00:00:00";
- Date leaveDate = per.getLeaveDate();
- DateFormat df_leave_limit = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Calendar Cal_leave_limit = Calendar.getInstance();
- Cal_leave_limit.setTime(df_leave_limit.parse(moth1));
- if (leaveDate != null && leaveDate.getTime() <= Cal_leave_limit.getTimeInMillis()) {
- // 如果离职时间点早于或等于工资结算月1号,不算入工资表中 zy20180420
- return false;
- }
- // //合同开始时间是否在工资计算之内
- Date contractStime = per.getContractStime();
- // 下个月起始,在这个节点之后入职的,不计入工资表
- Calendar cal_contract_limit = Calendar.getInstance();
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- cal_contract_limit.setTime(df.parse(moth1));
- cal_contract_limit.add(Calendar.MONTH, 1);
- if (contractStime == null || contractStime.getTime() >= cal_contract_limit.getTimeInMillis()) {
- return false;
- }
- return true;
- }
- /**
- * 通过人查询所属项目
- *
- * @param hm_cache
- * @param userid
- * @return
- */
- private String getBybelongId(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
- String temp = "";
- TSUserOrgDto uo = getTSUserOrgWithCache(hm_cache, userid);
- TSDepartDto tsDepart = getTSDepartWithCache(hm_cache, uo.getOrg_id());
- TSDepartDto parentDepartDto = getTSDepartWithCache(hm_cache, tsDepart.getParentdepartid());
- if ("1".equals(tsDepart.getOrg_type()) || "3".equals(tsDepart.getOrg_type()) || "4".equals(tsDepart.getOrg_type()) || "5".equals(tsDepart.getOrg_type())) {
- temp = tsDepart.getId();
- } else if ("2".equals(tsDepart.getOrg_type()) && "1".equals(parentDepartDto.getOrg_type())) {
- temp = tsDepart.getId();
- } else {
- temp = selectById(hm_cache, tsDepart.getId());
- }
- return temp;
- }
- /**
- * @param hm_cache
- * @param userid
- * @return
- */
- private TSUserOrgDto getTSUserOrgWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
- HashMap<String, Object> hm = hm_cache.get("getTSUserOrgWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getTSUserOrgWithCache", hm);
- List<TSUserOrgDto> entitiesFromDB = this.getSession().createSQLQuery("select * from t_s_user_org where ifpluralism = 0 and status=0").addScalar("id").addScalar("user_id").addScalar("org_id")
- .addScalar("ifpluralism").setResultTransformer(Transformers.aliasToBean(TSUserOrgDto.class)).list();
- for (TSUserOrgDto entity : entitiesFromDB) {
- hm.put(entity.getUser_id(), entity);
- }
- }
- return (TSUserOrgDto) hm.get(userid);
- }
- /**
- * @param hm_cache
- * @param userid
- * @return
- */
- private TSDepartDto getTSDepartWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String departid) {
- HashMap<String, Object> hm = hm_cache.get("getTSDepartWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getTSDepartWithCache", hm);
- List<TSDepartDto> entitiesFromDB = this.getSession().createSQLQuery("select * from t_s_depart where status=0").addScalar("id").addScalar("parentdepartid").addScalar("org_type").addScalar("departname")
- .setResultTransformer(Transformers.aliasToBean(TSDepartDto.class)).list();
- for (TSDepartDto entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (TSDepartDto) hm.get(departid);
- }
- private String selectById(HashMap<String, HashMap<String, Object>> hm_cache, String id) {
- String temp = "";
- TSDepartDto tsDepart = getTSDepartWithCache(hm_cache, id);
- if ("3".equals(tsDepart.getOrg_type()) || "5".equals(tsDepart.getOrg_type())) {
- temp = tsDepart.getId();
- } else {
- if (tsDepart.getParentdepartid() != null) {
- selectById(hm_cache, tsDepart.getParentdepartid());
- temp = tsDepart.getParentdepartid();
- }
- }
- return temp;
- }
- /**
- * 获得stime日期距离当月第一天的天数
- *
- * @param stime
- * 减数
- * @return
- * @throws ParseException
- */
- private static int dateDiff1(Date stime) throws ParseException {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- cal.setTime(format.parse(format.format(stime)));
- // 得到上个月的第一天
- Calendar cal_1 = Calendar.getInstance();// 获取当前日期
- cal_1.add(Calendar.MONTH, -1);
- cal_1.set(Calendar.DAY_OF_MONTH, 1);
- // return DateUtils.dateDiff('d', cal, cal_1);
- return daysBetween(format.parse(format.format(cal_1.getTime())), cal.getTime()) - 1;
- }
- /**
- * 相差的天数
- *
- * @param date1
- * 开始时间
- * @param date2
- * 结束时间
- * @return
- */
- public static int daysBetween(Date date1, Date date2) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(date1);
- long time1 = cal.getTimeInMillis();
- cal.setTime(date2);
- long time2 = cal.getTimeInMillis();
- long between_days = (time2 - time1) / (1000 * 3600 * 24);
- return Integer.parseInt(String.valueOf(between_days)) + 1;
- }
- public static void main(String[] args) throws ParseException {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- System.out.println(dateDiff1(sdf.parse("2017-12-10")));
- }
- /**
- * 获取某月的天数
- *
- * @param date
- * @return
- * @throws ParseException
- */
- private static int getDaysOfMonth(String date) throws ParseException {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(format.parse(date));
- return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
- }
- /**
- * 获得stime日期距离当月最后一天的天数
- *
- * @param stime
- * 减数
- * @return
- * @throws ParseException
- */
- private static int dateDiff2(Date stime, Date etime) throws ParseException {
- Calendar cal_1 = Calendar.getInstance();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- cal_1.setTime(format.parse(format.format(stime)));
- Calendar cale = Calendar.getInstance();
- if (etime != null) {
- cale.setTime(format.parse(format.format(etime)));
- } else {
- cale.set(Calendar.DAY_OF_MONTH, 0);// 设置为1号,当前日期既为本月第一天
- }
- // return DateUtils.dateDiff('d', cale, cal_1);
- return daysBetween(cal_1.getTime(), format.parse(format.format(cale.getTime())));
- }
- @SuppressWarnings("unchecked")
- private int dateDiff3(Date stime, Date etime) throws ParseException {
- int temp = 0;
- if (stime == null) {
- Calendar calendar = Calendar.getInstance();
- calendar.add(Calendar.MONTH, -1);
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- stime = calendar.getTime();
- }
- if (etime == null) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- calendar.add(Calendar.DATE, -1);
- etime = calendar.getTime();
- }
- StringBuffer str = new StringBuffer();
- str.append("select * from t_bus_calendar where ymd_date >= '" + stime + "' and ymd_date <= '" + etime + "' and dtype != 2");
- List<CalendarEntity> usList = this.getSession().createSQLQuery(str.toString()).addEntity(CalendarEntity.class).list();
- if (!usList.isEmpty()) {
- temp = usList.size();
- }
- return temp;
- }
- /**
- * 核算入职或离职当月的工资 在职天数:是除了星期六日外的工作日,不考虑节假日 在12月2日确定 得到入职时间的年月和上个月的年月,进行比较,是否是上个月入职
- * 如果不相等,说明非上个月入职,工资按照基本工资的80%进行计算
- * 如果相等,说明是上个月入职,则(基本工资+所有的补贴)/(21.75*8)*实际考勤时长,并且需单独计算工资
- *
- * @param hm_cache
- * @param uw
- * @param us
- * @param uat
- * @param meslList
- * 所有餐补
- * @return
- * @throws ParseException
- */
- private UserNewWageEntity calEntryOrLeaveWage(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, UserAttendanceTotalEntity uat, String month,
- PersonnelBaseArchivesManageOutDto per, List<MealsSubsidyEntity> meslList) throws ParseException {
-
- entryOrLeavePartlyWageCalculation(isCacheUsed, hm_cache, uw, us, uat, per);
-
- // 司龄津贴计算
- uw = comyearCalculation(hm_cache, us, uw, per);
- // 查询基本策略设定值
- uw = selectStrategy(isCacheUsed, hm_cache, us, uw, per);
- // 加班费计算
- uw = overtimeCalculation(isCacheUsed, hm_cache, uat, us, uw, month, per);
- // 餐补
- uw = mealsCalculation(isCacheUsed, hm_cache, uat, us, uw, meslList);
- // 缺勤病假扣事假扣
- uw = deductionCalculation(uat, us, uw, per, false);
- // 公积金和社保计算
- uw.setSocialSecurityDebit(new BigDecimal(0));
- uw.setComSocialSecurityDebit(BigDecimal.ZERO);
- uw.setProvidentFundDebit(new BigDecimal(0));
- uw.setComProvidentFundDebit(BigDecimal.ZERO);
- uw.setPaymentSubsidy(new BigDecimal(0));
- if (per.getLeaveDate() != null) {
- if (!equals(per.getContractStime(), per.getLeaveDate())) {
- Calendar calendar1 = Calendar.getInstance();
- calendar1.setTime(per.getLeaveDate());
- int month1 = calendar1.get(Calendar.DAY_OF_MONTH);
- if (month1 > 15) {
- uw = aloneCalculation(isCacheUsed, hm_cache, uw, us, per);
- }
- }
- } else {
- Calendar calendar1 = Calendar.getInstance();
- calendar1.setTime(per.getContractStime());
- int month1 = calendar1.get(Calendar.DAY_OF_MONTH);
- if (month1 < 16) {
- uw = aloneCalculation(isCacheUsed, hm_cache, uw, us, per);
- }
- }
- uw.setStatus(Globals.ARRANGESTATUS_0.toString());
- uw.setTaxMoney(new BigDecimal(0));
- if (us.getDeductPay() != null && us.getDeductPay().intValue() > 0) {
- uw.setOtherDebit(new BigDecimal(us.getDeductPay().toString()));
- }
- // 代扣款
- if (us.getDaikouFee() != null && us.getDaikouFee().doubleValue() > 0) {
- uw.setDaikouDebit(us.getDaikouFee());
- }
- if (uw.getOtherDebit() == null) {
- uw.setOtherDebit(BigDecimal.ZERO);
- }
- if (uw.getDaikouDebit() == null) {
- uw.setDaikouDebit(BigDecimal.ZERO);
- }
- if (uw.getBonus() == null) {
- uw.setBonus(BigDecimal.ZERO);
- }
- uw.recalculatePreTaxMoney();
- uw.recalculateActualMoney();
- uw.recalculateComCost();
- uw.setReissue(new BigDecimal(0));
- return uw;
- }
- private void entryOrLeavePartlyWageCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, UserAttendanceTotalEntity uat,
- PersonnelBaseArchivesManageOutDto per) throws ParseException {
- // 实际出勤时长
- BigDecimal shichang = new BigDecimal(0);
- if (uat.getActualAttendanceDate() != null) {
- shichang = uat.getActualAttendanceDate().divide(new BigDecimal(60), 3, BigDecimal.ROUND_HALF_UP);
- }
- //初始化
- uw.setBasicWage(new BigDecimal(0));
- uw.setDutiesAllowance(new BigDecimal(0));
- uw.setPostAllowance(new BigDecimal(0));
- uw.setDutieslevelAllowance(new BigDecimal(0));
- uw.setTalentAllowance(new BigDecimal(0));
- uw.setOtherworkSubsidy(new BigDecimal(0));
- uw.setJianguanBonus(new BigDecimal(0));
- uw.setXianchangBonus(new BigDecimal(0));
- uw.setProjectPerformance(new BigDecimal(0));
-
- if(shichang.compareTo(BigDecimal.ZERO) > 0) {
- // 查询基本工资
- uw = basicWagePartCalculation(isCacheUsed, hm_cache, us, uw, per);
- // 人才津贴计算
- uw = talentCalculation(isCacheUsed, hm_cache, us, uw, per);
- // 其它工作补贴
- uw = otherworkCalculation(isCacheUsed, hm_cache, us, uw, per);
- //项目监管绩效和项目现场绩效
- uw = projectAllowanceCalculation(isCacheUsed, hm_cache, us, uw, per);
- }
- // 基本工资和职务津贴
- if (StringUtils.isNotEmpty(us.getDutiesid())) {
- WagestrategyDto wa = getWagestrategyDto(isCacheUsed, hm_cache, per);
- BigDecimal basicWage = getBasicWage(isCacheUsed, hm_cache, per, us,wa);
- // 需要区分是管理层还是一线员工
- if (wa != null) {
- // 判断是管理层还是一线员工
- if (Globals.MANAGETYPE_2.toString().equals(per.getManagerType())) {
- calCommonEmployeeNotMonthlyWage(uw, shichang);
- } else {
- // 管理层:基本工资 = 基本工资/(21.75)*在职天数*80%
- if (per.getLeaveDate() != null) {
- calLeavedManagePersonWage(uw, per, basicWage);
- } else {
- calEntryManagePersonWage(uw, per, wa, basicWage);
- }
- }
- uw.setDutiesAllowance(wa.getSubsidy());
- }
- }
- }
- /**
- * 一线员工未达满月工资计算
- * @param uw
- * @param shichang
- */
- private void calCommonEmployeeNotMonthlyWage(UserNewWageEntity uw, BigDecimal shichang) {
- // 一线员工:基本工资 = 基本工资/(21.75*8)*实际出勤时长
- BigDecimal actAttendTimeRate = shichang.divide(new BigDecimal(21.75), 3, BigDecimal.ROUND_HALF_UP).divide(new BigDecimal(8), 3, BigDecimal.ROUND_HALF_UP);
- // 判断是否超过满月情况下的数字
- if (actAttendTimeRate.compareTo(BigDecimal.ONE) < 0) {
- uw.setBasicWage(uw.getBasicWage().multiply(actAttendTimeRate));
- uw.setDutiesAllowance(uw.getDutiesAllowance().multiply(actAttendTimeRate));
- uw.setPostAllowance(uw.getPostAllowance().multiply(actAttendTimeRate));
- uw.setDutieslevelAllowance(uw.getDutieslevelAllowance().multiply(actAttendTimeRate));
- uw.setTalentAllowance(uw.getTalentAllowance().multiply(actAttendTimeRate));
- uw.setOtherworkSubsidy(uw.getOtherworkSubsidy().multiply(actAttendTimeRate));
- uw.setJianguanBonus(uw.getJianguanBonus().multiply(actAttendTimeRate));
- uw.setXianchangBonus(uw.getXianchangBonus().multiply(actAttendTimeRate));
- uw.setProjectPerformance(uw.getProjectPerformance().multiply(actAttendTimeRate));
- }
- }
- /**
- * 管理层新入职工资计算
- * @param uw
- * @param per
- * @param wa
- * @param basicWage
- * @throws ParseException
- */
- private void calEntryManagePersonWage(UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per, WagestrategyDto wa, BigDecimal basicWage) throws ParseException {
- // 管理层:基本工资 = 基本工资/当月天数*在职自然日天数*80%
- if (per.getCorrectionDate() != null) {
- if (equals(per.getCorrectionDate(), per.getContractStime())) {
- // 基本工资
- uw.setBasicWage(CalCorrectAndEntryInSameMonth(basicWage, per));
- // 职务津贴
- uw.setDutiesAllowance(CalCorrectAndEntryInSameMonth(uw.getDutiesAllowance(), per));
- //岗位津贴
- uw.setPostAllowance(CalCorrectAndEntryInSameMonth(uw.getPostAllowance(), per));
- //等级津贴
- uw.setDutieslevelAllowance(CalCorrectAndEntryInSameMonth(uw.getDutieslevelAllowance(), per));
- //人才津贴
- uw.setTalentAllowance(CalCorrectAndEntryInSameMonth(uw.getTalentAllowance(), per));
- //其它工作补贴
- uw.setOtherworkSubsidy(CalCorrectAndEntryInSameMonth(uw.getOtherworkSubsidy(), per));
- //兼管
- uw.setJianguanBonus(CalCorrectAndEntryInSameMonth(uw.getJianguanBonus(), per));
- //现场
- uw.setXianchangBonus(CalCorrectAndEntryInSameMonth(uw.getXianchangBonus(), per));
- uw.setProjectPerformance(CalCorrectAndEntryInSameMonth(uw.getProjectPerformance(), per));
-
- } else {
- //入职和转正不在同一个月份
- uw.setBasicWage(basicWage.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
- uw.setDutiesAllowance(uw.getDutiesAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
- uw.setPostAllowance(uw.getPostAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
- uw.setDutieslevelAllowance(uw.getDutieslevelAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
- uw.setTalentAllowance(uw.getTalentAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
- uw.setOtherworkSubsidy(uw.getOtherworkSubsidy().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
- uw.setJianguanBonus(uw.getJianguanBonus().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
- uw.setXianchangBonus(uw.getXianchangBonus().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))).multiply(new BigDecimal(0.8)));
- }
- } else {
- uw.setBasicWage(basicWage.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
- .multiply(new BigDecimal(0.8)));
- uw.setDutiesAllowance(uw.getDutiesAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
- .multiply(new BigDecimal(0.8)));
- uw.setPostAllowance(uw.getPostAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
- .multiply(new BigDecimal(0.8)));
- uw.setDutieslevelAllowance(uw.getDutieslevelAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
- .multiply(new BigDecimal(0.8)));
- uw.setTalentAllowance(uw.getTalentAllowance().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
- .multiply(new BigDecimal(0.8)));
- uw.setOtherworkSubsidy(uw.getOtherworkSubsidy().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
- .multiply(new BigDecimal(0.8)));
- uw.setJianguanBonus(uw.getJianguanBonus().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
- .multiply(new BigDecimal(0.8)));
- uw.setXianchangBonus(uw.getXianchangBonus().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getContractStime(), null)))
- .multiply(new BigDecimal(0.8)));
- }
- }
- /**计算入职月份转正的工资
- * @param dutieslevelAllowance
- * @param per
- * @return
- * @throws ParseException
- */
- private BigDecimal CalCorrectAndEntryInSameMonth(BigDecimal allowanceComplete, PersonnelBaseArchivesManageOutDto per) throws ParseException {
- BigDecimal level = allowanceComplete.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));
- level = level.add(level.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null))));
- return level;
- }
-
- /**
- * 管理层离职工资计算
- * @param uw
- * @param per
- * @param basicWage
- * @throws ParseException
- */
- private void calLeavedManagePersonWage(UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per, BigDecimal basicWage) throws ParseException {
- uw.setBasicWage(calLeavedWageValue(per, basicWage));
- uw.setDutiesAllowance(calLeavedWageValue(per, uw.getDutiesAllowance()));
- uw.setPostAllowance(calLeavedWageValue(per, uw.getPostAllowance()));
- uw.setDutieslevelAllowance(calLeavedWageValue(per, uw.getDutieslevelAllowance()));
- uw.setTalentAllowance(calLeavedWageValue(per, uw.getTalentAllowance()));
- uw.setOtherworkSubsidy(calLeavedWageValue(per, uw.getOtherworkSubsidy()));
- uw.setJianguanBonus(calLeavedWageValue(per, uw.getJianguanBonus()));
- uw.setXianchangBonus(calLeavedWageValue(per, uw.getXianchangBonus()));
- uw.setProjectPerformance(calLeavedWageValue(per, uw.getProjectPerformance()));
- }
- private BigDecimal calLeavedWageValue(PersonnelBaseArchivesManageOutDto per, BigDecimal origValue) throws ParseException {
- BigDecimal value = origValue;
- if (per.getCorrectionDate() != null) {
- // 判断转正时间和离职时间是否在同一个月
- if (equals(per.getCorrectionDate(), per.getLeaveDate())) {
- // 管理层:基本工资/当月天数*80%*试用期自然日天数+ 基本工资/当月天数*转正后自然日天数
- if (equals(per.getCorrectionDate(), per.getContractStime())) {
- value = value.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));
- value = value.add(value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(daysBetween(per.getCorrectionDate(), per.getLeaveDate()))));
- } else {
- value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
- .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate())));
- value = value.add(origValue.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(daysBetween(per.getCorrectionDate(), per.getLeaveDate()))));
- }
- } else {
- // 管理层:基本工资/当月天数*在职自然日天数
- value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff1(per.getLeaveDate())));
- }
- } else {
- // 管理层:基本工资/当月天数*在职自然日天数*80%
- if (equals(per.getLeaveDate(), per.getContractStime())) {
- value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(daysBetween(per.getContractStime(), per.getLeaveDate()))).multiply(new BigDecimal(0.8));
- } else {
- value = value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff1(per.getLeaveDate()) + 1))
- .multiply(new BigDecimal(0.8));
- }
- }
- return value;
- }
- /**
- * 同月入职、转正、离职---奇葩
- * @param per
- * @param value
- * @return
- * @throws ParseException
- */
- private BigDecimal calCorrAndLeaveAndEntryInSameMonth(PersonnelBaseArchivesManageOutDto per, BigDecimal value) throws ParseException {
- value = value.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));
- value = value.add(value.divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP)
- .multiply(new BigDecimal(daysBetween(per.getCorrectionDate(), per.getLeaveDate()))));
- return value;
- }
- /**
- * 公积金修改
- *
- * @param hm_cache
- * @param uw
- * @param us
- * @param per
- * @return
- */
- private UserNewWageEntity aloneCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) {
- StringBuffer str = new StringBuffer();
- String st = " and status = 0 and delete_flag = 0";
- // 社保扣除
- if (StringUtils.isNotEmpty(us.getSocialSecurityStrategyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_social_security_strategy where id = '" + us.getSocialSecurityStrategyid() + "'");
- str.insert(str.length(), st);
- SocialSecurityStrategyEntity social = null;
- if (isCacheUsed) {
- social = getSocialSecurityStrategyEntityWithCache(hm_cache, us.getSocialSecurityStrategyid());
- } else {
- List<SocialSecurityStrategyEntity> socialList = this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list();
- if (socialList != null && socialList.size() > 0) {
- social = socialList.get(0);
- }
- }
- if (social != null) {
- // 设置社保单位
- uw.setSocialSecurityId(social.getId());
- uw.setSocialSecurityUnit(social.getSocialSecurityUnit());
- if (Globals.SOCIAL_SECURITY_STRATEGY_HUZHOU.equals(social.getId())) {
- huzhouSocialSecurityCalcu(uw, social);
- } else {
- normalSocialSecurityCalcu(uw, social);
- }
- }
- } else {
- uw.setSocialSecurityDebit(new BigDecimal(0));
- }
- // 公积金扣除
- if (StringUtils.isNotEmpty(us.getProvidentFundStrategyid())) {
- ProvidentFundStrategyEntity perobident = getProvidentFundStrategyEntityWithCache(hm_cache, us.getProvidentFundStrategyid());
- if (perobident != null) {
- ProvidentFundStrategyEntity meal = perobident;
- uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio().multiply(new BigDecimal(0.01))).setScale(0, BigDecimal.ROUND_HALF_UP));
- uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio().multiply(new BigDecimal(0.01))).setScale(0, BigDecimal.ROUND_HALF_UP));
- }
- } else {
- uw.setProvidentFundDebit(new BigDecimal(0));
- }
- // 缴金补贴
- String jiaojin_subsidy = us.getJiaojinSubsidyid();
- // zy20180428 如果工资策略里没有设定缴金补贴,则按照原始缴扣进行补贴.否则按照工资策略补贴
- if (jiaojin_subsidy == null) {
- uw.setPaymentSubsidy(uw.getSocialSecurityDebit().add(uw.getProvidentFundDebit()));
- } else {
- uw.setPaymentSubsidy(BigDecimal.ZERO);
- BigDecimal jiaonjinMoney = getJiaoJinSubsidyMoney(isCacheUsed, hm_cache, uw, us, per);
- if(jiaonjinMoney != null) {
- uw.setPaymentSubsidy(jiaonjinMoney);
- }
- }
- return uw;
- }
- /**
- * @param uw
- * @param social
- */
- private void huzhouSocialSecurityCalcu(UserNewWageEntity uw, SocialSecurityStrategyEntity social) {
- BigDecimal perInsu = BigDecimal.ZERO;
- perInsu = perInsu.add(social.getPersonalBasicRetireInsu().multiply(new BigDecimal(0.01)));
- perInsu = perInsu.add(social.getPersionalBasicMedicalInsu().multiply(new BigDecimal(0.01)));
- perInsu = perInsu.add(social.getPersonalUnemploymentInsu().multiply(new BigDecimal(0.01)));
- BigDecimal perResult = BigDecimal.ZERO;
- perResult = social.getBasePay().multiply(perInsu);
- uw.setSocialSecurityDebit(perResult.setScale(1, BigDecimal.ROUND_HALF_UP));
- BigDecimal comInsu = BigDecimal.ZERO;
- BigDecimal comResult = BigDecimal.ZERO;
- comInsu = comInsu.add(social.getCompanyBasicRetireInsu().multiply(new BigDecimal(0.01)));
- comInsu = comInsu.add(social.getCompanyBasicMedicalInsu().multiply(new BigDecimal(0.01)));
- comInsu = comInsu.add(social.getCompanyUnemploymentInsu().multiply(new BigDecimal(0.01)));
- comInsu = comInsu.add(social.getCompanyInjuryInsu().multiply(new BigDecimal(0.01)));
- comInsu = comInsu.add(social.getCompanyMaternityInsu().multiply(new BigDecimal(0.01)));
- comResult = comInsu.multiply(social.getBasePay());
- uw.setComSocialSecurityDebit(comResult.setScale(2, BigDecimal.ROUND_HALF_UP));
- }
- private void normalSocialSecurityCalcu(UserNewWageEntity uw, SocialSecurityStrategyEntity meal) {
- /**
- * 社保个人金额: 中间各项目计算结果:直接进位,保留1位小数; 合计:直接进位,保留1位小数;
- */
- uw.setSocialSecurityDebit(new BigDecimal(0));
- uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersonalBasicRetireInsu().multiply(new BigDecimal(0.01))).setScale(1, BigDecimal.ROUND_UP)));
- uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersionalBasicMedicalInsu().multiply(new BigDecimal(0.01))).setScale(1, BigDecimal.ROUND_UP)));
- uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersonalUnemploymentInsu().multiply(new BigDecimal(0.01))).setScale(1, BigDecimal.ROUND_UP)));
- uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().setScale(1, BigDecimal.ROUND_UP));
- /**
- * 社保单位金额: 中间各项目计算结果:四舍五入,保留4位小数; 合计:四舍五入,保留4位小数;
- */
- uw.setComSocialSecurityDebit(new BigDecimal(0));
- uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyBasicRetireInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
- uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyBasicMedicalInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
- uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyUnemploymentInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
- uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyInjuryInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
- uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyMaternityInsu().multiply(new BigDecimal(0.01))).setScale(4, BigDecimal.ROUND_HALF_UP)));
- uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().setScale(2, BigDecimal.ROUND_HALF_UP));
- }
- /**
- * 得到当前年月
- *
- * @return
- */
- private String getMonthlys() {
- Calendar cal = Calendar.getInstance();
- int year = cal.get(Calendar.YEAR);
- int month = cal.get(Calendar.MONTH);
- if (month < 10) {
- if (month == 0) {
- year = year - 1;
- month = 12;
- } else {
- // month = Integer.valueOf(0+""+month);
- return year + "-" + 0 + "" + month;
- }
- }
- return year + "-" + month;
- }
- /**
- * ----------------------------废弃的方法 by zhijia.wang--------------------------
- * 判断上个月是否为入职或离职
- *
- * @param us
- * @return
- * @throws ParseException
- */
- /*
- * private boolean entryOrLeave(UserNewWagestrategyEntity
- * us,PersonnelBaseArchivesManageOutDto per) throws ParseException{ boolean
- * isOrNot = true; if(per.getContractStime() != null){ Calendar
- * cal_1=Calendar.getInstance(); SimpleDateFormat format = new
- * SimpleDateFormat("yyyy-MM-dd"); Date stime = per.getContractStime();
- * cal_1.setTime(format.parse(format.format(stime)));
- *
- * int year = cal_1.get(Calendar.YEAR); int month = cal_1.get(Calendar.MONTH)+1;
- *
- * Calendar cal_2 = Calendar.getInstance();//获取当前日期 cal_2.add(Calendar.MONTH,
- * -1); cal_2.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
- *
- * int year1 = cal_2.get(Calendar.YEAR); int month1 =
- * cal_2.get(Calendar.MONTH)+1; if(year == year1 && month == month1){ isOrNot =
- * false; return isOrNot;
- *
- * } }
- *
- * //离职同入职原理相同 if(per.getLeaveDate() != null){ Calendar
- * cal_1=Calendar.getInstance(); SimpleDateFormat format = new
- * SimpleDateFormat("yyyy-MM-dd"); Date stime = per.getLeaveDate();
- * cal_1.setTime(format.parse(format.format(stime)));
- *
- * int year = cal_1.get(Calendar.YEAR); int month = cal_1.get(Calendar.MONTH)+1;
- *
- * Calendar cal_2 = Calendar.getInstance();//获取当前日期 cal_2.add(Calendar.MONTH,
- * -1); cal_2.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
- *
- * int year1 = cal_2.get(Calendar.YEAR); int month1 =
- * cal_2.get(Calendar.MONTH)+1; if(year == year1 && month == month1){ isOrNot =
- * false; return isOrNot; } }
- *
- * return isOrNot; }
- */
- /**
- * 判断是否当月入职或离职或者如果当月入职或离职,是否干满一个整月
- *
- * @author zhijia.wang
- * @date 2018-03-09 14:55:20
- * @param us
- * @return
- * @throws ParseException
- */
- private boolean isCompleteMonthWage(UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) throws ParseException {
- YearMonthDay entryDate = getEntryDate(per.getContractStime());
- YearMonthDay leaveDate = getLeaveDate(per.getLeaveDate());
- // 工资月月初时间
- Calendar cal_1 = Calendar.getInstance();// 获取当前日期
- cal_1.add(Calendar.MONTH, -1);// 设置为上个月(工资月)
- cal_1.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号
- int year = cal_1.get(Calendar.YEAR);
- int month = cal_1.get(Calendar.MONTH) + 1;
- // int firstday = cal_1.get(Calendar.DATE);
- // 工资月月末时间
- Calendar cal_2 = Calendar.getInstance();// 获取当前日期
- cal_2.add(Calendar.MONTH, -1);// 设置为上个月(工资月)
- cal_2.set(Calendar.DATE, cal_2.getActualMaximum(Calendar.DATE));// 设置为最后一天
- int year2 = cal_1.get(Calendar.YEAR);
- int month2 = cal_1.get(Calendar.MONTH) + 1;
- int lastday = cal_2.get(Calendar.DATE);
- // 判断离职
- if (leaveDate != null) {
- int leave_year = leaveDate.getYear();
- int leave_month = leaveDate.getMonth();
- int leave_day = leaveDate.getDay();
- if (year == leave_year && month == leave_month) {
- if (leave_day != lastday) {// 如果不是最后一天离职
- return false;
- }
- }
- }
- // 判断入职
- if (entryDate != null) {
- int enrty_year = entryDate.getYear();
- int enrty_month = entryDate.getMonth();
- int enrty_day = entryDate.getDay();
- if (year == enrty_year && month == enrty_month) {
- if (enrty_day == 1) {// 如果是1号入职
- // 判断离职
- if (leaveDate != null) {
- int leave_year = leaveDate.getYear();
- int leave_month = leaveDate.getMonth();
- int leave_day = leaveDate.getDay();
- if (year == leave_year && month == leave_month) {
- if (leave_day != lastday) {// 如果不是最后一天离职
- return false;
- }
- }
- }
- } else {
- return false;
- }
- }
- }
- return true;
- }
- // 获取入职日期
- private YearMonthDay getEntryDate(Date contractStime) throws ParseException {
- if (contractStime != null) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- Calendar cal_1 = Calendar.getInstance();// 获取当前日期
- cal_1.setTime(sdf.parse(sdf.format(contractStime)));
- int year = cal_1.get(Calendar.YEAR);
- int month = cal_1.get(Calendar.MONTH) + 1;
- int day = cal_1.get(Calendar.DATE);
- return new YearMonthDay(year, month, day);
- }
- return null;
- }
- // 获取离职日期
- private YearMonthDay getLeaveDate(Date leaveDate) throws ParseException {
- if (leaveDate != null) {
- Calendar cal_1 = Calendar.getInstance();// 获取当前日期
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- cal_1.setTime(sdf.parse(sdf.format(leaveDate)));
- int year = cal_1.get(Calendar.YEAR);
- int month = cal_1.get(Calendar.MONTH) + 1;
- int day = cal_1.get(Calendar.DATE);
- return new YearMonthDay(year, month, day);
- }
- return null;
- }
- /**
- * 判断是否在同一年并且同一个月
- *
- * @param date1
- * @param date2
- * @return
- */
- private static boolean equals(Date date1, Date date2) {
- Calendar calendar1 = Calendar.getInstance();
- calendar1.setTime(date1);
- Calendar calendar2 = Calendar.getInstance();
- calendar2.setTime(date2);
- return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH);
- }
- /**
- * 判断是否为上个月转正
- *
- * @param us
- * @return
- * @throws ParseException
- */
- private boolean isCorrection(PersonnelBaseArchivesManageOutDto per) throws ParseException {
- boolean isOrNot = true;
- if (per.getCorrectionDate() != null) {
- Calendar cal_1 = Calendar.getInstance();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- Date stime = per.getCorrectionDate();
- cal_1.setTime(format.parse(format.format(stime)));
- int year = cal_1.get(Calendar.YEAR);
- int month = cal_1.get(Calendar.MONTH) + 1;
- Calendar cal_2 = Calendar.getInstance();// 获取当前日期
- cal_2.add(Calendar.MONTH, -1);
- cal_2.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
- int year1 = cal_2.get(Calendar.YEAR);
- int month1 = cal_2.get(Calendar.MONTH) + 1;
- if (year == year1 && month == month1) {
- isOrNot = false;
- return isOrNot;
- }
- }
- return isOrNot;
- }
- /**
- * 查询基本工资
- *
- * @param isCacheUsed
- * @param hm_cache
- * @param idString
- * @param uw
- * @return
- * @throws ParseException
- */
- private UserNewWageEntity basicWagePartCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per)
- throws ParseException {
- uw.setBasicWage(new BigDecimal(0));
- uw.setDutiesAllowance(new BigDecimal(0));
- uw.setPostAllowance(new BigDecimal(0));
- uw.setDutieslevelAllowance(new BigDecimal(0));
- WagestrategyDto wa = getWagestrategyDto(isCacheUsed, hm_cache, per);
- if (wa != null) {
- if (wa != null) {
- uw.setDutiesid(wa.getId());
- // 判断转正日期是否在上个月,如果在,
- // 本月应发基本工资 = 基本工资 - 本月应扣除试用期工资【基本工资/21.75*20%*试用期天数(自然日)】
- // 如果不在,就为基本工资
- if (Globals.MANAGETYPE_2.toString().equals(per.getManagerType())) {
- uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa));
- uw.setDutiesAllowance(wa.getSubsidy());
- uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa));
- uw.setPostAllowance(wa.getPostMoney());
- } else {
- if(per.getCorrectionDate() == null) {
- uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa));
- uw.setDutiesAllowance(wa.getSubsidy());
- uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa));
- uw.setPostAllowance(wa.getPostMoney());
- }
- // 是否上个月转正
- else if (isCorrection(per)) {
- if (Globals.JOBSTATUS_1.equals(per.getPositionStatus())) {
- uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa).multiply(new BigDecimal(0.8)));
- uw.setDutiesAllowance(wa.getSubsidy().multiply(new BigDecimal(0.8)));
- uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa).multiply(new BigDecimal(0.8)));
- uw.setPostAllowance(wa.getPostMoney().multiply(new BigDecimal(0.8)));
- } else {
- uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa));
- uw.setDutiesAllowance(wa.getSubsidy());
- uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa));
- uw.setPostAllowance(wa.getPostMoney());
- }
- } else {
- uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa).divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
- .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate()))));
- uw.setBasicWage(getBasicWage(isCacheUsed, hm_cache, per, us,wa)
- .add(getBasicWage(isCacheUsed, hm_cache, per, us,wa).divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null)))));
- uw.setDutiesAllowance(wa.getSubsidy().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
- .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate()))));
- uw.setDutiesAllowance(uw.getDutiesAllowance()
- .add(wa.getSubsidy().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null)))));
- uw.setDutieslevelAllowance(getDutieslevelAllowance(per, wa).divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
- .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate()))));
- uw.setDutieslevelAllowance(uw.getDutiesAllowance()
- .add(wa.getPostMoney().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null)))));
- uw.setPostAllowance(wa.getPostMoney().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(0.8))
- .multiply(new BigDecimal(dateDiff1(per.getCorrectionDate()))));
- uw.setPostAllowance(uw.getPostAllowance()
- .add(wa.getPostMoney().divide(new BigDecimal(getDaysOfMonth(getMonthlys() + "-01")), 3, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(dateDiff2(per.getCorrectionDate(), null)))));
- }
- }
- }
- }
- return uw;
- }
- private WagestrategyDto getWagestrategyDto(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, PersonnelBaseArchivesManageOutDto per) {
- List<WagestrategyDto> perobident = getWagestrategyEntityWithCache(isCacheUsed, hm_cache, per.getDutiesId());
- if (perobident != null) {
- int resultlevel = -1;
- WagestrategyDto resultdto = null;
- for (WagestrategyDto dto : perobident) {
- int level = -1;
- if (dto.getProject() == null && dto.getZone() == null) {
- level = 0;
- } else if (dto.getZone() != null) {
- level = 1;
- } else if (dto.getProject() != null) {
- level = 2;
- }
- if (level > resultlevel) {
- resultdto = dto;
- }
- }
- return resultdto;
- }
- return null;
- }
- /**
- * @param hm_cache
- * @param isCacheUsed
- * @param per
- * @param wa
- * @return
- */
- private BigDecimal getBasicWage(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache
- , PersonnelBaseArchivesManageOutDto per, UserNewWagestrategyEntity us, WagestrategyDto wa) {
- HashMap<String, Object> hm = hm_cache.get("getBasicWage");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getBasicWage", hm);
- StringBuffer str = new StringBuffer();
- str.append("select * from t_bus_base_wagestrategy where 1=1");
- List<TBusBaseWagestrategyEntity> entitiesFromDB = this.getSession().createSQLQuery(str.toString()).addEntity(TBusBaseWagestrategyEntity.class).list();
-
-
- for (TBusBaseWagestrategyEntity entity : entitiesFromDB) {
- String userInEntity = entity.getZone();
- hm.put(userInEntity, entity);
- }
- }
- TBusBaseWagestrategyEntity resultEntity = null;
- if(per.getZoneId() != null && hm.containsKey(per.getZoneId())) {
- resultEntity = (TBusBaseWagestrategyEntity)hm.get(per.getZoneId());
- }else {
- resultEntity = (TBusBaseWagestrategyEntity)hm.get(null);
- if(resultEntity == null) {
- resultEntity = (TBusBaseWagestrategyEntity)hm.get("");
- }
- }
-
- BigDecimal result = resultEntity.getMoney();
- if(result == null) {
- result = BigDecimal.ZERO;
- }
- if(wa.getBasicWage() != null) {
- if(result.compareTo(wa.getBasicWage()) > 0) {
- return wa.getBasicWage();
- }
- }
- return result;
- }
- /**
- * @param per
- * @param wa
- * @return
- */
- private BigDecimal getDutieslevelAllowance(PersonnelBaseArchivesManageOutDto per, WagestrategyDto wa) {
- if ("1".equals(per.getDutieslevel())) {
- return wa.getLevelonesubsidy();
- }
- if ("2".equals(per.getDutieslevel())) {
- return wa.getLeveltwosubsidy();
- }
- if ("3".equals(per.getDutieslevel())) {
- return wa.getLevelthreesubsidy();
- }
- return BigDecimal.ZERO;
- }
- /**
- * @param isCacheAll true:缓存所有,否则缓存个别
- * @param hm_cache
- * @param belongDutiesid
- * @return
- */
- private List<WagestrategyDto> getWagestrategyEntityWithCache(boolean isCacheAll, HashMap<String, HashMap<String, Object>> hm_cache, String belongDutiesid) {
- HashMap<String, Object> hm = hm_cache.get("getWagestrategyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getWagestrategyEntityWithCache", hm);
- MiniDaoPage<WagestrategyDto> entitiesFromDB = null;
- if(isCacheAll) {
- entitiesFromDB = wagestrategyMiniDao.getAllEntities();
- }else {
- entitiesFromDB = wagestrategyMiniDao.getEntitiesByDutiesId(belongDutiesid);
- }
-
- for (WagestrategyDto entity : entitiesFromDB.getResults()) {
- String userInEntity = entity.getDutiesId();
- if (hm.containsKey(userInEntity)) {
- List<WagestrategyDto> entitylist = (List<WagestrategyDto>) hm.get(userInEntity);
- entitylist.add(entity);
- } else {
- List<WagestrategyDto> newlist = new ArrayList<>();
- newlist.add(entity);
- hm.put(userInEntity, newlist);
- }
- }
- }
- return (List<WagestrategyDto>) hm.get(belongDutiesid);
- }
- /**
- * 查询基本策略设定值
- *
- * @param isCacheUsed
- * @param us
- * @param uw
- * @param per
- * @return
- */
- private UserNewWageEntity selectStrategy(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
- BigDecimal certificateSubsidyMoney = getCertificateSubsidyMoneyWithCache(hm_cache, uw.getUserid());
- uw.setCertificateSubsidy(BigDecimal.ZERO);
- if (certificateSubsidyMoney != null) {
- uw.setCertificateSubsidy(certificateSubsidyMoney);
- }
- // 交通补贴
- BigDecimal trafficSub = getTrafficSubsidyMoney(hm_cache, us,per);
- uw.setTrafficSubsidy(BigDecimal.ZERO);
- if (trafficSub != null) {
- uw.setTrafficSubsidy(trafficSub);
- }
- // 高温补贴
- if (StringUtils.isNotEmpty(us.getMegathermalSubsidyid())) {
- // str.delete(0,str.length());
- // str.append("select * from t_bus_megathermal_subsidy where id
- // ='"+us.getMegathermalSubsidyid()+"'");
- // str.insert(str.length(), st);
- // List<MegathermalSubsidyEntity> trafficSubsidyList =
- // this.getSession().createSQLQuery(str.toString()).addEntity(MegathermalSubsidyEntity.class).list();
- MegathermalSubsidyEntity trafficSubsidyList = getMegathermalSubsidyEntityWithCache(hm_cache, us.getMegathermalSubsidyid());
- // List<MegathermalSubsidyEntity> trafficSubsidyList =
- // this.findListbySql(str.toString());
- if (oConvertUtils.isNotEmpty(trafficSubsidyList)) {
- uw.setMegathermalSubsidy(trafficSubsidyList.getSubsidyMoney());
- }
- } else {
- uw.setMegathermalSubsidy(new BigDecimal(0));
- }
- // 独生子女费
- if (us.getOnlychildPay() != null && us.getOnlychildPay().intValue() > 0) {
- uw.setOnlyChildCost(us.getOnlychildPay());
- } else {
- uw.setOnlyChildCost(new BigDecimal(0));
- }
- // 其他补贴
- /*
- * if(StringUtils.isNotEmpty(us.getOtherSubsidyid())){ //
- * str.delete(0,str.length()); //
- * str.append("select * from t_bus_other_subsidy where id ='"+us.
- * getOtherSubsidyid()+"'"); // str.insert(str.length(), st); //
- * List<OtherSubsidyEntity> trafficSubsidyList =
- * this.getSession().createSQLQuery(str.toString()).addEntity(OtherSubsidyEntity
- * .class).list(); //List<OtherSubsidyEntity> trafficSubsidyList =
- * this.findListbySql(str.toString()); OtherSubsidyEntity trafficSubsidyList =
- * getOtherSubsidyEntityWithCache(hm_cache,us.getOtherSubsidyid());
- * if(oConvertUtils.isNotEmpty(trafficSubsidyList)){ if(us.getAppendPay() !=
- * null && us.getAppendPay().intValue() > 0 ){
- * uw.setOtherSubsidy(us.getAppendPay().add(trafficSubsidyList.getSubsidyMoney()
- * )); }else{ uw.setOtherSubsidy(trafficSubsidyList.getSubsidyMoney()); } }
- * }else{ if(us.getAppendPay() != null && us.getAppendPay().intValue() > 0 ){
- * uw.setOtherSubsidy(us.getAppendPay()); }else{ uw.setOtherSubsidy(new
- * BigDecimal(0)); } }
- */
- return uw;
- }
- /**
- * @param hm_cache
- * @param userid
- * @return
- */
- private BigDecimal getTrafficSubsidyMoney(HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) {
- if(us.getTrafficSubsidyid() != null ) {
- return us.getTrafficSubsidyid();
- }
- WagestrategyDto companyLevelWagestrategy = getCompanyLevelWagestrategy(hm_cache, us, per);
- if(companyLevelWagestrategy != null) {
- return companyLevelWagestrategy.getTrafficsubsidy();
- }
-
- return null;
- }
- /**
- * @param hm_cache
- * @param us
- * @param per
- * @return
- */
- private WagestrategyDto getCompanyLevelWagestrategy(HashMap<String, HashMap<String, Object>> hm_cache, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) {
- List<WagestrategyDto> dtos = getWagestrategyEntityWithCache(true, hm_cache, per.getDutiesId());
- if(dtos != null && dtos.size() >0) {
- for(WagestrategyDto d : dtos) {
- if(d.getZone() == null && d.getProject() == null) {
- return d;
- }
- }
- }
-
- return null;
- }
- /**
- * @param hm_cache
- * @param otherSubsidyid
- * @return
- */
- private OtherSubsidyEntity getOtherSubsidyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String otherSubsidyid) {
- HashMap<String, Object> hm = hm_cache.get("getOtherSubsidyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getOtherSubsidyEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(OtherSubsidyEntity.class);
- specialcq.eq("deleteFlag", "0");
- specialcq.add();
- specialcq.eq("status", "0");
- specialcq.add();
- List<OtherSubsidyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (OtherSubsidyEntity entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (OtherSubsidyEntity) hm.get(otherSubsidyid);
- }
- /**
- * @param hm_cache
- * @param megathermalSubsidyid
- * @return
- */
- private MegathermalSubsidyEntity getMegathermalSubsidyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String megathermalSubsidyid) {
- // TODO Auto-generated method stub
- HashMap<String, Object> hm = hm_cache.get("getMegathermalSubsidyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getMegathermalSubsidyEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(MegathermalSubsidyEntity.class);
- specialcq.eq("deleteFlag", "0");
- specialcq.add();
- specialcq.eq("status", "0");
- specialcq.add();
- List<MegathermalSubsidyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (MegathermalSubsidyEntity entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (MegathermalSubsidyEntity) hm.get(megathermalSubsidyid);
- }
- /**
- * @param string
- * @param hm_cache
- * @param trafficSubsidyid
- * @return
- */
- private TrafficSubsidyEntity getTrafficSubsidyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String trafficSubsidyid) {
- // TODO Auto-generated method stub
- // str.delete(0,str.length());
- // str.append("select * from t_bus_traffic_subsidy where id
- // ='"+us.getTrafficSubsidyid()+"'");
- // str.insert(str.length(), st);
- // List<TrafficSubsidyEntity> trafficSubsidyList =
- // this.getSession().createSQLQuery(str.toString()).addEntity(TrafficSubsidyEntity.class).list();
- HashMap<String, Object> hm = hm_cache.get("getTrafficSubsidyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getTrafficSubsidyEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(TrafficSubsidyEntity.class);
- specialcq.eq("deleteFlag", "0");
- specialcq.add();
- specialcq.eq("status", "0");
- specialcq.add();
- List<TrafficSubsidyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (TrafficSubsidyEntity entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (TrafficSubsidyEntity) hm.get(trafficSubsidyid);
- }
- /**
- * @param hm_cache
- * @param userid
- * @return
- */
- private BigDecimal getCertificateSubsidyMoneyWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String userid) {
- // StringBuffer str = new StringBuffer();
- // String st = "and status = 0 and delete_flag = 0";
- //
- // 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";
- // List<CertificateSubsidyEntity> usList =
- // this.getSession().createSQLQuery(certiSql).addEntity(CertificateSubsidyEntity.class).list();
- // BigDecimal bigDecimal = new BigDecimal(0);
- HashMap<String, Object> hm = hm_cache.get("getCertificateSubsidyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getCertificateSubsidyEntityWithCache", hm);
- StringBuffer str_certificate = new StringBuffer();
- str_certificate.append("select * from t_bus_user_certificate where delete_flag = 0");
- List<UserCertificateEntity> entitiesUserCertificateEntity = this.getSession().createSQLQuery(str_certificate.toString()).addEntity(UserCertificateEntity.class).list();
- String str_subsidy = "select * from t_bus_certificate_subsidy where delete_flag = 0 and status=0";
- List<CertificateSubsidyEntity> subList = this.getSession().createSQLQuery(str_subsidy).addEntity(CertificateSubsidyEntity.class).list();
- HashMap<String, CertificateSubsidyEntity> subMap = new HashMap<>();
- for (CertificateSubsidyEntity sub : subList) {
- subMap.put(sub.getId(), sub);
- }
- for (UserCertificateEntity certificateEntity : entitiesUserCertificateEntity) {
- String userInEntity = certificateEntity.getUserid();
- String certInEntity = certificateEntity.getCertificateid();
- CertificateSubsidyEntity subEntity = subMap.get(certInEntity);
- BigDecimal subMoney = BigDecimal.ZERO;
- if (subEntity != null && subEntity.getSubsidyMoney() != null) {
- subMoney = subEntity.getSubsidyMoney();
- }
- if (hm.containsKey(userInEntity)) {
- BigDecimal old = BigDecimal.ZERO;
- if ((BigDecimal) hm.get(userInEntity) != null) {
- old = (BigDecimal) hm.get(userInEntity);
- }
- hm.put(userInEntity, subMoney.add(old));
- } else {
- if (subMoney == null) {
- subMoney = BigDecimal.ZERO;
- }
- hm.put(userInEntity, subMoney);
- }
- }
- }
- return (BigDecimal) hm.get(userid);
- }
- /**
- * 将从数据库中读取的字符串信息转化成实体类
- *
- * @author hualong.zhao
- * @date 2017-11-29
- * @param jsonobjString
- * @return
- */
- private AttendanceDetailJsonObj getJsonObjFromString(String jsonobjString) {
- AttendanceDetailJsonObj jsonObj = new AttendanceDetailJsonObj();
- if (oConvertUtils.isNotEmpty(jsonobjString)) {
- try {
- jsonObj = (JSONObject.parseObject(jsonobjString)).toJavaObject(AttendanceDetailJsonObj.class);
- } catch (Exception e) {
- }
- }
- return jsonObj;
- }
- /**
- * 餐费补助
- *
- * @param hm_cache
- * @param us
- * @param uw
- * @return
- */
- private UserNewWageEntity mealsCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw,
- List<MealsSubsidyEntity> meslList) {
- uw.setMealsSubsidyDay(new BigDecimal(0));
- uw.setMealsSubsidyNight(new BigDecimal(0));
- uw.setMealsSubsidy(new BigDecimal(0));
- if (uat != null) {
- if ("0".equals(us.getStrategyType())) {
- uw.setMealsSubsidy(new BigDecimal(0));
- // 每月固定餐补
- if (StringUtils.isNotEmpty(us.getFixedmealsSubsidyid())) {
- for (MealsSubsidyEntity mse : meslList) {
- if (us.getFixedmealsSubsidyid().equals(mse.getId())) {
- uw.setMealsSubsidy(uw.getMealsSubsidy().add(mse.getSubsidyMoney()));
- }
- if (uat.getExtraOvertime() != null && uat.getExtraOvertime().intValue() > 0 && StringUtils.isNotEmpty(us.getNofixedmealsSubsidyid())) {
- if (us.getNofixedmealsSubsidyid().equals(mse.getId())) {
- uw.setMealsSubsidy(uw.getMealsSubsidy().add(mse.getSubsidyMoney()).multiply(new BigDecimal(uat.getExtraOvertime())));
- }
- }
- }
- uw.setMealsSubsidyDay(new BigDecimal(0));
- uw.setMealsSubsidyNight(new BigDecimal(0));
- }
- } else {
- // 根据考勤记录及时餐补
- calcMealSubsidyMoneyByAttendanceTotal(isCacheUsed, hm_cache, uat, uw, meslList);
- BigDecimal big = new BigDecimal(0);
- for (MealsSubsidyEntity mse : meslList) {
- if (uat.getExtraOvertime() != null && uat.getExtraOvertime().intValue() > 0 && StringUtils.isNotEmpty(us.getNofixedmealsSubsidyid())) {
- if (us.getNofixedmealsSubsidyid().equals(mse.getId())) {
- big = mse.getSubsidyMoney().multiply(new BigDecimal(uat.getExtraOvertime()));
- }
- }
- }
- uw.setMealsSubsidy(uw.getMealsSubsidy().add(big));
- }
- }
- //适配加班申请中的餐费部分
- OvertimeDto overtimedto = getSpecialOvertimeSumEntityWithCache(hm_cache, us.getUserid(), uat.getYearmonth());
- if(overtimedto != null) {
- BigDecimal mealFee = overtimedto.getMealFee();
- if(mealFee != null) {
- BigDecimal mealSub = uw.getMealsSubsidy();
- if(mealSub != null) {
- mealSub = mealSub.add(mealFee);
- uw.setMealsSubsidy(mealSub);
- }
- }
- }
- // 餐费补助 end
- return uw;
- }
-
- private OvertimeDto getSpecialOvertimeSumEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache,
- String userid, String yearmonth) {
- HashMap<String, Object> hm = hm_cache.get("getSpecialOvertimeEntityWithCache");
- if(hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getSpecialOvertimeEntityWithCache", hm);
- OvertimeDto dtoIn = new OvertimeDto();
- dtoIn.setYearMonth(yearmonth);
- List<OvertimeDto> overtimeDtos = overtimeService.getOverTimeFees(dtoIn);
-
- if(overtimeDtos != null && overtimeDtos.size()>0) {
- for(OvertimeDto dtoDb : overtimeDtos) {
- String userInEntity = dtoDb.getUserid();
- BigDecimal overtimeFee = BigDecimal.ZERO;
- BigDecimal mealFee = BigDecimal.ZERO;
-
- if(dtoDb != null && dtoDb.getOvertimeFee() != null) {
- overtimeFee = dtoDb.getOvertimeFee();
- }
- if(dtoDb != null && dtoDb.getMealFee() != null) {
- mealFee = dtoDb.getMealFee();
- }
- if(hm.containsKey(userInEntity)) {
- if(hm.get(userInEntity) != null ) {
- OvertimeDto oldDto = (OvertimeDto)hm.get(userInEntity);
- BigDecimal oldDtoovertimeFee = oldDto.getOvertimeFee() == null ? BigDecimal.ZERO : oldDto.getOvertimeFee();
- BigDecimal oldDtomealFee = oldDto.getMealFee() == null ? BigDecimal.ZERO : oldDto.getMealFee();
- oldDto.setOvertimeFee(overtimeFee.add(oldDtoovertimeFee));
- oldDto.setMealFee(oldDtomealFee.add(oldDtomealFee));
- hm.put(userInEntity, oldDto);
- }
- }else {
- if(overtimeFee == null) {
- overtimeFee = BigDecimal.ZERO;
- }
- if(mealFee == null) {
- mealFee = BigDecimal.ZERO;
- }
- OvertimeDto newDto = new OvertimeDto();
- newDto.setOvertimeFee(overtimeFee);
- newDto.setMealFee(mealFee);
- hm.put(userInEntity, newDto);
- }
- }
- }
- }
- return (OvertimeDto)hm.get(userid);
- }
- private void calcMealSubsidyMoneyByAttendanceTotal(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat, UserNewWageEntity uw, List<MealsSubsidyEntity> meslList) {
- List<UserAttendanceDetailEntity> adeList = null;
- if (isCacheUsed) {
- adeList = getUserAttendanceDetailEntityWithCache(hm_cache, uat);
- } else {
- adeList = findByProperty(UserAttendanceDetailEntity.class, "attendanceId", uat.getId());
- }
- if (adeList != null && !adeList.isEmpty()) {
- for (UserAttendanceDetailEntity ade : adeList) {
- AttendanceDetailJsonObj jsonObj = getJsonObjFromString(oConvertUtils.getString(ade.getJsonObj()));
- for (MealsSubsidyEntity mse : meslList) {
- // 夜班白班津贴
- if (jsonObj.getDayShiftSubsidy() != null && jsonObj.getDayShiftSubsidy().intValue() > 0) {
- if (mse.getId().equals(jsonObj.getDayShiftSubsidyId())) {
- uw.setMealsSubsidyDay(uw.getMealsSubsidyDay().add(mse.getSubsidyMoney().multiply(new BigDecimal(jsonObj.getDayShiftSubsidy()))));
- }
- }
- // 夜班夜班津贴
- if (jsonObj.getNightShiftSubsidy() != null && jsonObj.getNightShiftSubsidy().intValue() > 0) {
- if (mse.getId().equals(jsonObj.getNightShiftSubsidyId())) {
- uw.setMealsSubsidyNight(uw.getMealsSubsidyNight().add(mse.getSubsidyMoney().multiply(new BigDecimal(jsonObj.getNightShiftSubsidy()))));
- }
- }
- // 日班
- if (jsonObj.getDayShift() != null && jsonObj.getDayShift().intValue() > 0) {
- if (mse.getId().equals(jsonObj.getDayShiftId())) {
- uw.setMealsSubsidy(uw.getMealsSubsidy().add(mse.getSubsidyMoney().multiply(new BigDecimal(jsonObj.getDayShift()))));
- }
- }
- // 常班
- if (jsonObj.getRegularShift() != null && jsonObj.getRegularShift().intValue() > 0) {
- if (mse.getId().equals(jsonObj.getRegularShiftId())) {
- uw.setMealsSubsidy(uw.getMealsSubsidy().add(mse.getSubsidyMoney().multiply(new BigDecimal(jsonObj.getRegularShift()))));
- }
- }
- }
- }
- }
- }
- /**
- * @param hm_cache
- * @param id
- * @return
- */
- private List<UserAttendanceDetailEntity> getUserAttendanceDetailEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat) {
- // TODO Auto-generated method stub
- // findByProperty(UserAttendanceDetailEntity.class, "attendanceId",
- // uat.getId());
- HashMap<String, Object> hm = hm_cache.get("getUserAttendanceDetailEntityWithCache");
- String month = uat.getYearmonth();
- List<UserAttendanceDetailEntity> list = null;
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getUserAttendanceDetailEntityWithCache", hm);
- String hql = "from UserAttendanceDetailEntity where ymd_date like '" + month + "%'";
- List<UserAttendanceDetailEntity> entitiesFromDB = findHql(hql);
- for (UserAttendanceDetailEntity entity : entitiesFromDB) {
- String userInEntity = entity.getAttendanceId();
- if (hm.containsKey(userInEntity)) {
- List<UserAttendanceDetailEntity> entitylist = (List<UserAttendanceDetailEntity>) hm.get(userInEntity);
- entitylist.add(entity);
- } else {
- List<UserAttendanceDetailEntity> newlist = new ArrayList<>();
- newlist.add(entity);
- hm.put(userInEntity, newlist);
- }
- }
- }
- return (List<UserAttendanceDetailEntity>) hm.get(uat.getId());
- }
- public AttendanceTotalJsonObj getTotalJsonObjFromString(String jsonobjString) {
- AttendanceTotalJsonObj jsonObj = new AttendanceTotalJsonObj();
- if (oConvertUtils.isNotEmpty(jsonobjString)) {
- try {
- jsonObj = (JSONObject.parseObject(jsonobjString)).toJavaObject(AttendanceTotalJsonObj.class);
- } catch (Exception e) {
- }
- }
- return jsonObj;
- }
- /**
- * 工资扣除事项
- *
- * @param uat
- * @param us
- * @param uw
- * @param flag
- * 是否考勤扣:true扣除,false不扣除
- * @return
- */
- private UserNewWageEntity deductionCalculation(UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per, boolean flag) {
- if (uat == null) {
- uw.setSickLeaveDebit(new BigDecimal(0));
- uw.setThingLeaveDebit(new BigDecimal(0));
- uw.setAbsenceDebit(new BigDecimal(0));
- } else {
- if (Globals.MANAGETYPE_2.toString().equals(per.getManagerType())) {
- // 按照合同年限来扣除病假 zy20180417
- calcuSickLeaveDebit(uat, uw, per);
- // if(jsonObj != null && jsonObj.getSickLeavetotalmins() != null &&
- // jsonObj.getSickLeavetotalmins().intValue() != 0){
- //
- // //病假时长由分钟转小时
- // BigDecimal bigs = jsonObj.getSickLeavetotalmins().divide(new
- // BigDecimal(60),3,BigDecimal.ROUND_HALF_UP);
- // //协议员工扣除全部费用
- // if(Globals.STAFFTYPE_1.toString().equals(per.getUserType())){
- // uw.setSickLeaveDebit((Globals.BASE_PAY.divide(new
- // BigDecimal(21.75*8),3,BigDecimal.ROUND_HALF_UP).multiply(bigs)));
- // }else{
- // BigDecimal bigDecimal = new BigDecimal(0);
- // int sicleave = bigs.divide(new
- // BigDecimal(8),3,BigDecimal.ROUND_HALF_UP).intValue();
- // BigDecimal baseBigDecimal = uw.getBasicWage().divide(new
- // BigDecimal(8*21.75),3,BigDecimal.ROUND_HALF_UP).multiply(bigs);
- // if(sicleave < 2){
- // bigDecimal = baseBigDecimal.multiply(new BigDecimal(0.4));
- // }else if(sicleave >= 2 && sicleave < 4){
- // bigDecimal = baseBigDecimal.multiply(new BigDecimal(0.3));
- // }else if(sicleave >= 4){
- // bigDecimal = baseBigDecimal.multiply(new BigDecimal(0.2));
- // }
- // //一线员工扣除的金额不能高于最低工资的20%
- // uw.setSickLeaveDebit((bigDecimal.intValue() >= Globals.BASE_PAY.multiply(new
- // BigDecimal(0.2)).intValue())?Globals.BASE_PAY.multiply(new
- // BigDecimal(0.2)):bigDecimal);
- // }
- // }else{
- // uw.setSickLeaveDebit(new BigDecimal(0));
- // }
- // 事假扣
- if (flag) {
- if (uat.getThingLeave() != null && uat.getThingLeave().intValue() != 0) {
- if (uat.getTimeoutOvertimeDuration().compareTo(BigDecimal.ZERO) >= 0) {
- // 超时加班工时大于等于零=实际工时已经扣除了事假时长,故不再扣除事假扣
- uw.setThingLeaveDebit(new BigDecimal(0));
- } else {
- // 超时工时小于零,说明超时工时不够抵扣事假。那么不扣超时加班费,但是要扣事假扣除和缺勤扣除
- 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)));
- }
- } else {
- uw.setThingLeaveDebit(new BigDecimal(0));
- }
- } else {
- uw.setThingLeaveDebit(new BigDecimal(0));
- }
- // 缺勤扣
- if (flag) {
- if (uat.getAbsenteeismAmount() != null && uat.getAbsenteeismAmount().intValue() != 0) {
- if (uat.getTimeoutOvertimeDuration().compareTo(BigDecimal.ZERO) >= 0) {
- // 超时加班工时大于等于零=实际工时已经扣除了缺勤时长,故不再扣除缺勤扣
- uw.setAbsenceDebit(new BigDecimal(0));
- } else {
- // 超时工时小于零,说明超时工时不够抵扣缺勤。那么不扣超时加班费,但是要扣事假扣除和缺勤扣除
- 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));
- }
- } else {
- uw.setAbsenceDebit(new BigDecimal(0));
- }
- } else {
- uw.setAbsenceDebit(new BigDecimal(0));
- }
- } else {
- uw.setSickLeaveDebit(new BigDecimal(0));
- uw.setThingLeaveDebit(new BigDecimal(0));
- uw.setAbsenceDebit(new BigDecimal(0));
- }
- }
- /*
- * //社保扣除 if(StringUtils.isNotEmpty(us.getSocialSecurityStrategyid())){
- * str.delete(0,str.length());
- * str.append("select * from t_bus_social_security_strategy where id = '"+us.
- * getSocialSecurityStrategyid()+"'"); str.insert(str.length(), st);
- * List<SocialSecurityStrategyEntity> social =
- * this.getSession().createSQLQuery(str.toString()).addEntity(
- * SocialSecurityStrategyEntity.class).list();
- * //List<SocialSecurityStrategyEntity> social = findListbySql(str.toString());
- * if(!social.isEmpty() && social.size() > 0){ SocialSecurityStrategyEntity meal
- * = social.get(0); //multiply(meal.getPersonalBasicRetireInsu().add(meal.
- * getPersionalBasicMedicalInsu().add(meal.getPersonalUnemploymentInsu()))).
- * multiply(new BigDecimal(0.01))
- *//**
- * 社保个人金额: 中间各项目计算结果:四舍五入,保留1位小数; 合计:四舍五入,保留1位小数;
- */
- /*
- * uw.setSocialSecurityDebit(new BigDecimal(0));
- * uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().
- * multiply(meal.getPersonalBasicRetireInsu().multiply(new
- * BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_HALF_UP)));
- * uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().
- * multiply(meal.getPersionalBasicMedicalInsu().multiply(new
- * BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_HALF_UP)));
- * uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().
- * multiply(meal.getPersonalUnemploymentInsu().multiply(new
- * BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_HALF_UP)));
- *//**
- * 社保单位金额: 中间各项目计算结果:四舍五入,保留4位小数; 合计:四舍五入,保留4位小数;
- *//*
- * uw.setComSocialSecurityDebit(new BigDecimal(0));
- * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
- * getBasePay().multiply(meal.getCompanyBasicRetireInsu().multiply(new
- * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
- * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
- * getBasePay().multiply(meal.getCompanyBasicMedicalInsu().multiply(new
- * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
- * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
- * getBasePay().multiply(meal.getCompanyUnemploymentInsu().multiply(new
- * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
- * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
- * getBasePay().multiply(meal.getCompanyInjuryInsu().multiply(new
- * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
- * uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.
- * getBasePay().multiply(meal.getCompanyMaternityInsu().multiply(new
- * BigDecimal(0.01))).setScale(4,BigDecimal.ROUND_HALF_UP)));
- *
- * uw.setComSocialSecurityDebit(meal.getBasePay().multiply(meal.
- * getCompanyBasicRetireInsu().add(meal.getCompanyBasicMedicalInsu())
- * .add(meal.getCompanyUnemploymentInsu()).add(meal.getCompanyInjuryInsu()).add(
- * meal.getCompanyMaternityInsu())).multiply(new BigDecimal(0.01))); }else{
- * uw.setSocialSecurityDebit(new BigDecimal(0)); } }else{
- * uw.setSocialSecurityDebit(new BigDecimal(0)); } //公积金扣除
- * if(StringUtils.isNotEmpty(us.getProvidentFundStrategyid())){
- * str.delete(0,str.length());
- * str.append("select * from t_bus_provident_fund_strategy where id = '"+us.
- * getProvidentFundStrategyid()+"'"); str.insert(str.length(), st);
- * List<ProvidentFundStrategyEntity> perobident =
- * this.getSession().createSQLQuery(str.toString()).addEntity(
- * ProvidentFundStrategyEntity.class).list();
- * //List<ProvidentFundStrategyEntity> perobident =
- * findListbySql(str.toString()); if(!perobident.isEmpty() && perobident.size()
- * > 0){ ProvidentFundStrategyEntity meal = perobident.get(0);
- * //uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio()
- * .multiply(new BigDecimal(0.01))));
- * uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio().
- * multiply(new BigDecimal(0.01))).setScale(0,BigDecimal.ROUND_HALF_UP));
- * //uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio
- * ().multiply(new BigDecimal(0.01))));
- * uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio()
- * .multiply(new BigDecimal(0.01))).setScale(0,BigDecimal.ROUND_HALF_UP));
- * }else{ uw.setProvidentFundDebit(new BigDecimal(0)); } }else{
- * uw.setProvidentFundDebit(new BigDecimal(0)); } //缴金补贴
- * if(Globals.MANAGETYPE_2.toString().equals(per.getManagerType())){
- * uw.setPaymentSubsidy(uw.getSocialSecurityDebit().add(uw.getProvidentFundDebit
- * ())); }else{ uw.setPaymentSubsidy(new BigDecimal(0)); }
- */
- return uw;
- }
- /**
- * 按照合同年限来扣除病假 zy20180417
- *
- * @param uat
- * @param uw
- * @param per
- */
- private void calcuSickLeaveDebit(UserAttendanceTotalEntity uat, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) {
- AttendanceTotalJsonObj jsonObj = getTotalJsonObjFromString(uat.getJsonObj());
- // 病假扣
- // 按照合同年限来扣除病假 zy20180417
- if (jsonObj != null && jsonObj.getSickLeavetotalmins() != null && jsonObj.getSickLeavetotalmins().intValue() != 0) {
- BigDecimal sickDebit = BigDecimal.ZERO;
- BigDecimal multiRate = BigDecimal.ZERO;
- // 获取工作年限
- int workYear = getWorkYears(per);
- // 获取员工基本工资
- BigDecimal basewage = uw.getBasicWage();
- // 病假时长由分钟转小时
- BigDecimal bigs = jsonObj.getSickLeavetotalmins().divide(new BigDecimal(60), 3, BigDecimal.ROUND_HALF_UP);
- multiRate = basewage.divide(new BigDecimal(21.75 * 8), 3, BigDecimal.ROUND_HALF_UP).multiply(bigs);
- // 协议员工扣除全部费用
- if (Globals.STAFFTYPE_1.toString().equals(per.getUserType())) {
- uw.setSickLeaveDebit(multiRate);
- } else {
- if (workYear < 2) {
- sickDebit = multiRate.multiply(new BigDecimal(0.4));
- } else if (workYear >= 2 && workYear < 4) {
- sickDebit = multiRate.multiply(new BigDecimal(0.3));
- } else if (workYear >= 4 && workYear < 10) {
- sickDebit = multiRate.multiply(new BigDecimal(0.2));
- } else if (workYear >= 10) {
- sickDebit = BigDecimal.ZERO;
- }
- // 一线员工扣除的金额不能高于最低工资的20%
- BigDecimal limit = basewage.multiply(new BigDecimal(0.2));
- if (sickDebit.compareTo(limit) <= 0) {
- uw.setSickLeaveDebit(sickDebit);
- } else {
- uw.setSickLeaveDebit(limit);
- }
- }
- } else {
- uw.setSickLeaveDebit(new BigDecimal(0));
- }
- }
- /**
- * 返回工作年限
- *
- * @param per
- * @return
- */
- private int getWorkYears(PersonnelBaseArchivesManageOutDto per) {
- try {
- Date startDate = per.getContractStime();
- Calendar startCalendar = Calendar.getInstance();
- Calendar endCalendar = Calendar.getInstance();
- startCalendar.setTime(startDate);
- if (endCalendar.compareTo(startCalendar) < 0) {
- return 0;
- }
- int day = endCalendar.get(Calendar.DAY_OF_MONTH) - startCalendar.get(Calendar.DAY_OF_MONTH);
- int month = endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
- int year = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
- if (day < 0) {
- month--;
- }
- if (month < 0) {
- month += 12;
- year--;
- }
- if (year > 0) {
- return year;
- }
- } catch (Exception e) {
- }
- return 0;
- }
- // private UserNewWageEntity comCost(UserAttendanceTotalEntity uat
- // ,UserNewWagestrategyEntity us,UserNewWageEntity
- // uw,PersonnelBaseArchivesManageOutDto per){
- // BigDecimal result = BigDecimal.ZERO;
- // if(uw.getPreTaxMone() != null) {
- // result = result.add(uw.getPreTaxMone());
- // }
- // if(uw.getComSocialSecurityDebit() != null) {
- // result = result.add(uw.getComSocialSecurityDebit());
- // }
- // if(uw.getComProvidentFundDebit() != null) {
- // result = result.add(uw.getComProvidentFundDebit());
- // }
- // return uw;
- // }
- /**
- * 查询社保和公积金
- *
- * @param hm_cache
- * @param uat
- * @param us
- * @param uw
- * @param per
- * @return
- */
- private UserNewWageEntity socialSecurityProvidentFund(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw,
- PersonnelBaseArchivesManageOutDto per) {
- StringBuffer str = new StringBuffer();
- String st = " and status = 0 and delete_flag = 0";
- // 社保扣除
- if (StringUtils.isNotEmpty(us.getSocialSecurityStrategyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_social_security_strategy where id = '" + us.getSocialSecurityStrategyid() + "'");
- str.insert(str.length(), st);
- // List<SocialSecurityStrategyEntity> social =
- // this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list();
- // List<SocialSecurityStrategyEntity> social = findListbySql(str.toString());
- SocialSecurityStrategyEntity social = null;
- if (isCacheUsed) {
- social = getSocialSecurityStrategyEntityWithCache(hm_cache, us.getSocialSecurityStrategyid());
- } else {
- List<SocialSecurityStrategyEntity> socialList = this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list();
- if (socialList != null && socialList.size() > 0) {
- social = socialList.get(0);
- }
- }
- if (social != null) {
- SocialSecurityStrategyEntity meal = social;
- uw.setSocialSecurityId(meal.getId());
- uw.setSocialSecurityUnit(meal.getSocialSecurityUnit());
- // multiply(meal.getPersonalBasicRetireInsu().add(meal.getPersionalBasicMedicalInsu().add(meal.getPersonalUnemploymentInsu()))).multiply(new
- // BigDecimal(0.01))
- if (Globals.SOCIAL_SECURITY_STRATEGY_HUZHOU.equals(social.getId())) {
- huzhouSocialSecurityCalcu(uw, social);
- } else {
- normalSocialSecurityCalcu(uw, social);
- }
- // /**
- // * 社保个人金额:
- // 中间各项目计算结果:直接进位,保留1位小数;
- // 合计:直接进位,保留1位小数;
- // */
- // uw.setSocialSecurityDebit(new BigDecimal(0));
- // uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersonalBasicRetireInsu().multiply(new
- // BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_UP)));
- // uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersionalBasicMedicalInsu().multiply(new
- // BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_UP)));
- // uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getPersonalUnemploymentInsu().multiply(new
- // BigDecimal(0.01))).setScale(1,BigDecimal.ROUND_UP)));
- // //合计值保留一位
- // uw.setSocialSecurityDebit(uw.getSocialSecurityDebit().setScale(1,BigDecimal.ROUND_UP));
- // /**
- // * 社保单位金额:
- // * 中间各项目计算结果:四舍五入,保留3位小数;
- // * 合计:四舍五入,保留2位小数;
- // */
- // uw.setComSocialSecurityDebit(new BigDecimal(0));
- // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyBasicRetireInsu().multiply(new
- // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
- // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyBasicMedicalInsu().multiply(new
- // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
- // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyUnemploymentInsu().multiply(new
- // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
- // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyInjuryInsu().multiply(new
- // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
- // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().add(meal.getBasePay().multiply(meal.getCompanyMaternityInsu().multiply(new
- // BigDecimal(0.01))).setScale(3,BigDecimal.ROUND_HALF_UP)));
- // uw.setComSocialSecurityDebit(uw.getComSocialSecurityDebit().setScale(2,BigDecimal.ROUND_HALF_UP));
- /*
- * uw.setComSocialSecurityDebit(meal.getBasePay().multiply(meal.
- * getCompanyBasicRetireInsu().add(meal.getCompanyBasicMedicalInsu())
- * .add(meal.getCompanyUnemploymentInsu()).add(meal.getCompanyInjuryInsu()).add(
- * meal.getCompanyMaternityInsu())).multiply(new BigDecimal(0.01)));
- */
- } else {
- uw.setSocialSecurityDebit(new BigDecimal(0));
- uw.setComSocialSecurityDebit(new BigDecimal(0));
- }
- } else {
- uw.setSocialSecurityDebit(new BigDecimal(0));
- uw.setComSocialSecurityDebit(new BigDecimal(0));
- }
- // 公积金扣除
- if (StringUtils.isNotEmpty(us.getProvidentFundStrategyid())) {
- ProvidentFundStrategyEntity perobident = null;
- if (isCacheUsed) {
- perobident = getProvidentFundStrategyEntityWithCache(hm_cache, us.getProvidentFundStrategyid());
- } else {
- str.delete(0, str.length());
- str.append("select * from t_bus_provident_fund_strategy where id = '" + us.getProvidentFundStrategyid() + "'");
- str.insert(str.length(), st);
- List<ProvidentFundStrategyEntity> perobidentList = this.getSession().createSQLQuery(str.toString()).addEntity(ProvidentFundStrategyEntity.class).list();
- if (perobidentList != null && perobidentList.size() > 0) {
- perobident = perobidentList.get(0);
- }
- }
- if (perobident != null) {
- ProvidentFundStrategyEntity meal = perobident;
- // uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio().multiply(new
- // BigDecimal(0.01))));
- uw.setProvidentFundDebit(meal.getBasePay().multiply(meal.getPersonalRatio().multiply(new BigDecimal(0.01))).setScale(0, BigDecimal.ROUND_HALF_UP));
- // uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio().multiply(new
- // BigDecimal(0.01))));
- uw.setComProvidentFundDebit(meal.getBasePay().multiply(meal.getCompanyRatio().multiply(new BigDecimal(0.01))).setScale(0, BigDecimal.ROUND_HALF_UP));
- } else {
- uw.setProvidentFundDebit(new BigDecimal(0));
- uw.setComProvidentFundDebit(new BigDecimal(0));
- }
- } else {
- uw.setProvidentFundDebit(new BigDecimal(0));
- uw.setComProvidentFundDebit(new BigDecimal(0));
- }
- // 缴金补贴
- java.lang.String jiaojin_subsidy = us.getJiaojinSubsidyid();
- // zy20180428 如果工资策略里没有设定缴金补贴,则按照原始缴扣进行补贴.否则按照工资策略补贴
- if (jiaojin_subsidy == null) {
- uw.setPaymentSubsidy(uw.getSocialSecurityDebit().add(uw.getProvidentFundDebit()));
- } else {
- uw.setPaymentSubsidy(BigDecimal.ZERO);
- BigDecimal jiaonjinMoney = getJiaoJinSubsidyMoney(isCacheUsed, hm_cache, uw, us, per);
- if(jiaonjinMoney != null) {
- uw.setPaymentSubsidy(jiaonjinMoney);
- }
- }
- return uw;
- }
- /**
- * @param isCacheUsed
- * @param hm_cache
- * @param uw
- * @param us
- * @param per
- * @return
- */
- private BigDecimal getJiaoJinSubsidyMoney(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) {
- if(Globals.JIAOJIN_DEFAULT_SUBSIDY_ID.equals(us.getJiaojinSubsidyid())) {
- return uw.getProvidentFundDebit().add(uw.getSocialSecurityDebit());
- }
- if(Globals.JIAOJIN_NO_SUBSIDY_ID.equals(us.getJiaojinSubsidyid())) {
- return BigDecimal.ZERO;
- }
-
- JiaojinSubsidyStrategyEntity jiaojinEntity = getJiaojinEntityWithCache(hm_cache, us.getJiaojinSubsidyid());
- if(jiaojinEntity != null) {
- return jiaojinEntity.getMoney();
- }
-
- return BigDecimal.ZERO;
- }
- /**
- * @param hm_cache
- * @param jiaojinSubsidyid
- * @return
- */
- private JiaojinSubsidyStrategyEntity getJiaojinEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String jiaojinSubsidyid) {
- HashMap<String, Object> hm = hm_cache.get("getJiaojinEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getJiaojinEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(JiaojinSubsidyStrategyEntity.class);
- List<JiaojinSubsidyStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (JiaojinSubsidyStrategyEntity entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (JiaojinSubsidyStrategyEntity) hm.get(jiaojinSubsidyid);
- }
- /**
- * @param hm_cache
- * @param providentFundStrategyid
- * @return
- */
- private ProvidentFundStrategyEntity getProvidentFundStrategyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String providentFundStrategyid) {
- HashMap<String, Object> hm = hm_cache.get("getProvidentFundStrategyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getProvidentFundStrategyEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(ProvidentFundStrategyEntity.class);
- specialcq.eq("deleteFlag", "0");
- specialcq.add();
- specialcq.eq("status", "0");
- specialcq.add();
- List<ProvidentFundStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (ProvidentFundStrategyEntity entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (ProvidentFundStrategyEntity) hm.get(providentFundStrategyid);
- }
- /**
- * @param hm_cache
- * @param socialSecurityStrategyid
- * @return
- */
- private SocialSecurityStrategyEntity getSocialSecurityStrategyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String socialSecurityStrategyid) {
- HashMap<String, Object> hm = hm_cache.get("getSocialSecurityStrategyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getSocialSecurityStrategyEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(SocialSecurityStrategyEntity.class);
- specialcq.eq("deleteFlag", "0");
- specialcq.add();
- specialcq.eq("status", "0");
- specialcq.add();
- List<SocialSecurityStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (SocialSecurityStrategyEntity entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (SocialSecurityStrategyEntity) hm.get(socialSecurityStrategyid);
- }
- /**
- * 加班统计
- *
- * @param hm_cache
- * @param uat
- * @param us
- * @param uw
- * @return
- */
- private UserNewWageEntity overtimeCalculation(boolean isCacheUsed, HashMap<String, HashMap<String, Object>> hm_cache, UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw, String month,
- PersonnelBaseArchivesManageOutDto per) {
- StringBuffer str = new StringBuffer();
- String st = " and status = 0 and delete_flag = 0";
- if (uat == null) {
- uw.setOvertimepayTimeout(new BigDecimal(0.00));
- uw.setOvertimepayFixed(new BigDecimal(0));
- uw.setDuty(new BigDecimal(0));
- uw.setSpecialOvertime(new BigDecimal(0));
- } else {
- // if("ff808081645a0e3d0164d097628a07f3".equals(uat.getUserId())) {
- // System.out.println("wu");
- // }
- // 超时加班费
- if (uat.getTimeoutOvertimeDuration() != null && uat.getTimeoutOvertimeDuration().intValue() > 0) {
- ArrangeDutyOperateEntity arrange = getArrangeDutyOperateEntityWithCache(hm_cache, month, us.getUserid());
- if (arrange == null || arrange.getRunway().contains("jijiabanfei")) {
- // 轮转方式为空,默认给加班费
- OvertimepayStrategyEntity overtimepaystrate = null;
- if (isCacheUsed) {
- overtimepaystrate = getOvertimepayStrategyEntityWithCache(hm_cache, us.getOvertimepayStrategyid());
- } else {
- str.delete(0, str.length());
- str.append("select * from t_bus_overtimepay_strategy where id = '" + us.getOvertimepayStrategyid() + "'");
- str.insert(str.length(), st);
- List<OvertimepayStrategyEntity> overtimepaystrateList = this.getSession().createSQLQuery(str.toString()).addEntity(OvertimepayStrategyEntity.class).list();
- if (overtimepaystrateList != null && overtimepaystrateList.size() > 0) {
- overtimepaystrate = overtimepaystrateList.get(0);
- }
- }
- if (overtimepaystrate != null) {
- 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)));
- } else {
- uw.setOvertimepayTimeout(new BigDecimal(0.00));
- }
- } else {
- uw.setOvertimepayTimeout(new BigDecimal(0.00));
- }
- } else {
- uw.setOvertimepayTimeout(new BigDecimal(0.00));
- }
- // 国家法定加班费
- // 两部分:一部分是国定超时加班,另一部分是国定值班,国定值班费在值班费的代码里计算 zy20180416
- if (uat.getNationalOvertimeDuration() != null && uat.getNationalOvertimeDuration().intValue() > 0) {
- WagestrategyDto wa = getWagestrategyDto(isCacheUsed, hm_cache, per);
- if (wa != null) {
- if (per != null && "2".equals(per.getManagerType())) {
- 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)));
- } else {
- uw.setOvertimepayFixed(new BigDecimal(0));
- }
- }
- } else {
- uw.setOvertimepayFixed(new BigDecimal(0));
- }
- // 值班费 duty_duration
- if (uat.getDutyDuration() != null && StringUtils.isNotEmpty(us.getDutyStrategyid())) {
- // str.delete(0,str.length());
- // str.append("select * from t_bus_dutyfee_strategy where id =
- // '"+us.getDutyStrategyid()+"'");
- // str.insert(str.length(), st);
- // List<DutyfeeStrategyEntity> mealList =
- // this.getSession().createSQLQuery(str.toString()).addEntity(DutyfeeStrategyEntity.class).list();
- DutyfeeStrategyEntity dutyfee = null;
- if (isCacheUsed) {
- dutyfee = getDutyfeeStrategyEntityWithCache(hm_cache, us.getDutyStrategyid());
- } else {
- str.delete(0, str.length());
- str.append("select * from t_bus_dutyfee_strategy where id = '" + us.getDutyStrategyid() + "'");
- str.insert(str.length(), st);
- List<DutyfeeStrategyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(DutyfeeStrategyEntity.class).list();
- if (mealList != null && mealList.size() > 0) {
- dutyfee = mealList.get(0);
- }
- }
- // List<DutyfeeStrategyEntity> mealList = findListbySql(str.toString());
- if (dutyfee != null) {
- DutyfeeStrategyEntity meal = dutyfee;
- uw.setDuty(uat.getDutyDuration().multiply(meal.getMoney()));
- // 把国定值班费算到国定加班zyzy20180416
- BigDecimal nationaltimeoutPay = uw.getOvertimepayFixed(); // 已有的国定超时加班费
- BigDecimal nationaldutyPay = meal.getMoney().multiply(new BigDecimal(3)).multiply(uat.getNationalDutyDuration()); // 3倍普通值班费*国定值班天数
- uw.setOvertimepayFixed(nationaltimeoutPay.add(nationaldutyPay)); // 两部分都赋值到国定加班费里
- } else {
- uw.setDuty(new BigDecimal(0));
- }
- } else {
- uw.setDuty(new BigDecimal(0));
- }
- // 适配新的加班申请 2019-12-05
- OvertimeDto overtimedto = getSpecialOvertimeSumEntityWithCache(hm_cache, per.getUserId(), month);
- if(overtimedto != null) {
- uw.setSpecialOvertime(overtimedto.getOvertimeFee() == null ? BigDecimal.ZERO : overtimedto.getOvertimeFee());
- }else {
- uw.setSpecialOvertime(new BigDecimal(0));
- }
- }
- return uw;
- }
- /**
- * @param hm_cache
- * @param month
- * @param userid
- * @return
- */
- private ArrangeDutyOperateEntity getArrangeDutyOperateEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String month, String userid) {
- // this.getSession().createSQLQuery("select * from t_bus_arrangeduty_operate
- // where userid like '%"+us.getUserid()+"%' and yearmonth =
- // '"+month+"'").addEntity(ArrangeDutyOperateEntity.class).list();
- HashMap<String, Object> hm = hm_cache.get("getArrangeDutyOperateEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getArrangeDutyOperateEntityWithCache", hm);
- List<ArrangeDutyOperateEntity> entitiesFromDB = this.getSession().createSQLQuery("select * from t_bus_arrangeduty_operate where yearmonth = '" + month + "'").addEntity(ArrangeDutyOperateEntity.class).list();
- hm.put("ALL", entitiesFromDB);
- }
- List<ArrangeDutyOperateEntity> entitiesFromDB = (List<ArrangeDutyOperateEntity>) hm.get("ALL");
- if (entitiesFromDB != null && entitiesFromDB.size() > 0) {
- for (ArrangeDutyOperateEntity entity : entitiesFromDB) {
- if (entity != null) {
- String userids = entity.getUserid();
- if (userids.indexOf(userid) > -1) {
- return entity;
- }
- }
- }
- }
- return null;
- }
- /**
- * @param hm_cache
- * @param dutyStrategyid
- * @return
- */
- private DutyfeeStrategyEntity getDutyfeeStrategyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String dutyStrategyid) {
- HashMap<String, Object> hm = hm_cache.get("getDutyfeeStrategyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getDutyfeeStrategyEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(DutyfeeStrategyEntity.class);
- specialcq.eq("deleteFlag", "0");
- specialcq.add();
- specialcq.eq("status", "0");
- specialcq.add();
- List<DutyfeeStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (DutyfeeStrategyEntity entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (DutyfeeStrategyEntity) hm.get(dutyStrategyid);
- }
- /**
- * @param hm_cache
- * @param overtimepayStrategyid
- * @return
- */
- private OvertimepayStrategyEntity getOvertimepayStrategyEntityWithCache(HashMap<String, HashMap<String, Object>> hm_cache, String overtimepayStrategyid) {
- // TODO Auto-generated method stub
- HashMap<String, Object> hm = hm_cache.get("getOvertimepayStrategyEntityWithCache");
- if (hm == null) {
- hm = new HashMap<>();
- hm_cache.put("getOvertimepayStrategyEntityWithCache", hm);
- CriteriaQuery specialcq = new CriteriaQuery(OvertimepayStrategyEntity.class);
- specialcq.eq("deleteFlag", "0");
- specialcq.add();
- specialcq.eq("status", "0");
- specialcq.add();
- List<OvertimepayStrategyEntity> entitiesFromDB = getListByCriteriaQuery(specialcq, false);
- for (OvertimepayStrategyEntity entity : entitiesFromDB) {
- hm.put(entity.getId(), entity);
- }
- }
- return (OvertimepayStrategyEntity) hm.get(overtimepayStrategyid);
- }
- /**
- * 查询保存员工工资策略设定历史表
- *
- * @param uwh
- * @param us
- * @return
- */
- private UserWagestrategyHistoryEntity historyUW(UserWagestrategyHistoryEntity uwh, UserNewWagestrategyEntity us) {
- StringBuffer str = new StringBuffer();
- String st = " and status = 0 and delete_flag = 0";
- // 职务
- if (StringUtils.isNotEmpty(us.getDutiesid())) {
- DutiesEntity dut = get(DutiesEntity.class, us.getDutiesid());
- uwh.setDutiesName(dut.getDutiesName());
- }
- // 证书补贴
- if (StringUtils.isNotEmpty(us.getCertificateSubsidyid())) {
- String[] certificteStrings = us.getCertificateSubsidyid().split(",");
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < certificteStrings.length; i++) {
- str.delete(0, str.length());
- str.append("select * from t_bus_certificate_subsidy where id = '" + certificteStrings[i] + "'");
- str.insert(str.length(), st);
- List<CertificateSubsidyEntity> usList = this.getSession().createSQLQuery(str.toString()).addEntity(CertificateSubsidyEntity.class).list();
- // List<CertificateSubsidyEntity> usList = findListbySql(str.toString());
- if (!usList.isEmpty()) {
- CertificateSubsidyEntity cer = usList.get(0);
- if (i == 0) {
- buffer.append(cer.getCertificateName() + "-" + cer.getSubsidyMoney() + "元");
- } else {
- buffer.append("," + cer.getCertificateName() + "-" + cer.getSubsidyMoney() + "元");
- }
- }
- }
- uwh.setCertificateSubsidyDesc(buffer.toString());
- }
- // 交通补贴
- // if (StringUtils.isNotEmpty(us.getTrafficSubsidyid())) {
- // str.delete(0, str.length());
- // str.append("select * from t_bus_traffic_subsidy where id ='" + us.getTrafficSubsidyid() + "'");
- // str.insert(str.length(), st);
- // List<TrafficSubsidyEntity> trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(TrafficSubsidyEntity.class).list();
- // // List<TrafficSubsidyEntity> trafficSubsidyList =
- // // this.findListbySql(str.toString());
- // if (oConvertUtils.isNotEmpty(trafficSubsidyList)) {
- // uwh.setTrafficSubsidyDesc(trafficSubsidyList.get(0).getSubsidyName() + "-" + trafficSubsidyList.get(0).getSubsidyMoney() + "元");
- // }
- // }
- // 高温补贴
- if (StringUtils.isNotEmpty(us.getMegathermalSubsidyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_megathermal_subsidy where id ='" + us.getMegathermalSubsidyid() + "'");
- str.insert(str.length(), st);
- List<MegathermalSubsidyEntity> trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(MegathermalSubsidyEntity.class).list();
- // List<MegathermalSubsidyEntity> trafficSubsidyList =
- // this.findListbySql(str.toString());
- if (oConvertUtils.isNotEmpty(trafficSubsidyList)) {
- uwh.setMegathermalSubsidyDesc(trafficSubsidyList.get(0).getSubsidyName() + "-" + trafficSubsidyList.get(0).getSubsidyMoney() + "元");
- }
- }
- // 独生子女费
- if (us.getOnlychildPay() != null) {
- uwh.setOnlychildPay(us.getOnlychildPay());
- }
- // 其他补贴
- if (StringUtils.isNotEmpty(us.getOtherSubsidyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_other_subsidy where id ='" + us.getOtherSubsidyid() + "'");
- str.insert(str.length(), st);
- List<OtherSubsidyEntity> trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(OtherSubsidyEntity.class).list();
- // List<OtherSubsidyEntity> trafficSubsidyList =
- // this.findListbySql(str.toString());
- if (oConvertUtils.isNotEmpty(trafficSubsidyList)) {
- uwh.setOtherSubsidyDesc(trafficSubsidyList.get(0).getSubsidyName() + "-" + trafficSubsidyList.get(0).getSubsidyMoney() + "元");
- }
- }
- // 餐补方式 0.每月固定 1.每月班次
- uwh.setStrategyType(us.getStrategyType());
- // 额外加班
- if (StringUtils.isNotEmpty(us.getNofixedmealsSubsidyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_meals_subsidy where id = '" + us.getNofixedmealsSubsidyid() + "'");
- str.insert(str.length(), st);
- List<MealsSubsidyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(MealsSubsidyEntity.class).list();
- // List<MealsSubsidyEntity> mealList = findListbySql(str.toString());
- if (!mealList.isEmpty() && mealList.size() > 0) {
- MealsSubsidyEntity meal = mealList.get(0);
- uwh.setNofixedmealsSubsidyDesc(meal.getSubsidyName() + "-" + meal.getSubsidyMoney() + "元");
- }
- }
- // 每月固定餐补
- if (StringUtils.isNotEmpty(us.getFixedmealsSubsidyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_meals_subsidy where id = '" + us.getFixedmealsSubsidyid() + "'");
- str.insert(str.length(), st);
- List<MealsSubsidyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(MealsSubsidyEntity.class).list();
- // List<MealsSubsidyEntity> mealList = findListbySql(str.toString());
- if (!mealList.isEmpty() && mealList.size() > 0) {
- MealsSubsidyEntity meal = mealList.get(0);
- uwh.setFixedmealsSubsidyDesc(meal.getSubsidyName() + "-" + meal.getSubsidyMoney() + "元");
- }
- }
- // 加班
- if (StringUtils.isNotEmpty(us.getOvertimepayStrategyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_overtimepay_strategy where id = '" + us.getOvertimepayStrategyid() + "'");
- str.insert(str.length(), st);
- List<OvertimepayStrategyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(OvertimepayStrategyEntity.class).list();
- // List<OvertimepayStrategyEntity> mealList = findListbySql(str.toString());
- if (!mealList.isEmpty() && mealList.size() > 0) {
- OvertimepayStrategyEntity meal = mealList.get(0);
- uwh.setOvertimepayStrategyDesc(meal.getStrategyName() + "-" + meal.getMultiple() + "倍");
- }
- }
- // 值班
- if (StringUtils.isNotEmpty(us.getDutyStrategyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_dutyfee_strategy where id = '" + us.getDutyStrategyid() + "'");
- str.insert(str.length(), st);
- List<DutyfeeStrategyEntity> mealList = this.getSession().createSQLQuery(str.toString()).addEntity(DutyfeeStrategyEntity.class).list();
- // List<DutyfeeStrategyEntity> mealList = findListbySql(str.toString());
- if (!mealList.isEmpty() && mealList.size() > 0) {
- DutyfeeStrategyEntity meal = mealList.get(0);
- uwh.setDutyStrategyDesc(meal.getStrategyName() + "-" + meal.getMoney() + "元");
- }
- }
- // 社保
- if (StringUtils.isNotEmpty(us.getSocialSecurityStrategyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_social_security_strategy where id = '" + us.getSocialSecurityStrategyid() + "'");
- str.insert(str.length(), st);
- List<SocialSecurityStrategyEntity> social = this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list();
- // List<SocialSecurityStrategyEntity> social = findListbySql(str.toString());
- if (!social.isEmpty() && social.size() > 0) {
- SocialSecurityStrategyEntity meal = social.get(0);
- uwh.setSocialSecurityStrategyDesc(meal.getSocialSecurityUnit());
- // 保存社保各个参数
- if (meal.getCompanyInjuryInsu() != null) {
- uwh.setCompanyInjuryInsu(meal.getCompanyInjuryInsu());
- }
- if (meal.getCompanyMaternityInsu() != null) {
- uwh.setCompanyMaternityInsu(meal.getCompanyMaternityInsu());
- }
- if (meal.getPersionalBasicMedicalInsu() != null) {
- uwh.setPersionalBasicMedicalInsu(meal.getPersionalBasicMedicalInsu());
- }
- if (meal.getCompanyBasicRetireInsu() != null) {
- uwh.setCompanyBasicRetireInsu(meal.getCompanyBasicRetireInsu());
- }
- if (meal.getBasePay() != null) {
- uwh.setSocialSecurityBasePay(meal.getBasePay());
- }
- if (meal.getPersonalUnemploymentInsu() != null) {
- uwh.setPersonalUnemploymentInsu(meal.getPersonalUnemploymentInsu());
- }
- if (meal.getCompanyBasicMedicalInsu() != null) {
- uwh.setCompanyBasicMedicalInsu(meal.getCompanyBasicMedicalInsu());
- }
- if (meal.getCompanyUnemploymentInsu() != null) {
- uwh.setCompanyUnemploymentInsu(meal.getCompanyUnemploymentInsu());
- }
- if (meal.getPersonalBasicRetireInsu() != null) {
- uwh.setPersonalBasicRetireInsu(meal.getPersonalBasicRetireInsu());
- }
- }
- }
- // 公积金
- if (StringUtils.isNotEmpty(us.getProvidentFundStrategyid())) {
- str.delete(0, str.length());
- str.append("select * from t_bus_provident_fund_strategy where id = '" + us.getProvidentFundStrategyid() + "'");
- str.insert(str.length(), st);
- List<ProvidentFundStrategyEntity> perobident = this.getSession().createSQLQuery(str.toString()).addEntity(ProvidentFundStrategyEntity.class).list();
- // List<ProvidentFundStrategyEntity> perobident = findListbySql(str.toString());
- if (!perobident.isEmpty() && perobident.size() > 0) {
- ProvidentFundStrategyEntity meal = perobident.get(0);
- uwh.setProvidentFundStrategyDesc(meal.getProvidentFundName());
- // 保存公积金各个参数
- if (meal.getPersonalRatio() != null) {
- uwh.setPersonalRatio(meal.getPersonalRatio());
- }
- if (meal.getBasePay() != null) {
- uwh.setProvidentFundBasePay(meal.getBasePay());
- }
- if (meal.getCompanyRatio() != null) {
- uwh.setCompanyRatio(meal.getCompanyRatio());
- }
- }
- }
- // 追加调整
- if (us.getAppendPay() != null) {
- uwh.setAppendPay(us.getAppendPay());
- }
- // 扣除调整
- if (us.getDeductPay() != null) {
- uwh.setDeductPay(us.getDeductPay());
- }
- // 扣除调整
- if (us.getDaikouFee() != null) {
- uwh.setDaikouFee(us.getDaikouFee());
- }
- return uwh;
- }
- @Override
- public Map<String, String> isDuties(String userid) {
- return userWageMinidaoDao.isDuties(userid);
- }
- @Override
- public void userPayrollOverride() throws Exception {
- StringBuffer hql = new StringBuffer("from UserNewWagestrategyEntity");
- List<UserNewWagestrategyEntity> userWagestrategyEntity = this.getSession().createQuery(hql.toString()).list();
- userPayroll(userWagestrategyEntity, null, "0");
- }
- }
|