| | |
| | | |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.PinYinUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.BaseDataMapper; |
| | | import com.doumee.dao.business.model.BaseData; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.service.business.BaseDataService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.Method; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private BaseDataMapper baseDataMapper; |
| | | @Autowired |
| | | private BaseGoodsMapper baseGoodsMapper; |
| | | @Autowired |
| | | private BaseGoodsParamMapper baseGoodsParamMapper; |
| | | @Autowired |
| | | private BaseCategoryMapper baseCategoryMapper; |
| | | @Autowired |
| | | private BaseCateParamMapper baseCateParamMapper; |
| | | @Autowired |
| | | private BrandMapper brandMapper; |
| | | |
| | | @Override |
| | | public Integer create(BaseData baseData) { |
| | | public String create(BaseData baseData) { |
| | | baseDataMapper.insert(baseData); |
| | | return baseData.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | public void deleteById(String id) { |
| | | baseDataMapper.deleteById(id); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByIdInBatch(List<Integer> ids) { |
| | | public void deleteByIdInBatch(List<String> ids) { |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | return; |
| | | } |
| | |
| | | QueryWrapper<BaseData> wrapper = new QueryWrapper<>(baseData); |
| | | return baseDataMapper.selectCount(wrapper); |
| | | } |
| | | public static boolean IS_RUNNING = false; |
| | | @Override |
| | | public void dealBaseData() { |
| | | if(IS_RUNNING){ |
| | | return; |
| | | } |
| | | IS_RUNNING = true; |
| | | |
| | | try { |
| | | BaseData param = new BaseData(); |
| | | param.setStatus(Constants.ZERO); |
| | | List<BaseData> allLis=findList(param); |
| | | if(allLis==null || allLis.size() ==0){ |
| | | return ; |
| | | } |
| | | Brand brand = new Brand(); |
| | | brand.setIsdeleted(Constants.ZERO); |
| | | brand.setType(Constants.ONE); |
| | | //查询全部品牌信息 |
| | | List<Brand> brandList = brandMapper.selectList(new QueryWrapper<>(brand)); |
| | | |
| | | BaseCategory cate = new BaseCategory(); |
| | | cate.setIsdeleted(Constants.ZERO); |
| | | //查询全部类别信息 |
| | | List<BaseCategory> cateList = baseCategoryMapper.selectList(new QueryWrapper<>(cate)); |
| | | BaseCateParam p = new BaseCateParam(); |
| | | p.setIsdeleted(Constants.ZERO); |
| | | //查询全部类别属性信息 |
| | | List<BaseCateParam> paramList = baseCateParamMapper.selectList(new QueryWrapper<>(p)); |
| | | Date date = new Date(); |
| | | for(BaseData data : allLis){ |
| | | BaseGoods goods = new BaseGoods(); |
| | | goods.setBaseDataId(data.getId()); |
| | | goods.setIsdeleted(Constants.ZERO); |
| | | goods.setCreateDate(date); |
| | | goods.setName(StringUtils.defaultString(data.getName(),data.getTitle())); |
| | | goods.setRemark(data.getTitle()); |
| | | goods.setContent(data.getTitle()); |
| | | goods.setStatus(Constants.ZERO); |
| | | goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName())); |
| | | goods.setPinyin(PinYinUtil.getFullSpell(goods.getName())); |
| | | goods.setPrice(data.getSaleprice()); |
| | | goods.setZdPrice(data.getPrice()); |
| | | //处理品牌数据 |
| | | Brand bModel = getBrandModelFromList(data.getBrand(),brandList); |
| | | if(bModel!= null){ |
| | | goods.setBrandId(bModel.getId()); |
| | | } |
| | | //处理列表数据 |
| | | BaseCategory cModel = getCateModelFromList(data.getBrand(),data.getCategoryImg(), cateList); |
| | | if(bModel!= null){ |
| | | goods.setBrandId(bModel.getId()); |
| | | } |
| | | |
| | | //插入新商品数据 |
| | | baseGoodsMapper.insert(goods); |
| | | //处理分类属性 |
| | | dealCateParamAll(cModel.getId(),goods.getId(),data,paramList); |
| | | data.setEditDate(new Date()); |
| | | data.setStatus(Constants.ONE); |
| | | //更新数据处理状态 |
| | | baseDataMapper.updateById(data); |
| | | } |
| | | }catch (Exception e){ |
| | | |
| | | }finally { |
| | | IS_RUNNING = false; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private void dealCateParamAll(Integer cateId,Integer goodsId, BaseData data ,List<BaseCateParam> cateList) { |
| | | Method[] fields = data.getClass().getMethods(); // 获取对象的所有属性 |
| | | for (Method item : fields) { |
| | | String name = item.getName(); |
| | | if(name.indexOf("getAttr") == 0){ |
| | | try { |
| | | String val =(String) item.invoke(data); |
| | | dealCateParam(cateId,goodsId,val.toString(),cateList); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // dealCateParam(cateId,goodsId,data.getAttr1(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr2(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr3(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr4(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr5(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr6(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr7(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr8(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr9(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr10(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr11(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr12(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr13(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr14(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr15(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr16(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr17(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr18(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr19(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr20(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr21(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr22(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr23(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr24(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr25(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr26(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr27(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr28(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr29(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr30(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr31(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr32(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr33(),cateList); |
| | | // dealCateParam(cateId,goodsId,data.getAttr34(),cateList); |
| | | } |
| | | |
| | | private void dealCateParam(Integer cateId, Integer goodsId, String attr,List<BaseCateParam> list) { |
| | | if(StringUtils.isBlank(attr)){ |
| | | return; |
| | | } |
| | | //如果属性不为空,处理属性数据 |
| | | int index = attr.indexOf(":"); |
| | | if(index <=0){ |
| | | return; |
| | | } |
| | | String attrName = attr.substring(0,index); |
| | | String val = attr.substring(index+1); |
| | | BaseCateParam cate = getCateParamModelFromList(cateId,attrName, list); |
| | | BaseGoodsParam p = new BaseGoodsParam(); |
| | | p.setName(attrName); |
| | | p.setPramaId(cate.getId()); |
| | | p.setIsdeleted(Constants.ZERO); |
| | | p.setStatus(Constants.ZERO); |
| | | p.setVal(val); |
| | | p.setCreateDate(new Date()); |
| | | p.setGoodsId(goodsId); |
| | | baseGoodsParamMapper.insert(p); |
| | | } |
| | | |
| | | /** |
| | | * 根据品类编码和参数名称查询参数对象,没有则插入新的 |
| | | * @param list |
| | | * @return |
| | | */ |
| | | |
| | | private BaseCateParam getCateParamModelFromList(Integer id,String name, List<BaseCateParam> list) { |
| | | if(list!=null && list.size()>0){ |
| | | for(BaseCateParam p : list){ |
| | | if(Constants.equalsInteger(id,p.getCategoryId()) && StringUtils.equals(name,p.getName())){ |
| | | return p; |
| | | } |
| | | } |
| | | } |
| | | BaseCateParam model = new BaseCateParam(); |
| | | model.setCreateDate(new Date()); |
| | | model.setName(name); |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setCategoryId(id); |
| | | //插入新的品牌信息 |
| | | baseCateParamMapper.insert(model); |
| | | //加入集合中 |
| | | list.add(model); |
| | | return model; |
| | | } |
| | | /** |
| | | * 根据品牌名称查询品牌对象,没有则插入新的 |
| | | * @param name |
| | | * @param brandList |
| | | * @return |
| | | */ |
| | | |
| | | private Brand getBrandModelFromList(String name, List<Brand> brandList) { |
| | | if(brandList!=null && brandList.size()>0){ |
| | | for(Brand brand : brandList){ |
| | | if(StringUtils.equals(name,brand.getName())){ |
| | | return brand; |
| | | } |
| | | } |
| | | } |
| | | Brand model = new Brand(); |
| | | model.setType(Constants.ONE); |
| | | model.setCreateDate(new Date()); |
| | | model.setName(name); |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setImgurl(null); |
| | | //插入新的品牌信息 |
| | | brandMapper.insert(model); |
| | | //加入集合中 |
| | | brandList.add(model); |
| | | return model; |
| | | } |
| | | /** |
| | | * 根据名称查询分类对象,没有则插入新的 |
| | | * @param name |
| | | * @param list |
| | | * @return |
| | | */ |
| | | |
| | | private BaseCategory getCateModelFromList(String name, String img,List<BaseCategory> list) { |
| | | if(list!=null && list.size()>0){ |
| | | for(BaseCategory p : list){ |
| | | if(StringUtils.equals(name,p.getName())){ |
| | | return p; |
| | | } |
| | | } |
| | | } |
| | | BaseCategory model = new BaseCategory(); |
| | | model.setCreateDate(new Date()); |
| | | model.setName(name); |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setImgurl(img); |
| | | //插入新的品牌信息 |
| | | baseCategoryMapper.insert(model); |
| | | //加入集合中 |
| | | list.add(model); |
| | | return model; |
| | | } |
| | | } |