|
|
@@ -3,6 +3,7 @@ package com.dderp.business.service;
|
|
|
import com.dderp.business.dao.StoreDao;
|
|
|
import com.dderp.common.api.NoSqlKeysService;
|
|
|
import com.dderp.common.api.PlatformService;
|
|
|
+import com.dderp.common.api.SortBuilderExecutor;
|
|
|
import com.dderp.common.api.StoreService;
|
|
|
import com.dderp.common.base.BaseService;
|
|
|
import com.dderp.common.datas.ESKeys;
|
|
|
@@ -12,6 +13,7 @@ import com.dderp.common.entity.site.ERPTokenUser;
|
|
|
import com.dderp.common.entity.store.*;
|
|
|
import com.dderp.common.tool.ERPUtils;
|
|
|
import com.dySweetFishPlugin.elasticsearch.ESClient;
|
|
|
+import com.dySweetFishPlugin.sql.RMapUtils;
|
|
|
import com.dySweetFishPlugin.sql.TableIdService;
|
|
|
import com.dySweetFishPlugin.sql.dao.TunaService;
|
|
|
import com.sweetfish.convert.json.JsonConvert;
|
|
|
@@ -22,19 +24,32 @@ import com.sweetfish.util.AnyValue;
|
|
|
import com.sweetfish.util.AutoLoad;
|
|
|
import com.sweetfish.util.ResourceType;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.lucene.search.join.ScoreMode;
|
|
|
import org.elasticsearch.action.DocWriteResponse;
|
|
|
+import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
|
|
+import org.elasticsearch.action.bulk.BulkResponse;
|
|
|
+import org.elasticsearch.action.index.IndexRequestBuilder;
|
|
|
import org.elasticsearch.action.index.IndexResponse;
|
|
|
import org.elasticsearch.action.support.WriteRequest;
|
|
|
+import org.elasticsearch.action.update.UpdateRequest;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.Operator;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
+import org.elasticsearch.index.reindex.DeleteByQueryAction;
|
|
|
+import org.elasticsearch.join.query.JoinQueryBuilders;
|
|
|
import org.elasticsearch.search.sort.SortBuilders;
|
|
|
import org.elasticsearch.search.sort.SortOrder;
|
|
|
import org.rex.RMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
|
|
|
|
@AutoLoad(value = false)
|
|
|
@Local
|
|
|
@@ -63,9 +78,10 @@ public class StoreServiceImpl extends BaseService implements StoreService {
|
|
|
storeDao = tunaService.generate(StoreDao.class);
|
|
|
}
|
|
|
|
|
|
+ //region 门店品牌档案
|
|
|
@Override
|
|
|
public List<StoreBrand> queryStoreBrandList(RMap params, PageFlipper pageFlipper, long supplierCode) {
|
|
|
- List<StoreBrand> storeBrandList = searchESList(esClient, jsonConvert,
|
|
|
+ return searchESList(esClient, jsonConvert,
|
|
|
StoreBrand.class,
|
|
|
null,
|
|
|
((sd) -> {
|
|
|
@@ -89,8 +105,6 @@ public class StoreServiceImpl extends BaseService implements StoreService {
|
|
|
}),
|
|
|
keysService.getESKey(ESKeys.ES_DELIVER_STORE_BRAND_TYPE, supplierCode),
|
|
|
(() -> SortBuilders.fieldSort("id").order(SortOrder.DESC)));
|
|
|
-
|
|
|
- return storeBrandList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -134,7 +148,7 @@ public class StoreServiceImpl extends BaseService implements StoreService {
|
|
|
if (itemResponse.getResult() == DocWriteResponse.Result.CREATED) {
|
|
|
storeDao.addStoreBrand(storeBrand, dataSourceId, supplierCode);
|
|
|
} else {
|
|
|
- return RetResult.<StoreBrand>errorT().retinfo("创建平台档案失败");
|
|
|
+ return RetResult.<StoreBrand>errorT().retinfo("创建门店品牌失败");
|
|
|
}
|
|
|
|
|
|
return RetResult.<StoreBrand>successT().result(storeBrand);
|
|
|
@@ -143,55 +157,581 @@ public class StoreServiceImpl extends BaseService implements StoreService {
|
|
|
@Override
|
|
|
public RetResult<StoreBrand> uploadBrandLogo(long idStoreBrand, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
return null;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetResult<StoreBrand> updateStoreBrand(StoreBrand storeBrand, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
- return null;
|
|
|
+ if (StringUtils.isBlank(storeBrand.getBrandName()))
|
|
|
+ return RetResult.<StoreBrand>errorT().retinfo("门店品牌名称不可为空");
|
|
|
+
|
|
|
+ StoreBrand esInfo = this.getStoreBrand(storeBrand.getId(), supplierCode);
|
|
|
+ if (esInfo == null)
|
|
|
+ return RetResult.<StoreBrand>errorT().retinfo("未找到此门店品牌");
|
|
|
+
|
|
|
+ //先查一下有没有重名的平台信息(防止修改名称改重)
|
|
|
+ StoreBrand checkNameInfo = this.getESOneInfo(esClient, jsonConvert,
|
|
|
+ StoreBrand.class,
|
|
|
+ (a) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_BRAND_TYPE));
|
|
|
+ qb.must(QueryBuilders.termQuery("brandName.raw", storeBrand.getBrandName()))
|
|
|
+ .mustNot(QueryBuilders.idsQuery(String.valueOf(storeBrand.getId())));
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ },
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_BRAND_INDEX, supplierCode),
|
|
|
+ null);
|
|
|
+
|
|
|
+ if (checkNameInfo != null) return RetResult.<StoreBrand>errorT().retinfo("已存在同名的门店品牌");
|
|
|
+
|
|
|
+ esInfo.setBrandName(storeBrand.getBrandName());
|
|
|
+ esInfo.setStartingPrice(storeBrand.getStartingPrice());
|
|
|
+ esInfo.setPackagingFee(storeBrand.getPackagingFee());
|
|
|
+ esInfo.setBrandMemo(storeBrand.getBrandMemo());
|
|
|
+ StoreBrand.update(esInfo, currentUser.getId());
|
|
|
+ try {
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest(keysService.getESKey(ESKeys.ES_DELIVER_STORE_BRAND_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_BRAND_TYPE, String.valueOf(esInfo.getId()))
|
|
|
+ .doc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("brandName", esInfo.getBrandName())
|
|
|
+ .field("startingPrice", esInfo.getStartingPrice())
|
|
|
+ .field("packagingFee", esInfo.getPackagingFee())
|
|
|
+ .field("brandMemo", esInfo.getBrandMemo())
|
|
|
+ .field("updateTimeLong", esInfo.getUpdateTimeLong())
|
|
|
+ .field("updateBy", esInfo.getUpdateBy())
|
|
|
+ .endObject())
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+
|
|
|
+ esClient.getClient().update(updateRequest).get();
|
|
|
+ } catch (IOException | InterruptedException | ExecutionException e) {
|
|
|
+ logger.error("修改门店品牌[" + esInfo.getId() + "出错:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ storeDao.updateStoreBrand(esInfo, dataSourceId, supplierCode);
|
|
|
+ return RetResult.successT();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetResult<StoreBrand> voidStoreBrand(StoreBrand storeBrand, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
- return null;
|
|
|
+ StoreBrand esInfo = this.getStoreBrand(storeBrand.getId(), supplierCode);
|
|
|
+ if (esInfo == null) {
|
|
|
+ return RetResult.<StoreBrand>errorT().retinfo("未找到此门店品牌");
|
|
|
+ }
|
|
|
+ esInfo.setVoidFlag(storeBrand.getVoidFlag());
|
|
|
+ StoreBrand.update(esInfo, currentUser.getId());
|
|
|
+ try {
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest(keysService.getESKey(ESKeys.ES_DELIVER_STORE_BRAND_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_BRAND_TYPE, String.valueOf(esInfo.getId()))
|
|
|
+ .doc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("voidFlag", esInfo.getVoidFlag())
|
|
|
+ .field("updateTimeLong", esInfo.getUpdateTimeLong())
|
|
|
+ .field("updateBy", esInfo.getUpdateBy())
|
|
|
+ .endObject())
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+
|
|
|
+ esClient.getClient().update(updateRequest).get();
|
|
|
+ } catch (IOException | InterruptedException | ExecutionException e) {
|
|
|
+ logger.error("禁用或启用门店品牌[" + esInfo.getId() + "出错:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ storeDao.voidStoreBrand(esInfo, dataSourceId, supplierCode);
|
|
|
+ return RetResult.successT();
|
|
|
}
|
|
|
+ //endregion
|
|
|
|
|
|
@Override
|
|
|
public List<ViewStoreInfo> queryViewStoreInfo(RMap params, PageFlipper pageFlipper, long supplierCode) {
|
|
|
- return null;
|
|
|
+ Set<Long> idStores = new HashSet<>();
|
|
|
+ List<StoreInfo> storeInfoList = searchESList(esClient, jsonConvert,
|
|
|
+ StoreInfo.class,
|
|
|
+ null,
|
|
|
+ ((sd) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery();
|
|
|
+ qb = qb.must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_INFO_TYPE));
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "storeName")) {
|
|
|
+ String storeName = params.getString("storeName");
|
|
|
+ BoolQueryBuilder qbStoreName = QueryBuilders.boolQuery()
|
|
|
+ .should(QueryBuilders.matchQuery("storeName", storeName).analyzer("query_ansj").operator(Operator.AND))
|
|
|
+ .should(QueryBuilders.termQuery("storeName.number", storeName.toLowerCase()))
|
|
|
+ .should(QueryBuilders.matchQuery("storeName.letter", storeName.toLowerCase()).operator(Operator.AND));
|
|
|
+ qb = qb.must(qbStoreName);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "idBrand")) {
|
|
|
+ qb = qb.must(QueryBuilders.termQuery("idBrand", params.getLong("idBrand")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "idStoreType")) {
|
|
|
+ qb = qb.must(QueryBuilders.termQuery("idStoreType", params.getLong("idStoreType")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "deliverSettleKind")) {
|
|
|
+ qb = qb.must(QueryBuilders.termQuery("deliverSettleKind", params.getInt("deliverSettleKind")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "storeCodeInput")) {
|
|
|
+ String storeCodeInput = params.getString("storeCodeInput");
|
|
|
+ BoolQueryBuilder qbStoreCode = QueryBuilders.boolQuery()
|
|
|
+ .should(QueryBuilders.matchQuery("storeCodeInput", storeCodeInput).analyzer("query_ansj").operator(Operator.AND))
|
|
|
+ .should(QueryBuilders.termQuery("storeCodeInput.number", storeCodeInput.toLowerCase()))
|
|
|
+ .should(QueryBuilders.matchQuery("storeCodeInput.letter", storeCodeInput.toLowerCase()).operator(Operator.AND));
|
|
|
+ qb = qb.must(qbStoreCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "contractPhone")) {
|
|
|
+ String phone = params.getString("contractPhone");
|
|
|
+ qb = qb.must(QueryBuilders.termQuery("contractPhone", phone));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "voidFlag")) {
|
|
|
+ qb = qb.must(QueryBuilders.termQuery("voidFlag", params.getInt("voidFlag")));
|
|
|
+ }
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ }),
|
|
|
+ ((op) -> {
|
|
|
+ idStores.add(op.getId());
|
|
|
+ }),
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ pageFlipper,
|
|
|
+ (() -> SortBuilders.fieldSort("id").order(SortOrder.DESC))
|
|
|
+ );
|
|
|
+
|
|
|
+ long[] idStoreArray = idStores.stream().mapToLong(Long::valueOf).toArray();
|
|
|
+ String idStoreStr = idStores.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
+ Map<Long, List<StorePlatform>> storePlatformMap = searchESMapList(idStoreArray, esClient, jsonConvert,
|
|
|
+ StorePlatform.class,
|
|
|
+ null,
|
|
|
+ ((sd) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery();
|
|
|
+ qb = qb.must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_PLATFORM_TYPE))
|
|
|
+ .must(QueryBuilders.termsQuery("idStore", idStoreStr.split(",")));
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ }),
|
|
|
+ (StorePlatform::getIdStore),
|
|
|
+ new String[]{keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode)},
|
|
|
+ (SortBuilderExecutor) null);
|
|
|
+
|
|
|
+ List<ViewStoreInfo> viewStoreInfoList = new ArrayList<>();
|
|
|
+
|
|
|
+ storeInfoList.forEach(x -> {
|
|
|
+ x.setPlatformList(storePlatformMap.get(x.getId()));
|
|
|
+ ViewStoreInfo viewStoreInfo = new ViewStoreInfo(x);
|
|
|
+ viewStoreInfoList.add(viewStoreInfo);
|
|
|
+ });
|
|
|
+
|
|
|
+ return viewStoreInfoList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ViewStoreInfo getViewStoreInfo(long idStore, long supplierCode, int withInvoice) {
|
|
|
- return null;
|
|
|
+ public ViewStoreInfo getViewStoreInfo(long idStore, long supplierCode, boolean readInvoice, boolean readEmployee, boolean readPlatform) {
|
|
|
+ StoreInfo storeInfo = getESOneInfo(esClient, jsonConvert, StoreInfo.class,
|
|
|
+ String.valueOf(idStore),
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_INFO_TYPE,
|
|
|
+ null
|
|
|
+ );
|
|
|
+
|
|
|
+ if (readInvoice) {
|
|
|
+ StoreInvoiceInfo storeInvoiceInfo = getESOneInfo(esClient, jsonConvert, StoreInvoiceInfo.class,
|
|
|
+ ((sd) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery();
|
|
|
+ qb = qb.must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_INVOICE_INFO_TYPE))
|
|
|
+ .must(QueryBuilders.termQuery("idStore", idStore));
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ }),
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_TYPE, supplierCode),
|
|
|
+ null
|
|
|
+ );
|
|
|
+ storeInfo.setInvoiceInfo(storeInvoiceInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (readEmployee) { //先不用
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (readPlatform) {
|
|
|
+ List<StorePlatform> platformList = searchESList(esClient,jsonConvert,StorePlatform.class,
|
|
|
+ null,
|
|
|
+ ((sd) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery();
|
|
|
+ qb = qb.must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_PLATFORM_TYPE))
|
|
|
+ .must(QueryBuilders.termQuery("idStore",idStore));
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ }),
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ (SortBuilderExecutor) null
|
|
|
+ );
|
|
|
+ storeInfo.setPlatformList(platformList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new ViewStoreInfo(storeInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetResult<StoreInfo> addStoreInfo(StoreInfo storeInfo, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
- return null;
|
|
|
+ if (StringUtils.isBlank(storeInfo.getStoreName()))
|
|
|
+ return RetResult.<StoreInfo>errorT().retinfo("门店名称不可为空");
|
|
|
+
|
|
|
+ //其他是否必须输入 前端判断
|
|
|
+ //先查一下有没有重名的平台信息
|
|
|
+ StoreBrand esInfo = this.getESOneInfo(esClient, jsonConvert,
|
|
|
+ StoreBrand.class,
|
|
|
+ (a) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_INFO_TYPE));
|
|
|
+ qb.must(QueryBuilders.termQuery("storeName.raw", storeInfo.getStoreName()));
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ },
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ null);
|
|
|
+
|
|
|
+ if (esInfo != null) return RetResult.<StoreInfo>errorT().retinfo("已存在同名的门店");
|
|
|
+
|
|
|
+ storeInfo.setId(tableIdService.getTableIdMulti("tbStoreInfo.id", 1, dataSourceId, String.valueOf(supplierCode)));
|
|
|
+ StoreInfo.create(storeInfo, currentUser.getId());
|
|
|
+ storeInfo.setEnableInvoice(0);
|
|
|
+
|
|
|
+ IndexResponse itemResponse = esClient.getClient()
|
|
|
+ .prepareIndex(keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_TYPE, supplierCode), ESKeys.ES_DELIVER_STORE_INFO_INDEX)
|
|
|
+ .setId(String.valueOf(storeInfo.getId()))
|
|
|
+ .setSource(jsonConvert.convertTo(storeInfo), XContentType.JSON)
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
|
|
+ .get();
|
|
|
+
|
|
|
+ if (itemResponse.getResult() == DocWriteResponse.Result.CREATED) {
|
|
|
+ storeDao.addStoreInfo(storeInfo, dataSourceId, supplierCode);
|
|
|
+ } else {
|
|
|
+ return RetResult.<StoreInfo>errorT().retinfo("创建门店失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ return RetResult.successT();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public StoreInvoiceInfo getStoreInvoiceInfo(long idStore, long supplierCode) {
|
|
|
+ return this.getESOneInfo(esClient, jsonConvert,
|
|
|
+ StoreInvoiceInfo.class,
|
|
|
+ (sd) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_INVOICE_INFO_TYPE));
|
|
|
+ qb.must(QueryBuilders.termQuery("idStore", idStore));
|
|
|
+ return qb;
|
|
|
+ },
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_TYPE, supplierCode),
|
|
|
+ null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetResult<StoreInvoiceInfo> configStoreInvoiceInfo(StoreInvoiceInfo invoiceInfo, int enableInvoice, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
- return null;
|
|
|
+ StoreInfo esStoreInfo = this.getViewStoreInfo(invoiceInfo.getIdStore(), supplierCode, false, false, false).getStoreInfo();
|
|
|
+ if (esStoreInfo == null)
|
|
|
+ return RetResult.<StoreInvoiceInfo>errorT().retinfo("未找到门店信息");
|
|
|
+ esStoreInfo.setEnableInvoice(enableInvoice);
|
|
|
+ StoreInfo.update(esStoreInfo, currentUser.getId());
|
|
|
+ try {
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest(
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_INFO_TYPE, String.valueOf(esStoreInfo.getId()))
|
|
|
+ .doc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("enableInvoice", esStoreInfo.getEnableInvoice())
|
|
|
+ .field("updateTimeLong", esStoreInfo.getUpdateTimeLong())
|
|
|
+ .field("updateBy", esStoreInfo.getUpdateBy())
|
|
|
+ .endObject())
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+ esClient.getClient().update(updateRequest).get();
|
|
|
+
|
|
|
+ } catch (IOException | InterruptedException | ExecutionException e) {
|
|
|
+ logger.error("启用或停用门店开票信息[" + esStoreInfo.getId() + "出错:" + e.getMessage(), e);
|
|
|
+ RetResult.<StoreInvoiceInfo>errorT().retinfo("启用或停用门店开票信息[" + esStoreInfo.getId() + "出错:");
|
|
|
+ }
|
|
|
+ if (enableInvoice == 0) { //停用门店开票 不动发票信息
|
|
|
+ storeDao.updateStoreEnableInvoice(esStoreInfo, dataSourceId, supplierCode);
|
|
|
+ return RetResult.successT();
|
|
|
+ }
|
|
|
+ // 启用开票
|
|
|
+ StoreInvoiceInfo esInvoice = getStoreInvoiceInfo(invoiceInfo.getIdStore(), supplierCode);
|
|
|
+ if (esInvoice == null) { // 未设置过发票信息 需要新增
|
|
|
+ invoiceInfo.setId(tableIdService.getTableIdMulti("tbStoreInvoiceInfo.id", 1, dataSourceId, String.valueOf(supplierCode)));
|
|
|
+ StoreInvoiceInfo.create(invoiceInfo, currentUser.getId());
|
|
|
+ IndexResponse itemResponse = esClient.getClient()
|
|
|
+ .prepareIndex(
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INVOICE_INFO_TYPE, supplierCode), ESKeys.ES_DELIVER_STORE_INFO_INDEX)
|
|
|
+ .setId(String.valueOf(invoiceInfo.getId()))
|
|
|
+ .setParent(String.valueOf(invoiceInfo.getIdStore()))
|
|
|
+ .setSource(jsonConvert.convertTo(invoiceInfo), XContentType.JSON)
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
|
|
+ .get();
|
|
|
+
|
|
|
+ if (itemResponse.getResult() == DocWriteResponse.Result.CREATED) {
|
|
|
+ storeDao.addStoreInvoiceInfo(invoiceInfo, esStoreInfo, dataSourceId, supplierCode);
|
|
|
+ } else {
|
|
|
+ return RetResult.<StoreInvoiceInfo>errorT().retinfo("门店启用开票失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ esInvoice.setTaxIdNo(invoiceInfo.getTaxIdNo());
|
|
|
+ esInvoice.setCompanyName(invoiceInfo.getCompanyName());
|
|
|
+ esInvoice.setDefaultTaxItemCode(invoiceInfo.getDefaultTaxItemCode());
|
|
|
+ esInvoice.setDefaultTaxItemName(invoiceInfo.getDefaultTaxItemName());
|
|
|
+ esInvoice.setTaxRate(invoiceInfo.getTaxRate());
|
|
|
+ StoreInvoiceInfo.update(esInvoice, currentUser.getId());
|
|
|
+
|
|
|
+ try {
|
|
|
+ UpdateRequest updateInvoiceRequest = new UpdateRequest(
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_INVOICE_INFO_TYPE, String.valueOf(esStoreInfo.getId()))
|
|
|
+ .doc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("taxIdNo", esInvoice.getTaxIdNo())
|
|
|
+ .field("companyName", esInvoice.getCompanyName())
|
|
|
+ .field("defaultTaxItemName", esInvoice.getDefaultTaxItemName())
|
|
|
+ .field("defaultTaxItemCode", esInvoice.getDefaultTaxItemCode())
|
|
|
+ .field("taxRate", esInvoice.getTaxRate())
|
|
|
+ .field("updateTimeLong", esInvoice.getUpdateTimeLong())
|
|
|
+ .field("updateBy", esInvoice.getUpdateBy())
|
|
|
+ .endObject())
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+ esClient.getClient().update(updateInvoiceRequest).get();
|
|
|
+
|
|
|
+ } catch (IOException | InterruptedException | ExecutionException e) {
|
|
|
+ logger.error("门店启用开票信息[" + esStoreInfo.getId() + "出错" + e.getMessage(), e);
|
|
|
+ return RetResult.<StoreInvoiceInfo>errorT().retinfo("门店启用开票失败");
|
|
|
+ }
|
|
|
+ storeDao.updateStoreInvoiceInfo(esInvoice, esStoreInfo, dataSourceId, supplierCode);
|
|
|
+ }
|
|
|
+ return RetResult.successT();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetResult<StoreInfo> updateStoreInfo(StoreInfo storeInfo, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
- return null;
|
|
|
+ if (StringUtils.isBlank(storeInfo.getStoreName()))
|
|
|
+ return RetResult.<StoreInfo>errorT().retinfo("门店名称不可为空");
|
|
|
+
|
|
|
+ StoreInfo esInfo = this.getViewStoreInfo(storeInfo.getId(), supplierCode, false, false, false).getStoreInfo();
|
|
|
+ if (esInfo == null) {
|
|
|
+ return RetResult.<StoreInfo>errorT().retinfo("未找到此门店品牌");
|
|
|
+ }
|
|
|
+ //先查一下有没有重名的门店信息(防止修改名称改重)同行业门店不同地区门店名可以重
|
|
|
+ StoreBrand checkNameInfo = this.getESOneInfo(esClient, jsonConvert,
|
|
|
+ StoreBrand.class,
|
|
|
+ (a) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_INFO_TYPE));
|
|
|
+ qb.must(QueryBuilders.termQuery("storeName.raw", esInfo.getStoreName()))
|
|
|
+ .mustNot(QueryBuilders.idsQuery(String.valueOf(esInfo.getId())));
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ },
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ null);
|
|
|
+
|
|
|
+ if (checkNameInfo != null) return RetResult.<StoreInfo>errorT().retinfo("已存在同名的门店");
|
|
|
+
|
|
|
+ esInfo.setStoreName(storeInfo.getStoreName());
|
|
|
+ esInfo.setIdBrand(storeInfo.getIdBrand());
|
|
|
+ esInfo.setBrandName(storeInfo.getBrandName());
|
|
|
+ esInfo.setIdStoreType(storeInfo.getIdStoreType());
|
|
|
+ esInfo.setDeliverSettleKind(storeInfo.getDeliverSettleKind());
|
|
|
+ esInfo.setStoreCodeInput(storeInfo.getStoreCodeInput());
|
|
|
+ esInfo.setStoreProvince(storeInfo.getStoreProvince());
|
|
|
+ esInfo.setStoreCity(storeInfo.getStoreCity());
|
|
|
+ esInfo.setStoreDistrict(storeInfo.getStoreDistrict());
|
|
|
+ esInfo.setStoreAddress(storeInfo.getStoreAddress());
|
|
|
+ esInfo.setLocationStr(storeInfo.getLocationStr());
|
|
|
+ esInfo.setContractPhone(storeInfo.getContractPhone());
|
|
|
+ esInfo.setStoreBossId(storeInfo.getStoreBossId());
|
|
|
+ StoreInfo.update(esInfo, currentUser.getId());
|
|
|
+ try {
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest(keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_INFO_TYPE, String.valueOf(esInfo.getId()))
|
|
|
+ .doc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("storeName", esInfo.getStoreName())
|
|
|
+ .field("idBrand", esInfo.getIdBrand())
|
|
|
+ .field("brandName", esInfo.getBrandName())
|
|
|
+ .field("idStoreType", esInfo.getIdStoreType())
|
|
|
+ .field("deliverSettleKind", esInfo.getDeliverSettleKind())
|
|
|
+ .field("storeCodeInput", esInfo.getStoreCodeInput())
|
|
|
+ .field("storeProvince", esInfo.getStoreProvince())
|
|
|
+ .field("storeCity", esInfo.getStoreCity())
|
|
|
+ .field("storeDistrict", esInfo.getStoreDistrict())
|
|
|
+ .field("storeAddress", esInfo.getStoreAddress())
|
|
|
+ .field("locationStr", esInfo.getLocationStr())
|
|
|
+ .field("contractPhone", esInfo.getContractPhone())
|
|
|
+ .field("storeBossId", esInfo.getStoreBossId())
|
|
|
+ .field("updateTimeLong", esInfo.getUpdateTimeLong())
|
|
|
+ .field("updateBy", esInfo.getUpdateBy())
|
|
|
+ .endObject())
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+
|
|
|
+ esClient.getClient().update(updateRequest).get();
|
|
|
+ } catch (IOException | InterruptedException | ExecutionException e) {
|
|
|
+ logger.error("修改门店[" + esInfo.getId() + "出错:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ storeDao.updateStoreInfo(esInfo, dataSourceId, supplierCode);
|
|
|
+ return RetResult.successT();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetResult<StoreInfo> voidStoreInfo(StoreInfo storeInfo, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
- return null;
|
|
|
+ StoreInfo esInfo = this.getViewStoreInfo(storeInfo.getId(), supplierCode, false, false, false).getStoreInfo();
|
|
|
+ if (esInfo == null) {
|
|
|
+ return RetResult.<StoreInfo>errorT().retinfo("未找到此门店");
|
|
|
+ }
|
|
|
+ esInfo.setVoidFlag(storeInfo.getVoidFlag());
|
|
|
+ StoreInfo.update(esInfo, currentUser.getId());
|
|
|
+ try {
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest(keysService.getESKey(ESKeys.ES_DELIVER_STORE_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_INFO_TYPE, String.valueOf(esInfo.getId()))
|
|
|
+ .doc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("voidFlag", esInfo.getVoidFlag())
|
|
|
+ .field("updateTimeLong", esInfo.getUpdateTimeLong())
|
|
|
+ .field("updateBy", esInfo.getUpdateBy())
|
|
|
+ .endObject())
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+
|
|
|
+ esClient.getClient().update(updateRequest).get();
|
|
|
+ } catch (IOException | InterruptedException | ExecutionException e) {
|
|
|
+ logger.error("禁用或启用门店[" + esInfo.getId() + "出错:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ storeDao.voidStoreInfo(esInfo, dataSourceId, supplierCode);
|
|
|
+ return RetResult.successT();
|
|
|
+ }
|
|
|
+
|
|
|
+ //region 门店平台
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public StorePlatform getStoreStorePlatformInfo(long id, long supplierCode) {
|
|
|
+ return this.getESOneInfo(esClient, jsonConvert, StorePlatform.class,
|
|
|
+ String.valueOf(id),
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_PLATFORM_TYPE,
|
|
|
+ null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetResult<StorePlatform> addStorePlatform(StorePlatform storePlatform, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
- return null;
|
|
|
+ StorePlatform esInfo = this.getESOneInfo(esClient, jsonConvert,
|
|
|
+ StorePlatform.class,
|
|
|
+ (a) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_PLATFORM_TYPE));
|
|
|
+ qb.must(QueryBuilders.termQuery("idPlatformInfo", storePlatform.getIdPlatformInfo()));
|
|
|
+ return qb;
|
|
|
+ },
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_PLATFORM_INDEX, supplierCode),
|
|
|
+ null);
|
|
|
+ if (esInfo != null)
|
|
|
+ return RetResult.<StorePlatform>errorT().retinfo("此平台已开通:" + storePlatform.getPlatformName());
|
|
|
+
|
|
|
+ storePlatform.setId(tableIdService.getTableIdMulti("tbStorePlatform.id", 1, dataSourceId, String.valueOf(supplierCode)));
|
|
|
+ StorePlatform.create(storePlatform, currentUser.getId());
|
|
|
+ storePlatform.setEnableStatue(0);
|
|
|
+
|
|
|
+ BulkRequestBuilder bulkRequest = esClient.getClient().prepareBulk().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+
|
|
|
+ bulkRequest.add(esClient.getClient().prepareIndex(
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_PLATFORM_INDEX, supplierCode), ESKeys.ES_DELIVER_STORE_PLATFORM_TYPE)
|
|
|
+ .setId(String.valueOf(storePlatform.getId()))
|
|
|
+ .setSource(jsonConvert.convertTo(storePlatform), XContentType.JSON));
|
|
|
+
|
|
|
+ storePlatform.getRequireList().forEach(x -> {
|
|
|
+ x.setId(tableIdService.getTableIdMulti("tbStorePlatformRequire.id", 1, dataSourceId, String.valueOf(supplierCode)));
|
|
|
+ x.setIdStore(storePlatform.getIdStore());
|
|
|
+ x.setIdStorePlatform(storePlatform.getId());
|
|
|
+ StorePlatformRequire.create(x, currentUser.getId());
|
|
|
+
|
|
|
+ bulkRequest.add(esClient.getClient().prepareIndex(
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_PLATFORM_INDEX, supplierCode), ESKeys.ES_DELIVER_STORE_PLATFORM_REQUIRE_TYPE)
|
|
|
+ .setId(String.valueOf(x.getId()))
|
|
|
+ .setParent(String.valueOf(storePlatform.getId()))
|
|
|
+ .setSource(jsonConvert.convertTo(storePlatform), XContentType.JSON));
|
|
|
+ });
|
|
|
+
|
|
|
+ BulkResponse bulkResponse = bulkRequest.get();
|
|
|
+
|
|
|
+ if (bulkResponse.hasFailures()) {
|
|
|
+ logger.error("门店开通平台出错:" + bulkResponse.buildFailureMessage());
|
|
|
+ return RetResult.<StorePlatform>errorT().retinfo("门店开通平台出错:" + storePlatform.getPlatformName());
|
|
|
+ } else {
|
|
|
+ logger.info("门店开通平台成功");
|
|
|
+ //写数据库
|
|
|
+ storeDao.addStorePlatform(storePlatform, storePlatform.getRequireList(), dataSourceId, supplierCode);
|
|
|
+ return RetResult.successT();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public RetResult<StorePlatform> configStorePlatform(StorePlatform storePlatform, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
- return null;
|
|
|
+ StorePlatform esInfo = this.getStoreStorePlatformInfo(storePlatform.getId(), supplierCode);
|
|
|
+ if (esInfo == null) {
|
|
|
+ return RetResult.<StorePlatform>errorT().retinfo("未找到此开通平台");
|
|
|
+ }
|
|
|
+
|
|
|
+ esInfo.setIdStore(storePlatform.getIdPlatformInfo());
|
|
|
+ esInfo.setPlatformName(storePlatform.getPlatformName());
|
|
|
+ esInfo.setPlatformType(storePlatform.getPlatformType());
|
|
|
+ esInfo.setEnableStatue(storePlatform.getEnableStatue());
|
|
|
+ StorePlatform.update(esInfo, currentUser.getId());
|
|
|
+
|
|
|
+ BulkRequestBuilder bulkRequest = esClient.getClient().prepareBulk().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
|
|
+ UpdateRequest updateRequest = null;
|
|
|
+ try {
|
|
|
+ updateRequest = new UpdateRequest(keysService.getESKey(ESKeys.ES_DELIVER_STORE_PLATFORM_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_STORE_PLATFORM_TYPE, String.valueOf(esInfo.getId()))
|
|
|
+ .doc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("idPlatformInfo", esInfo.getIdPlatformInfo())
|
|
|
+ .field("platformName", esInfo.getPlatformName())
|
|
|
+ .field("platformType", esInfo.getPlatformType())
|
|
|
+ .field("enableStatue", esInfo.getEnableStatue())
|
|
|
+ .field("updateTimeLong", esInfo.getUpdateTimeLong())
|
|
|
+ .field("updateBy", esInfo.getUpdateBy())
|
|
|
+ .endObject());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ bulkRequest.add(updateRequest);
|
|
|
+
|
|
|
+ storePlatform.getRequireList().forEach(x -> {
|
|
|
+ if (x.getId() <= 0) {
|
|
|
+ x.setId(tableIdService.getTableIdMulti("tbStorePlatformRequire.id", 1, dataSourceId, String.valueOf(supplierCode)));
|
|
|
+ StorePlatformRequire.create(x, currentUser.getId());
|
|
|
+ }
|
|
|
+ x.setIdStore(storePlatform.getIdStore());
|
|
|
+ x.setIdStorePlatform(storePlatform.getIdPlatformInfo());
|
|
|
+ StorePlatformRequire.update(x, currentUser.getId());
|
|
|
+ bulkRequest.add(esClient.getClient().prepareIndex(
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_STORE_PLATFORM_INDEX, supplierCode), ESKeys.ES_DELIVER_STORE_PLATFORM_REQUIRE_TYPE)
|
|
|
+ .setId(String.valueOf(x.getId()))
|
|
|
+ .setParent(String.valueOf(storePlatform.getId()))
|
|
|
+ .setSource(jsonConvert.convertTo(storePlatform), XContentType.JSON));
|
|
|
+ });
|
|
|
+
|
|
|
+ BoolQueryBuilder qbOrderPart = QueryBuilders.boolQuery()
|
|
|
+ .must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_STORE_PLATFORM_REQUIRE_TYPE))
|
|
|
+ .must(QueryBuilders.termQuery("idStorePlatform", esInfo.getId()));
|
|
|
+ DeleteByQueryAction.INSTANCE.newRequestBuilder(esClient.getClient())
|
|
|
+ .refresh(true)
|
|
|
+ .source(keysService.getESKey(ESKeys.ES_DELIVER_STORE_PLATFORM_INDEX, supplierCode))
|
|
|
+ .filter(qbOrderPart)
|
|
|
+ .get();
|
|
|
+
|
|
|
+ BulkResponse bulkResponse = bulkRequest.get();
|
|
|
+
|
|
|
+ if (bulkResponse.hasFailures()) {
|
|
|
+ logger.error("门店配置平台出错:" + bulkResponse.buildFailureMessage());
|
|
|
+ return RetResult.<StorePlatform>errorT().retinfo("门店配置平台出错:" + storePlatform.getPlatformName());
|
|
|
+ } else {
|
|
|
+ logger.info("门店配置平台成功");
|
|
|
+ //写数据库
|
|
|
+ storeDao.updateStorePlatform(esInfo, storePlatform.getRequireList(), dataSourceId, supplierCode);
|
|
|
+ return RetResult.successT();
|
|
|
+ }
|
|
|
}
|
|
|
+ //endregion
|
|
|
}
|