package com.doumee.service.business.impl; 
 | 
  
 | 
import com.doumee.biz.system.SystemDictDataBiz; 
 | 
import com.doumee.core.constants.ResponseStatus; 
 | 
import com.doumee.core.exception.BusinessException; 
 | 
import com.doumee.core.model.LoginUserInfo; 
 | 
import com.doumee.core.model.PageData; 
 | 
import com.doumee.core.model.PageWrap; 
 | 
import com.doumee.core.utils.Constants; 
 | 
import com.doumee.core.utils.DateUtil; 
 | 
import com.doumee.core.utils.Utils; 
 | 
import com.doumee.dao.business.YwProblemMapper; 
 | 
import com.doumee.dao.business.YwRoomMapper; 
 | 
import com.doumee.dao.business.model.*; 
 | 
import com.doumee.dao.system.MultifileMapper; 
 | 
import com.doumee.dao.system.model.Multifile; 
 | 
import com.doumee.dao.system.model.SystemUser; 
 | 
import com.doumee.service.business.YwProblemService; 
 | 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 
 | 
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 
 | 
import com.baomidou.mybatisplus.core.metadata.IPage; 
 | 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
 | 
import com.github.yulichang.wrapper.MPJLambdaWrapper; 
 | 
import org.apache.commons.lang3.StringUtils; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.stereotype.Service; 
 | 
import org.springframework.transaction.annotation.Transactional; 
 | 
import org.springframework.util.CollectionUtils; 
 | 
  
 | 
import java.util.*; 
 | 
  
 | 
/** 
 | 
 * 运维问题上报信息表Service实现 
 | 
 * @author 江蹄蹄 
 | 
 * @date 2025/01/06 11:05 
 | 
 */ 
 | 
@Service 
 | 
public class YwProblemServiceImpl implements YwProblemService { 
 | 
  
 | 
    @Autowired 
 | 
    private YwProblemMapper ywProblemMapper; 
 | 
  
 | 
    @Autowired 
 | 
    private YwRoomMapper ywRoomMapper; 
 | 
  
 | 
    @Autowired 
 | 
    private MultifileMapper multifileMapper; 
 | 
  
 | 
    @Autowired 
 | 
    private SystemDictDataBiz systemDictDataBiz; 
 | 
  
