|
|
|
@ -11,7 +11,6 @@ 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.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -38,28 +37,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("卫生自查模板新增失败"); |
|
|
|
|
} |
|
|
|
|
// 传模板id
|
|
|
|
|
HygieneTemplateEntity hygieneTemplateEntity = getHygieneTemplateByName(templateName); |
|
|
|
|
// 新增模板详情
|
|
|
|
|
hygieneTemplate = getHygieneTemplateByName(templateName); |
|
|
|
|
List<HygieneTemplateDetailEntity> detailList = hygieneTemplateDTO.getTemplateDetailList(); |
|
|
|
|
detailList.forEach(detail -> { |
|
|
|
|
detail.setTemplateId(hygieneTemplateEntity.getId()); |
|
|
|
|
for (HygieneTemplateDetailEntity detail : detailList) { |
|
|
|
|
detail.setTemplateId(hygieneTemplate.getId()); |
|
|
|
|
String[] scores = detail.getCheckItemScore().split(",|,"); |
|
|
|
|
// 校验检查项总成绩是否为标准总成绩
|
|
|
|
|
BaseUtil.getSumScore(scores, 100); |
|
|
|
|
}); |
|
|
|
|
return hygieneTemplateDetailService.saveBatch(hygieneTemplateDTO.getTemplateDetailList()); |
|
|
|
|
} |
|
|
|
|
return hygieneTemplateDetailService.saveBatch(detailList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -70,26 +69,33 @@ 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("卫生自查模板更新失败"); |
|
|
|
|
} |
|
|
|
|
// 更新模板详情
|
|
|
|
|
// 删除旧的模板详情数据
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|