package cn.autoform.web.controller.masterdata;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.concurrent.TimeoutException;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import cn.autoform.bean.CodeAndValueBean;
|
import cn.autoform.bean.MasterJson;
|
import cn.autoform.db.entity.MasterDefineEntity;
|
import cn.autoform.db.entity.MasterElementEntity;
|
import cn.autoform.db.entity.MasterValueEntity;
|
import cn.autoform.db.exten.MasterValue;
|
import cn.autoform.factory.FormFactory;
|
import cn.autoform.factory.product.ProductMethod;
|
import cn.autoform.factory.product.ProductMethod.IOType;
|
import cn.autoform.fw.exception.FormClientException;
|
import cn.autoform.fw.exception.RestResult;
|
import cn.autoform.fw.utility.ConstMap;
|
import cn.autoform.fw.utility.RestResultGenerator;
|
import cn.autoform.util.tool.JSONTool;
|
import cn.autoform.web.client.MasterClient;
|
import cn.autoform.web.service.masterdata.MasterDataService;
|
import net.sf.json.JSONObject;
|
|
@RestController
|
public class MasterDataController {
|
|
@Autowired
|
private MasterDataService masterDataService = null;
|
|
@Autowired
|
private FormFactory formFactory;
|
|
@Autowired
|
private MasterClient masterClient;
|
|
/**
|
* 获得主数据定义
|
* 查询列表
|
* @param tenantID 租户ID
|
* @return 主数据定义
|
* @throws TimeoutException
|
* @throws FormClientException
|
*/
|
@RequestMapping(value = "${requset.masterdata01}", method = RequestMethod.GET)
|
public RestResult<List<MasterDefineEntity>> getMasterBaseDataListService(String formID, String tenantID, String name, String flag) throws TimeoutException, FormClientException {
|
IOType where = flag.equals("services") ? IOType.services : IOType.cloud;
|
// IOType where = IOType.services;
|
ProductMethod productMethod = this.formFactory.createFormMethod(where);
|
List<MasterDefineEntity> masterDefineEntitys = productMethod.getMasterBaseDataListService(tenantID, name);
|
return RestResultGenerator.genSuccessResult(masterDefineEntitys);
|
}
|
|
/**
|
* 获得主数据元素
|
* 选择按钮点击
|
* @param tenantID 租户ID
|
* @param code 主数据定义Code
|
* @return 主数据元素
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.masterdata02}", method = RequestMethod.GET)
|
public RestResult<List<MasterElementEntity>> getMasterBaseElementListService(String formID, String tenantID, String code, String flag) throws Exception {
|
IOType where = flag.equals("services") ? IOType.services : IOType.cloud;
|
List<MasterElementEntity> masterElementEntitys = this.formFactory.createFormMethod(where).getMasterBaseElementListService(formID,tenantID, code);
|
return RestResultGenerator.genSuccessResult(masterElementEntitys);
|
}
|
|
/**
|
* 获得主数据元素值
|
*
|
* @param tenantID 租户ID
|
* @param defineCode 主数据定义代码
|
* @param eleCode 元素code
|
* @return 主数据元素
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.masterdata03}", method = RequestMethod.GET)
|
public RestResult<List<MasterValueEntity>> getMasterBaseValueListService(String tenantID,
|
String defineCode, String eleCode, String flag) throws Exception {
|
IOType where = flag.equals("services") ? IOType.services : IOType.cloud;
|
MasterValue eleCodeMasterValue = new MasterValue();
|
eleCodeMasterValue.setTenantID(tenantID);
|
eleCodeMasterValue.setDefineCode(defineCode);
|
eleCodeMasterValue.setVariableField(eleCode);
|
eleCodeMasterValue.setELE_CODE(eleCode);
|
List<MasterValueEntity> valuesEntitys = null;
|
//这个是最新的工厂方法 将下面if及下面的替换用的,现在还没到那~
|
this.formFactory.createFormMethod().queryMasterValues(tenantID, defineCode, eleCode);
|
if("services".equals(flag)){
|
// valuesEntitys = this.masterClient.queryClientMasterValues(eleCodeMasterValue);
|
}
|
valuesEntitys = masterDataService.queryMasterValues(tenantID, defineCode,
|
eleCode);
|
return RestResultGenerator.genSuccessResult(valuesEntitys);
|
}
|
|
/**
|
* 获得主数据元素
|
* 查询真正的数据
|
* @param tenantID 租户ID
|
* @param code 主数据定义Code
|
* @return 主数据元素
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.masterdata04}", method = RequestMethod.POST)
|
public RestResult<Object> getMasterBaseElementListServiceForNew(@RequestBody MasterJson m) throws Exception {
|
// TODO 当前端FLag值写完以后将换成工厂调用,现工厂中已有方法,没调~
|
IOType where = m.getFlag().equals("services") ? IOType.services : IOType.cloud;
|
return RestResultGenerator.genSuccessResult(
|
this.formFactory.createFormMethod(where)
|
.getMasterBaseElementListServiceForNew(m.getTenantID(),m.getCode(),m.getCallbackId(),m.getCodes(),m.getValue(),m.getIsAll()));
|
}
|
|
|
|
/**
|
* 获得主数据元素
|
*
|
* @param tenantID 租户ID
|
* @param code 主数据定义Code
|
* @return 主数据元素
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.masterdata05}", method = RequestMethod.POST)
|
public RestResult<Object> getMasterBaseElementListServiceForNew2(@RequestBody MasterJson m) throws Exception {
|
Map<String, Object> rsMap = new HashMap<>();
|
|
// MasterValue masterDataCodeEn = new MasterValue();
|
// masterDataCodeEn.setTenantID(m.getTenantID());
|
// masterDataCodeEn.setDefineCode(m.getDefindCode());
|
// masterDataCodeEn.setVariableField(m.getEleCode());
|
// masterDataCodeEn.setELE_CODE(m.getEleCode());
|
// masterDataCodeEn.setELE_CODE(m.getMasterCode());
|
|
MasterValue masterDataNameEn = new MasterValue();
|
masterDataNameEn.setTenantID(m.getTenantID());
|
masterDataNameEn.setDefineCode(m.getDefindCode());
|
masterDataNameEn.setVariableField(m.getMasterCode());
|
masterDataNameEn.setELE_CODE(m.getEleCode());
|
masterDataNameEn.setEleName(m.getEleValue());
|
|
//下面注释为cloud端代码
|
// List<MasterValueEntity> masterDataCode = masterDataService.queryMasterValues(tenantID, defindCode, eleCode);
|
// List<MasterValueEntity> masterDataName = masterDataService.queryMasterValues(tenantID, defindCode, masterCode);
|
|
//services业务系统的
|
// List<CodeAndValueBean> masterDataCode = this.masterClient.queryClientMasterValues(masterDataCodeEn);
|
// List<CodeAndValueBean> masterDataName = this.masterClient.queryClientMasterValues(masterDataNameEn);
|
// System.err.println(JSONTool.toJson(masterDataCode));
|
// System.err.println(JSONTool.toJson(masterDataName));
|
List<CodeAndValueBean> addList = new ArrayList<>();
|
// if (masterDataCode.size() == masterDataName.size()) {
|
// for (int i = 0; i < masterDataCode.size(); i++) {
|
// if (eleValue.equals(masterDataCode.get(i).getEle_value())) {
|
// CodeAndValueBean codeAndvaule = new CodeAndValueBean();
|
// codeAndvaule.setCode(masterDataCode.get(i).getEle_value());
|
// codeAndvaule.setValue(masterDataName.get(i).getEle_value());
|
// addList.add(codeAndvaule);
|
// }
|
// }
|
// }
|
CodeAndValueBean result = this.masterClient.masterValueCodeToName(masterDataNameEn);
|
addList.add(result);
|
rsMap.put(m.getItemId(), addList);
|
return RestResultGenerator.genSuccessResult(rsMap);
|
}
|
|
@RequestMapping(value="${requset.masterdata06}" , method = RequestMethod.POST)
|
public RestResult<String> queryNameBycode(@RequestBody String jsonStr) throws Exception{
|
return RestResultGenerator.genSuccessResult(this.masterDataService.queryNameBycode(jsonStr));
|
}
|
}
|