161 lines
7.8 KiB
Plaintext
161 lines
7.8 KiB
Plaintext
package com.cmeim.template.service.impl;
|
|
|
|
import com.cmeim.common.core.exception.ServiceException;
|
|
import com.cmeim.common.core.utils.BeanUtil;
|
|
import com.cmeim.common.core.utils.DateUtil;
|
|
import com.cmeim.common.core.utils.SecurityUtils;
|
|
import com.cmeim.common.core.web.domain.RespondEnum;
|
|
import com.cmeim.common.core.web.page.PageVo;
|
|
import com.cmeim.template.api.dto.TpTemplateDto;
|
|
import com.cmeim.template.enums.DelFlagEnum;
|
|
import com.cmeim.template.po.TpFormBind;
|
|
import com.cmeim.template.po.TpTemplate;
|
|
import com.cmeim.template.po.TpWorkcenterBind;
|
|
import com.cmeim.template.repository.TpTemplateRepository;
|
|
import com.cmeim.template.repository.TpWorkcenterBindRepository;
|
|
import com.cmeim.template.service.TpWorkcenterBindService;
|
|
import com.cmeim.template.util.BeansTool;
|
|
import com.google.common.collect.Lists;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Root;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Service
|
|
public class TpWorkcenterBindImpl implements TpWorkcenterBindService {
|
|
@Autowired
|
|
private TpWorkcenterBindRepository tpWorkcenterBindRepository;
|
|
@Autowired
|
|
private TpTemplateRepository tpTemplateRepository;
|
|
|
|
|
|
@Override
|
|
public void add(List<TpWorkcenterBind> tpWorkcenterBindList) {
|
|
for (int i = 0; i < tpWorkcenterBindList.size(); i++) {
|
|
if (tpWorkcenterBindList.get(i).getWorkCenterId() == null) {
|
|
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "工作中心不能为空");
|
|
}
|
|
if (tpWorkcenterBindList.get(i).getTemplateId() == null) {
|
|
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "模板ID不能为空");
|
|
}
|
|
if (StringUtils.isBlank(tpWorkcenterBindList.get(i).getTemplateCode())) {
|
|
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "模板编码不能为空");
|
|
}
|
|
tpWorkcenterBindList.get(i).setDeleted(DelFlagEnum.NOT_DELETED.getCode());
|
|
tpWorkcenterBindList.get(i).setCreatedBy(SecurityUtils.getUsername());
|
|
tpWorkcenterBindList.get(i).setCreatedDt(DateUtil.getCurrentDate());
|
|
tpWorkcenterBindRepository.save(tpWorkcenterBindList.get(i));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void update(TpWorkcenterBind tpWorkcenterBind) {
|
|
if (tpWorkcenterBind.getId() == null) {
|
|
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "ID不能为空");
|
|
}
|
|
if (tpWorkcenterBind.getWorkCenterId() == null) {
|
|
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "工作中心不能为空");
|
|
}
|
|
if (tpWorkcenterBind.getTemplateCode() == null) {
|
|
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "模板编码不能为空");
|
|
}
|
|
tpWorkcenterBind.setUpdatedBy(SecurityUtils.getUsername());
|
|
tpWorkcenterBind.setUpdatedDt(DateUtil.getCurrentDate());
|
|
tpWorkcenterBindRepository.save(tpWorkcenterBind);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void delete(List<Long> tpWorkcenterBindIdList) {
|
|
for (int i = 0; i < tpWorkcenterBindIdList.size(); i++) {
|
|
if (tpWorkcenterBindIdList.get(i) == null) {
|
|
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "ID不能为空");
|
|
}
|
|
}
|
|
for (int i = 0; i < tpWorkcenterBindIdList.size(); i++) {
|
|
TpWorkcenterBind tpWorkcenterBind = new TpWorkcenterBind();
|
|
TpWorkcenterBind tpWorkcenterBindDatabase = tpWorkcenterBindRepository.findById(tpWorkcenterBindIdList.get(i)).get();
|
|
BeansTool.copyNotNullProperties(tpWorkcenterBindDatabase, tpWorkcenterBind);
|
|
tpWorkcenterBind.setDeleted(DelFlagEnum.DELETED.getCode());
|
|
tpWorkcenterBind.setUpdatedBy(SecurityUtils.getUsername());
|
|
tpWorkcenterBind.setUpdatedDt(DateUtil.getCurrentDate());
|
|
tpWorkcenterBindRepository.save(tpWorkcenterBind);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public PageVo list(PageVo pv, TpWorkcenterBind tpWorkcenterBind, Sort.Order[] orders) {
|
|
tpWorkcenterBind.setDeleted((DelFlagEnum.NOT_DELETED.getCode()));
|
|
PageRequest pageRequest = PageRequest.of(pv.getPageNo() - 1, pv.getPageSize(),
|
|
Sort.by(orders));
|
|
Page page = tpWorkcenterBindRepository.findAll(buildSpecification(tpWorkcenterBind), pageRequest);
|
|
List<TpFormBind> list = page.getContent();
|
|
pv.setRecordsTotal(page.getTotalElements());
|
|
pv.setData(list);
|
|
return pv;
|
|
}
|
|
|
|
private Specification buildSpecification(TpWorkcenterBind tpWorkcenterBind) {
|
|
|
|
Specification<TpWorkcenterBind> specification = new Specification<TpWorkcenterBind>() {
|
|
@Override
|
|
public Predicate toPredicate(Root<TpWorkcenterBind> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
|
List<Predicate> predicates = Lists.newArrayList();
|
|
if (tpWorkcenterBind.getDeleted() != null) {
|
|
predicates.add(cb.equal(root.get("deleted"), tpWorkcenterBind.getDeleted()));
|
|
}
|
|
if (tpWorkcenterBind.getId() != null) {
|
|
predicates.add(cb.equal(root.get("id"), tpWorkcenterBind.getId()));
|
|
}
|
|
if (tpWorkcenterBind.getTemplateId() != null) {
|
|
predicates.add(cb.equal(root.get("templateId"), tpWorkcenterBind.getTemplateId()));
|
|
}
|
|
if (tpWorkcenterBind.getWorkCenterId() != null) {
|
|
predicates.add(cb.equal(root.get("workCenterId"), tpWorkcenterBind.getWorkCenterId()));
|
|
}
|
|
if (StringUtils.isNotBlank(tpWorkcenterBind.getTemplateName())) {
|
|
predicates.add(cb.like(root.get("templateName").as(String.class), "%" + tpWorkcenterBind.getTemplateName() + "%"));
|
|
}
|
|
if (StringUtils.isNotBlank(tpWorkcenterBind.getTemplateCode())) {
|
|
predicates.add(cb.like(root.get("templateCode").as(String.class), "%" + tpWorkcenterBind.getTemplateCode() + "%"));
|
|
}
|
|
if (StringUtils.isNotBlank(tpWorkcenterBind.getWorkCenterName())) {
|
|
predicates.add(cb.like(root.get("workCenterName").as(String.class), "%" + tpWorkcenterBind.getWorkCenterName() + "%"));
|
|
}
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
}
|
|
};
|
|
return specification;
|
|
}
|
|
|
|
@Override
|
|
public List<TpTemplateDto> queryQualityTp(Long workCenterId) {
|
|
//返回数据
|
|
List<TpTemplateDto> tpTemplateDtoList = new ArrayList<>();
|
|
//查询模板
|
|
List<TpWorkcenterBind> tpWorkcenterBindList = tpWorkcenterBindRepository.findByWorkCenterId(workCenterId);
|
|
List<Long> templateList = new ArrayList<>();
|
|
for (TpWorkcenterBind tpWorkcenterBind : tpWorkcenterBindList) {
|
|
templateList.add(tpWorkcenterBind.getTemplateId());
|
|
}
|
|
Long[] templateArr = templateList.toArray(new Long[templateList.size()]);
|
|
//查询模板下的质量模板
|
|
List<TpTemplate> tpTemplates = tpTemplateRepository.findByTemplateTypeAndTemplateCategoryAndIdIn(5, 10, templateArr);
|
|
for (TpTemplate tpTemplate : tpTemplates) {
|
|
TpTemplateDto tpTemplateVo = BeanUtil.copyProperties(tpTemplate, TpTemplateDto.class);
|
|
tpTemplateDtoList.add(tpTemplateVo);
|
|
}
|
|
return tpTemplateDtoList;
|
|
}
|
|
}
|