| | |
| | | package org.dromara.eims.service.impl; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import org.dromara.common.core.constant.DictConstants; |
| | | import org.dromara.common.core.service.RepairReqService; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.SpringUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.dromara.common.mybatis.core.page.PageQuery; |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.eims.domain.EimsEqu; |
| | | import org.dromara.eims.domain.EimsFixtureBorrow; |
| | | import org.dromara.eims.domain.EimsRepairRecord; |
| | | import org.dromara.eims.domain.vo.EimsFixtureVo; |
| | | import org.dromara.eims.domain.vo.EimsInventoryDetailVo; |
| | | import org.dromara.eims.mapper.EimsRepairRecordMapper; |
| | | import org.dromara.eims.utils.DataFilterUtil; |
| | | import org.dromara.system.domain.SysDept; |
| | | import org.dromara.system.domain.vo.SysDeptVo; |
| | | import org.dromara.system.mapper.SysDeptMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.dromara.eims.domain.bo.EimsRepairReqBo; |
| | | import org.dromara.eims.domain.vo.EimsRepairReqVo; |
| | | import org.dromara.eims.domain.EimsRepairReq; |
| | | import org.dromara.eims.mapper.EimsRepairReqMapper; |
| | | import org.dromara.eims.service.IEimsRepairReqService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Collection; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 故障报修Service业务层处理 |
| | |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | public class EimsRepairReqServiceImpl implements IEimsRepairReqService { |
| | | public class EimsRepairReqServiceImpl implements IEimsRepairReqService, RepairReqService { |
| | | |
| | | private final EimsRepairReqMapper baseMapper; |
| | | private final EimsRepairRecordMapper recordMapper; |
| | | private final SysDeptMapper sysDeptMapper; |
| | | |
| | | /** |
| | | * 查询故障报修 |
| | |
| | | * @return 故障报修 |
| | | */ |
| | | @Override |
| | | public EimsRepairReqVo queryById(Long id){ |
| | | public EimsRepairReqVo queryById(Long id) { |
| | | return baseMapper.selectVoById(id); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public TableDataInfo<EimsRepairReqVo> queryPageListCustom(EimsRepairReqBo bo, PageQuery pageQuery) { |
| | | //TODO |
| | | //DataFilterUtil.getInstance().filterRepairReq(bo); |
| | | Page<EimsRepairReqVo> page = baseMapper.selectRepairReqList(pageQuery.build(), buildWrapper(bo)); |
| | | return TableDataInfo.build(page); |
| | | } |
| | |
| | | private QueryWrapper<EimsRepairReq> buildWrapper(EimsRepairReqBo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | QueryWrapper<EimsRepairReq> qw = Wrappers.query(); |
| | | qw.eq(StringUtils.isNotBlank(bo.getCode()),"code", bo.getCode()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getStatus()), "status", bo.getStatus()); |
| | | qw.eq(bo.getReqTime() != null, "req_time", bo.getReqTime()); |
| | | qw.eq(bo.getReqDept() != null, "req_dept", bo.getReqDept()); |
| | | qw.eq(bo.getReqUser() != null,"req_user", bo.getReqUser()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getUrgencyLevel()), "urgency_level", bo.getUrgencyLevel()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getReqType()), "req_type", bo.getReqType()); |
| | | qw.eq(bo.getEquId() != null, "equ_id", bo.getEquId()); |
| | | qw.eq(bo.getRepairDept() != null,"repair_dept", bo.getRepairDept()); |
| | | qw.eq(bo.getRepairUser() != null, "repair_user", bo.getRepairUser()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getFaultType()), "fault_type", bo.getFaultType()); |
| | | qw.like(StringUtils.isNotBlank(bo.getCode()), "a.code", bo.getCode()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getStatus()), "a.status", bo.getStatus()); |
| | | qw.eq(bo.getReqTime() != null, "a.req_time", bo.getReqTime()); |
| | | qw.eq(bo.getReqUser() != null, "a.req_user", bo.getReqUser()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getUrgencyLevel()), "a.urgency_level", bo.getUrgencyLevel()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getReqType()), "a.req_type", bo.getReqType()); |
| | | qw.eq(bo.getEquId() != null, "a.equ_id", bo.getEquId()); |
| | | qw.eq(bo.getRepairDept() != null, "a.repair_dept", bo.getRepairDept()); |
| | | qw.eq(bo.getRepairUser() != null, "a.repair_user", bo.getRepairUser()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getFaultType()), "a,fault_type", bo.getFaultType()); |
| | | qw.in(params.containsKey("createBy"), "a.create_by", (List<Long>) params.get("createBy")); |
| | | Object status = params.get("status") == null ? "" : params.get("status"); |
| | | if (params.get("searchValue") != null && StringUtils.isNotBlank(params.get("searchValue").toString())) { |
| | | qw.and( wq ->wq.like("b.equ_name", params.get("searchValue")) |
| | | .or().like("b.asset_no", params.get("searchValue")) |
| | | ); |
| | | } |
| | | String[] split = status.toString().split(","); |
| | | qw.in(params.containsKey("status"), "a.status", split); |
| | | qw.between(params.get("beginReqTime") != null && params.get("endReqTime") != null, |
| | | "req_time", params.get("beginReqTime"), params.get("endReqTime")); |
| | | "a.req_time", params.get("beginReqTime"), params.get("endReqTime")); |
| | | qw.ne(StringUtils.isNotBlank(bo.getStatusLt()), "a.status", bo.getStatusLt()); |
| | | qw.eq(bo.getCreateBy()!=null, "a.create_by", bo.getCreateBy()); |
| | | qw.eq(StringUtils.isNotEmpty(bo.getStatus()), "a.status", bo.getStatus()); |
| | | qw.orderByDesc("a.create_time"); |
| | | |
| | | /** |
| | | * 查询部门下所有子部门 |
| | | */ |
| | | if (bo.getReqDept() != null) { |
| | | List<Long> allDescendantIds = getAllDescendantIds(bo.getReqDept()); |
| | | qw.in(bo.getReqDept() != null, "a.req_dept", allDescendantIds); |
| | | } |
| | | |
| | | return qw; |
| | | } |
| | | |
| | | /** |
| | | * 根据id,获取所有后代id |
| | | * |
| | | * @param rootId |
| | | * @return |
| | | */ |
| | | public List<Long> getAllDescendantIds(Long rootId) { |
| | | List<Long> result = new ArrayList<>(); |
| | | result.add(rootId); |
| | | collectDescendants(rootId, result); |
| | | return result; |
| | | } |
| | | |
| | | private void collectDescendants(Long currentId, List<Long> collector) { |
| | | QueryWrapper<SysDept> sysDeptWrapper = new QueryWrapper<>(); |
| | | sysDeptWrapper.lambda().eq(SysDept::getParentId, currentId); |
| | | |
| | | List<SysDeptVo> children = sysDeptMapper.selectVoList(sysDeptWrapper); |
| | | if (children != null && !children.isEmpty()) { |
| | | for (SysDeptVo child : children) { |
| | | Long childId = child.getDeptId(); |
| | | collector.add(childId); |
| | | collectDescendants(childId, collector); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询符合条件的故障报修列表 |
| | |
| | | lqw.eq(bo.getRepairDept() != null, EimsRepairReq::getRepairDept, bo.getRepairDept()); |
| | | lqw.eq(bo.getRepairUser() != null, EimsRepairReq::getRepairUser, bo.getRepairUser()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getFaultType()), EimsRepairReq::getFaultType, bo.getFaultType()); |
| | | // 按创建时间倒序 |
| | | lqw.orderByDesc(EimsRepairReq::getCreateTime); |
| | | return lqw; |
| | | } |
| | | |
| | |
| | | * @param bo 故障报修 |
| | | * @return 是否新增成功 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Boolean insertByBo(EimsRepairReqBo bo) { |
| | | EimsRepairReq add = MapstructUtils.convert(bo, EimsRepairReq.class); |
| | |
| | | boolean flag = baseMapper.insert(add) > 0; |
| | | if (flag) { |
| | | bo.setId(add.getId()); |
| | | //新增报修单时生成维修记录 |
| | | EimsRepairRecord record = new EimsRepairRecord(); |
| | | record.setReqId(add.getId()); |
| | | record.setHandleTime(new Date()); |
| | | //新增状态 |
| | | record.setOpera(DictConstants.REPAIR_RECORD_HANDLE_DETAIL.XINZENG); |
| | | record.setOperaUser(add.getCreateBy()); |
| | | record.setOperaResult("生成报修单"); |
| | | //新增时生成记录 |
| | | recordMapper.insert(record); |
| | | } |
| | | return flag; |
| | | } |
| | |
| | | /** |
| | | * 保存前的数据校验 |
| | | */ |
| | | private void validEntityBeforeSave(EimsRepairReq entity){ |
| | | private void validEntityBeforeSave(EimsRepairReq entity) { |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | if(isValid){ |
| | | if (isValid) { |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return baseMapper.deleteByIds(ids) > 0; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String selectRepairReqCodeByIds(String reqIds) { |
| | | List<String> list = new ArrayList<>(); |
| | | for (Long id : StringUtils.splitTo(reqIds, Convert::toLong)) { |
| | | EimsRepairReqVo vo = SpringUtils.getAopProxy(this).queryById(id); |
| | | if (ObjectUtil.isNotNull(vo)) { |
| | | list.add(vo.getCode()); |
| | | } |
| | | } |
| | | return String.join(StringUtils.SEPARATOR, list); |
| | | } |
| | | |
| | | } |