|
|
@@ -0,0 +1,255 @@
|
|
|
+package com.dderp.business.service;
|
|
|
+
|
|
|
+import com.dderp.business.dao.PlatformDao;
|
|
|
+import com.dderp.common.api.NoSqlKeysService;
|
|
|
+import com.dderp.common.api.PlatformService;
|
|
|
+import com.dderp.common.base.BaseService;
|
|
|
+import com.dderp.common.datas.ESKeys;
|
|
|
+import com.dderp.common.datas.business.PlatformType;
|
|
|
+import com.dderp.common.entity.platform.PlatformInfo;
|
|
|
+import com.dderp.common.entity.platform.PlatformRequire;
|
|
|
+import com.dderp.common.entity.site.ERPTokenUser;
|
|
|
+import com.dderp.common.tool.ERPUtils;
|
|
|
+import com.dySweetFishPlugin.elasticsearch.ESClient;
|
|
|
+import com.dySweetFishPlugin.sql.TableIdService;
|
|
|
+import com.dySweetFishPlugin.sql.dao.TunaService;
|
|
|
+import com.sweetfish.convert.json.JsonConvert;
|
|
|
+import com.sweetfish.service.Local;
|
|
|
+import com.sweetfish.service.RetResult;
|
|
|
+import com.sweetfish.source.PageFlipper;
|
|
|
+import com.sweetfish.util.AnyValue;
|
|
|
+import com.sweetfish.util.AutoLoad;
|
|
|
+import com.sweetfish.util.ResourceType;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.elasticsearch.action.DocWriteResponse;
|
|
|
+import org.elasticsearch.action.index.IndexResponse;
|
|
|
+import org.elasticsearch.action.support.WriteRequest;
|
|
|
+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.search.sort.SortBuilders;
|
|
|
+import org.elasticsearch.search.sort.SortOrder;
|
|
|
+import org.rex.RMap;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
|
+
|
|
|
+@AutoLoad(value = false)
|
|
|
+@Local
|
|
|
+@ResourceType(PlatformService.class)
|
|
|
+public class PlatformServiceImpl extends BaseService implements PlatformService {
|
|
|
+ @Resource
|
|
|
+ private ESClient esClient;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private JsonConvert jsonConvert;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private NoSqlKeysService keysService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TableIdService tableIdService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TunaService tunaService;
|
|
|
+
|
|
|
+ private PlatformDao platformDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void start(AnyValue config) {
|
|
|
+ super.start(config);
|
|
|
+ platformDao = tunaService.generate(PlatformDao.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PlatformInfo> queryPlatformList(RMap params, PageFlipper pageFlipper, long supplierCode) {
|
|
|
+ List<PlatformInfo> platformInfoList = searchESList(esClient, jsonConvert,
|
|
|
+ PlatformInfo.class,
|
|
|
+ null,
|
|
|
+ ((sd) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery();
|
|
|
+ qb = qb.must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_PLATFORM_INFO_TYPE));
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "platformType")) {
|
|
|
+ qb = qb.must(QueryBuilders.termQuery("platformType", params.getInt("platformType")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "platformName")) {
|
|
|
+ String platformName = params.getString("platformName");
|
|
|
+ BoolQueryBuilder qbPlatformName = QueryBuilders.boolQuery()
|
|
|
+ .should(QueryBuilders.matchQuery("platformName", platformName).analyzer("query_ansj").operator(Operator.AND))
|
|
|
+ .should(QueryBuilders.termQuery("platformName.number", platformName.toLowerCase()))
|
|
|
+ .should(QueryBuilders.matchQuery("platformName.letter", platformName.toLowerCase()).operator(Operator.AND));
|
|
|
+ qb = qb.must(qbPlatformName);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "voidFlag")) {
|
|
|
+ qb = qb.must(QueryBuilders.termQuery("voidFlag", params.getInt("voidFlag")));
|
|
|
+ }
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ }),
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode),
|
|
|
+ (() -> SortBuilders.fieldSort("id").order(SortOrder.DESC)));
|
|
|
+
|
|
|
+ return platformInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PlatformInfo getPlatformInfo(long idPlatformInfo, long supplierCode) {
|
|
|
+ return this.getESOneInfo(esClient, jsonConvert,
|
|
|
+ PlatformInfo.class,
|
|
|
+ String.valueOf(idPlatformInfo),
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_PLATFORM_INFO_TYPE,
|
|
|
+ null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RetResult<PlatformInfo> addPlatformInfo(PlatformInfo platformInfo, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
+ if (StringUtils.isBlank(platformInfo.getPlatformName()))
|
|
|
+ return RetResult.<PlatformInfo>errorT().retinfo("平台名称不可为空");
|
|
|
+
|
|
|
+ if (PlatformType.getName(platformInfo.getPlatformType()) == null)
|
|
|
+ return RetResult.<PlatformInfo>errorT().retinfo("平台类型非法");
|
|
|
+
|
|
|
+ //先查一下有没有重名的平台信息
|
|
|
+ PlatformInfo esInfo = this.getESOneInfo(esClient, jsonConvert,
|
|
|
+ PlatformInfo.class,
|
|
|
+ (a) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_PLATFORM_INFO_TYPE));
|
|
|
+ qb.must(QueryBuilders.termQuery("platformName.raw", platformInfo.getPlatformName()));
|
|
|
+ qb.must(QueryBuilders.termQuery("platformType", platformInfo.getPlatformType()));
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ },
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode),
|
|
|
+ null);
|
|
|
+
|
|
|
+ if (esInfo != null) return RetResult.<PlatformInfo>errorT().retinfo("已存在同名的平台");
|
|
|
+
|
|
|
+ platformInfo.setId(tableIdService.getTableIdMulti("tbPlatformInfo.id", 1, dataSourceId, String.valueOf(supplierCode)));
|
|
|
+ //前端传进来的是平台需求的list,由于获取平台信息的时候几乎必带需求信息而且一般不会很多,所以不做子表直接序列化进主表
|
|
|
+ platformInfo.setRequireListSerial(jsonConvert.convertTo(platformInfo.getRequireList()));
|
|
|
+ PlatformInfo.create(platformInfo, currentUser.getId());
|
|
|
+
|
|
|
+ IndexResponse itemResponse = esClient.getClient()
|
|
|
+ .prepareIndex(keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode), ESKeys.ES_DELIVER_PLATFORM_INFO_TYPE)
|
|
|
+ .setId(String.valueOf(platformInfo.getId()))
|
|
|
+ .setSource(jsonConvert.convertTo(platformInfo), XContentType.JSON)
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
|
|
+ .get();
|
|
|
+
|
|
|
+ if (itemResponse.getResult() == DocWriteResponse.Result.CREATED) {
|
|
|
+ platformDao.addPlatformInfo(platformInfo, dataSourceId, supplierCode);
|
|
|
+ } else {
|
|
|
+ return RetResult.<PlatformInfo>errorT().retinfo("创建平台档案失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ return RetResult.<PlatformInfo>successT().result(platformInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RetResult<PlatformInfo> updatePlatformInfo(PlatformInfo platformInfo, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
+ PlatformInfo esInfo = this.getPlatformInfo(platformInfo.getId(), supplierCode);
|
|
|
+ if (esInfo == null)
|
|
|
+ return RetResult.<PlatformInfo>errorT().retinfo("平台信息不存在");
|
|
|
+
|
|
|
+ esInfo.setPlatformName(platformInfo.getPlatformName());
|
|
|
+ esInfo.setPlatformType(platformInfo.getPlatformType());
|
|
|
+ esInfo.setRequireListSerial(jsonConvert.convertTo(platformInfo.getRequireList()));
|
|
|
+
|
|
|
+ PlatformInfo.update(esInfo, currentUser.getId());
|
|
|
+ try {
|
|
|
+ esClient.getClient().prepareUpdate(keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_PLATFORM_INFO_TYPE, String.valueOf(esInfo.getId()))
|
|
|
+ .setDoc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("platformName", esInfo.getPlatformName())
|
|
|
+ .field("platformType", esInfo.getPlatformType())
|
|
|
+ .field("requireListSerial", esInfo.getRequireListSerial())
|
|
|
+ .field("updateBy", esInfo.getUpdateBy())
|
|
|
+ .field("updateTimeLong", esInfo.getUpdateTimeLong())
|
|
|
+ .endObject())
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
|
|
+ .get();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ platformDao.updatePlatformInfo(esInfo, dataSourceId, supplierCode);
|
|
|
+
|
|
|
+ return RetResult.<PlatformInfo>successT().result(esInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RetResult<PlatformInfo> voidPlatformInfo(PlatformInfo platformInfo, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
+ PlatformInfo esInfo = this.getPlatformInfo(platformInfo.getId(), supplierCode);
|
|
|
+ if (esInfo == null)
|
|
|
+ return RetResult.<PlatformInfo>errorT().retinfo("平台信息不存在");
|
|
|
+
|
|
|
+ esInfo.setVoidFlag(platformInfo.getVoidFlag());
|
|
|
+
|
|
|
+ PlatformInfo.update(esInfo, currentUser.getId());
|
|
|
+ try {
|
|
|
+ esClient.getClient().prepareUpdate(keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_INFO_INDEX, supplierCode),
|
|
|
+ ESKeys.ES_DELIVER_PLATFORM_INFO_TYPE, String.valueOf(esInfo.getId()))
|
|
|
+ .setDoc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("voidFlag", esInfo.getVoidFlag())
|
|
|
+ .field("updateBy", esInfo.getUpdateBy())
|
|
|
+ .field("updateTimeLong", esInfo.getUpdateTimeLong())
|
|
|
+ .endObject())
|
|
|
+ .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
|
|
+ .get();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ platformDao.voidPlatformInfo(esInfo, dataSourceId, supplierCode);
|
|
|
+
|
|
|
+ return RetResult.<PlatformInfo>successT().result(esInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PlatformRequire> queryPlatformRequireList(RMap params, PageFlipper pageFlipper, long supplierCode) {
|
|
|
+ return this.searchESList(esClient, jsonConvert, PlatformRequire.class,
|
|
|
+ params,
|
|
|
+ (a) -> {
|
|
|
+ BoolQueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.typeQuery(ESKeys.ES_DELIVER_PLATFORM_REQUIRE_TYPE));
|
|
|
+
|
|
|
+ if (ERPUtils.mapContainKey(params, "requireName")) {
|
|
|
+ String requireName = params.getString("requireName");
|
|
|
+ BoolQueryBuilder qbRequireName = QueryBuilders.boolQuery()
|
|
|
+ .should(QueryBuilders.matchQuery("requireName", requireName).analyzer("query_ansj").operator(Operator.AND))
|
|
|
+ .should(QueryBuilders.termQuery("requireName.number", requireName.toLowerCase()))
|
|
|
+ .should(QueryBuilders.matchQuery("requireName.letter", requireName.toLowerCase()).operator(Operator.AND));
|
|
|
+ qb = qb.must(qbRequireName);
|
|
|
+ }
|
|
|
+
|
|
|
+ return qb;
|
|
|
+ },
|
|
|
+ keysService.getESKey(ESKeys.ES_DELIVER_PLATFORM_REQUIRE_INDEX, supplierCode),
|
|
|
+ (() -> SortBuilders.fieldSort("id").order(SortOrder.DESC)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PlatformRequire addPlatformRequire(PlatformRequire platformRequire, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RetResult<PlatformRequire> updatePlatformRequire(PlatformRequire platformRequire, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RetResult<PlatformRequire> voidPlatformRequire(PlatformRequire platformRequire, ERPTokenUser currentUser, String dataSourceId, long supplierCode) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|