198 lines
5.5 KiB
Plaintext
198 lines
5.5 KiB
Plaintext
package com.nationalelectric.greenH5;
|
||
|
||
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RequestMethod;
|
||
import org.springframework.web.bind.annotation.ResponseBody;
|
||
|
||
import com.nationalelectirc.Constant.Constant;
|
||
import com.nationalelectirc.utils.RestResult;
|
||
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
||
import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenUserInfoBizc;
|
||
import com.nationalelectric.greenH5.utils.DateUtil;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
|
||
import okhttp3.Call;
|
||
import okhttp3.FormBody;
|
||
import okhttp3.OkHttpClient;
|
||
import okhttp3.Request;
|
||
import okhttp3.Response;
|
||
|
||
|
||
/**
|
||
* <b>概述</b>:<br>
|
||
* <p>
|
||
* <b>功能</b>:<br>
|
||
*
|
||
* @author chenweikang
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/greenSysSetting")
|
||
public class GreenSysSettingController extends GreenBaseController {
|
||
|
||
/**
|
||
* 用户controller
|
||
*/
|
||
@Resource
|
||
private GreenUserInfoController greenUserInfoController;
|
||
|
||
/**
|
||
* 用户service
|
||
*/
|
||
@Resource
|
||
private IGreenUserInfoBizc greenuserinfoBizc;
|
||
|
||
/**
|
||
* 字典表controller
|
||
*/
|
||
@Resource
|
||
private GreenDictionaryInfoController greenDictionaryInfoController;
|
||
@Resource
|
||
private IGreenOperateLogBizc greenOperateLogBizc;
|
||
/**
|
||
* HibernateDao逻辑构件
|
||
*/
|
||
@Autowired
|
||
IHibernateDao hibernateDao;
|
||
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
/**
|
||
* 获取访客统计
|
||
*
|
||
* @param stime
|
||
* @param etime
|
||
* @return
|
||
*/
|
||
@SuppressWarnings({ "unchecked", "unused" })
|
||
@RequestMapping(value = "/getSetting", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getSetting() {
|
||
|
||
try {
|
||
HashMap<String, Object> content = new HashMap<String, Object>();
|
||
|
||
String visitorSql = "SELECT name,is_open from green_permission where `code` in( 2001)";
|
||
List<HashMap<String, Object>> cameralist = hibernateDao.queryForListWithSql("SELECT * from green_dictionary_info where data_type = 'cameraSwitch'");
|
||
|
||
|
||
List<HashMap<String, Object>> approvalCenter = hibernateDao.queryForListWithSql("SELECT * from green_dictionary_info where data_type = 'approvalCenter'");
|
||
|
||
|
||
|
||
List<HashMap<String, Object>> visitlist = hibernateDao.queryForListWithSql(visitorSql);
|
||
HashMap<String, Object> camera = new HashMap<String, Object>();
|
||
|
||
|
||
|
||
camera.put("name", "摄像头报警");
|
||
camera.put("is_open", cameralist.get(0).get("data_value"));
|
||
visitlist.add(camera);
|
||
|
||
HashMap<String, Object> approvalCenterMap = new HashMap<String, Object>();
|
||
|
||
approvalCenterMap.put("name", "approvalCenter");
|
||
approvalCenterMap.put("is_open", approvalCenter.get(0).get("data_value"));
|
||
visitlist.add(approvalCenterMap);
|
||
return new RestResult(Constant.SUCCESS, "请求成功", visitlist);
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 获取访客统计
|
||
*
|
||
* @param stime
|
||
* @param etime
|
||
* @return
|
||
*/
|
||
@SuppressWarnings({ "unchecked", "unused" })
|
||
@RequestMapping(value = "/setSetting", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult setSetting(String type, String code) {
|
||
|
||
try {
|
||
HashMap<String, Object> content = new HashMap<String, Object>();
|
||
String now = DateUtil.dateToStr(new Date(), "yyyy-MM-dd");
|
||
if(type.equals("visit")){
|
||
hibernateDao.updateWithSql("update GREEN_permission set is_open = ? where code = 2001",new Object[] { code});
|
||
}else if(type.equals("cameraSet")){
|
||
hibernateDao.updateWithSql("update green_dictionary_info set data_value = ? where data_type = 'cameraSwitch'",new Object[] { code});
|
||
if(code.equals("0")){
|
||
sendSetBeep("1");
|
||
}else if(code.equals("1")){
|
||
sendSetBeep("0");
|
||
}
|
||
}else if(type.equals("approvalCenter")){
|
||
if(code.equals("0")){
|
||
code = "1";
|
||
}else if(code.equals("1")){
|
||
code = "2";
|
||
}
|
||
|
||
hibernateDao.updateWithSql("update green_dictionary_info set data_value = ? where data_type = 'approvalCenter'",new Object[] { code});
|
||
|
||
}
|
||
|
||
return new RestResult(Constant.SUCCESS, "请求成功", null);
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
*
|
||
* @param code 0关 1开
|
||
* @return
|
||
*/
|
||
public boolean sendSetBeep(String code){
|
||
try {
|
||
System.err.println("消息推送");
|
||
OkHttpClient okHttpClient = new OkHttpClient();
|
||
okhttp3.RequestBody body = new FormBody.Builder()
|
||
.add("code", code)
|
||
.build();
|
||
// String url = "http://192.168.43.9:19001/zhhq/control/userInfo/queryPersonInfoByPage";
|
||
String url = "http://36.33.24.132:29001/zhhq/control/userInfo/setBeep";
|
||
|
||
Request request = new Request.Builder()
|
||
.url(url)
|
||
.post(body)
|
||
.build();
|
||
Call call = okHttpClient.newCall(request);
|
||
Response response = call.execute();
|
||
|
||
/*String responseContetn = response.body().string();
|
||
JSONObject responsejsonObject = new JSONObject().fromObject(responseContetn);
|
||
int code = responsejsonObject.getInt("returnCode");
|
||
System.err.println(DateTime.dateToStr(new Date())+"-222--->"+responsejsonObject.toString());
|
||
if(code == 0 ){
|
||
return true;
|
||
}else{
|
||
return false;
|
||
}*/
|
||
return true;
|
||
} catch (Exception e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
return false;
|
||
}
|
||
|
||
|
||
}
|