From 019ad9687157e4feb4e7b5098cae8e1d2676e993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E6=B6=9B?= <15850646081@163.com> Date: Tue, 31 May 2022 11:21:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B6=E4=BB=96=E6=89=A3=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../salary/service/OtherDeductionService.java | 2 +- .../impl/OtherDeductionServiceImpl.java | 54 ++++---- .../salary/web/OtherDeductionController.java | 41 ++---- .../salary/wrapper/OtherDeductionWrapper.java | 129 ++++++------------ 4 files changed, 83 insertions(+), 143 deletions(-) diff --git a/src/com/engine/salary/service/OtherDeductionService.java b/src/com/engine/salary/service/OtherDeductionService.java index f41765a61..f0c47b9c1 100644 --- a/src/com/engine/salary/service/OtherDeductionService.java +++ b/src/com/engine/salary/service/OtherDeductionService.java @@ -69,7 +69,7 @@ public interface OtherDeductionService { /** * 预览 */ - Map preview(Map params); + Map preview(OtherDeductionImportParam importParam); /** * 导入数据 diff --git a/src/com/engine/salary/service/impl/OtherDeductionServiceImpl.java b/src/com/engine/salary/service/impl/OtherDeductionServiceImpl.java index 168166a65..de7c5de70 100644 --- a/src/com/engine/salary/service/impl/OtherDeductionServiceImpl.java +++ b/src/com/engine/salary/service/impl/OtherDeductionServiceImpl.java @@ -1,5 +1,6 @@ package com.engine.salary.service.impl; +import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.biz.EmployBiz; import com.engine.salary.biz.OtherDeductionBiz; @@ -39,6 +40,7 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.file.ImageFileManager; import weaver.general.Util; +import weaver.hrm.User; import java.io.InputStream; import java.text.SimpleDateFormat; @@ -53,11 +55,16 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction private OtherDeductionMapper getOtherDeductionMapper() { return MapperProxyFactory.getProxy(OtherDeductionMapper.class); } - - private OtherDeductionMapper otherDeductionMapper; - private TaxAgentV2Service taxAgentService; - private AddUpDeductionService addUpDeductionService; - private SalaryEmployeeService salaryEmployeeService; + + private TaxAgentV2Service getTaxAgentV2Service(User user) { + return ServiceUtil.getService(TaxAgentV2ServiceImpl.class, user); + } + private AddUpDeductionService getAddUpDeductionService(User user) { + return ServiceUtil.getService(AddUpDeductionServiceImpl.class, user); + } + private SalaryEmployeeService getSalaryEmployeeService(User user) { + return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user); + } @Override public OtherDeductionPO getById(Long id) { @@ -69,15 +76,15 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction public PageInfo listPage(OtherDeductionQueryParam queryParam) { long employeeId = user.getUID(); // 未开启分权或是薪酬模块总管理员 - if (!taxAgentService.isOpenDevolution() || taxAgentService.isChief(employeeId)) { + if (!getTaxAgentV2Service(user).isOpenDevolution() || getTaxAgentV2Service(user).isChief(employeeId)) { SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize()); - List list = otherDeductionMapper.list(queryParam); + List list = getOtherDeductionMapper().list(queryParam); return new PageInfo<>(list, OtherDeductionListDTO.class); } else { - List taxAgentEmployees = taxAgentService.listTaxAgentAndEmployee(employeeId); - List taxAgentIdsAsAdmin = taxAgentService.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList()); + List taxAgentEmployees = getTaxAgentV2Service(user).listTaxAgentAndEmployee(employeeId); + List taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList()); // List lastList = getLastListByModifier(employeeId, tenantKey); - List list = otherDeductionMapper.list(queryParam); + List list = getOtherDeductionMapper().list(queryParam); list = list.stream().filter(f -> // 作为管理员 @@ -97,15 +104,15 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction public PageInfo recordListPage(OtherDeductionQueryParam queryParam) { long employeeId = user.getUID(); // 未开启分权或是薪酬模块总管理员 - if (!taxAgentService.isOpenDevolution() || taxAgentService.isChief(employeeId)) { + if (!getTaxAgentV2Service(user).isOpenDevolution() || getTaxAgentV2Service(user).isChief(employeeId)) { SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize()); - List list = otherDeductionMapper.recordList(queryParam); + List list = getOtherDeductionMapper().recordList(queryParam); return new PageInfo<>(list, OtherDeductionRecordDTO.class); } else { - List taxAgentEmployees = taxAgentService.listTaxAgentAndEmployee(employeeId); - List taxAgentIdsAsAdmin = taxAgentService.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList()); + List taxAgentEmployees = getTaxAgentV2Service(user).listTaxAgentAndEmployee(employeeId); + List taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList()); // List lastList = getLastListByModifier(employeeId, tenantKey); - List list = otherDeductionMapper.recordList(queryParam); + List list = getOtherDeductionMapper().recordList(queryParam); list = list.stream().filter(f -> // 作为管理员 @@ -122,11 +129,9 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction @Override - public Map preview(Map params) { + public Map preview(OtherDeductionImportParam importParam) { Map apidatas = new HashMap(); - //导入参数 - OtherDeductionImportParam importParam = (OtherDeductionImportParam) params.get("importParam"); //excel文件id String imageId = Util.null2String(importParam.getImageId()); Validate.notBlank(imageId, "imageId为空"); @@ -174,13 +179,13 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction List employees = employBiz.listEmployee(); List taxAgents = new TaxAgentBiz().listAll(); // 获取所有个税扣缴义务人 - Collection taxAgentList = taxAgentService.listTaxAgentAndEmployeeTree(currentEmployeeId); + Collection taxAgentList = getTaxAgentV2Service(user).listTaxAgentAndEmployeeTree(currentEmployeeId); //税款所属期 Date declareMonth = SalaryDateUtil.stringToDate(declareMonthStr + "-01"); // 获取已经核算的数据 - List salaryAcctEmployees = addUpDeductionService.getAccountedEmployeeData(declareMonthStr); + List salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr); // 查询已有数据 - List list = otherDeductionMapper.listSome(OtherDeductionPO.builder().declareMonth(declareMonth).build()); + List list = getOtherDeductionMapper().listSome(OtherDeductionPO.builder().declareMonth(declareMonth).build()); // 错误excel内容 List errorData = new ArrayList<>(); @@ -359,6 +364,7 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction } } + /** * 导出 * @@ -387,9 +393,9 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction List list = getOtherDeductionMapper().list(param); // 开启分权并且不是薪酬模块总管理员 - if (taxAgentService.isOpenDevolution() && !taxAgentService.isChief(employeeId)) { -// List taxAgentEmployees = taxAgentService.listTaxAgentAndEmployee(employeeId); - List taxAgentIdsAsAdmin = taxAgentService.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList()); + if (getTaxAgentV2Service(user).isOpenDevolution() && !getTaxAgentV2Service(user).isChief(employeeId)) { +// List taxAgentEmployees = getTaxAgentV2Service(user).listTaxAgentAndEmployee(employeeId); + List taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList()); list = list.stream().filter(f -> // 作为管理员 taxAgentIdsAsAdmin.contains(f.getTaxAgentId()) diff --git a/src/com/engine/salary/web/OtherDeductionController.java b/src/com/engine/salary/web/OtherDeductionController.java index c344a7c8b..528564f81 100644 --- a/src/com/engine/salary/web/OtherDeductionController.java +++ b/src/com/engine/salary/web/OtherDeductionController.java @@ -1,12 +1,13 @@ package com.engine.salary.web; -import com.engine.common.util.ParamUtil; import com.engine.common.util.ServiceUtil; +import com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO; +import com.engine.salary.entity.datacollection.dto.OtherDeductionRecordDTO; import com.engine.salary.entity.datacollection.param.OtherDeductionImportParam; import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam; -import com.engine.salary.service.OtherDeductionService; -import com.engine.salary.service.impl.OtherDeductionServiceImpl; import com.engine.salary.util.ResponseResult; +import com.engine.salary.util.page.PageInfo; +import com.engine.salary.wrapper.OtherDeductionWrapper; import io.swagger.v3.oas.annotations.parameters.RequestBody; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -47,8 +48,8 @@ import java.util.stream.Collectors; @Slf4j public class OtherDeductionController { - private OtherDeductionService getService(User user) { - return (OtherDeductionService) ServiceUtil.getService(OtherDeductionServiceImpl.class, user); + private OtherDeductionWrapper getOtherDeductionWrapper(User user) { + return ServiceUtil.getService(OtherDeductionWrapper.class, user); } /** @@ -61,7 +62,7 @@ public class OtherDeductionController { @Produces(MediaType.APPLICATION_JSON) public String getSearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) { User user = HrmUserVarify.getUser(request, response); - return new ResponseResult, Map>(user).run(getService(user)::getSearchCondition, ParamUtil.request2Map(request)); + return new ResponseResult, Map>(user).run(getOtherDeductionWrapper(user)::getSearchCondition); } @@ -70,9 +71,7 @@ public class OtherDeductionController { @Produces(MediaType.APPLICATION_JSON) public String list(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionQueryParam queryParam) { User user = HrmUserVarify.getUser(request, response); - Map map = ParamUtil.request2Map(request); - map.put("queryParam", queryParam); - return new ResponseResult, Map>(user).run(getService(user)::list, map); + return new ResponseResult>(user).run(getOtherDeductionWrapper(user)::list, queryParam); } @@ -81,9 +80,7 @@ public class OtherDeductionController { @Produces(MediaType.APPLICATION_JSON) public String getDetailList(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionQueryParam queryParam) { User user = HrmUserVarify.getUser(request, response); - Map map = ParamUtil.request2Map(request); - map.put("queryParam", queryParam); - return new ResponseResult, Map>(user).run(getService(user)::getDetailList, map); + return new ResponseResult>(user).run(getOtherDeductionWrapper(user)::getDetailList, queryParam); } @@ -94,7 +91,7 @@ public class OtherDeductionController { try { User user = HrmUserVarify.getUser(request, response); OtherDeductionQueryParam param = buildParam(request); - XSSFWorkbook workbook = getService(user).downloadTemplate(param); + XSSFWorkbook workbook = getOtherDeductionWrapper(user).downloadTemplate(param); String fileName = "其他免税扣除导入模板" + LocalDate.now(); try { fileName = URLEncoder.encode(fileName + ".xlsx", "UTF-8"); @@ -131,10 +128,7 @@ public class OtherDeductionController { OtherDeductionQueryParam param = buildParam(request); - Map map = ParamUtil.request2Map(request); - map.put("queryParam", param); - - XSSFWorkbook workbook = getService(user).export(map); + XSSFWorkbook workbook = getOtherDeductionWrapper(user).export(param); String fileName = null; try { @@ -168,10 +162,7 @@ public class OtherDeductionController { OtherDeductionQueryParam param = buildParam(request); - Map map = ParamUtil.request2Map(request); - map.put("queryParam", param); - - XSSFWorkbook workbook = getService(user).exportDetail(map); + XSSFWorkbook workbook = getOtherDeductionWrapper(user).exportDetail(param); String fileName = "其他免税扣除明细" + LocalDate.now(); try { @@ -269,9 +260,7 @@ public class OtherDeductionController { @Produces(MediaType.APPLICATION_JSON) public String preview(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionImportParam importParam) { User user = HrmUserVarify.getUser(request, response); - Map map = ParamUtil.request2Map(request); - map.put("importParam", importParam); - return new ResponseResult, Map>(user).run(getService(user)::preview, map); + return new ResponseResult>(user).run(getOtherDeductionWrapper(user)::preview, importParam); } @POST @@ -279,9 +268,7 @@ public class OtherDeductionController { @Produces(MediaType.APPLICATION_JSON) public String importAddUpDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionImportParam importParam) { User user = HrmUserVarify.getUser(request, response); - Map map = ParamUtil.request2Map(request); - map.put("importParam", importParam); - return new ResponseResult, Map>(user).run(getService(user)::importData, map); + return new ResponseResult>(user).run(getOtherDeductionWrapper(user)::importData, importParam); } diff --git a/src/com/engine/salary/wrapper/OtherDeductionWrapper.java b/src/com/engine/salary/wrapper/OtherDeductionWrapper.java index 6a6295caa..f43ffc63d 100644 --- a/src/com/engine/salary/wrapper/OtherDeductionWrapper.java +++ b/src/com/engine/salary/wrapper/OtherDeductionWrapper.java @@ -5,47 +5,46 @@ import com.api.browser.bean.SearchConditionItem; import com.api.browser.bean.SearchConditionOption; import com.api.browser.util.ConditionFactory; import com.api.browser.util.ConditionType; +import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO; import com.engine.salary.entity.datacollection.dto.OtherDeductionRecordDTO; +import com.engine.salary.entity.datacollection.param.OtherDeductionImportParam; import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam; import com.engine.salary.entity.datacollection.po.OtherDeductionPO; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.service.OtherDeductionService; import com.engine.salary.service.SalaryEmployeeService; import com.engine.salary.service.TaxAgentV2Service; +import com.engine.salary.service.impl.OtherDeductionServiceImpl; +import com.engine.salary.service.impl.SalaryEmployeeServiceImpl; +import com.engine.salary.service.impl.TaxAgentV2ServiceImpl; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.page.PageInfo; -import com.weaver.common.authority.format.FormatManager; -import com.weaver.common.component.table.WeaTable; -import com.weaver.common.component.table.page.Page; -import com.weaver.datasecurity.interceptor.DSTenantKeyThreadVar; -import com.weaver.framework.rpc.context.impl.TenantRpcContext; -import com.weaver.hrm.salary.common.excel.ExcelImportParam; -import com.weaver.teams.security.context.TenantContext; -import com.weaver.teams.security.context.UserContext; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import weaver.hrm.User; import weaver.systeminfo.SystemEnv; -import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * @Description: 其他免税扣除 * @Author: wangxiangzhong * @Date: 2022/3/14 16:09 */ -@Component public class OtherDeductionWrapper extends Service { - private OtherDeductionService otherDeductionService; - private TaxAgentV2Service taxAgentService; - private SalaryEmployeeService salaryEmployeeService; - + private OtherDeductionService getOtherDeductionService(User user) { + return ServiceUtil.getService(OtherDeductionServiceImpl.class, user); + } + private TaxAgentV2Service getTaxAgentV2Service(User user) { + return ServiceUtil.getService(TaxAgentV2ServiceImpl.class, user); + } + private SalaryEmployeeService getSalaryEmployeeService(User user) { + return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user); + } /** * 数据采集-其他免税扣除列表的高级搜索 * @@ -139,7 +138,7 @@ public class OtherDeductionWrapper extends Service { public PageInfo list(OtherDeductionQueryParam queryParam) { // queryParam.setDeclareMonthDate(queryParam.getDeclareMonth().stream().map(e-> LocalDate.of(e.getYear(),e.getMonthValue(),1)).collect(Collectors.toList())); - return otherDeductionService.listPage(queryParam); + return getOtherDeductionService(user).listPage(queryParam); } @@ -152,114 +151,62 @@ public class OtherDeductionWrapper extends Service { public PageInfo getDetailList(OtherDeductionQueryParam queryParam) { Long id = queryParam.getOtherTaxExemptDeductionId(); - OtherDeductionPO po = otherDeductionService.getById(id); + OtherDeductionPO po = getOtherDeductionService(user).getById(id); if (po == null) { throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel(100415, "其他免税扣除不存在") + "[id:%s]", id)); } - queryParam.setDeclareMonthDate(queryParam.getDeclareMonth().stream().map(e -> LocalDate.of(e.getYear(), e.getMonthValue(), 1)).collect(Collectors.toList())); +// queryParam.setDeclareMonthDate(queryParam.getDeclareMonth().stream().map(e -> LocalDate.of(e.getYear(), e.getMonthValue(), 1)).collect(Collectors.toList())); queryParam.setEmployeeId(po.getEmployeeId()); - Page page = new Page<>(queryParam.getCurrent(), queryParam.getPageSize(), true); - page = otherDeductionService.recordListPage(page, queryParam, currentEmployeeId, currentTenantKey); - // 记录表格 - WeaTable weaTable = FormatManager.getInstance() - .genTable(OtherDeductionRecordDTO.class, page); - weaTable.setModule("hrmsalary"); - return weaTable; + return getOtherDeductionService(user).recordListPage(queryParam); } /** * 导出-其他免税扣除列表 * * @param queryParam - * @param currentEmployeeId - * @param currentTenantKey * @return */ - public Map export(OtherDeductionQueryParam queryParam, Long currentEmployeeId, String currentTenantKey) { - // 构建异步导出参数 - Map map = salaryBatchService.buildeExportParam("exportOtherDeduction"); - - String username = UserContext.getCurrentUser().getUsername(); - String eteamsId = TenantRpcContext.getEteamsId(); - boolean isChief = taxAgentService.isChief(currentEmployeeId, currentTenantKey); - taskExecutor.execute(() -> { - try { - DSTenantKeyThreadVar.tenantKey.set(currentTenantKey); - otherDeductionService.export(map, username, eteamsId, isChief, queryParam, currentEmployeeId, currentTenantKey); - } finally { - DSTenantKeyThreadVar.tenantKey.remove(); - } - }); - return map; + public XSSFWorkbook export(OtherDeductionQueryParam queryParam) { + return getOtherDeductionService(user).export(queryParam); } /** * 导出-其他免税扣除详情列表 * * @param queryParam - * @param currentEmployeeId - * @param currentTenantKey * @return */ - public Map exportDetail(OtherDeductionQueryParam queryParam, Long currentEmployeeId, String currentTenantKey) { + public XSSFWorkbook exportDetail(OtherDeductionQueryParam queryParam) { Long id = queryParam.getOtherTaxExemptDeductionId(); - OtherDeductionPO po = otherDeductionService.getById(id, currentTenantKey); + OtherDeductionPO po = getOtherDeductionService(user).getById(id); if (po == null) { - throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100415, "其他免税扣除不存在") + "[id:%s]", id)); + throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel( 100415, "其他免税扣除不存在") + "[id:%s]", id)); } - boolean isChief = taxAgentService.isChief(currentEmployeeId, currentTenantKey); - // 构建异步导出参数 - Map map = salaryBatchService.buildeExportParam("exportOtherDeductionDetail"); - - String username = UserContext.getCurrentUser().getUsername(); - String eteamsId = TenantRpcContext.getEteamsId(); - taskExecutor.execute(() -> { - try { - DSTenantKeyThreadVar.tenantKey.set(currentTenantKey); - otherDeductionService.exportDetail(map, username, eteamsId, po.getEmployeeId(), isChief, queryParam, currentEmployeeId, currentTenantKey); - } finally { - DSTenantKeyThreadVar.tenantKey.remove(); - } - }); - return map; + return getOtherDeductionService(user).exportDetail(queryParam); } /** * 下载导入模板 * * @param queryParam - * @param currentEmployeeId - * @param currentTenantKey * @return */ - public Map downloadTemplate(OtherDeductionQueryParam queryParam, Long currentEmployeeId, String currentTenantKey) { - // 构建异步导出参数 - Map map = salaryBatchService.buildeExportParam("exportOtherDeduction"); - boolean isChief = taxAgentService.isChief(currentEmployeeId, currentTenantKey); - String username = UserContext.getCurrentUser().getUsername(); - String eteamsId = TenantRpcContext.getEteamsId(); - taskExecutor.execute(() -> { - try { - DSTenantKeyThreadVar.tenantKey.set(currentTenantKey); - otherDeductionService.export(map, username, eteamsId, isChief, queryParam, currentEmployeeId, currentTenantKey); - } finally { - DSTenantKeyThreadVar.tenantKey.remove(); - } - }); - return map; + public XSSFWorkbook downloadTemplate(OtherDeductionQueryParam queryParam) { + return getOtherDeductionService(user).export(queryParam); } /** - * 获取导入参数 - * - * @return + * 预览 */ - public ExcelImportParam getImportParams() { - return salaryBatchService.buildImportParam("importOtherDeduction", - "importOtherDeduction", - SalaryI18nUtil.getI18nLabel(TenantContext.getCurrentTenantKey(), UserContext.getCurrentEmployeeId(), 93849, "其他免税扣除"), - null, - null); + public Map preview(OtherDeductionImportParam importParam){ + return getOtherDeductionService(user).preview(importParam); + } + + /** + * 导入数据 + */ + public Map importData(OtherDeductionImportParam importParam){ + return getOtherDeductionService(user).importData(importParam); } }