package com.nationalelectric.greenH5;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.ObjectUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.hibernate.util.StringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
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.ResponseBody;
import com.gexin.fastjson.JSON;
import com.jysoft.card.controller.CardController;
import com.jysoft.card.service.GreenCard;
import com.jysoft.property.controller.PropertyController;
import com.jysoft.property.entity.GreenPropertyEntity;
import com.jysoft.questionnaire.controller.QuestionnaireController;
import com.jysoft.questionnaire.entity.GreenQuestionnaire;
import com.jysoft.visitor.controller.VisitorController;
import com.jysoft.weChat.controller.WechatController;
import com.jysoft.weChat.util.HttpUtil;
import com.jysoft.weChat.util.ParseUtil;
import com.jysoft.weChat.util.Wechatconfig;
import com.nationalelectirc.Constant.Constant;
import com.nationalelectirc.Constant.ConstantRegex;
import com.nationalelectirc.utils.RestResult;
import com.nationalelectirc.utils.Utils;
import com.nationalelectric.greenH5.DTO.GreenConstructDTO;
import com.nationalelectric.greenH5.DTO.GreenFoodOrderDetailDTO;
import com.nationalelectric.greenH5.DTO.GreenFoodOrderListDTO;
import com.nationalelectric.greenH5.DTO.GreenHaircutRemainDTO;
import com.nationalelectric.greenH5.DTO.GreenMealTicketApplyDTO;
import com.nationalelectric.greenH5.DTO.GreenMealTicketDTO;
import com.nationalelectric.greenH5.DTO.UserDTO;
import com.nationalelectric.greenH5.po.GreenActiveInfo;
import com.nationalelectric.greenH5.po.GreenActiveSign;
import com.nationalelectric.greenH5.po.GreenConstructPersonInfo;
import com.nationalelectric.greenH5.po.GreenDictionaryInfo;
import com.nationalelectric.greenH5.po.GreenDrugsApply;
import com.nationalelectric.greenH5.po.GreenDrugsDetail;
import com.nationalelectric.greenH5.po.GreenDrugsPush;
import com.nationalelectric.greenH5.po.GreenEAccount;
import com.nationalelectric.greenH5.po.GreenFaultRepairInfo;
import com.nationalelectric.greenH5.po.GreenFoodFeature;
import com.nationalelectric.greenH5.po.GreenFoodLottery;
import com.nationalelectric.greenH5.po.GreenFoodOrderDetail;
import com.nationalelectric.greenH5.po.GreenFoodVote;
import com.nationalelectric.greenH5.po.GreenGeneralInspecton;
import com.nationalelectric.greenH5.po.GreenGrantAuth;
import com.nationalelectric.greenH5.po.GreenHaircutComment;
import com.nationalelectric.greenH5.po.GreenHaircutInfo;
import com.nationalelectric.greenH5.po.GreenInfoGrather;
import com.nationalelectric.greenH5.po.GreenLicenseplateApproval;
import com.nationalelectric.greenH5.po.GreenMinorItem;
import com.nationalelectric.greenH5.po.GreenParkInfo;
import com.nationalelectric.greenH5.po.GreenPhysicalBase;
import com.nationalelectric.greenH5.po.GreenPhysicalItem;
import com.nationalelectric.greenH5.po.GreenProblemCollect;
import com.nationalelectric.greenH5.po.GreenRentHouseApply;
import com.nationalelectric.greenH5.po.GreenReport;
import com.nationalelectric.greenH5.po.GreenRetinueInfo;
import com.nationalelectric.greenH5.po.GreenSeekmedicalRecord;
import com.nationalelectric.greenH5.po.GreenSpanRegister;
import com.nationalelectric.greenH5.po.GreenStaffCardInfo;
import com.nationalelectric.greenH5.po.GreenTempParkInfo;
import com.nationalelectric.greenH5.po.GreenUsecarApply;
import com.nationalelectric.greenH5.po.GreenUserInfo;
import com.nationalelectric.greenH5.po.GreenVisitor;
import com.nationalelectric.greenH5.po.GreenVisitorInfo;
import com.nationalelectric.greenH5.po.GreenVisitorRetinueInfo;
import com.nationalelectric.greenH5.po.GreenWashCarInfo;
import com.nationalelectric.greenH5.po.Result;
import com.nationalelectric.greenH5.po.TorderEvaluate;
import com.nationalelectric.greenH5.po.UserVo;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* 概述:
*
*
* 功能:
* app主接口
*
* @author zhangkai
*
*/
@Controller
@RequestMapping("/mainInterface")
public class GreenMainInterfaceController {
private static final Pattern compile = Pattern.compile(ConstantRegex.REGEX_010);
@Resource
private GreenParkThirdController greenParkThirdController;
/**
* 访客预约controller
*/
@Resource
private GreenVisitorInfoController greenVisitorInfoController;
/**
* 员工卡controller
*/
@Resource
private GreenStaffCardInfoController greenStaffCardInfoController;
/**
* 临时停车controller
*/
@Resource
private GreenTempParkInfoController greenTempParkInfoController;
/**
* 故障报修controller
*/
@Resource
private GreenFaultRepairInfoController greenFaultRepairInfoController;
/**
* 理发预约controller
*/
@Resource
private GreenHaircutInfoController greenHaircutInfoController;
/**
* 餐卷controller
*/
@Resource
private GreenMealTicketController greenMealTicketController;
/**
* 餐卷applycontroller
*/
@Resource
private GreenMealTicketApplyController mealTicketApplyController;
/**
* 食堂订单
*/
@Resource
private GreenFoodOrderDetailController greenFoodOrderDetailController;
/**
* 用户订单
*/
@Resource
private GreenFoodOrderListController greenFoodOrderListController;
/**
* 菜品
*/
@Resource
private GreenFoodsMenuController greenFoodsMenuController;
/**
* 用户
*/
@Resource
private GreenUserInfoController greenUserInfoController;
/**
* 部门
*/
@Resource
private GreenDepartmentController greenDepartmentController;
/**
* 施工申请
*/
@Resource
private GreenConstructInfoController greenConstructInfoController;
/**
* 理发评论
*/
@Resource
private GreenHaircutCommentController greenHaircutCommentController;
/*
* 体检
*/
@Resource
private GreenPhysicalBaseController greenPhysicalBaseController;
/*
* 一般检查
*/
@Resource
private GreenGeneralInspectonController greenGeneralInspectonController;
/*
* 总检
*/
@Resource
private GreenPhysicalItemController greenPhysicalItemController;
/**
* 细项
*/
@Resource
private GreenMinorItemController greenMinorItemController;
/**
* 登录登出
*/
@Resource
private GreenLoginController greenLoginController;
/*
* 评价
*/
@Resource
private EvaluateController evaluateController;
/*
* 推荐菜
*/
@Resource
private FeatureController featureController;
@Resource
private GreenApplyController greenApplyController;
@Resource
private GreenSpanRegisterController greenSpanRegisterController;
@Resource
private WechatController wechatController;
@Resource
private HomeController HomeController;
@Resource
CameraManagerController cameraManagerController;
@Resource
private GreenGrantAuthController greenGrantAuthController;
/**
* 字典表
*/
@Resource
private GreenDictionaryInfoController greenDictionaryInfoController;
// 临时停车三级审批查看我的代办和我的审批
@Resource
private GreenParkThirdApproveController greenParkThirdApproveController;
@Resource
private GreenFoodLotterController lotteryController;
@Autowired
private GreenWashCarController greenWashCarController;
@Autowired
private GreenInfoGratherController greenInfoGratherController;
@Autowired
private GreenVisitorStatisticsController greenVisitorStatisticsController;
@Autowired
private GreenSysSettingController greenSysSettingController;
@Autowired
private EAccountController eaController;
@Autowired
private GreenLicenseplateApprovalController greenLicenseplateApprovalController;
@Autowired
private GreenParkInfoController greenParkInfoController;
@Autowired
private GreenParkRecordController greenParkRecordController;
@Autowired
private GreenMyHealthyController greenMyHealthyController;
@Autowired
private GreenEnterpriseController greenEnterpriseController;
@Autowired
private GreenDrugsApplyController greenDrugsApplyController;
@Autowired
private GreenUseCarApplyController greenUseCarApplyController;
@Autowired
private GreenCatagoryController greenCatagoryController;
@Autowired
private GreenExamController greenExamController;
@Autowired
private GreenCalendarController greenCalendarController;
@Autowired
private GreenSeekmedicalRecordController greenSeekmedicalRecordController;
@Autowired
private GreenStatisticsController greenStatisticsController;
@Autowired
private GreenHealthMsgController greenHealthMsgController;
@Autowired
private GreenDrugsPushController greenDrugsPushController;
@Autowired
private NewsInfoController newsInfoController;
@Autowired
private GreenReportController greenReportController;
@Autowired
private GreenActiveInfoController greenActiveInfoController;
@Autowired
private GreenMealCardController greenMealCardController;
@Autowired
private AppLoginController appLoginController;
@Autowired
private AppUpdateController appUpdateController;
@Autowired
private GreenProblemCollectController greenProblemCollectController;
@Autowired
private GreenNoticeController greenNoticeController;
@Autowired
private GreenMarketController greenMarketController;
@Autowired
private GreenMonitorController greenMonitorController;
@Autowired
private GreenWeekMenuController greenWeekMenuController;
@Autowired
private GreenServiceGuideController greenServiceGuideController;
@Autowired
private GreenBannerController greenBannerController;
@Autowired
private SingleLoginController singleLoginController;
@Autowired
private GreenHouseController greenHouseController;
@Autowired
private GreenEpidemicController greenEpidemicController;
@Autowired
private VisitorController visitorController;
@Autowired
private PropertyController propertyController;
@Autowired
private CardController cardController;
@Autowired
private GreenWeekMealController greenWeekMealController;
@Autowired
private QuestionnaireController questionnaireController;
// 审批相关模块接口(包括访客预约、临时停车申请、员工卡办理申请、故障报修申请、理发预约、餐券申请)
@SuppressWarnings("static-access")
@RequestMapping("/approvalModule")
public @ResponseBody RestResult approvalModule(HttpServletRequest request, HttpServletResponse response) {
String jsonStr = "";
try {
// 关闭数据防重放记录
// Utils.list.clear();
// 加密方式
byte buffer[];
// try {
buffer = getRequestPostBytes(request);
System.err.println("buffer");
jsonStr = new String(buffer, "UTF-8");
JSONObject jsonObject = JSONObject.fromObject(jsonStr.trim());
String method = jsonObject.getString("method");
String dataStr = jsonObject.getString("data");
JSONObject data = jsonObject.fromObject(dataStr);
System.err.println("jsonStr");
String checkTime = jsonObject.containsKey("checkTime") ? jsonObject.getString("checkTime")
: new Date().getTime() + "";
String clientId = jsonObject.containsKey("clientId") ? jsonObject.getString("clientId") : "";
// 加密方式
// byte buffer[] = getRequestPostBytes(request);
// String jsonStr = new String(buffer, "UTF-8"); //
// System.out.println("===== body data:" + jsonStr);
// JSONObject jsonObject = JSONObject.fromObject(jsonStr);
// String sign = jsonObject.getString("sign");
// String body = jsonObject.getString("body");
// String checkTimeDate = jsonObject.getString("checkTime"); //
// String src = jsonObject.getString("src"); //
// cSystem.out.println("===== sign:" + sign); //
// System.out.println("===== body:" + body); //
// System.out.println("===== src:" + src); String md5Sign =
// MD5Util.encrypt(body); if (!sign.equalsIgnoreCase(md5Sign)) { //
// System.out.println("====== md5 error "); return new
// RestResult(Constant.FAILED, "请求失败[数据异常-1]"); }
// String bodyData = AesEncryptUtil.desEncrypt(body);
// // System.out.println("===== 解密 body data:" + bodyData); if
// (bodyData == null) { // System.out.println("====== aes error ");
// return new RestResult(Constant.FAILED, "请求失败[数据异常-2]"); }
// String checkTime = AesEncryptUtil.desEncrypt(checkTimeDate);
// boolean find = compile.matcher(checkTime).find(); if (!find &&
// checkTime == null) { return new RestResult(Constant.FAILED,
// "请求失败[数据异常-2]"); }
// JSONObject bodyObject = JSONObject.fromObject(bodyData);
// String method = bodyObject.getString("method"); JSONObject data =
// bodyObject.getJSONObject("data");
// CheckParamUtil.checkJsonValue(data);
// String code = data.getString("code");
// if (code.length() > 0) {
// String url =
// "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" +
// Wechatconfig.appId + "&secret=" + Wechatconfig.appSecret +
// "&code=" + code + "&grant_type=authorization_code";
// String tokenString = HttpUtil.getHttpsResponse(url, "");
// System.out.println(tokenString);
// JSONObject tokenJson = new JSONObject().fromObject(tokenString);
//
// String openid = ParseUtil.parseText(tokenJson.get("openid"));
// String access_token =
// ParseUtil.parseText(tokenJson.get("access_token"));
//
// // 获取用户信息
//
// // http:GET(请使用https协议)
//
// String getUserUrl =
// "https://api.weixin.qq.com/sns/userinfo?access_token=" +
// access_token + "&openid=" + openid + "&lang=zh_CN";
// String userString = HttpUtil.getHttpsResponse(getUserUrl, "");
//
// String json = new String(userString.getBytes("ISO-8859-1"),
// "UTF-8");
//
// JSONObject resultObj = new JSONObject().fromObject(json);
// System.out.println(json);
// return new RestResult("1", "授权成功", resultObj);
// }else{
// return new RestResult("0", "授权失败");
// }
// 判断调用的接口
if ("greenVisitorInfo/saveVistorInfo".equals(method)) {// 访客预约保存
if (Utils.list.contains("greenVisitorInfo/saveVistorInfo" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
}
Map mapVisitClass = new HashMap();
mapVisitClass.put("greenRetinueInfoList", GreenRetinueInfo.class);
GreenVisitorRetinueInfo greenVisitorRetinueInfo = (GreenVisitorRetinueInfo) JSONObject.toBean(data,
GreenVisitorRetinueInfo.class, mapVisitClass);
return greenVisitorInfoController.saveVistorInfo(greenVisitorRetinueInfo, request);
} else if ("greenVisitorInfo/updateVisitorStatus".equals(method)) {// 访客预约的审批
if (Utils.list.contains("greenVisitorInfo/updateStatus" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/updateStatus" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.updateVisitorStatus(result);
} else if ("greenVisitorInfo/invite".equals(method)) {// 邀约的确认
if (Utils.list.contains("greenVisitorInfo/saveVistorInfo" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
}
Map mapVisitClass = new HashMap();
mapVisitClass.put("greenRetinueInfoList", GreenRetinueInfo.class);
GreenVisitorRetinueInfo greenVisitorRetinueInfo = (GreenVisitorRetinueInfo) JSONObject.toBean(data,
GreenVisitorRetinueInfo.class, mapVisitClass);
return greenVisitorInfoController.saveInviteInfo(greenVisitorRetinueInfo, request);
} else if ("greenVisitorInfo/getMyApplyList".equals(method)) {// 查询我的申请列表和我的待办列表
if (Utils.list.contains("greenVisitorInfo/getMyApplyList" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/getMyApplyList" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.getMyApplyList(result);
} else if ("greenVisitorInfo/getMyVisitorList".equals(method)) {// 查询我的预约申请列表和我的邀约列表
if (Utils.list.contains("greenVisitorInfo/getMyApplyList" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/getMyApplyList" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.getMyVisitorList(result);
} else if ("greenVisitorInfo/getCirculationList".equals(method)) {// 查询我的预约申请列表和我的邀约列表
if (Utils.list.contains("greenVisitorInfo/getCirculationList" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/getCirculationList" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.getCirculationList(result);
} else if ("greenVisitorInfo/submitCirculation".equals(method)) {// 查询我的预约申请列表和我的邀约列表
if (Utils.list.contains("greenVisitorInfo/submitCirculation" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/submitCirculation" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.submitCirculation(result);
} else if ("greenVisitorInfo/updateVisitorInfoBatch".equals(method)) {// 查询我的预约申请列表和我的邀约列表
if (Utils.list.contains("greenVisitorInfo/updateVisitorInfoBatch" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/updateVisitorInfoBatch" + checkTime);
}
JSONArray dataArr = data.getJSONArray("list");
try {
for (int i = 0; i < dataArr.size(); i++) {
JSONObject jb = dataArr.getJSONObject(i);
Result result = (Result) JSONObject.toBean(jb, Result.class);
greenVisitorInfoController.updateVisitorStatus(result);
}
return new RestResult(Constant.SUCCESS, "操作成功!");
} catch (Exception e) {
e.printStackTrace();
return new RestResult(Constant.FAILED, "处理失败");
}
// return
// greenVisitorInfoController.updateVisitorInfoBatch(result);
} else if ("greenVisitorInfo/submitCirculationBatch".equals(method)) {// 查询我的预约申请列表和我的邀约列表
if (Utils.list.contains("greenVisitorInfo/submitCirculationBatch" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/submitCirculationBatch" + checkTime);
}
JSONArray dataArr = data.getJSONArray("list");
try {
for (int i = 0; i < dataArr.size(); i++) {
JSONObject jb = dataArr.getJSONObject(i);
Result result = (Result) JSONObject.toBean(jb, Result.class);
greenVisitorInfoController.submitCirculation(result);
}
return new RestResult(Constant.SUCCESS, "操作成功!");
} catch (Exception e) {
e.printStackTrace();
return new RestResult(Constant.FAILED, "操作失败");
}
// return
// greenVisitorInfoController.updateVisitorInfoBatch(result);
} else if ("greenVisitorInfo/listReason".equals(method)) {// 查询访客预约理由列表
if (Utils.list.contains("greenVisitorInfo/listReason" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/listReason" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.listReason(result);
} else if ("greenVisitorInfo/countMyApplyList".equals(method)) {// 统计我的申请列表和我的待办列表
if (Utils.list.contains("greenVisitorInfo/countMyApplyList" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/countMyApplyList" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.countMyApplyList(result);
} else if ("greenVisitorInfo/getApplyInfo".equals(method)) {// 根据id和申请类型查询申请详情
if (Utils.list.contains("greenVisitorInfo/getApplyInfo" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/getApplyInfo" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.getApplyInfo(result, request);
} else if ("greenVisitorInfo/updateStatus".equals(method)) {// 申请的审批
if (Utils.list.contains("greenVisitorInfo/updateStatus" + checkTime)) {
return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求...");
} else {
Utils.list.add("greenVisitorInfo/updateStatus" + checkTime);
}
Result result = (Result) JSONObject.toBean(data, Result.class);
return greenVisitorInfoController.updateStatus(result);
} else if ("greenVisitorInfo/batchUpdateStatus".equals(method)) {// 批量审批
// @SuppressWarnings("unchecked")
// List