package com.kingdee.eas.custom.compensation.handler; import cn.com.servyou.dto.ApiResponse; import cn.com.servyou.dto.AsyncResult; import cn.com.servyou.dto.declare.CompanyDeclareRequest; import cn.com.servyou.dto.tax.*; import cn.com.servyou.rmi.client.ClientProxyFactory; import cn.com.servyou.service.DeclarationRequest; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.kingdee.bos.BOSException; import com.kingdee.bos.Context; import com.kingdee.bos.metadata.entity.*; import com.kingdee.bos.metadata.query.util.CompareType; import com.kingdee.bos.util.EASResource; import com.kingdee.eas.basedata.hraux.NationalityInfo; import com.kingdee.eas.basedata.person.PersonCollection; import com.kingdee.eas.basedata.person.PersonFactory; import com.kingdee.eas.basedata.person.PersonInfo; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.custom.shuiyou.task.TaskCatalogEnum; import com.kingdee.eas.custom.shuiyou.uitls.ISYUtilsFacade; import com.kingdee.eas.custom.shuiyou.uitls.SYUtilsFacadeFactory; import com.kingdee.eas.custom.shuiyou.utils.ClientProxyFactoryUtils; 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.base.syssetting.exception.ShrWebBizException; import com.kingdee.shr.base.syssetting.web.dynamic.util.DynamicUtil; import com.kingdee.shr.base.syssetting.web.dynamic.util.MD5; import com.kingdee.shr.base.syssetting.web.json.JSONUtils; import com.kingdee.shr.base.syssetting.web.util.UserUtil; import com.kingdee.shr.compensation.TbTypeEnum; import com.kingdee.shr.compensation.app.incomeTax.ITaxPersonRecordEntry; import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryCollection; import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryFactory; import com.kingdee.shr.compensation.app.incomeTax.TaxPersonRecordEntryInfo; import com.kingdee.shr.compensation.app.tax.*; import com.kingdee.shr.compensation.app.tax.base.TaxIncomeItemInfo; import com.kingdee.shr.compensation.app.taxCal.*; import com.kingdee.shr.compensation.util.*; import com.kingdee.shr.compensation.web.handler.tax.IncomeTaxDeclareListHandler; import com.kingdee.shr.compensation.web.handler.tax.dto.TaxDeclarExcelRowDTO; import com.kingdee.shr.compensation.web.handler.tax.dto.TaxDeclareDTO; import com.kingdee.util.StringUtils; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.*; import org.springframework.ui.ModelMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.math.BigDecimal; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.*; /** * @author qingwu * @date 2024/9/18 * @apiNote 个税申报扩展 */ public class IncomeTaxDeclareListHandlerEx extends IncomeTaxDeclareListHandler { private static final Logger LOG = Logger.getLogger(IncomeTaxDeclareListHandlerEx.class); private Context ctx = SHRContext.getInstance().getContext(); private ObjectMapper mapper = new ObjectMapper(); /** * 个税申报 * * @param request * @param response * @param modelMap */ @Override public void taxDeclareAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, SHRWebException { LOG.error("taxDeclareAction-----------start-----------"); Context ctx = SHRContext.getInstance().getContext(); try { boolean isHaveTaxService = CmpTaxUtil.isHaveTaxService(ctx); if (!isHaveTaxService) { throw new ShrWebBizException(EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label136", ctx.getLocale())); } else { String selectedId = request.getParameter("selectedId"); Map resultMap = new HashMap(); Map declareData = this.getDeclareData(ctx, selectedId); Map paramMap = new HashMap(); paramMap.put("declaData", declareData.get("WATI_TO_DECLARE")); LOG.error("paramMap-----------" + paramMap); try { //纳税单位 List advanceDeclareInfo = (List) declareData.get("advanceDeclareInfo"); LOG.error("advanceDeclareInfo------------" + advanceDeclareInfo); if (!advanceDeclareInfo.isEmpty()) { throw new ShrWebBizException(this.combineError(advanceDeclareInfo)); } //个税审批 审批状态=审批通过的数据 List waitToDeclareList = (List) paramMap.get("declaData"); if (waitToDeclareList.size() <= 0) { resultMap.put("success", false); resultMap.put("excel", ""); resultMap.put("hasErrData", true); resultMap.put("hasCheckDataErr", true); resultMap.put("info", "不可重复声申报!!"); JSONUtils.SUCCESS(resultMap); return; } //检查纳税申报数据 Map checkResultMap = this.checkTaxDeclareData(ctx, request, waitToDeclareList); Boolean hasErr = (Boolean) checkResultMap.get("hasErrData"); if (hasErr != null && hasErr) { resultMap.put("success", false); resultMap.put("excel", checkResultMap.get("excel")); resultMap.put("hasErrData", true); resultMap.put("hasCheckDataErr", true); resultMap.put("info", ""); JSONUtils.SUCCESS(resultMap); return; } String errMsg = this.checkTaxCalStatus(ctx, waitToDeclareList); if (null != errMsg) { resultMap.put("success", false); resultMap.put("dataError", true); resultMap.put("errMsg", errMsg); JSONUtils.SUCCESS(resultMap); return; } checkResultMap = this.checkIncomeTaxIssue(ctx, waitToDeclareList); if (checkResultMap != null) { checkResultMap.put("success", false); JSONUtils.SUCCESS(checkResultMap); return; } //errMsg = this.checkReductionItems(ctx, waitToDeclareList); //if (null != errMsg) { // resultMap.put("success", false); // resultMap.put("reductionError", true); // resultMap.put("errMsg", errMsg); // JSONUtils.SUCCESS(resultMap); // return; //} //Map taxDeclareResult = IncomeTaxDeclareFacadeFactory.getLocalInstance(ctx).taxDeclare(paramMap); //调佣税友纳税申报 Map taxDeclareResult = callShuiYouTaxDeclare(paramMap); Boolean isSuccess = (Boolean) taxDeclareResult.get("success"); resultMap.put("success", isSuccess); resultMap.put("excel", ""); resultMap.put("hasErrData", !isSuccess); resultMap.put("hasCheckDataErr", false); resultMap.put("info", declareData.get("info")); } catch (Exception var17) { var17.printStackTrace(); LOG.error(var17.getMessage(), var17); resultMap.put("success", false); resultMap.put("excel", ""); resultMap.put("hasErrData", true); resultMap.put("hasCheckDataErr", false); resultMap.put("info", declareData.get("info")); resultMap.put("errorMsg", var17.getMessage()); } LOG.error("taxDeclareAction-----------end-----------"); JSONUtils.SUCCESS(resultMap); } } catch (JsonProcessingException e) { e.printStackTrace(); throw new RuntimeException(e); } } /** * 调佣税友纳税申报 * * @param paramMap * @return */ public Map callShuiYouTaxDeclare(Map paramMap) { LOG.error("callShuiYouTaxDeclare--------------------paramMap" + paramMap); Map resultMap = new HashMap(); resultMap.put("success", true); resultMap.put("msg", ""); List waitToDeclareList = (List) paramMap.get("declaData"); Map requestParamMap = new HashMap(); List paramList = new ArrayList(); try { if (waitToDeclareList != null && waitToDeclareList.size() > 0) { for (int i = 0; i < waitToDeclareList.size(); i++) { IncomeTaxDeclarInfo taxDeclarInfo = waitToDeclareList.get(i); JSONObject param = new JSONObject(); param.put("taxDeclarId", taxDeclarInfo.getId()); param.put("taxDeclarBatchNo", taxDeclarInfo.getBatchNo()); //纳税单位 TaxUnitInfo taxUnitInfo = taxDeclarInfo.getTaxUnit(); //客户端代理工厂 ClientProxyFactory clientProxyFactory = ClientProxyFactoryUtils.getClientProxyFactory(); //算税请求接口 DeclarationRequest declarationRequest = clientProxyFactory.getDeclarationRequest(); //获取请求参数 CompanyDeclareRequest declareRequestParameter = getDeclareRequestParameter(taxUnitInfo, taxDeclarInfo); LOG.error("declareRequestParameter-----------------" + mapper.writeValueAsString(declareRequestParameter)); ApiResponse apiResponse = declarationRequest.send(declareRequestParameter); LOG.error("asyncResultApiResponse-----getCode-------" + apiResponse.getHead().getCode()); LOG.error("asyncResultApiResponse-----getMsg--------" + apiResponse.getHead().getMsg()); resultMap.put("msg", mapper.writeValueAsString(declareRequestParameter)); if (apiResponse.getHead().getCode().equals("00000000")) { AsyncResult body = apiResponse.getBody(); String requestId = body.getRequestId(); LOG.error("requestId-----" + requestId); LOG.error("apiResponse-----" + mapper.writeValueAsString(apiResponse)); //查询反算反馈结果 ISYUtilsFacade isyUtilsFacade = SYUtilsFacadeFactory.getLocalInstance(ctx); //backTask(url,requestId,回调osf服务,自定义参数,任务类型) //isyUtilsFacade.backTask(isyUtilsFacade.getConfig().get("ip") + "/gateway/iit/reverseCalculateTax/getASynIndividualIncomeTaxFeedback", requestId, "synIndividualIncomeTaxService", jsonObject.toString(), TaskCatalogEnum.CAL_GET); JSONObject json = new JSONObject(); json.put("requestId", requestId); json.put("param", param.toString()); isyUtilsFacade.addTask("synIncomeTaxDeclareService", json.toJSONString(), TaskCatalogEnum.UN_CAL_GET, ""); } } } } catch (Exception e) { e.printStackTrace(); resultMap.put("success", false); resultMap.put("msg", e.getMessage()); return resultMap; } return resultMap; } /** * 获取请求参数 * 注意: * 1.解除劳动合同一次性补偿金、全年一次性奖金所得,不能单独申报,需要同正常工资薪金一起申报。 * 2.解除劳动合同一次性补偿金、稿酬所得,由于税务规则需要,解除劳动合同一次性补偿金、稿酬所得必须填写免税附表。 * * @param taxUnitInfo * @param taxDeclarInfo * @return */ private CompanyDeclareRequest getDeclareRequestParameter(TaxUnitInfo taxUnitInfo, IncomeTaxDeclarInfo taxDeclarInfo ) throws BOSException, JsonProcessingException, EASBizException, SQLException { LOG.error("getDeclareRequestParameter-----------taxDeclarInfo-----" + taxDeclarInfo); CompanyDeclareRequest declareRequestPara = new CompanyDeclareRequest(); Map requestParamMap = new HashMap(); //随机id String bizNo = UUID.randomUUID().toString(); LOG.error("bizNo:" + bizNo); //外部业务订单号* declareRequestPara.setBizNo(bizNo); //企业名称* declareRequestPara.setName(taxUnitInfo.getName()); //税号* declareRequestPara.setTaxNo(taxUnitInfo.getTaxNumber()); //行政区划代码* declareRequestPara.setArea(taxUnitInfo.getAreaCode()); //登记序号 declareRequestPara.setRegistrationNumber(taxUnitInfo.getRegNumber()); String declPassword = taxUnitInfo.getDeclPassword(); if (StringUtils.isEmpty(declPassword)) { throw new BOSException("申报密码不能为空!"); } declareRequestPara.setDeclarePassword(Base64Utils.decode(declPassword)); //所得月份 String yearMonth = taxDeclarInfo.getYearMonth(); String replaceYearMonth = yearMonth.replace("-", ""); LOG.error("replaceYearMonth----------------" + replaceYearMonth); //税款所属期YYYYMM* declareRequestPara.setMonth(replaceYearMonth); //总金额 //BigDecimal totalMoney = taxDeclarInfo.getTotalMoney(); //应退税额 //BigDecimal taxRebate = taxDeclarInfo.getTaxRebate(); //总人数 //long totalPerson = taxDeclarInfo.getTotalPerson(); //申报表分类 1=预扣预缴申报表 2=分类所得申报表 3=非居民所得申报表 //String tbTble = taxDeclarInfo.getTbType().getValue(); //纳税单位ID //String taxUnitId = taxUnitInfo.getId().toString(); //Map tbTypeMap = new HashMap(); //if (totalMoney.compareTo(BigDecimal.ZERO) == 0) { // tbTypeMap.put("zje", 0.0); //} else { // tbTypeMap.put("zje", totalMoney); //} // //if (taxRebate.compareTo(BigDecimal.ZERO) == 0) { // tbTypeMap.put("ynse", 0.0); //} else { // tbTypeMap.put("ynse", taxRebate); //} //tbTypeMap.put("zrs", totalPerson); //Map dataMap = new HashMap(); //if ("1".equals(tbTble)) { // dataMap.put("ykyj", tbTypeMap); //} else if ("2".equals(tbTble)) { // dataMap.put("flsd", tbTypeMap); //} else if ("3".equals(tbTble)) { // dataMap.put("fjm", tbTypeMap); //} //密码类型* declareRequestPara.setPasswordType("0"); //离职日期处理策略 1、不传或传1,代表离职日期自动清空,即人员状态由“非正常”变更为“正常”时,离职日期字段自动清空,默认逻辑。 //2、传2离职日期不自动清空,即人员状态由“非正常”变更为“正常”时,离职日期不自动清空,客户如需清空需对离职日期字段传入空字符串。 //declareRequestPara.setResignDateStrategy(); //批次号 String batchNo = taxDeclarInfo.getBatchNo(); LOG.error("taxCalConfigDetailCollection--------taxDeclarInfo---------" + taxDeclarInfo); //个税应用+税款计算最终拆分明细表 ITaxCalConfigDetail taxCalConfigDetail = TaxCalConfigDetailFactory.getLocalInstance(ctx); TaxCalConfigDetailCollection taxCalConfigDetailCollection = taxCalConfigDetail.getTaxCalConfigDetailCollection("select *,incomeItem.*, person.* where batchNo = '" + batchNo + "' and state = '20'"); LOG.error("taxCalConfigDetailCollection-----------------" + taxCalConfigDetailCollection.size()); //员工信息ID Set personIds = new HashSet(); //综合所得对象 ComplexIncomeRequest complexIncomeRequest = new ComplexIncomeRequest(); //正常工资薪金对象 NormalSalarySpecIncome normalSalarySpecIncome = new NormalSalarySpecIncome(); //正常工资薪金列表 List normalSalarySpec = new ArrayList(); //全年一次性奖金收入 List annualOneTimeBonusIncome = new ArrayList(); //全年一次性奖金收入 List laborRemunerationIncome = new ArrayList(); if (taxCalConfigDetailCollection.size() > 0) { for (int i = 0; i < taxCalConfigDetailCollection.size(); i++) { TaxCalConfigDetailInfo taxCalConfigDetailInfo = taxCalConfigDetailCollection.get(i); //员工信息 PersonInfo personInfo = taxCalConfigDetailInfo.getPerson(); personIds.add(personInfo.getId().toString()); //所得项目 TaxIncomeItemInfo incomeItem = taxCalConfigDetailInfo.getIncomeItem(); //本期收入 Integer sre = null; String getSreSql = "select t1 from T_HR_STaxCalConfigDetail where fid ='" + taxCalConfigDetailInfo.getId().toString() + "'"; IRowSet iRowSet = DbUtil.executeQuery(ctx, getSreSql); while (iRowSet.next()) { sre = iRowSet.getInt("t1"); } LOG.error("incomeItem-----------------" + incomeItem); //所属项目名称 String incomeItemName = incomeItem.getName(); //所属项目编码 String incomeItemNumber = incomeItem.getNumber(); //正常工资薪金 if ("zcgzxjlb".equals(incomeItemNumber)) { //getComplexIncome(员工信息对象 ,所属项目,本期收入) normalSalarySpec.add(getComplexIncome(personInfo, incomeItemName, sre)); //正常工资薪金列表 保存数据 normalSalarySpecIncome.setNormalSalarySpec(normalSalarySpec); LOG.error("normalSalarySpecIncome-----------------" + mapper.writeValueAsString(normalSalarySpecIncome)); complexIncomeRequest.setNormalSalarySpecIncome(normalSalarySpecIncome); } //全年一次性奖金收入 if ("qnycxjjlb".equals(incomeItemNumber)) { annualOneTimeBonusIncome.add(getComplexIncome(personInfo, incomeItemName, sre)); LOG.error("annualOneTimeBonusIncome-----------------" + mapper.writeValueAsString(annualOneTimeBonusIncome)); LOG.error("annualOneTimeBonusIncome-----------------" + annualOneTimeBonusIncome); LOG.error("annualOneTimeBonusIncome.size()-----------------" + annualOneTimeBonusIncome.size()); //全年一次性奖金收入 保存数据 complexIncomeRequest.setAnnualOneTimeBonusIncome(annualOneTimeBonusIncome); } //一般劳务报酬所得 if ("lwbclb".equals(incomeItemNumber)) { laborRemunerationIncome.add(getComplexIncome(personInfo, incomeItemName, sre)); LOG.error("laborRemunerationIncome-----------------" + mapper.writeValueAsString(laborRemunerationIncome)); //一般劳务报酬所得 保存数据 complexIncomeRequest.setLaborRemunerationIncome(laborRemunerationIncome); } } } //综合所得 declareRequestPara.setComplexIncomeRequest(complexIncomeRequest); //企业员工列表 List companyEmployeeList = getCompanyEmployeeList(personIds); declareRequestPara.setCompanyEmployeeList(companyEmployeeList); LOG.error("companyEmployeeList-----------------" + mapper.writeValueAsString(companyEmployeeList)); return declareRequestPara; } /*** * 员工 * @return */ private ComplexIncome getComplexIncome(PersonInfo personInfo, String incomeItemName, Integer sre) { ComplexIncome complexIncome = new ComplexIncome(); //姓名 complexIncome.setName(personInfo.getName()); //居民身份证 if (personInfo.getIdCardNO() != null) { //证照号码 complexIncome.setLicenseNumber(personInfo.getIdCardNO()); //证照类型 complexIncome.setLicenseType("居民身份证"); } //中国护照不 if (personInfo.getPassportNO() != null) { //证照类型 complexIncome.setLicenseType("中国护照"); //证照号码 complexIncome.setLicenseNumber(personInfo.getPassportNO()); } //收入额 complexIncome.setIncome(new BigDecimal(sre)); complexIncome.setIncomeItemName(incomeItemName); return complexIncome; } /** * 企业员工列表* * * @return */ private List getCompanyEmployeeList(Set personIds) throws BOSException, EASBizException { List companyEmployeeList = new ArrayList(); SelectorItemCollection sic = new SelectorItemCollection(); sic.add("*"); FilterInfo filterInfo = new FilterInfo(); filterInfo.getFilterItems().add(new FilterItemInfo("id", personIds, CompareType.INCLUDE)); EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null); //获取人员数据 PersonCollection personCollection = PersonFactory.getLocalInstance(ctx).getPersonCollection(entityViewInfo); if (personCollection.size() > 0) { for (int i = 0; i < personCollection.size(); i++) { PersonInfo personInfo = personCollection.get(i); companyEmployeeList.add(getDetailCompanyEmployee(personInfo)); } } return companyEmployeeList; } /** * 人员 * * @return */ public DetailCompanyEmployee getDetailCompanyEmployee(PersonInfo personInfo) throws BOSException, EASBizException { //人员对象 DetailCompanyEmployee detailCompanyEmployee = new DetailCompanyEmployee(); ////姓名 //detailCompanyEmployee.setName("何云"); ////证件类型 //detailCompanyEmployee.setLicenseType("居民身份证"); ////证照号码 //detailCompanyEmployee.setLicenseNumber("429004198601085125"); //姓名 detailCompanyEmployee.setName(personInfo.getName()); //complexIncome.setName("何云"); //居民身份证 if (personInfo.getIdCardNO() != null) { //证照号码 detailCompanyEmployee.setLicenseNumber(personInfo.getIdCardNO()); //证照类型 detailCompanyEmployee.setLicenseType("居民身份证"); //人员地区 detailCompanyEmployee.setArea("境内"); } //中国护照 if (personInfo.getPassportNO() != null) { //证照类型 detailCompanyEmployee.setLicenseType("中国护照"); //证照号码 detailCompanyEmployee.setLicenseNumber(personInfo.getPassportNO()); //人员地区 detailCompanyEmployee.setArea("境外"); } //电话号码 detailCompanyEmployee.setPhone(personInfo.getCell()); //人员状态 detailCompanyEmployee.setState(personInfo.getEmployeeType().getName()); //人员报税信息->任职受雇从业信息 ITaxPersonRecordEntry iTaxPersonRecordEntry = TaxPersonRecordEntryFactory.getLocalInstance(ctx); TaxPersonRecordEntryCollection taxPersonRecordEntryCollection = iTaxPersonRecordEntry.getTaxPersonRecordEntryCollection("where person.id = '" + personInfo.getId() + "'"); TaxPersonRecordEntryInfo taxPersonRecordEntryInfo = taxPersonRecordEntryCollection.get(0); //任职受雇类型 可选择雇员、保险营销员、证券经纪人、其他、实习学生(全日制学历教育) //detailCompanyEmployee.setIsEmployee("其他"); detailCompanyEmployee.setIsEmployee(taxPersonRecordEntryInfo.getEmployedType().getAlias()); //受雇日期 YYYY-MM-DD,不能大于当前时间,任职受雇类型选择雇员、保险营销员、证券经纪人时必录 SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd"); detailCompanyEmployee.setEmployedDate(inputFormat.format(taxPersonRecordEntryInfo.getEmployedDate())); //性别 detailCompanyEmployee.setGender(personInfo.getGender().getAlias()); //出生日期 detailCompanyEmployee.setBirthday(inputFormat.format(personInfo.getBirthday())); //国籍 nationality NationalityInfo nationality = personInfo.getNationality(); detailCompanyEmployee.setNationality(nationality.getName()); return detailCompanyEmployee; } private String getCheckSqlByType(Map incomeIdMap, String taxUnitId, String yearMonth, TbTypeEnum typeEnum) { StringBuilder sqlBuf = new StringBuilder(); sqlBuf.append(" SELECT distinct tx.FTAXUNITID,t1.Fname_l2 as TAXNAME,p1.FNUMBER,p1.Fname_l2 as PERSONNAME, ti.fIncomeCode "); sqlBuf.append(" FROM T_HR_STaxCalConfigDetail tx "); sqlBuf.append(" left join T_HR_TAXUNIT as t1 on t1.fid = tx.FTaxUnitID "); sqlBuf.append(" left join T_BD_PERSON as p1 on p1.fid = tx.FPersonId "); sqlBuf.append(" left join t_hr_sTaxIncomeItem as ti on tx.fIncomeItemId = ti.fid "); String dateFilter = CmpSQLUtil.generateSqlDateFilter("tx.FPeriodBegin", "tx.FPeriodEnd", yearMonth); sqlBuf.append(" where ").append(dateFilter); sqlBuf.append(" and tx.FTAXUNITID='").append(taxUnitId).append("'"); sqlBuf.append(" and tx.FSTATE=10"); sqlBuf.append(" and tx.FIsLast=1"); sqlBuf.append(" and tx.FIncomeItemId in ").append(incomeIdMap.get(typeEnum.getValue())); return sqlBuf.toString(); } //private Map checkTaxDeclareData(Context ctx, List waitToDeclareList) throws BOSException { // Map checkDataResultMap = new HashMap(); // return null; //} private Map checkTaxDeclareData(Context ctx, HttpServletRequest request, List waitToDeclareList) throws BOSException, SQLException, ShrWebBizException { Map checkDataResultMap = new HashMap(); boolean hasErrData = false; if (waitToDeclareList != null && waitToDeclareList.size() > 0) { List preCheckSql = new ArrayList(); List specCheckForPre = new ArrayList(); List notPersonCheckSql = new ArrayList(); List classifyCheckSql = new ArrayList(); Map incomeIdMap = new HashMap(); incomeIdMap.put("1", CmpTaxUtil.genIncomeItemId(ctx, "1")); incomeIdMap.put("2", CmpTaxUtil.genIncomeItemId(ctx, "2")); incomeIdMap.put("3", CmpTaxUtil.genIncomeItemId(ctx, "3")); Iterator i$ = waitToDeclareList.iterator(); String yearMonth; while (i$.hasNext()) { IncomeTaxDeclarInfo declareInfo = (IncomeTaxDeclarInfo) i$.next(); TbTypeEnum tbType = declareInfo.getTbType(); String taxUnitId = declareInfo.getTaxUnit().getId().toString(); yearMonth = declareInfo.getYearMonth(); if (tbType != null) { if ("1".equals(tbType.getValue())) { preCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0701)); specCheckForPre.add(this.getPreCheckSql(declareInfo)); } else if ("3".equals(tbType.getValue())) { notPersonCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0703)); } else { classifyCheckSql.add(this.getCheckSqlByType(incomeIdMap, taxUnitId, yearMonth, TbTypeEnum.SB0702)); } } } Map reasonOperaMap = new HashMap(); reasonOperaMap.put("noCalDataReson", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label140", ctx.getLocale())); reasonOperaMap.put("noCalDataOper", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label141", ctx.getLocale())); reasonOperaMap.put("preDataReason", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label142", ctx.getLocale())); reasonOperaMap.put("preDataOpera", EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label143", ctx.getLocale())); List taxDeclareExcelRowDTOS = new ArrayList(); taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, preCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0701)); taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, classifyCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0702)); taxDeclareExcelRowDTOS.addAll(this.getExceptData(ctx, notPersonCheckSql, specCheckForPre, reasonOperaMap, TbTypeEnum.SB0703)); String filePath = ""; if (taxDeclareExcelRowDTOS.size() > 0) { hasErrData = true; HSSFWorkbook workbook = new HSSFWorkbook(); yearMonth = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label144", ctx.getLocale()); this.fillTitle(ctx, workbook, yearMonth.split(",")); this.fillWorkdBookData(workbook, taxDeclareExcelRowDTOS); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); File dir = new File(UserUtil.getUserTempDirAbsolutePath(request.getSession())); if (!dir.exists()) { dir.mkdirs(); } String fileName = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label145", ctx.getLocale()) + "_" + format.format(new Date()) + ".xls"; String realFileName = MD5.md5Hash(fileName); File file = new File(dir, realFileName); FileOutputStream out = null; try { out = new FileOutputStream(file); workbook.write(out); out.flush(); } catch (FileNotFoundException var33) { LOG.error(var33.getMessage(), var33); } catch (IOException var34) { LOG.error(var34.getMessage(), var34); } finally { if (out != null) { try { out.close(); } catch (IOException var32) { LOG.error(var32.getMessage(), var32); } } } Map params = new HashMap(); params.put("method", "tmp"); params.put("file", realFileName); params.put("filename", fileName); filePath = DynamicUtil.assembleUrl("/downloadfile.do", params); } checkDataResultMap.put("excel", filePath); } checkDataResultMap.put("hasErrData", hasErrData); return checkDataResultMap; } private void fillTitle(Context ctx, HSSFWorkbook workbook, String[] titleArr) { HSSFSheet sheet = workbook.createSheet(); HSSFRow createRow = sheet.createRow(0); HSSFCell infoCell = createRow.createCell(0); infoCell.setCellValue(EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label146", ctx.getLocale())); sheet.setColumnWidth(0, 12800); createRow = sheet.createRow(1); HSSFFont font = workbook.createFont(); font.setColor((short) 8); font.setFontHeightInPoints((short) 12); font.setBoldweight((short) 700); HSSFCellStyle style = workbook.createCellStyle(); style.setFont(font); style.setAlignment((short) 2); style.setVerticalAlignment((short) 1); if (titleArr != null && titleArr.length > 0) { for (int i = 0; i < titleArr.length; ++i) { HSSFCell cell = createRow.createCell(i); cell.setCellStyle(style); cell.setCellValue(titleArr[i]); if (i > 3) { sheet.setColumnWidth(i, 15360); } else { sheet.setColumnWidth(i, 7680); } } } } private void fillWorkdBookData(HSSFWorkbook workbook, List dataList) { HSSFSheet sheet = workbook.getSheetAt(0); if (dataList != null && dataList.size() > 0) { for (int i = 0; i < dataList.size(); ++i) { HSSFRow row = sheet.createRow(i + 2); TaxDeclarExcelRowDTO excelRowDTO = (TaxDeclarExcelRowDTO) dataList.get(i); HSSFCell cell = row.createCell(0); cell.setCellValue(excelRowDTO.getPersonNum()); cell = row.createCell(1); cell.setCellValue(excelRowDTO.getPersonName()); cell = row.createCell(2); cell.setCellValue(excelRowDTO.getTaxName()); cell = row.createCell(3); cell.setCellValue(excelRowDTO.getDeclarType()); cell = row.createCell(4); cell.setCellValue(excelRowDTO.getReason()); cell = row.createCell(5); cell.setCellValue(excelRowDTO.getOperation()); } } } private String getSqlDateFilterLqDate(String dateStr) { String[] beginDateArr = dateStr.split("-"); Calendar calendar = Calendar.getInstance(); calendar.set(Integer.parseInt(beginDateArr[0]), Integer.parseInt(beginDateArr[1]) - 1, 1, 0, 0, 0); Date beginDate = calendar.getTime(); return CmpDateUtil.toKSqlDate(beginDate); } private List getExceptData(Context ctx, List preCheckSql, List specCheckForPre, Map noCalDataOper, TbTypeEnum typeEnum) throws BOSException, SQLException, ShrWebBizException { List taxDeclarExcelRowDTOS = new ArrayList(); Iterator i$; String s; IRowSet rowSet; TaxDeclarExcelRowDTO taxDeclareExcelRow; if (preCheckSql != null && preCheckSql.size() > 0) { i$ = preCheckSql.iterator(); while (i$.hasNext()) { s = (String) i$.next(); rowSet = DbUtil.executeQuery(ctx, s); while (rowSet.next()) { taxDeclareExcelRow = new TaxDeclarExcelRowDTO(); taxDeclareExcelRow.setPersonNum(rowSet.getString("FNUMBER")); taxDeclareExcelRow.setPersonName(rowSet.getString("PERSONNAME")); String taxUnitName = rowSet.getString("TAXNAME"); taxDeclareExcelRow.setTaxName(taxUnitName); taxDeclareExcelRow.setDeclarType(typeEnum.getAlias()); taxDeclareExcelRow.setReason((String) noCalDataOper.get("noCalDataReson")); taxDeclareExcelRow.setOperation((String) noCalDataOper.get("noCalDataOper")); String incomeCode = (String) noCalDataOper.get("fIncomeCode"); taxDeclarExcelRowDTOS.add(taxDeclareExcelRow); } } } if ("1".equals(typeEnum.getValue()) && specCheckForPre != null && specCheckForPre.size() > 0) { i$ = specCheckForPre.iterator(); while (i$.hasNext()) { s = (String) i$.next(); rowSet = DbUtil.executeQuery(ctx, s); while (rowSet.next()) { taxDeclareExcelRow = new TaxDeclarExcelRowDTO(); taxDeclareExcelRow.setPersonNum(rowSet.getString("FNUMBER")); taxDeclareExcelRow.setPersonName(rowSet.getString("PERSONNAME")); taxDeclareExcelRow.setTaxName(rowSet.getString("TAXNAME")); taxDeclareExcelRow.setDeclarType(typeEnum.getAlias()); taxDeclareExcelRow.setReason((String) noCalDataOper.get("preDataReason")); taxDeclareExcelRow.setOperation((String) noCalDataOper.get("preDataOpera")); taxDeclarExcelRowDTOS.add(taxDeclareExcelRow); } } } return taxDeclarExcelRowDTOS; } private String getPreCheckSql(IncomeTaxDeclarInfo incomeTaxDeclarInfo) { StringBuilder sqlBuf = new StringBuilder(); String yearMonth = incomeTaxDeclarInfo.getYearMonth(); String taxUnitId = incomeTaxDeclarInfo.getTaxUnit().getId().toString(); String sql = "select FPersonID from T_HR_STaxCalConfigDetail where FTaxUnitId='" + taxUnitId + "' and FPeriodBegin = " + CmpDateUtil.toKSqlDate(incomeTaxDeclarInfo.getYearMonthDate()); sqlBuf.append(" SELECT distinct ent.FTAXUNITID, t.Fname_l2 as TAXNAME, p.FNUMBER, p.Fname_l2 as PERSONNAME "); sqlBuf.append(" FROM T_HR_STaxPersonRecordEntry ent "); sqlBuf.append(" left join T_HR_TAXUNIT as t on t.fid = ent.FTaxUnitID "); sqlBuf.append(" left join T_BD_PERSON as p on p.fid = ent.FPersonId "); sqlBuf.append(" where ent.FSubmitStatus='2' and ent.FPersonStatus='1' "); sqlBuf.append(" and ent.FTaxUnitID='").append(taxUnitId).append("'"); sqlBuf.append(" and ent.FENDDATE <=").append(this.getSqlDateFilterLqDate(yearMonth)); sqlBuf.append(" and ent.FPersonID not in ( ").append(sql).append(" )"); return sqlBuf.toString(); } private Map checkIncomeTaxIssue(Context ctx, List waitToDeclareList) throws BOSException { StringBuilder taxUnitIds = new StringBuilder(); IncomeTaxDeclarInfo declareInfo; for (Iterator i$ = waitToDeclareList.iterator(); i$.hasNext(); taxUnitIds.append(declareInfo.getTaxUnit().getId().toString())) { declareInfo = (IncomeTaxDeclarInfo) i$.next(); if (taxUnitIds.length() > 0) { taxUnitIds.append(","); } } String oql = "select person.person.name where taxUnit.id in " + CmpStrUtil.buildInSql(taxUnitIds.toString()) + " and result = " + 1 + " and status = " + 2 + " and inviteStatus = " + 0; IncomeTaxIssueCollection collection = IncomeTaxIssueFactory.getLocalInstance(ctx).getIncomeTaxIssueCollection(oql); if (collection != null && !collection.isEmpty()) { StringBuilder errMsg = new StringBuilder(); for (int i = 0; i < collection.size() && i != 5; ++i) { if (errMsg.length() > 0) { errMsg.append(","); } errMsg.append("[").append(collection.get(i).getPerson().getPerson().getName()).append("]"); } Map map = new HashMap(); map.put("errMsg", "以下员工存在申诉属实争议,且未进行邀请确认,需要进行发送邀请确认后才可进行个税申报或者进行非正常人员报送(更新人员报税信息中的人员状态为非正常,并进行人员报送成功),员工姓名:" + errMsg.toString() + ",选择[是]则跳转到[申诉争议-申诉属实人员]列表,选择[否]则跳转到[人员报税信息]列表。"); map.put("issueError", true); return map; } else { return null; } } private String checkTaxCalStatus(Context ctx, List waitToDeclareList) throws SHRWebException { String sql = "select t.fState, u.fName_l2 taxUnitName, d.fIncomeItemId from t_hr_sTaxCalConfigDetail d left join t_hr_sTaxCalInitDetail t on d.fCmpCalTableId = t.fCmpCalTableId and d.fIncomeItemId = t.fIncomeItemId left join t_hr_taxUnit u on d.fTaxUnitId = u.fid where d.fTaxUnitId = ? and d.fPeriodBegin = ?"; try { Iterator i$ = waitToDeclareList.iterator(); boolean isTaxCalFinished; String taxUnitName; do { if (!i$.hasNext()) { return null; } IncomeTaxDeclarInfo declareInfo = (IncomeTaxDeclarInfo) i$.next(); String taxUnitId = declareInfo.getTaxUnit().getId().toString(); Date periodDate = declareInfo.getYearMonthDate(); Object[] param = new Object[]{taxUnitId, CmpDateUtil.toSqlDate(periodDate)}; IRowSet rs = DbUtil.executeQuery(ctx, sql, param); boolean havingSalaryIncome = false; isTaxCalFinished = true; taxUnitName = ""; while (rs.next()) { int state = rs.getInt("fState"); taxUnitName = rs.getString("taxUnitName"); String incomeItemId = rs.getString("fIncomeItemId"); if (state != 40) { isTaxCalFinished = false; } if ("8r0AAABCg2PDiOoP".equals(incomeItemId)) { havingSalaryIncome = true; } } TbTypeEnum typeEnum = declareInfo.getTbType(); if (!havingSalaryIncome && typeEnum == TbTypeEnum.SB0701) { return "纳税单位[" + taxUnitName + "]当期预扣预缴申报表未包含所得项目为正常工资薪金所得的员工,不允许申报,请确认"; } } while (isTaxCalFinished); return "纳税单位【" + taxUnitName + "】存在接口算税未完成的数据,请确认"; } catch (Exception var15) { LOG.error("checkTaxCalStatus error: ", var15); throw new SHRWebException(var15.getMessage()); } } /** * 异常提醒 * * @param advanceDeclareInfo * @return */ private String combineError(List advanceDeclareInfo) { StringBuilder error = new StringBuilder(); error.append("以下纳税单位尚未到申报时间,请不要提前申报:"); Iterator i$ = advanceDeclareInfo.iterator(); while (i$.hasNext()) { String taxUnitInfo = (String) i$.next(); if (advanceDeclareInfo.indexOf(taxUnitInfo) == 5) { error.append("..."); break; } if (advanceDeclareInfo.indexOf(taxUnitInfo) > 0) { error.append(","); } String[] arr = taxUnitInfo.split("_"); error.append(arr[0]).append("【").append(arr[1]).append("】"); } return error.toString(); } /** * 获取个税申报审批通过数据 * * @param ctx * @param selectedId * @return * @throws BOSException */ private Map getDeclareData(Context ctx, String selectedId) throws BOSException, JsonProcessingException { Map resultMap = new HashMap(); List declaredList = new ArrayList(); List waitToDeclareList = new ArrayList(); String sqlInString = CmpUtils.spiltToSqlString(selectedId); if (StringUtils.isEmpty(sqlInString)) { sqlInString = "''"; } String currentYearMonth = CmpDateUtil.getDateStr(new Date(), "yyyy-MM"); String oqlBuffer = "select id,yearMonth,totalPerson,totalMoney,taxRebate,declareStatus,versionCode,yearMonthDate,tbType,taxUnit.id,taxUnit.name,taxUnit.taxNumber,taxUnit.regNumber,taxUnit.areaCode,taxUnit.declPassword, batchNo where id in ( " + sqlInString + " )"; LOG.error("getDeclareData----------oqlBuffer------" + oqlBuffer); IncomeTaxDeclarCollection declareCollection = IncomeTaxDeclarFactory.getLocalInstance(ctx).getIncomeTaxDeclarCollection(oqlBuffer); LOG.error("getDeclareData----------declareCollection------" + declareCollection.size()); String ms1 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label137", ctx.getLocale()); String ms2 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label138", ctx.getLocale()); String ms3 = EASResource.getString("com.kingdee.shr.compensation.resource.CommonResource", "label139", ctx.getLocale()); List taxUnitInfo = new ArrayList(); if (declareCollection != null && declareCollection.size() > 0) { for (int i = 0; i < declareCollection.size(); ++i) { IncomeTaxDeclarInfo declareInfo = declareCollection.get(i); String declareStatus = declareInfo.getDeclareStatus().getValue(); LOG.error("getDeclareData----------declareStatus------" + declareStatus); String taxUnitName = declareInfo.getTaxUnit().getName(); String tbTypeAlia = declareInfo.getTbType().getAlias(); if (currentYearMonth.compareTo(declareInfo.getYearMonth()) <= 0) { taxUnitInfo.add(declareInfo.getTaxUnit().getName() + "_" + declareInfo.getYearMonth()); } if (!"1".equals(declareStatus) && !"2".equals(declareStatus)) { waitToDeclareList.add(declareInfo); LOG.error("getDeclareData----------waitToDeclareList------" + waitToDeclareList); } else { TaxDeclareDTO dto = new TaxDeclareDTO(taxUnitName, tbTypeAlia); declaredList.add(dto); } } if (declaredList.size() == declareCollection.size()) { resultMap.put("info", ms1); } else if (declaredList.size() == 0) { resultMap.put("info", ms2); } else { resultMap.put("info", ms3); } } LOG.error("getDeclareData----------resultMap------" + resultMap); resultMap.put("DECLARED", declaredList); resultMap.put("advanceDeclareInfo", taxUnitInfo); resultMap.put("WATI_TO_DECLARE", waitToDeclareList); return resultMap; } }