package com.chinaztt.mes.plan.service.impl;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.chinaztt.mes.plan.entity.MoTestStandardParam;
|
import com.chinaztt.mes.plan.mapper.MoTestStandardParamMapper;
|
import com.chinaztt.mes.plan.service.MoTestStandardParamService;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.List;
|
import java.util.regex.Pattern;
|
|
/**
|
* 制造订单-检测标准参数
|
*
|
* @author cxf
|
* @date 2021-04-27 13:27:40
|
*/
|
@Service
|
@Transactional(rollbackFor = Exception.class)
|
@AllArgsConstructor
|
public class MoTestStandardParamServiceImpl extends ServiceImpl<MoTestStandardParamMapper, MoTestStandardParam> implements MoTestStandardParamService {
|
|
/**
|
* 保留小数(匹配#.00)
|
*/
|
private static final String MATH_FORMAT_PATTEN_STR = "^#.\\d0{0,9}";
|
private static final Pattern PATTEN_MIN_MATH_FORMAT = Pattern.compile(MATH_FORMAT_PATTEN_STR);
|
|
@Override
|
public boolean saveList(List<MoTestStandardParam> moTestStandardParamList) {
|
if (CollectionUtil.isNotEmpty(moTestStandardParamList)) {
|
// 先删除
|
baseMapper.delete(Wrappers.<MoTestStandardParam>lambdaQuery().eq(MoTestStandardParam::getMoTestStandardId, moTestStandardParamList.get(0).getMoTestStandardId()));
|
// 后更新/新增
|
moTestStandardParamList.stream().forEach(moTestStandardParam -> {
|
if (moTestStandardParam.getId() != null && moTestStandardParam.getId() != 0) {
|
if (StringUtils.isNotBlank(moTestStandardParam.getParameterFormat())) {
|
boolean matches = moTestStandardParam.getParameterFormat().matches(PATTEN_MIN_MATH_FORMAT.pattern());
|
if (!matches) {
|
throw new RuntimeException("参数格式错误");
|
}
|
}
|
baseMapper.activeById(moTestStandardParam.getId());
|
baseMapper.updateById(moTestStandardParam);
|
} else {
|
if (StringUtils.isNotBlank(moTestStandardParam.getParameterFormat())) {
|
boolean matches = moTestStandardParam.getParameterFormat().matches(PATTEN_MIN_MATH_FORMAT.pattern());
|
if (!matches) {
|
throw new RuntimeException("参数格式错误");
|
}
|
}
|
baseMapper.insert(moTestStandardParam);
|
}
|
});
|
}
|
return true;
|
}
|
}
|