JSD-7843 开源材料
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.1 KiB

/*
* Copyright (C), 2018-2021
* Project: starter
* FileName: CallBackController
* Author: Louis
* Date: 2021/3/29 22:36
*/
package com.fr.plugin.j7843.sso.request;
import com.fanruan.api.i18n.I18nKit;
import com.fanruan.api.log.LogKit;
import com.fr.decision.webservice.annotation.LoginStatusChecker;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.j7843.sso.bean.CstDataBean;
import com.fr.plugin.j7843.sso.bean.DataResponse;
import com.fr.plugin.j7843.sso.config.SsoConfig;
import com.fr.plugin.j7843.sso.dao.CstDataDao;
import com.fr.plugin.j7843.sso.dao.CstStatusDao;
import com.fr.plugin.j7843.sso.entity.CstDataEntity;
import com.fr.plugin.j7843.sso.entity.CstStatusEntity;
import com.fr.third.springframework.stereotype.Controller;
import com.fr.third.springframework.web.bind.annotation.RequestBody;
import com.fr.third.springframework.web.bind.annotation.RequestMapping;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.third.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import static com.fr.plugin.j7843.sso.entity.CstDataEntity.*;
/**
* <Function Description><br>
* <ServiceController>
*
* @author Louis
* @since 1.0.0
*/
@Controller
@RequestMapping("postCstData")
public class ServiceController {
private SsoConfig config;
public ServiceController() {
// this.config = SsoConfig.getInstance();
}
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
@LoginStatusChecker(required = false)
public DataResponse doAction(@RequestBody String paramBody, HttpServletRequest req, HttpServletResponse res) {
try {
setHeader(res);
JSONObject params = new JSONObject(paramBody);
return operation(params.getJSONArray("data"));
} catch (Exception e) {
LogKit.error(e.getMessage(), e);
}
return DataResponse.error("500", I18nKit.getLocText("Plugin-J7843-Sso_Error_500"));
}
/**
* 企业应用业务事件处理
*
* @param cstArray
* @return
*/
private DataResponse operation(JSONArray cstArray) throws Exception {
List<CstDataBean> result = new ArrayList<>();
List<CstStatusEntity> cstStatusList;
JSONObject cstObject;
CstDataBean cstDataBean;
for (int i = 0; i < cstArray.size(); i++) {
cstObject = cstArray.getJSONObject(i);
final CstDataEntity cstDataEntity = (new CstDataEntity()).id(cstObject.getString("id"))
.pcode(cstObject.getString(COLUMN_P_CODE))
.name(cstObject.getString(COLUMN_NAME))
.telphone(cstObject.getString(COLUMN_TELPHONE))
.time(cstObject.getString(COLUMN_TIME))
.projName(cstObject.getString(COLUMN_PROJ_NAME))
.cityCo(cstObject.getString(COLUMN_CITY_CO));
CstDataDao.save(cstDataEntity);
cstStatusList = CstStatusDao.getStatus(cstDataEntity.getPcode(), cstDataEntity.getTelphone());
for (CstStatusEntity cstStatusEntity : cstStatusList) {
if (cstStatusEntity != null) {
cstDataBean = new CstDataBean();
cstDataEntity.createBean(cstDataBean);
cstStatusEntity.createBean(cstDataBean);
result.add(cstDataBean);
}
}
}
return DataResponse.operation(result);
}
/**
* 解决跨域访问问题
*
* @param res
*/
private void setHeader(HttpServletResponse res) {
// 跨域设置header
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
res.setHeader("Access-Control-Max-Age", "3600");
res.setHeader("Access-Control-Allow-Headers", "x-requested-with");
}
}