com.addplus.server.action.controller.CommonAction Maven / Gradle / Ivy
The newest version!
package com.addplus.server.action.controller;
import com.addplus.server.action.config.constant.ConfigConsts;
import com.addplus.server.action.config.system.AddplusContainer;
import com.addplus.server.core.constant.ConfigConstsBase;
import com.addplus.server.core.model.base.ReturnDataSet;
import com.addplus.server.core.utils.DataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 类名: CommonAction
*
* @author zhangjiehang
* @version V1.0
* @date 2019-04-16 19:16
* @description 类描述:公共请求控制层
*/
@RestController
public class CommonAction {
@Autowired
private AddplusContainer addplusContainer;
@Value("${action.param.encrypted:false}")
private Boolean encrypted;
@GetMapping(value = "/get/{model}/{module}/{service}/{method}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object get(@PathVariable String model, @PathVariable String module, @PathVariable String service, @PathVariable String method, @RequestParam Map map, @RequestHeader Map headerMap) throws Exception {
ReturnDataSet returnDataSet = addplusContainer.invoke(model, model + "." + module + "." + service, method, DataUtils.getIpAddress(headerMap), map, true, headerMap.getOrDefault(ConfigConstsBase.TOKEN, null));
if (encrypted && ConfigConsts.REST.equals(model)) {
return addplusContainer.encryptAESContent(returnDataSet, model + "." + module + "." + service, method);
}
return returnDataSet;
}
@PostMapping(value = "/post/{model}/{module}/{service}/{method}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object post(@PathVariable String model, @PathVariable String module, @PathVariable String service, @PathVariable String method, @RequestBody(required = false) String contentStr, @RequestHeader Map headerMap) throws Exception {
ReturnDataSet returnDataSet = addplusContainer.invoke(model, model + "." + module + "." + service, method, DataUtils.getIpAddress(headerMap), contentStr, false, headerMap.getOrDefault(ConfigConstsBase.TOKEN, null));
if (encrypted && ConfigConsts.REST.equals(model)) {
return addplusContainer.encryptAESContent(returnDataSet, model + "." + module + "." + service, method);
}
return returnDataSet;
}
}