| | |
| | | package com.yeshi.fanli.service.impl.goods;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.TaoBaoClassMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.TaoBaoClassRelationMapper;
|
| | | import com.yeshi.fanli.entity.bus.clazz.TaoBaoClass;
|
| | | import com.yeshi.fanli.entity.bus.clazz.TaoBaoClassRelation;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoClassService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | |
| | |
|
| | | @Resource
|
| | | private TaoBaoClassMapper taoBaoClassMapper;
|
| | | |
| | | @Resource
|
| | | private TaoBaoClassRelationMapper taoBaoClassRelationMapper;
|
| | |
|
| | | @Override
|
| | | public int deleteByPrimaryKey(Long id) {
|
| | | return taoBaoClassMapper.deleteByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int insert(TaoBaoClass record) {
|
| | | return taoBaoClassMapper.insert(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int insertSelective(TaoBaoClass record) {
|
| | | return taoBaoClassMapper.insertSelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoClass selectByPrimaryKey(Long id) {
|
| | | return taoBaoClassMapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKeySelective(TaoBaoClass record) {
|
| | | return taoBaoClassMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int updateByPrimaryKey(TaoBaoClass record) {
|
| | | return taoBaoClassMapper.updateByPrimaryKey(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<TaoBaoClass> listBySystemCid(long start, int count, Long systemCid) {
|
| | |
| | |
|
| | | @Override
|
| | | public String getTaoBaoCatIds(Long classId) {
|
| | | |
| | | |
| | | List<TaoBaoClass> listCatIds = listBySystemCid(0, 10, classId);
|
| | | if (listCatIds == null || listCatIds.size() == 0) {
|
| | | return null;
|
| | |
| | | if (categoryId == null ) {
|
| | | continue;
|
| | | }
|
| | | |
| | | taobaoCatIds += categoryId + ",";
|
| | | }
|
| | | |
| | |
|
| | | if (!StringUtil.isNullOrEmpty(taobaoCatIds)){
|
| | | taobaoCatIds = taobaoCatIds.substring(0, taobaoCatIds.length()-1);
|
| | | }
|
| | | |
| | | return taobaoCatIds;
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public TaoBaoClass getByCategoryId(Integer categoryId) {
|
| | | return taoBaoClassMapper.getByCategoryId(categoryId);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | @Transactional
|
| | | public void save(Long classId, String taobaoCids) {
|
| | | if (StringUtil.isNullOrEmpty(taobaoCids) || "null".equalsIgnoreCase(taobaoCids)) {
|
| | | return;
|
| | | }
|
| | | |
| | | List<Long> listId = new ArrayList<Long>();
|
| | | List<TaoBaoClass> listExist = taoBaoClassMapper.listBySystemCid(0, Integer.MAX_VALUE, classId);
|
| | | if (listExist != null && listExist.size() > 0) {
|
| | | for (TaoBaoClass taoBaoClass: listExist) {
|
| | | listId.add(taoBaoClass.getId());
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | String[] array = taobaoCids.split(",");
|
| | | for (String info: array) {
|
| | | if(StringUtil.isNullOrEmpty(info)) {
|
| | | continue;
|
| | | }
|
| | | |
| | | try {
|
| | | String[] taobaoArray = info.split("-");
|
| | | |
| | | Integer categoryId = Integer.parseInt(taobaoArray[1]);
|
| | | if (listExist != null && listExist.size() > 0) {
|
| | | for (int i =0; i< listExist.size(); i++) {
|
| | | TaoBaoClass taoBaoClass = listExist.get(i);
|
| | | Integer categoryId2 = taoBaoClass.getCategoryId();
|
| | | if (categoryId == categoryId2 || categoryId.equals(categoryId2)) {
|
| | | if (listId.size() > 0) {
|
| | | listId.remove(taoBaoClass.getId());
|
| | | listExist.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | TaoBaoClass tbClass = taoBaoClassMapper.getByCategoryId(Integer.parseInt(taobaoArray[1]));
|
| | | if (tbClass == null) {
|
| | | tbClass = new TaoBaoClass();
|
| | | tbClass.setCategoryName(taobaoArray[0].trim());
|
| | | tbClass.setCategoryId(Integer.parseInt(taobaoArray[1].trim()));
|
| | | tbClass.setCreatetime(new Date());
|
| | | tbClass.setUpdatetime(new Date());
|
| | | taoBaoClassMapper.insert(tbClass);
|
| | | }
|
| | | |
| | | TaoBaoClassRelation relation = taoBaoClassRelationMapper.getByLocalCid(tbClass.getId());
|
| | | if (relation != null) {
|
| | | if (classId.equals(relation.getCid()) || classId == relation.getCid()) {
|
| | | continue;
|
| | | }
|
| | | TaoBaoClassRelation updateRelation = new TaoBaoClassRelation();
|
| | | updateRelation.setId(relation.getId());
|
| | | updateRelation.setCid(classId);
|
| | | updateRelation.setUpdatetime(new Date());
|
| | | taoBaoClassRelationMapper.updateByPrimaryKeySelective(updateRelation);
|
| | | } else {
|
| | | relation = new TaoBaoClassRelation();
|
| | | relation.setCid(classId);
|
| | | relation.setTaobaoCid(tbClass.getId());
|
| | | relation.setCreatetime(new Date());
|
| | | relation.setUpdatetime(new Date());
|
| | | relation.setWeight(0.0);
|
| | | taoBaoClassRelationMapper.insertSelective(relation);
|
| | | }
|
| | | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | if (listId.size() > 0) {
|
| | | for (Long id: listId) {
|
| | | taoBaoClassMapper.deleteByPrimaryKey(id);
|
| | | taoBaoClassRelationMapper.deleteRelationByLocalCid(id);
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | }
|