考勤和申报表的分权

This commit is contained in:
钱涛 2022-06-07 15:43:22 +08:00
parent 38557e2e03
commit cedc9f2644
21 changed files with 256 additions and 115 deletions

View File

@ -25,6 +25,8 @@ public class AttendQuoteQueryParam extends BaseQueryParam {
private Collection<Long> ids;
private Collection<Long> salarySobIds;
//薪资所属月
private List<String> salaryYearMonth;
}

View File

@ -64,7 +64,7 @@ public class SalarySobBO {
* @param salarySobs 薪资账套po
* @return
*/
public static List<SalarySobListDTO> convert2ListDTO(Collection<SalarySobPO> salarySobs) {
public static List<SalarySobListDTO> convert2ListDTO(Collection<SalarySobPO> salarySobs,Map<Long, String> taxAgentIdTONameMap) {
if (CollectionUtils.isEmpty(salarySobs)) {
return Collections.emptyList();
}
@ -72,6 +72,7 @@ public class SalarySobBO {
.map(salarySobPO -> SalarySobListDTO.builder()
.id(salarySobPO.getId())
.name(salarySobPO.getName())
.taxAgentName(taxAgentIdTONameMap.get(salarySobPO.getTaxAgentId()))
.salaryCycle(buildSalaryCycle(salarySobPO))
.disable(salarySobPO.getDisable())
.description(salarySobPO.getDescription())

View File

@ -42,6 +42,10 @@ public class SalarySobListDTO {
@TableTitle(title = "账套名称", key = "name", dataIndex = "name")
private String name;
@SalaryTableColumn(text = "个税扣缴义务人", width = "10%", column = "taxAgentName")
@TableTitle(title = "个税扣缴义务人", key = "taxAgentName", dataIndex = "taxAgentName")
private String taxAgentName;
@SalaryTableColumn(text = "薪资周期", width = "10%", column = "salaryCycle", transmethod = "com.engine.salary.transmethod.TransMethod.buildSalaryCycle", otherPara = "column:salaryCycleFromDay")
@TableTitle(title = "薪资周期", key = "salaryCycle", dataIndex = "salaryCycle")
private String salaryCycle;

View File

@ -224,7 +224,7 @@ public class TaxAgentBO {
}
Date now = new Date();
return TaxAgentPO.builder()
.id(saveParam.getId())
// .id(saveParam.getId())
.name(saveParam.getName())
.description(saveParam.getDescription())
.createTime(now)

View File

@ -4,31 +4,37 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import weaver.hrm.User;
import java.time.YearMonth;
/**
* @description: 生成个税申报表参数
* @author: xiajun
* @modified By: xiajun
* @date: Created in 12/15/21 9:44 AM
* @version:v1.0
*/
* 生成个税申报表参数
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TaxDeclarationSaveParam {
//薪资所属月")
/**
* 薪资所属月
*/
private YearMonth salaryMonth;
//备注")
/**
* 个税扣缴义务人
*/
private Long taxAgentId;
/**
* 备注
*/
private String description;
private String salaryMonthStr;
private User user;
}

View File

@ -262,6 +262,12 @@
#{id}
</foreach>
</if>
<if test="param.salarySobIds != null and param.salarySobIds.size()>0">
AND t1.salary_sob_id IN
<foreach collection="param.salarySobIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<!-- 薪资所属月 -->
<if test="param.salaryYearMonth != null">
<if test="param.salaryYearMonth.size() == 1">

View File

@ -123,6 +123,9 @@
#{taxAgentId}
</foreach>
</if>
<if test="taxAgentId != null">
AND tax_agent_id = #{taxAgentId}
</if>
<include refid="listSomeParamSql"/>
ORDER BY id DESC
</select>

View File

@ -27,13 +27,6 @@ public interface TaxAgentMapper {
*/
TaxAgentPO getById(Long id);
/**
* 新增插入所有字段
*
* @param taxAgent 新增的记录
* @return 返回影响行数
*/
int insert(TaxAgentPO taxAgent);
/**
* 新增忽略null字段

View File

@ -63,37 +63,11 @@
WHERE id = #{id} AND delete_type = 0
</select>
<!-- 插入全部字段 -->
<insert id="insert" parameterType="com.engine.salary.entity.taxagent.po.TaxAgentPO"
keyProperty="id" keyColumn="id" useGeneratedKeys="true"
>
INSERT INTO hrsa_tax_agent
<trim prefix="(" suffix=")" suffixOverrides=",">
create_time,
creator,
delete_type,
description,
id,
name,
tenant_key,
update_time,
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
#{createTime},
#{creator},
#{deleteType},
#{description},
#{id},
#{name},
#{tenantKey},
#{updateTime},
</trim>
</insert>
<!-- 插入不为NULL的字段 -->
<insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.taxagent.po.TaxAgentPO"
keyProperty="id" keyColumn="id" useGeneratedKeys="true"
>
<insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.taxagent.po.TaxAgentPO" databaseId="oracle">
<selectKey keyProperty="id" resultType="long" order="AFTER">
select hrsa_tax_agent_id.currval from dual
</selectKey>
INSERT INTO hrsa_tax_agent
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -62,6 +62,9 @@
#{id}
</foreach>
</if>
<if test="taxAgentId != null">
AND tax_agent_id = #{taxAgentId}
</if>
ORDER BY id DESC
</select>
<insert id="batchInsert">

View File

@ -63,6 +63,14 @@ public interface SalarySobService {
*/
List<SalarySobPO> listByDisable(Integer disable);
/**
* 获取拥有管理权限的账套
* @return
*/
List<SalarySobPO> listByAdmin();
List<SalarySobPO> listByTaxAgentId(Long taxAgentId);
/**
* 根据薪资类型查询薪资账套
*
@ -130,8 +138,10 @@ public interface SalarySobService {
/**
* 按权限过滤掉无权限的薪资账套
*
* 总管理员拥有权限
* @param salarySobPOS
* @return
*/
List<SalarySobPO> filterByAuthority(List<SalarySobPO> salarySobPOS);
}

View File

@ -62,7 +62,7 @@ public class AddUpSituationServiceImpl extends Service implements AddUpSituation
return ServiceUtil.getService(AddUpDeductionServiceImpl.class, user);
}
private TaxAgentService getTaxAgentV2Service(User user) {
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
private SalaryEmployeeService getSalaryEmployeeService(User user) {
@ -163,12 +163,12 @@ public class AddUpSituationServiceImpl extends Service implements AddUpSituation
public PageInfo<AddUpSituationDTO> listPage(AddUpSituationQueryParam queryParam) {
long employeeId = user.getUID();
// 未开启分权或是薪酬模块总管理员
if (!getTaxAgentV2Service(user).isOpenDevolution() || getTaxAgentV2Service(user).isChief(employeeId)) {
if (!getTaxAgentService(user).isOpenDevolution() || getTaxAgentService(user).isChief(employeeId)) {
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<AddUpSituationDTO> list = getAddUpSituationMapper().list(queryParam);
return new PageInfo<>(list, AddUpSituationDTO.class);
} else {
List<Long> taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<AddUpSituationDTO> list = getAddUpSituationMapper().list(queryParam);
list = list.stream().filter(f ->
// 作为管理员
@ -187,12 +187,12 @@ public class AddUpSituationServiceImpl extends Service implements AddUpSituation
public PageInfo<AddUpSituationRecordDTO> recordListPage(AddUpSituationQueryParam queryParam) {
long employeeId = user.getUID();
// 未开启分权或是薪酬模块总管理员
if (!getTaxAgentV2Service(user).isOpenDevolution() || getTaxAgentV2Service(user).isChief(employeeId)) {
if (!getTaxAgentService(user).isOpenDevolution() || getTaxAgentService(user).isChief(employeeId)) {
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<AddUpSituationRecordDTO> list = getAddUpSituationMapper().recordList(queryParam);
return new PageInfo<>(list, AddUpSituationRecordDTO.class);
} else {
List<Long> taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
List<AddUpSituationRecordDTO> list = getAddUpSituationMapper().recordList(queryParam);
// 分页参数
PageInfo<AddUpSituationRecordDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), AddUpSituationRecordDTO.class);
@ -253,8 +253,8 @@ public class AddUpSituationServiceImpl extends Service implements AddUpSituation
List<AddUpSituationDTO> list = biz.list(param);
// 开启分权并且不是薪酬模块总管理员
if (getTaxAgentV2Service(user).isOpenDevolution() && !getTaxAgentV2Service(user).isChief(employeeId)) {
List<Long> taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
if (getTaxAgentService(user).isOpenDevolution() && !getTaxAgentService(user).isChief(employeeId)) {
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
list = list.stream().filter(f ->
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
).collect(Collectors.toList());
@ -318,8 +318,8 @@ public class AddUpSituationServiceImpl extends Service implements AddUpSituation
List<AddUpSituationRecordDTO> list = biz.recordList(param);
// 开启了分权
if (getTaxAgentV2Service(user).isOpenDevolution() || !getTaxAgentV2Service(user).isChief(employeeId)) {
List<Long> taxAgentIdsAsAdmin = getTaxAgentV2Service(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
if (getTaxAgentService(user).isOpenDevolution() || !getTaxAgentService(user).isChief(employeeId)) {
List<Long> taxAgentIdsAsAdmin = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
@ -546,7 +546,7 @@ public class AddUpSituationServiceImpl extends Service implements AddUpSituation
Long currentEmployeeId = (long) user.getUID();
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentV2Service(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId);
// 获取租户下所有的人员
List<DataCollectionEmployee> employees = employBiz.listEmployee();
// 已经核算过的不可操作

View File

@ -11,24 +11,26 @@ import com.engine.salary.entity.datacollection.param.AttendQuoteDataQueryParam;
import com.engine.salary.entity.datacollection.param.AttendQuoteQueryParam;
import com.engine.salary.entity.datacollection.po.AttendQuoteDataPO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
import com.engine.salary.entity.salarysob.po.SalarySobPO;
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.datacollection.AttendQuoteMapper;
import com.engine.salary.service.AttendQuoteService;
import com.engine.salary.service.SalaryAcctRecordService;
import com.engine.salary.service.SalarySobService;
import com.engine.salary.service.TaxAgentService;
import com.engine.salary.util.SalaryDateUtil;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.math.NumberUtils;
import weaver.hrm.User;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@ -43,7 +45,15 @@ public class AttendQuoteServiceImpl extends Service implements AttendQuoteServic
}
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
return (SalaryAcctRecordService) ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
}
private SalarySobService getSalarySobService(User user) {
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
@Override
@ -53,8 +63,20 @@ public class AttendQuoteServiceImpl extends Service implements AttendQuoteServic
@Override
public PageInfo<AttendQuoteListDTO> listPage(AttendQuoteQueryParam queryParam) {
long currentEmployeeId = user.getUID();
Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId);
if (needAuth) {
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByDisable(NumberUtils.INTEGER_ZERO);
Set<Long> salarySobIds = SalaryEntityUtil.properties(salarySobPOS, SalarySobPO::getId);
queryParam.setSalarySobIds(salarySobIds);
}
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<AttendQuoteListDTO> list = getAttendQuoteMapper().list(queryParam);
return new PageInfo<>(list, AttendQuoteListDTO.class);
}

View File

@ -412,7 +412,7 @@ public class SalaryAcctRecordServiceImpl extends Service implements SalaryAcctRe
// 薪资所属月所在年的日期范围第一天最后一天
LocalDateRange yearRange = SalaryDateUtil.localDate2YearRange(salaryAcctRecordPO.getSalaryMonth());
if (Objects.isNull(yearRange)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "薪资所属月为空"));
}
// 查询薪资所属月所在年的所有薪资核算记录
List<SalaryAcctRecordPO> salaryAcctRecordPOS = listBySalaryMonth(yearRange);

View File

@ -128,6 +128,17 @@ public class SalarySobServiceImpl extends Service implements SalarySobService {
return filterByAuthority(salarySobPOS);
}
@Override
public List<SalarySobPO> listByAdmin() {
List<SalarySobPO> salarySobPOS = salarySobMapper.listSome(SalarySobPO.builder().disable(NumberUtils.INTEGER_ZERO).build());
return filterByAdmin(salarySobPOS);
}
@Override
public List<SalarySobPO> listByTaxAgentId(Long taxAgentId) {
return salarySobMapper.listSome(SalarySobPO.builder().disable(NumberUtils.INTEGER_ZERO).taxAgentId(taxAgentId).build());
}
@Override
public List<SalarySobPO> listByIncomeCategory(IncomeCategoryEnum incomeCategory) {
return salarySobMapper.listSome(SalarySobPO.builder().incomeCategory(incomeCategory.getValue()).build());
@ -521,4 +532,32 @@ public class SalarySobServiceImpl extends Service implements SalarySobService {
}).collect(Collectors.toList());
}
public List<SalarySobPO> filterByAdmin(List<SalarySobPO> salarySobPOS) {
long employeeId = user.getUID();
// 判断是否是总管理员
Boolean isChief = getTaxAgentService(user).isChief(employeeId);
// 是否开启分权
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
// 开启分权后
// 总管理员都能看见
// 管理员自己管理的个税下的
if (!openDevolution) {
return salarySobPOS;
}
// 查询所有的个税扣缴义务人
Collection<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listAll();
Set<Long> allTaxAgentIds = SalaryEntityUtil.properties(taxAgentPOS, TaxAgentPO::getId);
// 查询个税扣缴义务人的管理员
List<TaxAgentAdminPO> taxAgentAdminPOS = getTaxAgentAdminService(user).listByTaxAgentIds(allTaxAgentIds);
Map<Long, Set<Long>> adminMap = SalaryEntityUtil.group2Map(taxAgentAdminPOS, TaxAgentAdminPO::getEmployeeId, TaxAgentAdminPO::getTaxAgentId);
return salarySobPOS.stream().filter(salarySobPO -> {
Set<Long> taxAgentIds = adminMap.get(employeeId);
if (CollectionUtils.isEmpty(taxAgentIds)) {
return false;
}
return taxAgentIds.contains(salarySobPO.getTaxAgentId());
}).collect(Collectors.toList());
}
}

View File

@ -49,6 +49,7 @@ public class TaxAgentAdminServiceImpl extends Service implements TaxAgentAdminSe
.employeeId(e)
.createTime(now)
.updateTime(now)
.deleteType(0)
.creator((long) user.getUID())
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.build())

View File

@ -15,6 +15,7 @@ import com.engine.salary.service.SalaryAcctRecordService;
import com.engine.salary.service.TaxAgentBaseService;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.db.MapperProxyFactory;
import dm.jdbc.util.IdGenerator;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import weaver.hrm.User;
@ -79,7 +80,7 @@ public class TaxAgentBaseServiceImpl extends Service implements TaxAgentBaseServ
if (base == null) {
getTaxAgentBaseMapper().insertIgnoreNull(
TaxAgentBasePO.builder()
// .id(IdGenerator.generate())
.id(IdGenerator.generate())
.devolutionStatus(devolutionStatus)
.createTime(now)
.updateTime(now)

View File

@ -37,7 +37,6 @@ import com.engine.salary.util.page.SalaryPageUtil;
import com.engine.salary.util.valid.RuntimeTypeEnum;
import com.engine.salary.util.valid.ValidUtil;
import com.google.common.collect.Lists;
import dm.jdbc.util.IdGenerator;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@ -286,11 +285,11 @@ public class TaxAgentServiceImpl extends Service implements TaxAgentService {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(115130, "名称不允许与社保福利代缴机构名称重复"));
// }
// 保存
saveParam.setId(IdGenerator.generate());
// saveParam.setId(IdGenerator.generate());
TaxAgentPO taxAgent = TaxAgentBO.convertToPO(saveParam, (long) user.getUID());
getTaxAgentMapper().insert(taxAgent);
getTaxAgentMapper().insertIgnoreNull(taxAgent);
if (isOpenDevolution) {
getTaxAgentAdminService(user).batchInsert(saveParam.getId(), saveParam.getAdminUserIds());
getTaxAgentAdminService(user).batchInsert(taxAgent.getId(), saveParam.getAdminUserIds());
}
// 记录日志
// SalaryLoggerUtil.recordAddSingleLog(taxAgentLoggerTemplate,

View File

@ -93,7 +93,6 @@ public class TaxDeclarationController {
public String save(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody TaxDeclarationSaveParam param) {
User user = HrmUserVarify.getUser(request, response);
param.setSalaryMonth(SalaryDateUtil.String2YearMonth(param.getSalaryMonthStr()));
param.setUser(user);
return new ResponseResult<TaxDeclarationSaveParam, Long>(user).run(getTaxDeclarationWrapper(user)::save, param);
}

View File

@ -54,7 +54,11 @@ public class SalarySobWrapper extends Service {
// 查询薪资账套
PageInfo<SalarySobPO> page = getSalarySobService(user).listPageByParam(queryParam);
// 薪资账套po转换成薪资账套列表dto
List<SalarySobListDTO> salarySobListDTOS = SalarySobBO.convert2ListDTO(page.getList());
List<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listAll();
Map<Long, String> taxAgentIdTONameMap = SalaryEntityUtil.convert2Map(taxAgentPOS, TaxAgentPO::getId, TaxAgentPO::getName);
List<SalarySobListDTO> salarySobListDTOS = SalarySobBO.convert2ListDTO(page.getList(),taxAgentIdTONameMap);
PageInfo<SalarySobListDTO> dtoPage = new PageInfo<>(salarySobListDTOS, SalarySobListDTO.class);
dtoPage.setTotal(page.getTotal());
dtoPage.setPageNum(page.getPageNum());

View File

@ -54,19 +54,19 @@ import java.util.stream.Collectors;
public class TaxDeclarationWrapper extends Service {
private TaxDeclarationService getTaxDeclarationService(User user) {
return ServiceUtil.getService(TaxDeclarationServiceImpl.class, user);
return ServiceUtil.getService(TaxDeclarationServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
private TaxDeclarationDetailService getTaxDeclarationDetailService(User user) {
return ServiceUtil.getService(TaxDeclarationDetailServiceImpl.class, user);
return ServiceUtil.getService(TaxDeclarationDetailServiceImpl.class, user);
}
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
}
private TaxDeclarationMapper getTaxDeclarationMapper() {
@ -82,11 +82,11 @@ public class TaxDeclarationWrapper extends Service {
}
private AddUpSituationService getAddUpSituationService(User user) {
return (AddUpSituationService) ServiceUtil.getService(AddUpSituationServiceImpl.class, user);
return ServiceUtil.getService(AddUpSituationServiceImpl.class, user);
}
private SalarySobService getSalarySobService(User user) {
return (SalarySobService) ServiceUtil.getService(SalarySobServiceImpl.class, user);
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
}
private SalaryAcctResultService getSalaryAcctResultService(User user) {
@ -138,18 +138,13 @@ public class TaxDeclarationWrapper extends Service {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
String transformDate = simpleDateFormat.format(taxDeclaration.getSalaryMonth());
// 转换成个税申报表详情dto
formDTO = TaxDeclarationFormDTO.builder()
.salaryMonth(SalaryDateUtil.String2YearMonth(transformDate))
.taxAgentId(taxDeclaration.getTaxAgentId())
.taxAgentName(Optional.ofNullable(taxAgent).map(TaxAgentPO::getName).orElse(""))
.description(taxDeclaration.getDescription())
.build();
formDTO = TaxDeclarationFormDTO.builder().salaryMonth(SalaryDateUtil.String2YearMonth(transformDate)).taxAgentId(taxDeclaration.getTaxAgentId()).taxAgentName(Optional.ofNullable(taxAgent).map(TaxAgentPO::getName).orElse("")).description(taxDeclaration.getDescription()).build();
}
// 转换成前端所需的数据格式
// WeaForm weaForm = SalaryFormatUtil.<TaxDeclarationFormDTO>getInstance().buildForm(TaxDeclarationFormDTO.class, formDTO);
// 查询租户所有的个税扣缴义务人
Collection<TaxAgentPO> taxAgentListDTOS =getTaxAgentService(user).listAll();
Collection<TaxAgentPO> taxAgentListDTOS = getTaxAgentService(user).listAll();
// 表单中个税扣缴义务人的可选项
List<WeaFormOption> weaFormOptions = Lists.newArrayListWithExpectedSize(taxAgentListDTOS.size());
for (TaxAgentPO taxAgent : taxAgentListDTOS) {
@ -185,12 +180,9 @@ public class TaxDeclarationWrapper extends Service {
String transformDate = simpleDateFormat.format(taxDeclaration.getSalaryMonth());
// 查询个税扣缴义务人
TaxAgentPO taxAgentPO = getTaxAgentService(user).getById(taxDeclaration.getTaxAgentId());
return TaxDeclarationInfoDTO.builder()
.salaryMonth(SalaryDateUtil.String2YearMonth(transformDate))
.taxAgentId(taxDeclaration.getTaxAgentId())
.taxAgentName(Optional.ofNullable(taxAgentPO).map(TaxAgentPO::getName).orElse(""))
.build();
return TaxDeclarationInfoDTO.builder().salaryMonth(SalaryDateUtil.String2YearMonth(transformDate)).taxAgentId(taxDeclaration.getTaxAgentId()).taxAgentName(Optional.ofNullable(taxAgentPO).map(TaxAgentPO::getName).orElse("")).build();
}
/**
* 保存
*
@ -198,55 +190,78 @@ public class TaxDeclarationWrapper extends Service {
*/
@Transactional(rollbackFor = Exception.class)
public void save(TaxDeclarationSaveParam saveParam) {
User user = saveParam.getUser();
long currentEmployeeId = user.getUID();
// 薪资所属月的日期范围
LocalDateRange salaryMonthDateRange = SalaryDateUtil.localDate2Range(SalaryDateUtil.localDateToDate(saveParam.getSalaryMonth().atDay(1)));
if (Objects.isNull(salaryMonthDateRange)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "薪资所属月参数错误"));
}
// 查询薪资所属月已经生成过的个税申报表
List<TaxDeclarationPO> taxDeclarationPOS = listBySalaryMonthTax(salaryMonthDateRange);
Long taxAgentId = saveParam.getTaxAgentId();
if (Objects.isNull(taxAgentId)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "请选择个税扣缴义务人"));
}
//查询个税扣缴义务人
TaxAgentPO taxAgentPO = getTaxAgentService(user).getById(taxAgentId);
if (Objects.isNull(taxAgentPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "所选个税扣缴义务人不存在"));
}
//开启分权
Boolean isNeedAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId);
if (isNeedAuth) {
Collection<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listAllTaxAgentsAsAdmin(currentEmployeeId);
Set<Long> taxAgentIds = SalaryEntityUtil.properties(taxAgentPOS, TaxAgentPO::getId);
if(!taxAgentIds.contains(taxAgentId)){
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "无权限操作所选个税扣缴义务人"));
}
}
//获取个税扣缴义务人下的账套
List<SalarySobPO> salarySobs = getSalarySobService(user).listByTaxAgentId(taxAgentId);
Set<Long> salarySobIds = SalaryEntityUtil.properties(salarySobs, SalarySobPO::getId);
// 查询薪资所属月个税扣缴义务人已经生成过的个税申报表
List<TaxDeclarationPO> taxDeclarationPOS = listBySalaryMonthTax(TaxDeclarationPO.builder().salaryMonths(salaryMonthDateRange).taxAgentId(taxAgentId).build());
// 已经生成过个税申报表不允许再次生成个税申报表
if (CollectionUtils.isNotEmpty(taxDeclarationPOS)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98873, "{0}已经生成过个税申报表,不允许再次生成")
.replace("{0}", saveParam.getSalaryMonth().toString()));
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98873, "{0}已经生成过个税申报表,不允许再次生成").replace("{0}", saveParam.getSalaryMonth().toString()));
}
// 查询薪资所属月的薪资核算记录
List<SalaryAcctRecordPO> salaryAcctRecordPOS = listBySalaryMonth(salaryMonthDateRange);
List<SalaryAcctRecordPO> salaryAcctRecordPOS = listBySalaryMonth(SalaryAcctRecordPO.builder().salaryMonths(salaryMonthDateRange).salarySobIds(salarySobIds).build());
// 无薪资核算记录不允许生成个税申报表
if (CollectionUtils.isEmpty(salaryAcctRecordPOS)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98874, "{0}无申报数据")
.replace("{0}", saveParam.getSalaryMonth().toString()));
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98874, "{0}无申报数据").replace("{0}", saveParam.getSalaryMonth().toString()));
}
// 如果存在未归档的也不允许生成个税申报表
boolean notArchived = salaryAcctRecordPOS.stream().anyMatch(salaryAcctRecordPO -> !Objects.equals(salaryAcctRecordPO.getStatus(), SalaryAcctRecordStatusEnum.ARCHIVED.getValue()));
if (notArchived) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98875, "{0}有未归档数据,请全部归档后再申报")
.replace("{0}", saveParam.getSalaryMonth().toString()));
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98875, "{0}有未归档数据,请全部归档后再申报").replace("{0}", saveParam.getSalaryMonth().toString()));
}
// 如果当前薪资所属月下存在不同的税款所属期属于异常业务场景不允许生成个税申报表
Date taxCycle = salaryAcctRecordPOS.get(0).getTaxCycle();
boolean differentTaxCycle = salaryAcctRecordPOS.stream().anyMatch(salaryAcctRecordPO -> salaryAcctRecordPO.getTaxCycle().compareTo(taxCycle) != 0);
if (differentTaxCycle) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98876, "{0}存在不同的税款所属期,无法正常生成个税申报表,请调整账套设置,重新核算后再生成个税申报表")
.replace("{0}", saveParam.getSalaryMonth().toString()));
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98876, "{0}存在不同的税款所属期,无法正常生成个税申报表,请调整账套设置,重新核算后再生成个税申报表").replace("{0}", saveParam.getSalaryMonth().toString()));
}
// 查询薪资核算结果
Set<Long> salaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getId);
List<SalaryAcctResultPO> salaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctRecordIds(salaryAcctRecordIds);
// 无薪资核算结果不允许生成个税申报表
if (CollectionUtils.isEmpty(salaryAcctResultPOS)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98874, "{0}无申报数据")
.replace("{0}", saveParam.getSalaryMonth().toString()));
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98874, "{0}无申报数据").replace("{0}", saveParam.getSalaryMonth().toString()));
}
// 查询薪资账套
Set<Long> salarySobIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getSalarySobId);
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByIds(salarySobIds);
// Set<Long> salarySobIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getSalarySobId);
// List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByIds(salarySobIds);
// 查询所有薪资项目
List<SalaryItemPO> salaryItemPOS = new SalaryItemBiz().listAll();
// 处理要保存的数据
TaxDeclarationBO.Result result = TaxDeclarationBO.handle(saveParam, taxCycle, user, salaryItemPOS, salarySobPOS, salaryAcctResultPOS);
TaxDeclarationBO.Result result = TaxDeclarationBO.handle(saveParam, taxCycle, user, salaryItemPOS, salarySobs, salaryAcctResultPOS);
// 保存个税申报表
if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxDeclarations())) {
getTaxDeclarationMapper().batchInsert(result.getNeedInsertTaxDeclarations());
@ -258,12 +273,71 @@ public class TaxDeclarationWrapper extends Service {
// 保存累计情况
if (CollectionUtils.isNotEmpty(result.getNeedInsertAccumulatedSituations())) {
Set<Long> taxAgentIds = SalaryEntityUtil.properties(result.getNeedInsertTaxDeclarations(), TaxDeclarationPO::getTaxAgentId);
getAddUpSituationService(user).deleteByTaxYearMonthAndTaxAgentIds(SalaryDateUtil.localDate2YearMonth(taxCycle),taxAgentIds);
getAddUpSituationService(user).deleteByTaxYearMonthAndTaxAgentIds(SalaryDateUtil.localDate2YearMonth(taxCycle), taxAgentIds);
List<List<AddUpSituation>> partition = Lists.partition((List) result.getNeedInsertAccumulatedSituations(), 100);
partition.forEach(getAddUpSituationMapper()::insertData);
}
// 更新薪资核算记录的状态
getSalaryAcctRecordService(user).updateStatusByIds(salaryAcctRecordIds, SalaryAcctRecordStatusEnum.DECLARED);
//
// } else {
//
// // 查询薪资所属月已经生成过的个税申报表
// List<TaxDeclarationPO> taxDeclarationPOS = listBySalaryMonthTax(TaxDeclarationPO.builder().salaryMonths(salaryMonthDateRange).build());
// // 已经生成过个税申报表不允许再次生成个税申报表
// if (CollectionUtils.isNotEmpty(taxDeclarationPOS)) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98873, "{0}已经生成过个税申报表,不允许再次生成").replace("{0}", saveParam.getSalaryMonth().toString()));
// }
// // 查询薪资所属月的薪资核算记录
// List<SalaryAcctRecordPO> salaryAcctRecordPOS = listBySalaryMonth(SalaryAcctRecordPO.builder().salaryMonths(salaryMonthDateRange).build());
// // 无薪资核算记录不允许生成个税申报表
// if (CollectionUtils.isEmpty(salaryAcctRecordPOS)) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98874, "{0}无申报数据").replace("{0}", saveParam.getSalaryMonth().toString()));
// }
// // 如果存在未归档的也不允许生成个税申报表
// boolean notArchived = salaryAcctRecordPOS.stream().anyMatch(salaryAcctRecordPO -> !Objects.equals(salaryAcctRecordPO.getStatus(), SalaryAcctRecordStatusEnum.ARCHIVED.getValue()));
// if (notArchived) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98875, "{0}有未归档数据,请全部归档后再申报").replace("{0}", saveParam.getSalaryMonth().toString()));
// }
// // 如果当前薪资所属月下存在不同的税款所属期属于异常业务场景不允许生成个税申报表
// Date taxCycle = salaryAcctRecordPOS.get(0).getTaxCycle();
// boolean differentTaxCycle = salaryAcctRecordPOS.stream().anyMatch(salaryAcctRecordPO -> salaryAcctRecordPO.getTaxCycle().compareTo(taxCycle) != 0);
// if (differentTaxCycle) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98876, "{0}存在不同的税款所属期,无法正常生成个税申报表,请调整账套设置,重新核算后再生成个税申报表").replace("{0}", saveParam.getSalaryMonth().toString()));
// }
// // 查询薪资核算结果
// Set<Long> salaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getId);
// List<SalaryAcctResultPO> salaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctRecordIds(salaryAcctRecordIds);
// // 无薪资核算结果不允许生成个税申报表
// if (CollectionUtils.isEmpty(salaryAcctResultPOS)) {
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98874, "{0}无申报数据").replace("{0}", saveParam.getSalaryMonth().toString()));
// }
// // 查询薪资账套
// Set<Long> salarySobIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getSalarySobId);
// List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByIds(salarySobIds);
//
// // 查询所有薪资项目
// List<SalaryItemPO> salaryItemPOS = new SalaryItemBiz().listAll();
// // 处理要保存的数据
// TaxDeclarationBO.Result result = TaxDeclarationBO.handle(saveParam, taxCycle, user, salaryItemPOS, salarySobPOS, salaryAcctResultPOS);
// // 保存个税申报表
// if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxDeclarations())) {
// getTaxDeclarationMapper().batchInsert(result.getNeedInsertTaxDeclarations());
// }
// // 保存个税申报表明细
// if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxDeclarationDetails())) {
// getTaxDeclarationDetailService(user).batchSave(result.getNeedInsertTaxDeclarationDetails());
// }
// // 保存累计情况
// if (CollectionUtils.isNotEmpty(result.getNeedInsertAccumulatedSituations())) {
// Set<Long> taxAgentIds = SalaryEntityUtil.properties(result.getNeedInsertTaxDeclarations(), TaxDeclarationPO::getTaxAgentId);
// getAddUpSituationService(user).deleteByTaxYearMonthAndTaxAgentIds(SalaryDateUtil.localDate2YearMonth(taxCycle), taxAgentIds);
// List<List<AddUpSituation>> partition = Lists.partition((List) result.getNeedInsertAccumulatedSituations(), 100);
// partition.forEach(getAddUpSituationMapper()::insertData);
// }
// // 更新薪资核算记录的状态
// getSalaryAcctRecordService(user).updateStatusByIds(salaryAcctRecordIds, SalaryAcctRecordStatusEnum.DECLARED);
// }
// 查询个税扣缴义务人
// Set<Long> taxAgentIds = SalaryEntityUtil.properties(result.getNeedInsertTaxDeclarations(), TaxDeclarationPO::getTaxAgentId);
// List<TaxAgent> taxAgentPOS = new TaxAgentBiz().listByIds(taxAgentIds);
@ -282,12 +356,12 @@ public class TaxDeclarationWrapper extends Service {
}*/
}
public List<TaxDeclarationPO> listBySalaryMonthTax(LocalDateRange salaryMonthDateRange) {
return getTaxDeclarationMapper().listSome(TaxDeclarationPO.builder().salaryMonths(salaryMonthDateRange).build());
public List<TaxDeclarationPO> listBySalaryMonthTax(TaxDeclarationPO build) {
return getTaxDeclarationMapper().listSome(build);
}
public List<SalaryAcctRecordPO> listBySalaryMonth(LocalDateRange salaryMonthDateRange) {
return getSalaryAcctRecordMapper().listSome(SalaryAcctRecordPO.builder().salaryMonths(salaryMonthDateRange).build());
public List<SalaryAcctRecordPO> listBySalaryMonth(SalaryAcctRecordPO po) {
return getSalaryAcctRecordMapper().listSome(po);
}
}