|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.apache.commons.collections4.CollectionUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class AllocationExtensionServiceImpl extends ServiceImpl<AllocationExtensionMapper, AllocationExtension> implements AllocationExtensionService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // private final All | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AllocationService allocationService; | 
|---|
|  |  |  | private final FileTableService fileTableService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public AllocationExtensionServiceImpl( FileTableService fileTableService) { | 
|---|
|  |  |  | this.fileTableService = fileTableService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public AllocationExtensionExt extOne(Integer id) { | 
|---|
|  |  |  | return this.baseMapper.extOne(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) { | 
|---|
|  |  |  | return this.baseMapper.extPage(allocationExtensionPageCond.getPage().convertPage(), allocationExtensionPageCond); | 
|---|
|  |  |  | List<Integer> unitList = allocationService.unitResult(); | 
|---|
|  |  |  | allocationExtensionPageCond.setUnitList(unitList); | 
|---|
|  |  |  | Integer codeId =  allocationService.unitAreaCode(); | 
|---|
|  |  |  | Page<AllocationExtensionPageExt> page =  this.baseMapper.extPage(allocationExtensionPageCond.getPage().convertPage(), allocationExtensionPageCond); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(page.getRecords())){ | 
|---|
|  |  |  | page.getRecords().forEach(it->{ | 
|---|
|  |  |  | if((CollectionUtils.isEmpty(unitList)&&codeId.equals(1))||codeId.equals(2)){ | 
|---|
|  |  |  | it.setIsApprove(1); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | it.setIsApprove(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return page; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|