package com.newfiber.api.pc.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.newfiber.api.config.FileVisitProperty; import com.newfiber.api.core.utils.DateUtil; import com.newfiber.api.core.utils.UUIDPK; import com.newfiber.api.pc.dao.EventsManage.ComplainPicDao; import com.newfiber.api.pc.dao.EventsManage.ComplaintProcessMapper; import com.newfiber.api.pc.dao.EventsManage.ComplaintTaskMapper; import com.newfiber.api.pc.model.EventsManage.ComplainPic; import com.newfiber.api.pc.model.EventsManage.ComplaintProcessDto; import com.newfiber.api.pc.model.EventsManage.ComplaintTask; import com.newfiber.api.pc.model.EventsManage.ComplaintTaskDto; import com.newfiber.api.pc.service.ComplaintTaskService; import com.newfiber.api.pc.service.ComplaintUserStateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; @Service("complaintTaskService") public class ComplaintTaskServiceImpl extends ServiceImpl<ComplaintTaskMapper, ComplaintTask> implements ComplaintTaskService { @Autowired private ComplaintTaskMapper complaintTaskMapper; @Autowired private ComplaintProcessMapper complaintProcessMapper; @Autowired private ComplainPicDao complainPicDao; @Autowired private FileVisitProperty fileVisitProperty; @Autowired private ComplaintUserStateService complaintUserStateService; @Override public PageInfo<ComplaintTask> listForPage(String searchStr, Integer pageNo, Integer pageSize) { PageHelper.startPage(pageNo, pageSize); EntityWrapper<ComplaintTask> wapper = new EntityWrapper<>(); //name 模糊匹配的字段 wapper.like("name", searchStr); List<ComplaintTask> list = complaintTaskMapper.selectList(wapper); PageInfo<ComplaintTask> result = new PageInfo<>(); if (!list.isEmpty()) { result = new PageInfo<ComplaintTask>(list); } return result; } @Override public boolean submit(ComplaintTask complaintTask) { //todo 审核人未定 complaintTask.setLeaderNo("admin"); complaintTask.setLeaderName("管理员"); complaintTask.setState(1); complaintTask.setStateDesc("待分配"); //绑定图片 saveImg(complaintTask); //保存记录 Integer i = complaintTaskMapper.insert(complaintTask); //添加一个投诉的人的查看状态 和 审核人处理状态 complaintUserStateService.addOrUpdateUserState(complaintTask.getId(),complaintTask.getComplaintType(),complaintTask.getCreateUserName(),2); complaintUserStateService.addOrUpdateUserState(complaintTask.getId(),complaintTask.getComplaintType(),complaintTask.getLeaderNo(),1); return i > 0 ? true : false; } @Override public PageInfo<ComplaintTaskDto> appList(String userName, Integer type, Integer state, Integer pageNo, Integer pageSize) { PageInfo<ComplaintTaskDto> result = new PageInfo<>(); PageHelper.startPage(pageNo, pageSize); List<ComplaintTaskDto> list = complaintTaskMapper.wxTaskList(userName, type, state); if (!list.isEmpty()) { result = new PageInfo<>(list); } return result; } @Override public ComplaintTaskDto appDetail(String userName,Long taskId,String isApp) { ComplaintTaskDto dto = complaintTaskMapper.wxTaskDetail(userName,taskId); //组装流程和图片 if(dto!=null){ if(!StringUtils.isEmpty(isApp) && "1".equalsIgnoreCase(isApp)){ setProcessImgPath(dto,taskId,fileVisitProperty.getAppPic()); }else { setProcessImgPath(dto,taskId,fileVisitProperty.getWxPic()); } } return dto; } @Override public PageInfo<ComplaintTaskDto> pcList(String userName, Integer complaintType, Integer problemType, Integer level, Integer isVisit, Integer state, Integer pageNo, Integer pageSize) { PageInfo<ComplaintTaskDto> result = new PageInfo<>(); PageHelper.startPage(pageNo, pageSize); List<ComplaintTaskDto> list = complaintTaskMapper.pcTaskList(userName, complaintType, problemType,level,isVisit,state); if (!list.isEmpty()) { result = new PageInfo<>(list); } return result; } @Override public PageInfo<ComplaintTaskDto> unCompleteList(String userName, Integer complaintType, Integer problemType, Integer level, Integer isVisit, Integer state, Integer pageNo, Integer pageSize) { PageInfo<ComplaintTaskDto> result = new PageInfo<>(); PageHelper.startPage(pageNo, pageSize); List<ComplaintTaskDto> list = complaintTaskMapper.unCompleteList(userName, complaintType, problemType,level,isVisit,state); if (!list.isEmpty()) { result = new PageInfo<>(list); } return result; } @Override public ComplaintTaskDto pcDetail(String userName,Long taskId) { ComplaintTaskDto dto = complaintTaskMapper.wxTaskDetail(userName,taskId); //组装流程和图片 setProcessImgPath(dto,taskId,fileVisitProperty.getWebPic()); return dto; } @Override public Map<String, Object> getData(String userNo) { Date dayBegin = DateUtil.getDayBegin(); Date dayEnd = DateUtil.getDayEnd(); return complaintTaskMapper.getData(dayBegin,dayEnd); } /** * 组装图片 * @param dto * @param taskId */ public void setProcessImgPath(ComplaintTaskDto dto, Long taskId, String path){ if(dto!=null && dto.getPicNo()!=null){ List<ComplainPic> problemPics = dto.getComplainPics(); if(problemPics!=null){ saveAppImgPath(problemPics,path); } dto.setComplainPics(problemPics); } List<ComplaintProcessDto> process = new ArrayList<>(); process = complaintProcessMapper.selectListByTaskId(taskId); if(process!= null && process.size()>0){ for (ComplaintProcessDto processDto : process) { if(processDto!=null && processDto.getProcessPics()!=null && processDto.getProcessPics().size()>0){ List<ComplainPic> problemPics = processDto.getProcessPics(); saveAppImgPath(problemPics,path); } } dto.setComplainProcess(process); } } /** * 组装需要的图片 * @param problemPics */ private void saveAppImgPath(List<ComplainPic> problemPics,String path) { for (ComplainPic problemPic : problemPics) { if(!StringUtils.isEmpty(problemPic.getPicPath())){ problemPic.setPicRealPath(path+problemPic.getPicPath()); } } } /** * 绑定巡查流程图片 * * @param complaintTask */ private void saveImg(ComplaintTask complaintTask) { if (complaintTask.getComplainPics() != null) { String picNo = UUIDPK.UUIDGenerator.getUUID(); complaintTask.setPicNo(picNo); List<ComplainPic> pic = complaintTask.getComplainPics(); //绑定图片 if (!pic.isEmpty()) { for (ComplainPic partolManagePic : pic) { partolManagePic.setEventsNo(picNo); partolManagePic.setPicType(complaintTask.getComplaintType()); partolManagePic.setPicTypeName(complaintTask.getComplaintName()); } complainPicDao.insertBatch(pic); } } } }