其他免税扣除-新增、删除所选、一键清空功能

This commit is contained in:
Harryxzy 2022-10-27 18:02:05 +08:00
parent a406eed4b9
commit ddd0c49cdd
9 changed files with 282 additions and 7 deletions

View File

@ -183,4 +183,24 @@ public class OtherDeductionBiz extends BaseBean {
}
/**
* @description 批量删除
* @return void
* @author Harryxzy
* @date 2022/10/27 16:07
*/
public void batchDeleteByIDS(List<Long> deleteIds) {
if (CollectionUtils.isEmpty(deleteIds)) {
return;
}
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
OtherDeductionMapper mapper = sqlSession.getMapper(OtherDeductionMapper.class);
List<List<Long>> partition = Lists.partition(deleteIds, 100);
partition.forEach(mapper::deleteData);
sqlSession.commit();
} finally {
sqlSession.close();
}
}
}

View File

@ -4,7 +4,6 @@ import com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO;
import com.engine.salary.entity.datacollection.dto.OtherDeductionRecordDTO;
import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam;
import com.engine.salary.entity.datacollection.po.OtherDeductionPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -45,4 +44,9 @@ public interface OtherDeductionMapper {
*/
void updateData(@Param("collection") List<OtherDeductionPO> pos);
/**
* 批量删除
* @param longs
*/
void deleteData(List<Long> longs);
}

View File

@ -36,6 +36,17 @@
, t.tenant_key
</sql>
<!--批量删除-->
<update id="deleteData">
UPDATE hrsa_other_deduction t
SET delete_type = 1
WHERE delete_type = 0
AND id IN
<foreach collection="collection" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</update>
<!-- 根据主键获取单条记录 -->
<select id="getById" resultMap="BaseResultMap" parameterType="Long">

View File

@ -2,6 +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;
@ -92,4 +93,19 @@ public interface OtherDeductionService {
* 编辑数据
*/
void editData(OtherDeductionParam otherDeductionParam);
/**
* 新增数据
*/
void createData(OtherDeductionParam otherDeductionParam);
/**
* 删除所选数据
*/
void deleteSelectData(AddUpDeductionRecordDeleteParam deleteParam);
/**
* 一键清空数据
*/
void deleteAllData(AddUpDeductionRecordDeleteParam deleteParam);
}

View File

@ -539,7 +539,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(byId.getEmployeeId()) && f.getTaxAgentId().equals(byId.getTaxAgentId())).findFirst();
if (optionalAcctEmp.isPresent()) {
throw new SalaryRunTimeException("所选数据在该年月中已经核算过,不可进行删除!");
throw new SalaryRunTimeException("所选数据在该年月中已完成核算并归档,不可进行删除!");
}
}
deleteList.add(byId.getId());
@ -554,7 +554,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
List<Long> taxagentIds = taxAgentList.stream().map(TaxAgentManageRangeEmployeeDTO::getTaxAgentId).collect(Collectors.toList());
List<Long> taxAgentIds = taxAgentList.stream().map(TaxAgentManageRangeEmployeeDTO::getTaxAgentId).collect(Collectors.toList());
AddUpDeductionBiz addUpDeductionBiz = new AddUpDeductionBiz();
ArrayList<Date> declareMonthDate = new ArrayList<>();
try {
@ -562,7 +562,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
}catch (Exception e){
throw new SalaryRunTimeException("日期异常");
}
AddUpDeductionQueryParam queryParam = AddUpDeductionQueryParam.builder().declareMonthDate(declareMonthDate).taxAgentIds(taxagentIds).build();
AddUpDeductionQueryParam queryParam = AddUpDeductionQueryParam.builder().declareMonthDate(declareMonthDate).taxAgentIds(taxAgentIds).build();
// 获取所有想要删除的数据
List<AddUpDeductionDTO> list = addUpDeductionBiz.list(queryParam);
// 获取已经核算的数据
@ -571,7 +571,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction
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()) {
throw new SalaryRunTimeException("员工:"+item.getUsername()+",在该年月中已经核算过,不能进行一键清空!");
throw new SalaryRunTimeException("员工:"+item.getUsername()+",在该年月中已完成核算并归档,不能进行一键清空!");
}
}
}

View File

