薪资项目 和 字段管理的排序

This commit is contained in:
Harryxzy 2023-06-01 17:52:31 +08:00
parent 601b90d188
commit 74c5b4f19f
13 changed files with 238 additions and 66 deletions

View File

@ -152,16 +152,6 @@ public class SalaryItemBiz {
}
}
public Integer getMaxItemSortedIndex(Integer useInEmployeeSalary) {
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
SalaryItemMapper mapper = sqlSession.getMapper(SalaryItemMapper.class);
return mapper.getMaxItemSortedIndex(useInEmployeeSalary);
} finally {
sqlSession.close();
}
}
}

View File

@ -5,6 +5,7 @@ import com.engine.salary.constant.SalaryDefaultTenantConstant;
import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.entity.salaryitem.dto.SalaryItemFormDTO;
import com.engine.salary.entity.salaryitem.dto.SalaryItemListDTO;
import com.engine.salary.entity.salaryitem.dto.SalaryItemSobListDTO;
import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO;
@ -120,6 +121,50 @@ public class SalaryItemBO {
).collect(Collectors.toList());
}
/**
* 薪资项目po转换成薪资账套中薪资项目列表dto
*
* @param salaryItems 薪资项目po
* @param expressFormulas 公式详情
* @return
*/
public static List<SalaryItemSobListDTO> convert2itemSobListDTO(Collection<SalaryItemPO> salaryItems, List<ExpressFormula> expressFormulas, List<SysSalaryItemPO> sysSalaryItemPOS) {
if (CollectionUtils.isEmpty(salaryItems)) {
return Collections.emptyList();
}
Map<Long, String> formulaMap = SalaryEntityUtil.convert2Map(expressFormulas, ExpressFormula::getId, ExpressFormula::getFormula);
Map<Long, String> sysSalaryItemNameMap = SalaryEntityUtil.convert2Map(sysSalaryItemPOS, SysSalaryItemPO::getId, SysSalaryItemPO::getName);
return salaryItems.stream().map(salaryItemPO -> {
SalaryRoundingModeEnum salaryRoundingModeEnum = SalaryRoundingModeEnum.parseByValue(salaryItemPO.getRoundingMode());
SalaryValueTypeEnum salaryValueTypeEnum = SalaryValueTypeEnum.parseByValue(salaryItemPO.getValueType());
SalaryDataTypeEnum salaryDataTypeEnum = SalaryDataTypeEnum.parseByValue(salaryItemPO.getDataType());
return SalaryItemSobListDTO.builder()
.id(salaryItemPO.getId())
.code(salaryItemPO.getCode())
.name(salaryItemPO.getName())
.systemName(sysSalaryItemNameMap.getOrDefault(salaryItemPO.getSysSalaryItemId(), StringUtils.EMPTY))
.useInEmployeeSalary(salaryItemPO.getUseInEmployeeSalary())
.useDefault(salaryItemPO.getUseDefault())
.roundingMode(Optional.ofNullable(salaryRoundingModeEnum)
.map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel()))
.orElse(StringUtils.EMPTY))
.pattern(salaryItemPO.getPattern())
.valueType(Optional.ofNullable(salaryValueTypeEnum)
.map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel()))
.orElse(StringUtils.EMPTY))
.dataType(Optional.ofNullable(salaryDataTypeEnum)
.map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel()))
.orElse(StringUtils.EMPTY))
.taxDeclarationColumn(buildTaxDeclarationColumn(salaryItemPO.getCode()))
.sortedIndex(salaryItemPO.getSortedIndex())
.description(salaryItemPO.getDescription())
.salaryItemType(salaryItemPO.getUseInEmployeeSalary() == 0 ? "薪资项目" : "档案字段")
.build();
}
).collect(Collectors.toList());
}
/**
* 转换成薪资项目详情dto
*
@ -142,7 +187,8 @@ public class SalaryItemBO {
.setDescription(salaryItemPO.getDescription())
.setCanEdit(salaryItemPO.getCanEdit())
.setTaxAgentIds(salaryItemPO.getTaxAgentIds())
.setSharedType(salaryItemPO.getSharedType());
.setSharedType(salaryItemPO.getSharedType())
.setSortedIndex(salaryItemPO.getSortedIndex());
}
/**

View File

@ -73,6 +73,10 @@ public class SalaryFieldListDTO {
//是否可以删除
private Boolean canDelete;
@SalaryTableColumn(text = "显示顺序", width = "10%", column = "sortedIndex")
@TableTitle(title = "显示顺序",dataIndex = "sortedIndex",key = "sortedIndex")
private String sortedIndex;
@SalaryTableColumn(text = "操作", width = "20%", column = "operate")
private String operate;
}

View File

@ -85,4 +85,6 @@ public class SalaryItemFormDTO {
private Integer sharedType;
private String taxAgentIds;
private Integer sortedIndex;
}

View File

@ -96,6 +96,8 @@ public class SalaryItemListDTO {
private Boolean canDelete;
//排序
@SalaryTableColumn(text = "显示顺序", width = "10%", column = "sortedIndex")
@TableTitle(title = "显示顺序",dataIndex = "sortedIndex",key = "sortedIndex")
private Integer sortedIndex;
@SalaryTableColumn(text = "操作", width = "20%", column = "operate")

View File

@ -0,0 +1,103 @@
package com.engine.salary.entity.salaryitem.dto;
import com.engine.salary.annotation.SalaryTableColumn;
import com.engine.salary.annotation.TableTitle;
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Harryxzy
* @date 2023/06/01 17:05
* @description 薪资账套薪资项目列表
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SalaryItemSobListDTO {
@JsonSerialize(using = ToStringSerializer.class)
@SalaryTableColumn(column = "id", display = false)
private Long id;
@SalaryTableColumn(text = "名称", width = "10%", column = "name")
@TableTitle(title = "名称",dataIndex = "name",key = "name")
private String name;
private String code;
@SalaryTableColumn(text = "系统名", width = "10%", column = "systemName")
@TableTitle(title = "系统名",dataIndex = "systemName",key = "systemName")
private String systemName;
//薪资档案引用
// @SalaryTableColumn(text = "薪资档案引用", width = "10%", column = "useInEmployeeSalary")
// @TableTitle(title = "薪资档案引用",dataIndex = "useInEmployeeSalary",key = "useInEmployeeSalary")
private Integer useInEmployeeSalary;
// 薪资项目类型
@SalaryTableColumn(text = "项目类型", width = "10%", column = "salaryItemType")
@TableTitle(title = "项目类型",dataIndex = "salaryItemType",key = "salaryItemType")
private String salaryItemType;
//默认使用
@SalaryTableColumn(text = "默认使用", width = "10%", column = "useDefault")
@TableTitle(title = "默认使用",dataIndex = "useDefault",key = "useDefault")
private Integer useDefault;
//进位规则
@SalaryTableColumn(text = "进位规则", width = "10%", column = "roundingMode",transmethod = "com.engine.salary.transmethod.TransMethod.roundingMode")
@TableTitle(title = "进位规则",dataIndex = "roundingMode",key = "roundingMode")
private String roundingMode;
//保留小数位
@SalaryTableColumn(text = "保留小数位", width = "10%", column = "pattern")
@TableTitle(title = "保留小数位",dataIndex = "pattern",key = "pattern")
private Integer pattern;
//取值方式
@SalaryTableColumn(text = "取值方式", width = "10%", column = "valueType",transmethod = "com.engine.salary.transmethod.TransMethod.datasource")
@TableTitle(title = "取值方式",dataIndex = "valueType",key = "valueType")
private String valueType;
/**
* @see SalaryDataTypeEnum
*/
@SalaryTableColumn(text = "字段类型", width = "10%", column = "dataType",transmethod = "com.engine.salary.transmethod.TransMethod.dataType")
@TableTitle(title = "字段类型",dataIndex = "dataType",key = "dataType")
private String dataType;
//公式id
private Long formulaId;
//公式内容
private String formulaContent;
@SalaryTableColumn(text = "个税申报表对应字段", width = "10%", column = "taxDeclarationColumn")
@TableTitle(title = "个税申报表对应字段",dataIndex = "taxDeclarationColumn",key = "taxDeclarationColumn")
private String taxDeclarationColumn;
//备注
@SalaryTableColumn(text = "备注", width = "10%", column = "description")
@TableTitle(title = "备注",dataIndex = "description",key = "description")
private String description;
//是否可以编辑
private Boolean canEdit;
//是否可以删除
private Boolean canDelete;
//排序
private Integer sortedIndex;
@SalaryTableColumn(text = "操作", width = "20%", column = "operate")
private String operate;
}

