|
@@ -10,12 +10,10 @@ import com.abi.qms.platform.dto.res.ListQrVariableRes;
|
|
|
import com.abi.qms.platform.dto.res.PreviewQrVariableRes;
|
|
|
import com.abi.qms.platform.infrastructure.util.AssertUtil;
|
|
|
import com.abi.qms.platform.infrastructure.util.BuildCodeUtil;
|
|
|
-import com.abi.qms.platform.infrastructure.util.PageUtil;
|
|
|
import com.abi.qms.platform.service.QrVariableService;
|
|
|
import com.abi.task.common.api.exception.BusinessException;
|
|
|
import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -23,7 +21,6 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.regex.Pattern;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 码格式变量 Service业务层处理
|
|
@@ -34,94 +31,94 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class QrVariableServiceImpl implements QrVariableService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private QrVariableMapper qrVariableMapper;
|
|
|
-
|
|
|
- /**
|
|
|
- * 码格式变量查询分页
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ListQrVariableRes listQrVariable(ListQrVariableReq req) {
|
|
|
- // 拼接条件
|
|
|
- QueryWrapper<QrVariable> qrVariableQw = new QueryWrapper<>();
|
|
|
- qrVariableQw.eq("is_delete", 0);
|
|
|
- qrVariableQw.eq(req.getValid() != null, "valid", req.getValid());
|
|
|
- qrVariableQw.eq(req.getDataType() != null, "data_type", req.getDataType());
|
|
|
- qrVariableQw.eq(req.getParamType() != null, "param_type", req.getParamType());
|
|
|
- qrVariableQw.orderByAsc("sort_number");
|
|
|
-
|
|
|
- List<QrVariable> qrVariableList = qrVariableMapper.selectList(qrVariableQw);
|
|
|
-
|
|
|
- // 封装出参
|
|
|
- ListQrVariableRes res = new ListQrVariableRes();
|
|
|
- List<ListQrVariableRes.QrVariableBean> qrVariableBeanList = PojoConverterUtils.copyList(qrVariableList, ListQrVariableRes.QrVariableBean.class);
|
|
|
- res.setQrVariableBeanList(qrVariableBeanList);
|
|
|
-
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 码格式变量生成码预览
|
|
|
- */
|
|
|
- @Override
|
|
|
- public PreviewQrVariableRes previewQrVariable(PreviewQrVariableReq req) {
|
|
|
- //校验入参
|
|
|
- if(CollectionUtils.isEmpty(req.getIds())){
|
|
|
- throw new BusinessException("码格式入参id为空");
|
|
|
- }
|
|
|
- // 查询码格式变量
|
|
|
- QueryWrapper<QrVariable> qrVariableQw = new QueryWrapper<>();
|
|
|
- qrVariableQw.in("id",req.getIds());
|
|
|
- List<QrVariable> qrVariableList = qrVariableMapper.selectList(qrVariableQw);
|
|
|
- if(CollectionUtils.isEmpty(qrVariableList)){
|
|
|
- throw new BusinessException("码格式变量不存在");
|
|
|
- }
|
|
|
- if(qrVariableList.size()!=req.getIds().size()){
|
|
|
- throw new BusinessException("部分码格式变量不存在");
|
|
|
- }
|
|
|
-
|
|
|
- // 生成单个码
|
|
|
- StringBuffer codeSb = new StringBuffer();
|
|
|
- for(QrVariable qrVariable:qrVariableList){
|
|
|
- String tempCode = BuildCodeUtil.buildSingleCode(qrVariable.getBuildCodeClass(), null);
|
|
|
- codeSb.append(tempCode);
|
|
|
- }
|
|
|
- String code = codeSb.toString();
|
|
|
- PreviewQrVariableRes res = new PreviewQrVariableRes();
|
|
|
- res.setCode(code);
|
|
|
-
|
|
|
- // 位数
|
|
|
- res.setDigit(code.length());
|
|
|
-
|
|
|
- // 获得或计算理论不重复数量
|
|
|
- //TODO 先取一个看看
|
|
|
- QrVariable qrVariable = qrVariableList.get(0);
|
|
|
- String effectiveQuantity = qrVariable.getEffectiveQuantity();
|
|
|
- Long maxCount;
|
|
|
- Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
- boolean isDigit = pattern.matcher(effectiveQuantity).matches();
|
|
|
- if (isDigit) {
|
|
|
- maxCount = Long.parseLong(effectiveQuantity);
|
|
|
- } else {
|
|
|
- maxCount = BuildCodeUtil.getMaxCount(effectiveQuantity, null);
|
|
|
- }
|
|
|
- res.setMaxCount(maxCount);
|
|
|
-
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 码格式变量查询详情
|
|
|
- */
|
|
|
- @Override
|
|
|
- public GetQrVariableDetailRes getQrVariableDetail(GetQrVariableDetailReq req) {
|
|
|
- QueryWrapper<QrVariable> qrVariableQw = new QueryWrapper<>();
|
|
|
- qrVariableQw.eq(req.getId() != null, "id", req.getId());
|
|
|
- qrVariableQw.eq(StringUtils.isNotBlank(req.getParamName()), "param_name", req.getParamName());
|
|
|
-
|
|
|
- QrVariable qrVariable = qrVariableMapper.selectOne(qrVariableQw);
|
|
|
- AssertUtil.isNull(qrVariable, "码格式变量不存在");
|
|
|
-
|
|
|
- return PojoConverterUtils.copy(qrVariable, GetQrVariableDetailRes.class);
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private QrVariableMapper qrVariableMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码格式变量查询分页
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ListQrVariableRes listQrVariable(ListQrVariableReq req) {
|
|
|
+ // 拼接条件
|
|
|
+ QueryWrapper<QrVariable> qrVariableQw = new QueryWrapper<>();
|
|
|
+ qrVariableQw.eq("is_delete", 0);
|
|
|
+ qrVariableQw.eq(req.getValid() != null, "valid", req.getValid());
|
|
|
+ qrVariableQw.eq(req.getDataType() != null, "data_type", req.getDataType());
|
|
|
+ qrVariableQw.eq(req.getParamType() != null, "param_type", req.getParamType());
|
|
|
+ qrVariableQw.orderByAsc("sort_number");
|
|
|
+
|
|
|
+ List<QrVariable> qrVariableList = qrVariableMapper.selectList(qrVariableQw);
|
|
|
+
|
|
|
+ // 封装出参
|
|
|
+ ListQrVariableRes res = new ListQrVariableRes();
|
|
|
+ List<ListQrVariableRes.QrVariableBean> qrVariableBeanList = PojoConverterUtils.copyList(qrVariableList, ListQrVariableRes.QrVariableBean.class);
|
|
|
+ res.setQrVariableBeanList(qrVariableBeanList);
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码格式变量生成码预览
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PreviewQrVariableRes previewQrVariable(PreviewQrVariableReq req) {
|
|
|
+ //校验入参
|
|
|
+ if (CollectionUtils.isEmpty(req.getIds())) {
|
|
|
+ throw new BusinessException("码格式入参id为空");
|
|
|
+ }
|
|
|
+ // 查询码格式变量
|
|
|
+ QueryWrapper<QrVariable> qrVariableQw = new QueryWrapper<>();
|
|
|
+ qrVariableQw.in("id", req.getIds());
|
|
|
+ List<QrVariable> qrVariableList = qrVariableMapper.selectList(qrVariableQw);
|
|
|
+ if (CollectionUtils.isEmpty(qrVariableList)) {
|
|
|
+ throw new BusinessException("码格式变量不存在");
|
|
|
+ }
|
|
|
+ if (qrVariableList.size() != req.getIds().size()) {
|
|
|
+ throw new BusinessException("部分码格式变量不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成单个码
|
|
|
+ StringBuffer codeSb = new StringBuffer();
|
|
|
+ for (QrVariable qrVariable : qrVariableList) {
|
|
|
+ String tempCode = BuildCodeUtil.buildSingleCode(qrVariable.getBuildCodeClass(), null);
|
|
|
+ codeSb.append(tempCode).append(" ");
|
|
|
+ }
|
|
|
+ String code = codeSb.toString();
|
|
|
+ PreviewQrVariableRes res = new PreviewQrVariableRes();
|
|
|
+ res.setCode(code);
|
|
|
+
|
|
|
+ // 位数
|
|
|
+ res.setDigit(code.length());
|
|
|
+
|
|
|
+ // 获得或计算理论不重复数量
|
|
|
+ //TODO 先取一个看看
|
|
|
+ QrVariable qrVariable = qrVariableList.get(0);
|
|
|
+ String effectiveQuantity = qrVariable.getEffectiveQuantity();
|
|
|
+ Long maxCount;
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
+ boolean isDigit = pattern.matcher(effectiveQuantity).matches();
|
|
|
+ if (isDigit) {
|
|
|
+ maxCount = Long.parseLong(effectiveQuantity);
|
|
|
+ } else {
|
|
|
+ maxCount = BuildCodeUtil.getMaxCount(effectiveQuantity, null);
|
|
|
+ }
|
|
|
+ res.setMaxCount(maxCount);
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 码格式变量查询详情
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public GetQrVariableDetailRes getQrVariableDetail(GetQrVariableDetailReq req) {
|
|
|
+ QueryWrapper<QrVariable> qrVariableQw = new QueryWrapper<>();
|
|
|
+ qrVariableQw.eq(req.getId() != null, "id", req.getId());
|
|
|
+ qrVariableQw.eq(StringUtils.isNotBlank(req.getParamName()), "param_name", req.getParamName());
|
|
|
+
|
|
|
+ QrVariable qrVariable = qrVariableMapper.selectOne(qrVariableQw);
|
|
|
+ AssertUtil.isNull(qrVariable, "码格式变量不存在");
|
|
|
+
|
|
|
+ return PojoConverterUtils.copy(qrVariable, GetQrVariableDetailRes.class);
|
|
|
+ }
|
|
|
}
|