maven
23 小时以前 d0a809ce7f0b729552f77cb32e22b506f8234b79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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());
    }
}