ApiGoodsSpecificationService.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.kmall.api.service;
  2. import com.google.common.collect.Maps;
  3. import com.kmall.api.dao.ApiGoodsSpecificationMapper;
  4. import com.kmall.api.entity.GoodsSpecificationVo;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. @Service
  12. public class ApiGoodsSpecificationService {
  13. @Autowired
  14. private ApiGoodsSpecificationMapper apiGoodsSpecificationMapper;
  15. public GoodsSpecificationVo queryObject(Integer id) {
  16. return apiGoodsSpecificationMapper.queryObject(id);
  17. }
  18. public List<GoodsSpecificationVo> queryList(Map<String, Object> map) {
  19. return apiGoodsSpecificationMapper.queryList(map);
  20. }
  21. public int queryTotal(Map<String, Object> map) {
  22. return apiGoodsSpecificationMapper.queryTotal(map);
  23. }
  24. public void save(GoodsSpecificationVo goods) {
  25. apiGoodsSpecificationMapper.save(goods);
  26. }
  27. public void update(GoodsSpecificationVo goods) {
  28. apiGoodsSpecificationMapper.update(goods);
  29. }
  30. public void delete(Integer id) {
  31. apiGoodsSpecificationMapper.delete(id);
  32. }
  33. public void deleteBatch(Integer[] ids) {
  34. apiGoodsSpecificationMapper.deleteBatch(ids);
  35. }
  36. public String[] queryNamesByIds(String[] ids) {
  37. String[] goodsSepcifitionValue = null;
  38. Map specificationParam = Maps.newHashMap();
  39. specificationParam.put("ids", ids);
  40. List<GoodsSpecificationVo> specificationEntities = queryList(specificationParam);
  41. goodsSepcifitionValue = new String[specificationEntities.size()];
  42. for (int i = 0; i < specificationEntities.size(); i++) {
  43. goodsSepcifitionValue[i] = specificationEntities.get(i).getValue();
  44. }
  45. return goodsSepcifitionValue;
  46. }
  47. /**
  48. * 按规格名称分组
  49. */
  50. public List<Map> queryByGoodsIdGroupByNames(Long goodsId) {
  51. Map specificationParam = Maps.newHashMap();
  52. specificationParam.put("fields", "gs.*, s.name");
  53. specificationParam.put("goods_id", goodsId);
  54. specificationParam.put("specification", true);
  55. specificationParam.put("sidx", "s.sort_order");
  56. specificationParam.put("order", "asc");
  57. List<GoodsSpecificationVo> goodsSpecificationEntityList = apiGoodsSpecificationMapper.queryList(specificationParam);
  58. List<Map> specificationList = new ArrayList();
  59. //按规格名称分组
  60. for (int i = 0; i < goodsSpecificationEntityList.size(); i++) {
  61. GoodsSpecificationVo specItem = goodsSpecificationEntityList.get(i);
  62. //
  63. List<GoodsSpecificationVo> tempList = null;
  64. for (int j = 0; j < specificationList.size(); j++) {
  65. if (specificationList.get(j).get("specification_id").equals(specItem.getSpecification_id())) {
  66. tempList = (List<GoodsSpecificationVo>) specificationList.get(j).get("valueList");
  67. break;
  68. }
  69. }
  70. //
  71. if (null == tempList) {
  72. Map temp = Maps.newHashMap();
  73. temp.put("specification_id", specItem.getSpecification_id());
  74. temp.put("name", specItem.getName());
  75. tempList = new ArrayList();
  76. tempList.add(specItem);
  77. temp.put("valueList", tempList);
  78. specificationList.add(temp);
  79. } else {
  80. for (int j = 0; j < specificationList.size(); j++) {
  81. if (specificationList.get(j).get("specification_id").equals(specItem.getSpecification_id())) {
  82. tempList = (List<GoodsSpecificationVo>) specificationList.get(j).get("valueList");
  83. tempList.add(specItem);
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. return specificationList;
  90. }
  91. }