View File

@ -67,11 +67,5 @@ public interface SalaryItemMapper {
void batchUpdateSortedIndex(@Param("collection")List<SalaryItemPO> salaryItemPOS);
/**
* 获取薪资项目的最大sortedIndex
* @param useInEmployeeSalary
* @return
*/
Integer getMaxItemSortedIndex(Integer useInEmployeeSalary);
}

View File

@ -59,7 +59,7 @@
<include refid="baseColumns"/>
FROM hrsa_salary_item t
WHERE delete_type = 0
ORDER BY sorted_index DESC
ORDER BY sorted_index DESC, id DESC
</select>
<!-- 根据主键获取单条记录 -->
@ -139,7 +139,7 @@
#{id}
</foreach>
</if>
ORDER BY sorted_index DESC
ORDER BY sorted_index DESC, id DESC
</select>
<!-- 插入不为NULL的字段 -->
@ -349,6 +349,7 @@
<if test="taxAgentIds != null">
tax_agent_ids=#{taxAgentIds},
</if>
sorted_index=#{sortedIndex},
</set>
WHERE id = #{id} AND delete_type = 0
</update>
@ -461,7 +462,7 @@
WHERE
delete_type = 0
<include refid="paramSql"/>
ORDER BY sorted_index DESC
ORDER BY sorted_index DESC, id DESC
</select>
<select id="listByParamOrderById" resultType="com.engine.salary.entity.salaryitem.po.SalaryItemPO">
@ -475,11 +476,6 @@
ORDER BY id DESC
</select>
<select id="getMaxItemSortedIndex" resultType="java.lang.Integer">
select max(sorted_index)
from hrsa_salary_item
where delete_type=0 and use_in_employee_salary = #{useInEmployeeSalary}
</select>
<sql id="paramSql">
<if test="param.name != null and param.name != ''">

