郑永安
2023-06-19 2fcd97552d16718cc7997629fd637a73a5a4483f
src/main/java/com/gk/firework/Service/ServiceImpl/SelfCheckReportServiceImpl.java
对比新文件
@@ -0,0 +1,191 @@
package com.gk.firework.Service.ServiceImpl;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.firework.Domain.Enterprise;
import com.gk.firework.Domain.SelfCheckReport;
import com.gk.firework.Domain.Utils.JsonUtils;
import com.gk.firework.Domain.Utils.PageInfo;
import com.gk.firework.Domain.Vo.SelfCheckReportSearchVo;
import com.gk.firework.Domain.Vo.SelfCheckReportVo;
import com.gk.firework.Mapper.EnterpriseMapper;
import com.gk.firework.Mapper.SelfCheckReportMapper;
import com.gk.firework.Service.EnterpriseService;
import com.gk.firework.Service.SelfCheckReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service("SelfCheckReportService")
public class SelfCheckReportServiceImpl extends ServiceImpl<SelfCheckReportMapper,SelfCheckReport> implements SelfCheckReportService {
    @Autowired
    SelfCheckReportMapper selfCheckReportMapper;
    @Autowired
    EnterpriseService enterpriseService;
    @Override
    public int createNewReport(SelfCheckReportVo reportVo) {
        if(checkVoForCreate(reportVo) == false){
            return 0;
        }
        SelfCheckReport selfCheckReport = null;
        Enterprise e = enterpriseService.getById(reportVo.getEid());
        if(e!= null){
            selfCheckReport = new SelfCheckReport();
            Date sysTime = new Date();
            selfCheckReport.setEid(e.getId());
            selfCheckReport.setEname(e.getEnterprisename());
            selfCheckReport.setChecktime(sysTime);
            selfCheckReport.setPrice(reportVo.getPrice());
            if(reportVo.getStatus()==1 || reportVo.getStatus()==2){
                selfCheckReport.setStatus(reportVo.getStatus());
            }
            else{
                selfCheckReport.setStatus((byte)1);
            }
            selfCheckReport.setYhdesc(reportVo.getYhdesc());
            selfCheckReport.setYhlevel(reportVo.getYhlevel());
            selfCheckReport.setSolution(reportVo.getSolution());
            selfCheckReport.setEndtime(reportVo.getEndtime());
            selfCheckReport.setChargeperson(reportVo.getChargeperson());
        }
        if(selfCheckReport!=null){
            return selfCheckReportMapper.insert(selfCheckReport);
        }else {
            return 0;
        }
    }
    @Override
    public SelfCheckReport getSelfCheckReportById(Long id) {
        return selfCheckReportMapper.selectByReportId(id);
    }
    @Override
    public int updateSelfCheckReport(SelfCheckReportVo reportVo) {
        SelfCheckReport report = selfCheckReportMapper.selectByReportId(reportVo.getId());
        if(report == null){
            return 0;
        }
        if(!report.getEid().equals(reportVo.getEid())){
            return 0;
        }
        if(report.getStatus() == 2){
            return 0;
        }
        if(report.getStatus() ==1 && reportVo.getStatus() == 2){
            report.setStatus((byte) 2);
        }
        if(!reportVo.getChargeperson().isEmpty()){
            report.setChargeperson(reportVo.getChargeperson());
        }
        if(!reportVo.getYhdesc().isEmpty()){
            report.setYhdesc(reportVo.getYhdesc());
        }
        if(reportVo.getEndtime() != null){
            report.setEndtime(reportVo.getEndtime());
        }
        if(!reportVo.getSolution().isEmpty()){
            report.setSolution(reportVo.getSolution());
        }
        if(reportVo.getYhlevel() == 1 || reportVo.getYhlevel() == 2){
            report.setYhlevel(reportVo.getYhlevel());
        }
        report.setPrice(reportVo.getPrice());
        return selfCheckReportMapper.updateReport(report);
    }
    @Override
    public List<SelfCheckReport> findSelfCheckReportList(Long enterpriseId, Byte status,Byte yhlevel) {
        return selfCheckReportMapper.selectReportListByCondition(enterpriseId,status,yhlevel);
    }
    @Override
    public List<SelfCheckReport> findSelfCheckReportListWithAllCondition(SelfCheckReportSearchVo searchVo) {
        //1、解析企业ID集合
        List<Long> eidList = null;
        //优先级别:1-指定企业ID,2-指定企业名称。3-指定省市区范围
        if(searchVo.getEid() != null && searchVo.getEid().longValue() > 0){
            if(enterpriseService.getById(searchVo.getEid())!=null){
                eidList = new ArrayList<>();
                eidList.add(searchVo.getEid());
            }else {
                return null;
            }
        }else if(searchVo.getEname() != null && !searchVo.getEname().isEmpty()){
            List<Enterprise> list = enterpriseService.selectEnterpriseListByNameLike(searchVo.getEname());
            if(list != null && list.size() >0){
                eidList = new ArrayList<>();
                for(Enterprise e : list){
                    eidList.add(e.getId());
                }
            }else {
                return null;
            }
        }else if(searchVo.getProvince()!=null && !searchVo.getProvince().isEmpty()){
            List<Enterprise> enterpriseList = enterpriseService.findEnterpriseListByLocation(searchVo.getProvince(),searchVo.getCity(),searchVo.getDistrict(),searchVo.getStreet(),searchVo.getCommittee());
            if(enterpriseList!=null){
                eidList = new ArrayList<>();
                for(Enterprise e : enterpriseList){
                    eidList.add(e.getId());
                }
            }
            if(eidList == null || eidList.size()<=0 ){
                return null;
            }
        }
        //2、设定分页参数
        if (searchVo.getPage()==null || searchVo.getPage() <=0){
            //未指定页数,默认第1页
            searchVo.setPage(1);
        }
        if(searchVo.getPageSize() == null || searchVo.getPageSize() <= 0){
            //未指定页大小,默认20条
            searchVo.setPageSize(20);
        }
        Page<SelfCheckReport> page = new Page<>(searchVo.getPage(),searchVo.getPageSize());
        List<OrderItem> orderItems = new ArrayList<>();
        OrderItem orderItem = new OrderItem();
        orderItem.setAsc(false);
        orderItem.setColumn("id");
        orderItems.add(orderItem);
        page.setOrders(orderItems);
        //3、查找
        List<SelfCheckReport> list = null;
        list =  selfCheckReportMapper.selectReportListWithEnterpriseIdList(eidList,searchVo.getStatus(),searchVo.getYhlevel(),searchVo.getStartTime(),searchVo.getEndTime(),page);
        searchVo.setTotalCount(page.getTotal());
        return list;
    }
    /**
     * 新增隐患信息参数检查
     * @param reportVo
     * @return
     */
    private boolean checkVoForCreate(SelfCheckReportVo reportVo){
        if(reportVo.getStatus()<1 ||reportVo.getStatus()>2){
           return false;
        }
        if(reportVo.getYhlevel() <1 || reportVo.getYhlevel() >2){
           return false;
        }
        if(reportVo.getChargeperson().isEmpty() || reportVo.getYhdesc().isEmpty() || reportVo.getSolution().isEmpty()){
           return false;
        }
        if(reportVo.getPrice().intValue()<0){
            return false;
        }
        if(reportVo.getEndtime().before(new Date())){
            return false;
        }
        return true;
    }
}