package com.panzhihua.sangeshenbian.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.sangeshenbian.enums.ReportTypeEnum;
import com.panzhihua.sangeshenbian.model.entity.*;
import com.panzhihua.sangeshenbian.dao.ComplaintFlowMapper;
import com.panzhihua.sangeshenbian.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
*
* 诉求流转记录表 服务实现类
*
*
* @author
* @since 2025-02-22
*/
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ComplaintFlowServiceImpl extends ServiceImpl implements IComplaintFlowService {
private final IComplaintService complaintService;
private final IBcRegionService bcRegionService;
private final IComStreetService comStreetService;
private final IComActService comActService;
@Override
public void createFlow(Long complaintId , Integer type, Long userId) {
Complaint complaint = complaintService.getById(complaintId);
Integer reportType = complaint.getReportType();
String name = getFlowName(reportType, complaint);
ComplaintFlow complaintFlow = new ComplaintFlow();
complaintFlow.setComplaintId(complaintId);
complaintFlow.setLevel(reportType);
complaintFlow.setName(name);
complaintFlow.setCreateTime(new Date(System.currentTimeMillis()));
complaintFlow.setType(type);
save(complaintFlow);
}
private String getFlowName(Integer reportType, Complaint complaint) {
String name;
if (reportType == ReportTypeEnum.COMMUNITY.getCode()) {
ComAct byId = comActService.getById(complaint.getSuperiorId());
name = byId.getName();
}else if (reportType == ReportTypeEnum.STREET.getCode()) {
ComStreet comStreet = comStreetService.getById(complaint.getSuperiorId());
name = comStreet.getName();
} else if (reportType == ReportTypeEnum.CITY.getCode() || reportType == ReportTypeEnum.DISTRICT.getCode()){
BcRegion bcRegion = bcRegionService.getOne(new LambdaQueryWrapper()
.eq(BcRegion::getRegionCode, complaint.getSuperiorId()));
name = bcRegion.getRegionName();
} else {
// 处理未预期的账号等级
throw new ServiceException("未知的账号等级");
}
return name;
}
}