View File

@ -137,7 +137,34 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService
.stream().map(TaxAgentPO::getId).collect(Collectors.toSet());
salaryItemPOS = salaryItemPOS.stream()
.filter(po -> filterInRange(userTaxAgentIds, po))
.sorted(Comparator.comparing(SalaryItemPO::getSystemType))
.sorted(new Comparator<SalaryItemPO>() {
@Override
public int compare(SalaryItemPO o1, SalaryItemPO o2) {
if(o1 == null)
return 1;
if(o2 == null)
return -1;
if(o1 == null && o2 == null)
return 0;
if(o1.getSortedIndex() == null && o2.getSortedIndex() == null){
Integer systemType1=o1.getSystemType();
Integer systemType2=o2.getSystemType();
if(systemType1 == null)
systemType1=0;
if(systemType2 == null)
systemType2=0;
return systemType1.compareTo(systemType2);
}else{
Integer sortedIndex1=o1.getSortedIndex();
Integer sortedIndex2=o2.getSortedIndex();
if(sortedIndex1 == null)
sortedIndex1=0;
if(sortedIndex2 == null)
sortedIndex2=0;
return sortedIndex2.compareTo(sortedIndex1);
}
}
})
.collect(Collectors.toList());
} else {
//普通用户
@ -180,9 +207,6 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService
if (CollectionUtils.isNotEmpty(sysSalaryItemPOS)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98328, "自定义薪资项目的名称不能和系统薪资项目的名称重名"));
}
// 保存薪资项目
Integer maxItemSortedIndex = salaryItemBiz.getMaxItemSortedIndex(saveParam.getUseInEmployeeSalary());
saveParam.setSortedIndex(maxItemSortedIndex+1);
SalaryItemPO salaryItemPO = SalaryItemBO.convert2SalaryItemPO(saveParam, (long) user.getUID());
salaryItemBiz.insert(salaryItemPO);
// todo 记录日志
@ -235,6 +259,7 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService
newSalaryItemPO.setUpdateTime(new Date());
newSalaryItemPO.setSharedType(saveParam.getSharedType());
newSalaryItemPO.setTaxAgentIds(saveParam.getTaxAgentIds());
newSalaryItemPO.setSortedIndex(saveParam.getSortedIndex());
salaryItemBiz.updateById(newSalaryItemPO);
//改名后更新公式

View File

