123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890 |
- package com.kmall.admin.service.impl;
- import cn.hutool.http.HttpUtil;
- import com.alibaba.druid.support.json.JSONUtils;
- import com.alibaba.fastjson.JSON;
- import com.google.common.collect.ImmutableBiMap;
- 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.mk.MkActivitiesEntity;
- import com.kmall.admin.service.*;
- import com.kmall.admin.service.mk.MkActivitiesService;
- import com.kmall.admin.service.mk.MkActivityFormService;
- import com.kmall.admin.service.GoodsService;
- 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.common.utils.print.ticket.item.Goods;
- import org.apache.poi.util.StringUtil;
- 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 {
- @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 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;
- @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
- 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<>();
- 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());
- }
- //校验产品条码是否存在
- // List<GoodsEntity> prodbarGoods = goodsDao.queryObjectByProdBarcode(goodsDto.getProdBarcode(),merchSn,null);
- // if(prodbarGoods != null && prodbarGoods.size() > 0){
- // isFail = true;
- // failProdbarGoodsSnList.add(goodsDto.getGoodsSn());
- // }else{
- 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);
- // supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
- goodsEntity.setSupplierId(supplierEntity.getId());
- } else {
- goodsEntity.setSupplierId(supplierEntity.getId());
- }
- }
- //商品配置校验
- /*CategoryEntity categoryEntity = categoryDao.queryObjectByName(goodsDto.getCategoryName(),goodsDto.getMerchSn());
- if(categoryEntity==null){
- isFail = true;
- failCateGoodsSnList.add(goodsDto.getGoodsSn());
- }else{
- if(categoryEntity.getLevel().equalsIgnoreCase("L2")) {
- goodsEntity.setCategoryId(categoryEntity.getId());
- goodsEntity.setAttributeCategory(categoryEntity.getParentId());
- }else{
- isFail = true;
- failCateL2GoodsSnList.add(goodsDto.getGoodsSn());
- }
- }
- BrandEntity brandEntity = brandDao.queryObjectByName(goodsDto.getBrandName(),goodsDto.getMerchSn());
- if (brandEntity == null) {
- isFail = true;
- failBrandGoodsSnList.add(goodsDto.getGoodsSn());
- } else {
- goodsEntity.setBrandId(brandEntity.getId());
- }
- //运费
- FreightEntity freightEntity = freightDao.queryObjectByName(goodsDto.getDefaultFreight(),goodsDto.getMerchSn());
- if(freightEntity==null){
- isFail = true;
- failFreightGoodsSnList.add(goodsDto.getGoodsSn());
- failFreightList.add(goodsDto.getDefaultFreight());
- }else {
- goodsEntity.setFreightId(freightEntity.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.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(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);
- // // 保税商品修改各个门店商品价格
- // 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);
- 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(failProdbarGoodsSnList != null && failProdbarGoodsSnList.size() > 0){
- // exportExceptionDataEntity.setExportExceptionData("不能有重复的产品条码信息!请检查商品编码【"+failProdbarGoodsSnList+"】的商品产品条码信息");
- // goodsUtils.save(exportExceptionDataEntity);
- // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- // }
- if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
- exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
- goodsUtils.save(exportExceptionDataEntity);
- throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- }
- // if(failCateGoodsSnList != null && failCateGoodsSnList.size() > 0){
- // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中维护,商品分类与商户信息对应,请检查该商品商户信息下的分类是否维护,不存在的商品编码【"+failCateGoodsSnList+"】");
- // exportExceptionDataDao.save(exportExceptionDataEntity);
- // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- // }
- // if(failCateL2GoodsSnList != null && failCateL2GoodsSnList.size() > 0){
- // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中查看,商品分类必须为二级分类,不存在的商品编码【"+failCateL2GoodsSnList+"】");
- // exportExceptionDataDao.save(exportExceptionDataEntity);
- // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- // }
- // if(failBrandGoodsSnList != null && failBrandGoodsSnList.size() > 0){
- // exportExceptionDataEntity.setExportExceptionData("品牌信息请在商城配置》品牌制造商中维护,品牌与商户信息对应,请检查该商品商户信息下的品牌是否维护,不存在的商品编码【" + failBrandGoodsSnList + "】");
- // exportExceptionDataDao.save(exportExceptionDataEntity);
- // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
- // }
- // if(failFreightGoodsSnList != null && failFreightGoodsSnList.size() > 0){
- // exportExceptionDataEntity.setExportExceptionData("运费信息请在商城配置》运费模板中维护,运费与商户信息对应,请检查该商品商户信息下的运费是否维护,不存在的商品编码【"+failFreightGoodsSnList+"】,运费【"+failFreightList+"】");
- // exportExceptionDataDao.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
- @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());
- if(goods!=null) {// 修改商品
- goodsEntity.setId(goods.getId());
- goodsEntity.setVideoUrl(goods.getVideoUrl());
- goodsEntity.setListPicUrl(goods.getListPicUrl());
- goodsEntity.setPrimaryPicUrl(goods.getPrimaryPicUrl());
- goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
- goodsDao.update(goodsEntity);
- }else{
- goodsDao.save(goodsEntity);
- }
- // 修改产品
- 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) {
- return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
- }
- @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) {
- /**
- * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
- */
- GoodsDetailsDto goods = queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
- if(goods == null) {
- return null;
- }
- goods.setDiscountedPrice(new BigDecimal(0));
- BigDecimal goodsRate = null;
- try {
- goodsRate = new BigDecimal(goods.getGoodsRate());
- } catch (Exception e) {
- goodsRate = new BigDecimal(0);
- }
- BigDecimal retailPrice = goods.getRetailPrice();
- BigDecimal tax = goodsRate.multiply(retailPrice.divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
- goods.setGoodstaxes(tax.toString());
- 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){
- 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,Long> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
- // 将所有的营销活动新增到list中
- for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
- topicList.add(mkActivitiesEntity.getMkaTopic());
- mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkActivitiesEntity.getMkaId());
- }
- // 判断有哪些营销活动
- 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){
- Long 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){
- Long 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){
- Long 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){
- Long 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){
- Long mkaId = mkaIdMap.get("drjbj");
- MkActivitiesHalfPriceEntity activitiesHalfPriceEntity = halfPriceService.queryByCodeOrBrand(mkaId,prodBarcode);
- if(activitiesHalfPriceEntity != null){
- skuActivitiesMap.put("drjbj",activitiesHalfPriceEntity);
- }
- }
- // --------------------------------------------------------------------------------------
- /**
- * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
- */
- if(coupon){
- Long 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){
- Long mkaId = mkaIdMap.get("dz");
- MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
- // TODO 可能会直接替代产品价格
- if (discountEntity != null) {
- goods.setActualPaymentAmount(discountEntity.getActivityPrice());
- goods.setRetailPrice(discountEntity.getActivityPrice());
- tax = goodsRate.multiply(discountEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
- goods.setGoodstaxes(tax.toString());
- // goods.setDiscountedPrice(retailPrice.subtract(discountEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
- goods.setActivity("打折");
- }
- }
- /**
- * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
- */
- if(daily){
- Long mkaId = mkaIdMap.get("rchd");
- MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
- if(dailyActivitiesEntity != null){
- goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
- goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
- tax = goodsRate.multiply(dailyActivitiesEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
- goods.setGoodstaxes(tax.toString());
- // goods.setDiscountedPrice(retailPrice.subtract(dailyActivitiesEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
- goods.setActivity("日常活动");
- }
- }
- /**
- * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
- */
- if(promotion){
- Long mkaId = mkaIdMap.get("lscx");
- MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
- // 如果该商品存在临时促销,直接替换活动价格
- if(promotionEntity != null){
- goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
- goods.setRetailPrice(promotionEntity.getActivityPrice());
- tax = goodsRate.multiply(promotionEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
- goods.setGoodstaxes(tax.toString());
- // goods.setDiscountedPrice(retailPrice.subtract(promotionEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
- goods.setActivity("临时促销");
- }
- }
- 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
- @Transactional
- public void syncOmsHsCode() {
- List<String> skuList = goodsDao.queryNonSyncOmsHsCodeSkuList();
- if (Objects.nonNull(skuList) && skuList.size()>0){
- String result = HttpUtil.get("https://oms.ds-bay.com/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");
- 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.setLegalUnit2Qty(legalUnit2Qty);
- goodsEntity.setCosmThresholdValue(cosmThresholdValue);
- goodsDao.update(goodsEntity);
- }
- }
- }
- }
- }
- }
- }
- @Override
- @Transactional
- public void syncOmsGoodsRate() {
- List<GoodsEntity> list = goodsDao.queryNonSyncOmsGoodsRateSkuList();
- if (Objects.nonNull(list) && list.size()>0){
- String result = HttpUtil.get("https://oms.ds-bay.com/oms-controller-mgt/taxBill/queryGoodsRate?thirdPartyMerchCode=CW001");
- Map<String,String> map = JSON.parseObject(result, Map.class);
- for (GoodsEntity goodsEntity : list) {
- String goodsRate = map.get(goodsEntity.getHsCode());
- if (StringUtils.isNotEmpty(goodsRate)){
- goodsEntity.setIsSyncGoodsRate("1");
- goodsEntity.setGoodsRate(new BigDecimal(goodsRate));
- goodsDao.update(goodsEntity);
- }
- }
- }
- }
- @Override
- @Transactional
- public void syncGoodsRate() {
- String storeId = "163"; // 市场部说所有门店价格一致,并且活动一致,可直接取其中一个门店价格进行计算税率
- // 查询出所有商品
- List<GoodsEntity> allGoodsList = goodsDao.queryAllList();
- 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);
- goodsDao.update(goodsEntity);
- }
- }
- }
- }
- }
|