| | |
| | | |
| | | 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.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | @Autowired |
| | | private ShopProductAttributeDao shopProductAttributeDao; |
| | | |
| | | @Autowired |
| | | private RedisClient redisClient; |
| | | |
| | | public <T> List<T> mapsToListBean(List<Map<String, Object>> maps, Class<T> t) { |
| | | List<T> list = new ArrayList<>(); |
| | |
| | | return JSONObject.parseObject(s, t); |
| | | } |
| | | |
| | | private final Long companyId = 37L; |
| | | private final Long shopId = 53L; |
| | | |
| | | @DS("slave") |
| | | public List<ShopProductAttribute> oldProductAttr() { |
| | | return null; |
| | | List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from cere_product_classify where classify_pid=0"); |
| | | |
| | | List<ShopProductAttribute> list = new ArrayList<>(); |
| | | for (Map<String, Object> map : maps) { |
| | | Object classifyId = map.get("classify_id"); |
| | | |
| | | List<Map<String, Object>> subMaps = jdbcTemplate.queryForList("select * from cere_product_classify where classify_pid=" + classifyId.toString()); |
| | | |
| | | for (Map<String, Object> 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<ShopProductAttribute> list) { |
| | | Map<Integer, Integer> 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); |
| | | } |
| | | |
| | | } |