 | 
    @Override 
 | 
    @Transactional(rollbackFor = {Exception.class,BusinessException.class}) 
 | 
    public Integer create(YwProblem ywProblem) { 
 | 
        if(Objects.isNull(ywProblem) 
 | 
            || Objects.isNull(ywProblem.getSubmitDate()) 
 | 
            || StringUtils.isBlank(ywProblem.getContent()) 
 | 
            || StringUtils.isBlank(ywProblem.getPhone()) 
 | 
            || StringUtils.isBlank(ywProblem.getName()) 
 | 
        ){ 
 | 
            throw new BusinessException(ResponseStatus.BAD_REQUEST); 
 | 
        } 
 | 
        ywProblem.setCreateDate(new Date()); 
 | 
        ywProblem.setIsdeleted(Constants.ZERO); 
 | 
        ywProblem.setStatus(Constants.ZERO); 
 | 
        ywProblem.setDealStatus(Constants.ZERO); 
 | 
        ywProblemMapper.insert(ywProblem); 
 | 
  
 | 
        List<Multifile> fileList = new ArrayList<>(); 
 | 
        if(ywProblem.getFileList()!=null && ywProblem.getFileList().size()>0){ 
 | 
            for (int i = 0; i <  ywProblem.getFileList().size(); i++) { 
 | 
                Multifile multifile =  ywProblem.getFileList().get(i); 
 | 
                if(StringUtils.isBlank(multifile.getFileurl())){ 
 | 
                    continue; 
 | 
                } 
 | 
                multifile.setCreateDate(ywProblem.getCreateDate()); 
 | 
                multifile.setIsdeleted(Constants.ZERO); 
 | 
                multifile.setObjId(ywProblem.getId()); 
 | 
                multifile.setObjType(Constants.MultiFile.PROBLEM_FILE.getKey()); 
 | 
                multifile.setSortnum(i+1); 
 | 
                fileList.add(multifile); 
 | 
            } 
 | 
        } 
 | 
        if(fileList.size()>0){ 
 | 
            multifileMapper.insert(fileList); 
 | 
        } 
 | 
  
 | 
        return ywProblem.getId(); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public void deleteById(Integer id) { 
 | 
        ywProblemMapper.deleteById(id); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public void delete(YwProblem ywProblem) { 
 | 
        UpdateWrapper<YwProblem> deleteWrapper = new UpdateWrapper<>(ywProblem); 
 | 
        ywProblemMapper.delete(deleteWrapper); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public void deleteByIdInBatch(List<Integer> ids) { 
 | 
        if (CollectionUtils.isEmpty(ids)) { 
 | 
            return; 
 | 
        } 
 | 
        ywProblemMapper.deleteBatchIds(ids); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public void updateById(YwProblem ywProblem) { 
 | 
        ywProblemMapper.updateById(ywProblem); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public void updateByIdInBatch(List<YwProblem> ywProblems) { 
 | 
        if (CollectionUtils.isEmpty(ywProblems)) { 
 | 
            return; 
 | 
        } 
 | 
        for (YwProblem ywProblem: ywProblems) { 
 | 
            this.updateById(ywProblem); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public YwProblem findById(Integer id) { 
 | 
        return ywProblemMapper.selectById(id); 
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
    @Override 
 | 
    public YwProblem getDetail(Integer id) { 
 | 
        MPJLambdaWrapper<YwProblem> queryWrapper = new MPJLambdaWrapper<YwProblem>(); 
 | 
        queryWrapper.selectAll(YwProblem.class) 
 | 
                .selectAs(SystemUser::getRealname,YwProblem::getDealUserName) 
 | 
                .selectAs(Company::getName,YwProblem::getDealUserCompanyName) 
 | 
                .leftJoin(SystemUser.class,SystemUser::getId,YwProblem::getDealUserId) 
 | 
                .leftJoin(Company.class,Company::getId,SystemUser::getCompanyId) 
 | 
                .eq(YwProblem::getId,id) 
 | 
        ; 
 | 
        YwProblem ywProblem = ywProblemMapper.selectJoinOne(YwProblem.class,queryWrapper); 
 | 
        if(Objects.isNull(ywProblem)){ 
 | 
            throw new BusinessException(ResponseStatus.DATA_EMPTY); 
 | 
        } 
 | 
        List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda() 
 | 
                .eq(Multifile::getObjId, ywProblem.getId() ) 
 | 
                .in(Multifile::getObjType, Arrays.asList(new Integer[]{Constants.MultiFile.PROBLEM_FILE.getKey() })) 
 | 
                .eq(Multifile::getIsdeleted,Constants.ZERO)); 
 | 
        if(multifiles!=null){ 
 | 
            String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() 
 | 
                    +systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_PROBLEM).getCode(); 
 | 
            for(Multifile f : multifiles){ 
 | 
                if(StringUtils.isBlank(f.getFileurl())){ 
 | 
                    continue; 
 | 
                } 
 | 
                f.setFileurlFull(path+f.getFileurl()); 
 | 
            } 
 | 
            ywProblem.setFileList(multifiles); 
 | 
        } 
 | 
        return ywProblem; 
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
    @Override 
 | 
    @Transactional(rollbackFor = {Exception.class,BusinessException.class}) 
 | 
    public void editProblem(YwProblem ywProblem,YwWorkorderServiceImpl ywWorkorderService){ 
 | 
        if(Objects.isNull(ywProblem) 
 | 
            || Objects.isNull(ywProblem.getId()) 
 | 
            || Objects.isNull(ywProblem.getDealStatus()) 
 | 
            || !(Constants.equalsInteger(ywProblem.getDealStatus(),Constants.ONE)||Constants.equalsInteger(ywProblem.getDealStatus(),Constants.TWO)) 
 | 
            || (Constants.equalsInteger(ywProblem.getDealStatus(),Constants.TWO)&&StringUtils.isBlank(ywProblem.getDealInfo())) 
 | 
        ){ 
 | 
            throw new BusinessException(ResponseStatus.BAD_REQUEST); 
 | 
        } 
 | 
        LoginUserInfo loginUserInfo = ywProblem.getLoginUserInfo(); 
 | 
        //关闭问题 
 | 
        if(Constants.equalsInteger(ywProblem.getDealStatus(),Constants.TWO)){ 
 | 
            ywProblemMapper.update(new UpdateWrapper<YwProblem>().lambda() 
 | 
                    .set(YwProblem::getDealDate, DateUtil.getCurrDateTime()) 
 | 
                    .set(YwProblem::getDealInfo,ywProblem.getDealInfo()) 
 | 
                    .set(YwProblem::getDealType,Constants.ONE) 
 | 
                    .set(YwProblem::getDealStatus,ywProblem.getDealStatus()) 
 | 
                    .set(YwProblem::getDealUserId,loginUserInfo.getId()) 
 | 
                    .set(YwProblem::getEditor,loginUserInfo.getId()) 
 | 
                    .set(YwProblem::getEditDate, DateUtil.getCurrDateTime()) 
 | 
                    .eq(YwProblem::getId,ywProblem.getId()) 
 | 
            ); 
 | 
        }else{ 
 | 
            if(Objects.isNull(ywProblem.getWorkOrderAreaType()) 
 | 
                    ||Objects.isNull(ywProblem.getWorkOrderCateId()) 
 | 
                    ||StringUtils.isBlank(ywProblem.getWorkOrderContent()) 
 | 
            ){ 
 | 
                throw new BusinessException(ResponseStatus.BAD_REQUEST); 
 | 
            } 
 | 
            YwWorkorder ywWorkorder = new YwWorkorder(); 
 | 
            ywWorkorder.setAreaType(ywProblem.getWorkOrderAreaType()); 
 | 
            ywWorkorder.setCateId(ywProblem.getWorkOrderCateId()); 
 | 
            ywWorkorder.setContent(ywProblem.getWorkOrderContent()); 
 | 
            ywWorkorder.setRoomId(ywProblem.getWorkOrderRoomId()); 
 | 
            ywWorkorder.setFloorId(ywProblem.getWorkOrderFloorId()); 
 | 
            ywWorkorder.setGetDate(ywProblem.getWorkOrderGetDate()); 
 | 
            ywWorkorder.setOrigin(Constants.ONE); 
 | 
            ywWorkorder.setLoginUserInfo(loginUserInfo); 
 | 
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywProblem.getWorkOrderFileList())){ 
 | 
                ywWorkorder.setFileList(ywProblem.getWorkOrderFileList()); 
 | 
            } 
 | 
            Integer workOrderId = ywWorkorderService.create(ywWorkorder); 
 | 
            ywProblemMapper.update(new UpdateWrapper<YwProblem>().lambda() 
 | 
                    .set(YwProblem::getDealDate, DateUtil.getCurrDateTime()) 
 | 
                    .set(YwProblem::getDealInfo,ywProblem.getDealInfo()) 
 | 
                    .set(YwProblem::getDealType,Constants.ZERO) 
 | 
                    .set(YwProblem::getDealStatus,ywProblem.getDealStatus()) 
 | 
                    .set(YwProblem::getDealUserId,loginUserInfo.getId()) 
 | 
                    .set(YwProblem::getEditor,loginUserInfo.getId()) 
 | 
                    .set(YwProblem::getEditDate, DateUtil.getCurrDateTime()) 
 | 
                    .set(YwProblem::getWorkorderId,workOrderId) 
 | 
                    .eq(YwProblem::getId,ywProblem.getId()) 
 | 
            ); 
 | 
  
 | 
        } 
 | 
  
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
    @Override 
 | 
    public YwProblem findOne(YwProblem ywProblem) { 
 | 
        QueryWrapper<YwProblem> wrapper = new QueryWrapper<>(ywProblem); 
 | 
        return ywProblemMapper.selectOne(wrapper); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public List<YwProblem> findList(YwProblem ywProblem) { 
 | 
        QueryWrapper<YwProblem> wrapper = new QueryWrapper<>(ywProblem); 
 | 
        return ywProblemMapper.selectList(wrapper); 
 | 
    } 
 | 
   
 | 
    @Override 
 | 
    public PageData<YwProblem> findPage(PageWrap<YwProblem> pageWrap) { 
 | 
        IPage<YwProblem> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); 
 | 
        MPJLambdaWrapper<YwProblem> queryWrapper = new MPJLambdaWrapper<YwProblem>(); 
 | 
        Utils.MP.blankToNull(pageWrap.getModel()); 
 | 
        YwProblem model = pageWrap.getModel(); 
 | 
        queryWrapper.selectAll(YwProblem.class) 
 | 
                .selectAs(SystemUser::getRealname,YwProblem::getDealUserName) 
 | 
                .leftJoin(SystemUser.class,SystemUser::getId,YwProblem::getDealUserId) 
 | 
                .like(StringUtils.isNotBlank(model.getContent()),YwProblem::getContent,model.getContent()) 
 | 
                .ge(Objects.nonNull(model.getDealDateStart()),YwProblem::getDealDate, Utils.Date.getStart(model.getDealDateStart())) 
 | 
                .le(Objects.nonNull(model.getDealDateEnd()),YwProblem::getDealDate, Utils.Date.getEnd(model.getDealDateEnd())) 
 | 
                .eq(Objects.nonNull(model.getDealStatus()),YwProblem::getDealStatus,model.getDealStatus()) 
 | 
        ; 
 | 
        IPage iPage = ywProblemMapper.selectJoinPage(page,YwProblem.class,queryWrapper); 
 | 
        return PageData.from(iPage); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public long count(YwProblem ywProblem) { 
 | 
        QueryWrapper<YwProblem> wrapper = new QueryWrapper<>(ywProblem); 
 | 
        return ywProblemMapper.selectCount(wrapper); 
 | 
    } 
 | 
} 
 |