| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.PinYinUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.core.utils.aliyun.ALiYunUtil; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.business.model.dto.OssModel; |
| | | 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.extension.plugins.pagination.Page; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | import java.lang.reflect.Method; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * ååæºæ°æ®ä¿¡æ¯è¡¨Serviceå®ç° |
| | |
| | | |
| | | @Autowired |
| | | private BaseDataMapper baseDataMapper; |
| | | @Autowired |
| | | @Lazy |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private BaseGoodsMapper baseGoodsMapper; |
| | | @Autowired |
| | |
| | | p.setIsdeleted(Constants.ZERO); |
| | | //æ¥è¯¢å
¨é¨ç±»å«å±æ§ä¿¡æ¯ |
| | | List<BaseCateParam> paramList = baseCateParamMapper.selectList(new QueryWrapper<>(p)); |
| | | |
| | | OssModel ossModel = initOssModel(); |
| | | Date date = new Date(); |
| | | for(BaseData data : allLis){ |
| | | BaseGoods goods = new BaseGoods(); |
| | |
| | | goods.setBrandId(bModel.getId()); |
| | | } |
| | | //å¤çåè¡¨æ°æ® |
| | | BaseCategory cModel = getCateModelFromList(data.getBrand(),data.getCategoryImg(), cateList); |
| | | BaseCategory cModel = getCateModelFromList(data.getBrand(),ossModel,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); |
| | | //æ´æ°æ°æ®å¤çç¶æ |
| | |
| | | }finally { |
| | | IS_RUNNING = false; |
| | | } |
| | | } |
| | | |
| | | private OssModel initOssModel() { |
| | | OssModel model = new OssModel(); |
| | | model.setUrl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()); |
| | | model.setEndpoint(systemDictDataBiz.queryByCode(Constants.OSS, Constants.ENDPOINT).getCode()); |
| | | model.setAccessId(systemDictDataBiz.queryByCode(Constants.OSS, Constants.ACCESS_ID).getCode()); |
| | | model.setAccessKey(systemDictDataBiz.queryByCode(Constants.OSS, Constants.ACCESS_KEY).getCode()); |
| | | model.setBucket(systemDictDataBiz.queryByCode(Constants.OSS, Constants.BUCKETNAME).getCode()); |
| | | model.setCateFolder(systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode()); |
| | | model.setAccessKey(systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode()); |
| | | |
| | | return model; |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | |
| | | private BaseCategory getCateModelFromList(String name, String img,List<BaseCategory> list) { |
| | | private BaseCategory getCateModelFromList(String name,OssModel ossModel, String img,List<BaseCategory> list) { |
| | | if(list!=null && list.size()>0){ |
| | | for(BaseCategory p : list){ |
| | | if(StringUtils.equals(name,p.getName())){ |
| | |
| | | model.setCreateDate(new Date()); |
| | | model.setName(name); |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setImgurl(img); |
| | | model.setImgurl(getOssImgurl(ossModel,img)); |
| | | //æå
¥æ°çåçä¿¡æ¯ |
| | | baseCategoryMapper.insert(model); |
| | | //å å
¥éåä¸ |
| | | list.add(model); |
| | | return model; |
| | | } |
| | | |
| | | private String getOssImgurl(OssModel ossModel, String img) { |
| | | if(StringUtils.isBlank(img)){ |
| | | return null; |
| | | } |
| | | try { |
| | | String nowDate = DateUtil.getNowShortDate();// å½åæ¶é´ï¼å¹´ææ¥ï¼ |
| | | String nfix = img.lastIndexOf(".")>0?img.substring(img.lastIndexOf(".")):null; |
| | | nfix = StringUtils.defaultString(nfix,".jpg"); |
| | | String fileName = UUID.randomUUID() + nfix; |
| | | String tempFileName = nowDate + "/" + fileName; |
| | | String key = ossModel.getCateFolder() + tempFileName;// æä»¶å |
| | | |
| | | ALiYunUtil obs = new ALiYunUtil(ossModel.getEndpoint(), ossModel.getAccessId(), ossModel.getAccessKey()); |
| | | if (obs.uploadOnlineObject(img,ossModel.getBucket(), key,null)) { |
| | | return tempFileName; |
| | | } |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | } |