2024-09-23 17:50:28 +08:00
|
|
|
package com.gunshi.project.xyt.controller;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
import com.gunshi.core.result.R;
|
|
|
|
|
import com.gunshi.project.xyt.entity.so.PersonnelPlanLogPage;
|
|
|
|
|
import com.gunshi.project.xyt.entity.vo.PersonnelPlanLogStatisticsVo;
|
|
|
|
|
import com.gunshi.project.xyt.model.PersonnelPlan;
|
|
|
|
|
import com.gunshi.project.xyt.model.PersonnelPlanLog;
|
|
|
|
|
import com.gunshi.project.xyt.service.PersonnelPlanLogService;
|
|
|
|
|
import com.gunshi.project.xyt.service.PersonnelPlanService;
|
|
|
|
|
import com.gunshi.project.xyt.util.DateUtil;
|
|
|
|
|
import com.gunshi.project.xyt.validate.markers.Insert;
|
|
|
|
|
import com.gunshi.project.xyt.validate.markers.Update;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Description:
|
|
|
|
|
* Created by XuSan on 2024/9/23.
|
|
|
|
|
*
|
|
|
|
|
* @author XuSan
|
|
|
|
|
* @version 1.0
|
|
|
|
|
*/
|
2024-09-24 17:25:12 +08:00
|
|
|
@Tag(name = "培训记录表")
|
2024-09-23 17:50:28 +08:00
|
|
|
@RestController
|
|
|
|
|
@RequestMapping(value = "/personnelPlanLog")
|
|
|
|
|
public class PersonnelPlanLogController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PersonnelPlanLogService service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PersonnelPlanService planService;
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "新增")
|
|
|
|
|
@PostMapping("/insert")
|
|
|
|
|
public R<PersonnelPlanLog> insert(@Validated(Insert.class) @RequestBody PersonnelPlanLog dto) {
|
|
|
|
|
|
|
|
|
|
if (dto.getStm().compareTo(dto.getEtm()) >= 0) {
|
|
|
|
|
throw new IllegalArgumentException("开始时间不能大于结束时间");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LambdaQueryChainWrapper<PersonnelPlanLog> query = service.lambdaQuery()
|
|
|
|
|
.eq(PersonnelPlanLog::getPlanDate, dto. getPlanDate())
|
|
|
|
|
.eq(PersonnelPlanLog::getName, dto.getName());
|
|
|
|
|
if (query.count() > 0){
|
|
|
|
|
throw new IllegalArgumentException("当前培训日期标题名称重复");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (planService.lambdaQuery().eq(PersonnelPlan::getId, dto.getPlanId()).count() == 0) {
|
|
|
|
|
throw new IllegalArgumentException("培训计划不存在");
|
|
|
|
|
}
|
|
|
|
|
dto.setId(IdWorker.getId());
|
|
|
|
|
boolean result = service.save(dto);
|
|
|
|
|
return R.ok(result ? dto : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "修改")
|
|
|
|
|
@PostMapping("/update")
|
|
|
|
|
public R<PersonnelPlanLog> update(@Validated(Update.class) @RequestBody PersonnelPlanLog dto) {
|
|
|
|
|
if (dto.getStm().compareTo(dto.getEtm()) >= 0) {
|
|
|
|
|
throw new IllegalArgumentException("开始时间不能大于结束时间");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LambdaQueryChainWrapper<PersonnelPlanLog> query = service.lambdaQuery()
|
|
|
|
|
.ne(PersonnelPlanLog::getId, dto.getId())
|
|
|
|
|
.eq(PersonnelPlanLog::getPlanDate, dto. getPlanDate())
|
|
|
|
|
.eq(PersonnelPlanLog::getName, dto.getName());
|
|
|
|
|
if (query.count() > 0){
|
|
|
|
|
throw new IllegalArgumentException("当前培训日期标题名称重复");
|
|
|
|
|
}
|
|
|
|
|
if (planService.lambdaQuery().eq(PersonnelPlan::getId, dto.getPlanId()).count() == 0) {
|
|
|
|
|
throw new IllegalArgumentException("培训计划不存在");
|
|
|
|
|
}
|
|
|
|
|
boolean result = service.updateById(dto);
|
|
|
|
|
return R.ok(result ? dto : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除")
|
|
|
|
|
@GetMapping("/del/{id}")
|
|
|
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
|
|
|
return R.ok(service.removeById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "列表")
|
|
|
|
|
@PostMapping("/list")
|
|
|
|
|
public R<List<PersonnelPlanLog>> list() {
|
|
|
|
|
return R.ok(service.lambdaQuery()
|
|
|
|
|
.list());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "统计")
|
|
|
|
|
@GetMapping("/statistics/{year}")
|
|
|
|
|
public R<PersonnelPlanLogStatisticsVo> statistics(@PathVariable("year") Integer year) {
|
|
|
|
|
if (year < 1970 || year > LocalDate.now().getYear()) {
|
|
|
|
|
throw new IllegalArgumentException("年份不合法");
|
|
|
|
|
}
|
|
|
|
|
Date stm = DateUtil.convertStringToDate(year + "-01-01 00:00:00");
|
|
|
|
|
Date etm = DateUtil.convertStringToDate(year + "-12-31 23:59:59");
|
|
|
|
|
List<PersonnelPlanLog> planLogs = service.lambdaQuery()
|
|
|
|
|
.between(PersonnelPlanLog::getPlanDate, stm, etm)
|
|
|
|
|
.list();
|
|
|
|
|
List<PersonnelPlan> plans = planService.lambdaQuery()
|
|
|
|
|
.between(PersonnelPlan::getStm, stm, etm)
|
|
|
|
|
.list();
|
|
|
|
|
PersonnelPlanLogStatisticsVo vo = new PersonnelPlanLogStatisticsVo();
|
|
|
|
|
|
|
|
|
|
// 实际
|
|
|
|
|
Map<Integer, PersonnelPlanLogStatisticsVo.EchartsData> map1 = Maps.newHashMap();
|
|
|
|
|
|
|
|
|
|
// 计划
|
|
|
|
|
Map<Integer, PersonnelPlanLogStatisticsVo.EchartsData> map2 = Maps.newHashMap();
|
|
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(planLogs)) {
|
|
|
|
|
vo.setNumberOfPeriods1(planLogs.size());
|
|
|
|
|
vo.setPersonNum1(planLogs.stream().mapToInt(PersonnelPlanLog::getNumPeople).sum());
|
|
|
|
|
for (int i = 1; i <= 12; i++) {
|
|
|
|
|
PersonnelPlanLogStatisticsVo.EchartsData echartsData1 = map1.get(i);
|
|
|
|
|
PersonnelPlanLogStatisticsVo.EchartsData echartsData2 = map2.get(i);
|
|
|
|
|
|
|
|
|
|
if (Objects.isNull(echartsData1)) {
|
|
|
|
|
echartsData1 = new PersonnelPlanLogStatisticsVo.EchartsData();
|
|
|
|
|
}
|
|
|
|
|
int finalI = i;
|
|
|
|
|
List<PersonnelPlanLog> list = planLogs.stream()
|
|
|
|
|
.filter(item ->
|
|
|
|
|
{
|
|
|
|
|
calendar.setTime(item.getPlanDate());
|
|
|
|
|
return calendar.get(Calendar.MONTH) == finalI;
|
|
|
|
|
})
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
echartsData1.setMonth(finalI)
|
|
|
|
|
.setNum1(list.stream().mapToInt(PersonnelPlanLog::getNumPeople).sum());
|
|
|
|
|
map1.put(i, echartsData1);
|
|
|
|
|
|
|
|
|
|
echartsData2
|
|
|
|
|
.setMonth(finalI)
|
|
|
|
|
.setNum1(list.size());
|
|
|
|
|
map2.put(i, echartsData2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(plans)) {
|
|
|
|
|
vo.setNumberOfPeriods2(plans.stream().mapToInt(PersonnelPlan::getNum).sum());
|
|
|
|
|
vo.setPersonNum2(plans.stream().mapToInt(PersonnelPlan::getNumPeople).sum());
|
|
|
|
|
for (int i = 1; i <= 12; i++) {
|
|
|
|
|
PersonnelPlanLogStatisticsVo.EchartsData echartsData1 = map1.get(i);
|
|
|
|
|
if (Objects.isNull(echartsData1)) {
|
|
|
|
|
echartsData1 = new PersonnelPlanLogStatisticsVo.EchartsData();
|
|
|
|
|
}
|
|
|
|
|
PersonnelPlanLogStatisticsVo.EchartsData echartsData2 = map2.get(i);
|
|
|
|
|
if (Objects.isNull(echartsData2)) {
|
|
|
|
|
echartsData2 = new PersonnelPlanLogStatisticsVo.EchartsData();
|
|
|
|
|
}
|
|
|
|
|
int finalI = i;
|
|
|
|
|
List<PersonnelPlan> list = plans.stream()
|
|
|
|
|
.filter(item ->
|
|
|
|
|
{
|
|
|
|
|
calendar.setTime(item.getStm());
|
|
|
|
|
return calendar.get(Calendar.MONTH) == finalI;
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
|
|
echartsData1.setMonth(finalI)
|
|
|
|
|
.setNum2(list.stream().mapToInt(PersonnelPlan::getNumPeople).sum());
|
|
|
|
|
map1.put(i, echartsData1);
|
|
|
|
|
|
|
|
|
|
echartsData2
|
|
|
|
|
.setMonth(finalI)
|
|
|
|
|
.setNum2(list.size());
|
|
|
|
|
map2.put(i, echartsData2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vo.setList1(map1.values().stream().toList());
|
|
|
|
|
vo.setList2(map2.values().stream().toList());
|
|
|
|
|
|
|
|
|
|
return R.ok(vo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "分页")
|
|
|
|
|
@PostMapping("/page")
|
|
|
|
|
public R<Page<PersonnelPlanLog>> page(@RequestBody @Validated PersonnelPlanLogPage page) {
|
|
|
|
|
LambdaQueryChainWrapper<PersonnelPlanLog> query = service.lambdaQuery();
|
|
|
|
|
|
|
|
|
|
Date stm = page.getStm();
|
|
|
|
|
if (Objects.nonNull(stm)) {
|
|
|
|
|
query.ge(PersonnelPlanLog::getPlanDate, stm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Date etm = page.getEtm();
|
|
|
|
|
if (Objects.nonNull(etm)) {
|
|
|
|
|
query.le(PersonnelPlanLog::getPlanDate, etm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer type = page.getType();
|
|
|
|
|
if (Objects.nonNull(type)) {
|
|
|
|
|
query.eq(PersonnelPlanLog::getType, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String trainees = page.getTrainees();
|
|
|
|
|
if (StringUtils.isNotBlank(trainees)) {
|
|
|
|
|
query.like(PersonnelPlanLog::getName, trainees);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String unit = page.getUnit();
|
|
|
|
|
if (StringUtils.isNotBlank(unit)) {
|
|
|
|
|
query.like(PersonnelPlanLog::getApplicant, unit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return R.ok(service.page(page.getPageSo().toPage(), query));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|