package cn.autoform.web.service.masterdata; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestBody; import cn.autoform.bean.CodeAndValueBean; import cn.autoform.db.entity.MasterDefineEntity; import cn.autoform.db.entity.MasterElementEntity; import cn.autoform.db.entity.MasterValueEntity; import cn.autoform.factory.FormFactory; import cn.autoform.factory.product.ProductMethod.IOType; import cn.autoform.util.tool.JSONTool; import cn.autoform.util.tool.RequestContext; import cn.autoform.web.mapper.formset.FormSetMapper; import cn.autoform.web.mapper.masterdata.MasterDataMapper; import net.sf.json.JSONObject; @Service public class MasterDataService { @Autowired MasterDataMapper masterDataMapper = null; @Autowired FormSetMapper FormSetMapper; @Autowired private FormFactory formFactory; public List queryMasterDefines(String tenantID, String name) { return masterDataMapper.queryMasterDefines(tenantID, name); } public List queryMasterElements(String tenantID, String code) { return masterDataMapper.queryMasterElements(tenantID, code); } public List queryMasterValues(String tenantID, String defineCode, String eleCode) { return masterDataMapper.queryMasterValues(tenantID, defineCode, eleCode); } @SuppressWarnings("unchecked") public String queryNameBycode(String jsonStr) throws Exception{ JSONObject jsonObj =JSONObject.fromObject(jsonStr); String tenantID = jsonObj.getString("tenantID"); String formID = jsonObj.getString("formID"); String code = jsonObj.getString("code"); String where = jsonObj.getString("where"); String callbackId = "item_1"; StringBuilder result = new StringBuilder(); String flag = FormSetMapper.getFlagByFormID(formID, RequestContext.getTenantId()); IOType go = "services".equals(flag) ? IOType.services : IOType.cloud; Map> value = (Map>) this.formFactory.createFormMethod(go).getMasterBaseElementListServiceForNew(tenantID, code, callbackId,null,null,null); value.get("item_1").stream().filter(cAndV -> cAndV.getCode().equals(where)) .forEach(cAndV ->result.append(cAndV.getValue())); return result.toString(); } }