mitao
2025-02-24 17bd0962b7caba32f35d29a1082e7c998342e65d
springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintFlowServiceImpl.java
@@ -1,10 +1,17 @@
package com.panzhihua.sangeshenbian.service.impl;
import com.panzhihua.sangeshenbian.model.entity.ComplaintFlow;
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.IComplaintFlowService;
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;
/**
 * <p>
@@ -15,6 +22,46 @@
 * @since 2025-02-22
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ComplaintFlowServiceImpl extends ServiceImpl<ComplaintFlowMapper, ComplaintFlow> 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<BcRegion>()
                    .eq(BcRegion::getRegionCode, complaint.getSuperiorId()));
            name = bcRegion.getRegionName();
        } else {
            // 处理未预期的账号等级
            throw new ServiceException("未知的账号等级");
        }
        return name;
    }
}