package cn.com.lzt.userwage.service.impl; import java.io.Serializable; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.jeecgframework.core.common.model.json.AjaxJson; import org.jeecgframework.core.common.service.impl.CommonServiceImpl; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.core.util.ApplicationContextUtil; import org.jeecgframework.core.util.JeecgDataAutorUtils; import org.jeecgframework.core.util.MyBeanUtils; import org.jeecgframework.core.util.MyClassLoader; import org.jeecgframework.core.util.StringUtil; import org.jeecgframework.minidao.annotation.Param; import org.jeecgframework.minidao.pojo.MiniDaoPage; import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter; import org.jeecgframework.web.system.pojo.base.TSDepart; import org.jeecgframework.web.system.pojo.base.TSUserOrg; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import cn.com.lzt.arrangeduty.dto.ProjectDepartDto; import cn.com.lzt.userwage.dao.UserWageMinidaoDao; import cn.com.lzt.userwage.dto.UserWageDto; import cn.com.lzt.userwage.dto.UserWageViewDto; import cn.com.lzt.userwage.entity.UserWageEntity; import cn.com.lzt.userwage.service.UserWageServiceI; @Service("userWageService") @Transactional public class UserWageServiceImpl extends CommonServiceImpl implements UserWageServiceI { @Autowired UserWageMinidaoDao userWageMinidaoDao; @Autowired SystemService systemService; public void delete(UserWageEntity entity) throws Exception{ super.delete(entity); //执行删除操作增强业务 this.doDelBus(entity); } public Serializable save(UserWageEntity entity) throws Exception{ Serializable t = super.save(entity); //执行新增操作增强业务 this.doAddBus(entity); return t; } public void saveOrUpdate(UserWageEntity entity) throws Exception{ super.saveOrUpdate(entity); //执行更新操作增强业务 this.doUpdateBus(entity); } /** * 新增操作增强业务 * @param t * @return */ private void doAddBus(UserWageEntity t) throws Exception{ //-----------------sql增强 start---------------------------- //-----------------sql增强 end------------------------------ //-----------------java增强 start--------------------------- //-----------------java增强 end----------------------------- } /** * 更新操作增强业务 * @param t * @return */ private void doUpdateBus(UserWageEntity t) throws Exception{ //-----------------sql增强 start---------------------------- //-----------------sql增强 end------------------------------ //-----------------java增强 start--------------------------- //-----------------java增强 end----------------------------- } /** * 删除操作增强业务 * @param id * @return */ private void doDelBus(UserWageEntity t) throws Exception{ //-----------------sql增强 start---------------------------- //-----------------sql增强 end------------------------------ //-----------------java增强 start--------------------------- //-----------------java增强 end----------------------------- } private Map populationMap(UserWageEntity t){ Map map = new HashMap(); map.put("id", t.getId()); map.put("userid", t.getUserid()); map.put("belong_unitid", t.getBelongUnitid()); map.put("dutiesid", t.getDutiesid()); map.put("monthly", t.getMonthly()); map.put("basic_wage", t.getBasicWage()); map.put("duties_allowance", t.getDutiesAllowance()); map.put("certificate_subsidy", t.getCertificateSubsidy()); map.put("traffic_subsidy", t.getTrafficSubsidy()); map.put("megathermal_subsidy", t.getMegathermalSubsidy()); map.put("only_child_cost", t.getOnlyChildCost()); map.put("other_subsidy", t.getOtherSubsidy()); map.put("bonus", t.getBonus()); map.put("project_performance", t.getProjectPerformance()); map.put("meals_subsidy_day", t.getMealsSubsidyDay()); map.put("meals_subsidy_night", t.getMealsSubsidyNight()); map.put("meals_subsidy", t.getMealsSubsidy()); map.put("overtimepay_timeout", t.getOvertimepayTimeout()); map.put("overtimepay_fixed", t.getOvertimepayFixed()); map.put("duty", t.getDuty()); map.put("special_overtime", t.getSpecialOvertime()); map.put("sick_leave_debit", t.getSickLeaveDebit()); map.put("thing_leave_debit", t.getThingLeaveDebit()); map.put("absence_debit", t.getAbsenceDebit()); map.put("payment_subsidy", t.getPaymentSubsidy()); map.put("social_security_debit", t.getSocialSecurityDebit()); map.put("provident_fund_debit", t.getProvidentFundDebit()); map.put("pre_tax_mone", t.getPreTaxMone()); map.put("other_debit", t.getOtherDebit()); map.put("daikou_debit", t.getDaikouDebit()); map.put("reissue",t.getReissue()); map.put("tax_money", t.getTaxMoney()); map.put("actual_money", t.getActualMoney()); map.put("status", t.getStatus()); map.put("remark", t.getRemark()); return map; } /** * 替换sql中的变量 * @param sql * @param t * @return */ public String replaceVal(String sql,UserWageEntity t){ sql = sql.replace("#{id}",String.valueOf(t.getId())); sql = sql.replace("#{userid}",String.valueOf(t.getUserid())); sql = sql.replace("#{belong_unitid}",String.valueOf(t.getBelongUnitid())); sql = sql.replace("#{dutiesid}",String.valueOf(t.getDutiesid())); sql = sql.replace("#{monthly}",String.valueOf(t.getMonthly())); sql = sql.replace("#{basic_wage}",String.valueOf(t.getBasicWage())); sql = sql.replace("#{duties_allowance}",String.valueOf(t.getDutiesAllowance())); sql = sql.replace("#{certificate_subsidy}",String.valueOf(t.getCertificateSubsidy())); sql = sql.replace("#{traffic_subsidy}",String.valueOf(t.getTrafficSubsidy())); sql = sql.replace("#{megathermal_subsidy}",String.valueOf(t.getMegathermalSubsidy())); sql = sql.replace("#{only_child_cost}",String.valueOf(t.getOnlyChildCost())); sql = sql.replace("#{other_subsidy}",String.valueOf(t.getOtherSubsidy())); sql = sql.replace("#{bonus}",String.valueOf(t.getBonus())); sql = sql.replace("#{project_performance}",String.valueOf(t.getProjectPerformance())); sql = sql.replace("#{meals_subsidy_day}",String.valueOf(t.getMealsSubsidyDay())); sql = sql.replace("#{meals_subsidy_night}",String.valueOf(t.getMealsSubsidyNight())); sql = sql.replace("#{meals_subsidy}",String.valueOf(t.getMealsSubsidy())); sql = sql.replace("#{overtimepay_timeout}",String.valueOf(t.getOvertimepayTimeout())); sql = sql.replace("#{overtimepay_fixed}",String.valueOf(t.getOvertimepayFixed())); sql = sql.replace("#{duty}",String.valueOf(t.getDuty())); sql = sql.replace("#{special_overtime}",String.valueOf(t.getSpecialOvertime())); sql = sql.replace("#{sick_leave_debit}",String.valueOf(t.getSickLeaveDebit())); sql = sql.replace("#{thing_leave_debit}",String.valueOf(t.getThingLeaveDebit())); sql = sql.replace("#{absence_debit}",String.valueOf(t.getAbsenceDebit())); sql = sql.replace("#{payment_subsidy}",String.valueOf(t.getPaymentSubsidy())); sql = sql.replace("#{social_security_debit}",String.valueOf(t.getSocialSecurityDebit())); sql = sql.replace("#{provident_fund_debit}",String.valueOf(t.getProvidentFundDebit())); sql = sql.replace("#{pre_tax_mone}",String.valueOf(t.getPreTaxMone())); sql = sql.replace("#{other_debit}",String.valueOf(t.getOtherDebit())); sql = sql.replace("#{daikou_debit}",String.valueOf(t.getDaikouDebit())); sql = sql.replace("#{tax_money}",String.valueOf(t.getTaxMoney())); sql = sql.replace("#{actual_money}",String.valueOf(t.getActualMoney())); sql = sql.replace("#{reissue}",String.valueOf(t.getReissue())); sql = sql.replace("#{status}",String.valueOf(t.getStatus())); sql = sql.replace("#{remark}",String.valueOf(t.getRemark())); sql = sql.replace("#{UUID}",UUID.randomUUID().toString()); return sql; } /** * 执行JAVA增强 */ private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map data) throws Exception { if(StringUtil.isNotEmpty(cgJavaValue)){ Object obj = null; try { if("class".equals(cgJavaType)){ //因新增时已经校验了实例化是否可以成功,所以这块就不需要再做一次判断 obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance(); }else if("spring".equals(cgJavaType)){ obj = ApplicationContextUtil.getContext().getBean(cgJavaValue); } if(obj instanceof CgformEnhanceJavaInter){ CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj; javaInter.execute("t_bus_user_wage",data); } } catch (Exception e) { e.printStackTrace(); throw new Exception("执行JAVA增强出现异常!"); } } } @Override public List getAllEntities(UserWageDto userWageDto,List uidList,String moth,String authSql) { return userWageMinidaoDao.getAllEntities(userWageDto,uidList,moth,authSql); } @Override public MiniDaoPage getPagedEntities(UserWageDto userWageDto,List uidList,String moth,int page, int rows, String authSql) { return userWageMinidaoDao.getPagedEntities(userWageDto,uidList,moth,page, rows,authSql); } @Override public List getAll(UserWageDto userWageDto,List uidList,String moth,String authSql) { return userWageMinidaoDao.getAll(userWageDto,uidList,moth,authSql); } @Override public MiniDaoPage getViewEntities(UserWageViewDto userWageViewDto,List uidList,int page, int rows,String authSql) { return userWageMinidaoDao.getViewEntities(userWageViewDto,uidList, page, rows, authSql); } @Override public Map getMoneySUM(UserWageDto userWageDto,List uidList,String moth) { return userWageMinidaoDao.getMoneySUM(userWageDto,uidList,moth); } @Override public BigDecimal getMoney(UserWageEntity userWageDto) { // if("ff8080816275ac02016283c8b3a30025".equals(userWageDto.getUserid())) { // System.out.println("ff8080816275ac02016283c8b3a30025"); // } BigDecimal big = new BigDecimal(userWageDto.getBasicWage().toString()); if(userWageDto.getDutiesAllowance() != null){ big = big.add(userWageDto.getDutiesAllowance()); } if(userWageDto.getCertificateSubsidy() != null){ big = big.add(userWageDto.getCertificateSubsidy()); } if(userWageDto.getTrafficSubsidy()!= null){ big = big.add(userWageDto.getTrafficSubsidy()); } if(userWageDto.getMegathermalSubsidy()!= null){ big = big.add(userWageDto.getMegathermalSubsidy()); } if(userWageDto.getOnlyChildCost()!= null){ big = big.add(userWageDto.getOnlyChildCost()); } if(userWageDto.getOtherSubsidy()!= null){ big = big.add(userWageDto.getOtherSubsidy()); } if(userWageDto.getDuty()!= null){ big = big.add(userWageDto.getDuty()); } if(userWageDto.getProjectPerformance()!= null){ big = big.add(userWageDto.getProjectPerformance()); } if(userWageDto.getMealsSubsidyDay()!= null){ big = big.add(userWageDto.getMealsSubsidyDay()); } if(userWageDto.getMealsSubsidyNight()!= null){ big = big.add(userWageDto.getMealsSubsidyNight()); } // // 奖金和项目绩效计入应发 zy 20180425 if(userWageDto.getBonus()!= null){ big = big.add(userWageDto.getBonus()); } if(userWageDto.getProjectPerformance()!= null){ big = big.add(userWageDto.getProjectPerformance()); } if(userWageDto.getMealsSubsidy()!= null){ big = big.add(userWageDto.getMealsSubsidy()); } if(userWageDto.getOvertimepayTimeout()!= null){ big = big.add(userWageDto.getOvertimepayTimeout()); } if(userWageDto.getOvertimepayFixed()!= null){ big = big.add(userWageDto.getOvertimepayFixed()); } /* if(userWageDto.getDuty()!= null){ big = big.add(userWageDto.getDuty()); }*/ if(userWageDto.getSpecialOvertime()!= null){ big = big.add(userWageDto.getSpecialOvertime()); } if(userWageDto.getSickLeaveDebit()!= null){ big = big.subtract(userWageDto.getSickLeaveDebit()); } if(userWageDto.getThingLeaveDebit()!= null){ big = big.subtract(userWageDto.getThingLeaveDebit()); } if(userWageDto.getAbsenceDebit()!= null){ big = big.subtract(userWageDto.getAbsenceDebit()); } /*if(userWageDto.getSocialSecurityDebit()!= null){ big = big.subtract(userWageDto.getSocialSecurityDebit()); } if(userWageDto.getProvidentFundDebit()!= null){ big = big.subtract(userWageDto.getProvidentFundDebit()); }*/ if(userWageDto.getOtherDebit()!= null){ big = big.subtract(userWageDto.getOtherDebit()); } if(userWageDto.getDaikouDebit()!= null){ big = big.subtract(userWageDto.getDaikouDebit()); } if(userWageDto.getReissue()!= null){ big = big.add(userWageDto.getReissue()); } if(userWageDto.getPaymentSubsidy()!= null){ big = big.add(userWageDto.getPaymentSubsidy()); } return big; } /** * 保存新增/更新的行数据 */ @Override public AjaxJson addOrEdit(List entitys) throws Exception { String message = null; AjaxJson j = new AjaxJson(); if(CollectionUtils.isNotEmpty(entitys)){ for(UserWageEntity jeecgDemo:entitys){ if (StringUtil.isNotEmpty(jeecgDemo.getId())) { UserWageEntity t =systemService.get(UserWageEntity.class, jeecgDemo.getId()); try { message = "员工工资核算: " + jeecgDemo.getUserid() + "被更新成功"; MyBeanUtils.copyBeanNotNull2Bean(jeecgDemo, t); // t.setPreTaxMone(this.getMoney(t)); t.recalculatePreTaxMoney(); t.recalculateActualMoney(); t.recalculateComCost(); // if(StringUtils.isNotEmpty(t.getPreTaxMone().toString())){ // t.setActualMoney(t.getPreTaxMone().subtract(t.getTaxMoney())); // }else{ // t.setActualMoney(t.getPreTaxMone()); // } // // if(t.getSocialSecurityDebit()!= null && t.getSocialSecurityDebit().intValue() > 0){ // t.setActualMoney(t.getActualMoney().subtract(t.getSocialSecurityDebit())); // } // if(t.getProvidentFundDebit()!= null && t.getProvidentFundDebit().intValue() > 0){ // t.setActualMoney(t.getActualMoney().subtract(t.getProvidentFundDebit())); // } // this.saveOrUpdate(t); systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); } catch (Exception e) { e.printStackTrace(); } } else { try { message = "JeecgDemo例子: " + jeecgDemo.getUserid() + "被添加成功"; //jeecgDemo.setStatus("0"); jeecgDemo.recalculatePreTaxMoney(); jeecgDemo.recalculateActualMoney(); jeecgDemo.recalculateComCost(); this.save(jeecgDemo); systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO); } catch (Exception e) { e.printStackTrace(); } } } } return j; } @Override public Map getMoneyViewSUM(UserWageViewDto userWageiewDto,List uidList) { return userWageMinidaoDao.getMoneyViewSUM(userWageiewDto,uidList); } /** * 工资进行确认和上报 */ @Override public AjaxJson updateStatus(List idList,boolean status) { String message = null; AjaxJson j = new AjaxJson(); if(CollectionUtils.isNotEmpty(idList)){ for (String id : idList) { UserWageEntity t =systemService.get(UserWageEntity.class, id); if(t != null){ j.setSuccess(true); if(status){ message = t.getMonthly()+",员工id为:"+t.getUserid()+"的工资进行了上报"; t.setStatus("1"); }else{ message = t.getMonthly()+",员工id为:"+t.getUserid()+"的工资进行了确认"; t.setStatus("2"); } systemService.saveOrUpdate(t); systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO); } } } return j; } @Override public List getByuserid(String userid, String monthly) { return userWageMinidaoDao.getByuserid(userid, monthly); } @Override public List getProjectDepartAll(ProjectDepartDto projectDepartDto,String userid) { List projectDepartDtoList = new ArrayList(); if(StringUtils.isNotEmpty(userid)){ List ts = this.getSession().createQuery("from TSUserOrg where tsUser.id = :userId and status = 0").setParameter("userId",userid).list(); if(!ts.isEmpty()){ boolean temp = false; for (TSUserOrg tsUserOrg : ts) { TSDepart tss = get(TSDepart.class, tsUserOrg.getTsDepart().getId()); if(tss != null && tss.getTSPDepart() != null){ if("1".equals(tss.getTSPDepart().getOrgType())&&"2".equals(tss.getOrgType()) || "4".equals(tss.getOrgType())){ temp = true; break; } }else{ if("1".equals(tss.getOrgType())){ temp = true; break; } } } if(temp){ List tsDepartsList = this.getSession().createQuery("from TSDepart where parentdepartid is null").list(); List idList = null; if(!tsDepartsList.isEmpty()){ idList=new ArrayList(); for (TSDepart idTSDepart : tsDepartsList) { List dt = this.getSession().createQuery("from TSDepart where parentdepartid = :parentdepartid and orgType = 2").setParameter("parentdepartid", idTSDepart.getId()).list(); if(!dt.isEmpty()){ for (TSDepart tsDepart : dt) { idList.add(tsDepart.getId()); } } } projectDepartDto.getDepartIdList().addAll(idList); } List orgTypeList=new ArrayList(); orgTypeList.add(Globals.org_type_3); orgTypeList.add(Globals.org_type_5); projectDepartDto.getOrgTypeList().addAll(orgTypeList); String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); projectDepartDtoList=userWageMinidaoDao.getProjectDepartAll(projectDepartDto, authSql); }else{ List idList=new ArrayList(); for (TSUserOrg tsUserOrg : ts) { TSDepart tss = get(TSDepart.class, tsUserOrg.getTsDepart().getId()); idList.add(selectById(tss.getId())); } projectDepartDto.getDepartIdList().addAll(idList); String authSql = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); projectDepartDtoList=userWageMinidaoDao.getProjectDepartAll(projectDepartDto, authSql); } } } return projectDepartDtoList; } private String selectById(String id){ String temp = ""; TSDepart tsDepart = systemService.getEntity(TSDepart.class,id); if("3".equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){ temp = tsDepart.getId(); }else{ if(tsDepart.getTSPDepart() != null){ selectById(tsDepart.getTSPDepart().getId()); } } return temp; } }