数据同步
This commit is contained in:
@@ -32,7 +32,7 @@ public class CurProdGroup implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* id
|
* id
|
||||||
*/
|
*/
|
||||||
@Id(keyType = KeyType.Auto)
|
@Id(keyType = KeyType.None)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class CurShopProdSpec implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* id
|
* id
|
||||||
*/
|
*/
|
||||||
@Id(keyType = KeyType.Auto)
|
@Id(keyType = KeyType.None)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.czg.mergedata.cur.service.impl;
|
package com.czg.mergedata.cur.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.czg.mergedata.common.resp.CzgResult;
|
import com.czg.mergedata.common.resp.CzgResult;
|
||||||
import com.czg.mergedata.common.utils.PageUtils;
|
import com.czg.mergedata.common.utils.PageUtils;
|
||||||
@@ -41,7 +44,7 @@ public class CurProdGroupServiceImpl extends ServiceImpl<CurProdGroupMapper, Cur
|
|||||||
private OldProductGroupService oldProductGroupService;
|
private OldProductGroupService oldProductGroupService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
//@Transactional
|
||||||
public CzgResult<String> mergeData() {
|
public CzgResult<String> mergeData() {
|
||||||
getMapper().truncateTable();
|
getMapper().truncateTable();
|
||||||
curProdGroupRelationMapper.truncateTable();
|
curProdGroupRelationMapper.truncateTable();
|
||||||
@@ -61,37 +64,52 @@ public class CurProdGroupServiceImpl extends ServiceImpl<CurProdGroupMapper, Cur
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveProdGroup(List<OldProductGroup> oldProductGroupList) {
|
private void saveProdGroup(List<OldProductGroup> oldProductGroupList) {
|
||||||
List<CurProdGroup> curProdGroupList = new ArrayList<>();
|
for (OldProductGroup old : oldProductGroupList) {
|
||||||
List<CurProdGroupRelation> curProdGroupRelationList = new ArrayList<>();
|
Integer id = old.getId();
|
||||||
|
String name = old.getName();
|
||||||
for (OldProductGroup oldProductGroup : oldProductGroupList) {
|
Integer shopId = old.getShopId();
|
||||||
CurProdGroup curProdGroup = new CurProdGroup();
|
String pic = old.getPic();
|
||||||
|
Integer isShow = old.getIsShow();
|
||||||
curProdGroup.setId(Long.valueOf(oldProductGroup.getId()));
|
Integer sort = old.getSort();
|
||||||
curProdGroup.setName(oldProductGroup.getName());
|
String sortMode = old.getSortMode();
|
||||||
curProdGroup.setShopId(Long.valueOf(oldProductGroup.getId()));
|
String productIds = old.getProductIds();
|
||||||
curProdGroup.setPic(oldProductGroup.getPic());
|
Long createdAt = old.getCreatedAt();
|
||||||
curProdGroup.setStatus(oldProductGroup.getIsShow());
|
Long updatedAt = old.getUpdatedAt();
|
||||||
curProdGroup.setSort(oldProductGroup.getSort());
|
Integer useTime = old.getUseTime();
|
||||||
curProdGroup.setSortMode(oldProductGroup.getSortMode());
|
String saleStartTime = old.getSaleStartTime();
|
||||||
curProdGroup.setUseTime(oldProductGroup.getUseTime());
|
String saleEndTime = old.getSaleEndTime();
|
||||||
curProdGroup.setSaleStartTime(oldProductGroup.getSaleStartTime());
|
CurProdGroup cur = new CurProdGroup();
|
||||||
curProdGroup.setSaleEndTime(oldProductGroup.getSaleEndTime());
|
cur.setId(id.longValue());
|
||||||
curProdGroup.setCreateTime(DateUtil.toLocalDateTime(oldProductGroup.getCreatedAt() == null ? new Date() : new Date(oldProductGroup.getCreatedAt())));
|
cur.setName(name);
|
||||||
|
cur.setShopId(Long.valueOf(shopId));
|
||||||
curProdGroupList.add(curProdGroup);
|
cur.setPic(pic);
|
||||||
|
cur.setStatus(isShow);
|
||||||
List<Long> list = JSONArray.parseArray(oldProductGroup.getProductIds(), Long.class);
|
cur.setSort(sort);
|
||||||
|
cur.setSortMode(StrUtil.nullToDefault(sortMode, "0"));
|
||||||
|
cur.setUseTime(useTime);
|
||||||
|
if (StrUtil.isAllNotEmpty(saleStartTime, saleEndTime)) {
|
||||||
|
cur.setSaleStartTime(saleStartTime + ":00");
|
||||||
|
cur.setSaleEndTime(saleEndTime + ":59");
|
||||||
|
}
|
||||||
|
cur.setCreateTime(LocalDateTimeUtil.of(createdAt));
|
||||||
|
cur.setUpdateTime(LocalDateTimeUtil.of(updatedAt));
|
||||||
|
save(cur);
|
||||||
|
if (StrUtil.isEmpty(productIds)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<Long> list = JSONArray.parseArray(productIds, Long.class);
|
||||||
|
if (CollUtil.isEmpty(list)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int index = 0;
|
||||||
for (Long productId : list) {
|
for (Long productId : list) {
|
||||||
CurProdGroupRelation curProdGroupRelation = new CurProdGroupRelation();
|
index++;
|
||||||
curProdGroupRelation.setProductId(productId);
|
CurProdGroupRelation relation = new CurProdGroupRelation();
|
||||||
curProdGroupRelation.setProdGroupId(Long.valueOf(oldProductGroup.getId()));
|
relation.setProductId(productId);
|
||||||
curProdGroupRelation.setSort(1);
|
relation.setProdGroupId(cur.getId());
|
||||||
curProdGroupRelationList.add(curProdGroupRelation);
|
relation.setSort(index);
|
||||||
|
curProdGroupRelationService.save(relation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveBatch(curProdGroupList);
|
|
||||||
curProdGroupRelationService.saveBatch(curProdGroupRelationList);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.czg.mergedata.cur.service.impl;
|
package com.czg.mergedata.cur.service.impl;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.czg.mergedata.common.resp.CzgResult;
|
import com.czg.mergedata.common.resp.CzgResult;
|
||||||
@@ -29,13 +34,13 @@ import java.util.stream.Collectors;
|
|||||||
* @since 2025-02-17
|
* @since 2025-02-17
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class CurShopProdSpecServiceImpl extends ServiceImpl<CurShopProdSpecMapper, CurShopProdSpec> implements CurShopProdSpecService{
|
public class CurShopProdSpecServiceImpl extends ServiceImpl<CurShopProdSpecMapper, CurShopProdSpec> implements CurShopProdSpecService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private OldProductSpecService oldProductSpecService;
|
private OldProductSpecService oldProductSpecService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
//@Transactional
|
||||||
public CzgResult<String> mergeProductSpec() {
|
public CzgResult<String> mergeProductSpec() {
|
||||||
getMapper().truncateTable();
|
getMapper().truncateTable();
|
||||||
|
|
||||||
@@ -54,105 +59,71 @@ public class CurShopProdSpecServiceImpl extends ServiceImpl<CurShopProdSpecMappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveProdSpec(List<OldProductSpec> oldProductSpecs) {
|
private void saveProdSpec(List<OldProductSpec> oldProductSpecs) {
|
||||||
List<CurShopProdSpec> firstSpecs = new ArrayList<>();
|
|
||||||
|
|
||||||
// 保存一级规格
|
|
||||||
List<Long> parentIds = List.of(0L);
|
|
||||||
String pids = parentIds.stream()
|
|
||||||
.map(Object::toString)
|
|
||||||
.collect(Collectors.joining(",")) + ",";
|
|
||||||
for (OldProductSpec oldProductSpec : oldProductSpecs) {
|
for (OldProductSpec oldProductSpec : oldProductSpecs) {
|
||||||
CurShopProdSpec curShopProdSpec = new CurShopProdSpec();
|
Integer id = oldProductSpec.getId();
|
||||||
|
String shopId = oldProductSpec.getShopId();
|
||||||
|
String name = oldProductSpec.getName();
|
||||||
|
Integer sort = oldProductSpec.getSort();
|
||||||
|
Long createdAt = oldProductSpec.getCreatedAt();
|
||||||
|
Long updatedAt = oldProductSpec.getUpdatedAt();
|
||||||
|
CurShopProdSpec one = new CurShopProdSpec();
|
||||||
|
one.setId(id.longValue());
|
||||||
|
one.setName(name);
|
||||||
|
one.setFullName(name);
|
||||||
|
one.setLevel(1);
|
||||||
|
one.setSort(sort);
|
||||||
|
one.setPid(0L);
|
||||||
|
one.setPids("0,");
|
||||||
|
one.setShopId(Convert.toLong(shopId));
|
||||||
|
one.setStatus(1);
|
||||||
|
one.setCreateTime(LocalDateTimeUtil.of(createdAt));
|
||||||
|
one.setUpdateTime(LocalDateTimeUtil.of(updatedAt));
|
||||||
|
save(one);
|
||||||
|
|
||||||
Long curShopId = Long.valueOf(oldProductSpec.getShopId());
|
String specList = oldProductSpec.getSpecList();
|
||||||
curShopProdSpec.setId(Long.valueOf(oldProductSpec.getId()));
|
if (StrUtil.isEmpty(specList)) {
|
||||||
curShopProdSpec.setShopId(curShopId);
|
|
||||||
curShopProdSpec.setLevel(1);
|
|
||||||
curShopProdSpec.setPid(0L);
|
|
||||||
curShopProdSpec.setPids(pids);
|
|
||||||
curShopProdSpec.setStatus(1);
|
|
||||||
curShopProdSpec.setName(oldProductSpec.getName());
|
|
||||||
curShopProdSpec.setFullName(oldProductSpec.getName());
|
|
||||||
curShopProdSpec.setSort(oldProductSpec.getSort() == null ? 1 : oldProductSpec.getSort());
|
|
||||||
|
|
||||||
firstSpecs.add(curShopProdSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
saveBatch(firstSpecs);
|
|
||||||
|
|
||||||
Map<Long, CurShopProdSpec> oldAndCurSpecIdMap = new HashMap<>();
|
|
||||||
for (OldProductSpec oldProductSpec : oldProductSpecs) {
|
|
||||||
for (CurShopProdSpec firstSpec : firstSpecs) {
|
|
||||||
if (oldProductSpec.getName().equals(firstSpec.getName())) {
|
|
||||||
oldAndCurSpecIdMap.put(Long.valueOf(oldProductSpec.getShopId()), firstSpec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存二级规格
|
|
||||||
for (OldProductSpec oldProductSpec : oldProductSpecs) {
|
|
||||||
if (StrUtil.isBlank(oldProductSpec.getSpecList())) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
JSONArray specListJson = JSON.parseArray(specList);
|
||||||
JSONArray jsonArray = JSONArray.parse(oldProductSpec.getSpecList());
|
if (specListJson.isEmpty()) {
|
||||||
if (jsonArray.isEmpty()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < specListJson.size(); i++) {
|
||||||
|
JSONObject row = specListJson.getJSONObject(i);
|
||||||
|
String name2 = row.getString("name");
|
||||||
|
int index = i + 1;
|
||||||
|
CurShopProdSpec two = new CurShopProdSpec();
|
||||||
|
two.setId(Long.valueOf(one.getId() + "" + index));
|
||||||
|
two.setName(name2);
|
||||||
|
two.setFullName(one.getName() + " - " + name2);
|
||||||
|
two.setLevel(2);
|
||||||
|
two.setSort(index);
|
||||||
|
two.setPid(one.getId());
|
||||||
|
two.setPids(one.getPids() + Convert.toStr(one.getId()) + ",");
|
||||||
|
two.setShopId(Convert.toLong(shopId));
|
||||||
|
two.setStatus(1);
|
||||||
|
two.setCreateTime(one.getCreateTime());
|
||||||
|
two.setUpdateTime(one.getUpdateTime());
|
||||||
|
save(two);
|
||||||
|
|
||||||
CurShopProdSpec first = oldAndCurSpecIdMap.get(Long.valueOf(oldProductSpec.getShopId()));
|
JSONArray v = row.getJSONArray("value");
|
||||||
|
for (int j = 0; j < v.size(); j++) {
|
||||||
List<Long> pids2 = List.of(0L, first.getId());
|
String name3 = v.getString(j);
|
||||||
String pids2Str = pids2.stream()
|
int seq = j + 1;
|
||||||
.map(Object::toString)
|
CurShopProdSpec three = new CurShopProdSpec();
|
||||||
.collect(Collectors.joining(",")) + ",";
|
three.setId(Long.valueOf(two.getId() + "" + seq));
|
||||||
for (Object item : jsonArray) {
|
three.setName(name3);
|
||||||
JSONObject jsonItem = (JSONObject) item;
|
three.setFullName(two.getName() + " - " + name3);
|
||||||
|
three.setLevel(3);
|
||||||
CurShopProdSpec curShopProdSpec = new CurShopProdSpec();
|
three.setSort(seq);
|
||||||
curShopProdSpec.setName(jsonItem.getString("name"));
|
three.setPid(two.getId());
|
||||||
curShopProdSpec.setFullName(String.format("%s-%s", first.getFullName(), curShopProdSpec.getName()));
|
three.setPids(two.getPids() + Convert.toStr(two.getId()) + ",");
|
||||||
curShopProdSpec.setLevel(2);
|
three.setShopId(Convert.toLong(shopId));
|
||||||
curShopProdSpec.setSort(1);
|
three.setStatus(1);
|
||||||
curShopProdSpec.setPid(first.getId());
|
three.setCreateTime(two.getCreateTime());
|
||||||
curShopProdSpec.setPids(pids2Str);
|
three.setUpdateTime(two.getUpdateTime());
|
||||||
curShopProdSpec.setShopId(first.getShopId());
|
save(three);
|
||||||
curShopProdSpec.setStatus(1);
|
|
||||||
|
|
||||||
save(curShopProdSpec);
|
|
||||||
|
|
||||||
String value = jsonItem.getString("value");
|
|
||||||
if (StrUtil.isBlank(value)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray array = JSONArray.parse(value);
|
|
||||||
if (array.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<CurShopProdSpec> thirdSpecs = new ArrayList<>();
|
|
||||||
List<Long> pids3 = List.of(0L, first.getId(), curShopProdSpec.getId());
|
|
||||||
String pids3Str = pids3.stream()
|
|
||||||
.map(Object::toString)
|
|
||||||
.collect(Collectors.joining(",")) + ",";
|
|
||||||
for (Object item2 : array) {
|
|
||||||
String name = (String) item2;
|
|
||||||
CurShopProdSpec curShopProdSpec2 = new CurShopProdSpec();
|
|
||||||
curShopProdSpec2.setName(name);
|
|
||||||
curShopProdSpec2.setFullName(String.format("%s-%s", curShopProdSpec.getFullName(), name));
|
|
||||||
curShopProdSpec2.setLevel(3);
|
|
||||||
curShopProdSpec2.setSort(1);
|
|
||||||
curShopProdSpec2.setPid(curShopProdSpec.getId());
|
|
||||||
curShopProdSpec2.setPids(pids3Str);
|
|
||||||
curShopProdSpec2.setShopId(first.getShopId());
|
|
||||||
curShopProdSpec2.setStatus(1);
|
|
||||||
|
|
||||||
thirdSpecs.add(curShopProdSpec2);
|
|
||||||
}
|
|
||||||
|
|
||||||
saveBatch(thirdSpecs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user