package com.matrix.system.dataMove; import com.alibaba.fastjson.JSONObject; import com.baomidou.dynamic.datasource.annotation.DS; import com.matrix.component.redis.RedisClient; import com.matrix.core.tools.StringUtils; import com.matrix.system.shopXcx.bean.ShopProductAttribute; import com.matrix.system.shopXcx.dao.ShopProductAttributeDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import java.util.*; /** * @author wzy * @date 2021-08-11 **/ @Service public class SjfDataMoveServiceImpl { @Autowired private JdbcTemplate jdbcTemplate; @Autowired private ShopProductAttributeDao shopProductAttributeDao; @Autowired private RedisClient redisClient; public List mapsToListBean(List> maps, Class t) { List list = new ArrayList<>(); for (Map map : maps) { String s = JSONObject.toJSONString(map); T object = JSONObject.parseObject(s, t); list.add(object); } return list; } public T mapToBane(Map map, Class t) { String s = JSONObject.toJSONString(map); return JSONObject.parseObject(s, t); } private final Long companyId = 37L; private final Long shopId = 53L; @DS("slave") public List oldProductAttr() { List> maps = jdbcTemplate.queryForList("select * from cere_product_classify where classify_pid=0"); List list = new ArrayList<>(); for (Map map : maps) { Object classifyId = map.get("classify_id"); List> subMaps = jdbcTemplate.queryForList("select * from cere_product_classify where classify_pid=" + classifyId.toString()); for (Map subMap : subMaps) { ShopProductAttribute subAttr = new ShopProductAttribute(); subAttr.setAttrId((int) Long.parseLong(subMap.get("classify_id").toString())); subAttr.setParentId(Integer.parseInt(subMap.get("classify_pid").toString())); String subName = subMap.get("classify_name").toString(); subAttr.setAttrName(subName); subAttr.setAttrCode(StringUtils.toHanyuPinyin(subName)); subAttr.setCreateBy("善吉凡"); subAttr.setUpdateBy("善吉凡"); subAttr.setCreateTime(new Date()); subAttr.setUpdateTime(new Date()); subAttr.setShopId(shopId); subAttr.setCompanyId(companyId); list.add(subAttr); } ShopProductAttribute attr = new ShopProductAttribute(); attr.setAttrId((int) Long.parseLong(map.get("classify_id").toString())); attr.setParentId(Integer.parseInt(map.get("classify_pid").toString())); String name = map.get("classify_name").toString(); attr.setAttrName(name); attr.setAttrCode(StringUtils.toHanyuPinyin(name)); attr.setCreateBy("善吉凡"); attr.setUpdateBy("善吉凡"); attr.setCreateTime(new Date()); attr.setUpdateTime(new Date()); attr.setShopId(shopId); attr.setCompanyId(companyId); list.add(attr); } return list; } public void productAttr(List list) { Map map = new HashMap<>(); for (ShopProductAttribute shopProductAttribute : list) { Integer oldId = shopProductAttribute.getAttrId(); shopProductAttribute.setAttrId(null); shopProductAttributeDao.insert(shopProductAttribute); map.put(oldId, shopProductAttribute.getAttrId()); } redisClient.saveMapValue("attrIds", map); } }