package com.ruoyi.production.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.framework.web.domain.AjaxResult;
|
import com.ruoyi.production.dto.ProductionReportDto;
|
import com.ruoyi.production.dto.SalesLedgerWorkDto;
|
import com.ruoyi.production.mapper.SalesLedgerProductionAccountingMapper;
|
import com.ruoyi.production.mapper.SalesLedgerWorkMapper;
|
import com.ruoyi.production.pojo.SalesLedgerProductionAccounting;
|
import com.ruoyi.production.pojo.SalesLedgerWork;
|
import com.ruoyi.production.service.SalesLedgerProductionAccountingService;
|
import com.ruoyi.production.service.SalesLedgerWorkService;
|
import com.ruoyi.project.system.domain.SysUser;
|
import com.ruoyi.project.system.mapper.SysUserMapper;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.time.LocalDate;
|
import java.time.format.DateTimeFormatter;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author :yys
|
* @date : 2025/7/21 14:40
|
*/
|
@Service
|
@RequiredArgsConstructor
|
@Slf4j
|
public class SalesLedgerWorkServiceImpl extends ServiceImpl<SalesLedgerWorkMapper, SalesLedgerWork> implements SalesLedgerWorkService {
|
|
private final SalesLedgerWorkMapper salesLedgerWorkMapper;
|
|
private final SysUserMapper sysUserMapper;
|
|
private final SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
|
|
@Override
|
public IPage<SalesLedgerWorkDto> listPage(Page page, SalesLedgerWorkDto salesLedgerWorkDto) {
|
IPage<SalesLedgerWorkDto> iPage = salesLedgerWorkMapper.listPage(page, salesLedgerWorkDto);
|
return iPage;
|
}
|
|
@Override
|
public int productionReport(ProductionReportDto productionReportDto) {
|
SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(productionReportDto.getId());
|
SysUser sysUser = sysUserMapper.selectUserById(productionReportDto.getSchedulingUserId());
|
if (salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
|
if (salesLedgerWork.getStatus() == 3) throw new RuntimeException("报工已完成");
|
if (sysUser == null) throw new RuntimeException("生产人不存在");
|
salesLedgerWork.setFinishedNum(salesLedgerWork.getFinishedNum().add(productionReportDto.getFinishedNum()));
|
if(salesLedgerWork.getSchedulingNum().compareTo(salesLedgerWork.getFinishedNum()) <= 0){
|
salesLedgerWork.setStatus(3);
|
}else{
|
salesLedgerWork.setStatus(2);
|
}
|
salesLedgerWorkMapper.updateById(salesLedgerWork);
|
// 新增报工数据
|
SalesLedgerProductionAccounting.SalesLedgerProductionAccountingBuilder builder = SalesLedgerProductionAccounting.builder()
|
.salesLedgerWorkId(salesLedgerWork.getId())
|
.salesLedgerSchedulingId(salesLedgerWork.getSalesLedgerSchedulingId())
|
.salesLedgerId(salesLedgerWork.getSalesLedgerId())
|
.salesLedgerProductId(salesLedgerWork.getSalesLedgerProductId())
|
.schedulingUserId(sysUser.getUserId())
|
.schedulingUserName(sysUser.getNickName())
|
.finishedNum(productionReportDto.getFinishedNum())
|
.workHours(salesLedgerWork.getWorkHours())
|
.process(salesLedgerWork.getProcess())
|
.schedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
|
salesLedgerProductionAccountingMapper.insert(builder.build());
|
return 0;
|
}
|
|
@Override
|
public int productionReportUpdate(ProductionReportDto productionReportDto) {
|
SalesLedgerProductionAccounting salesLedgerProductionAccounting = salesLedgerProductionAccountingMapper.selectById(productionReportDto.getId());
|
if(salesLedgerProductionAccounting == null) throw new RuntimeException("报工数据不存在");
|
SysUser sysUser = sysUserMapper.selectUserById(productionReportDto.getSchedulingUserId());
|
if(sysUser == null) throw new RuntimeException("生产人不存在");
|
salesLedgerProductionAccounting.setFinishedNum(productionReportDto.getFinishedNum());
|
salesLedgerProductionAccounting.setSchedulingUserId(sysUser.getUserId());
|
salesLedgerProductionAccounting.setSchedulingUserName(sysUser.getNickName());
|
salesLedgerProductionAccounting.setSchedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
|
salesLedgerProductionAccountingMapper.updateById(salesLedgerProductionAccounting);
|
|
// 更新报工数据
|
SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(salesLedgerProductionAccounting.getSalesLedgerWorkId());
|
if(salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
|
salesLedgerWork.setFinishedNum(productionReportDto.getFinishedNum());
|
if(salesLedgerWork.getSchedulingNum().compareTo(salesLedgerWork.getFinishedNum()) <= 0){
|
salesLedgerWork.setStatus(3);
|
}else{
|
salesLedgerWork.setStatus(2);
|
}
|
salesLedgerWork.setSchedulingUserId(sysUser.getUserId());
|
salesLedgerWork.setSchedulingUserName(sysUser.getNickName());
|
salesLedgerWork.setSchedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
|
salesLedgerWorkMapper.updateById(salesLedgerWork);
|
return 0;
|
}
|
|
@Override
|
public List<ProductionReportDto> getList(Long id) {
|
SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(id);
|
if(salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
|
LambdaQueryWrapper<SalesLedgerProductionAccounting> salesLedgerProductionAccountingLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
salesLedgerProductionAccountingLambdaQueryWrapper.eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, id);
|
List<SalesLedgerProductionAccounting> salesLedgerProductionAccountingList = salesLedgerProductionAccountingMapper.selectList(salesLedgerProductionAccountingLambdaQueryWrapper);
|
if(CollectionUtils.isEmpty(salesLedgerProductionAccountingList)) throw new RuntimeException("没有生产记录数据");
|
return salesLedgerProductionAccountingList.stream().map(salesLedgerProductionAccounting -> {
|
ProductionReportDto productionReportDto = new ProductionReportDto();
|
BeanUtils.copyProperties(salesLedgerProductionAccounting, productionReportDto);
|
productionReportDto.setSchedulingDate(salesLedgerProductionAccounting.getSchedulingDate().format(DateTimeFormatter.ISO_LOCAL_DATE));
|
productionReportDto.setSchedulingNum(salesLedgerWork.getSchedulingNum());
|
return productionReportDto;
|
}).collect(Collectors.toList());
|
}
|
}
|