|
|
|
@ -1,10 +1,25 @@
|
|
|
|
|
package com.hnac.hzims.safeproduct.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.hnac.hzims.safeproduct.entity.CarCheckTemplateEntity; |
|
|
|
|
import com.hnac.hzims.safeproduct.dto.CarCheckTemplateDTO; |
|
|
|
|
import com.hnac.hzims.safeproduct.entity.*; |
|
|
|
|
import com.hnac.hzims.safeproduct.mapper.CarCheckTemplateMapper; |
|
|
|
|
import com.hnac.hzims.safeproduct.service.ICarCheckTemplateService; |
|
|
|
|
import com.hnac.hzims.safeproduct.vo.CarCheckTemplateDetailVO; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 车检模板服务实现类 |
|
|
|
@ -14,8 +29,133 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
@Service |
|
|
|
|
public class CarCheckTemplateServiceImpl extends ServiceImpl<CarCheckTemplateMapper, CarCheckTemplateEntity> implements ICarCheckTemplateService { |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ICarCheckTemplateDetailService carCheckTemplateDetailService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
CarCheckTemplateMapper carCheckTemplateMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 新增车检模板 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public boolean saveCarCheckTemplate() { |
|
|
|
|
return false; |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean saveCarCheckTemplate(CarCheckTemplateDTO dto) { |
|
|
|
|
String templateName = dto.getTemplateName(); |
|
|
|
|
// 重名校验
|
|
|
|
|
CarCheckTemplateEntity template = getCarCheckTemplateByName(templateName); |
|
|
|
|
if (template != null) { |
|
|
|
|
throw new ServiceException("模板名不可重复"); |
|
|
|
|
} |
|
|
|
|
// 新增车检模板
|
|
|
|
|
CarCheckTemplateEntity templateEntity = new CarCheckTemplateEntity(); |
|
|
|
|
templateEntity.setTemplateName(templateName); |
|
|
|
|
boolean saveTemplate = this.save(templateEntity); |
|
|
|
|
if (!saveTemplate) { |
|
|
|
|
throw new ServiceException("车检模板新增失败"); |
|
|
|
|
} |
|
|
|
|
// 新增模板详情
|
|
|
|
|
template = getCarCheckTemplateByName(templateName); |
|
|
|
|
List<CarCheckTemplateDetailEntity> details = dto.getDetailList(); |
|
|
|
|
for (CarCheckTemplateDetailEntity detail : details) { |
|
|
|
|
detail.setTemplateId(template.getId()); |
|
|
|
|
} |
|
|
|
|
return carCheckTemplateDetailService.saveBatch(details); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据名称获取车检模板 |
|
|
|
|
*/ |
|
|
|
|
public CarCheckTemplateEntity getCarCheckTemplateByName(String name) { |
|
|
|
|
QueryWrapper<CarCheckTemplateEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.lambda().eq(CarCheckTemplateEntity::getTemplateName, name); |
|
|
|
|
return this.getOne(queryWrapper); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 修改车检模板 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean updateCarCheckTemplate(CarCheckTemplateDTO dto) { |
|
|
|
|
String templateName = dto.getTemplateName(); |
|
|
|
|
Long templateId = dto.getId(); |
|
|
|
|
// 重名校验
|
|
|
|
|
QueryWrapper<CarCheckTemplateEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.lambda().eq(CarCheckTemplateEntity::getTemplateName, templateName); |
|
|
|
|
queryWrapper.lambda().ne(CarCheckTemplateEntity::getId, templateId); |
|
|
|
|
CarCheckTemplateEntity template = this.getOne(queryWrapper); |
|
|
|
|
if (template != null) { |
|
|
|
|
throw new ServiceException("模板名不可重复"); |
|
|
|
|
} |
|
|
|
|
// 更新模板
|
|
|
|
|
CarCheckTemplateEntity templateEntity = new CarCheckTemplateEntity(); |
|
|
|
|
templateEntity.setId(templateId); |
|
|
|
|
templateEntity.setTemplateName(templateName); |
|
|
|
|
boolean updateTemplate = this.updateById(templateEntity); |
|
|
|
|
if (!updateTemplate) { |
|
|
|
|
throw new ServiceException("车检模板更新失败"); |
|
|
|
|
} |
|
|
|
|
// 更新模板详情
|
|
|
|
|
// 删除旧的模板详情数据
|
|
|
|
|
boolean removeDetail = carCheckTemplateDetailService.removeReferenceDetail(templateId); |
|
|
|
|
if (!removeDetail) { |
|
|
|
|
throw new ServiceException("车检模板详情数据删除失败"); |
|
|
|
|
} |
|
|
|
|
// 新增新的模板详情数据
|
|
|
|
|
List<CarCheckTemplateDetailEntity> detailList = dto.getDetailList(); |
|
|
|
|
for (CarCheckTemplateDetailEntity detail : detailList) { |
|
|
|
|
detail.setTemplateId(templateId); |
|
|
|
|
} |
|
|
|
|
return carCheckTemplateDetailService.saveBatch(detailList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除车检模板 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean removeCarCheckTemplate(Long id) { |
|
|
|
|
boolean removeTemplate = this.removeById(id); |
|
|
|
|
if (!removeTemplate) { |
|
|
|
|
throw new ServiceException("车检模板删除失败"); |
|
|
|
|
} |
|
|
|
|
return carCheckTemplateDetailService.removeReferenceDetail(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 车检模板详情 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public CarCheckTemplateDetailVO getCarCheckTemplateDetail(Long id) { |
|
|
|
|
CarCheckTemplateEntity templateEntity = this.getById(id); |
|
|
|
|
CarCheckTemplateDetailVO vo = new CarCheckTemplateDetailVO(); |
|
|
|
|
vo.setId(templateEntity.getId()); |
|
|
|
|
vo.setTemplateName(templateEntity.getTemplateName()); |
|
|
|
|
List<CarCheckTemplateDetailEntity> list = carCheckTemplateDetailService.getReferenceDetail(id); |
|
|
|
|
vo.setTemplateDetailList(list); |
|
|
|
|
return vo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 车检分页 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public IPage<CarCheckTemplateEntity> getCarCheckTemplatePage(Query query, Map<String, Object> param) { |
|
|
|
|
IPage<CarCheckTemplateEntity> page = new Page<>(query.getCurrent(), query.getSize()); |
|
|
|
|
IPage<CarCheckTemplateEntity> templatePage = carCheckTemplateMapper.getCarCheckTemplatePage(page, param); |
|
|
|
|
List<CarCheckTemplateEntity> templateList = templatePage.getRecords(); |
|
|
|
|
// 获取机构名
|
|
|
|
|
templateList.forEach(template -> { |
|
|
|
|
R<String> deptName = sysClient.getDeptName(template.getCreateDept()); |
|
|
|
|
if (deptName.isSuccess()) { |
|
|
|
|
template.setCreateDeptName(deptName.getData()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
templatePage.setRecords(templateList); |
|
|
|
|
return templatePage; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|