package com.product.admin.controller;
|
|
import com.product.admin.config.CmnConst;
|
import com.product.admin.config.SystemCode;
|
import com.product.admin.service.PromptService;
|
import com.product.common.lang.StringUtils;
|
import com.product.core.cache.DataPoolRefreshCache;
|
import com.product.core.config.CoreConst;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.entity.RequestParameterEntity;
|
import com.product.core.exception.BaseException;
|
import com.product.core.permission.PermissionService;
|
import com.product.core.spring.context.SpringMVCContextHolder;
|
import com.product.module.sys.config.SystemErrorCode;
|
import com.product.module.sys.version.ApiVersion;
|
import com.product.util.BaseUtil;
|
import com.product.util.support.AbstractBaseController;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* @author shicf
|
*/
|
@RequestMapping("/api/prompt/business")
|
@RestController
|
|
public class PromptController extends AbstractBaseController {
|
|
|
/**
|
* 数据查询 ,spring 注入
|
*/
|
@Autowired
|
public PromptService promptService ;
|
|
|
/**
|
* 数据权限验证
|
*/
|
@Autowired
|
PermissionService permissionService;
|
|
|
|
@PostMapping("/get-prompt-filter-key/{version}")
|
@ApiVersion(1)
|
public String getPromptFilterKey(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
|
String promptName = fse.getString(CmnConst.PROMPT_NAME);
|
if (StringUtils.isEmpty(promptName)) {
|
throw new BaseException(SystemCode.SYSTEM_FORM_COUNT);
|
}
|
return BaseUtil.success(promptService.getPromptFilterKey(promptName));
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return this.error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return error(SystemCode.GET_PROMPT_FILTER_KEY, e);
|
}
|
}
|
|
/**
|
* 高级参照料数据查询-web端
|
*
|
* @param request
|
* @return
|
*/
|
@RequestMapping(value = "/findPrompt/{version}")
|
@ApiVersion(1)
|
public String find(HttpServletRequest request) {
|
try {
|
Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
|
RequestParameterEntity reqp = (RequestParameterEntity) bean;
|
Object client_type = reqp.getOther().get(CoreConst.SYSTEM_CLIENT_TYPE_);
|
FieldSetEntity fse = reqp.getFormData();
|
//数据操作的权限验证
|
if (!permissionService.validDataPermission(fse, CoreConst.DATA_PERMISSION_VALID_TYPE_USER)) {
|
SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
|
SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
|
return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
|
}
|
//手机端
|
fse.setValue("~client_type~", client_type);
|
Object dt = promptService.getPromptValue(fse);
|
Map<String, Object> prompt_list_header_desc = new HashMap<>();
|
//app 不查询字段描述
|
if (dt instanceof DataTableEntity && !"App".equals(client_type)) {
|
prompt_list_header_desc.put("prompt_list_header_desc", promptService.getPromptFieldDesc(((DataTableEntity) dt).getMeta()));
|
}
|
return BaseUtil.success(dt, prompt_list_header_desc);
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return this.error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return this.error(SystemErrorCode.SYSTEM_PROMPT_FIND_ERROR.getValue(), SystemErrorCode.SYSTEM_PROMPT_FIND_ERROR.getText() + e.getMessage());
|
}
|
}
|
|
/**
|
* 高级参照料数据查询-手机端
|
*
|
* @param request
|
* @return
|
*/
|
@RequestMapping(value = "/findPrompt-mobile/{version}")
|
@ApiVersion(1)
|
public String findMobile(HttpServletRequest request) {
|
try {
|
|
Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
|
RequestParameterEntity reqp = (RequestParameterEntity) bean;
|
FieldSetEntity fse = reqp.getFormData();
|
//数据操作的权限验证
|
if (!permissionService.validDataPermission(fse, CoreConst.DATA_PERMISSION_VALID_TYPE_USER)) {
|
SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
|
SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
|
return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
|
}
|
//手机端
|
fse.setValue(CoreConst.SYSTEM_LANGUAGE_CODE,
|
reqp.getOther().get(CoreConst.SYSTEM_LANGUAGE_CODE_));
|
return BaseUtil.success(promptService.getPromptValue(fse), null);
|
} catch (BaseException e) {
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return this.error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return this.error(SystemErrorCode.SYSTEM_PROMPT_FIND_ERROR.getValue(), SystemErrorCode.SYSTEM_PROMPT_FIND_ERROR.getText() + e.getMessage());
|
}
|
}
|
|
/**
|
* 高级参照料数据查询-web端
|
*
|
* @param request
|
* @return
|
*/
|
@RequestMapping(value = "/refreshPrompt/{version}")
|
@ApiVersion(1)
|
public String refresh(HttpServletRequest request) {
|
try {
|
//更新缓存数据-------------------------------------------
|
DataPoolRefreshCache.getInstance().put("product_sys_prompt");
|
return OK();
|
} catch (BaseException e) {
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return this.error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return this.error(SystemCode.SYSTEM_PROMPT_REFRESH_ERROR.getValue(), SystemCode.SYSTEM_PROMPT_REFRESH_ERROR.getText() + e.getMessage());
|
}
|
}
|
}
|