|  |  |  | 
|---|
|  |  |  | package com.doumee.service.business.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.*; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.YwWorkorderDataDTO; | 
|---|
|  |  |  | import com.doumee.dao.business.model.*; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.YwWorkorderDataVO; | 
|---|
|  |  |  | import com.doumee.dao.system.MultifileMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.SystemUserMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.join.NoticesJoinMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.model.Multifile; | 
|---|
|  |  |  | import com.doumee.dao.system.model.Notices; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemUser; | 
|---|
|  |  |  | import com.doumee.service.business.YwWorkorderService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 运维工单信息表Service实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | private YwBuildingMapper ywBuildingMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwFloorMapper ywFloorMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NoticesJoinMapper noticesJoinMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | 
|---|
|  |  |  | update.setDispatchInfo(ywWorkorder.getDispatchInfo()); | 
|---|
|  |  |  | update.setDealUserId(ywWorkorder.getDealUserId()); | 
|---|
|  |  |  | ywWorkorderMapper.updateById(update); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //添加待办信息 | 
|---|
|  |  |  | Notices notices = new Notices(); | 
|---|
|  |  |  | notices.setCreateDate(new Date()); | 
|---|
|  |  |  | notices.setCreator(update.getEditor()); | 
|---|
|  |  |  | notices.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | notices.setParam1(DateUtil.formatDate(model.getCreateDate(),"yyyy-MM-dd")); | 
|---|
|  |  |  | notices.setTitle("工单待办"); | 
|---|
|  |  |  | notices.setObjId(update.getId()); | 
|---|
|  |  |  | notices.setObjType(Constants.TWO); | 
|---|
|  |  |  | notices.setType(notices.getObjType()); | 
|---|
|  |  |  | notices.setUserId(ywWorkorder.getDealUserId()); | 
|---|
|  |  |  | notices.setStatus(Constants.ZERO); | 
|---|
|  |  |  | //整理json数据 | 
|---|
|  |  |  | Map<String,Object> jsonMap = new HashMap<>(); | 
|---|
|  |  |  | jsonMap.put("key1", model.getBuildingName()+"/"+model.getFloorName()); | 
|---|
|  |  |  | jsonMap.put("key2", DateUtil.getFomartDate(model.getCreateDate(),"yyyy-MM-dd HH:mm:ss")); | 
|---|
|  |  |  | jsonMap.put("key3", Constants.equalsInteger(model.getAreaType(),Constants.ZERO)?"室内维修":"公共区域"); | 
|---|
|  |  |  | jsonMap.put("key4", model.getCategoryParentName()+"/"+model.getCategoryName()); | 
|---|
|  |  |  | notices.setParam2(JSONObject.toJSONString(jsonMap)); | 
|---|
|  |  |  | notices.setParam3(Constants.ZERO+""); | 
|---|
|  |  |  | noticesJoinMapper.insert(notices); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | dealLogBiz(model,Constants.YwLogType.WORKORDER_DISPATCH,ywWorkorder.getLoginUserInfo().getRealname(),user.getRealname());//记录新建日志 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | update.setDealDate(update.getEditDate()); | 
|---|
|  |  |  | update.setDealInfo(ywWorkorder.getDealInfo()); | 
|---|
|  |  |  | ywWorkorderMapper.updateById(update); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //标记待办已处理 | 
|---|
|  |  |  | noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() | 
|---|
|  |  |  | .set(Notices::getStatus,Constants.ONE) | 
|---|
|  |  |  | .set(Notices::getParam3,Constants.TWO) | 
|---|
|  |  |  | .eq(Notices::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(Notices::getObjType,Constants.TWO) | 
|---|
|  |  |  | .eq(Notices::getObjId,update.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Multifile> fileList = new ArrayList<>(); | 
|---|
|  |  |  | if(ywWorkorder.getDealFileList()!=null && ywWorkorder.getDealFileList().size()>0){ | 
|---|
|  |  |  | 
|---|
|  |  |  | MPJLambdaWrapper<YwWorkorder> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | queryWrapper.selectAll(YwWorkorder.class ) | 
|---|
|  |  |  | .selectAs(SystemUser::getRealname,YwWorkorder::getDealUserName) | 
|---|
|  |  |  | .selectAs(Company::getName,YwWorkorder::getDealUserCompany) | 
|---|
|  |  |  | .select("t3.realname",YwWorkorder::getCreatorName) | 
|---|
|  |  |  | .selectAs(Category::getName,YwWorkorder::getCategoryName) | 
|---|
|  |  |  | .select("t3.mobile",YwWorkorder::getCreatorMobile) | 
|---|
|  |  |  | .select("c.name",YwWorkorder::getCreatorCompany) | 
|---|
|  |  |  | .select("ct.name",YwWorkorder::getCategoryName) | 
|---|
|  |  |  | .select("ct1.name",YwWorkorder::getCategoryParentName) | 
|---|
|  |  |  | .selectAs(YwRoom::getName,YwWorkorder::getRoomName) | 
|---|
|  |  |  | .selectAs(YwRoom::getRoomNum,YwWorkorder::getRoomNum) | 
|---|
|  |  |  | .selectAs(YwFloor::getName,YwWorkorder::getFloorName) | 
|---|
|  |  |  | .selectAs(YwBuilding::getName,YwWorkorder::getBuildingName) | 
|---|
|  |  |  | .selectAs(YwProject::getName,YwWorkorder::getProjectName) | 
|---|
|  |  |  | .leftJoin(SystemUser.class,SystemUser::getId,YwWorkorder::getDealUserId) | 
|---|
|  |  |  | .leftJoin(Category.class,Category::getId,YwWorkorder::getCateId) | 
|---|
|  |  |  | .leftJoin(SystemUser.class,SystemUser::getId,YwWorkorder::getCreator) | 
|---|
|  |  |  | .leftJoin(Company.class,Company::getId,SystemUser::getCompanyId) | 
|---|
|  |  |  | .leftJoin(YwRoom.class,YwRoom::getId,YwWorkorder::getRoomId) | 
|---|
|  |  |  | .leftJoin(YwFloor.class,YwFloor::getId,YwWorkorder::getFloorId) | 
|---|
|  |  |  | .leftJoin(YwBuilding.class,YwBuilding::getId,YwWorkorder::getBuildingId) | 
|---|
|  |  |  | .leftJoin(YwProject.class,YwProject::getId,YwWorkorder::getProjectId) | 
|---|
|  |  |  | .leftJoin(" company c on c.id = t1.company_id  ") | 
|---|
|  |  |  | .leftJoin(" category ct on ct.id = t.cate_id  ") | 
|---|
|  |  |  | .leftJoin(" category ct1 on ct1.id = ct.PARENT_ID  ") | 
|---|
|  |  |  | .eq(YwWorkorder::getId,id); | 
|---|
|  |  |  | YwWorkorder model = ywWorkorderMapper.selectJoinOne(YwWorkorder.class,queryWrapper); | 
|---|
|  |  |  | initFiles(model);//读取附件信息 | 
|---|
|  |  |  | 
|---|
|  |  |  | .selectAs(YwRoom::getRoomNum,YwWorkorder::getRoomNum) | 
|---|
|  |  |  | .selectAs(YwFloor::getName,YwWorkorder::getFloorName) | 
|---|
|  |  |  | .selectAs(YwBuilding::getName,YwWorkorder::getBuildingName) | 
|---|
|  |  |  | .selectAs(YwProject::getName,YwWorkorder::getProjectName) | 
|---|
|  |  |  | .selectAs(YwProblem::getId,YwWorkorder::getProblemId) | 
|---|
|  |  |  | .leftJoin(SystemUser.class,SystemUser::getId,YwWorkorder::getDealUserId) | 
|---|
|  |  |  | .leftJoin(Category.class,Category::getId,YwWorkorder::getCateId) | 
|---|
|  |  |  | .leftJoin(SystemUser.class,SystemUser::getId,YwWorkorder::getCreator) | 
|---|
|  |  |  | .leftJoin(YwRoom.class,YwRoom::getId,YwWorkorder::getRoomId) | 
|---|
|  |  |  | .leftJoin(YwFloor.class,YwFloor::getId,YwWorkorder::getFloorId) | 
|---|
|  |  |  | .leftJoin(YwBuilding.class,YwBuilding::getId,YwWorkorder::getBuildingId); | 
|---|
|  |  |  | .leftJoin(YwBuilding.class,YwBuilding::getId,YwWorkorder::getBuildingId) | 
|---|
|  |  |  | .leftJoin(YwProject.class,YwProject::getId,YwBuilding::getProjectId) | 
|---|
|  |  |  | .leftJoin(YwProblem.class,YwProblem::getWorkorderId,YwWorkorder::getId) | 
|---|
|  |  |  | .apply(StringUtils.isNotBlank(pageWrap.getModel().getQueryStatus())," find_in_set(t.DEAL_STATUS ,'"+pageWrap.getModel().getQueryStatus()+"') "); | 
|---|
|  |  |  | pageWrap.getModel().setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | Utils.MP.blankToNull(pageWrap.getModel()); | 
|---|
|  |  |  | if (pageWrap.getModel().getId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getDispatchUserId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getDispatchUserId, pageWrap.getModel().getDispatchUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Objects.nonNull(pageWrap.getModel().getRoomName())){ | 
|---|
|  |  |  | queryWrapper.and(i->i.like(YwFloor::getName,pageWrap.getModel().getRoomName()).or() | 
|---|
|  |  |  | .like(YwRoom::getRoomNum,pageWrap.getModel().getRoomName()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreator() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getCreator, pageWrap.getModel().getCreator()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getOrigin() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getOrigin, pageWrap.getModel().getOrigin()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreateDate() != null) { | 
|---|
|  |  |  | queryWrapper.ge(YwWorkorder::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getRemark, pageWrap.getModel().getRemark()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getStatus() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getStatus, pageWrap.getModel().getStatus()); | 
|---|
|  |  |  | queryWrapper.eq(!Constants.equalsInteger(pageWrap.getModel().getStatus(),-1),YwWorkorder::getStatus, pageWrap.getModel().getStatus()); | 
|---|
|  |  |  | queryWrapper.in(Constants.equalsInteger(pageWrap.getModel().getStatus(),-1),YwWorkorder::getStatus, Constants.ZERO,Constants.ONE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getSortnum() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getSortnum, pageWrap.getModel().getSortnum()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getRoomId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getRoomId, pageWrap.getModel().getRoomId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getFloorId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getFloorId, pageWrap.getModel().getFloorId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getUserId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getUserId, pageWrap.getModel().getUserId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getDealStatus() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getDealStatus, pageWrap.getModel().getDealStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getDispatchUserId() != null) { | 
|---|
|  |  |  | queryWrapper.eq(YwWorkorder::getDispatchUserId, pageWrap.getModel().getDispatchUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getDispatchDate() != null) { | 
|---|
|  |  |  | queryWrapper.ge(YwWorkorder::getDispatchDate, Utils.Date.getStart(pageWrap.getModel().getDispatchDate())); | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.orderByAsc(sortData.getProperty()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(StringUtils.isNotBlank(pageWrap.getModel().getBuildingName())){ | 
|---|
|  |  |  | queryWrapper.and(rw ->{ | 
|---|
|  |  |  | rw.like(YwBuilding::getName,pageWrap.getModel().getBuildingName()).or() | 
|---|
|  |  |  | .like(YwRoom::getName,pageWrap.getModel().getBuildingName()); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | queryWrapper.ge(Objects.nonNull(pageWrap.getModel().getQueryStartTime()), YwWorkorder::getCreateDate, pageWrap.getModel().getQueryStartTime()) | 
|---|
|  |  |  | .le(Objects.nonNull(pageWrap.getModel().getQueryEndTime()), YwWorkorder::getCreateDate, pageWrap.getModel().getQueryEndTime()); | 
|---|
|  |  |  | queryWrapper.orderByDesc(YwContract::getCreateDate ); | 
|---|
|  |  |  | return PageData.from(ywWorkorderMapper.selectPage(page, queryWrapper)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PageData<YwWorkorder> result =   PageData.from(ywWorkorderMapper.selectPage(page, queryWrapper)); | 
|---|
|  |  |  | if(result!=null && result.getRecords()!=null){ | 
|---|
|  |  |  | for(YwWorkorder m : result.getRecords()){ | 
|---|
|  |  |  | if(Constants.equalsInteger(m.getAreaType(),Constants.ZERO)){ | 
|---|
|  |  |  | //0室内维修 | 
|---|
|  |  |  | m.setAreaNameInfo(StringUtils.defaultString(m.getBuildingName(),"")+"/"+StringUtils.defaultString(m.getRoomNum(),"")); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | m.setAreaNameInfo(StringUtils.defaultString(m.getBuildingName(),"")+"/"+StringUtils.defaultString(m.getFloorName(),"")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<YwWorkorder> wrapper = new QueryWrapper<>(ywWorkorder); | 
|---|
|  |  |  | return ywWorkorderMapper.selectCount(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public YwWorkorderDataVO getDataVO(YwWorkorderDataDTO dto){ | 
|---|
|  |  |  | YwWorkorderDataVO ywWorkorderDataVO = new YwWorkorderDataVO(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<YwWorkorder> list = ywWorkorderMapper.selectList(new QueryWrapper<YwWorkorder>().lambda() | 
|---|
|  |  |  | .eq(YwWorkorder::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(Constants.equalsInteger(dto.getQueryType(),Constants.ONE),YwWorkorder::getProjectId,dto.getQueryId()) | 
|---|
|  |  |  | .eq(Constants.equalsInteger(dto.getQueryType(),Constants.TWO),YwWorkorder::getFloorId,dto.getQueryId()) | 
|---|
|  |  |  | .eq(Constants.equalsInteger(dto.getQueryType(),Constants.THREE),YwWorkorder::getRoomId,dto.getQueryId())); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){ | 
|---|
|  |  |  | ywWorkorderDataVO.setAmount(list.size()); | 
|---|
|  |  |  | ywWorkorderDataVO.setMonthAmount(list.stream().filter(i-> DateUtil.formatDate(i.getCreateDate(),"yyyy-MM").equals(DateUtil.formatDate(new Date(),"yyyy-MM"))).collect(Collectors.toList()).size()); | 
|---|
|  |  |  | ywWorkorderDataVO.setWaitDealAmount(list.stream().filter(i-> Constants.equalsInteger(i.getDealStatus(),Constants.ONE)).collect(Collectors.toList()).size()); | 
|---|
|  |  |  | ywWorkorderDataVO.setWaitAssignAmount(list.stream().filter(i-> Constants.equalsInteger(i.getDealStatus(),Constants.ZERO)).collect(Collectors.toList()).size()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ywWorkorderDataVO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|