1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776 |
- package com.kmall.admin.service.impl;
- import cn.hutool.http.HttpUtil;
- import com.alibaba.fastjson.JSON;
- import com.google.common.collect.ImmutableBiMap;
- import com.google.common.collect.Lists;
- import com.google.common.collect.Maps;
- import com.kmall.admin.dao.*;
- import com.kmall.admin.dto.GoodsDetailsDto;
- import com.kmall.admin.dto.GoodsDto;
- import com.kmall.admin.dto.GoodsPanoramaDto;
- import com.kmall.admin.entity.*;
- import com.kmall.admin.entity.kmall2eccs.KtoEccsEntity;
- import com.kmall.admin.entity.mk.MkActivitiesEntity;
- import com.kmall.admin.entity.shop.ShopErrorPriceRecordEntity;
- import com.kmall.admin.haikong.client.HaiKongWarehouseTemplate;
- import com.kmall.admin.haikong.vo.QueryGoodsVO;
- import com.kmall.admin.service.*;
- import com.kmall.admin.service.kmall2eccs.KtoEccsService;
- import com.kmall.admin.service.mk.MkActivitiesService;
- import com.kmall.admin.service.mk.MkActivityFormService;
- import com.kmall.admin.service.GoodsService;
- import com.kmall.admin.service.shop.ShopErrorPriceRecordService;
- import com.kmall.admin.utils.CalculateTax;
- import com.kmall.admin.utils.GoodsUtils;
- import com.kmall.admin.utils.ShiroUtils;
- import com.kmall.api.entity.exportpdf.PDFGoodsDto;
- import com.kmall.common.constant.Dict;
- import com.kmall.admin.fromcomm.entity.SysUserEntity;
- import com.kmall.common.utils.*;
- import com.kmall.manager.manager.redis.JedisUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * Service实现类
- *
- * @author Scott
- * @email
- * @date 2017-08-21 21:19:49
- */
- @Service("goodsService")
- public class GoodsServiceImpl implements GoodsService {
- private static final Logger log = LoggerFactory.getLogger(GoodsServiceImpl.class);
- @Autowired
- private MerchDao merchDao;
- @Autowired
- private GoodsDao goodsDao;
- @Autowired
- private ProductDao productDao;
- @Autowired
- private GoodsGalleryDao goodsGalleryDao;
- @Autowired
- private GoodsSpecificationDao goodsSpecificationDao;
- @Autowired
- private ProductStoreRelaDao productStoreRelaDao;
- @Autowired
- private StoreDao storeDao;
- @Autowired
- private GoodsGroupDao goodsGroupDao;
- @Autowired
- private CategoryDao categoryDao;
- @Autowired
- private SupplierDao supplierDao;
- @Autowired
- private SysCusNationCodeDao sysCusNationCodeDao;
- @Autowired
- private SysCusUnitCodeDao sysCusUnitCodeDao;
- @Autowired
- private ExportExceptionDataDao exportExceptionDataDao;
- @Autowired
- private CartDao cartDao;
- @Autowired
- private ThirdMerchantBizDao thirdMerchantBizDao;
- @Autowired
- private MngChangeDao mngChangeDao;
- @Autowired
- private MerchUserDao merchUserDao;
- @Autowired
- private StoreMngChangeDao storeMngChangeDao;
- @Autowired
- private GoodsUtils goodsUtils;
- @Autowired
- private TaxErrorRecordDao taxErrorRecordDao;
- @Autowired
- private MkActivityFormService mkActivityFormService; // 活动表
- @Autowired
- private MkActivitiesService mkActivitiesService; // 营销方式表
- @Autowired
- private MkDailyActivitiesService dailyActivitiesService; // 日常活动
- @Autowired
- private MkActivitiesCouponService couponService; // 优惠券
- @Autowired
- private MkActivitiesCombinationPriceService combinationPriceService; // 组合价
- @Autowired
- private MkActivitiesDiscountService discountService; // 折扣
- @Autowired
- private MkActivitiesFullGiftService fullGiftService; // 满赠
- @Autowired
- private MkActivitiesFullReductionService fullReductionService; // 满减
- @Autowired
- private MkActivitiesGetOneFreeGoodsService getOneFreeGoodsService; // 买一送一
- @Autowired
- private MkActivitiesPromotionService promotionService; // 临时促销
- @Autowired
- private MkActivitiesHalfPriceService halfPriceService; // 第二份半价
- @Autowired
- private BrandService brandService;
- @Autowired
- private ShopErrorPriceRecordService shopErrorPriceRecordService;
- @Autowired
- private KtoEccsService ktoEccsService;
- @Autowired
- private HaiKongWarehouseTemplate haiKongWarehouseTemplate;
- @Override
- public GoodsEntity queryObject(Integer id) {
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("goodsId", id);
- // List<GoodsAttributeEntity> attributeEntities = goodsAttributeDao.queryList(map);
- List<ProductEntity> productEntityList = productDao.queryList(map);
- GoodsEntity entity = goodsDao.queryObject(id);
- // entity.setAttributeEntityList(attributeEntities);
- entity.setProductEntityList(productEntityList);
- return entity;
- }
- @Override
- public GoodsEntity queryObjectByProdBarcodeAndBizType(String prodBarcode, Integer storeId){
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("prodBarcode", prodBarcode);
- GoodsEntity entity = goodsDao.queryObjectByProdBarcodeAndBizType(prodBarcode, storeId);
- return entity;
- }
- @Override
- public List<GoodsEntity> queryList(Map<String, Object> map) {
- return goodsDao.queryList(map);
- }
- @Override
- public List<GoodsEntity> querySame(Map<String, Object> map) {
- return goodsDao.querySame(map);
- }
- @Override
- public int queryTotal(Map<String, Object> map) {
- return goodsDao.queryTotal(map);
- }
- @Override
- @Transactional
- public int save(GoodsEntity goods) {
- Map<String, Object> valideDate = MapBeanUtil.fromObject(goods);
- ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
- builder.put("merchSn", "商户编号");
- builder.put("thirdPartyMerchCode", "第三方商户编号");
- // builder.put("attributeCategory", "商品分类");
- // builder.put("categoryId", "商品二级分类");
- builder.put("goodsSn", "商品编码");
- builder.put("name", "商品名称");
- builder.put("goodsUnit", "商品单位");
- builder.put("prodBarcode", "产品条码");
- builder.put("goodsBizType", "货品业务类型");
- // builder.put("brandId", "品牌");
- builder.put("supplierId", "供应商");
- // builder.put("freightId", "运费模版");
- builder.put("goodsNumber", "商品总库存");
- builder.put("primaryPicUrl", "商品主图");
- builder.put("listPicUrl", "商品列表图");
- builder.put("goodsDesc", "商品描述");
- builder.put("isOnSale", "上架");
- builder.put("isHot", "热销");
- builder.put("englishName", "商品英文名称");
- builder.put("plu", "PLU");
- R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- } else {
- if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
- // 海关信息,普通货物可不添加
- builder.put("sku", "SKU");
- builder.put("goodsRate", "商品税率");
- // builder.put("retailPrice", "零售价");
- builder.put("brand", "产品品牌");
- builder.put("unitCode", "计量单位代码");
- builder.put("cusGoodsCode", "海关商品编码");
- builder.put("ciqProdModel", "国检规格型号");
- builder.put("oriCntCode", "原产国代码");
- builder.put("cusDeclEle", "海关申报要素");
- builder.put("cusRecCode", "海关备案编号");
- }
- r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- }
- }
- /*ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goods.getThirdPartyMerchCode());
- if(thirdMerchantBizEntity == null){
- throw new RRException("第三方商户信息不存在");
- }
- if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goods.getGoodsBizType())){
- if(Dict.isStockShare.item_1.getItem().equalsIgnoreCase(thirdMerchantBizEntity.getIsStockShare())){
- builder.put("goodsNumber", "商品库存");
- }
- }*/
- r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- }
- // 商品轮播图
- List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
- if (galleryEntityList == null || galleryEntityList.size() <= 0) {
- throw new RRException("至少添加一张商品轮播图!");
- }
- // List<GoodsEntity> prodbarGoodsList = goodsDao.queryObjectByProdBarcode(goods.getProdBarcode(),goods.getMerchSn(),null);
- // if(prodbarGoodsList != null && prodbarGoodsList.size() > 0){
- // throw new RRException("不能有重复的产品条码信息!");
- // }
- SysUserEntity user = ShiroUtils.getUserEntity();
- Map<String, Object> map = new HashMap<>();
- map.put("isSame", "true");
- map.put("sku", goods.getSku());
- map.put("goodsSn", goods.getGoodsSn());
- map.put("goodsBizType", goods.getGoodsBizType());
- List<GoodsEntity> list = querySame(map);
- if (list != null && list.size() != 0) {
- throw new RRException("已存在该商品编码,或该货品业务类型下已存在此SKU!");
- }
- // 添加商品
- if (Dict.orderBizType.item_02.getItem().equals(goods.getGoodsBizType())
- || Dict.orderBizType.item_10.getItem().equals(goods.getGoodsBizType())) {
- goods.setIsHot(0);
- }
- // goods.setAttributeCategory(categoryDao.queryObject(goods.getCategoryId()).getParentId());
- goods.setAddTime(new Date());
- goods.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
- goods.setIsNew(0);
- goods.setCreateUserId(user.getUserId());
- goods.setUpdateUserId(user.getUserId());
- goods.setUpdateTime(new Date());
- goods.setModTime(new Date());
- goods.setCreateTime(new Date());
- // 新增商品
- goodsDao.save(goods);
- Long id = goods.getId();
- // 添加商品轮播图
- for (int i=0;i<galleryEntityList.size();i++) {
- GoodsGalleryEntity galleryEntity =galleryEntityList.get(i);
- galleryEntity.setMerchSn(goods.getMerchSn());
- galleryEntity.setGoodsId(id);
- galleryEntity.setSortOrder((i+1));
- galleryEntity.setFileType("0");//图片
- goodsGalleryDao.save(galleryEntity);
- }
- if(org.apache.commons.lang.StringUtils.isNotEmpty(goods.getVideoUrl())){
- GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
- galleryEntity.setMerchSn(goods.getMerchSn());
- galleryEntity.setGoodsId(id);
- galleryEntity.setSortOrder(0);
- galleryEntity.setFileType("1");//视频
- goodsGalleryDao.save(galleryEntity);
- }
- /*
- // 添加商品参数
- List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
- if (attributeEntityList != null && attributeEntityList.size() > 0) {
- for (GoodsAttributeEntity item : attributeEntityList) {
- if (item.getIsDelete() == 0) {
- if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNotEmpty(item.getValue())) {
- item.setGoodsId(id);
- item.setMerchSn(goods.getMerchSn());
- goodsAttributeDao.save(item);
- } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNullOrEmpty(item.getValue())) {
- throw new RRException("商品属性【" + attributeDao.queryObject(item.getAttributeId()).getName() + "】值不能为空!");
- } else if (item.getId() == null && item.getAttributeId() == null) {
- continue;
- }
- }
- }
- }*/
- if (goods.getGoodsNumber() != null){
- MngChangeEntity mngChangeEntity = new MngChangeEntity();
- mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(id)));
- mngChangeEntity.setThirdPartyMerchCode(goods.getThirdPartyMerchCode());
- mngChangeEntity.setChangeReason("新增商户商品总库存");
- mngChangeEntity.setChangeType(Dict.changeType.item_0.getItem());
- mngChangeEntity.setChangeNum(goods.getGoodsNumber());//变化数
- mngChangeEntity.setOriginalNum(0);//原库存数
- mngChangeEntity.setValidNum(goods.getGoodsNumber());//可用数
- mngChangeEntity.setCreateTime(new Date());
- mngChangeEntity.setModTime(new Date());
- mngChangeEntity.setCreaterSn(user.getUsername());
- mngChangeEntity.setModerSn(user.getUsername());
- mngChangeEntity.setIsValid(0);
- mngChangeEntity.setMerchSn(goods.getMerchSn());
- mngChangeDao.save(mngChangeEntity);
- }
- // 添加产品
- ProductEntity product = new ProductEntity();
- product.setGoodsId(id);
- product.setGoodsSn(goods.getGoodsSn());
- // 保税商品,普通货物暂不添加商品规格
- if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
- // 添加商品规格
- GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
- goodsSpecification.setGoodsId(id);
- goodsSpecification.setValue(goods.getCiqProdModel());
- goodsSpecification.setSpecificationId(1);
- goodsSpecificationDao.save(goodsSpecification);
- product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
- product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
- }
- return productDao.save(product);
- }
- @Override
- @Transactional
- public int update(GoodsEntity goods) {
- Map<String, Object> valideDate = MapBeanUtil.fromObject(goods);
- ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
- builder.put("merchSn", "商户编号");
- builder.put("thirdPartyMerchCode", "第三方商户编号");
- // builder.put("attributeCategory", "商品分类");
- // builder.put("categoryId", "商品二级分类");
- builder.put("goodsSn", "商品编码");
- builder.put("name", "商品名称");
- builder.put("goodsUnit", "商品单位");
- builder.put("prodBarcode", "产品条码");
- builder.put("goodsBizType", "货品业务类型");
- // builder.put("brandId", "品牌");
- builder.put("supplierId", "供应商");
- builder.put("goodsNumber", "商品总库存");
- // builder.put("freightId", "运费模版");
- builder.put("primaryPicUrl", "商品主图");
- builder.put("listPicUrl", "商品列表图");
- // builder.put("goodsDesc", "商品描述");
- builder.put("isOnSale", "上架");
- builder.put("isHot", "热销");
- R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- } else {
- if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
- // 海关信息,普通货物可不添加
- builder.put("sku", "SKU");
- builder.put("goodsRate", "商品税率");
- // builder.put("retailPrice", "零售价");
- builder.put("brand", "产品品牌");
- builder.put("unitCode", "计量单位代码");
- builder.put("cusGoodsCode", "海关商品编码");
- builder.put("ciqProdModel", "国检规格型号");
- builder.put("oriCntCode", "原产国代码");
- builder.put("cusRecCode", "海关备案编号");
- builder.put("cusDeclEle", "海关申报要素");
- }
- r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- }
- }
- /*ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goods.getThirdPartyMerchCode());
- if(thirdMerchantBizEntity == null){
- throw new RRException("所属第三方商户不存在");
- }*/
- GoodsEntity goodsEntity = goodsDao.queryObject(goods.getId());
- if(goodsEntity != null){
- /*if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goods.getGoodsBizType())){
- if(Dict.isStockShare.item_1.getItem().equalsIgnoreCase(thirdMerchantBizEntity.getIsStockShare())){
- builder.put("goodsNumber", "商品库存");
- }
- }
- r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- }*/
- }else{
- throw new RRException("商品不存在");
- }
- // 商品轮播图
- List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
- if (galleryEntityList == null || galleryEntityList.size() <= 0) {
- // throw new RRException("至少保留一张商品轮播图!");
- }
- // List<GoodsEntity> prodbarGoodsList = goodsDao.queryObjectByProdBarcode(goods.getProdBarcode(),goods.getMerchSn(),goods.getId());
- // if(prodbarGoodsList != null && prodbarGoodsList.size() > 0){
- // throw new RRException("不能有重复的产品条码信息!");
- // }
- SysUserEntity user = ShiroUtils.getUserEntity();
- Map<String, Object> map = new HashMap<>();
- map.put("isSame", "true");
- map.put("sku", goods.getSku());
- map.put("goodsSn", goods.getGoodsSn());
- map.put("goodsBizType", goods.getGoodsBizType());
- map.put("id", goods.getId());
- List<GoodsEntity> list = querySame(map);
- if (list != null && list.size() != 0) {
- throw new RRException("已存在该商品编码,或该货品业务类型下已存在此SKU!");
- }
- // 修改商品
- if (Dict.orderBizType.item_02.getItem().equals(goods.getGoodsBizType())
- || Dict.orderBizType.item_10.getItem().equals(goods.getGoodsBizType())) {
- goods.setIsHot(0);
- }
- // goods.setAttributeCategory(categoryDao.queryObject(goods.getCategoryId()).getParentId());
- goods.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
- goods.setIsNew(0);
- goods.setUpdateUserId(user.getUserId());
- goods.setUpdateTime(new Date());
- goods.setModTime(new Date());
- if(goods.getGoodsNumber()==null){
- goods.setGoodsNumber(0);
- }else{
- if(goodsEntity.getGoodsNumber() == null){
- goodsEntity.setGoodsNumber(0);
- }
- MngChangeEntity mngChangeEntity = new MngChangeEntity();
- mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goods.getId())));
- mngChangeEntity.setThirdPartyMerchCode(goods.getThirdPartyMerchCode());
- mngChangeEntity.setChangeReason("更新商户商品总库存");
- mngChangeEntity.setCreateTime(new Date());
- mngChangeEntity.setModTime(new Date());
- mngChangeEntity.setCreaterSn(user.getUsername());
- mngChangeEntity.setModerSn(user.getUsername());
- mngChangeEntity.setIsValid(0);
- mngChangeEntity.setMerchSn(goods.getMerchSn());
- if(goodsEntity.getGoodsNumber() != goods.getGoodsNumber()) {
- if (goodsEntity.getGoodsNumber() > goods.getGoodsNumber()) {
- mngChangeEntity.setChangeNum(goodsEntity.getGoodsNumber() - goods.getGoodsNumber());//变化数
- mngChangeEntity.setChangeType(Dict.changeType.item_4.getItem());
- } else {
- mngChangeEntity.setChangeNum(goods.getGoodsNumber() - goodsEntity.getGoodsNumber());//变化数
- mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
- }
- mngChangeEntity.setOriginalNum(goodsEntity.getGoodsNumber());//原库存数
- mngChangeEntity.setValidNum(goods.getGoodsNumber());//可用数
- mngChangeDao.save(mngChangeEntity);
- }
- }
- // 修改商品
- goodsDao.update(goods);
- // 保税商品修改各个门店商品价格
- List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goodsEntity.getId());
- Long[] storeIds = new Long[productStoreRelaEntityList.size()];
- Integer goodsNumber = goods.getGoodsNumber();//商品总库存
- Integer storeTotalGoodsNumber = 0;//商品分配库存
- if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
- for (int i = 0; i < productStoreRelaEntityList.size(); i++) {
- //修改该商品的所属商户信息,如在该商户门店中有该上架的商品信息,则提示该商品不能修改
- ProductStoreRelaEntity relaEntity = productStoreRelaEntityList.get(i);
- if(org.apache.commons.lang3.StringUtils.isNotEmpty(relaEntity.getMerchSn()) && relaEntity.getMerchSn().equalsIgnoreCase(goods.getMerchSn())
- && goods.getIsOnSale() == Integer.parseInt(Dict.isOnSale.item_1.getItem())) {
- }else {
- if (goods.getIsOnSale() != Integer.parseInt(Dict.isOnSale.item_0.getItem())) {
- throw new RRException("商品编码为【" + goods.getGoodsSn() + "】的商品已上架在商户编号为【" + relaEntity.getMerchSn() + "】的门店中,可先将该商品下架后再进行修改!");
- }
- }
- storeTotalGoodsNumber = storeTotalGoodsNumber + relaEntity.getStockNum();
- storeIds[i] = relaEntity.getStoreId();
- }
- }
- if(goodsEntity.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
- if (goodsNumber < storeTotalGoodsNumber) {
- throw new RRException("该商品已在各门店分配库存" + storeTotalGoodsNumber + ",当前商品总库存不能小于分配库存总额!请先修改门店库存!");
- }
- }else{
- //共享库存商品库存变化,修改该商品的所有库存信息
- ProductStoreRelaEntity productStoreRelaEntity = new ProductStoreRelaEntity();
- productStoreRelaEntity.setStockNum(goodsNumber);
- productStoreRelaEntity.setGoodsId(goods.getId());
- productStoreRelaDao.updateStockNumByGoodsId(productStoreRelaEntity);
- for (int i = 0; i < productStoreRelaEntityList.size(); i++) {
- ProductStoreRelaEntity relaEntity = productStoreRelaEntityList.get(i);
- //新增库存操作记录
- StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
- storeMngChangeEntity.setChangeReason("共享库存变更,更新门店商品库存");
- storeMngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(relaEntity.getGoodsId())));
- storeMngChangeEntity.setStoreId(Integer.parseInt(String.valueOf(relaEntity.getStoreId())));
- storeMngChangeEntity.setMerchSn(goods.getMerchSn());
- storeMngChangeEntity.setCreateTime(new Date());
- storeMngChangeEntity.setModTime(new Date());
- storeMngChangeEntity.setCreaterSn(user.getUsername());
- storeMngChangeEntity.setModerSn(user.getUsername());
- storeMngChangeEntity.setIsValid(0);
- Integer orginalNum = relaEntity.getStockNum()==null?0:relaEntity.getStockNum();//原有库存
- if(goodsNumber != orginalNum) {
- if (orginalNum > goodsNumber) {
- storeMngChangeEntity.setChangeType(Dict.changeType.item_4.getItem());
- storeMngChangeEntity.setStoreChangeNum(orginalNum - goodsNumber);//变化数
- } else {
- storeMngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
- storeMngChangeEntity.setStoreChangeNum(goodsNumber - orginalNum);//变化数
- }
- storeMngChangeEntity.setStoreOriginalNum(orginalNum);//原库存数
- storeMngChangeEntity.setStoreValidNum(goodsNumber);//可用数
- storeMngChangeDao.save(storeMngChangeEntity);
- }
- }
- }
- Map cartMap = Maps.newHashMap();
- cartMap.put("goodsId",goods.getId());
- List<CartEntity> cartList = cartDao.queryList(cartMap);
- if (cartList != null && cartList.size() > 0) {
- for (CartEntity cartEntity : cartList) {
- // cartEntity.setRetailPrice(goods.getRetailPrice());
- // cartEntity.setMarketPrice(goods.getMarketPrice());
- cartEntity.setSku(goods.getSku());
- cartEntity.setGoodsName(goods.getName());
- cartEntity.setGoodsSn(goods.getGoodsSn());
- cartDao.update(cartEntity);
- }
- }
- // 修改商品轮播图
- goodsGalleryDao.deleteByGoodsId(goods.getId());
- for (int i=0;i<galleryEntityList.size();i++) {
- GoodsGalleryEntity galleryEntity =galleryEntityList.get(i);
- galleryEntity.setMerchSn(goods.getMerchSn());
- galleryEntity.setGoodsId(goods.getId());
- galleryEntity.setSortOrder((i+1));
- galleryEntity.setFileType("0");//图片
- goodsGalleryDao.save(galleryEntity);
- }
- if(org.apache.commons.lang.StringUtils.isNotEmpty(goods.getVideoUrl())){
- GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
- galleryEntity.setMerchSn(goods.getMerchSn());
- galleryEntity.setGoodsId(goods.getId());
- galleryEntity.setSortOrder(0);
- galleryEntity.setFileType("1");//视频
- galleryEntity.setImgUrl(goods.getVideoUrl());
- goodsGalleryDao.save(galleryEntity);
- }
- /*// 修改商品参数
- List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
- if (attributeEntityList != null && attributeEntityList.size() > 0) {
- for (GoodsAttributeEntity item : attributeEntityList) {
- if (item.getIsDelete() == 0) {
- if (item.getId() != null) {
- item.setMerchSn(goods.getMerchSn());
- goodsAttributeDao.update(item);
- } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNotEmpty(item.getValue())) {
- item.setGoodsId(goods.getId());
- item.setMerchSn(goods.getMerchSn());
- goodsAttributeDao.save(item);
- } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNullOrEmpty(item.getValue())) {
- throw new RRException("商品属性【" + attributeDao.queryObject(item.getAttributeId()).getName() + "】值不能为空!");
- } else if (item.getId() == null && item.getAttributeId() == null) {
- continue;
- }
- } else if (item.getIsDelete() == 1) {
- goodsAttributeDao.delete(item.getId());
- }
- }
- }*/
- // 修改产品
- ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goods.getId()),"");
- GoodsSpecificationEntity goodsSpecification = null;
- // 保税商品,普通货物暂不添加商品规格
- if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
- // 添加商品规格
- goodsSpecification = goodsSpecificationDao.queryByGoodsId(goods.getId());
- if(goodsSpecification != null) {
- goodsSpecification.setValue(goods.getCiqProdModel());
- goodsSpecificationDao.update(goodsSpecification);
- }else{
- goodsSpecification = new GoodsSpecificationEntity();
- goodsSpecification.setGoodsId(goods.getId());
- goodsSpecification.setValue(goods.getCiqProdModel());
- goodsSpecification.setSpecificationId(1);
- goodsSpecificationDao.save(goodsSpecification);
- }
- //更新门店商品是否有修改字段
- if(storeIds.length > 0){
- for(int i=0;i<storeIds.length;i++){
- updateLoadGoodsByStoreId(storeIds[i], user);
- }
- }
- if(product == null){
- product = new ProductEntity();
- product.setGoodsSn(goods.getGoodsSn());
- product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
- product.setGoodsSpecificationIds(goodsSpecification.getId()+"");
- product.setGoodsId(goods.getId());
- product.setGoodsNumber(goods.getGoodsNumber());
- product.setGoodsDefault(0);
- return productDao.save(product);
- }else{
- product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
- product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
- return productDao.update(product);
- }
- }
- return 1;
- }
- @Transactional
- @Override
- public void updateForImgUrl(GoodsEntity goodsEntity){
- // 修改商品
- goodsDao.update(goodsEntity);
- }
- @Override
- public List<GoodsEntity> queryByName(String storeId, String goodsName) {
- return goodsDao.queryByName(storeId, goodsName);
- }
- /**
- * 更新门店商品是否有修改字段
- * @param storeId
- * @param user
- */
- private void updateLoadGoodsByStoreId(Long storeId, SysUserEntity user){
- List<MerchUserEntity> list = merchUserDao.queryMerchUserByLoadGoods(storeId);
- for(MerchUserEntity entity : list) {
- entity.setIsLoadGoods("1");
- entity.setModerSn(user.getUsername());
- entity.setStoreId(Integer.valueOf(String.valueOf(storeId)));
- merchUserDao.updateStoreLoadGoodsById(entity);
- }
- }
- @Override
- public int delete(Integer id) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- GoodsEntity goodsEntity = goodsDao.queryObject(id);
- goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_1.getItem()));
- goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
- goodsEntity.setUpdateUserId(user.getUserId());
- goodsEntity.setUpdateTime(new Date());
- Map params = Maps.newHashMap();
- params.put("goodsId", id);
- List<GoodsGroupEntity> groupVos = goodsGroupDao.queryList(params);
- if (null != groupVos && groupVos.size() > 0) {
- for (GoodsGroupEntity groupVo : groupVos) {
- groupVo.setOpenStatus(3);
- goodsGroupDao.update(groupVo);
- }
- }
- return goodsDao.update(goodsEntity);
- }
- @Override
- @Transactional
- public int deleteBatch(Integer[] ids) {
- int result = 0;
- for (Integer id : ids) {
- result += delete(id);
- }
- return result;
- }
- @Override
- @Transactional
- public int back(Integer[] ids) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- int result = 0;
- for (Integer id : ids) {
- GoodsEntity goodsEntity = queryObject(id);
- goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
- goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
- goodsEntity.setUpdateUserId(user.getUserId());
- goodsEntity.setUpdateTime(new Date());
- result += goodsDao.update(goodsEntity);
- }
- return result;
- }
- @Override
- public int enSale(Integer id) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- GoodsEntity goodsEntity = queryObject(id);
- if (1 == goodsEntity.getIsOnSale()) {
- throw new RRException("此商品已处于上架状态!");
- }
- goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
- goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
- goodsEntity.setUpdateUserId(user.getUserId());
- goodsEntity.setUpdateTime(new Date());
- return goodsDao.update(goodsEntity);
- }
- @Override
- public int unSale(Integer id) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- GoodsEntity goodsEntity = queryObject(id);
- if (0 == goodsEntity.getIsOnSale()) {
- throw new RRException("此商品已处于下架状态!");
- }
- goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
- goodsEntity.setUpdateUserId(user.getUserId());
- goodsEntity.setUpdateTime(new Date());
- return goodsDao.update(goodsEntity);
- }
- @Override
- public int enSaleBatch(Integer[] ids) {
- int result = 0;
- SysUserEntity user = ShiroUtils.getUserEntity();
- for (Integer id : ids) {
- GoodsEntity goodsEntity = queryObject(id);
- goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
- goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
- goodsEntity.setUpdateUserId(user.getUserId());
- goodsEntity.setUpdateTime(new Date());
- result += goodsDao.update(goodsEntity);
- }
- return result;
- }
- @Override
- public int unSaleBatch(Integer[] ids) {
- int result = 0;
- SysUserEntity user = ShiroUtils.getUserEntity();
- for (Integer id : ids) {
- GoodsEntity goodsEntity = queryObject(id);
- goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
- goodsEntity.setUpdateUserId(user.getUserId());
- goodsEntity.setUpdateTime(new Date());
- result += goodsDao.update(goodsEntity);
- }
- return result;
- }
- @Override
- @Transactional
- public int uploadExcel(List<GoodsDto> goodsEntityList,int exportDataType) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- String merchSn = user.getMerchSn();
- boolean isFail = false;
- List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
- // failSuppGoodsSnList = new ArrayList<>(),
- failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),
- // failProdbarGoodsSnList = new ArrayList<>(),
- failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
- // failCateL2GoodsSnList = new ArrayList<>(),
- // failCateGoodsSnList = new ArrayList<>(),
- // failBrandGoodsSnList = new ArrayList<>(),
- // failFreightGoodsSnList = new ArrayList<>(),
- failMerchUserGoodsSnList = new ArrayList<>();
- List<String> failGoodsSnList = new ArrayList<>();
- List<String> failGoodsTypeList = new ArrayList<>();
- // List<String> failFreightList = new ArrayList<>();
- // 定义需要批量插入的list
- List<ProductEntity> insertProductList = new LinkedList<>();
- List<GoodsSpecificationEntity> insertSpecificationList = new LinkedList<>();
- List<MngChangeEntity> insertMngChangeList = new LinkedList<>();
- List<GoodsEntity> insertGoodsList = new LinkedList<>();
- List<SupplierEntity> insertSupplierList = new LinkedList<>();
- // 定义需要批量修改的list
- List<ProductEntity> updateProductList = new LinkedList<>();
- List<GoodsSpecificationEntity> updateSpecificationList = new LinkedList<>();
- List<GoodsEntity> updateGoodsList = new LinkedList<>();
- if (goodsEntityList != null && goodsEntityList.size() > 0) {
- for (int i = 0; i < goodsEntityList.size(); i++) {
- GoodsDto goodsDto = goodsEntityList.get(i);
- GoodsEntity goodsEntity = new GoodsEntity();
- Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
- ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
- builder.put("goodsSn", "商品编码");
- builder.put("thirdPartyMerchCode", "第三方商户代码");
- // builder.put("categoryName", "商品分类");
- builder.put("goodsBizType", "货品业务类型");
- builder.put("name", "商品名称");
- // builder.put("brandName", "商品品牌名称");
- // builder.put("defaultFreight", "运费");
- builder.put("isOnSaleStr", "上架");
- builder.put("goodsUnit", "商品单位");
- builder.put("isHotStr", "热销");
- builder.put("prodBarcode", "产品条码");
- // builder.put("marketPrice", "市场价");
- // builder.put("retailPrice", "零售价");
- builder.put("supplierName", "供应商");
- builder.put("goodsNumber", "商品总库存");
- R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- } else {
- if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
- // 海关信息,普通货物可不添加
- builder.put("goodsRate", "商品税率");
- builder.put("sku", "SKU");
- builder.put("brand", "产品品牌");
- builder.put("unitName", "计量单位");
- builder.put("oriCntName", "原产国");
- builder.put("cusGoodsCode", "海关商品编码");
- builder.put("ciqProdModel", "国检规格型号");
- builder.put("cusDeclEle", "海关申报要素");
- builder.put("cusRecCode", "海关备案编号");
- }
- r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- }
- }
- //业务类型校验
- if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
- if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
- || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
- || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
- isFail = true;
- failTypeGoodsSnList.add(goodsDto.getSku());
- }
- }
- ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
- if(thirdMerchantBizEntity != null){
- goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
- goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
- if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
- if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
- isFail = true;
- failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
- }
- }
- }else{//商户不存在
- isFail = true;
- failMerchGoodsSnList.add(goodsDto.getGoodsSn());
- }
- //校验商品信息是否已存在
- Map<String, Object> map = new HashMap<>();
- map.put("isSame", "true");
- map.put("sku", goodsDto.getSku());
- map.put("goodsSn", goodsDto.getGoodsSn());
- map.put("goodsBizType", goodsDto.getGoodsBizType());
- List<GoodsEntity> list = querySame(map);
- if (list != null && list.size() != 0) {
- // isFail = true;
- if(goodsDto.getSku()!=null) {
- failSameSkuList.add(goodsDto.getSku());
- }
- failGoodsSnList.add(goodsDto.getGoodsSn());
- failGoodsTypeList.add(goodsDto.getGoodsBizType());
- }
- goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
- //热销商品校验
- if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
- || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
- if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
- isFail = true;
- failHotGoodsSnList.add(goodsDto.getGoodsSn());
- }
- }
- if(thirdMerchantBizEntity != null) {
- SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
- if (supplierEntity == null) {
- //导入没有查到供货商,执行新增
- MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
- // if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
- // isFail = true;
- // failSuppGoodsSnList.add(goodsDto.getGoodsSn());
- // }
- supplierEntity = new SupplierEntity();
- supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
- supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
- supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
- supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
- supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
- supplierEntity.setIsShow("0");
- // TODO 这里改成批量插入 SupplierEntity
- // insertSupplierList.add(supplierEntity);
- //新增商品供货信息
- supplierDao.save(supplierEntity);
- // supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
- goodsEntity.setSupplierId(supplierEntity.getId());
- } else {
- goodsEntity.setSupplierId(supplierEntity.getId());
- }
- }
- //商品配置校验
- /*
- 先在redis在查询该品牌是否存在,如果存在获取品牌id,如果不存在,先新增该品牌,在将品牌存入到redis中,在获取品牌id
- */
- // 获取品牌唯一简码
- checkBrand(goodsDto, goodsEntity);
- // 获取二级分类id
- checkCategory(goodsDto, goodsEntity);
- if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
- SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
- if (sysCusUnitCodeEntity == null) {
- isFail = true;
- failUnitGoodsSnList.add(goodsDto.getGoodsSn());
- } else {
- goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
- }
- //原产国
- SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
- if (sysCusNationCodeEntity == null) {
- isFail = true;
- failNationGoodsSnList.add(goodsDto.getGoodsSn());
- } else {
- goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
- }
- if(goodsDto.getGoodsRate().indexOf("%") != -1){
- goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
- goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
- }else{
- goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())));
- }
- }
- goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
- goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
- // goodsEntity.setRetailPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getRetailPrice())));
- // goodsEntity.setMarketPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getMarketPrice())));
- goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
- goodsEntity.setSku(goodsDto.getSku());
- goodsEntity.setName(goodsDto.getName());
- goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
- goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
- goodsEntity.setBrand(goodsDto.getBrand());
- goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
- goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
- goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
- goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
- goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
- goodsEntity.setIsNew(0);
- goodsEntity.setUpdateUserId(user.getUserId());
- goodsEntity.setAddTime(new Date());
- goodsEntity.setCreateTime(new Date());
- goodsEntity.setUpdateTime(new Date());
- goodsEntity.setModTime(new Date());
- goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
- goodsEntity.setPlu(goodsDto.getPlu());
- goodsEntity.setMychemId(goodsDto.getMychemId());
- if(!isFail){
- GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
- MngChangeEntity mngChangeEntity = new MngChangeEntity();
- mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
- mngChangeEntity.setChangeReason("更新商户商品总库存");
- mngChangeEntity.setCreateTime(new Date());
- mngChangeEntity.setModTime(new Date());
- mngChangeEntity.setCreaterSn(user.getUsername());
- mngChangeEntity.setModerSn(user.getUsername());
- mngChangeEntity.setIsValid(0);
- mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
- if(goods!=null) {// 修改商品
- mngChangeEntity.setOriginalNum(goods.getGoodsNumber());//原库存数
- mngChangeEntity.setValidNum(goods.getGoodsNumber() + Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
- mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
- mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
- mngChangeEntity.setGoodsId(goods.getId().intValue());
- goodsEntity.setId(goods.getId());
- goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
- // TODO 这里改成批量修改 GoodsEntity
- // updateGoodsList.add(goodsEntity);
- goodsDao.update(goodsEntity);
- }else{
- mngChangeEntity.setOriginalNum(0);//原库存数
- mngChangeEntity.setValidNum(Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
- mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
- mngChangeEntity.setChangeType(Dict.changeType.item_2.getItem());
- goodsDao.save(goodsEntity);
- insertGoodsList.add(goodsEntity);
- mngChangeEntity.setGoodsId(goodsEntity.getId().intValue());
- }
- // TODO 这里改成批量插入 MngChangeEntity
- // mngChangeDao.save(mngChangeEntity);
- insertMngChangeList.add(mngChangeEntity);
- // // 保税商品修改各个门店商品价格
- // if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
- // List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goodsDto.getId());
- // if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
- // for (ProductStoreRelaEntity productStoreRela : productStoreRelaEntityList) {
- // productStoreRela.setMarketPrice(goodsEntity.getMarketPrice());
- // productStoreRela.setRetailPrice(goodsEntity.getRetailPrice());
- // productStoreRelaDao.update(productStoreRela);
- // }
- // }
- // }
- // 修改产品
- ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
- GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
- // 普通货物暂不添加商品规格
- if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
- // 添加商品规格
- GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
- if(specificationEntity == null) {
- goodsSpecification.setGoodsId(goodsEntity.getId());
- goodsSpecification.setValue(goodsEntity.getCiqProdModel());
- goodsSpecification.setSpecificationId(1);
- // TODO 这里改成批量插入 GoodsSpecificationEntity
- goodsSpecificationDao.save(goodsSpecification);
- // insertSpecificationList.add(goodsSpecification);
- }else {
- goodsSpecification.setValue(goodsDto.getCiqProdModel());
- goodsSpecification.setId(specificationEntity.getId());
- // TODO 这里改成批量更新 GoodsSpecificationEntity
- // goodsSpecificationDao.update(goodsSpecification);
- updateSpecificationList.add(goodsSpecification);
- }
- if(product == null){
- product = new ProductEntity();
- product.setGoodsSn(goodsDto.getGoodsSn());
- product.setGoodsId(goodsEntity.getId());
- product.setGoodsDefault(0);
- product.setGoodsNumber(goodsEntity.getGoodsNumber());
- product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
- product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
- // TODO 这里改成批量插入 ProductEntity
- // insertProductList.add(product);
- productDao.save(product);
- }else{
- product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
- product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
- // TODO 这里改成批量更新 ProductEntity
- updateProductList.add(product);
- // productDao.update(product);
- }
- }
- }
- }
- // 批量插入数据
- // if(insertProductList != null && insertProductList.size() > 0) {
- // // 长度限制,如果大于50,就分多次插入
- // if(insertProductList.size() > 50){
- // List<List<ProductEntity>> partition = Lists.partition(insertProductList, 50);
- // for (List<ProductEntity> productEntities : partition) {
- // productDao.saveBatch(productEntities);
- // }
- // }else{
- // productDao.saveBatch(insertProductList);;
- //
- // }
- // }
- // if(insertSpecificationList != null && insertSpecificationList.size() > 0) {
- // goodsSpecificationDao.saveBatch(insertSpecificationList);
- // }
- if(insertMngChangeList != null && insertMngChangeList.size() > 0 ){
- if(insertMngChangeList.size() > 50){
- List<List<MngChangeEntity>> partition = Lists.partition(insertMngChangeList, 50);
- for (List<MngChangeEntity> mngChangeEntities : partition) {
- mngChangeDao.saveBatch(mngChangeEntities);
- }
- }else{
- mngChangeDao.saveBatch(insertMngChangeList);
- }
- }
- // if(insertGoodsList != null && insertGoodsList.size() > 0 ){
- // goodsDao.saveBatch(insertGoodsList);
- // }
- // if(insertSupplierList != null && insertSupplierList.size() > 0 ){
- // if(insertSupplierList.size() > 50){
- // List<List<SupplierEntity>> partition = Lists.partition(insertSupplierList, 50);
- // for (List<SupplierEntity> supplierEntities : partition) {
- // supplierDao.saveBatch(supplierEntities);
- // }
- // }else{
- // supplierDao.saveBatch(insertSupplierList);
- //
- // }
- // }
- // 批量更新数据
- if(updateProductList != null && updateProductList.size() > 0 ){
- if(updateProductList.size() > 50){
- List<List<ProductEntity>> partition = Lists.partition(updateProductList, 50);
- for (List<ProductEntity> productEntities : partition) {
- productDao.updateBatch(productEntities);
- }
- }else{
- productDao.updateBatch(updateProductList);
- }
- }
- if(updateSpecificationList != null && updateSpecificationList.size() > 0 ){
- if(updateSpecificationList.size() > 50){
- List<List<GoodsSpecificationEntity>> partition = Lists.partition(updateSpecificationList, 50);
- for (List<GoodsSpecificationEntity> goodsSpecificationEntities : partition) {
- goodsSpecificationDao.updateBatch(goodsSpecificationEntities);
- }
- }else{
- goodsSpecificationDao.updateBatch(updateSpecificationList);
- }
- }
- // if(updateGoodsList != null && updateGoodsList.size() > 0 ){
- // if(updateGoodsList.size() > 50){
- // List<List<GoodsEntity>> partition = Lists.partition(updateGoodsList, 50);
- // for (List<GoodsEntity> goodsEntities : partition) {
- // goodsDao.updateBatch(goodsEntities);
- // }
- // }else{
- // goodsDao.updateBatch(updateGoodsList);
- // }
- // }
- ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
- exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
- exportExceptionDataEntity.setUserId(user.getUserId().intValue());
- exportExceptionDataEntity.setCreateTime(new Date());
- exportExceptionDataEntity.setModTime(new Date());
- exportExceptionDataEntity.setMerchSn(merchSn);
- exportExceptionDataEntity.setStoreId(user.getStoreId());
- if(exportDataType == 1) {
- exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
- }else{
- exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
- }
- if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- // 将插入的商品和更新的商品放到一个list中
- List<GoodsEntity> goodsEntities = new LinkedList<>();
- goodsEntities.addAll(insertGoodsList);
- goodsEntities.addAll(updateGoodsList);
- List<KtoEccsEntity> ktoEccsEntities = new LinkedList<>();
- if(goodsEntities.size() > 0){
- for (GoodsEntity goodsEntity : goodsEntities) {
- KtoEccsEntity ktoEccsEntity = new KtoEccsEntity();
- ktoEccsEntity.setRequestData(JSON.toJSONString(goodsEntity));
- ktoEccsEntity.setRequestType("01");
- ktoEccsEntity.setSendStatus("00");
- ktoEccsEntity.setCreaterSn(user.getUserId()+"");
- ktoEccsEntity.setCreateTime(new Date());
- ktoEccsEntities.add(ktoEccsEntity);
- }
- }
- if(ktoEccsEntities.size() > 0){
- if(ktoEccsEntities.size() > 50){
- List<List<KtoEccsEntity>> partition = Lists.partition(ktoEccsEntities, 50);
- for (List<KtoEccsEntity> ktoEccs : partition) {
- ktoEccsService.saveBatch(ktoEccs);
- }
- }else{
- ktoEccsService.saveBatch(ktoEccsEntities);
- }
- }
- }else{
- throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
- }
- return 1;
- }
- private void checkCategory(GoodsDto goodsDto, GoodsEntity goodsEntity) {
- String secondLevel = goodsDto.getSecondLevel(); // 二级分类名称
- Map<String, String> categoryCache = JedisUtil.getMap(secondLevel);
- if(categoryCache != null){
- String categoryId = categoryCache.get("categoryId");
- String level = categoryCache.get("level");
- if(categoryId == null){
- CategoryEntity category = categoryDao.queryByName(secondLevel);
- if (category == null) {
- // 将该id存入带缓存中
- Map<String,String> categoryCacheData = new HashMap<>();
- categoryCacheData.put("level",Dict.Level.item_L2.getItem());
- // 查询数据库中是否有一级分类
- String firstLevel = goodsDto.getFirstLevel();
- CategoryEntity firstCategory = categoryDao.queryByName(firstLevel);
- if(firstCategory == null){
- // 一级分类不存在
- // 新增一级分类
- CategoryEntity firstCategoryEntity = initCategory(firstLevel, 0, Dict.Level.item_L1);
- categoryDao.save(firstCategoryEntity);
- // 新增二级分类
- CategoryEntity secondCategoryEntity = initCategory(secondLevel, firstCategoryEntity.getId(), Dict.Level.item_L2);
- categoryDao.save(secondCategoryEntity);
- categoryId = secondCategoryEntity.getId()+"";
- }else{
- // 新增二级分类
- CategoryEntity saveCategoryEntity = initCategory(secondLevel, firstCategory.getId(), Dict.Level.item_L2);
- categoryDao.save(saveCategoryEntity);
- categoryId = saveCategoryEntity.getId()+"";
- }
- categoryCacheData.put("categoryId",categoryId);
- JedisUtil.setMap(secondLevel,categoryCacheData,0);
- goodsEntity.setCategoryId(Integer.parseInt(categoryId));
- }else if(category != null && Dict.Level.item_L2.getItem().equals(category.getLevel())){
- // 缓存中没有,数据库中有,直接存入数据库中查询到的数据
- goodsEntity.setCategoryId(category.getId());
- // 将该id存入带缓存中
- Map<String,String> categoryCacheData = new HashMap<>();
- categoryCacheData.put("level",Dict.Level.item_L2.getItem());
- categoryCacheData.put("categoryId",category.getId()+"");
- JedisUtil.setMap(secondLevel,categoryCacheData,0);
- }else{
- throw new RuntimeException("该分类不是二级分类,请检查,对应sku是:"+ goodsDto.getSku()+",分类名称为:"+ goodsDto.getSecondLevel());
- }
- }else if(Dict.Level.item_L2.getItem().equals(level)){
- // 二级分类id在缓存中有,直接存入商品
- goodsEntity.setCategoryId(Integer.parseInt(categoryId));
- }else {
- throw new RuntimeException("该分类不是二级分类,请检查,对应sku是:"+ goodsDto.getSku()+",分类名称为:"+ goodsDto.getSecondLevel());
- }
- }else {
- String categoryId = "";
- CategoryEntity category = categoryDao.queryByName(secondLevel);
- if (category == null) {
- // 将该id存入带缓存中
- Map<String,String> categoryCacheData = new HashMap<>();
- categoryCacheData.put("level",Dict.Level.item_L2.getItem());
- // 查询数据库中是否有一级分类
- String firstLevel = goodsDto.getFirstLevel();
- CategoryEntity firstCategory = categoryDao.queryByName(firstLevel);
- if(firstCategory == null){
- // 一级分类不存在
- // 新增一级分类
- CategoryEntity firstCategoryEntity = initCategory(firstLevel, 0, Dict.Level.item_L1);
- categoryDao.save(firstCategoryEntity);
- // 新增二级分类
- CategoryEntity secondCategoryEntity = initCategory(secondLevel, firstCategoryEntity.getId(), Dict.Level.item_L2);
- categoryDao.save(secondCategoryEntity);
- categoryId = secondCategoryEntity.getId()+"";
- }else{
- // 新增二级分类
- CategoryEntity saveCategoryEntity = initCategory(secondLevel, firstCategory.getId(), Dict.Level.item_L2);
- categoryDao.save(saveCategoryEntity);
- categoryId = saveCategoryEntity.getId()+"";
- }
- categoryCacheData.put("categoryId",categoryId);
- JedisUtil.setMap(secondLevel,categoryCacheData,0);
- goodsEntity.setCategoryId(Integer.parseInt(categoryId));
- }else if(category != null && Dict.Level.item_L2.getItem().equals(category.getLevel())){
- // 缓存中没有,数据库中有,直接存入数据库中查询到的数据
- goodsEntity.setCategoryId(category.getId());
- // 将该id存入带缓存中
- Map<String,String> categoryCacheData = new HashMap<>();
- categoryCacheData.put("level",Dict.Level.item_L2.getItem());
- categoryCacheData.put("categoryId",category.getId()+"");
- JedisUtil.setMap(secondLevel,categoryCacheData,0);
- }else{
- throw new RuntimeException("该分类不是二级分类,请检查,对应sku是:"+ goodsDto.getSku()+",分类名称为:"+ goodsDto.getSecondLevel());
- }
- }
- }
- private void checkBrand(GoodsDto goodsDto, GoodsEntity goodsEntity) {
- String uniqueIdentifier = goodsDto.getUniqueIdentifier();
- String brandName = goodsDto.getBrand();
- Map<String, String> brandCache = JedisUtil.getMap(uniqueIdentifier);
- if(brandCache != null) {
- String brandId = brandCache.get("brandId");
- if (brandId == null) {
- Map<String, String> brandCacheData = new HashMap<>();
- // 数据库里面查询
- BrandEntity queryBrand = brandService.queryByUniqueIdentifier(uniqueIdentifier);
- if (queryBrand == null) {
- BrandEntity brandEntity = new BrandEntity();
- brandEntity.setName(brandName);
- brandEntity.setUniqueIdentifier(uniqueIdentifier);
- brandEntity.setSimpleDesc(brandName);
- brandEntity.setIsShow(1);
- brandEntity.setIsNew(0);
- brandService.save(brandEntity);
- brandCacheData.put("brandId", brandEntity.getId() + "");
- brandCacheData.put("brandName", brandName);
- goodsEntity.setBrandId(brandEntity.getId());
- } else {
- brandCacheData.put("brandId", queryBrand.getId() + "");
- brandCacheData.put("brandName", queryBrand.getName());
- goodsEntity.setBrandId(queryBrand.getId());
- }
- JedisUtil.setMap(uniqueIdentifier, brandCacheData, 0);
- } else {
- goodsEntity.setBrandId(Integer.parseInt(brandId));
- }
- }else{
- Map<String, String> brandCacheData = new HashMap<>();
- // 数据库里面查询
- BrandEntity queryBrand = brandService.queryByUniqueIdentifier(uniqueIdentifier);
- if (queryBrand == null) {
- BrandEntity brandEntity = new BrandEntity();
- brandEntity.setName(brandName);
- brandEntity.setUniqueIdentifier(uniqueIdentifier);
- brandEntity.setSimpleDesc(brandName);
- brandEntity.setIsShow(1);
- brandEntity.setIsNew(0);
- brandService.save(brandEntity);
- brandCacheData.put("brandId", brandEntity.getId() + "");
- brandCacheData.put("brandName", brandName);
- goodsEntity.setBrandId(brandEntity.getId());
- } else {
- brandCacheData.put("brandId", queryBrand.getId() + "");
- brandCacheData.put("brandName", queryBrand.getName());
- goodsEntity.setBrandId(queryBrand.getId());
- }
- JedisUtil.setMap(uniqueIdentifier, brandCacheData, 0);
- }
- }
- private CategoryEntity initCategory(String firstLevel, int parentId, Dict.Level item) {
- CategoryEntity firstCategoryEntity = new CategoryEntity();
- firstCategoryEntity.setName(firstLevel);
- firstCategoryEntity.setParentId(parentId);
- firstCategoryEntity.setIsShow(1);
- firstCategoryEntity.setFrontDesc(firstLevel);
- firstCategoryEntity.setType(0);
- firstCategoryEntity.setLevel(item.getItem());
- return firstCategoryEntity;
- }
- @Override
- @Transactional
- public int uploadExcelByCover(List<GoodsDto> goodsEntityList, int exportDataType) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- String merchSn = user.getMerchSn();
- boolean isFail = false;
- List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
- failSuppGoodsSnList = new ArrayList<>(),
- failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),
- failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
- failMerchUserGoodsSnList = new ArrayList<>();
- // List<String> failGoodsSnList = new ArrayList<>();
- List<String> failGoodsTypeList = new ArrayList<>();
- if (goodsEntityList != null && goodsEntityList.size() > 0) {
- for (int i = 0; i < goodsEntityList.size(); i++) {
- GoodsDto goodsDto = goodsEntityList.get(i);
- GoodsEntity goodsEntity = new GoodsEntity();
- Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
- ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
- builder.put("goodsSn", "商品编码");
- builder.put("thirdPartyMerchCode", "第三方商户代码");
- builder.put("goodsBizType", "货品业务类型");
- builder.put("name", "商品名称");
- builder.put("isOnSaleStr", "上架");
- builder.put("goodsUnit", "商品单位");
- builder.put("isHotStr", "热销");
- builder.put("prodBarcode", "产品条码");
- builder.put("supplierName", "供应商");
- builder.put("goodsNumber", "商品总库存");
- R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- } else {
- if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
- // 海关信息,普通货物可不添加
- builder.put("goodsRate", "商品税率");
- builder.put("sku", "SKU");
- builder.put("brand", "产品品牌");
- builder.put("unitName", "计量单位");
- builder.put("oriCntName", "原产国");
- builder.put("cusGoodsCode", "海关商品编码");
- builder.put("ciqProdModel", "国检规格型号");
- builder.put("cusDeclEle", "海关申报要素");
- builder.put("cusRecCode", "海关备案编号");
- }
- r = ValidatorUtil.isEmpty(builder.build(), valideDate);
- if (Integer.valueOf(r.get("code").toString()) != 0) {
- throw new RRException(r.get("msg").toString());
- }
- }
- //业务类型校验
- if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
- if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
- || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
- || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
- isFail = true;
- failTypeGoodsSnList.add(goodsDto.getSku());
- }
- }
- ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
- if(thirdMerchantBizEntity != null){
- goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
- goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
- if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
- if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
- isFail = true;
- failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
- }
- }
- }else{//商户不存在
- isFail = true;
- failMerchGoodsSnList.add(goodsDto.getGoodsSn());
- }
- //校验商品信息是否已存在
- Map<String, Object> map = new HashMap<>();
- map.put("isSame", "true");
- map.put("sku", goodsDto.getSku());
- map.put("goodsSn", goodsDto.getGoodsSn());
- map.put("goodsBizType", goodsDto.getGoodsBizType());
- // List<GoodsEntity> list = querySame(map);
- // if (list != null && list.size() != 0) {
- // isFail = true;
- // if(goodsDto.getSku()!=null) {
- // failSameSkuList.add(goodsDto.getSku());
- // }
- // failGoodsSnList.add(goodsDto.getGoodsSn());
- // failGoodsTypeList.add(goodsDto.getGoodsBizType());
- // }
- //校验产品条码是否存在
- goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
- //热销商品校验
- if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
- || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
- if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
- isFail = true;
- failHotGoodsSnList.add(goodsDto.getGoodsSn());
- }
- }
- if(thirdMerchantBizEntity != null) {
- SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
- if (supplierEntity == null) {
- //导入没有查到供货商,执行新增
- MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
- if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
- isFail = true;
- failSuppGoodsSnList.add(goodsDto.getGoodsSn());
- }
- supplierEntity = new SupplierEntity();
- supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
- supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
- supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
- supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
- supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
- supplierEntity.setIsShow("0");
- supplierDao.save(supplierEntity);
- goodsEntity.setSupplierId(supplierEntity.getId());
- } else {
- goodsEntity.setSupplierId(supplierEntity.getId());
- }
- }
- if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
- SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
- if (sysCusUnitCodeEntity == null) {
- isFail = true;
- failUnitGoodsSnList.add(goodsDto.getGoodsSn());
- } else {
- goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
- }
- //原产国
- SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
- if (sysCusNationCodeEntity == null) {
- isFail = true;
- failNationGoodsSnList.add(goodsDto.getGoodsSn());
- } else {
- goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
- }
- if(goodsDto.getGoodsRate().indexOf("%") != -1){
- goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
- }
- goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
- }
- goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
- goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
- goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
- goodsEntity.setSku(goodsDto.getSku());
- goodsEntity.setName(goodsDto.getName());
- goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
- goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
- goodsEntity.setBrand(goodsDto.getBrand());
- goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
- goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
- goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
- goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
- goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
- goodsEntity.setIsNew(0);
- goodsEntity.setUpdateUserId(user.getUserId());
- goodsEntity.setAddTime(new Date());
- goodsEntity.setCreateTime(new Date());
- goodsEntity.setUpdateTime(new Date());
- goodsEntity.setModTime(new Date());
- goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
- if(!isFail){
- GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
- MngChangeEntity mngChangeEntity = new MngChangeEntity();
- mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
- mngChangeEntity.setChangeReason("更新商户商品总库存");
- mngChangeEntity.setCreateTime(new Date());
- mngChangeEntity.setModTime(new Date());
- mngChangeEntity.setCreaterSn(user.getUsername());
- mngChangeEntity.setModerSn(user.getUsername());
- mngChangeEntity.setIsValid(0);
- mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
- if(goods!=null) {// 修改商品
- mngChangeEntity.setOriginalNum(goods.getGoodsNumber());//原库存数
- mngChangeEntity.setValidNum(goods.getGoodsNumber() + Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
- mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
- mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
- mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goods.getId())));
- goodsEntity.setId(goods.getId());
- goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
- goodsDao.update(goodsEntity);
- }else{
- mngChangeEntity.setOriginalNum(0);//原库存数
- mngChangeEntity.setValidNum(Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
- mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
- mngChangeEntity.setChangeType(Dict.changeType.item_2.getItem());
- goodsDao.save(goodsEntity);
- mngChangeEntity.setGoodsId(goodsEntity.getId().intValue());
- }
- mngChangeDao.save(mngChangeEntity);
- // 修改产品
- ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
- GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
- // 普通货物暂不添加商品规格
- if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
- // 添加商品规格
- GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
- if(specificationEntity == null) {
- goodsSpecification.setGoodsId(goodsEntity.getId());
- goodsSpecification.setValue(goodsEntity.getCiqProdModel());
- goodsSpecification.setSpecificationId(1);
- goodsSpecificationDao.save(goodsSpecification);
- }else {
- goodsSpecification.setValue(goodsDto.getCiqProdModel());
- goodsSpecification.setId(specificationEntity.getId());
- goodsSpecificationDao.update(goodsSpecification);
- }
- if(product == null){
- product = new ProductEntity();
- product.setGoodsSn(goodsDto.getGoodsSn());
- product.setGoodsId(goodsEntity.getId());
- product.setGoodsDefault(0);
- product.setGoodsNumber(goodsEntity.getGoodsNumber());
- product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
- product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
- productDao.save(product);
- }else{
- product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
- product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
- productDao.update(product);
- }
- }
- }
- }
- ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
- exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
- exportExceptionDataEntity.setUserId(user.getUserId().intValue());
- exportExceptionDataEntity.setCreateTime(new Date());
- exportExceptionDataEntity.setModTime(new Date());
- exportExceptionDataEntity.setMerchSn(merchSn);
- exportExceptionDataEntity.setStoreId(user.getStoreId());
- if(exportDataType == 1) {
- exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
- }else{
- exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
- }
- if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- // if(failGoodsSnList != null && failGoodsSnList.size() > 0){
- // if(failSameSkuList.size()>0) {
- // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
- // failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
- // goodsUtils.save(exportExceptionDataEntity);
- // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- // }else{
- // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
- // failGoodsTypeList + "】的商品信息");
- // goodsUtils.save(exportExceptionDataEntity);
- // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- // }
- // }
- if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- }else{
- throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
- }
- return 1;
- }
- @Override
- public GoodsDetailsDto queryGoodsDetailsByProdBarcode(String prodBarcode, String storeId,String sku) {
- return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId,sku);
- }
- @Override
- public GoodsPanoramaDto searchGoodsPanoramaDtoByKeyword(String keyword) {
- return goodsDao.searchGoodsPanoramaDtoByKeyword(keyword);
- }
- @Override
- public List<GoodsEntity> queryExportList(Map<String, Object> params) {
- return goodsDao.queryExportList(params);
- }
- /**
- * 查出pdf需要的需要
- *
- * @param sku 商品sku
- * @param storeId
- * @param prodBarcode
- * @return
- */
- @Override
- public PDFGoodsDto queryForPDFData(String sku, String storeId, String prodBarcode) {
- return goodsDao.queryForPDFData(sku,storeId,prodBarcode);
- }
- /**
- * 查询产品价格
- * 改进后的逻辑:
- * @param prodBarcode
- * @param storeId
- * @return
- */
- @Override
- @Transactional
- public Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId,String sku) {
- /**
- * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
- */
- GoodsDetailsDto goods = queryGoodsDetailsByProdBarcode(prodBarcode,storeId,sku);
- if(goods == null) {
- return null;
- }
- /*
- * 2. 查询海仓仓库系统,判断库存是否足够
- * TODO 测试的时候注释,海控仓库系统没有测试环境,上生产时放开注释
- * */
- /*WareQueryStockParamDTO wareQueryStockParamDTO = new WareQueryStockParamDTO();
- List<Criteria> criteriaList = new ArrayList<>();
- Criteria criteria = new Criteria();
- criteria.setItemId(goods.getProdBarcode());
- criteria.setItemCode(goods.getSku());
- criteriaList.add(criteria);
- wareQueryStockParamDTO.setCriteriaList(criteriaList);
- String queryWarehouseStockResponse = haiKongWarehouseTemplate.queryWarehouseStock(wareQueryStockParamDTO);
- log.info("调用海控仓库系统,请求参数,门店:{}、商品条码:{}、商品编码:{},响应数据:{}", storeId, prodBarcode, sku, queryWarehouseStockResponse);
- if (org.springframework.util.StringUtils.isEmpty(queryWarehouseStockResponse)) {
- log.error("调用库存系统接口出现错误!返回结果为空!");
- throw new ServiceException("调用库存系统接口出现错误!");
- }
- WareQueryStockResponseDTO wareQueryStockResponseDTO = JacksonUtil.fromStringJson(queryWarehouseStockResponse, WareQueryStockResponseDTO.class);
- if (Objects.isNull(wareQueryStockResponseDTO)) {
- log.error("解析一步达库存系统响应数据出现错误!请求响应结果:{}", queryWarehouseStockResponse);
- throw new ServiceException("解析一步达库存系统响应数据出现错误!");
- }
- // 校验库存
- WareQueryStockResponseDTO.WareQueryStockResponseItemDTO itemDTO = wareQueryStockResponseDTO.getItems().get(0);
- // 仓库可用库存
- int wareQuantity = itemDTO.getQuantity() - itemDTO.getLockQuantity();
- // 海控展销店出区数
- Integer exitRegionNumber = goods.getExitRegionNumber();
- // 门店库存
- String stockNum = goods.getStockNum();
- // 扫码只会扫一件商品,保税仓库存 + 展销店库存 - 出区数 >= 购买数
- if (!((wareQuantity + Integer.parseInt(stockNum) - exitRegionNumber) >= 1)) {
- // 库存不足
- log.error("商品条码:【{}】,sku:【{}】,门店ID:【{}】,该商品库存不足!", prodBarcode, sku, storeId);
- throw new ServiceException(String.format("商品条码:【%s】,sku:【%s】,门店ID:【%s】,该商品库存不足!", prodBarcode, sku, storeId));
- }*/
- goods.setDiscountedPrice(new BigDecimal(0));
- BigDecimal retailPrice = goods.getRetailPrice();
- goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
- Map<String,Object> skuActivitiesMap = new HashMap<>();
- // /**
- // * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
- // * 参数: 当前时间 门店id
- // */
- // /*List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId,format.format(new Date()));
- //
- // if(mkActivitiesEntityList == null || mkActivitiesEntityList.size() == 0){
- // // 计算税费
- // GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
- // BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
- // goods.setGoodstaxes(tax.toString());
- // skuActivitiesMap.put("goods",goods);
- // return skuActivitiesMap;
- // }
- //
- //
- //
- // // 遍历活动集合,查询有哪些活动是开启的
- // boolean daily = false,coupon = false,combinationPrice = false
- // ,discount = false,fullGift = false,fullReduction = false
- // ,getOneFree = false,promotion = false,halfPrice = false;
- //
- // List<String> topicList = new ArrayList<>(); // 记录有哪些营销活动的topic
- // Map<String,String> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
- // // 将所有的营销活动新增到list中
- // for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
- // topicList.add(mkActivitiesEntity.getMkaTopic());
- // String mkaId = mkaIdMap.putIfAbsent(mkActivitiesEntity.getMkaTopic(), mkActivitiesEntity.getMkaId()+"");
- // if(StringUtils.isNotEmpty(mkaId)){
- //// mkaId = "'"+mkaId + "','" + mkActivitiesEntity.getMkaId()+"'";
- // mkaId += String.format(",%s",mkActivitiesEntity.getMkaId());
- // mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkaId);
- // }
- // }
- // // 判断有哪些营销活动
- // if(topicList.contains("zhjsp")) // 组合价
- // combinationPrice = true;
- // if(topicList.contains("dz")) // 打折
- // discount = true;
- // if(topicList.contains("mz")) //满赠
- // fullGift = true;
- // if(topicList.contains("mj")) // 满减
- // fullReduction = true;
- // if(topicList.contains("mysy")) // 买一送一
- // getOneFree = true;
- // if(topicList.contains("rchd")) // 日常活动
- // daily = true;
- // if(topicList.contains("yhq")) // 优惠券
- // coupon = true;
- // if(topicList.contains("lscx")) // 临时促销
- // promotion = true;
- // if(topicList.contains("drjbj"))
- // halfPrice = true;
- //
- //
- // // 获取未优惠前的商品价格
- // retailPrice = goods.getRetailPrice();
- //
- //
- // // 根据条码查询商品品牌名称 mall_brand mall_product_store_rela mall_goods
- // String brandName = goods.getBrand();
- //
- // *//**
- // * 优先级:临时促销 》买一送一=满赠 》 组合价=日常活动 》 打折=满减 》 优惠券
- // *//*
- //
- // *//**
- // * 组合价的做法就是将参与组合的条码带到收银端
- // * 现根据营销活动id跟条形码,查询有哪些参与该条码组合的商品
- // *
- // *
- // * TODO
- // *//*
- // if(combinationPrice){
- // String mkaId = mkaIdMap.get("zhjsp");
- // Map<String,Object> param = new HashMap<>();
- // param.put("mkaId",mkaId);
- // param.put("prodBarcode",prodBarcode);
- // List<MkActivitiesCombinationPriceEntity> combinationPriceList = combinationPriceService.queryList(param);
- // if(combinationPriceList != null && combinationPriceList.size() > 0) {
- // Map<String, List<MkActivitiesCombinationPriceEntity>> collect =
- // combinationPriceList.stream().collect(Collectors.groupingBy(MkActivitiesCombinationPriceEntity::getCombinationType));
- //
- // skuActivitiesMap.put("zhjsp",collect);
- // }
- // }
- //
- //
- //
- // format = new SimpleDateFormat("yyyy-MM-dd");
- // String nowTime = format.format(new Date());
- // *//**
- // * 满减可能是跟着条码,也可能跟着品牌
- // * 根据商品品牌跟商品条码去查询是否有优惠金额
- // *
- // * 满足金额 购买商品条码 赠品条码
- // *
- // *//*
- // Map<String,Object> fullReductionMap = new HashMap<>();
- // if(fullReduction){
- // String mkaId = mkaIdMap.get("mj");
- // MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
- // if(fullReductionEntity != null) {
- // if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
- // // 跟着品牌走
- // fullReductionMap.put(brandName,fullReductionEntity);
- // }else{
- // // 跟着条码走
- // fullReductionMap.put(fullReductionEntity.getBarcode(), fullReductionEntity);
- // }
- // skuActivitiesMap.put("mj",fullReductionMap);
- // }
- // }
- //
- // *//**
- // * 满赠可能是跟着条码,也可能跟着品牌
- // * 根据商品品牌跟商品条码去查询是否有满赠
- // * 1.先扫买的商品,然后查询出赠送的商品条码
- // * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
- // * 满足的金额 购买的商品条码或者品牌 赠送的商品条码
- // * TODO
- // *//*
- // Map<String,Object> fullGiftMap = new HashMap<>();
- // if(fullGift){
- // String mkaId = mkaIdMap.get("mz");
- // MkActivitiesFullGiftEntity giftEntity = fullGiftService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
- // if(giftEntity != null) {
- // if(giftEntity.getProductBrand() != null){
- // // 跟着品牌走
- // fullGiftMap.put(brandName,giftEntity);
- // }else{
- // // 跟着条码走
- // fullGiftMap.put(giftEntity.getBarcode(), giftEntity);
- // }
- // skuActivitiesMap.put("mz",fullGiftMap);
- // }
- // }
- //
- // *//**
- // * 买一送一可能是跟着条码,也可能跟着品牌
- // * 根据商品品牌跟商品条码去查询是否有送的商品
- // * 有两个场景
- // * 1.先扫买的商品,然后查询出赠送的商品条码
- // * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
- // * 所以就需要一个map
- // * key为购买的商品条码或者商品品牌 value为赠送的商品条码
- // * 但是品牌是根据条码查询的,所以最终map里面的结构是
- // * key 商品条码 value 赠品条码
- // *//*
- // if(getOneFree){
- // String mkaId = mkaIdMap.get("mysy");
- // MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
- // if(getOneFreeGoodsEntity != null){
- // if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
- // getOneFreeGoodsEntity.setBrand(false);
- // skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
- // }else{
- // getOneFreeGoodsEntity.setBrand(true);
- // skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
- // }
- //
- // }
- // }
- //
- //
- // // 第二份半价
- // if(halfPrice){
- // String mkaId = mkaIdMap.get("drjbj");
- // MkActivitiesHalfPriceEntity activitiesHalfPriceEntity = halfPriceService.queryByCodeOrBrand(mkaId,prodBarcode);
- // if(activitiesHalfPriceEntity != null){
- // skuActivitiesMap.put("drjbj",activitiesHalfPriceEntity);
- //
- // }
- //
- // }
- //
- //
- // // --------------------------------------------------------------------------------------
- //
- // *//**
- // * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
- // *//*
- //
- // if(coupon){
- // String mkaId = mkaIdMap.get("yhq");
- // MkActivitiesCouponEntity couponEntity = couponService.queryByBarCode(mkaId,prodBarcode,nowTime);
- // if(couponEntity != null){ // 优惠券码,优惠金额
- // Map<String,Object> returnMap = new HashMap<>();
- // returnMap.put(couponEntity.getCouponSn() , couponEntity.getCouponPrice());
- // skuActivitiesMap.put("yhq",returnMap);
- // }
- // }
- //
- //
- // *//**
- // * 打折的价格是与条形码对应的,所以需要根据条形码和营销方式id去查询活动价格
- // *//*
- //
- // if(discount){
- // String mkaId = mkaIdMap.get("dz");
- // MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
- // // TODO 可能会直接替代产品价格
- // if (discountEntity != null) {
- // goods.setActualPaymentAmount(discountEntity.getActivityPrice());
- // goods.setRetailPrice(discountEntity.getActivityPrice());
- //
- // goods.setActivity("打折");
- // }
- // }
- //
- //
- // *//**
- // * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
- // *//*
- // if(daily){
- // String mkaId = mkaIdMap.get("rchd");
- // MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
- // if(dailyActivitiesEntity != null){
- // goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
- // goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
- //
- // goods.setActivity("日常活动");
- //
- // }
- // }
- //
- //
- // *//**
- // * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
- // *//*
- // if(promotion){
- // String mkaId = mkaIdMap.get("lscx");
- // MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
- // // 如果该商品存在临时促销,直接替换活动价格
- // if(promotionEntity != null){
- // goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
- // goods.setRetailPrice(promotionEntity.getActivityPrice());
- //
- // goods.setActivity("临时促销");
- //
- // }
- // }*/
- // 计算税费
- GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
- goods.setGoodstaxes(tax.toString());
- goods.setSellVolume(1);
- skuActivitiesMap.put("goods",goods);
- return skuActivitiesMap;
- }
- @Override
- public List<Map<String,Object>> selectSkuDetails(String prodBarcode, String storeId) {
- /**
- * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
- */
- List<GoodsDetailsDto> goodsList = goodsDao.queryGoodsSkuList(prodBarcode,storeId);
- List<Map<String,Object>> mapList = new ArrayList<>();
- if (goodsList == null) {
- return null;
- }
- for(GoodsDetailsDto goods : goodsList){
- mapList.add(selectGetSkuDetails(goods,prodBarcode,storeId));
- }
-
- return mapList;
- }
- public Map<String,Object> selectGetSkuDetails(GoodsDetailsDto goods,String prodBarcode, String storeId) {
- /**
- * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
- */
- goods.setDiscountedPrice(new BigDecimal(0));
- BigDecimal retailPrice = goods.getRetailPrice();
- goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
- Map<String,Object> skuActivitiesMap = new HashMap<>();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- /**
- * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
- * 参数: 当前时间 门店id
- */
- List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId,format.format(new Date()));
- if(mkActivitiesEntityList == null || mkActivitiesEntityList.size() == 0){
- // 计算税费
- GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
- goods.setGoodstaxes(tax.toString());
- skuActivitiesMap.put("goods",goods);
- return skuActivitiesMap;
- }
- // 遍历活动集合,查询有哪些活动是开启的
- boolean daily = false,coupon = false,combinationPrice = false
- ,discount = false,fullGift = false,fullReduction = false
- ,getOneFree = false,promotion = false,halfPrice = false;
- List<String> topicList = new ArrayList<>(); // 记录有哪些营销活动的topic
- Map<String,String> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
- // 将所有的营销活动新增到list中
- for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
- topicList.add(mkActivitiesEntity.getMkaTopic());
- String mkaId = mkaIdMap.putIfAbsent(mkActivitiesEntity.getMkaTopic(), mkActivitiesEntity.getMkaId()+"");
- if(StringUtils.isNotEmpty(mkaId)){
- // mkaId = "'"+mkaId + "','" + mkActivitiesEntity.getMkaId()+"'";
- mkaId += String.format(",%s",mkActivitiesEntity.getMkaId());
- mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkaId);
- }
- }
- // 判断有哪些营销活动
- if(topicList.contains("zhjsp")) // 组合价
- combinationPrice = true;
- if(topicList.contains("dz")) // 打折
- discount = true;
- if(topicList.contains("mz")) //满赠
- fullGift = true;
- if(topicList.contains("mj")) // 满减
- fullReduction = true;
- if(topicList.contains("mysy")) // 买一送一
- getOneFree = true;
- if(topicList.contains("rchd")) // 日常活动
- daily = true;
- if(topicList.contains("yhq")) // 优惠券
- coupon = true;
- if(topicList.contains("lscx")) // 临时促销
- promotion = true;
- if(topicList.contains("drjbj"))
- halfPrice = true;
- // 获取未优惠前的商品价格
- retailPrice = goods.getRetailPrice();
- // 根据条码查询商品品牌名称 mall_brand mall_product_store_rela mall_goods
- String brandName = goods.getBrand();
- /**
- * 优先级:临时促销 》买一送一=满赠 》 组合价=日常活动 》 打折=满减 》 优惠券
- */
- /**
- * 组合价的做法就是将参与组合的条码带到收银端
- * 现根据营销活动id跟条形码,查询有哪些参与该条码组合的商品
- *
- *
- * TODO
- */
- if(combinationPrice){
- String mkaId = mkaIdMap.get("zhjsp");
- Map<String,Object> param = new HashMap<>();
- param.put("mkaId",mkaId);
- param.put("prodBarcode",prodBarcode);
- List<MkActivitiesCombinationPriceEntity> combinationPriceList = combinationPriceService.queryList(param);
- if(combinationPriceList != null && combinationPriceList.size() > 0) {
- Map<String, List<MkActivitiesCombinationPriceEntity>> collect =
- combinationPriceList.stream().collect(Collectors.groupingBy(MkActivitiesCombinationPriceEntity::getCombinationType));
- skuActivitiesMap.put("zhjsp",collect);
- }
- }
- format = new SimpleDateFormat("yyyy-MM-dd");
- String nowTime = format.format(new Date());
- /**
- * 满减可能是跟着条码,也可能跟着品牌
- * 根据商品品牌跟商品条码去查询是否有优惠金额
- *
- * 满足金额 购买商品条码 赠品条码
- *
- */
- Map<String,Object> fullReductionMap = new HashMap<>();
- if(fullReduction){
- String mkaId = mkaIdMap.get("mj");
- MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
- if(fullReductionEntity != null) {
- if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
- // 跟着品牌走
- fullReductionMap.put(brandName,fullReductionEntity);
- }else{
- // 跟着条码走
- fullReductionMap.put(fullReductionEntity.getBarcode(), fullReductionEntity);
- }
- skuActivitiesMap.put("mj",fullReductionMap);
- }
- }
- /**
- * 满赠可能是跟着条码,也可能跟着品牌
- * 根据商品品牌跟商品条码去查询是否有满赠
- * 1.先扫买的商品,然后查询出赠送的商品条码
- * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
- * 满足的金额 购买的商品条码或者品牌 赠送的商品条码
- * TODO
- */
- Map<String,Object> fullGiftMap = new HashMap<>();
- if(fullGift){
- String mkaId = mkaIdMap.get("mz");
- MkActivitiesFullGiftEntity giftEntity = fullGiftService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
- if(giftEntity != null) {
- if(giftEntity.getProductBrand() != null){
- // 跟着品牌走
- fullGiftMap.put(brandName,giftEntity);
- }else{
- // 跟着条码走
- fullGiftMap.put(giftEntity.getBarcode(), giftEntity);
- }
- skuActivitiesMap.put("mz",fullGiftMap);
- }
- }
- /**
- * 买一送一可能是跟着条码,也可能跟着品牌
- * 根据商品品牌跟商品条码去查询是否有送的商品
- * 有两个场景
- * 1.先扫买的商品,然后查询出赠送的商品条码
- * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
- * 所以就需要一个map
- * key为购买的商品条码或者商品品牌 value为赠送的商品条码
- * 但是品牌是根据条码查询的,所以最终map里面的结构是
- * key 商品条码 value 赠品条码
- */
- if(getOneFree){
- String mkaId = mkaIdMap.get("mysy");
- MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
- if(getOneFreeGoodsEntity != null){
- if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
- getOneFreeGoodsEntity.setBrand(false);
- skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
- }else{
- getOneFreeGoodsEntity.setBrand(true);
- skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
- }
- }
- }
- // 第二份半价
- if(halfPrice){
- String mkaId = mkaIdMap.get("drjbj");
- MkActivitiesHalfPriceEntity activitiesHalfPriceEntity = halfPriceService.queryByCodeOrBrand(mkaId,prodBarcode);
- if(activitiesHalfPriceEntity != null){
- skuActivitiesMap.put("drjbj",activitiesHalfPriceEntity);
- }
- }
- // --------------------------------------------------------------------------------------
- /**
- * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
- */
- if(coupon){
- String mkaId = mkaIdMap.get("yhq");
- MkActivitiesCouponEntity couponEntity = couponService.queryByBarCode(mkaId,prodBarcode,nowTime);
- if(couponEntity != null){ // 优惠券码,优惠金额
- Map<String,Object> returnMap = new HashMap<>();
- returnMap.put(couponEntity.getCouponSn() , couponEntity.getCouponPrice());
- skuActivitiesMap.put("yhq",returnMap);
- }
- }
- /**
- * 打折的价格是与条形码对应的,所以需要根据条形码和营销方式id去查询活动价格
- */
- if(discount){
- String mkaId = mkaIdMap.get("dz");
- MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
- // TODO 可能会直接替代产品价格
- if (discountEntity != null) {
- goods.setActualPaymentAmount(discountEntity.getActivityPrice());
- goods.setRetailPrice(discountEntity.getActivityPrice());
- goods.setActivity("打折");
- }
- }
- /**
- * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
- */
- if(daily){
- String mkaId = mkaIdMap.get("rchd");
- MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
- if(dailyActivitiesEntity != null){
- goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
- goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
- goods.setActivity("日常活动");
- }
- }
- /**
- * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
- */
- if(promotion){
- String mkaId = mkaIdMap.get("lscx");
- MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
- // 如果该商品存在临时促销,直接替换活动价格
- if(promotionEntity != null){
- goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
- goods.setRetailPrice(promotionEntity.getActivityPrice());
- goods.setActivity("临时促销");
- }
- }
- // 计算税费
- GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
- BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
- goods.setGoodstaxes(tax.toString());
- skuActivitiesMap.put("goods",goods);
- return skuActivitiesMap;
- }
- /**
- * 根据条形码查询商品
- *
- * @param barCode
- * @return
- */
- @Override
- public GoodsEntity queryByBarcode(String barCode) {
- return goodsDao.queryByBarcode(barCode);
- }
- /**
- * 根据sku查询商品
- *
- * @param sku
- * @return
- */
- @Override
- public GoodsEntity queryBySku(String sku) {
- return goodsDao.queryBySku(sku);
- }
- /* @Override
- @Transactional
- public int uploadExcel(MultipartFile file) {
- SysUserEntity user = ShiroUtils.getUserEntity();
- List<String[]> list = ExcelImport.getExcelData(file);
- // 取门店名称
- StoreEntity storeEntity = storeDao.queryObjectByName(list.get(0)[3]);
- if (null == storeEntity) {
- return 0;
- }
- //去除表头两行、底部合计
- if (list != null && list.size() > 3) {
- ProductStoreRelaEntity storeRelaEntity;
- ProductEntity productEntity;
- for (int i = 2; i < list.size() - 1; i++) {
- String[] item = list.get(i);
- String goodsSn = item[0];
- productEntity = productDao.queryObjectBySn(goodsSn);
- if (StringUtils.isNullOrEmpty(goodsSn)) {
- continue;
- }
- if (null == productEntity || null == productEntity.getId()) {
- continue;
- }
- storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(storeEntity.getId(), productEntity.getId());
- if (null != storeRelaEntity && null != storeRelaEntity.getId()) {
- storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
- storeRelaEntity.setStockNum(Integer.valueOf(item[3].replace(".00", "")));
- storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
- productStoreRelaDao.update(storeRelaEntity);
- } else {
- storeRelaEntity = new ProductStoreRelaEntity();
- storeRelaEntity.setGoodsId(productEntity.getGoodsId());
- storeRelaEntity.setProductId(productEntity.getId());
- storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
- storeRelaEntity.setMarketPrice(new BigDecimal(item[6]));
- storeRelaEntity.setStockNum(Integer.valueOf(item[3]));
- storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
- storeRelaEntity.setStoreId(storeEntity.getId());
- productStoreRelaDao.save(storeRelaEntity);
- }
- }
- }
- return 1;
- }*/
- public GoodsEntity queryObjectBySn(String goodsSn) {
- return goodsDao.queryObjectBySn(goodsSn);
- }
- /**
- * 全量拉取
- */
- @Override
- public void syncOmsHsCodeTask() {
- syncOmsHsCodeSegment(goodsDao.queryNonSyncOmsHsCodeSkuList());
- }
- /**
- * 全量计算
- */
- @Override
- public void syncGoodsRateTask() {
- // 查询出所有商品
- List<GoodsEntity> allGoodsList = goodsDao.queryAllList(null,null);
- syncGoodsRate(allGoodsList);
- }
- /**
- * 还原园区库存
- *
- * @param goodsEntities 数据
- */
- @Override
- public int restoreBatch(List<GoodsEntity> goodsEntities) {
- return goodsDao.restoreBatch(goodsEntities);
- }
- /**
- * 查询库存及sku的信息,查询出来的库存是门店的库存
- *
- * @param prodBarcode 条码
- * @param storeId 门店id
- * @param sku sku
- * @return 商品信息
- */
- @Override
- public GoodsEntity queryGoodsStockByBarcodeAndStoreIdAndSku(String prodBarcode, Integer storeId, String sku) {
- return goodsDao.queryGoodsStockByBarcodeAndStoreIdAndSku(prodBarcode, storeId, sku);
- }
- /**
- * 查询库存及sku的信息,查询出来的库存是门店的库存
- *
- * @param queryGoodsVOList 查询条件,包含商品条码、sku、门店id
- * @return 商品信息
- */
- @Override
- public List<GoodsEntity> queryGoodsStockByQueryGoodsVoList(List<QueryGoodsVO> queryGoodsVOList) {
- return goodsDao.queryGoodsStockByQueryGoodsVoList(queryGoodsVOList);
- }
- /**
- * 选择拉取
- * @param ids
- */
- @Override
- public void syncOmsHsCodeGoode(List<Integer> ids) {
- syncOmsHsCodeSegment(goodsDao.syncOmsHsCodeGoode(ids));
- }
- /**
- * 选择计算
- * @param ids
- */
- @Override
- public void syncGoodsRateGoode(List<Integer> ids) {
- syncGoodsRate(goodsDao.syncGoodsRateGoode(ids));
- }
- public void syncOmsHsCodeSegment(List<String> skuList) {
- int segmentLimitSize = 300;
- if (skuList.size() < segmentLimitSize) {
- this.syncOmsHsCode(skuList);
- } else {
- int segmentSize = skuList.size() % segmentLimitSize == 0 ? skuList.size() / segmentLimitSize : (skuList.size() / segmentLimitSize) + 1;
- List<List<String>> segment = new ArrayList<>();
- for (int i = 0; i < segmentSize; i++) {
- int end = (i == segmentSize - 1) ? skuList.size() : i * segmentLimitSize + segmentLimitSize;
- segment.add(new ArrayList<>(skuList.subList(i * segmentLimitSize, end)));
- }
- for (List<String> tmp : segment) {
- this.syncOmsHsCode(tmp);
- }
- }
- }
- @Transactional
- public void syncOmsHsCode(List<String> skuList) {
- if (Objects.nonNull(skuList) && skuList.size()>0){
- String result = HttpUtil.get("https://oms.ds-bay.com/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
- //String result = HttpUtil.get("http://183.3.221.143:8080/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
- //String result = HttpUtil.get("http://127.0.0.1:8080/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
- Map<String,Map> map = JSON.parseObject(result, Map.class);
- for (String sku : skuList) {
- Map skuInfoMap = map.get(sku);
- if (Objects.nonNull(skuInfoMap)){
- String hsCodeName = (String) skuInfoMap.get("cusGoodsName");
- String hsCode = (String) skuInfoMap.get("cusGoodsCode");
- String prodName = (String) skuInfoMap.get("prodName");
- String prodRecordName = (String) skuInfoMap.get("prodRecordName");
- BigDecimal impConsumTaxRate = (BigDecimal) skuInfoMap.get("impConsumTaxRate");
- BigDecimal valueAddedTaxRate = (BigDecimal) skuInfoMap.get("valueAddedTaxRate");
- BigDecimal legalUnit1Qty = (BigDecimal) skuInfoMap.get("legalUnit1Qty");
- BigDecimal legalUnit2Qty = (BigDecimal) skuInfoMap.get("legalUnit2Qty");
- BigDecimal cosmThresholdValue = (BigDecimal) skuInfoMap.get("cosmThresholdValue");
- if (StringUtils.isNotEmpty(hsCodeName) && StringUtils.isNotEmpty(hsCode)){
- List<GoodsEntity> goodsEntityList = goodsDao.queryListBySku(sku);
- if (Objects.nonNull(goodsEntityList) && goodsEntityList.size()>0){
- for (GoodsEntity goodsEntity : goodsEntityList) {
- goodsEntity.setHsCode(hsCode);
- goodsEntity.setHsCodeName(hsCodeName);
- goodsEntity.setImpConsumTaxRate(impConsumTaxRate);
- goodsEntity.setValueAddedTaxRate(valueAddedTaxRate);
- goodsEntity.setIsSyncHsCode("1");
- goodsEntity.setLegalUnit1Qty(legalUnit1Qty);
- goodsEntity.setProdName(prodName);
- goodsEntity.setProdRecordName(prodRecordName);
- goodsEntity.setLegalUnit2Qty(legalUnit2Qty);
- goodsEntity.setCosmThresholdValue(cosmThresholdValue);
- goodsDao.update(goodsEntity);
- }
- }
- }
- }
- }
- }
- }
- @Transactional
- public void syncGoodsRate(List<GoodsEntity> allGoodsList) {
- String storeId = "163"; // 市场部说所有门店价格一致,并且活动一致,可直接取其中一个门店价格进行计算税率
- for (GoodsEntity goodsEntity : allGoodsList) {
- // 同步过海关商品编码才可以算税率
- if ("1".equals(goodsEntity.getIsSyncHsCode())) {
- // Map<String, Object> goodsDetailMap = calculateGoodsDetail(goodsEntity.getProdBarcode(), storeId);
- // if (Objects.nonNull(goodsDetailMap)) {
- // GoodsDetailsDto goods = (GoodsDetailsDto) goodsDetailMap.get("goods");
- // 顾客给的钱 就是税后价
- // BigDecimal actualPaymentAmount = goods.getActualPaymentAmount(); //随便拿一个门店的当前时间的价格,如果有活动价会使用活动价
- // BigDecimal calculateTax = CalculateTax.calculateTax(goodsEntity, actualPaymentAmount);// 税费
- // BigDecimal goodsRate = calculateTax.divide(actualPaymentAmount, 4, BigDecimal.ROUND_HALF_UP);
- BigDecimal goodsRate =CalculateTax.calculateGoodsRate(goodsEntity);
- goodsEntity.setGoodsRate(goodsRate);
- goodsEntity.setIsSyncHsCode("0");
- goodsDao.update(goodsEntity);
- // }
- }
- }
- }
- @Override
- public void updateTaxErrorRecord(TaxErrorRecordEntity taxErrorRecordEntity) {
- taxErrorRecordDao.update(taxErrorRecordEntity);
- }
- @Override
- public void insertTaxErrorRecord(TaxErrorRecordEntity taxErrorRecordEntity) {
- taxErrorRecordDao.save(taxErrorRecordEntity);
- }
- @Override
- public void updateByEntity(GoodsEntity updateGoods) {
- goodsDao.update(updateGoods);
- }
- @Override
- public void checkGoodsPrice(SysUserEntity user) {
- Map<String, BigDecimal> hsCodeMap = CalculateTax.hsCodeMap;
- Set<String> hdCodeSet = hsCodeMap.keySet();
- List<Map<String,String>> errorPriceSkuList = new LinkedList<>();
- // 保存各种异常价格对象集合
- List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities = new LinkedList<>();
- // 查询所有特殊化妆品的商品
- List<GoodsEntity> queryGoodsDetails = goodsDao.querySpecialCosmetics(hdCodeSet);
- for (GoodsEntity goodsEntity : queryGoodsDetails) {
- calculateShopPrice(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
- calculateDailyPrice(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
- calculeatePromotion(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
- }
- if(shopErrorPriceRecordEntities.size() != 0){
- shopErrorPriceRecordService.saveBatch(shopErrorPriceRecordEntities);
- }
- }
- @Override
- public List<GoodsEntity> queryAllList(Integer page,Integer pageSize) {
- return goodsDao.queryAllList(page,pageSize);
- }
- private void calculeatePromotion(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
- String prodBarcode = goods.getProdBarcode();
- String storeId = goods.getStoreId()+"";
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- /**
- * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
- * 参数: 当前时间 门店id
- */
- MkActivitiesPromotionEntity promotionEntity = promotionService.queryByDateAndBarcode(storeId,format.format(new Date()),"lscx",prodBarcode);
- // 如果该商品存在临时促销,直接替换活动价格
- if(promotionEntity == null){
- return ;
- }
- goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
- goods.setRetailPrice(promotionEntity.getActivityPrice());
- goods.setActivity("临时促销");
- try {
- CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
- } catch (Exception e) {
- ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
- shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
- shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
- shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
- shopErrorPriceRecordEntity.setPriceType(3); // 3 是临时促销
- shopErrorPriceRecordEntity.setSku(goods.getSku());
- shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
- shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
- shopErrorPriceRecordEntity.setCheckTime(new Date());
- shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
- shopErrorPriceRecordEntity.setCreateTime(new Date());
- shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
- if(e.getMessage().contains("-")){
- String suggestPrice = e.getMessage().split("-")[0];
- String highestPrice = e.getMessage().split("-")[1];
- String lowestPrice = e.getMessage().split("-")[2];
- shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
- shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
- shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
- }
- shopErrorPriceRecordEntity.setMkaId(promotionEntity.getMkaId());
- shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
- }
- }
- private void calculateDailyPrice(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
- String prodBarcode = goods.getProdBarcode();
- String storeId = goods.getStoreId()+"";
- /**
- * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
- * 参数: 当前时间 门店id
- */
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- /**
- * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
- */
- MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByDateAndBarcode(storeId,format.format(new Date()),"rchd",prodBarcode);
- if(dailyActivitiesEntity == null){
- return ;
- }
- goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
- goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
- goods.setActivity("日常活动");
- // 计算税费
- try {
- CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
- } catch (Exception e) {
- // 记录有异常的sku
- ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
- shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
- shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
- shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
- shopErrorPriceRecordEntity.setPriceType(2); // 2 是日常活动
- shopErrorPriceRecordEntity.setSku(goods.getSku());
- shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
- shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
- shopErrorPriceRecordEntity.setCheckTime(new Date());
- shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
- shopErrorPriceRecordEntity.setCreateTime(new Date());
- shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
- if(e.getMessage().contains("-")){
- String suggestPrice = e.getMessage().split("-")[0];
- String highestPrice = e.getMessage().split("-")[1];
- String lowestPrice = e.getMessage().split("-")[2];
- shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
- shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
- shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
- }
- shopErrorPriceRecordEntity.setMkaId(dailyActivitiesEntity.getMkaId());
- shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
- }
- }
- private void calculateShopPrice(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
- goods.setDiscountedPrice(new BigDecimal(0));
- BigDecimal retailPrice = goods.getRetailPrice();
- goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
- // 计算税费
- try {
- CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
- } catch (Exception e) {
- // 记录有异常的sku
- ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
- shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
- shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
- shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
- shopErrorPriceRecordEntity.setPriceType(1); // 1 门店商品价格
- shopErrorPriceRecordEntity.setSku(goods.getSku());
- shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
- shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
- shopErrorPriceRecordEntity.setCheckTime(new Date());
- shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
- shopErrorPriceRecordEntity.setCreateTime(new Date());
- shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
- if(e.getMessage().contains("-")){
- String suggestPrice = e.getMessage().split("-")[0];
- String highestPrice = e.getMessage().split("-")[1];
- String lowestPrice = e.getMessage().split("-")[2];
- shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
- shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
- shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
- }
- shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
- }
- }
- /**
- * 根据产品条码和sku查询保税展示补货的商品
- *
- * @param prodBarcode 商品条码
- * @param sku sku
- * @return 商品信息
- */
- @Override
- public GoodsEntity queryGoodsInfoByProductBarcodeAndSku(String prodBarcode, String sku) {
- return goodsDao.queryGoodsInfoByProductBarcodeAndSku(prodBarcode, sku);
- }
- @Override
- public int updateStockNumberByProductCodeAndSku(GoodsEntity goodsEntity) {
- return goodsDao.updateStockNumberByProductCodeAndSku(goodsEntity);
- }
- }
|