123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- package com.kingdee.shr.compensation.web.handler.timepiece.bill;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.metadata.entity.EntityViewInfo;
- import com.kingdee.bos.metadata.entity.FilterInfo;
- import com.kingdee.bos.metadata.entity.FilterItemInfo;
- import com.kingdee.bos.metadata.entity.SelectorItemCollection;
- import com.kingdee.bos.metadata.entity.SelectorItemInfo;
- import com.kingdee.bos.metadata.query.util.CompareType;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.custom.calcdailypay.IInspectionRate;
- import com.kingdee.eas.custom.calcdailypay.InspectionRateCollection;
- import com.kingdee.eas.custom.calcdailypay.InspectionRateFactory;
- import com.kingdee.eas.custom.calcdailypay.InspectionRateInfo;
- import com.kingdee.eas.framework.CoreBaseCollection;
- import com.kingdee.eas.framework.CoreBaseInfo;
- import com.kingdee.eas.util.ToolUtils;
- import com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import com.kingdee.shr.base.syssetting.context.SHRContext;
- import com.kingdee.shr.base.syssetting.exception.SHRWebException;
- import com.kingdee.shr.compensation.app.integrate.*;
- import com.kingdee.shr.compensation.app.utils.DateRange;
- import com.kingdee.shr.compensation.app.utils.SubmitShemeUtils;
- import com.kingdee.shr.compensation.exception.ExceptionHandle;
- import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
- import java.math.BigDecimal;
- import java.sql.SQLException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- 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 javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.commons.lang3.ObjectUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.ui.ModelMap;
- /**
- * 提报单拓展
- * @author coyle
- * 20250520
- */
- public class TimepieceSchemeBillEditHandlerEx extends TimepieceSchemeBillEditHandler {
- private static Logger logger = LoggerFactory.getLogger(TimepieceSchemeBillEditHandlerEx.class);
- private static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");
- //完成率
- // private static String COMRATE = "MQ005";
- // //岗位类型
- // private static String JOBTYPE = "MQ004";
- // //技能等级 SKILLLEVEL
- // private static String SKILLLEVEL = "MQ003";
- // //是否现场作业 On site
- // private static String ONSITE = "MQ007";
- // //班组任职 Team app
- // private static String TEAMAPP = "MQ007";
- // //工资序列 Salary seq
- // private static String SALARYSEQ = "MQ007";
- //
- // private static String[] ITEMNUMS = {COMRATE,JOBTYPE,SKILLLEVEL,ONSITE,TEAMAPP,SALARYSEQ};
- //
- // private static Map<String,String> FEILDS = new HashMap();
- // public TimepieceSchemeBillEditHandlerEx() throws BOSException {
- // Context ctx = SHRContext.getInstance().getContext();
- // CalSubmitItemCollection subColl = CalSubmitItemFactory.getLocalInstance(ctx)
- // .getCalSubmitItemCollection("SELECT ID,FieldSn,number where number in (" + ToolUtils.aryToStr(ITEMNUMS) + ")");
- // if (subColl != null && subColl.size() > 0) {
- // for (int i =0 ;i<subColl.size();i++) {
- // CalSubmitItemInfo itemInfo = subColl.get(i);
- // if (itemInfo != null) {
- // String columnName = "S" + itemInfo.getFieldSn();
- // FEILDS.put(itemInfo.getNumber() , columnName);
- // }
- // }
- // }
- // }
- protected void beforeSave(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
- throws SHRWebException {
- super.beforeSave(request, response, model);
- Context ctx = SHRContext.getInstance().getContext();
- BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo) model;
- BatchSubmitShemeBillEntryCollection entry = info.getEntry();
- String billId = "";
- if(ObjectUtils.allNotNull(info.getId())) {
- billId = info.getId().toString();
- }
- //拉取mes点检率数据
- exeDataOnDay( request,billId,entry);
- //先重置点检率标识
- SubmitShemeUtils.reductionInspectionRate( ctx, info);
- //更新点检率数据
- Set<String> checkbillIds = (Set<String> ) request.getAttribute("checkbillIds");
- SubmitShemeUtils.updateInspectionRate(ctx, info,checkbillIds);
- }
- /**
- * 数据处理
- * 校验对应的某一天已存在数据/mes数据获取等
- * @param billId
- * @param entrys
- * @throws SHRWebException
- */
- public void exeDataOnDay(HttpServletRequest request,String billId,BatchSubmitShemeBillEntryCollection entrys) throws SHRWebException {
- Context ctx = SHRContext.getInstance().getContext();
- Map<String, Set<String>> personDateMap = new HashMap<>();
- //
- HashSet<String> selectPerson = new HashSet();
- HashSet<String> selectDate = new HashSet();
- for (int i = 0; i < entrys.size(); i++) {
- BatchSubmitShemeBillEntryInfo entry = entrys.get(i);
- String personId = entry.getPerson().getId().toString();
- selectPerson.add(personId);
- Date effectDate = entry.getEffectDate();
- // 增加对 effectDate 为 null 的检查
- if (effectDate == null) {
- throw new IllegalArgumentException("分录中发生日期不能为空,请检查");
- }
- String formattedEffectDate = SDF.format(effectDate);
- selectDate.add(formattedEffectDate);
- // 使用 computeIfAbsent 减少冗余代码,并增加重复检查
- personDateMap.computeIfAbsent(personId, k -> new HashSet<>());
- if (!personDateMap.get(personId).add(formattedEffectDate)) {
- // 如果 add 方法返回 false,说明该日期已经存在,抛出异常
- throw new IllegalArgumentException("分录中" + entry.getPerson().getName() + ",有当日重复提报的数据,请检查");
- }
- }
- if (personDateMap.isEmpty()) {
- return;
- }
- // 找出最大日期与最小日期
- DateRange dateRange = SubmitShemeUtils.findMinMaxDate(selectDate);
- //校验重复
- verifiOneData(ctx, billId, selectPerson, dateRange, personDateMap);
- //校验完后进行mes数据填充;
- //获取mes数据
- HashMap<String, HashMap> mesData = SubmitShemeUtils.getMesData( ctx, selectPerson, dateRange);
- SubmitShemeUtils.setMesData( request, entrys, mesData);
- }
- /**
- * 校验当天是否有重复数据
- * @param ctx
- * @param billId
- * @param selectPerson
- * @param dateRange
- * @param personDateMap
- * @throws SHRWebException
- */
- public void verifiOneData(Context ctx ,String billId,HashSet<String> selectPerson,DateRange dateRange,Map<String, Set<String>> personDateMap) throws SHRWebException {
- HashMap<String,String> dataMap = new HashMap();
- try {
- IBatchSubmitShemeBillEntry entryIns = BatchSubmitShemeBillEntryFactory.getLocalInstance(ctx);
- FilterInfo filter = new FilterInfo();
- filter.getFilterItems().add(new FilterItemInfo("person", selectPerson, CompareType.INCLUDE));
- filter.getFilterItems().add(new FilterItemInfo("bill.id", billId , CompareType.NOTEQUALS ));
- filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMaxDate() , CompareType.LESS_EQUALS));
- filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMinDate() , CompareType.GREATER_EQUALS ));
- EntityViewInfo viewInfo = new EntityViewInfo();
- SelectorItemCollection selector = viewInfo.getSelector();
- selector.add(new SelectorItemInfo("person.id"));
- selector.add(new SelectorItemInfo("person.name"));
- selector.add(new SelectorItemInfo("bill.number"));
- selector.add(new SelectorItemInfo("effectDate"));
- viewInfo.setFilter(filter);
- BatchSubmitShemeBillEntryCollection entryCol = entryIns.getBatchSubmitShemeBillEntryCollection(viewInfo);
- for(int i = 0;i<entryCol.size();i++) {
- BatchSubmitShemeBillEntryInfo entryInfo = entryCol.get(i);
- Date effectDate = entryInfo.getEffectDate();
- String personId = entryInfo.getPerson().getId().toString();
- Set<String> pAndDate = personDateMap.get(personId);
- if(pAndDate.contains(SDF.format(effectDate))) {
- String personName = entryInfo.getPerson().getName().toString();
- BatchSubmitShemeBillInfo billInfo = entryInfo.getBill();
- String billNo = billInfo.getNumber();
- dataMap.put(personName, billNo);
- }
- }
- } catch (BOSException e) {
- e.printStackTrace();
- }
- //如果dataMap不为空则循环dataMap的数据组成字符串并抛出异常,"存在哪些人,单据编码为:****"
- if(!dataMap.isEmpty()) {
- String errorMsg = "存在以下当日重复提报人员,姓名与单据编码为:";
- for(String personName : dataMap.keySet()) {
- String billNo = dataMap.get(personName);
- errorMsg += personName + ":" + billNo + " ";
- }
- throw new SHRWebException(errorMsg);
- }
- }
-
- /**
- * handler校验,先不启用
- * @param request
- * @param response
- * @param modelMap
- * @throws SHRWebException
- */
- public void hasDataOnDayAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
- throws SHRWebException {
- Context ctx = SHRContext.getInstance().getContext();
- // 获取人员 //格式为[pseron1:2025-04-03,person2:2025-04-03],需要转为map
- String proposers = request.getParameter("proposers");
- if (proposers == null || proposers.isEmpty()) {
- return;
- }
- String[] personArr = proposers.split(",");
- HashSet<String> selectPerson = new HashSet();
- HashSet<String> selectData = new HashSet();
- Map<String, Set<String>> personDateMap = new HashMap<>();
- for (int i = 0; i< personArr.length;i++) {
- String personIds = personArr[i];
- String[] parts = personIds.split(":");
- if (parts.length == 2) {
- String personId = parts[0].trim();
- String date = parts[1].trim();
- selectPerson.add(personId);
- selectData.add(date);
- personDateMap.computeIfAbsent(personId, k -> new HashSet<>()).add(date);
- }
- }
- if (personDateMap.isEmpty()) {
- return;
- }
- HashMap<String,String> dataMap = new HashMap();
- // 找出最大日期与最小日期
- DateRange dateRange = SubmitShemeUtils.findMinMaxDate(selectData);
- IBatchSubmitShemeBillEntry entryIns;
- try {
- entryIns = BatchSubmitShemeBillEntryFactory.getLocalInstance(ctx);
- FilterInfo filter = new FilterInfo();
- filter.getFilterItems().add(new FilterItemInfo("proposer", selectPerson, CompareType.INCLUDE));
- filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMaxDate() , CompareType.LESS_EQUALS));
- filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMinDate() , CompareType.GREATER_EQUALS ));
- EntityViewInfo viewInfo = new EntityViewInfo();
- viewInfo.setFilter(filter);
- BatchSubmitShemeBillEntryCollection entryCol = entryIns.getBatchSubmitShemeBillEntryCollection(viewInfo);
- for(int i = 0;i<entryCol.size();i++) {
- BatchSubmitShemeBillEntryInfo entryInfo = entryCol.get(i);
- Date effectDate = entryInfo.getEffectDate();
- String personId = entryInfo.getPerson().getId().toString();
- Set<String> pAndDate = personDateMap.get(personId);
- if(pAndDate.contains(SDF.format(effectDate))) {
- String personName = entryInfo.getPerson().getName().toString();
- BatchSubmitShemeBillInfo billInfo = entryInfo.getBill();
- String billNo = billInfo.getNumber();
- dataMap.put(personName, billNo);
- }
- }
- } catch (BOSException e) {
- e.printStackTrace();
- }
- Map resultMap = new HashMap();
- JSONUtils.SUCCESS( resultMap );
- }
-
- protected void afterSave(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
- throws SHRWebException {
- super.afterSave(request, response, model);
- Context ctx = SHRContext.getInstance().getContext();
- BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo) model;
- BatchSubmitShemeBillEntryCollection entry = info.getEntry();
-
- }
-
- // public void getDataOnDay(String billId,BatchSubmitShemeBillEntryCollection entrys) throws SHRWebException {
- // Context ctx = SHRContext.getInstance().getContext();
- // Map<String, Set<String>> personDateMap = new HashMap<>();
- // //
- // HashSet<String> selectPerson = new HashSet();
- // HashSet<String> selectDate = new HashSet();
- // for (int i = 0; i < entrys.size(); i++) {
- // BatchSubmitShemeBillEntryInfo entry = entrys.get(i);
- // String personId = entry.getPerson().getId().toString();
- // selectPerson.add(personId);
- // Date effectDate = entry.getEffectDate();
- //
- // String formattedEffectDate = SDF.format(effectDate);
- // selectDate.add(formattedEffectDate);
- // // 使用 computeIfAbsent 减少冗余代码,并增加重复检查
- // personDateMap.computeIfAbsent(personId, k -> new HashSet<>());
- // if (!personDateMap.get(personId).add(formattedEffectDate)) {
- // // 如果 add 方法返回 false,说明该日期已经存在,抛出异常
- // throw new IllegalArgumentException("分录中" + entry.getPerson().getName() + ",有当日重复提报的数据,请检查");
- // }
- // }
- //
- // if (personDateMap.isEmpty()) {
- // return;
- // }
- // // 找出最大日期与最小日期
- // DateRange dateRange = findMinMaxDate(selectDate);
- // //校验重复
- // verifiOneData(ctx, billId, selectPerson, dateRange, personDateMap);
- // //获取mes数据
- // HashMap<String, HashMap> mesData = getMesData(ctx, selectPerson, dateRange);
- // setMesData(ctx, billId, entrys, mesData);
- // }
- public String saveAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
- throws SHRWebException {
- try {
- BatchSubmitShemeBillInfo model = (BatchSubmitShemeBillInfo) request.getAttribute("dynamic_model");
- this.doFieldPermFilterSave(request, model);
- this.doSave(request, response, model);
- this.afterSave(request, response, model);
- this.saveAttachment(request, response, model);
- Object responseData = this.generateResponseDataAfterSave(request, response, model);
- Map resultMap = new HashMap();
- resultMap.put("responseData", responseData);
- resultMap.put("assignedRowsCount", request.getAttribute("assignedRowsCount"));
- this.writeSuccessData(resultMap);
- } catch (Exception var6) {
- ExceptionHandle.handleException(var6);
- }
- return null;
- }
-
- // /**
- // * 删除单据
- // */
- // @Override
- // public String deleteAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
- // String returnStr = super.deleteAction(request, response, modelMap);
- // reductionAllInsRate(request);
- // return returnStr ;
- // }
- // /**
- // * 重置所有点检率
- // * @param request
- // * @throws SHRWebException
- // */
- // private void reductionAllInsRate (HttpServletRequest request) throws SHRWebException {
- // String billId = getBillId(request);
- // String[] ids = billId.split(",");
- // //ids转为list集合
- // List<String> idList = Arrays.asList(ids);
- //
- // Context ctx = SHRContext.getInstance().getContext();
- // FilterInfo filter = new FilterInfo();
- // filter.getFilterItems().add(new FilterItemInfo("id", ToolUtils.aryToStr(idList,false), CompareType.INCLUDE));
- // EntityViewInfo viewInfo = new EntityViewInfo( ) ;
- // viewInfo.setFilter(filter);
- // SelectorItemCollection selector = viewInfo.getSelector();
- // selector.add(new SelectorItemInfo("number"));
- // try {
- // IBatchSubmitShemeBill subIns = BatchSubmitShemeBillFactory.getLocalInstance(ctx);
- // BatchSubmitShemeBillCollection subCol = subIns.getBatchSubmitShemeBillCollection(viewInfo);
- // for(int i = 0;i<subCol.size();i++){
- // BatchSubmitShemeBillInfo subInfo = subCol.get(i);
- // SubmitShemeUtils.reductionInspectionRate(ctx, subInfo);
- // }
- // } catch (BOSException e) {
- // throw new RuntimeException(e);
- // }
- // }
- }
|