兼职凭证模块优化
This commit is contained in:
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.entity.hr;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.jinbooks.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/3/11 10:40
|
||||
*/
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("jbx_employee_salary_voucher_rule")
|
||||
@Data
|
||||
public class EmployeeSalaryVoucherRule extends BaseEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -1147383342734834415L;
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
private String summary;
|
||||
|
||||
private String direction;
|
||||
|
||||
private String templateId;
|
||||
|
||||
private String selectedValue;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String subjectName;
|
||||
|
||||
private String subjectCode;
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.entity.hr;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.jinbooks.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/5/7 9:33
|
||||
*/
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("jbx_employee_salary_voucher_rule_template")
|
||||
@Data
|
||||
public class EmployeeSalaryVoucherRuleTemplate extends BaseEntity {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -7024142146097930876L;
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
private Integer voucherType;
|
||||
|
||||
private String wordHead;
|
||||
|
||||
private Integer status;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@TableLogic(value = "n", delval = "y")
|
||||
private String deleted;
|
||||
|
||||
private String bookId;
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.entity.hr.dto;
|
||||
|
||||
import com.jinbooks.validate.AddGroup;
|
||||
import com.jinbooks.validate.EditGroup;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/3/11 15:12
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class EmployeeSalaryVoucherRuleChangeDto {
|
||||
@NotEmpty(message = "编辑对象不能为空", groups = {EditGroup.class})
|
||||
private String id;
|
||||
|
||||
@NotEmpty(message = "摘要不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String summary;
|
||||
|
||||
@NotEmpty(message = "借贷方向不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String direction;
|
||||
|
||||
@NotEmpty(message = "科目不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String subjectId;
|
||||
|
||||
@NotNull(message = "凭证类型不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private Integer voucherType;
|
||||
|
||||
@NotEmpty(message = "凭证字不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String wordHead;
|
||||
|
||||
@NotNull(message = "状态不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private Integer status;
|
||||
|
||||
private String bookId;
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.entity.hr.dto;
|
||||
|
||||
import com.jinbooks.entity.PageQuery;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/3/11 11:07
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class EmployeeSalaryVoucherRulePageDto extends PageQuery {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7810040682885187416L;
|
||||
|
||||
private String bookId;
|
||||
|
||||
private Integer voucherType;
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.entity.hr.dto;
|
||||
|
||||
import com.jinbooks.validate.AddGroup;
|
||||
import com.jinbooks.validate.EditGroup;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/5/6 17:23
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class SalaryTemplateDetailDto {
|
||||
private String id;
|
||||
|
||||
@NotEmpty(message = "摘要不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String summary;
|
||||
|
||||
@NotEmpty(message = "借贷方向不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String direction;
|
||||
|
||||
@NotEmpty(message = "科目编码不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String subjectCode;
|
||||
|
||||
@NotEmpty(message = "取值不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String selectedValue;
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.entity.hr.dto;
|
||||
|
||||
import com.jinbooks.validate.AddGroup;
|
||||
import com.jinbooks.validate.EditGroup;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/5/6 17:22
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class SalaryTemplateDto {
|
||||
|
||||
/**
|
||||
* 模板ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
@NotNull(message = "凭证类型不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private Integer voucherType;
|
||||
|
||||
@NotEmpty(message = "凭证字不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String wordHead;
|
||||
|
||||
private String bookId;
|
||||
|
||||
@Valid
|
||||
@NotEmpty(message = "分录数据不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
List<SalaryTemplateDetailDto> salaryTemplateDetailDtos;
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.entity.hr.vo;
|
||||
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRule;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/5/7 15:46
|
||||
*/
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SalaryTemplateVo extends EmployeeSalaryVoucherRuleTemplate {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 2811823829011666525L;
|
||||
|
||||
List<EmployeeSalaryVoucherRule> employeeSalaryVoucherRules;
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.persistence.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRule;
|
||||
import com.jinbooks.entity.hr.dto.EmployeeSalaryVoucherRulePageDto;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface EmployeeSalaryVoucherRuleMapper extends BaseMapper<EmployeeSalaryVoucherRule> {
|
||||
Page<EmployeeSalaryVoucherRule> pageList(Page<?> page, @Param("dto")EmployeeSalaryVoucherRulePageDto dto);
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.persistence.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface EmployeeSalaryVoucherRuleTemplateMapper extends BaseMapper<EmployeeSalaryVoucherRuleTemplate> {
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.persistence.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jinbooks.entity.Message;
|
||||
import com.jinbooks.entity.dto.ChangeStatusDto;
|
||||
import com.jinbooks.entity.dto.ListIdsDto;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRule;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
import com.jinbooks.entity.hr.dto.EmployeeSalaryVoucherRulePageDto;
|
||||
import com.jinbooks.entity.hr.dto.SalaryTemplateDto;
|
||||
import com.jinbooks.entity.hr.vo.SalaryTemplateVo;
|
||||
|
||||
public interface EmployeeSalaryVoucherRuleService extends IService<EmployeeSalaryVoucherRule> {
|
||||
|
||||
Message<Page<EmployeeSalaryVoucherRuleTemplate>> pageList(EmployeeSalaryVoucherRulePageDto dto);
|
||||
|
||||
Message<String> save(SalaryTemplateDto dto);
|
||||
|
||||
Message<String> update(SalaryTemplateDto dto);
|
||||
|
||||
Message<String> delete(ListIdsDto dto);
|
||||
|
||||
Message<String> changeStatus(ChangeStatusDto dto);
|
||||
|
||||
Message<SalaryTemplateVo> getTemplateDetail(String id);
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.persistence.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
|
||||
public interface EmployeeSalaryVoucherRuleTemplateService extends IService<EmployeeSalaryVoucherRuleTemplate> {
|
||||
}
|
||||
@ -19,10 +19,8 @@
|
||||
package com.jinbooks.persistence.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jinbooks.entity.Message;
|
||||
@ -31,9 +29,6 @@ import com.jinbooks.entity.book.dto.BookChangeDto;
|
||||
import com.jinbooks.entity.book.dto.BookPageDto;
|
||||
import com.jinbooks.entity.book.vo.BookVo;
|
||||
import com.jinbooks.entity.dto.ListIdsDto;
|
||||
import com.jinbooks.entity.hr.EmployeeSalarySummary;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRule;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
import com.jinbooks.enums.BookBusinessExceptionEnum;
|
||||
import com.jinbooks.exception.BusinessException;
|
||||
import com.jinbooks.persistence.mapper.BookMapper;
|
||||
@ -45,7 +40,6 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
@ -85,12 +79,6 @@ public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements Bo
|
||||
@Autowired
|
||||
StandardSubjectCashFlowService standardSubjectCashFlowService;
|
||||
|
||||
@Autowired
|
||||
EmployeeSalaryVoucherRuleTemplateService employeeSalaryVoucherRuleTemplateService;
|
||||
|
||||
@Autowired
|
||||
EmployeeSalaryVoucherRuleService employeeSalaryVoucherRuleService;
|
||||
|
||||
@Override
|
||||
public Message<Page<Book>> pageList(BookPageDto dto) {
|
||||
Page<Book> page = bookMapper.pageList(dto.build(), dto);
|
||||
@ -125,9 +113,6 @@ public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements Bo
|
||||
//新增默认科目和现金流量的关系
|
||||
standardSubjectCashFlowService.saveTemplateRelationships(dto.getId());
|
||||
|
||||
//新增默认工资凭证规则模板
|
||||
setSalaryVoucherRule(dto.getId());
|
||||
|
||||
//新增账套
|
||||
Book newBook = new Book();
|
||||
BeanUtil.copyProperties(dto, newBook);
|
||||
@ -219,72 +204,4 @@ public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements Bo
|
||||
return bookMapper.listBooks(userId);
|
||||
}
|
||||
|
||||
private void setSalaryVoucherRule(String bookId) {
|
||||
// 1. 查询内置的模板数据(bookId为null的数据)
|
||||
List<EmployeeSalaryVoucherRuleTemplate> builtInTemplates = employeeSalaryVoucherRuleTemplateService.list(
|
||||
Wrappers.<EmployeeSalaryVoucherRuleTemplate>lambdaQuery()
|
||||
.isNull(EmployeeSalaryVoucherRuleTemplate::getBookId)
|
||||
);
|
||||
|
||||
if (ObjectUtils.isEmpty(builtInTemplates)) {
|
||||
return; // 如果没有内置模板数据,直接返回
|
||||
}
|
||||
|
||||
// 2. 获取内置模板的ID列表
|
||||
List<String> builtInTemplateIds = builtInTemplates.stream()
|
||||
.map(EmployeeSalaryVoucherRuleTemplate::getId)
|
||||
.toList();
|
||||
|
||||
// 3. 查询对应的内置规则数据
|
||||
List<EmployeeSalaryVoucherRule> builtInRules = employeeSalaryVoucherRuleService.list(
|
||||
Wrappers.<EmployeeSalaryVoucherRule>lambdaQuery()
|
||||
.in(EmployeeSalaryVoucherRule::getTemplateId, builtInTemplateIds)
|
||||
);
|
||||
|
||||
// 4. 复制模板数据并设置新的bookId,同时建立映射关系
|
||||
CopyOptions copyOptions = new CopyOptions();
|
||||
copyOptions.setIgnoreProperties("id", "createdBy", "createdDate", "modifiedBy", "modifiedDate");
|
||||
|
||||
Map<String, String> templateIdMapping = new HashMap<>();
|
||||
|
||||
// 逐个处理模板数据,确保映射关系正确
|
||||
for (EmployeeSalaryVoucherRuleTemplate builtInTemplate : builtInTemplates) {
|
||||
String oldTemplateId = builtInTemplate.getId();
|
||||
|
||||
// 复制模板数据
|
||||
EmployeeSalaryVoucherRuleTemplate newTemplate = BeanUtil.copyProperties(
|
||||
builtInTemplate,
|
||||
EmployeeSalaryVoucherRuleTemplate.class,
|
||||
"id", "createdBy", "createdDate", "modifiedBy", "modifiedDate", "deleted"
|
||||
);
|
||||
newTemplate.setBookId(bookId);
|
||||
|
||||
// 保存单个模板以获取新生成的ID
|
||||
employeeSalaryVoucherRuleTemplateService.save(newTemplate);
|
||||
|
||||
// 建立新旧ID映射关系
|
||||
String newTemplateId = newTemplate.getId();
|
||||
templateIdMapping.put(oldTemplateId, newTemplateId);
|
||||
}
|
||||
|
||||
// 5. 复制规则数据并设置新的templateId
|
||||
if (ObjectUtils.isNotEmpty(builtInRules)) {
|
||||
List<EmployeeSalaryVoucherRule> newRules = BeanUtil.copyToList(
|
||||
builtInRules,
|
||||
EmployeeSalaryVoucherRule.class,
|
||||
copyOptions
|
||||
);
|
||||
|
||||
// 更新规则数据的templateId为新模板的ID
|
||||
newRules.forEach(rule -> {
|
||||
String oldTemplateId = rule.getTemplateId();
|
||||
String newTemplateId = templateIdMapping.get(oldTemplateId);
|
||||
rule.setTemplateId(newTemplateId);
|
||||
});
|
||||
|
||||
// 6. 批量保存新的规则数据
|
||||
employeeSalaryVoucherRuleService.saveBatch(newRules);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -26,10 +26,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.jinbooks.entity.book.Book;
|
||||
import com.jinbooks.entity.book.BookSubject;
|
||||
import com.jinbooks.entity.hr.*;
|
||||
import com.jinbooks.entity.voucher.VoucherTemplate;
|
||||
import com.jinbooks.entity.voucher.VoucherTemplateItem;
|
||||
import com.jinbooks.entity.voucher.dto.GenerateVoucherDto;
|
||||
import com.jinbooks.entity.voucher.dto.VoucherChangeDto;
|
||||
import com.jinbooks.entity.voucher.dto.VoucherItemChangeDto;
|
||||
import com.jinbooks.enums.SalaryVoucherTemplateEnum;
|
||||
import com.jinbooks.enums.VoucherStatusEnum;
|
||||
import com.jinbooks.persistence.mapper.*;
|
||||
import com.jinbooks.persistence.service.VoucherService;
|
||||
@ -50,6 +51,8 @@ import com.jinbooks.entity.hr.dto.SalarySummaryChangeDto;
|
||||
import com.jinbooks.entity.PeriodStr;
|
||||
import com.jinbooks.entity.hr.vo.TaxDeductionExportVo;
|
||||
import com.jinbooks.exception.BusinessException;
|
||||
import com.jinbooks.persistence.service.BookSubjectService;
|
||||
import com.jinbooks.persistence.service.ConfigSysService;
|
||||
import com.jinbooks.persistence.service.EmployeeSalaryService;
|
||||
import com.jinbooks.util.PeriodDateUtils;
|
||||
import com.jinbooks.util.DateUtils;
|
||||
@ -73,7 +76,6 @@ import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@ -96,16 +98,19 @@ public class EmployeeSalaryServiceImpl extends ServiceImpl<EmployeeSalaryMapper,
|
||||
private BookMapper bookMapper;
|
||||
|
||||
@Autowired
|
||||
private EmployeeSalaryVoucherRuleMapper employeeSalaryVoucherRuleMapper;
|
||||
|
||||
VoucherTemplateMapper voucherTemplateMapper;
|
||||
|
||||
@Autowired
|
||||
private EmployeeSalaryVoucherRuleTemplateMapper employeeSalaryVoucherRuleTemplateMapper;
|
||||
|
||||
@Autowired
|
||||
private BookSubjectMapper bookSubjectMapper;
|
||||
VoucherTemplateItemMapper voucherTemplateItemMapper;
|
||||
|
||||
@Autowired
|
||||
private VoucherService voucherService;
|
||||
|
||||
@Autowired
|
||||
ConfigSysService configSysService;
|
||||
|
||||
@Autowired
|
||||
BookSubjectService bookSubjectService;
|
||||
|
||||
@Override
|
||||
public Message<Page<EmployeeSalary>> pageList(SalaryDetailPageDto dto) {
|
||||
@ -309,66 +314,76 @@ public class EmployeeSalaryServiceImpl extends ServiceImpl<EmployeeSalaryMapper,
|
||||
String bookId = dto.getBookId();
|
||||
Book book = bookMapper.selectById(bookId);
|
||||
Integer voucherType = dto.getVoucherType();
|
||||
EmployeeSalary summary = super.getById(dto.getId());
|
||||
|
||||
if (voucherType == 0 && StringUtils.isNotBlank(summary.getAccrualVoucherId())) {
|
||||
return Message.ok("计提凭证已生成");
|
||||
} else if (voucherType == 1 && StringUtils.isNotBlank(summary.getSalaryVoucherId())) {
|
||||
EmployeeSalary salary = super.getById(dto.getId());
|
||||
String tplCode = (voucherType == 2 ? "jt_fp_lwf" : "zf_lwf");
|
||||
if (voucherType == 2 && StringUtils.isNotBlank(salary.getAccrualVoucherId())) {
|
||||
return Message.ok("收票凭证已生成");
|
||||
} else if (voucherType == 3 && StringUtils.isNotBlank(salary.getSalaryVoucherId())) {
|
||||
return Message.ok("发放凭证已生成");
|
||||
} else if (voucherType == 2 && StringUtils.isNotBlank(summary.getAccrualVoucherId())) {
|
||||
return Message.ok("收票(兼职)凭证已生成");
|
||||
} else if (voucherType == 3 && StringUtils.isNotBlank(summary.getSalaryVoucherId())) {
|
||||
return Message.ok("发放(兼职)凭证已生成");
|
||||
}
|
||||
|
||||
String currentTerm = configSysService.getCurrentTerm(bookId);
|
||||
|
||||
Date formattedDate = getFormattedCurrentDate();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(formattedDate);
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
int month = calendar.get(Calendar.MONTH) + 1;
|
||||
Date monthEndDate = configSysService.getCurrentTermLastDate(bookId);
|
||||
int year = Integer.parseInt(currentTerm.split("-")[0]);
|
||||
int month = Integer.parseInt(currentTerm.split("-")[1]);
|
||||
|
||||
List<EmployeeSalaryVoucherRule> rules = getSalaryVoucherRules(bookId, voucherType);
|
||||
LambdaQueryWrapper<VoucherTemplate> itemTpl = Wrappers.lambdaQuery();
|
||||
itemTpl.eq(VoucherTemplate::getRelatedId, bookId);
|
||||
itemTpl.eq(VoucherTemplate::getCode, tplCode);
|
||||
itemTpl.eq(VoucherTemplate::getDeleted, "n");
|
||||
|
||||
VoucherTemplate voucherTemplate = voucherTemplateMapper.selectOne(itemTpl);
|
||||
logger.debug("voucherTemplate {}", voucherTemplate);
|
||||
LambdaQueryWrapper<VoucherTemplateItem> itemLqw = Wrappers.lambdaQuery();
|
||||
itemLqw.eq(VoucherTemplateItem::getRelatedId, voucherTemplate.getRelatedId());
|
||||
itemLqw.eq(VoucherTemplateItem::getTemplateId, voucherTemplate.getId());
|
||||
List<VoucherTemplateItem> items = voucherTemplateItemMapper.selectList(itemLqw);
|
||||
|
||||
BigDecimal debitAmount = BigDecimal.ZERO;
|
||||
BigDecimal creditAmount = BigDecimal.ZERO;
|
||||
|
||||
List<VoucherItemChangeDto> voucherItems = new ArrayList<>();
|
||||
|
||||
for (EmployeeSalaryVoucherRule rule : rules) {
|
||||
rule.setSummary(generateVoucherItemSummary(rule.getSummary(), year, month));
|
||||
|
||||
String selectedValue = rule.getSelectedValue();
|
||||
SalaryVoucherTemplateEnum matchedEnum = SalaryVoucherTemplateEnum.fromValue(selectedValue);
|
||||
if (matchedEnum == null) {
|
||||
throw new BusinessException(50001, "凭证模板明细数据有误,请联系管理员");
|
||||
}
|
||||
|
||||
BigDecimal amount = switch (matchedEnum) {
|
||||
case COMPANY_COSTS -> summary.getBusinessExpenditureCosts();
|
||||
case SALARY_PAYABLE -> summary.getTotalAmount().add(summary.getTotalSocialInsurance()).add(summary.getProvidentFund()).add(summary.getPersonalTax());
|
||||
case ACTUAL_SALARY -> summary.getTotalAmount();
|
||||
case PERSONAL_INCOME_TAX -> summary.getPersonalTax();
|
||||
case PERSONAL_WITHHOLDING_SOCIAL_SECURITY -> summary.getTotalSocialInsurance();
|
||||
case PERSONAL_WITHHOLDING_PROVIDENT_FUND -> summary.getProvidentFund();
|
||||
case ENTERPRISES_PAY_SOCIAL_INSURANCE -> summary.getBusinessSocialInsurance();
|
||||
case PROVIDENT_FUND_PAID_BY_ENTERPRISES -> summary.getBusinessProvidentFund();
|
||||
};
|
||||
|
||||
boolean isDebit = "1".equals(rule.getDirection());
|
||||
voucherItems.add(createVoucherItemDto(bookId, rule, isDebit, amount));
|
||||
|
||||
if (isDebit) {
|
||||
debitAmount = debitAmount.add(amount);
|
||||
} else {
|
||||
creditAmount = creditAmount.add(amount);
|
||||
}
|
||||
Map<String, VoucherTemplateItem> itemsMap = new HashMap<>();
|
||||
for (VoucherTemplateItem item : items) {
|
||||
itemsMap.put(item.getSubjectCode(), item);
|
||||
}
|
||||
|
||||
if (voucherTemplate.getCode().equals("jt_fp_lwf")) {//收发票
|
||||
if(itemsMap.containsKey("660222")) {
|
||||
//劳务费
|
||||
debitAmount = debitAmount.add(salary.getPayAmount());
|
||||
voucherItems.add(createVoucherItemDto(bookId, itemsMap.get("660222"), salary.getPayAmount()));
|
||||
}
|
||||
if(itemsMap.containsKey("222114")) {
|
||||
//个税
|
||||
creditAmount = creditAmount.add(salary.getPersonalTax());
|
||||
voucherItems.add(createVoucherItemDto(bookId, itemsMap.get("222114"), salary.getPersonalTax()));
|
||||
}
|
||||
if(itemsMap.containsKey("224101")) {
|
||||
//应付个人
|
||||
creditAmount = creditAmount.add(salary.getTotalAmount());
|
||||
voucherItems.add(createVoucherItemDto(bookId, itemsMap.get("224101"), salary.getTotalAmount()));
|
||||
}
|
||||
}else if (voucherTemplate.getCode().equals("zf_lwf")) {//发放劳务费
|
||||
if(itemsMap.containsKey("224101")) {
|
||||
//发放金额
|
||||
debitAmount = debitAmount.add(salary.getTotalAmount());
|
||||
voucherItems.add(createVoucherItemDto(bookId, itemsMap.get("224101"), salary.getTotalAmount()));
|
||||
}
|
||||
|
||||
for (VoucherTemplateItem item : items) {
|
||||
if(item.getSubjectCode().startsWith("1002")) {
|
||||
voucherItems.add(createVoucherItemDto(bookId, item, debitAmount));
|
||||
}
|
||||
}
|
||||
creditAmount = debitAmount;
|
||||
}
|
||||
|
||||
if (debitAmount.compareTo(creditAmount) != 0) {
|
||||
throw new BusinessException(50001, "借贷不平衡,请调整工资凭证模板");
|
||||
}
|
||||
Employee employee = employeeMapper.selectById(salary.getEmployeeId());
|
||||
|
||||
VoucherChangeDto voucherChangeDto = createVoucherChangeDto(book, bookId, formattedDate, year, month, debitAmount);
|
||||
voucherChangeDto.setRemark(rules.get(0).getSummary());
|
||||
VoucherChangeDto voucherChangeDto = createVoucherChangeDto(book, bookId, monthEndDate, year, month, debitAmount);
|
||||
voucherChangeDto.setRemark(voucherTemplate.getRemark().replace("{yyyy}", year + "").replace("{mm}", month + "").replace("{name}", employee.getDisplayName()));
|
||||
voucherChangeDto.setItems(voucherItems);
|
||||
voucherChangeDto.setStatus(VoucherStatusEnum.DRAFT.getValue());
|
||||
|
||||
@ -386,77 +401,26 @@ public class EmployeeSalaryServiceImpl extends ServiceImpl<EmployeeSalaryMapper,
|
||||
return Message.ok(voucherChangeDto.getId());
|
||||
}
|
||||
|
||||
public String generateVoucherItemSummary(String summary, int year, int month) {
|
||||
return summary.replace("{yy}", (year + "").substring(2)).replace("{yyyy}", year + "").replace("{mm}", month + "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current date formatted as yyyy-MM-dd with time set to 00:00:00
|
||||
*/
|
||||
private Date getFormattedCurrentDate() {
|
||||
try {
|
||||
Date currentDate = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDateStr = dateFormat.format(currentDate);
|
||||
return dateFormat.parse(formattedDateStr);
|
||||
} catch (ParseException e) {
|
||||
log.error("Error formatting date");
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
|
||||
private List<EmployeeSalaryVoucherRule> getSalaryVoucherRules(String bookId, Integer voucherType) {
|
||||
List<EmployeeSalaryVoucherRuleTemplate> employeeSalaryVoucherRuleTemplates = employeeSalaryVoucherRuleTemplateMapper.selectList(Wrappers.<EmployeeSalaryVoucherRuleTemplate>lambdaQuery()
|
||||
.eq(EmployeeSalaryVoucherRuleTemplate::getBookId, bookId)
|
||||
.eq(EmployeeSalaryVoucherRuleTemplate::getStatus, 1)
|
||||
.eq(EmployeeSalaryVoucherRuleTemplate::getVoucherType, voucherType));
|
||||
if (ObjectUtils.isEmpty(employeeSalaryVoucherRuleTemplates)) {
|
||||
if (Objects.equals(voucherType, 0)) {
|
||||
throw new BusinessException(50001, "缺少计提工资凭证模板,请先在工资凭证规则处生成");
|
||||
} else {
|
||||
throw new BusinessException(50001, "缺少发放工资凭证模板,请先在工资凭证规则处生成");
|
||||
}
|
||||
}
|
||||
|
||||
String id = employeeSalaryVoucherRuleTemplates.get(0).getId();
|
||||
List<EmployeeSalaryVoucherRule> employeeSalaryVoucherRules = employeeSalaryVoucherRuleMapper.selectList(Wrappers.<EmployeeSalaryVoucherRule>lambdaQuery()
|
||||
.eq(EmployeeSalaryVoucherRule::getTemplateId, id));
|
||||
|
||||
if (employeeSalaryVoucherRules.size() < 2) {
|
||||
throw new BusinessException(50001, "请添加模板明细数据");
|
||||
}
|
||||
|
||||
return employeeSalaryVoucherRules;
|
||||
}
|
||||
|
||||
private VoucherItemChangeDto createVoucherItemDto(String bookId,
|
||||
EmployeeSalaryVoucherRule rule, boolean isDebit, BigDecimal amount) {
|
||||
|
||||
LambdaQueryWrapper<BookSubject> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(BookSubject::getBookId, bookId);
|
||||
wrapper.eq(BookSubject::getCode, rule.getSubjectCode());
|
||||
BookSubject bookSubject = bookSubjectMapper.selectOne(wrapper);
|
||||
|
||||
if (Objects.isNull(bookSubject)) {
|
||||
throw new BusinessException(50001, "查询不到该工资凭证规则设置的账套科目,请检查。");
|
||||
}
|
||||
|
||||
VoucherItemChangeDto itemDto = new VoucherItemChangeDto();
|
||||
itemDto.setSummary(rule.getSummary());
|
||||
itemDto.setSubjectId(bookSubject.getId());
|
||||
if (isDebit) {
|
||||
itemDto.setDebitAmount(amount);
|
||||
} else {
|
||||
itemDto.setCreditAmount(amount);
|
||||
}
|
||||
itemDto.setAuxiliary(List.of());
|
||||
itemDto.setSubjectCode(bookSubject.getCode());
|
||||
itemDto.setSubjectName(bookSubject.getCode() + "-" + bookSubject.getName());
|
||||
itemDto.setDetailedAccounts("");
|
||||
// itemDto.setSubjectBalance(BigDecimal.ZERO);
|
||||
|
||||
return itemDto;
|
||||
}
|
||||
VoucherTemplateItem item, BigDecimal amount) {
|
||||
BookSubject bookSubject = bookSubjectService.selectSubject(bookId, item.getSubjectCode());
|
||||
|
||||
VoucherItemChangeDto itemDto = new VoucherItemChangeDto();
|
||||
itemDto.setSummary(item.getSummary());
|
||||
itemDto.setSubjectId(bookSubject.getId());
|
||||
if (item.getDirection() == 1) {
|
||||
itemDto.setDebitAmount(amount);
|
||||
} else {
|
||||
itemDto.setCreditAmount(amount);
|
||||
}
|
||||
itemDto.setSubjectBalance(bookSubject.getBalance());
|
||||
itemDto.setAuxiliary(List.of());
|
||||
itemDto.setSubjectCode(bookSubject.getCode());
|
||||
itemDto.setSubjectName(bookSubject.getCode() + "-" + bookSubject.getName());
|
||||
itemDto.setDetailedAccounts("");
|
||||
|
||||
return itemDto;
|
||||
}
|
||||
|
||||
private VoucherChangeDto createVoucherChangeDto(Book book, String bookId,
|
||||
Date voucherDate, Integer year, Integer month, BigDecimal amount) {
|
||||
|
||||
@ -19,26 +19,15 @@
|
||||
package com.jinbooks.persistence.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jinbooks.entity.Message;
|
||||
import com.jinbooks.entity.book.Book;
|
||||
import com.jinbooks.entity.book.BookSubject;
|
||||
import com.jinbooks.entity.hr.EmployeeSalarySummary;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRule;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
import com.jinbooks.entity.hr.dto.SalaryDetailPageDto;
|
||||
import com.jinbooks.entity.hr.dto.SalarySummaryChangeDto;
|
||||
import com.jinbooks.entity.voucher.dto.GenerateVoucherDto;
|
||||
import com.jinbooks.entity.voucher.dto.VoucherChangeDto;
|
||||
import com.jinbooks.entity.voucher.dto.VoucherItemChangeDto;
|
||||
import com.jinbooks.enums.SalaryVoucherTemplateEnum;
|
||||
import com.jinbooks.enums.VoucherStatusEnum;
|
||||
import com.jinbooks.exception.BusinessException;
|
||||
import com.jinbooks.persistence.mapper.*;
|
||||
import com.jinbooks.persistence.service.ConfigSysService;
|
||||
import com.jinbooks.persistence.service.EmployeeSalarySummaryService;
|
||||
@ -47,9 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.YearMonth;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
@ -64,12 +51,6 @@ public class EmployeeSalarySummaryServiceImpl extends ServiceImpl<EmployeeSalary
|
||||
@Autowired
|
||||
EmployeeSalaryMapper employeeSalaryMapper;
|
||||
|
||||
@Autowired
|
||||
EmployeeSalaryVoucherRuleMapper employeeSalaryVoucherRuleMapper;
|
||||
|
||||
@Autowired
|
||||
EmployeeSalaryVoucherRuleTemplateMapper employeeSalaryVoucherRuleTemplateMapper;
|
||||
|
||||
@Autowired
|
||||
VoucherService voucherService;
|
||||
|
||||
|
||||
@ -1,283 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.persistence.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jinbooks.entity.Message;
|
||||
import com.jinbooks.entity.dto.ChangeStatusDto;
|
||||
import com.jinbooks.entity.dto.ListIdsDto;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRule;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
import com.jinbooks.entity.hr.dto.EmployeeSalaryVoucherRulePageDto;
|
||||
import com.jinbooks.entity.hr.dto.SalaryTemplateDetailDto;
|
||||
import com.jinbooks.entity.hr.dto.SalaryTemplateDto;
|
||||
import com.jinbooks.entity.hr.vo.SalaryTemplateVo;
|
||||
import com.jinbooks.exception.BusinessException;
|
||||
import com.jinbooks.persistence.mapper.EmployeeSalaryVoucherRuleMapper;
|
||||
import com.jinbooks.persistence.service.EmployeeSalaryVoucherRuleService;
|
||||
import com.jinbooks.persistence.service.EmployeeSalaryVoucherRuleTemplateService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/3/11 10:47
|
||||
*/
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EmployeeSalaryVoucherRuleServiceImpl extends ServiceImpl<EmployeeSalaryVoucherRuleMapper, EmployeeSalaryVoucherRule> implements EmployeeSalaryVoucherRuleService {
|
||||
|
||||
private final EmployeeSalaryVoucherRuleTemplateService employeeSalaryVoucherRuleTemplateService;
|
||||
|
||||
@Override
|
||||
public Message<Page<EmployeeSalaryVoucherRuleTemplate>> pageList(EmployeeSalaryVoucherRulePageDto dto) {
|
||||
|
||||
LambdaQueryWrapper<EmployeeSalaryVoucherRuleTemplate> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmployeeSalaryVoucherRuleTemplate::getBookId, dto.getBookId());
|
||||
|
||||
Page<EmployeeSalaryVoucherRuleTemplate> page = employeeSalaryVoucherRuleTemplateService.page(dto.build(), wrapper);
|
||||
|
||||
return Message.ok(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Message<String> save(SalaryTemplateDto dto) {
|
||||
|
||||
checkTemplate(dto, false);
|
||||
|
||||
//凭证类型
|
||||
Integer voucherType = dto.getVoucherType();
|
||||
//凭证字
|
||||
String wordHead = dto.getWordHead();
|
||||
//账套ID
|
||||
String bookId = dto.getBookId();
|
||||
|
||||
EmployeeSalaryVoucherRuleTemplate employeeSalaryVoucherRuleTemplate = new EmployeeSalaryVoucherRuleTemplate();
|
||||
employeeSalaryVoucherRuleTemplate.setVoucherType(voucherType);
|
||||
employeeSalaryVoucherRuleTemplate.setWordHead(wordHead);
|
||||
employeeSalaryVoucherRuleTemplate.setBookId(bookId);
|
||||
boolean templateResult = employeeSalaryVoucherRuleTemplateService.save(employeeSalaryVoucherRuleTemplate);
|
||||
|
||||
if (!templateResult) {
|
||||
return Message.failed("新增模板失败");
|
||||
}
|
||||
|
||||
List<SalaryTemplateDetailDto> salaryTemplateDetailDtos = dto.getSalaryTemplateDetailDtos();
|
||||
|
||||
List<EmployeeSalaryVoucherRule> employeeSalaryVoucherRules = new ArrayList<>();
|
||||
|
||||
for (SalaryTemplateDetailDto salaryTemplateDetailDto : salaryTemplateDetailDtos) {
|
||||
EmployeeSalaryVoucherRule employeeSalaryVoucherRule = BeanUtil.copyProperties(salaryTemplateDetailDto, EmployeeSalaryVoucherRule.class);
|
||||
employeeSalaryVoucherRule.setTemplateId(employeeSalaryVoucherRuleTemplate.getId());
|
||||
employeeSalaryVoucherRules.add(employeeSalaryVoucherRule);
|
||||
}
|
||||
|
||||
boolean save = super.saveBatch(employeeSalaryVoucherRules);
|
||||
|
||||
return save ? Message.ok("新增成功") : Message.failed("新增失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Message<String> update(SalaryTemplateDto dto) {
|
||||
checkTemplate(dto, true);
|
||||
|
||||
//找出已经存在的数据
|
||||
List<EmployeeSalaryVoucherRule> employeeSalaryVoucherRules = super.list(Wrappers.<EmployeeSalaryVoucherRule>lambdaQuery()
|
||||
.eq(EmployeeSalaryVoucherRule::getTemplateId, dto.getId()));
|
||||
//入参集合
|
||||
List<SalaryTemplateDetailDto> salaryTemplateDetailDtos = dto.getSalaryTemplateDetailDtos();
|
||||
|
||||
// 3.1 找出要新增的记录(入参ID为null)
|
||||
List<SalaryTemplateDetailDto> toAddList = salaryTemplateDetailDtos.stream()
|
||||
.filter(item -> StringUtils.isEmpty(item.getId()))
|
||||
.toList();
|
||||
|
||||
// 3.2 创建现有记录的ID映射,用于快速查找
|
||||
Map<String, EmployeeSalaryVoucherRule> existingMap = employeeSalaryVoucherRules.stream()
|
||||
.collect(Collectors.toMap(EmployeeSalaryVoucherRule::getId, Function.identity()));
|
||||
|
||||
// 3.3 创建入参记录的ID映射,用于快速查找
|
||||
Map<String, SalaryTemplateDetailDto> inputMap = salaryTemplateDetailDtos.stream()
|
||||
.filter(item -> StringUtils.isNotEmpty(item.getId()))
|
||||
.collect(Collectors.toMap(SalaryTemplateDetailDto::getId, Function.identity()));
|
||||
|
||||
// 3.4 找出要删除的记录(在现有记录中但不在入参中)
|
||||
List<EmployeeSalaryVoucherRule> toDeleteList = employeeSalaryVoucherRules.stream()
|
||||
.filter(item -> !inputMap.containsKey(item.getId()))
|
||||
.toList();
|
||||
|
||||
// 3.5 找出要更新的记录(两边都有)
|
||||
List<SalaryTemplateDetailDto> toUpdateList = salaryTemplateDetailDtos.stream()
|
||||
.filter(item -> StringUtils.isNotEmpty(item.getId()) && existingMap.containsKey(item.getId()))
|
||||
.toList();
|
||||
|
||||
// 4. 处理新增
|
||||
if (!toAddList.isEmpty()) {
|
||||
List<EmployeeSalaryVoucherRule> newRules = toAddList.stream()
|
||||
.map(this::convertToRule) // 需要实现一个转换方法
|
||||
.peek(rule -> rule.setTemplateId(dto.getId()))
|
||||
.toList();
|
||||
|
||||
super.saveBatch(newRules);
|
||||
}
|
||||
|
||||
// 5. 处理删除
|
||||
if (!toDeleteList.isEmpty()) {
|
||||
List<String> idsToDelete = toDeleteList.stream()
|
||||
.map(EmployeeSalaryVoucherRule::getId)
|
||||
.toList();
|
||||
|
||||
super.removeByIds(idsToDelete);
|
||||
}
|
||||
|
||||
// 6. 处理更新
|
||||
if (!toUpdateList.isEmpty()) {
|
||||
List<EmployeeSalaryVoucherRule> updatedRules = toUpdateList.stream()
|
||||
.map(item -> {
|
||||
EmployeeSalaryVoucherRule existingRule = existingMap.get(item.getId());
|
||||
// 更新规则的属性
|
||||
updateRuleFromDto(existingRule, item);
|
||||
return existingRule;
|
||||
})
|
||||
.toList();
|
||||
|
||||
super.updateBatchById(updatedRules);
|
||||
}
|
||||
|
||||
|
||||
/* BookSubject bookSubject = bookSubjectMapper.selectById(dto.getSubjectId());
|
||||
String auxiliary = bookSubject.getAuxiliary();
|
||||
if (StringUtils.isNotBlank(auxiliary) && !"[]".equals(auxiliary)) {
|
||||
throw new BusinessException(500001, "不能选择辅助核算科目作为工资凭证规则");
|
||||
}
|
||||
|
||||
EmployeeSalaryVoucherRule employeeSalaryVoucherRule = BeanUtil.copyProperties(dto, EmployeeSalaryVoucherRule.class);
|
||||
boolean result = super.updateById(employeeSalaryVoucherRule);
|
||||
return result ? Message.ok("修改成功") : Message.failed("修改失败");*/
|
||||
return Message.ok("修改成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Message<String> delete(ListIdsDto dto) {
|
||||
List<String> ids = dto.getListIds();
|
||||
//状态检查
|
||||
List<EmployeeSalaryVoucherRuleTemplate> list = employeeSalaryVoucherRuleTemplateService.list(Wrappers.<EmployeeSalaryVoucherRuleTemplate>lambdaQuery()
|
||||
.eq(EmployeeSalaryVoucherRuleTemplate::getStatus, 1)
|
||||
.in(EmployeeSalaryVoucherRuleTemplate::getId, ids));
|
||||
if (ObjectUtils.isNotEmpty(list)) {
|
||||
throw new BusinessException(50001, "请先禁用当前数据再进行删除操作");
|
||||
}
|
||||
//删除模板数据
|
||||
boolean result = employeeSalaryVoucherRuleTemplateService.removeBatchByIds(ids);
|
||||
//删除明细数据
|
||||
super.remove(Wrappers.<EmployeeSalaryVoucherRule>lambdaQuery()
|
||||
.in(EmployeeSalaryVoucherRule::getTemplateId, ids));
|
||||
return result ? new Message<>(Message.SUCCESS, "删除成功") : new Message<>(Message.FAIL, "删除失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<String> changeStatus(ChangeStatusDto dto) {
|
||||
Integer status = dto.getStatus();
|
||||
String id = dto.getId();
|
||||
|
||||
EmployeeSalaryVoucherRuleTemplate employeeSalaryVoucherRuleTemplate = employeeSalaryVoucherRuleTemplateService.getById(id);
|
||||
|
||||
//启用
|
||||
if (Objects.equals(status, 1)) {
|
||||
SalaryTemplateDto salaryTemplateDto = new SalaryTemplateDto();
|
||||
salaryTemplateDto.setBookId(employeeSalaryVoucherRuleTemplate.getBookId());
|
||||
salaryTemplateDto.setVoucherType(employeeSalaryVoucherRuleTemplate.getVoucherType());
|
||||
checkTemplate(salaryTemplateDto, false);
|
||||
}
|
||||
|
||||
employeeSalaryVoucherRuleTemplate.setStatus(status);
|
||||
|
||||
boolean result = employeeSalaryVoucherRuleTemplateService.updateById(employeeSalaryVoucherRuleTemplate);
|
||||
|
||||
return result ? Message.ok("操作成功") : Message.failed("操作失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<SalaryTemplateVo> getTemplateDetail(String id) {
|
||||
EmployeeSalaryVoucherRuleTemplate template = employeeSalaryVoucherRuleTemplateService.getById(id);
|
||||
SalaryTemplateVo salaryTemplateVo = BeanUtil.copyProperties(template, SalaryTemplateVo.class);
|
||||
|
||||
List<EmployeeSalaryVoucherRule> list = super.list(Wrappers.<EmployeeSalaryVoucherRule>lambdaQuery()
|
||||
.eq(EmployeeSalaryVoucherRule::getTemplateId, id));
|
||||
|
||||
salaryTemplateVo.setEmployeeSalaryVoucherRules(list);
|
||||
|
||||
return Message.ok(salaryTemplateVo);
|
||||
}
|
||||
|
||||
private void checkTemplate(SalaryTemplateDto dto, boolean isEdit) {
|
||||
LambdaQueryWrapper<EmployeeSalaryVoucherRuleTemplate> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmployeeSalaryVoucherRuleTemplate::getBookId, dto.getBookId());
|
||||
wrapper.eq(EmployeeSalaryVoucherRuleTemplate::getStatus, 1);
|
||||
wrapper.eq(EmployeeSalaryVoucherRuleTemplate::getVoucherType, dto.getVoucherType());
|
||||
if (isEdit) {
|
||||
wrapper.ne(EmployeeSalaryVoucherRuleTemplate::getId, dto.getId());
|
||||
}
|
||||
|
||||
List<EmployeeSalaryVoucherRuleTemplate> list = employeeSalaryVoucherRuleTemplateService.list(wrapper);
|
||||
if (ObjectUtils.isNotEmpty(list)) {
|
||||
throw new BusinessException(50001, "保存失败!该薪资类型的模版已被启用");
|
||||
}
|
||||
}
|
||||
|
||||
// 需要实现的辅助方法
|
||||
private EmployeeSalaryVoucherRule convertToRule(SalaryTemplateDetailDto dto) {
|
||||
EmployeeSalaryVoucherRule rule = new EmployeeSalaryVoucherRule();
|
||||
// 设置属性
|
||||
rule.setSummary(dto.getSummary());
|
||||
rule.setDirection(dto.getDirection());
|
||||
rule.setSubjectCode(dto.getSubjectCode());
|
||||
rule.setSelectedValue(dto.getSelectedValue());
|
||||
// 设置其他属性...
|
||||
return rule;
|
||||
}
|
||||
|
||||
private void updateRuleFromDto(EmployeeSalaryVoucherRule rule, SalaryTemplateDetailDto dto) {
|
||||
// 更新属性
|
||||
rule.setSummary(dto.getSummary());
|
||||
rule.setDirection(dto.getDirection());
|
||||
rule.setSubjectCode(dto.getSubjectCode());
|
||||
rule.setSelectedValue(dto.getSelectedValue());
|
||||
// 更新其他属性...
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.persistence.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
import com.jinbooks.persistence.mapper.EmployeeSalaryVoucherRuleTemplateMapper;
|
||||
import com.jinbooks.persistence.service.EmployeeSalaryVoucherRuleTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/5/7 9:36
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class EmployeeSalaryVoucherRuleTemplateServiceImpl extends ServiceImpl<EmployeeSalaryVoucherRuleTemplateMapper, EmployeeSalaryVoucherRuleTemplate>
|
||||
implements EmployeeSalaryVoucherRuleTemplateService {
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jinbooks.persistence.mapper.EmployeeSalaryVoucherRuleMapper">
|
||||
<select id="pageList"
|
||||
parameterType="com.jinbooks.entity.hr.dto.EmployeeSalaryVoucherRulePageDto"
|
||||
resultType="com.jinbooks.entity.hr.EmployeeSalaryVoucherRule">
|
||||
select jesvr.*,jbs.display_name as subjectName,jbs.code as subjectCode
|
||||
from jbx_employee_salary_voucher_rule jesvr
|
||||
join jbx_book_subject jbs on jesvr.subject_id = jbs.id
|
||||
and jbs.deleted = 'n'
|
||||
and jbs.book_id = #{dto.bookId}
|
||||
and (jbs.is_auxiliary <> 1 OR jbs.is_auxiliary IS NULL)
|
||||
where jesvr.deleted = 'n'
|
||||
and jesvr.book_id = #{dto.bookId}
|
||||
<if test="dto.voucherType != null">
|
||||
and jesvr.voucher_type = #{dto.voucherType}
|
||||
</if>
|
||||
order by jesvr.created_date desc
|
||||
</select>
|
||||
</mapper>
|
||||
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright [2025] [JinBooks of copyright http://www.jinbooks.com]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.jinbooks.web.hr.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jinbooks.authn.annotation.CurrentUser;
|
||||
import com.jinbooks.entity.Message;
|
||||
import com.jinbooks.entity.dto.ChangeStatusDto;
|
||||
import com.jinbooks.entity.dto.ListIdsDto;
|
||||
import com.jinbooks.entity.hr.EmployeeSalaryVoucherRuleTemplate;
|
||||
import com.jinbooks.entity.hr.dto.EmployeeSalaryVoucherRulePageDto;
|
||||
import com.jinbooks.entity.hr.dto.SalaryTemplateDto;
|
||||
import com.jinbooks.entity.hr.vo.SalaryTemplateVo;
|
||||
import com.jinbooks.entity.idm.UserInfo;
|
||||
import com.jinbooks.persistence.service.EmployeeSalaryVoucherRuleService;
|
||||
import com.jinbooks.validate.AddGroup;
|
||||
import com.jinbooks.validate.EditGroup;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: orangeBabu
|
||||
* @time: 2025/3/11 10:49
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/employee/salary-voucher-rule")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class EmployeeSalaryVoucherRuleController {
|
||||
|
||||
static final Logger logger = LoggerFactory.getLogger(EmployeeSalaryVoucherRuleController.class);
|
||||
|
||||
private final EmployeeSalaryVoucherRuleService employeeSalaryVoucherRuleService;
|
||||
|
||||
@GetMapping(value = {"/fetch"})
|
||||
public Message<Page<EmployeeSalaryVoucherRuleTemplate>> fetch(@ParameterObject EmployeeSalaryVoucherRulePageDto dto, @CurrentUser UserInfo currentUser) {
|
||||
dto.setBookId(currentUser.getBookId());
|
||||
logger.debug("fetch {}", dto);
|
||||
return employeeSalaryVoucherRuleService.pageList(dto);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public Message<SalaryTemplateVo> getById(@PathVariable(name = "id") String id) {
|
||||
return employeeSalaryVoucherRuleService.getTemplateDetail(id);
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
public Message<String> save(@Validated(value = AddGroup.class) @RequestBody SalaryTemplateDto dto,
|
||||
@CurrentUser UserInfo currentUser) {
|
||||
dto.setBookId(currentUser.getBookId());
|
||||
return employeeSalaryVoucherRuleService.save(dto);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
public Message<String> update(@Validated(value = EditGroup.class) @RequestBody SalaryTemplateDto dto) {
|
||||
return employeeSalaryVoucherRuleService.update(dto);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
public Message<String> delete(@RequestBody ListIdsDto dto) {
|
||||
return employeeSalaryVoucherRuleService.delete(dto);
|
||||
}
|
||||
|
||||
@PutMapping("/change-status")
|
||||
public Message<String> changeStatus(@RequestBody ChangeStatusDto dto) {
|
||||
return employeeSalaryVoucherRuleService.changeStatus(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user