@ -10,6 +10,7 @@ import com.engine.salary.encrypt.datacollection.OtherDeductionRecordDTOEncrypt;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
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;
@ -575,6 +576,165 @@ public class OtherDeductionServiceImpl extends Service implements OtherDeduction
}
}
@Override
public void createData(OtherDeductionParam otherDeductionParam) {
long currentEmployeeId = user.getUID();
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
OtherDeductionBiz OtherDeductionBiz = new OtherDeductionBiz();
EmployBiz employBiz = new EmployBiz();
//查询对于人员信息导入筛选的全局配置
SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode");
String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0";
//税款所属期
String declareMonthStr = Util.null2String(otherDeductionParam.getDeclareMonth());
//人员信息
List<DataCollectionEmployee> employees = employBiz.listEmployee();
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
//税款所属期
Date declareMonth = SalaryDateUtil.stringToDate(declareMonthStr + "-01");
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
// 查询已有数据
List<OtherDeductionPO> list = getOtherDeductionMapper().listSome(OtherDeductionPO.builder().declareMonth(declareMonth).build());
//合规数据
List<OtherDeductionPO> insertData = new ArrayList<>();
List<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> taxAgentEmployees = Lists.newArrayList();
Date now = new Date();
//待插入数据库对象
OtherDeductionPO po = OtherDeductionPO.builder()
.tenantKey(DEFAULT_TENANT_KEY)
.createTime(now)
.updateTime(now)
.creator((long) user.getUID())
.declareMonth(declareMonth).build();
//筛选导入人员信息可以在人力资源池中匹配到的人员信息
boolean employeeSameId = employees.stream().anyMatch(e -> e.getEmployeeId() == otherDeductionParam.getEmployeeId());
if(!employeeSameId){
throw new SalaryRunTimeException("员工信息不存在");
}
po.setEmployeeId(otherDeductionParam.getEmployeeId());
String taxAgentName = otherDeductionParam.getTaxAgentName();
if (StringUtils.isBlank(taxAgentName)) {
//个税扣缴义务人不能为空
throw new SalaryRunTimeException("个税扣缴义务人不能为空");
} else {
Optional<TaxAgentManageRangeEmployeeDTO> optionalTemp = taxAgentList.stream().filter(m -> m.getTaxAgentName().equals(taxAgentName)).findFirst();
if (optionalTemp.isPresent()) {
po.setTaxAgentId(optionalTemp.get().getTaxAgentId());
taxAgentEmployees = optionalTemp.get().getEmployeeList();
} else {
//个税扣缴义务人不存在或不在权限范围内
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
}
}
//商业健康保险
String businessHealthyInsurance = otherDeductionParam.getBusinessHealthyInsurance();
po.setBusinessHealthyInsurance(businessHealthyInsurance);
//税延养老保险
String taxDelayEndowmentInsurance = otherDeductionParam.getTaxDelayEndowmentInsurance();
po.setTaxDelayEndowmentInsurance(taxDelayEndowmentInsurance);
//其他
String otherDeduction = otherDeductionParam.getOtherDeduction();
po.setOtherDeduction(otherDeduction);
//准予扣除的捐赠额
String deductionAllowedDonation = otherDeductionParam.getDeductionAllowedDonation();
po.setDeductionAllowedDonation(deductionAllowedDonation);
//fixme 分权判断
// if (openDevolution) {
// OtherDeductionPO finalPoE = po;
// Optional<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> optionalTaxAgentEmp = taxAgentEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPoE.getEmployeeId())).findFirst();
// if (!optionalTaxAgentEmp.isPresent()) {
// Map<String, String> errorMessageMap = Maps.newHashMap();
// errorMessageMap.put("message", rowIndex + "该条数据不在个税扣缴义务人人员范围内,不可导入");
// errorData.add(errorMessageMap);
// errorSum += 1;
// }
// }
// 判断是否有核算过
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
OtherDeductionPO finalPo = po;
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId())).findFirst();
boolean isExist = list.stream().anyMatch(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId()));
if (optionalAcctEmp.isPresent() && isExist) {
throw new SalaryRunTimeException("该年月这条数据已经核算过,不可导入");
}
}
insertData.add(po);
//入库
OtherDeductionBiz.handleImportData(insertData);
}
@Override
public void deleteSelectData(AddUpDeductionRecordDeleteParam deleteParam) {
long currentEmployeeId = user.getUID();
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
OtherDeductionBiz OtherDeductionBiz = new OtherDeductionBiz();
String declareMonthStr = deleteParam.getDeclareMonth();
List<Long> deleteIds = deleteParam.getIds();
// 已经核算过的不可操作
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees = getAddUpDeductionService(user).getAccountedEmployeeData(declareMonthStr);
// 判断是否有核算过
List<Long> deleteList = new ArrayList<>();
for(int i=0; i<deleteIds.size(); i++){
Long id = deleteIds.get(i);
OtherDeductionPO byId = OtherDeductionBiz.getById(id);
// 判断是否在个税扣缴义务人范围内
Optional<TaxAgentManageRangeEmployeeDTO> first = taxAgentList.stream().filter(m -> m.getTaxAgentId() == byId.getTaxAgentId()).findFirst();
if(!first.isPresent()){
throw new SalaryRunTimeException("个税扣缴义务人不存在或不在权限范围内");
}
// 判断用户是否存在
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(byId.getEmployeeId()) && f.getTaxAgentId().equals(byId.getTaxAgentId())).findFirst();
if (optionalAcctEmp.isPresent()) {
throw new SalaryRunTimeException("所选数据在该年月中已经核算过并归档,不可进行删除!");
}
}
deleteList.add(byId.getId());
}
OtherDeductionBiz.batchDeleteByIDS(deleteList);
}
@Override
public void deleteAllData(AddUpDeductionRecordDeleteParam deleteParam) {
String declareMonthStr = deleteParam.getDeclareMonth();
long currentEmployeeId = user.getUID();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取所有个税扣缴义务人
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;
try {
declareMonthDate = sdf.parse(declareMonthStr+"-01");
}catch (Exception e){
throw new SalaryRunTimeException("日期异常");
}
OtherDeductionPO 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){
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()) {
throw new SalaryRunTimeException("有员工在该年月中已经完成核算并归档,不能进行一键清空!");
}
}
}
List<Long> deleteIds = list.stream().map(OtherDeductionPO::getId).collect(Collectors.toList());
otherDeductionBiz.batchDeleteByIDS(deleteIds);
}
@Override
public XSSFWorkbook downloadTemplate(OtherDeductionQueryParam param) {
// 1.工作簿名称

View File

@ -292,7 +292,7 @@ public class AddUpDeductionController {
* @description 累计专项附加扣除-删除所选
* @return String
* @author Harryxzy
* @date 2022/10/25 14:08
* @date 2022/10/27 14:08
*/
@POST
@Path("/deleteSelectAddUpDeduction")
@ -306,7 +306,7 @@ public class AddUpDeductionController {
* @description 累计专项附加扣除-一键清空
* @return String
* @author Harryxzy
* @date 2022/10/25 14:08
* @date 2022/10/27 14:08
*/
@POST
@Path("/deleteAllAddUpDeduction")

View File

@ -3,6 +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;
@ -289,5 +290,47 @@ public class OtherDeductionController {
return new ResponseResult<OtherDeductionParam, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::editData, otherDeductionParam);
}
/**
* @description 新建其他免税扣除
* @return String
* @author Harryxzy
* @date 2022/10/27 14:41
*/
@POST
@Path("/createData")
@Produces(MediaType.APPLICATION_JSON)
public String createOtherDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionParam otherDeductionParam) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<OtherDeductionParam, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::createData, otherDeductionParam);
}
/**
* @description 删除所选其他免税扣除
* @return String
* @author Harryxzy
* @date 2022/10/27 14:41
*/
@POST
@Path("/deleteSelectData")
@Produces(MediaType.APPLICATION_JSON)
public String deleteSelectOtherDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionRecordDeleteParam otherDeductionDeleteParam) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<AddUpDeductionRecordDeleteParam, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::deleteSelectData, otherDeductionDeleteParam);
}
/**
* @description 一键清空其他免税扣除
* @return null
* @author Harryxzy
* @date 2022/10/27 15:15
*/
@POST
@Path("/deleteAllData")
@Produces(MediaType.APPLICATION_JSON)
public String deleteAllOtherDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionRecordDeleteParam otherDeductionDeleteParam) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<AddUpDeductionRecordDeleteParam, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::deleteAllData, otherDeductionDeleteParam);
}
}

View File

@ -8,6 +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;
@ -214,4 +215,24 @@ public class OtherDeductionWrapper extends Service {
}
/**
* 新增数据
*/
public void createData(OtherDeductionParam otherDeductionParam) {
getOtherDeductionService(user).createData(otherDeductionParam);
}
/**
* 删除所选数据
*/
public void deleteSelectData(AddUpDeductionRecordDeleteParam deleteParam) {
getOtherDeductionService(user).deleteSelectData(deleteParam);
}
/**
* 一键清空所有数据
*/
public void deleteAllData(AddUpDeductionRecordDeleteParam deleteParam) {
getOtherDeductionService(user).deleteAllData(deleteParam);
}
}