优化工资计算逻辑
This commit is contained in:
@@ -24,6 +24,7 @@ import com.ruoyi.oa.domain.vo.OaSalaryVo;
|
||||
import com.ruoyi.oa.domain.bo.OaSalaryBo;
|
||||
import com.ruoyi.oa.service.IOaSalaryService;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 薪资管理
|
||||
@@ -118,4 +119,6 @@ public class OaSalaryController extends BaseController {
|
||||
public R<Void> calc(@RequestBody OaSalaryBo bo) {
|
||||
return R.ok(iOaSalaryService.calcSalary(bo));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.ruoyi.oa.domain.bo.OaSalaryBo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.*;
|
||||
@@ -47,6 +48,12 @@ public class OaSalaryItemController extends BaseController {
|
||||
return iOaSalaryItemService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/check-file")
|
||||
public R<Boolean> checkFile(OaSalaryItemBo bo, PageQuery pageQuery) {
|
||||
return R.ok(iOaSalaryItemService.checkFile(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出薪水详情列表
|
||||
*/
|
||||
@@ -100,4 +107,6 @@ public class OaSalaryItemController extends BaseController {
|
||||
@PathVariable Long[] salaryItemIds) {
|
||||
return toAjax(iOaSalaryItemService.deleteWithValidByIds(Arrays.asList(salaryItemIds), true));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,13 +27,11 @@ public class OaSalaryItemBo extends BaseEntity {
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@NotNull(message = "主键id不能为空", groups = { EditGroup.class })
|
||||
private Long salaryItemId;
|
||||
|
||||
/**
|
||||
* 奖惩类型
|
||||
*/
|
||||
@NotNull(message = "奖惩类型不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long type;
|
||||
|
||||
/**
|
||||
@@ -44,13 +42,11 @@ public class OaSalaryItemBo extends BaseEntity {
|
||||
/**
|
||||
* 涉及金额
|
||||
*/
|
||||
@NotNull(message = "涉及金额不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Double price;
|
||||
|
||||
/**
|
||||
* 奖罚记号1奖0罚
|
||||
*/
|
||||
@NotNull(message = "奖罚记号不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long flag;
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,4 +70,6 @@ public class OaSalaryVo extends OaSalary {
|
||||
private String remark;
|
||||
|
||||
private List<OaSalaryItemVo> itemList;
|
||||
|
||||
private Double laborCost;
|
||||
}
|
||||
|
||||
@@ -27,4 +27,6 @@ public interface OaSalaryMapper extends BaseMapperPlus<OaSalaryMapper, OaSalary,
|
||||
OaSalaryVo selectVoAndItemVoById(@Param("salaryId")Long salaryId,@Param("payTime")Date payTime);
|
||||
|
||||
void delByPayTime(Date date);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -46,4 +46,7 @@ public interface IOaSalaryItemService {
|
||||
* 校验并批量删除薪水详情信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
|
||||
Boolean checkFile(OaSalaryItemBo bo);
|
||||
}
|
||||
|
||||
@@ -111,4 +111,12 @@ public class OaSalaryItemServiceImpl implements IOaSalaryItemService {
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkFile(OaSalaryItemBo bo) {
|
||||
LambdaQueryWrapper<OaSalaryItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.like(OaSalaryItem::getSignTime,bo.getSignTime());
|
||||
lambdaQueryWrapper.eq(OaSalaryItem::getType,3L);
|
||||
return baseMapper.selectList(lambdaQueryWrapper).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ruoyi.oa.domain.OaSalaryItem;
|
||||
import com.ruoyi.oa.domain.bo.SysOaAttendanceBo;
|
||||
import com.ruoyi.oa.domain.vo.CalcResultVo;
|
||||
import com.ruoyi.oa.domain.vo.SysOaAttendanceVo;
|
||||
import com.ruoyi.oa.domain.vo.SysOaHolidayVo;
|
||||
import com.ruoyi.oa.mapper.OaSalaryItemMapper;
|
||||
import com.ruoyi.oa.service.ISysOaAttendanceService;
|
||||
import com.ruoyi.oa.service.ISysOaHolidayService;
|
||||
import com.ruoyi.oa.utils.OwnHttpUtils;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
@@ -36,7 +39,6 @@ import com.ruoyi.oa.mapper.OaSalaryMapper;
|
||||
import com.ruoyi.oa.service.IOaSalaryService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -81,6 +83,9 @@ public class OaSalaryServiceImpl implements IOaSalaryService {
|
||||
@Autowired
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysOaAttendanceService sysOaAttendanceService;
|
||||
|
||||
/**
|
||||
* 查询薪资管理
|
||||
*/
|
||||
@@ -94,11 +99,17 @@ public class OaSalaryServiceImpl implements IOaSalaryService {
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<OaSalaryVo> queryPageList(OaSalaryBo bo, PageQuery pageQuery) {
|
||||
|
||||
List<Long> userIds = sysUserRoleMapper.selectUserIdsByNotRoleId(1852970465740505090L);
|
||||
QueryWrapper<OaSalary> lqw = new QueryWrapper<>();
|
||||
lqw.in("os.user_id",userIds);
|
||||
Page<OaSalaryVo> result = baseMapper.selectStaffVoPage(pageQuery.build(), lqw,bo.getPayTime());
|
||||
// 判断一下是否传参 如果没传参则默认查询当月记录,如果当月记录为空则创造当月的记录然后返回回去
|
||||
Date payTime = bo.getPayTime()!=null?bo.getPayTime():new Date();
|
||||
Page<OaSalaryVo> result = baseMapper.selectStaffVoPage(pageQuery.build(), lqw,payTime);
|
||||
if (result.getRecords().isEmpty()){
|
||||
// 判断是否有当前月的记录 没有则进行创造新的记录
|
||||
this.importSalaryUser();
|
||||
result = baseMapper.selectStaffVoPage(pageQuery.build(), lqw,payTime);
|
||||
}
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@@ -108,7 +119,13 @@ public class OaSalaryServiceImpl implements IOaSalaryService {
|
||||
List<Long> userIds = sysUserRoleMapper.selectUserIdsByRoleId(1852970465740505090L);
|
||||
QueryWrapper<OaSalary> lqw = new QueryWrapper<>();
|
||||
lqw.in("os.user_id",userIds);
|
||||
Page<OaSalaryVo> result = baseMapper.selectStaffVoPage(pageQuery.build(), lqw,bo.getPayTime());
|
||||
Date payTime = bo.getPayTime()!=null?bo.getPayTime():new Date();
|
||||
Page<OaSalaryVo> result = baseMapper.selectStaffVoPage(pageQuery.build(), lqw,payTime);
|
||||
if (result.getRecords().isEmpty()){
|
||||
// 判断是否有当前月的记录 没有则进行创造新的记录
|
||||
this.importSalaryUser();
|
||||
result = baseMapper.selectStaffVoPage(pageQuery.build(), lqw,payTime);
|
||||
}
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@@ -199,6 +216,9 @@ public class OaSalaryServiceImpl implements IOaSalaryService {
|
||||
String jsonPath = OwnHttpUtils.getJsonName(bo.getMonthStr(), bo.getFilePath());
|
||||
// 2拿到所有的用户
|
||||
Date yearMonth = StringToDate(combineYearMonth(bo.getMonthStr()));
|
||||
// 添加去重思想 即拿到月份如果之前计算过,则将原来的全部删掉然后新增新的
|
||||
baseMapper.delByPayTime(yearMonth);
|
||||
|
||||
List<SysUser> sysUsers = userService.selectUserList2();
|
||||
// 3遍历user列表 拿出所有的nickName分别拿到他们的json 进行第二步分析
|
||||
for (SysUser user : sysUsers) {
|
||||
@@ -277,6 +297,11 @@ public class OaSalaryServiceImpl implements IOaSalaryService {
|
||||
});
|
||||
}
|
||||
}
|
||||
List<String> days = getDays(bo, res.getAbsentDates());
|
||||
res.setAbsentDates(days);
|
||||
List<String> days05 = getDays(bo, res.getAbsent05Dates());
|
||||
res.setAbsentDates(days);
|
||||
res.setAbsent05Dates(days05);
|
||||
buildItemAbsent(res.getAbsentDates(), salary,1.0,yearMonth);
|
||||
buildItemAbsent(res.getAbsent05Dates(), salary,0.5,yearMonth);
|
||||
|
||||
@@ -350,6 +375,20 @@ public class OaSalaryServiceImpl implements IOaSalaryService {
|
||||
return "计算成功";
|
||||
}
|
||||
|
||||
private List<String> getDays(OaSalaryBo bo, List<String> res) {
|
||||
List<String> days = new ArrayList<>();
|
||||
for (String absentDate : res) {
|
||||
String dateString = combineYearMonthAndDay(bo.getMonthStr(), absentDate);
|
||||
Date date = StringToDate(dateString);
|
||||
SysOaAttendanceBo sysOaAttendanceBo = new SysOaAttendanceBo();
|
||||
sysOaAttendanceBo.setCreateTime(date);
|
||||
SysOaAttendanceVo sysOaAttendanceVo = sysOaAttendanceService.queryList(sysOaAttendanceBo).get(0);
|
||||
if (sysOaAttendanceVo != null && sysOaAttendanceVo.getProjectId()!=0) {
|
||||
days.add(absentDate);
|
||||
}
|
||||
}
|
||||
return days;
|
||||
}
|
||||
|
||||
|
||||
private void buildItemAbsent(List<String> realDate2, OaSalary salary,Double flag,Date yearMonth) {
|
||||
@@ -378,6 +417,7 @@ public class OaSalaryServiceImpl implements IOaSalaryService {
|
||||
salaryItemMapper.insert(oaSalaryItem);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取从 startTime 到 endTime(含首尾)的所有日期列表
|
||||
*
|
||||
|
||||
@@ -84,6 +84,7 @@ public class SysOaAttendanceServiceImpl implements ISysOaAttendanceService {
|
||||
lqw.eq(bo.getProjectId() != null, SysOaAttendance::getProjectId, bo.getProjectId());
|
||||
lqw.eq(bo.getDayLength() != null, SysOaAttendance::getDayLength, bo.getDayLength());
|
||||
lqw.eq(bo.getHour() != null, SysOaAttendance::getHour, bo.getHour());
|
||||
lqw.like(bo.getCreateTime()!=null, SysOaAttendance::getCreateTime, bo.getCreateTime());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@@ -123,8 +124,6 @@ public class SysOaAttendanceServiceImpl implements ISysOaAttendanceService {
|
||||
sysOaAttendanceVo.setDelFlag(0L);
|
||||
sysOaAttendanceVo.setDayLength(bo.getDayLength()!=null?bo.getDayLength():0);
|
||||
sysOaAttendanceVo.setHour(bo.getHour()!=null?bo.getHour():0);
|
||||
|
||||
|
||||
return baseMapper.updateDelAttendance(BeanUtil.toBean(sysOaAttendanceVo, SysOaAttendance.class)) > 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
os.salary_id,
|
||||
os.user_id,
|
||||
os.pay_time,
|
||||
os.base_salary,
|
||||
(
|
||||
COALESCE(SUM(
|
||||
CASE
|
||||
@@ -44,7 +43,8 @@
|
||||
) AS real_salary,
|
||||
osi.salary_item_id,
|
||||
osi.sign_time,
|
||||
su.nick_name
|
||||
su.nick_name,
|
||||
labor_cost as base_salary
|
||||
FROM oa_salary os
|
||||
LEFT JOIN oa_salary_item osi
|
||||
ON osi.salary_id = os.salary_id
|
||||
|
||||
Reference in New Issue
Block a user