package com.jd.jdx.x.sr.cms.service.container.impl; import com.jd.bk.common.web.result.Result; import com.jd.jdx.x.sr.cms.domain.base.constants.BaseConstants; import com.jd.jdx.x.sr.cms.domain.base.ui.Page; import com.jd.jdx.x.sr.cms.domain.biz.dto.BizSequenceDto; import com.jd.jdx.x.sr.cms.domain.container.dto.GoodsBoxDto; import com.jd.jdx.x.sr.cms.domain.container.dto.StaticTemGoodsDto; import com.jd.jdx.x.sr.cms.domain.container.model.*; import com.jd.jdx.x.sr.cms.domain.container.query.ConSellerGoodsQuery; import com.jd.jdx.x.sr.cms.domain.container.query.ConStaticTemplateQuery; import com.jd.jdx.x.sr.cms.domain.container.query.ConTemGoodsQuery; import com.jd.jdx.x.sr.cms.domain.util.CommonConfig; import com.jd.jdx.x.sr.cms.manager.biz.BizSequenceManager; import com.jd.jdx.x.sr.cms.manager.container.*; import com.jd.jdx.x.sr.cms.service.container.ConStaticTemplateService; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * 業務模塊-商品靜態模板服務實現 * * @author wanghonghong5 */ @Component("conStaticTemplateService") public class ConStaticTemplateServiceImpl implements ConStaticTemplateService { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(ConStaticTemplateServiceImpl.class); /** * the ConStaticTemplateManager */ private ConStaticTemplateManager conStaticTemplateManager; private ConTemGoodsManager conTemGoodsManager; private BizSequenceManager bizSequenceManager; private ConDeviceGoodsManager conDeviceGoodsManager; private ConDeviceManager conDeviceManager; /** * 商家商品 */ private ConSellerGoodsManager conSellerGoodsManager; @Override public Result insertConStaticTemplate(ConStaticTemplate conStaticTemplate) { Result result = new Result(); try { if (null != conStaticTemplate) { boolean returnFlag = true; //保存通用消息 returnFlag = conStaticTemplateManager.insertConStaticTemplate(conStaticTemplate); if (returnFlag) { result.setSuccess(true); result.setResultCode(BaseConstants.SERVICE_RESULT_SUCCESS_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_SUCCESS_CODE, returnFlag); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } catch (Exception e) { logger.error("ConStaticTemplateServiceImpl!insertConStaticTemplate -> error!!", e); result.setSuccess(false); } return result; } @Override public Result updateConStaticTemplate(ConStaticTemplate conStaticTemplate) { Result result = new Result(); try { if (null != conStaticTemplate) { boolean returnFlag = true; //保存通用消息 returnFlag = conStaticTemplateManager.updateConStaticTemplate(conStaticTemplate); if (returnFlag) { result.setSuccess(true); result.setResultCode(BaseConstants.SERVICE_RESULT_SUCCESS_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_SUCCESS_CODE, returnFlag); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } catch (Exception e) { logger.error("ConStaticTemplateServiceImpl!updateConStaticTemplate -> error!!", e); result.setSuccess(false); } return result; } @Override public Result deleteConStaticTemplate(Long id) { Result result = new Result(); try { if (null != id) { boolean returnFlag = true; //保存通用消息 returnFlag = conStaticTemplateManager.deleteConStaticTemplate(id); if (returnFlag) { result.setSuccess(true); result.setResultCode(BaseConstants.SERVICE_RESULT_SUCCESS_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_SUCCESS_CODE, returnFlag); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } catch (Exception e) { logger.error("ConStaticTemplateServiceImpl!deleteConStaticTemplate -> error!!", e); result.setSuccess(false); } return result; } @Override public Result getConStaticTemplate(Long id) { Result result = new Result(); try { if (null != id) { boolean returnFlag = true; //保存通用消息 ConStaticTemplate conStaticTemplate = conStaticTemplateManager.getConStaticTemplate(id); if (conStaticTemplate != null) { result.setSuccess(true); result.setResultCode(BaseConstants.SERVICE_RESULT_SUCCESS_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_SUCCESS_CODE, conStaticTemplate); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } catch (Exception e) { logger.error("ConStaticTemplateServiceImpl!getConStaticTemplate -> error!!", e); result.setSuccess(false); } return result; } @Override public Result findConStaticTemplateList(Page page, ConStaticTemplateQuery conStaticTemplateQuery) { Result result = new Result(); try { if (null != conStaticTemplateQuery) { boolean returnFlag = true; //保存通用消息 conStaticTemplateQuery.setTemType(CommonConfig.temTypeByUser); conStaticTemplateManager.findConStaticTemplateList(page, conStaticTemplateQuery); if (conStaticTemplateQuery != null) { result.setSuccess(true); result.setResultCode(BaseConstants.SERVICE_RESULT_SUCCESS_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_SUCCESS_CODE, page); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } catch (Exception e) { logger.error("ConStaticTemplateServiceImpl!findConStaticTemplateList -> error!!", e); result.setSuccess(false); } return result; } @Override public Result insertStaticTemAndGoods(StaticTemGoodsDto staticTemGoodsDto) { Result result = new Result(); try { if (null != staticTemGoodsDto) { boolean returnFlag = true; // 生成模板編號 BizSequenceDto bizSequenceDto = bizSequenceManager.getSequence(CommonConfig.TemNo_SEQ, 1); if (bizSequenceDto != null) { String temNo = CommonConfig.Tem_Pre + bizSequenceDto.getEndSeq(); staticTemGoodsDto.setTemNo(temNo); //保存通用消息 returnFlag = conStaticTemplateManager.insertStaticTemAndGoods(staticTemGoodsDto); if (returnFlag) { result.setSuccess(true); result.setResultCode(BaseConstants.SERVICE_RESULT_SUCCESS_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_SUCCESS_CODE, returnFlag); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { logger.error("沒有取到序列號:" + staticTemGoodsDto.getTemName()); result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } catch (Exception e) { logger.error("ConStaticTemplateServiceImpl!insertStaticTemAndGoods -> error!!", e); result.setSuccess(false); } return result; } @Override public Result updateStaticTemAndGoods(StaticTemGoodsDto staticTemGoodsDto) { Result result = new Result(); try { if (null != staticTemGoodsDto) { boolean returnFlag = true; //保存通用消息 ConStaticTemplate conStaticTemplate = conStaticTemplateManager.getConStaticTemplate(staticTemGoodsDto.getTemId()); conStaticTemplate.setCreateTime(new Date()); conStaticTemplate.setUpdateUser(staticTemGoodsDto.getUserName()); GoodsBoxDto goodsBoxDto = new GoodsBoxDto(); goodsBoxDto.setSellerNo(conStaticTemplate.getSellerNo()); goodsBoxDto.setTemNo(conStaticTemplate.getTemNo()); // 判斷如果如果這個模板有綁定設備即櫃子需要更新設備商品模板表 // 當前模板下的所有設備的設備商品信息 List<ConDeviceGoods> boxGoodsList = conDeviceGoodsManager.getBoxGoodsList(goodsBoxDto); staticTemGoodsDto.setTemNo(conStaticTemplate.getTemNo()); staticTemGoodsDto.setBoxGoodsList(boxGoodsList); staticTemGoodsDto.setConStaticTemplate(conStaticTemplate); returnFlag = conStaticTemplateManager.updateStaticTemAndGoods(staticTemGoodsDto); if (returnFlag) { result.setSuccess(true); result.setResultCode(BaseConstants.SERVICE_RESULT_SUCCESS_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_SUCCESS_CODE, boxGoodsList); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } catch (Exception e) { logger.error("ConStaticTemplateServiceImpl!updateStaticTemAndGoods -> error!!", e); result.setSuccess(false); } return result; } @Override public Result validBoxTemGoods(StaticTemGoodsDto staticTemGoodsDto) { Result result = new Result(); try { if (null != staticTemGoodsDto) { boolean returnFlag = true; //保存通用消息 GoodsBoxDto goodsBoxDto = new GoodsBoxDto(); goodsBoxDto.setSellerNo(staticTemGoodsDto.getSellerNo()); goodsBoxDto.setTemNo(staticTemGoodsDto.getTemNo()); // 該模板-原始設備-對應的商品 List<ConDeviceGoods> boxGoodsList = conDeviceGoodsManager.getBoxGoodsList(goodsBoxDto); // 模板-商品編碼 ConTemGoodsQuery conTemGoodsQuery = new ConTemGoodsQuery(); conTemGoodsQuery.setTemNo(staticTemGoodsDto.getTemNo()); List<ConTemGoods> listTemoGoods = conTemGoodsManager.getConTemGoodsList(conTemGoodsQuery); List<String> listTemoGoodsNos = listTemoGoods.stream().map(p -> p.getGoodsNo()).distinct().collect(Collectors.toList()); // 商家-商品信息 ConSellerGoodsQuery conSellerGoodsQuery = new ConSellerGoodsQuery(); conSellerGoodsQuery.setSellerNo(staticTemGoodsDto.getSellerNo()); List<ConSellerGoods> listSellerGoods = conSellerGoodsManager.getConSellerGoodsList(conSellerGoodsQuery); // 過濾出該模板的商家商品全信息 listSellerGoods = listSellerGoods.stream().filter(p -> listTemoGoodsNos.contains(p.getGoodsNo())).collect(Collectors.toList()); // 用來存最終設備商品信息 List<ConDeviceGoods> boxGoodsListFinal = new ArrayList<>(); if (listSellerGoods.size() > 0) { // 本次選擇的商品信息列表-商品編碼列表-新值 List<String> listGoodsNosNew = listSellerGoods.stream().map(p -> p.getGoodsNo()).collect(Collectors.toList()); // 設備商品信息列表-商品編碼列表-原始值 List<String> listBoxGoodsNosOld = boxGoodsList.stream().map(p -> p.getGoodsNo()).distinct().collect(Collectors.toList()); // 生效的設備 List<String> listBoxNos = staticTemGoodsDto.getListBoxNos(); // 如果有設備商品則需要做一些操作 if (boxGoodsList.size() > 0) { // 1、新模板有此商品,則不需要改變任何信息 boxGoodsListFinal = boxGoodsList.stream().filter(p -> listGoodsNosNew.contains(p.getGoodsNo())). collect(Collectors.toList()); // 2、過濾商家當前模板商品-新增的模板商品 listSellerGoods = listSellerGoods.stream().filter(p -> !listBoxGoodsNosOld.contains(p.getGoodsNo())). collect(Collectors.toList()); } // 3、獲取設備列表信息 ConBox conBox = new ConBox(); conBox.setTemNo(staticTemGoodsDto.getTemNo()); conBox.setConBoxNosList(staticTemGoodsDto.getListBoxNos()); List<ConBox> listBoxs = conDeviceManager.getConBoxListByTemNo(conBox); for (ConBox conBoxItem : listBoxs ) { List<ConDeviceGoods> listComBoxGoods = listSellerGoods.stream() .map(e -> new ConDeviceGoods(e.getSellerNo(), e.getSellerName(), conBoxItem.getBoxNo(), conBoxItem.getBoxName(), e.getGoodsNo(), e.getGoodsName(), staticTemGoodsDto.getTemNo(), staticTemGoodsDto.getTemName(), new Date(), new Date(), staticTemGoodsDto.getUserName(), staticTemGoodsDto.getUserName(), e.getSalePrice(), e.getSaleUnitRealPrice(), conBoxItem.getStoreNo(),conBoxItem.getStoreName())) .collect(Collectors.toList()); // 追加list boxGoodsListFinal.addAll(listComBoxGoods); } } staticTemGoodsDto.setTemNo(staticTemGoodsDto.getTemNo()); staticTemGoodsDto.setBoxGoodsList(boxGoodsListFinal); returnFlag = conStaticTemplateManager.validBoxTemGoods(staticTemGoodsDto); if (returnFlag) { result.setSuccess(true); result.setResultCode(BaseConstants.SERVICE_RESULT_SUCCESS_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_SUCCESS_CODE, boxGoodsListFinal); } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } else { result.setSuccess(false); result.setResultCode(BaseConstants.SERVICE_RESULT_FAIL_CODE); result.addDefaultModel(BaseConstants.SERVICE_RESULT_FAIL_CODE, BaseConstants.SERVICE_RESULT_FAIL_MESSAGE); } } catch (Exception e) { logger.error("ConStaticTemplateServiceImpl!validBoxTemGoods -> error!!", e); result.setSuccess(false); } return result; } public void setConStaticTemplateManager(ConStaticTemplateManager conStaticTemplateManager) { this.conStaticTemplateManager = conStaticTemplateManager; } public void setBizSequenceManager(BizSequenceManager bizSequenceManager) { this.bizSequenceManager = bizSequenceManager; } public void setConDeviceGoodsManager(ConDeviceGoodsManager conDeviceGoodsManager) { this.conDeviceGoodsManager = conDeviceGoodsManager; } public void setConTemGoodsManager(ConTemGoodsManager conTemGoodsManager) { this.conTemGoodsManager = conTemGoodsManager; } public void setConDeviceManager(ConDeviceManager conDeviceManager) { this.conDeviceManager = conDeviceManager; } public void setConSellerGoodsManager(ConSellerGoodsManager conSellerGoodsManager) { this.conSellerGoodsManager = conSellerGoodsManager; } }
