From 59e91a4e9ddaf23cebb12993c774aa899ab22d16 Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: Mon, 19 Jun 2023 14:22:45 +0800
Subject: [PATCH] 描述
---
src/main/java/com/gk/firework/Service/ServiceImpl/ControlPrintParamServiceImpl.java | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 155 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/gk/firework/Service/ServiceImpl/ControlPrintParamServiceImpl.java b/src/main/java/com/gk/firework/Service/ServiceImpl/ControlPrintParamServiceImpl.java
new file mode 100644
index 0000000..5f44c72
--- /dev/null
+++ b/src/main/java/com/gk/firework/Service/ServiceImpl/ControlPrintParamServiceImpl.java
@@ -0,0 +1,155 @@
+package com.gk.firework.Service.ServiceImpl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gk.firework.Domain.ControlPrintParam;
+import com.gk.firework.Domain.Exception.BusinessException;
+import com.gk.firework.Domain.UserInfo;
+import com.gk.firework.Domain.Utils.PageInfo;
+import com.gk.firework.Domain.Utils.StringUtils;
+import com.gk.firework.Mapper.ControlPrintParamMapper;
+import com.gk.firework.Service.ControlPrintParamService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class ControlPrintParamServiceImpl extends ServiceImpl<ControlPrintParamMapper, ControlPrintParam> implements ControlPrintParamService {
+ @Autowired
+ ControlPrintParamMapper controlPrintParamMapper;
+
+ private static final String defaultSettingsOwner = "admin";
+ //内包装设置
+ private static final byte inner = 1;
+ //外包装设置
+ private static final byte outer = 2;
+
+ @Override
+ public ControlPrintParam getParamsByUser(UserInfo userInfo, byte type) {
+ LambdaQueryWrapper<ControlPrintParam> wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(ControlPrintParam::getOwner,userInfo.getUsername());
+ wrapper.eq(ControlPrintParam::getType,type);
+ ControlPrintParam controlPrintParam = baseMapper.selectOne(wrapper);
+ if (controlPrintParam == null){
+ wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(ControlPrintParam::getOwner,"admin");
+ wrapper.eq(ControlPrintParam::getType,type);
+ }
+ return baseMapper.selectOne(wrapper);
+ }
+
+ @Override
+ public void selectDataGrid(PageInfo pageInfo) {
+ Page<ControlPrintParam> page = new Page<>(pageInfo.getPageIndex(), pageInfo.getPageSize());
+ List<OrderItem> orderItems = new ArrayList<>();
+ OrderItem orderItem = new OrderItem();
+ if (StringUtils.isNotBlank(pageInfo.getSort()) && StringUtils.isNotBlank(pageInfo.getOrder())) {
+ orderItem.setAsc(pageInfo.getOrder().equalsIgnoreCase("ascending"));
+ orderItem.setColumn(pageInfo.getSort());
+ }else {
+ orderItem.setAsc(false);
+ orderItem.setColumn("id");
+ }
+ orderItems.add(orderItem);
+ page.setOrders(orderItems);
+ List<ControlPrintParam> res = controlPrintParamMapper.selectDataGrid(page,pageInfo.getCondition());
+ //没有配置就返回默认配置
+ List<ControlPrintParam> settings = new ArrayList<>(res);
+ boolean flag = pageInfo.getCondition().get("enterprisename") == null &&
+ pageInfo.getCondition().get("type") == null;
+ //默认内包装
+ if (flag && settings.stream().filter(item -> item.getType() == inner).count() < 1) {
+ settings.addAll(this.selectDefaultSettings(inner,defaultSettingsOwner));
+ page.setTotal(page.getTotal() + 1);
+ }
+ //默认外包装
+ if (flag && settings.stream().filter(item -> item.getType() == outer).count() < 1) {
+ settings.addAll(this.selectDefaultSettings(outer,defaultSettingsOwner));
+ page.setTotal(page.getTotal() + 1);
+ }
+ pageInfo.setResult(settings);
+ pageInfo.setTotalCount(page.getTotal());
+ }
+
+ /**
+ * @Description: 获取内外包装默认设置,owner为admin
+ * @param type 类型 null 查询所有
+ * @date 2022/2/9 16:32
+ */
+ @Override
+ public List<ControlPrintParam> selectDefaultSettings(Byte type,String owner) {
+ return controlPrintParamMapper.selectList(
+ new LambdaQueryWrapper<ControlPrintParam>()
+ .eq(ControlPrintParam::getOwner, owner)
+ .eq(ControlPrintParam::getType,type));
+ }
+
+ /**
+ * @Description: 查找自己的type方案
+ * @date 2022/2/11 14:02
+ */
+ @Override
+ public ControlPrintParam getOwnSelectType(Byte type, UserInfo user) {
+ if (type == null) throw new BusinessException("参数不能为空");
+ List<ControlPrintParam> ownType = this.selectDefaultSettings(type, user.getUsername());
+ if (ownType.size() > 1) throw new BusinessException("配置重复,请检查数据");
+ //没有配置返回默认配置
+ ControlPrintParam param = new ControlPrintParam();
+ param.setType(type);
+ if (ownType.size() == 0) {
+ List<ControlPrintParam> defaultSettings = this.selectDefaultSettings(type, defaultSettingsOwner);
+ if (defaultSettings.size() > 0) param = defaultSettings.get(0);
+ }
+ if (ownType.size() == 1) {
+ param = ownType.get(0);
+ }
+
+ return param;
+
+ }
+
+
+ /**
+ * @Description: 新增配置方案
+ * @date 2022/2/11 16:17
+ */
+ @Override
+ public void addOrUpdateControlParams(ControlPrintParam controlPrintParam,UserInfo userInfo) {
+
+ Long id = controlPrintParam.getId();
+ if (id == null) {
+ controlPrintParam.setOwner(userInfo.getUsername());
+ this.save(controlPrintParam);
+ } else{
+ if (userInfo.getUsername().equals(controlPrintParam.getOwner())) {
+ this.updateById(controlPrintParam);
+ }else{
+ if (userInfo.getType() != 1)
+ controlPrintParam.setOwner(userInfo.getUsername());
+ this.save(controlPrintParam);
+ }
+ }
+
+
+ }
+
+ /**
+ * @Description: 更新配置方案
+ * @date 2022/2/11 17:30
+ */
+ @Override
+ public void updateControlParams(ControlPrintParam controlPrintParam, UserInfo user) {
+
+ Long id = controlPrintParam.getId();
+ if (id == null) throw new BusinessException("参数不能为空");
+ controlPrintParam.setOwner(null);
+ controlPrintParam.setType(null);
+ this.updateById(controlPrintParam);
+ }
+
+}
--
Gitblit v1.9.2