123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package com.kmall.api.service;
- import com.google.common.collect.Maps;
- import com.kmall.api.dao.ApiGoodsSpecificationMapper;
- import com.kmall.api.entity.GoodsSpecificationVo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @Service
- public class ApiGoodsSpecificationService {
- @Autowired
- private ApiGoodsSpecificationMapper apiGoodsSpecificationMapper;
- public GoodsSpecificationVo queryObject(Integer id) {
- return apiGoodsSpecificationMapper.queryObject(id);
- }
- public List<GoodsSpecificationVo> queryList(Map<String, Object> map) {
- return apiGoodsSpecificationMapper.queryList(map);
- }
- public int queryTotal(Map<String, Object> map) {
- return apiGoodsSpecificationMapper.queryTotal(map);
- }
- public void save(GoodsSpecificationVo goods) {
- apiGoodsSpecificationMapper.save(goods);
- }
- public void update(GoodsSpecificationVo goods) {
- apiGoodsSpecificationMapper.update(goods);
- }
- public void delete(Integer id) {
- apiGoodsSpecificationMapper.delete(id);
- }
- public void deleteBatch(Integer[] ids) {
- apiGoodsSpecificationMapper.deleteBatch(ids);
- }
- public String[] queryNamesByIds(String[] ids) {
- String[] goodsSepcifitionValue = null;
- Map specificationParam = Maps.newHashMap();
- specificationParam.put("ids", ids);
- List<GoodsSpecificationVo> specificationEntities = queryList(specificationParam);
- goodsSepcifitionValue = new String[specificationEntities.size()];
- for (int i = 0; i < specificationEntities.size(); i++) {
- goodsSepcifitionValue[i] = specificationEntities.get(i).getValue();
- }
- return goodsSepcifitionValue;
- }
- /**
- * 按规格名称分组
- */
- public List<Map> queryByGoodsIdGroupByNames(Long goodsId) {
- Map specificationParam = Maps.newHashMap();
- specificationParam.put("fields", "gs.*, s.name");
- specificationParam.put("goods_id", goodsId);
- specificationParam.put("specification", true);
- specificationParam.put("sidx", "s.sort_order");
- specificationParam.put("order", "asc");
- List<GoodsSpecificationVo> goodsSpecificationEntityList = apiGoodsSpecificationMapper.queryList(specificationParam);
- List<Map> specificationList = new ArrayList();
- //按规格名称分组
- for (int i = 0; i < goodsSpecificationEntityList.size(); i++) {
- GoodsSpecificationVo specItem = goodsSpecificationEntityList.get(i);
- //
- List<GoodsSpecificationVo> tempList = null;
- for (int j = 0; j < specificationList.size(); j++) {
- if (specificationList.get(j).get("specification_id").equals(specItem.getSpecification_id())) {
- tempList = (List<GoodsSpecificationVo>) specificationList.get(j).get("valueList");
- break;
- }
- }
- //
- if (null == tempList) {
- Map temp = Maps.newHashMap();
- temp.put("specification_id", specItem.getSpecification_id());
- temp.put("name", specItem.getName());
- tempList = new ArrayList();
- tempList.add(specItem);
- temp.put("valueList", tempList);
- specificationList.add(temp);
- } else {
- for (int j = 0; j < specificationList.size(); j++) {
- if (specificationList.get(j).get("specification_id").equals(specItem.getSpecification_id())) {
- tempList = (List<GoodsSpecificationVo>) specificationList.get(j).get("valueList");
- tempList.add(specItem);
- break;
- }
- }
- }
- }
- return specificationList;
- }
- }
|