feat: 其他附加扣除沿用上月功能完成

This commit is contained in:
fcli 2022-11-16 11:08:45 +08:00
parent 15749ecc10
commit 5743fa2162
6 changed files with 168 additions and 39 deletions

View File

@ -0,0 +1,21 @@
package com.engine.salary.entity.datacollection.param;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class OtherDeductionExtendLastParam {
private String declareMonth;
private LocalDateTime yearMonthTime;
private Integer taxAgentId;
}

View File

@ -2,10 +2,7 @@ package com.engine.salary.service;
import com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO;
import com.engine.salary.entity.datacollection.dto.OtherDeductionRecordDTO;
import com.engine.salary.entity.datacollection.param.AddUpDeductionRecordDeleteParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionImportParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam;
import com.engine.salary.entity.datacollection.param.*;
import com.engine.salary.entity.datacollection.po.OtherDeductionPO;
import com.engine.salary.util.page.PageInfo;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -113,4 +110,6 @@ public interface OtherDeductionService {
* 获取数据
*/
OtherDeductionRecordDTO getOtherDeduction(OtherDeductionParam otherDeductionParam);
String extendToLastMonth(OtherDeductionExtendLastParam param);
}

View File

@ -1,10 +1,12 @@
package com.engine.salary.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.api.formmode.mybatis.util.SqlProxyHandle;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.biz.EmployBiz;
import com.engine.salary.biz.OtherDeductionBiz;
import com.engine.salary.constant.SalaryDefaultTenantConstant;
import com.engine.salary.encrypt.datacollection.OtherDeductionListDTOEncrypt;
import com.engine.salary.encrypt.datacollection.OtherDeductionRecordDTOEncrypt;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
@ -49,6 +51,7 @@ import weaver.hrm.User;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.*;
import java.util.stream.Collectors;
@ -563,12 +566,12 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
OtherDeductionPO byId = OtherDeductionBiz.getById(otherDeductionParam.getId());
if(byId == null){
if (byId == null) {
throw new SalaryRunTimeException("该数据不存在!");
}
Long taxAgentId = byId.getTaxAgentId();
boolean canEdit = taxAgentList.stream().anyMatch(t -> Objects.equals(t.getTaxAgentId() , taxAgentId));
if(!canEdit){
boolean canEdit = taxAgentList.stream().anyMatch(t -> Objects.equals(t.getTaxAgentId(), taxAgentId));
if (!canEdit) {
//没有编辑权限
throw new SalaryRunTimeException("该个税扣缴义务人无权限编辑此数据!");
}
@ -577,8 +580,8 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction
// 判断是否有核算过
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(otherDeductionParam.getEmployeeId()) && f.getTaxAgentId().equals(otherDeductionParam.getTaxAgentId())).findFirst();
if (optionalAcctEmp.isPresent()) {
throw new SalaryRunTimeException("该年月这条数据已经核算过,不可进行编辑!");
if (optionalAcctEmp.isPresent()) {
throw new SalaryRunTimeException("该年月这条数据已经核算过,不可进行编辑!");
}
}
ArrayList<OtherDeductionPO> updateList = new ArrayList<>();
@ -622,8 +625,8 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction
.declareMonth(declareMonth).build();
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
boolean employeeSameId = employees.stream().anyMatch(e -> Objects.equals(e.getEmployeeId() , otherDeductionParam.getEmployeeId()));
if(!employeeSameId){
boolean employeeSameId = employees.stream().anyMatch(e -> Objects.equals(e.getEmployeeId(), otherDeductionParam.getEmployeeId()));
if (!employeeSameId) {
throw new SalaryRunTimeException("员工信息不存在");
}
po.setEmployeeId(otherDeductionParam.getEmployeeId());
@ -655,7 +658,7 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction
String deductionAllowedDonation = otherDeductionParam.getDeductionAllowedDonation();
po.setDeductionAllowedDonation(deductionAllowedDonation);
//fixme 分权判断
//fixme 分权判断
// if (openDevolution) {
// OtherDeductionPO finalPoE = po;
// Optional<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> optionalTaxAgentEmp = taxAgentEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPoE.getEmployeeId())).findFirst();
@ -694,15 +697,15 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
// 判断是否有核算过
List<Long> deleteList = new ArrayList<>();
for(int i=0; i<deleteIds.size(); i++){
for (int i = 0; i < deleteIds.size(); i++) {
Long id = deleteIds.get(i);
OtherDeductionPO byId = otherDeductionBiz.getById(id);
if(byId == null){
if (byId == null) {
throw new SalaryRunTimeException("数据不存在或已被删除!");
}
// 判断是否在个税扣缴义务人范围内
Optional<TaxAgentManageRangeEmployeeDTO> first = taxAgentList.stream().filter(m -> Objects.equals(m.getTaxAgentId() , byId.getTaxAgentId())).findFirst();
if(!first.isPresent()){
Optional<TaxAgentManageRangeEmployeeDTO> first = taxAgentList.stream().filter(m -> Objects.equals(m.getTaxAgentId(), byId.getTaxAgentId())).findFirst();
if (!first.isPresent()) {
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
}
// 判断用户是否存在
@ -726,32 +729,32 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
List<Long> taxAgentIds = taxAgentList.stream().map(TaxAgentManageRangeEmployeeDTO::getTaxAgentId).collect(Collectors.toList());
OtherDeductionBiz otherDeductionBiz = new OtherDeductionBiz();
Date declareMonthDate =null;
Date declareMonthDate = null;
try {
declareMonthDate = sdf.parse(declareMonthStr+"-01");
}catch (Exception e){
declareMonthDate = sdf.parse(declareMonthStr + "-01");
} catch (Exception e) {
throw new SalaryRunTimeException("日期异常");
}
OtherDeductionPO queryParam = null;
if(deleteParam.getTaxAgentId() != null && (!deleteParam.getTaxAgentId().equals(""))){
if (deleteParam.getTaxAgentId() != null && (!deleteParam.getTaxAgentId().equals(""))) {
// 设置了个税扣缴义务人
Long taxAgentId = SalaryEntityUtil.string2Long(deleteParam.getTaxAgentId());
boolean canDelete = taxAgentIds.stream().anyMatch(t -> Objects.equals(t , taxAgentId));
if(!canDelete){
boolean canDelete = taxAgentIds.stream().anyMatch(t -> Objects.equals(t, taxAgentId));
if (!canDelete) {
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内!");
}
ArrayList<Long> tai = new ArrayList<>();
tai.add(taxAgentId);
queryParam = OtherDeductionPO.builder().declareMonth(declareMonthDate).taxAgentIds(tai).build();
}else {
queryParam = OtherDeductionPO.builder().declareMonth(declareMonthDate).taxAgentIds(tai).build();
} else {
queryParam = OtherDeductionPO.builder().declareMonth(declareMonthDate).taxAgentIds(taxAgentIds).build();
}
// 获取所有想要删除的数据
List<OtherDeductionPO> list = otherDeductionBiz.listSome(queryParam);
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
for(OtherDeductionPO item : list){
for (OtherDeductionPO item : list) {
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(item.getEmployeeId()) && f.getTaxAgentId().equals(item.getTaxAgentId())).findFirst();
if (optionalAcctEmp.isPresent()) {
@ -775,16 +778,72 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction
List<OtherDeductionRecordDTO> list = getOtherDeductionMapper().recordList(build);
OtherDeductionRecordDTOEncrypt.decryptOtherDeductionRecordDTOList(list);
if(list==null || list.size()==0){
if (list == null || list.size() == 0) {
throw new SalaryRunTimeException("该数据不存在!");
}
String taxAgentName = list.get(0).getTaxAgentName();
if(!taxAgentNames.contains(taxAgentName)){
if (!taxAgentNames.contains(taxAgentName)) {
throw new SalaryRunTimeException("您无权查看该数据!");
}
return list.get(0);
}
@Override
public String extendToLastMonth(OtherDeductionExtendLastParam param) {
// 查找到所有个税扣缴义务人
Boolean needAuth = getTaxAgentService(user).isNeedAuth((long) user.getUID());
Collection<TaxAgentPO> taxAgentPOS;
if (needAuth) {
taxAgentPOS = getTaxAgentService(user).listAllTaxAgentsAsAdmin((long) user.getUID());
} else {
taxAgentPOS = getTaxAgentService(user).listAll();
}
List<Long> taxAgentIds = taxAgentPOS.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
//查询上月数据
LocalDateTime lastMonth = param.getYearMonthTime().minusMonths(1);
OtherDeductionQueryParam queryParam = OtherDeductionQueryParam.builder()
.taxAgentIds(taxAgentIds)
.declareMonthDate(Collections.singletonList(
SalaryDateUtil.toDate(lastMonth))
).build();
List<OtherDeductionListDTO> lastMonthInfo = getOtherDeductionMapper().list(queryParam);
// 查询当前月id
queryParam.setDeclareMonthDate(Collections.singletonList(
SalaryDateUtil.toDate(param.getYearMonthTime())
));
Map<String, Long> updateIdMap = getOtherDeductionMapper()
.list(queryParam).stream()
.collect(Collectors.toMap(i -> i.getEmployeeId()+"" + i.getTaxAgentId(), OtherDeductionListDTO::getId));
List<OtherDeductionPO> insertInfo = new ArrayList<>();
List<OtherDeductionPO> updatetInfo = new ArrayList<>();
for (OtherDeductionListDTO dto : lastMonthInfo) {
OtherDeductionPO po
= JSONObject.parseObject(JSONObject.toJSONString(dto), OtherDeductionPO.class);
po.setDeclareMonth(SalaryDateUtil.toDate(param.getYearMonthTime()));
po.setUpdateTime(new Date());
po.setId(null);
po.setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY);
boolean hasOld = updateIdMap.containsKey(po.getEmployeeId() + "" + po.getTaxAgentId());
if (hasOld) {
po.setId(updateIdMap.get(po.getEmployeeId() + "" + po.getTaxAgentId()));
updatetInfo.add(po);
} else {
po.setCreator((long) user.getUID());
po.setCreateTime(new Date());
insertInfo.add(po);
}
}
List<List<OtherDeductionPO>> list = Lists.partition(insertInfo, 1000);
list.forEach(l->getOtherDeductionMapper().insertData(l));
List<List<OtherDeductionPO>> updateList = Lists.partition(updatetInfo, 1000);
list.forEach(l->getOtherDeductionMapper().updateData(l));
return "";
}
@Override
public XSSFWorkbook downloadTemplate(OtherDeductionQueryParam param) {
// 1.工作簿名称

View File

@ -1,5 +1,6 @@
package com.engine.salary.util;
import cn.hutool.core.util.StrUtil;
import com.engine.salary.common.LocalDateRange;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -528,6 +529,30 @@ public class SalaryDateUtil {
return inDataRange;
}
/**
* 转换时间对象
* @see SalaryDateUtil#toDate(LocalDateTime, String)
* @param dateTime LocalDateTime
* @return Date
*/
public static Date toDate(LocalDateTime dateTime) {
return toDate(dateTime, null);
}
/**
* 转换时间对象
* @param dateTime LocalDateTime
* @param offset 时区e.g. +8
* @return Date
*/
public static Date toDate(LocalDateTime dateTime, String offset) {
if (dateTime == null) {
return null;
}
ZoneId zoneOffset = StrUtil.isNotEmpty(offset) ? ZoneOffset.of(offset) : ZoneOffset.systemDefault();
return Date.from(dateTime.atZone(zoneOffset).toInstant());
}
}

View File

@ -3,10 +3,7 @@ package com.engine.salary.web;
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.AddUpDeductionRecordDeleteParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionImportParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam;
import com.engine.salary.entity.datacollection.param.*;
import com.engine.salary.util.ResponseResult;
import com.engine.salary.util.SalaryDateUtil;
import com.engine.salary.util.page.PageInfo;
@ -346,5 +343,12 @@ public class OtherDeductionController {
return new ResponseResult<AddUpDeductionRecordDeleteParam, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::deleteAllData, otherDeductionDeleteParam);
}
@POST
@Path("/extendToLastMonth")
@Produces(MediaType.APPLICATION_JSON)
public String extendToLastMonth(@Context HttpServletRequest request, @Context HttpServletResponse response,
@RequestBody OtherDeductionExtendLastParam param) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<OtherDeductionExtendLastParam, String>(user).run(getOtherDeductionWrapper(user)::extendToLastMonth, param);
}
}

View File

@ -8,10 +8,7 @@ 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.AddUpDeductionRecordDeleteParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionImportParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionParam;
import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam;
import com.engine.salary.entity.datacollection.param.*;
import com.engine.salary.entity.datacollection.po.OtherDeductionPO;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.service.OtherDeductionService;
@ -22,9 +19,13 @@ import com.engine.salary.service.impl.SalaryEmployeeServiceImpl;
import com.engine.salary.service.impl.TaxAgentServiceImpl;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.page.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.hrm.User;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -35,16 +36,20 @@ import java.util.Map;
* @Author: wangxiangzhong
* @Date: 2022/3/14 16:09
*/
@Slf4j
public class OtherDeductionWrapper extends Service {
private OtherDeductionService getOtherDeductionService(User user) {
return ServiceUtil.getService(OtherDeductionServiceImpl.class, user);
}
private TaxAgentService getTaxAgentV2Service(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
private SalaryEmployeeService getSalaryEmployeeService(User user) {
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
}
/**
* 数据采集-其他免税扣除列表的高级搜索
*
@ -178,7 +183,7 @@ public class OtherDeductionWrapper extends Service {
Long id = queryParam.getOtherTaxExemptDeductionId();
OtherDeductionPO po = getOtherDeductionService(user).getById(id);
if (po == null) {
throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel( 100415, "其他免税扣除不存在") + "[id:%s]", id));
throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel(100415, "其他免税扣除不存在") + "[id:%s]", id));
}
return getOtherDeductionService(user).exportDetail(queryParam);
}
@ -196,14 +201,14 @@ public class OtherDeductionWrapper extends Service {
/**
* 预览
*/
public Map<String, Object> preview(OtherDeductionImportParam importParam){
public Map<String, Object> preview(OtherDeductionImportParam importParam) {
return getOtherDeductionService(user).preview(importParam);
}
/**
* 导入数据
*/
public Map<String, Object> importData(OtherDeductionImportParam importParam){
public Map<String, Object> importData(OtherDeductionImportParam importParam) {
return getOtherDeductionService(user).importData(importParam);
}
@ -242,4 +247,20 @@ public class OtherDeductionWrapper extends Service {
public OtherDeductionRecordDTO getOtherDeduction(OtherDeductionParam otherDeductionParam) {
return getOtherDeductionService(user).getOtherDeduction(otherDeductionParam);
}
public String extendToLastMonth(OtherDeductionExtendLastParam param) {
LocalDateTime localDate = null;
try {
localDate = LocalDate.parse(param.getDeclareMonth() + "-01",
DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay();
param.setYearMonthTime(localDate);
} catch (Exception e) {
log.error("", e);
}
if (null == param.getDeclareMonth() || null == param.getYearMonthTime()) {
throw new SalaryRunTimeException("当前年月不合法");
}
param.setYearMonthTime(localDate);
return getOtherDeductionService(user).extendToLastMonth(param);
}
}