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 userWagestrategyEntity, String moth, String type) throws Exception { List userWageList = null; // List uwhList = null; List userWageList1 = null; HashMap> hm_cache = new HashMap<>(); userWageList = new ArrayList(); // uwhList = new ArrayList(); // List 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 userid = new ArrayList(); 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 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> hm_cache, boolean isCacheAll, UserNewWagestrategyEntity us) { List 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> 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> hm_cache, boolean isCacheAll, UserNewWageEntity uw, List 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 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> 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> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) { String userid = us.getUserid(); String years = uw.getMonthly().split("-")[0]; HashSet 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 getProjectRatingDtosWithCache(HashMap> hm_cache, String years, String userid) { HashMap hm = hm_cache.get("getProjectAllowanceWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getProjectAllowanceWithCache", hm); MiniDaoPage entitiesPrjMiniDaoPage = projectRationgDao.getAllEntitiesNopage(years); for(ProjectRatingDto pj : entitiesPrjMiniDaoPage.getResults()) { if(pj.getJianguanLeader() != null) { if(hm.containsKey(pj.getJianguanLeader())){ HashSet list = (HashSet)hm.get(pj.getJianguanLeader()); list.add(pj); }else { HashSet list = new HashSet<>(); list.add(pj); hm.put(pj.getJianguanLeader(), list); } } if(pj.getXianchangLeader() != null) { if(hm.containsKey(pj.getXianchangLeader())){ HashSet list = (HashSet)hm.get(pj.getXianchangLeader()); list.add(pj); }else { HashSet list = new HashSet<>(); list.add(pj); hm.put(pj.getXianchangLeader(), list); } } } } return (HashSet) hm.get(userid); } /** * @param hm_cache * @param userid * @return */ private BigDecimal getOtherworkSubsidyMoneyWithCache(HashMap> hm_cache, String userid) { HashMap 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 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 subList = this.getSession().createSQLQuery(str_subsidy).addEntity(OtherworkSubsidyEntity.class).list(); HashMap 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> 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> hm_cache) { HashMap hm = hm_cache.get("getComageSubsidyEntityWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getComageSubsidyEntityWithCache", hm); CriteriaQuery specialcq = new CriteriaQuery(ComageSubsidyEntity.class); List 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> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) { BigDecimal talentAll = BigDecimal.ZERO; // 初始是0 uw.setTalentAllowance(talentAll); List 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 getUserTalentSubsidyDtosWithCache(boolean isCacheAll, HashMap> hm_cache, UserNewWagestrategyEntity us, UserNewWageEntity uw, PersonnelBaseArchivesManageOutDto per) { HashMap hm = hm_cache.get("getUserTalentSubsidyDtosWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getUserTalentSubsidyDtosWithCache", hm); List entitiesFromDB = userTalentSubsidyMiniDao.getAllEntities(isCacheAll?null:per.getUserId()).getResults(); for (UserTalentSubsidyDto entity : entitiesFromDB) { String userInEntity = entity.getUserid(); if (hm.containsKey(userInEntity)) { List entitylist = (List) hm.get(userInEntity); entitylist.add(entity); } else { List newlist = new ArrayList<>(); newlist.add(entity); hm.put(userInEntity, newlist); } } } List dtoInDB = (List) hm.get(per.getUserId()); // 把人员信息里的教育背景关联上,暂时先不关联。 joinEducationInfo(dtoInDB); return dtoInDB; } /** * @param dtoInDB */ private void joinEducationInfo(List dtoInDB) { } private List getUserAttendanceTotalEntityList(String moth, HashMap> hm_cache, boolean isCacheUsed, UserNewWagestrategyEntity us) { List uatList = null; if (isCacheUsed) { uatList = getUserAttendanceTotalEntityWithCache(hm_cache, us.getUserid(), moth); } else { uatList = userAttendanceTotalService.getByuserid(us.getUserid(), moth); } return uatList; } private PersonnelBaseArchivesManageOutDto getPersonnelDto(HashMap> hm_cache, boolean isCacheUsed, UserNewWagestrategyEntity us) { PersonnelBaseArchivesManageOutDto per = null; if (isCacheUsed) { per = getPersonnelBaseArchivesManageEntityWithCache(hm_cache, us.getUserid()); } else { MiniDaoPage minPage = personnelBaseArchivesManageDao.getEntityByUserId(us.getUserid()); per = minPage.getResults().get(0); } return per; } /** * 去重 * * @param userWagestrategyEntity * @return */ private List filterRepeatUserWagestrategy(List userWagestrategyEntity) { HashMap hm_userid = new HashMap<>(); if (userWagestrategyEntity != null) { for (UserNewWagestrategyEntity entity : userWagestrategyEntity) { hm_userid.put(entity.getUserid(), entity); } } return new ArrayList(hm_userid.values()); } /** * @param userid * @param moth * @return */ private List getUserAttendanceTotalEntityWithCache(HashMap> hm_cache, String userid, String moth) { HashMap 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 entitiesFromDB = getListByCriteriaQuery(specialcq, false); for (UserAttendanceTotalEntity entity : entitiesFromDB) { String userInEntity = entity.getUserId(); if (hm.containsKey(userInEntity)) { List entitylist = (List) hm.get(userInEntity); entitylist.add(entity); } else { List newlist = new ArrayList<>(); newlist.add(entity); hm.put(userInEntity, newlist); } } } return (List) hm.get(userid); } /** * @param hm_cache * @param userid * @return */ private PersonnelBaseArchivesManageOutDto getPersonnelBaseArchivesManageEntityWithCache(HashMap> hm_cache, String userid) { HashMap hm = hm_cache.get("getPersonnelBaseArchivesManageEntityWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getPersonnelBaseArchivesManageEntityWithCache", hm); MiniDaoPage minPage = personnelBaseArchivesManageDao.getAllEntities(); List 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> 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> hm_cache, String userid) { HashMap hm = hm_cache.get("getTSUserOrgWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getTSUserOrgWithCache", hm); List 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> hm_cache, String departid) { HashMap hm = hm_cache.get("getTSDepartWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getTSDepartWithCache", hm); List 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> 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 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> hm_cache, UserNewWageEntity uw, UserNewWagestrategyEntity us, UserAttendanceTotalEntity uat, String month, PersonnelBaseArchivesManageOutDto per, List 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> 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> 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 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> 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> hm_cache, PersonnelBaseArchivesManageOutDto per) { List 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> hm_cache , PersonnelBaseArchivesManageOutDto per, UserNewWagestrategyEntity us, WagestrategyDto wa) { HashMap 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 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 getWagestrategyEntityWithCache(boolean isCacheAll, HashMap> hm_cache, String belongDutiesid) { HashMap hm = hm_cache.get("getWagestrategyEntityWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getWagestrategyEntityWithCache", hm); MiniDaoPage 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 entitylist = (List) hm.get(userInEntity); entitylist.add(entity); } else { List newlist = new ArrayList<>(); newlist.add(entity); hm.put(userInEntity, newlist); } } } return (List) hm.get(belongDutiesid); } /** * 查询基本策略设定值 * * @param isCacheUsed * @param us * @param uw * @param per * @return */ private UserNewWageEntity selectStrategy(boolean isCacheUsed, HashMap> 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 trafficSubsidyList = // this.getSession().createSQLQuery(str.toString()).addEntity(MegathermalSubsidyEntity.class).list(); MegathermalSubsidyEntity trafficSubsidyList = getMegathermalSubsidyEntityWithCache(hm_cache, us.getMegathermalSubsidyid()); // List 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 trafficSubsidyList = * this.getSession().createSQLQuery(str.toString()).addEntity(OtherSubsidyEntity * .class).list(); //List 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> 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> hm_cache, UserNewWagestrategyEntity us, PersonnelBaseArchivesManageOutDto per) { List 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> hm_cache, String otherSubsidyid) { HashMap 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 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> hm_cache, String megathermalSubsidyid) { // TODO Auto-generated method stub HashMap 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 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> 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 trafficSubsidyList = // this.getSession().createSQLQuery(str.toString()).addEntity(TrafficSubsidyEntity.class).list(); HashMap 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 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> 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 usList = // this.getSession().createSQLQuery(certiSql).addEntity(CertificateSubsidyEntity.class).list(); // BigDecimal bigDecimal = new BigDecimal(0); HashMap 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 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 subList = this.getSession().createSQLQuery(str_subsidy).addEntity(CertificateSubsidyEntity.class).list(); HashMap 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> hm_cache, UserAttendanceTotalEntity uat, UserNewWagestrategyEntity us, UserNewWageEntity uw, List 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> hm_cache, String userid, String yearmonth) { HashMap hm = hm_cache.get("getSpecialOvertimeEntityWithCache"); if(hm == null) { hm = new HashMap<>(); hm_cache.put("getSpecialOvertimeEntityWithCache", hm); OvertimeDto dtoIn = new OvertimeDto(); dtoIn.setYearMonth(yearmonth); List 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> hm_cache, UserAttendanceTotalEntity uat, UserNewWageEntity uw, List meslList) { List 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 getUserAttendanceDetailEntityWithCache(HashMap> hm_cache, UserAttendanceTotalEntity uat) { // TODO Auto-generated method stub // findByProperty(UserAttendanceDetailEntity.class, "attendanceId", // uat.getId()); HashMap hm = hm_cache.get("getUserAttendanceDetailEntityWithCache"); String month = uat.getYearmonth(); List list = null; if (hm == null) { hm = new HashMap<>(); hm_cache.put("getUserAttendanceDetailEntityWithCache", hm); String hql = "from UserAttendanceDetailEntity where ymd_date like '" + month + "%'"; List entitiesFromDB = findHql(hql); for (UserAttendanceDetailEntity entity : entitiesFromDB) { String userInEntity = entity.getAttendanceId(); if (hm.containsKey(userInEntity)) { List entitylist = (List) hm.get(userInEntity); entitylist.add(entity); } else { List newlist = new ArrayList<>(); newlist.add(entity); hm.put(userInEntity, newlist); } } } return (List) 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 social = * this.getSession().createSQLQuery(str.toString()).addEntity( * SocialSecurityStrategyEntity.class).list(); * //List 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 perobident = * this.getSession().createSQLQuery(str.toString()).addEntity( * ProvidentFundStrategyEntity.class).list(); * //List 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> 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 social = // this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list(); // List social = findListbySql(str.toString()); SocialSecurityStrategyEntity social = null; if (isCacheUsed) { social = getSocialSecurityStrategyEntityWithCache(hm_cache, us.getSocialSecurityStrategyid()); } else { List 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 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> 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> hm_cache, String jiaojinSubsidyid) { HashMap hm = hm_cache.get("getJiaojinEntityWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getJiaojinEntityWithCache", hm); CriteriaQuery specialcq = new CriteriaQuery(JiaojinSubsidyStrategyEntity.class); List 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> hm_cache, String providentFundStrategyid) { HashMap 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 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> hm_cache, String socialSecurityStrategyid) { HashMap 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 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> 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 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 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 mealList = this.getSession().createSQLQuery(str.toString()).addEntity(DutyfeeStrategyEntity.class).list(); if (mealList != null && mealList.size() > 0) { dutyfee = mealList.get(0); } } // List 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> 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 hm = hm_cache.get("getArrangeDutyOperateEntityWithCache"); if (hm == null) { hm = new HashMap<>(); hm_cache.put("getArrangeDutyOperateEntityWithCache", hm); List entitiesFromDB = this.getSession().createSQLQuery("select * from t_bus_arrangeduty_operate where yearmonth = '" + month + "'").addEntity(ArrangeDutyOperateEntity.class).list(); hm.put("ALL", entitiesFromDB); } List entitiesFromDB = (List) 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> hm_cache, String dutyStrategyid) { HashMap 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 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> hm_cache, String overtimepayStrategyid) { // TODO Auto-generated method stub HashMap 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 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 usList = this.getSession().createSQLQuery(str.toString()).addEntity(CertificateSubsidyEntity.class).list(); // List 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 trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(TrafficSubsidyEntity.class).list(); // // List 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 trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(MegathermalSubsidyEntity.class).list(); // List 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 trafficSubsidyList = this.getSession().createSQLQuery(str.toString()).addEntity(OtherSubsidyEntity.class).list(); // List 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 mealList = this.getSession().createSQLQuery(str.toString()).addEntity(MealsSubsidyEntity.class).list(); // List 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 mealList = this.getSession().createSQLQuery(str.toString()).addEntity(MealsSubsidyEntity.class).list(); // List 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 mealList = this.getSession().createSQLQuery(str.toString()).addEntity(OvertimepayStrategyEntity.class).list(); // List 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 mealList = this.getSession().createSQLQuery(str.toString()).addEntity(DutyfeeStrategyEntity.class).list(); // List 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 social = this.getSession().createSQLQuery(str.toString()).addEntity(SocialSecurityStrategyEntity.class).list(); // List 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 perobident = this.getSession().createSQLQuery(str.toString()).addEntity(ProvidentFundStrategyEntity.class).list(); // List 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 isDuties(String userid) { return userWageMinidaoDao.isDuties(userid); } @Override public void userPayrollOverride() throws Exception { StringBuffer hql = new StringBuffer("from UserNewWagestrategyEntity"); List userWagestrategyEntity = this.getSession().createQuery(hql.toString()).list(); userPayroll(userWagestrategyEntity, null, "0"); } }