cjl
2023-09-27 b8fe4c7b5f4f03dcfadff95702a07040ab9a1b57
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
package com.moral.api.service.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.entity.Allocation;
import com.moral.api.entity.AllocationExtension;
import com.moral.api.exception.BusinessException;
import com.moral.api.mapper.AllocationExtensionMapper;
import com.moral.api.pojo.enums.AllocationExtensionApproveEnum;
import com.moral.api.pojo.enums.FileTableEnum;
import com.moral.api.pojo.ext.allocation.AllocationExt;
import com.moral.api.pojo.ext.allocationextension.AllocationExtensionExt;
import com.moral.api.pojo.ext.allocationextension.AllocationExtensionPageExt;
import com.moral.api.pojo.query.allocationextension.AllocationExtensionAddCond;
import com.moral.api.pojo.query.allocationextension.AllocationExtensionPageCond;
import com.moral.api.service.AllocationExtensionService;
import com.moral.api.service.AllocationService;
import com.moral.api.service.FileTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * <p>
 * 交办单延期 服务实现类
 * </p>
 * deyt template generate
 * @author JI
 * @since 2023-09-25
 */
@Service
public class AllocationExtensionServiceImpl extends ServiceImpl<AllocationExtensionMapper, AllocationExtension> implements AllocationExtensionService {
 
    @Autowired
    private AllocationService allocationService;
    private final FileTableService fileTableService;
 
    public AllocationExtensionServiceImpl( FileTableService fileTableService) {
        this.fileTableService = fileTableService;
    }
 
 
    @Override
    public AllocationExtensionExt extOne(Integer id) {
        AllocationExtensionExt extensionExt = this.baseMapper.extOne(id);
        AllocationExt extOne = allocationService.oneAllocation(extensionExt.getAllocationId());
        extensionExt.setAllocationNum(extOne.getAllocationNum())
                    .setEscalationTime(extOne.getEscalationTime())
                    .setPollutePosition(extOne.getPollutePosition())
                    .setUnitId(extOne.getUnitId())
                    .setPolluteType(extOne.getPolluteType())
                    .setChangeType(extOne.getChangeType())
                    .setChangeDay(extOne.getChangeDay())
                    .setEscalationName(extOne.getEscalationName())
                    .setInvestigationType(extOne.getInvestigationType())
                    .setProblemDescribe(extOne.getProblemDescribe())
                    .setEscalationUnitId(extOne.getEscalationUnitId());
        extensionExt.setFileBaseList(fileTableService.list(extensionExt.getAllocationId(), FileTableEnum.ALLOCATION_FOUNDATION.value));
        extensionExt.setFileList(fileTableService.list(id, FileTableEnum.ALLOCATION_EXTENSION.value));
        return extensionExt;
    }
 
 
 
    @Override
    public Page<AllocationExtensionPageExt> extPage(AllocationExtensionPageCond allocationExtensionPageCond) {
        List<Integer> unitList = allocationService.unitResult();
        allocationExtensionPageCond.setUnitList(unitList);
        return this.baseMapper.extPage(allocationExtensionPageCond.getPage().convertPage(), allocationExtensionPageCond);
    }
 
    @Override
    public boolean save(AllocationExtensionAddCond allocationExtensionAddCond) {
        return this.save(allocationExtensionAddCond.convert());
    }
 
    @Override
    @Transactional
    public boolean check(Integer id, Integer state) {
        AllocationExtensionExt extensionExt = this.baseMapper.extOne(id);
        if(!AllocationExtensionApproveEnum.APPLYING.value.equals(extensionExt.getState())){
            throw new BusinessException("审批中才能发起审批!");
        }
        AllocationExtension allocationExtension = new AllocationExtension();
        allocationExtension.setId(id);
        allocationExtension.setState(state);
        this.baseMapper.updateById(allocationExtension);
        if(AllocationExtensionApproveEnum.PASS.value.equals(state)){
            Allocation allocation = new Allocation();
            allocation.setAllocationId(extensionExt.getAllocationId());
            allocation.setChangeDay(extensionExt.getChangeDay()+extensionExt.getExtensionNum());
            allocationService.updateById(allocation);
        }
        return true;
    }
}