|
@@ -1,5 +1,7 @@
|
|
|
package com.sdtool.business.service.mall;
|
|
package com.sdtool.business.service.mall;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.dySweetFishPlugin.redis.RedisService;
|
|
import com.dySweetFishPlugin.redis.RedisService;
|
|
|
import com.dySweetFishPlugin.sql.TableIdService;
|
|
import com.dySweetFishPlugin.sql.TableIdService;
|
|
|
import com.dySweetFishPlugin.sql.dao.TunaService;
|
|
import com.dySweetFishPlugin.sql.dao.TunaService;
|
|
@@ -11,19 +13,18 @@ import com.sdtool.common.datas.RedisKeys;
|
|
|
import com.sdtool.common.entity.base.BaseEntity;
|
|
import com.sdtool.common.entity.base.BaseEntity;
|
|
|
import com.sdtool.common.entity.base.ProcessIdItem;
|
|
import com.sdtool.common.entity.base.ProcessIdItem;
|
|
|
import com.sdtool.common.entity.base.ProcessStringItem;
|
|
import com.sdtool.common.entity.base.ProcessStringItem;
|
|
|
-import com.sdtool.common.entity.design.DesignFont;
|
|
|
|
|
-import com.sdtool.common.entity.design.DesignTemplate;
|
|
|
|
|
-import com.sdtool.common.entity.design.DesignTemplateItem;
|
|
|
|
|
|
|
+import com.sdtool.common.entity.design.*;
|
|
|
|
|
+import com.sdtool.common.entity.design.fabric.FabricMain;
|
|
|
import com.sdtool.common.entity.site.ERPTokenUser;
|
|
import com.sdtool.common.entity.site.ERPTokenUser;
|
|
|
import com.sdtool.common.tool.ERPUtils;
|
|
import com.sdtool.common.tool.ERPUtils;
|
|
|
import com.sweetfish.convert.json.JsonConvert;
|
|
import com.sweetfish.convert.json.JsonConvert;
|
|
|
|
|
+import com.sweetfish.convert.json.JsonFactory;
|
|
|
import com.sweetfish.service.Local;
|
|
import com.sweetfish.service.Local;
|
|
|
import com.sweetfish.service.RetResult;
|
|
import com.sweetfish.service.RetResult;
|
|
|
import com.sweetfish.source.PageFlipper;
|
|
import com.sweetfish.source.PageFlipper;
|
|
|
import com.sweetfish.util.AnyValue;
|
|
import com.sweetfish.util.AnyValue;
|
|
|
import com.sweetfish.util.AutoLoad;
|
|
import com.sweetfish.util.AutoLoad;
|
|
|
import com.sweetfish.util.ResourceType;
|
|
import com.sweetfish.util.ResourceType;
|
|
|
-import org.apache.commons.compress.utils.Lists;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.rex.RMap;
|
|
import org.rex.RMap;
|
|
|
|
|
|
|
@@ -35,10 +36,7 @@ import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
|
import java.nio.file.StandardOpenOption;
|
|
import java.nio.file.StandardOpenOption;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
|
-import java.util.Comparator;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
@Local
|
|
@Local
|
|
|
@AutoLoad(false)
|
|
@AutoLoad(false)
|
|
@@ -60,6 +58,9 @@ public class DesignServiceImpl extends BaseService implements DesignService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private NoSqlKeysService keysService;
|
|
private NoSqlKeysService keysService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ JsonFactory jsonRootFactory;
|
|
|
|
|
+
|
|
|
@Resource(name = "APP_HOME")
|
|
@Resource(name = "APP_HOME")
|
|
|
private String appHome;
|
|
private String appHome;
|
|
|
|
|
|
|
@@ -67,6 +68,7 @@ public class DesignServiceImpl extends BaseService implements DesignService {
|
|
|
private String tokenKey;
|
|
private String tokenKey;
|
|
|
|
|
|
|
|
private String designContentRoot;
|
|
private String designContentRoot;
|
|
|
|
|
+ private String orderContentRoot;
|
|
|
|
|
|
|
|
private DesignDao designDao;
|
|
private DesignDao designDao;
|
|
|
|
|
|
|
@@ -75,6 +77,7 @@ public class DesignServiceImpl extends BaseService implements DesignService {
|
|
|
designDao = tunaService.generate(DesignDao.class);
|
|
designDao = tunaService.generate(DesignDao.class);
|
|
|
|
|
|
|
|
designContentRoot = appHome + File.separator + "conf" + File.separator + "designContent";
|
|
designContentRoot = appHome + File.separator + "conf" + File.separator + "designContent";
|
|
|
|
|
+ orderContentRoot = appHome + File.separator + "conf" + File.separator + "orderContent";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -133,6 +136,63 @@ public class DesignServiceImpl extends BaseService implements DesignService {
|
|
|
return RetResult.<DesignTemplate>successT().result(redisTemplate);
|
|
return RetResult.<DesignTemplate>successT().result(redisTemplate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取供编辑的设计模板,带参数
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param id
|
|
|
|
|
+ * @param params
|
|
|
|
|
+ * @param dataSourceId
|
|
|
|
|
+ * @param supplierCode
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public RetResult<DesignTemplate> getDesignTemplateEdit(long id, RMap params, String dataSourceId, long supplierCode) {
|
|
|
|
|
+ DesignTemplate redisTemplate = getRedisDocInfo(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_EDIT, supplierCode),
|
|
|
|
|
+ String.valueOf(id), DesignTemplate.class);
|
|
|
|
|
+
|
|
|
|
|
+ if (redisTemplate == null) return RetResult.<DesignTemplate>errorT().retinfo("模板id不正确");
|
|
|
|
|
+ else {
|
|
|
|
|
+ FabricMain fabricMain = jsonConvert.convertFrom(FabricMain.class, redisTemplate.getJsonContent());
|
|
|
|
|
+
|
|
|
|
|
+ //根据传入参数不同,查找替换
|
|
|
|
|
+ if (ERPUtils.mapContainKey(params, "backgroundWidth") &&
|
|
|
|
|
+ ERPUtils.mapContainKey(params, "backgroundHeight")) {
|
|
|
|
|
+ //传进来的默认都是mm,但是fabric记录的是px,需要转一下
|
|
|
|
|
+ double width = ERPUtils.mm2px(params.getDouble("backgroundWidth"));
|
|
|
|
|
+ double height = ERPUtils.mm2px(params.getDouble("backgroundHeight"));
|
|
|
|
|
+
|
|
|
|
|
+ fabricMain.setHeight(height * fabricMain.getZoom());
|
|
|
|
|
+ fabricMain.setWidth(width * fabricMain.getZoom());
|
|
|
|
|
+
|
|
|
|
|
+ fabricMain.getObjects().forEach(object -> {
|
|
|
|
|
+ if (object.get("id").equals("WorkSpaceDrawType")) {
|
|
|
|
|
+ //背景对象
|
|
|
|
|
+ object.put("height", height);
|
|
|
|
|
+ object.put("width", width);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ERPUtils.mapContainKey(params, "backgroundColor")) {
|
|
|
|
|
+ //格式 rgba(125,125,125,1)
|
|
|
|
|
+ String color = params.getString("backgroundColor");
|
|
|
|
|
+ fabricMain.getObjects().forEach(object -> {
|
|
|
|
|
+ if (object.get("id").equals("WorkSpaceDrawType")) {
|
|
|
|
|
+ //背景对象
|
|
|
|
|
+ object.put("color", color);
|
|
|
|
|
+ object.put("fill", color);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ fabricMain.getWorkSpace().setColor(color);
|
|
|
|
|
+ fabricMain.getWorkSpace().setFill(color);
|
|
|
|
|
+ }
|
|
|
|
|
+// redisTemplate.setJsonContent(jsonConvert.convertTo(fabricMain));
|
|
|
|
|
+ redisTemplate.setJsonContent(JSON.toJSONString(fabricMain, SerializerFeature.WriteMapNullValue));
|
|
|
|
|
+ return RetResult.<DesignTemplate>successT().result(redisTemplate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public RetResult<DesignTemplate> getDesignTemplateImposition(long id, String dataSourceId, long supplierCode) {
|
|
public RetResult<DesignTemplate> getDesignTemplateImposition(long id, String dataSourceId, long supplierCode) {
|
|
|
DesignTemplate redisTemplate = getRedisDocInfo(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_IMPOSITION, supplierCode),
|
|
DesignTemplate redisTemplate = getRedisDocInfo(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_IMPOSITION, supplierCode),
|
|
@@ -144,7 +204,11 @@ public class DesignServiceImpl extends BaseService implements DesignService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//todo 转换fabric的元素结构
|
|
//todo 转换fabric的元素结构
|
|
|
- private List<DesignTemplateItem> convertJsonObjectsToItems(String jsonObjects) {
|
|
|
|
|
|
|
+ private List<DesignTemplateItem> convertJsonObjectsToTemplateItems(String jsonObjects) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<DesignOrderItem> convertJsonObjectsToOrderItems(String jsonObjects) {
|
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -183,7 +247,7 @@ public class DesignServiceImpl extends BaseService implements DesignService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
redisService.hset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_EDIT, supplierCode), String.valueOf(template.getId()), template);
|
|
redisService.hset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_EDIT, supplierCode), String.valueOf(template.getId()), template);
|
|
|
- List<DesignTemplateItem> itemList = convertJsonObjectsToItems(template.getJsonContent());
|
|
|
|
|
|
|
+ List<DesignTemplateItem> itemList = convertJsonObjectsToTemplateItems(template.getJsonContent());
|
|
|
template.setJsonContent(fileName);
|
|
template.setJsonContent(fileName);
|
|
|
template.setItemList(itemList);
|
|
template.setItemList(itemList);
|
|
|
redisService.hset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_IMPOSITION, supplierCode), String.valueOf(template.getId()), template);
|
|
redisService.hset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_TEMPLATE_IMPOSITION, supplierCode), String.valueOf(template.getId()), template);
|
|
@@ -271,4 +335,60 @@ public class DesignServiceImpl extends BaseService implements DesignService {
|
|
|
|
|
|
|
|
return RetResult.<ProcessStringItem>successT().result(resultItem);
|
|
return RetResult.<ProcessStringItem>successT().result(resultItem);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private DesignOrder convertTemplateToOrder(DesignTemplate designTemplate) {
|
|
|
|
|
+ DesignOrder designOrder = new DesignOrder();
|
|
|
|
|
+ designOrder.setIdTemplate(designTemplate.getId());
|
|
|
|
|
+ designOrder.setOrderMame("[" + designTemplate.getTemplateName() + "]" + ERPUtils.parseTimeFormat(new Date(), "yyyyMMdd") + "设计订单");
|
|
|
|
|
+ designOrder.setProductIdentity(designTemplate.getProductIdentity());
|
|
|
|
|
+ designOrder.setJsonContent(designTemplate.getJsonContent());
|
|
|
|
|
+
|
|
|
|
|
+ return designOrder;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public RetResult<DesignOrder> newDesignOrder(DesignTemplate customerDesign, String dataSourceId, long supplierCode, ERPTokenUser currentUser) {
|
|
|
|
|
+ DesignOrder designOrder = convertTemplateToOrder(customerDesign);
|
|
|
|
|
+ designOrder.setId(tableIdService.getTableIdMulti("deDesignOrder.id", 1, dataSourceId, String.valueOf(supplierCode)));
|
|
|
|
|
+ DesignOrder.create(designOrder, currentUser.getId());
|
|
|
|
|
+
|
|
|
|
|
+ String fileName = orderContentRoot + File.separator + supplierCode +
|
|
|
|
|
+ File.separator + designOrder.getId() + ".txt";
|
|
|
|
|
+ Path path = Paths.get(fileName);
|
|
|
|
|
+
|
|
|
|
|
+ String writeContent = "";
|
|
|
|
|
+ if (StringUtils.isNotEmpty(designOrder.getJsonContent())) {
|
|
|
|
|
+ writeContent = designOrder.getJsonContent();
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!Files.exists(path.getParent())) {
|
|
|
|
|
+ Files.createDirectories(path.getParent());
|
|
|
|
|
+ }
|
|
|
|
|
+ Files.write(path,
|
|
|
|
|
+ Collections.singleton(new StringBuilder(writeContent)),
|
|
|
|
|
+ StandardCharsets.UTF_8,
|
|
|
|
|
+ StandardOpenOption.CREATE,
|
|
|
|
|
+ StandardOpenOption.WRITE,
|
|
|
|
|
+ StandardOpenOption.TRUNCATE_EXISTING);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ redisService.hset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_ORDER_EDIT, supplierCode), String.valueOf(designOrder.getId()), designOrder);
|
|
|
|
|
+ List<DesignOrderItem> itemList = convertJsonObjectsToOrderItems(designOrder.getJsonContent());
|
|
|
|
|
+ designOrder.setJsonContent(fileName);
|
|
|
|
|
+ designOrder.setItemList(itemList);
|
|
|
|
|
+ redisService.hset(keysService.getRedisKey(RedisKeys.KEY_DESIGNER_DESIGN_ORDER_IMPOSITION, supplierCode), String.valueOf(designOrder.getId()), designOrder);
|
|
|
|
|
+
|
|
|
|
|
+ //todo 生成pdf
|
|
|
|
|
+
|
|
|
|
|
+ designDao.addDesignTemplate(designOrder, designOrder.getItemList(), dataSourceId, supplierCode);
|
|
|
|
|
+
|
|
|
|
|
+ return RetResult.<DesignOrder>successT().result(designOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public RetResult<DesignOrder> updateDesignOrder(DesignOrder designOrder, String dataSourceId, long supplierCode, ERPTokenUser currentUser) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|