| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- package com.kingdee.eas.custom.wamke.web;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.log4j.Logger;
- import org.apache.log4j.Priority;
- import org.springframework.ui.ModelMap;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.eas.custom.wamke.syncdata.dto.MobileAttachDto;
- import com.kingdee.eas.custom.wamke.syncdata.web.MobileEntryBillExtendEditHandler;
- import com.kingdee.eas.framework.CoreBaseInfo;
- import com.kingdee.eas.hr.affair.FlucInBizBillInfo;
- import com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import com.kingdee.shr.affair.web.handler.hrman.FlucInBizBillHrManEditHandler;
- import com.kingdee.shr.base.syssetting.context.SHRContext;
- import com.kingdee.shr.base.syssetting.exception.SHRWebException;
- public class FlucInBizBillHrManEditExtendHandler extends
- FlucInBizBillHrManEditHandler {
- /**
- * 跨公司调入单提交生效
- */
- @Override
- public void submitEffectAction(HttpServletRequest request,
- HttpServletResponse response, ModelMap modelMap)
- throws SHRWebException {
- super.submitEffectAction(request, response, modelMap);
- CoreBaseInfo model = (CoreBaseInfo) request.getAttribute("dynamic_model");
- //提交之后,判断是否为万净公司下的组织,再根据岗位更新工种
- FlucInBizBillInfo billInfo = (FlucInBizBillInfo) model;
-
- try{
- adjustWorkType(billInfo.getId().toString());
- }
- catch(Exception e){
- logInfo("执行更新工种时发生了异常");
- e.printStackTrace();
- }
- }
-
- // @Override
- // protected void afterSubmit(HttpServletRequest request,
- // HttpServletResponse response, CoreBaseInfo model)
- // throws SHRWebException {
- //
- // super.afterSubmit(request, response, model);
- //
- // //提交之后,判断是否为万净公司下的组织,再根据岗位更新工种
- // FlucInBizBillInfo billInfo = (FlucInBizBillInfo) model;
- // adjustWorkType(billInfo.getId().toString());
- // }
-
- /**
- * 根据跨公司调动单ID进行员工新工种信息
- * @param id
- */
- private void adjustWorkType(String id){
- Map<String,String> info = isWjCompany(id,true);
- if(info.get("pass").equals("true")){
- String posId = info.get("posId");
- String personId = info.get("personId");
- String workId = getWorkCategoryIdByPosId(posId);
- if(null==workId){
- return;
- }
- updatePersonWorkType(personId,workId);
- }
- }
-
- /**
- * 根据岗位ID获取对应匹配的工种ID
- * @param posId
- * @return
- */
- private String getWorkCategoryIdByPosId(String posId){
- try{
- String sql = " SELECT work_category_id fROM T_ORG_Position a "
- + " INNER JOIN CT_WK_work_category_setting b ON(a.FName_l2 COLLATE Chinese_PRC_CI_AS = b.position_name) "
- + " WHERE a.FID= '"+posId+"' ";
- logInfo("根据岗位ID获取对应匹配的工种IDsql:"+sql);
- Context ctx = SHRContext.getInstance().getContext();
- IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
- while(rowSet.next()){
- return rowSet.getString("work_category_id");
- }
- }
- catch(Exception e){
- logInfo("根据岗位ID获取对应匹配的工种ID时发生异常:"+e.getMessage());
- e.printStackTrace();
- return null;
- }
- return null;
- }
-
- /**
- * 根据岗位更新对应人员的工种
- * @param personId
- * @param personId
- * @param workId
- */
- private void updatePersonWorkType(String personId, String workId){
-
- try{
- Context ctx = SHRContext.getInstance().getContext();
-
- //更新人员表
- String sql = "UPDATE T_BD_Person SET CFWORKCATEGORYID = '"+workId+"' WHERE FID = '"+personId+"'";
- logInfo("根据岗位更新对应人员表的工种sql:"+sql);
- DbUtil.execute(ctx, sql);
-
- //更新人员历史表
- sql = "UPDATE T_BD_PersonHis SET CFWORKCATEGORYID = '"+workId+"' "
- +" WHERE FNumber = ( SELECT TOP 1 FNumber FROM T_BD_Person WHERE FID = '"+personId+"' ) AND FLEFFDT >='2199-12-31'";
- logInfo("根据岗位更新对应人员历史表的工种sql:"+sql);
- DbUtil.execute(ctx, sql);
- }
- catch(Exception e){
- logInfo("根据岗位更新对应人员表的工种字段发生异常:"+e.getMessage());
- e.printStackTrace();
- }
- }
-
- /**
- * 判断是否为万净公司下的人员
- * @param id
- * @param isSubmitEffect 是否提交生效
- * @return
- */
- private Map<String,String> isWjCompany(String id, boolean isSubmitEffect) {
- Map<String,String> result = new HashMap<String,String>();
- result.put("pass","false");
-
- try{
- String sql = "SELECT TOP 1 FADMINORGID, FPersonId, FPositionId, FBIZDATE FROM T_HR_FlucInBizBillEntry WHERE FBILLID = '"+id+"' ";
- logInfo("执行跨公司调入单据数据sql:"+sql);
- Context ctx = SHRContext.getInstance().getContext();
- IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
- String adminId = null, posId = null, personId = null;
- Date bizDate = null;
- while (rowSet.next()) {
- adminId = rowSet.getString("FADMINORGID");
- posId = rowSet.getString("FPositionId");
- personId = rowSet.getString("FPersonId");
- bizDate = rowSet.getDate("FBIZDATE");
- result.put("adminId",adminId);
- result.put("posId",posId);
- result.put("personId",personId);
- break;
- }
-
- if(adminId==null || adminId == ""){
- result.put("pass","false");
- return result;
- }
-
- //如果为提交生效,则需要判断日期
- if(isSubmitEffect){
- //如果生效时间<=当前日期,则执行,否则直接返回(由定时器扫描再去变更)
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- String bizDateStr = sdf.format(bizDate);
- String currentDate = sdf.format(new Date());
- if(bizDateStr.compareTo(currentDate)>0){
- result.put("pass","false");
- return result;
- }
- }
-
- sql = "SELECT TOP 1 FID FROM T_ORG_ADmin WHERE FId = '"+adminId+"' AND FLONGNUMBER LIKE '01!WKWY!50952375!%";
- logInfo("执行查询是否为万净公司sql:"+sql);
- IRowSet rowSetWj = DbUtil.executeQuery(ctx, sql);
- while(rowSetWj.next()){
- if(rowSetWj.getString("FID") != null && rowSetWj.getString("FID") != ""){
- result.put("pass","true");
- }
- else{
- result.put("pass","false");
- }
- break;
- }
- return result;
- }
- catch(Exception e ){
- logInfo("判 断是否为万净公司数据时发生了异常:"+e.getMessage());
- e.printStackTrace();
- return result;
- }
- }
- private static Logger logger = Logger.getLogger(FlucInBizBillHrManEditExtendHandler.class);
- private void logInfo(String msg) {
- System.out.println(msg);
- logger.log(Priority.INFO, msg);
- }
- }
|