@ -1,7 +1,7 @@
package com.engine.salary.web;
import com.engine.common.util.ServiceUtil;
import com.engine.salary.entity.salaryitem.dto.SalaryItemListDTO;
import com.engine.salary.entity.salaryitem.dto.SalaryItemSobListDTO;
import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam;
import com.engine.salary.entity.salarysob.dto.*;
import com.engine.salary.entity.salarysob.param.*;
@ -281,7 +281,7 @@ public class SalarySobController {
@Produces(MediaType.APPLICATION_JSON)
public String listSalaryItem(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryItemSearchParam queryParam) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<SalaryItemSearchParam, PageInfo<SalaryItemListDTO> >(user).run(getSalarySobItemWrapper(user)::listPage4SalaryItem, queryParam);
return new ResponseResult<SalaryItemSearchParam, PageInfo<SalaryItemSobListDTO> >(user).run(getSalarySobItemWrapper(user)::listPage4SalaryItem, queryParam);
}

View File

@ -11,8 +11,6 @@ import com.engine.salary.entity.salaryacct.dto.SalaryAcctRecordListDTO;
import com.engine.salary.entity.salaryacct.param.SalaryAcctRecordQueryParam;
import com.engine.salary.entity.salaryacct.param.SalaryAcctRecordSaveParam;
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salarysob.dto.SalarySobCycleDTO;
import com.engine.salary.entity.salarysob.po.SalarySobPO;
import com.engine.salary.exception.SalaryRunTimeException;
@ -29,7 +27,6 @@ import org.apache.commons.lang3.math.NumberUtils;
import weaver.hrm.User;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
@ -74,8 +71,6 @@ public class SalaryAcctRecordWrapper extends Service implements SalaryAcctRecord
SalarySobUtil.handleEmployeeStatusHistory();
// 处理工资单发放历史数据
getSalarySendService(user).handleHistory();
// 处理历史数据给薪资项目都增加个默认排序
generateSalaryItemSortedIndex();
// 查询薪资核算记录分页
PageInfo<SalaryAcctRecordPO> page = getSalaryAcctRecordService(user).listPageByParam(queryParam);
PageInfo<SalaryAcctRecordListDTO> dtoPage = new PageInfo<SalaryAcctRecordListDTO>(SalaryAcctRecordListDTO.class);
@ -127,28 +122,28 @@ public class SalaryAcctRecordWrapper extends Service implements SalaryAcctRecord
* @author Harryxzy
* @date 2023/5/29 14:37
*/
private void generateSalaryItemSortedIndex() {
// 查询所有薪资项目
List<SalaryItemPO> salaryItemList = getSalaryItemService(user).listByParamOrderById(SalaryItemSearchParam.builder().build());
Optional<SalaryItemPO> needGenerate = salaryItemList.stream().filter(item -> item.getSortedIndex() == null).findFirst();
if(needGenerate.isPresent()){
Map<Integer, List<SalaryItemPO>> salaryItemMap = SalaryEntityUtil.group2Map(salaryItemList, SalaryItemPO::getUseInEmployeeSalary);
for(Map.Entry<Integer, List<SalaryItemPO>> entry : salaryItemMap.entrySet()){
List<SalaryItemPO> values = entry.getValue();
if(CollectionUtils.isNotEmpty(values)){
// 将系统薪资项目放到最后
values = values.stream()
.sorted(Comparator.comparing(SalaryItemPO::getSystemType))
.collect(Collectors.toList());
// 添加默认sortedIndex
AtomicInteger index = new AtomicInteger(values.size());
values.stream().forEach(value -> value.setSortedIndex(index.getAndDecrement()));
// 保存排序
getSalaryItemService(user).batchUpdateSortedIndex(values);
}
}
}
}
// private void generateSalaryItemSortedIndex() {
// // 查询所有薪资项目
// List<SalaryItemPO> salaryItemList = getSalaryItemService(user).listByParamOrderById(SalaryItemSearchParam.builder().build());
// Optional<SalaryItemPO> needGenerate = salaryItemList.stream().filter(item -> item.getSortedIndex() == null).findFirst();
// if(needGenerate.isPresent()){
// Map<Integer, List<SalaryItemPO>> salaryItemMap = SalaryEntityUtil.group2Map(salaryItemList, SalaryItemPO::getUseInEmployeeSalary);
// for(Map.Entry<Integer, List<SalaryItemPO>> entry : salaryItemMap.entrySet()){
// List<SalaryItemPO> values = entry.getValue();
// if(CollectionUtils.isNotEmpty(values)){
// // 将系统薪资项目放到最后
// values = values.stream()
// .sorted(Comparator.comparing(SalaryItemPO::getSystemType))
// .collect(Collectors.toList());
// // 添加默认sortedIndex
// AtomicInteger index = new AtomicInteger(values.size());
// values.stream().forEach(value -> value.setSortedIndex(index.getAndDecrement()));
// // 保存排序
// getSalaryItemService(user).batchUpdateSortedIndex(values);
// }
// }
// }
// }
/**
* 薪资核算记录详情

View File

@ -138,7 +138,6 @@ public class SalaryArchiveWrapper extends Service {
.stream().map(TaxAgentPO::getId).collect(Collectors.toSet());
salaryItems = salaryItems.stream()
.filter(po -> getSalaryItemService(user).filterInRange(userTaxAgentIds, po))
.sorted((Comparator.comparing(SalaryItemPO::getSortedIndex)))
.collect(Collectors.toList());

View File

@ -6,7 +6,7 @@ import com.engine.salary.annotation.SalaryFormulaVar;
import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.entity.salaryformula.dto.SalaryFormulaEmployeeDTO;
import com.engine.salary.entity.salaryitem.bo.SalaryItemBO;
import com.engine.salary.entity.salaryitem.dto.SalaryItemListDTO;
import com.engine.salary.entity.salaryitem.dto.SalaryItemSobListDTO;
import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO;
@ -19,6 +19,7 @@ import com.engine.salary.service.impl.*;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import weaver.hrm.User;
@ -68,8 +69,13 @@ public class SalarySobItemWrapper extends Service {
* @param queryParam 列表查询条件
* @return
*/
public PageInfo<SalaryItemListDTO> listPage4SalaryItem(SalaryItemSearchParam queryParam) {
public PageInfo<SalaryItemSobListDTO> listPage4SalaryItem(SalaryItemSearchParam queryParam) {
Integer searchPageSize = queryParam.getPageSize();
Integer searchCurrent = queryParam.getCurrent();
// 分页查询薪资项目
queryParam.setPageSize(10000000);
queryParam.setCurrent(1);
PageInfo<SalaryItemPO> page = getSalaryItemService(user).listPageByParam(queryParam);
List<SalaryItemPO> salaryItemList = page.getList();
@ -80,11 +86,22 @@ public class SalarySobItemWrapper extends Service {
salaryItemList = salaryItemList.stream()
.filter(po -> getSalaryItemService(user).filterInRange(taxAgentIds, po))
.collect(Collectors.toList());
// 薪资项目排序薪资项目放在前面首先按照设置的排序没有设置按照id倒序系统薪资项目放在最后档案字段放在后面
salaryItemList = salaryItemList.stream()
.sorted(new Comparator<SalaryItemPO>() {
@Override
public int compare(SalaryItemPO o1, SalaryItemPO o2) {
return Integer.compare(o1.getUseInEmployeeSalary(),o2.getUseInEmployeeSalary());
}
})
.collect(Collectors.toList());
SalaryPageUtil.buildPage(searchCurrent, searchPageSize, salaryItemList);
//最终返回的分页对象
PageInfo<SalaryItemListDTO> dtoPage = new PageInfo<>(SalaryItemListDTO.class);
dtoPage.setPageSize(page.getPageSize());
dtoPage.setPageNum(page.getPageNum());
PageInfo<SalaryItemSobListDTO> dtoPage = new PageInfo<>(SalaryItemSobListDTO.class);
dtoPage.setPageSize(searchPageSize);
dtoPage.setPageNum(searchCurrent);
dtoPage.setTotal(page.getTotal());
if (CollectionUtils.isNotEmpty(salaryItemList)) {
// 查询公式
@ -94,12 +111,11 @@ public class SalarySobItemWrapper extends Service {
Set<Long> sysSalaryItemIds = SalaryEntityUtil.properties(salaryItemList, SalaryItemPO::getSysSalaryItemId);
List<SysSalaryItemPO> sysSalaryItemPOS = getSysSalaryItemService(user).listByIds(sysSalaryItemIds);
// 转换成薪资项目列表dto
dtoPage.setList(SalaryItemBO.convert2ListDTO(salaryItemList, expressFormulas, sysSalaryItemPOS));
dtoPage.setList(SalaryItemBO.convert2itemSobListDTO(salaryItemList, expressFormulas, sysSalaryItemPOS));
}
return dtoPage;
}
/**
* 获取薪资账套的薪资项目详情
*