|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
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.dto.HygieneTemplateDTO; |
|
|
|
|
import com.hnac.hzims.safeproduct.entity.HygieneTemplateDetailEntity; |
|
|
|
@ -8,15 +10,20 @@ import com.hnac.hzims.safeproduct.entity.HygieneTemplateEntity;
|
|
|
|
|
import com.hnac.hzims.safeproduct.mapper.HygieneTemplateMapper; |
|
|
|
|
import com.hnac.hzims.safeproduct.service.IHygieneTemplateDetailService; |
|
|
|
|
import com.hnac.hzims.safeproduct.service.IHygieneTemplateService; |
|
|
|
|
import com.hnac.hzims.safeproduct.utils.BaseUtil; |
|
|
|
|
import com.hnac.hzims.safeproduct.vo.HygieneTemplateDetailVO; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
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; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -30,6 +37,12 @@ public class HygieneTemplateServiceImpl extends ServiceImpl<HygieneTemplateMappe
|
|
|
|
|
@Autowired |
|
|
|
|
IHygieneTemplateDetailService hygieneTemplateDetailService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
HygieneTemplateMapper hygieneTemplateMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 新增卫生自查模板 |
|
|
|
|
*/ |
|
|
|
@ -37,19 +50,28 @@ public class HygieneTemplateServiceImpl extends ServiceImpl<HygieneTemplateMappe
|
|
|
|
|
@Override |
|
|
|
|
public boolean saveHygieneTemplate(HygieneTemplateDTO hygieneTemplateDTO) { |
|
|
|
|
String templateName = hygieneTemplateDTO.getTemplateName(); |
|
|
|
|
QueryWrapper<HygieneTemplateEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.lambda().eq(HygieneTemplateEntity::getTemplateName, templateName); |
|
|
|
|
List<HygieneTemplateEntity> list = this.list(queryWrapper); |
|
|
|
|
if (CollectionUtil.isNotEmpty(list)) { |
|
|
|
|
// 重名校验
|
|
|
|
|
HygieneTemplateEntity hygieneTemplate = getHygieneTemplateByName(templateName); |
|
|
|
|
if (hygieneTemplate != null) { |
|
|
|
|
throw new ServiceException("模板名不可重复"); |
|
|
|
|
} |
|
|
|
|
HygieneTemplateEntity hygieneTemplate = new HygieneTemplateEntity(); |
|
|
|
|
hygieneTemplate.setTemplateName(templateName); |
|
|
|
|
boolean saveTemplate = this.save(hygieneTemplate); |
|
|
|
|
// 新增模板
|
|
|
|
|
HygieneTemplateEntity hygieneTemplateEntity = new HygieneTemplateEntity(); |
|
|
|
|
hygieneTemplateEntity.setTemplateName(templateName); |
|
|
|
|
boolean saveTemplate = this.save(hygieneTemplateEntity); |
|
|
|
|
if (!saveTemplate) { |
|
|
|
|
throw new ServiceException("卫生自查模板新增失败"); |
|
|
|
|
} |
|
|
|
|
return hygieneTemplateDetailService.saveBatch(hygieneTemplateDTO.getTemplateDetailList()); |
|
|
|
|
// 新增模板详情
|
|
|
|
|
hygieneTemplate = getHygieneTemplateByName(templateName); |
|
|
|
|
List<HygieneTemplateDetailEntity> detailList = hygieneTemplateDTO.getTemplateDetailList(); |
|
|
|
|
for (HygieneTemplateDetailEntity detail : detailList) { |
|
|
|
|
detail.setTemplateId(hygieneTemplate.getId()); |
|
|
|
|
String[] scores = detail.getCheckItemScore().split(",|,"); |
|
|
|
|
// 校验检查项总成绩是否为标准总成绩
|
|
|
|
|
BaseUtil.getSumScore(scores, 100); |
|
|
|
|
} |
|
|
|
|
return hygieneTemplateDetailService.saveBatch(detailList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -60,21 +82,37 @@ public class HygieneTemplateServiceImpl extends ServiceImpl<HygieneTemplateMappe
|
|
|
|
|
public boolean updateHygieneTemplate(HygieneTemplateDTO hygieneTemplateDTO) { |
|
|
|
|
String templateName = hygieneTemplateDTO.getTemplateName(); |
|
|
|
|
Long templateId = hygieneTemplateDTO.getTemplateId(); |
|
|
|
|
// 重名校验
|
|
|
|
|
QueryWrapper<HygieneTemplateEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.lambda().eq(HygieneTemplateEntity::getTemplateName, templateName); |
|
|
|
|
queryWrapper.lambda().ne(HygieneTemplateEntity::getId, templateId); |
|
|
|
|
List<HygieneTemplateEntity> list = this.list(queryWrapper); |
|
|
|
|
if (CollectionUtil.isNotEmpty(list)) { |
|
|
|
|
HygieneTemplateEntity hygieneTemplate = this.getOne(queryWrapper); |
|
|
|
|
if (hygieneTemplate != null) { |
|
|
|
|
throw new ServiceException("模板名不可重复"); |
|
|
|
|
} |
|
|
|
|
HygieneTemplateEntity hygieneTemplate = new HygieneTemplateEntity(); |
|
|
|
|
hygieneTemplate.setId(templateId); |
|
|
|
|
hygieneTemplate.setTemplateName(templateName); |
|
|
|
|
boolean updateTemplate = this.updateById(hygieneTemplate); |
|
|
|
|
// 更新模板
|
|
|
|
|
HygieneTemplateEntity hygieneTemplateEntity = new HygieneTemplateEntity(); |
|
|
|
|
hygieneTemplateEntity.setId(templateId); |
|
|
|
|
hygieneTemplateEntity.setTemplateName(templateName); |
|
|
|
|
boolean updateTemplate = this.updateById(hygieneTemplateEntity); |
|
|
|
|
if (!updateTemplate) { |
|
|
|
|
throw new ServiceException("卫生自查模板修改失败"); |
|
|
|
|
throw new ServiceException("卫生自查模板更新失败"); |
|
|
|
|
} |
|
|
|
|
// 更新模板详情
|
|
|
|
|
// 删除旧的模板详情数据
|
|
|
|
|
boolean removeDetail = hygieneTemplateDetailService.removeReferenceDetail(templateId); |
|
|
|
|
if (!removeDetail) { |
|
|
|
|
throw new ServiceException("卫生自查模板详情数据删除失败"); |
|
|
|
|
} |
|
|
|
|
// 新增新的模板详情数据
|
|
|
|
|
hygieneTemplate = getHygieneTemplateByName(templateName); |
|
|
|
|
List<HygieneTemplateDetailEntity> detailList = hygieneTemplateDTO.getTemplateDetailList(); |
|
|
|
|
for (HygieneTemplateDetailEntity detail : detailList) { |
|
|
|
|
detail.setTemplateId(hygieneTemplate.getId()); |
|
|
|
|
String[] scores = detail.getCheckItemScore().split(",|,"); |
|
|
|
|
BaseUtil.getSumScore(scores, 100); |
|
|
|
|
} |
|
|
|
|
return hygieneTemplateDetailService.updateBatchById(hygieneTemplateDTO.getTemplateDetailList()); |
|
|
|
|
return hygieneTemplateDetailService.saveBatch(detailList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -104,4 +142,32 @@ public class HygieneTemplateServiceImpl extends ServiceImpl<HygieneTemplateMappe
|
|
|
|
|
hygieneTemplateDetailVO.setTemplateDetailList(details); |
|
|
|
|
return hygieneTemplateDetailVO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据模板名获取模板 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public HygieneTemplateEntity getHygieneTemplateByName(String name) { |
|
|
|
|
QueryWrapper<HygieneTemplateEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.lambda().eq(HygieneTemplateEntity::getTemplateName, name); |
|
|
|
|
return this.getOne(queryWrapper); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 卫生自查页面 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public IPage<HygieneTemplateEntity> getHygieneTemplatePage(Map<String, Object> param, Query query) { |
|
|
|
|
IPage<HygieneTemplateEntity> page = new Page<>(query.getCurrent(), query.getSize()); |
|
|
|
|
IPage<HygieneTemplateEntity> templatePage = hygieneTemplateMapper.getHygieneTemplatePage(page, param); |
|
|
|
|
List<HygieneTemplateEntity> 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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|