| | |
| | | import com.ruoyi.lavorissue.pojo.LaborIssue; |
| | | import com.ruoyi.lavorissue.service.LavorIssueService; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | | import com.ruoyi.project.system.domain.SysDictData; |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.project.system.service.ISysDictDataService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author :yys |
| | |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | |
| | | @Autowired |
| | | private ISysDictDataService iSysDictDataService; |
| | | |
| | | @GetMapping("/listPage") |
| | | @Log(title = "劳保发放-分页查询", businessType = BusinessType.OTHER) |
| | | @ApiOperation("劳保发放-分页查询") |
| | |
| | | return AjaxResult.success(listPage); |
| | | } |
| | | |
| | | /** |
| | | * 根据 dictId 分组统计领用数量(num)总和 |
| | | * @param laborIssueList 原始数据列表 |
| | | * @return key: dictId, value: 该字典下的总领用数量 |
| | | */ |
| | | public Map<String, Long> statisticsByDictId(List<LaborIssueDto> laborIssueList) { |
| | | // 空值校验,避免空指针异常 |
| | | if (laborIssueList == null || laborIssueList.isEmpty()) { |
| | | return new HashMap<>(); // 低版本可用 new HashMap<>() |
| | | } |
| | | |
| | | // 核心分组统计逻辑 |
| | | return laborIssueList.stream() |
| | | // 过滤掉无效数据(dictId为空 或 num为空/小于0的情况) |
| | | .filter(dto -> dto.getDictId() != null && !dto.getDictId().isEmpty()) |
| | | .filter(dto -> dto.getNum() != null && dto.getNum() >= 0) |
| | | // 按 dictId 分组,累加 num 数量 |
| | | .collect(Collectors.groupingBy( |
| | | LaborIssueDto::getDictId, // 分组依据:dictId |
| | | Collectors.summingLong(LaborIssueDto::getNum) // 求和:num |
| | | )); |
| | | } |
| | | |
| | | @PostMapping("/add") |
| | | @Log(title = "劳保发放-添加", businessType = BusinessType.INSERT) |
| | | @ApiOperation("劳保发放-添加") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult add(@RequestBody LaborIssue laborIssue){ |
| | | SysDictData dictData = new SysDictData(); |
| | | dictData.setDictType("sys_lavor_issue"); |
| | | List<SysDictData> sysDictData = iSysDictDataService.selectDictDataList(dictData); |
| | | Map<String, Long> stringLongMap = statisticsByDictId(laborIssue.getLaborIssueList()); |
| | | // 判断库存是否充足 |
| | | for (SysDictData sysDictDatum : sysDictData) { |
| | | Long aLong = stringLongMap.get(sysDictDatum.getDictValue()); |
| | | if (aLong != null && aLong > sysDictDatum.getNum()) { |
| | | throw new RuntimeException("库存不足"); |
| | | } |
| | | } |
| | | for (LaborIssueDto issue : laborIssue.getLaborIssueList()) { |
| | | LaborIssue laborIssue1 = new LaborIssue(); |
| | | BeanUtils.copyProperties(laborIssue, laborIssue1); |
| | |
| | | |
| | | } |
| | | laborIssueService.save(laborIssue1); |
| | | // 减库存 |
| | | List<SysDictData> collect = sysDictData |
| | | .stream() |
| | | .filter(item -> item.getDictValue().equals(issue.getDictId())) |
| | | .collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(collect)){ |
| | | SysDictData sysDictData1 = collect.get(0); |
| | | sysDictData1.setNum(sysDictData1.getNum() - issue.getNum()); |
| | | iSysDictDataService.updateDictData(sysDictData1); |
| | | } |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | |
| | | return AjaxResult.success(statisticsLaborIssue); |
| | | } |
| | | |
| | | @ApiOperation("发放进度-总计") |
| | | @GetMapping("/progressTotal") |
| | | public AjaxResult progressTotal(LaborIssue laborIssue) throws Exception { |
| | | Map<String, Object> list = laborIssueService.progressTotal(laborIssue); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | @ApiOperation("领取进度占比") |
| | | @GetMapping("/progressPercent") |
| | | public AjaxResult progressPercent(LaborIssue laborIssue) throws Exception { |
| | | Map<String, Object> list = laborIssueService.progressPercent(laborIssue); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | @ApiOperation("进度分布") |
| | | @GetMapping("/progressDistribution") |
| | | public AjaxResult progressDistribution(LaborIssue laborIssue) throws Exception { |
| | | Map<String, Object> list = laborIssueService.progressDistribution(laborIssue); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |