var express = require('express');
var router = express.Router();
require('../util/string');
let request = require("request");
var resultStatus=require('../util/model').resultStatus;
let artemis = require('../application.json').artemis;
var command=require('../util/database');
router.get("/queryhls/:type/:indexcode", function (req, res, next) {
    let type=req.params.type;
    let indexcode=req.params.indexcode;
    request(artemis.server+'/queryhls/'+type+"/"+indexcode, function (error, response, body) {
        if (!error && response.statusCode == 200) {
            res.json({resultStatus:resultStatus.success,data:JSON.parse(body)});
        }else{
            res.json({resultStatus:resultStatus.error(error)});
        }
    });
});

//重点人员详情
router.get('/zdry/:type/:sfz',function(req,res,next){
    command.executesql("select a.*,b.name xm,b.xb,b.xjzd,b.lxdh,b.whcd,b.mz,b.csny from "+req.params.type+" a,population b  where a.zjhm(+)=b.zjhm and b.zjhm='"+req.params.sfz+"'",(x)=>{
       res.render("detail/"+req.params.type,x);
    }); 
 });
 
 //党员个人信息
 router.get('/dygrxx/:sfz',function(req,res,next){
    command.executesql("select a.zjhm ,a.rdrq,a.zz,(select groupname from partygroup where id=a.ssdz and rownum<=1) szdxz,a.szdzb,b.xb,b.name xm,b.mz,b.csny csrq,b.lxdh,b.whcd xl from partymember a, population b where  a.zjhm(+)=b.zjhm and  b.zjhm='"+req.params.sfz+"'",(x)=>{
       res.render("detail/dygrxx",x);
   });
 });

  //场所详细信息
router.get('/areadetail/:type/:id',function(req,res,next){
    command.executesql("select * from "+req.params.type+" where id='"+req.params.id+"'",(x)=>{
        res.json(x);
      }); 
 });

  // 党群连心驿站（加的）
router.get('/querydqlxyzhdnr/:id', function(req, res, next) {
    command.executesql("select * from local_dqyzxxqk t where t.id='"+req.params.id+"'",(resultx)=>{
        res.json(resultx);
    });
});
  // 党员志愿者服务站详情（加的）
  router.get('/querydyzyzfwz/', function(req, res, next) {
    command.executesql("select * from local_zyzhdqk t",(resultx)=>{
        res.json(resultx);
    });
});

//留守流动儿童个人信息
router.get('/local_ldlschildren/:sfz',function(req,res,next){
    let x=req.params.sfz;
    let sqlstr=`select d.*,    f.hzname, 
    f.hzmobile, 
    f.hzzjhm, 
    f.relation, 
    f.difficulttype, 
    f.difficultdesc, 
    f.remark, 
    f.type
   from  population d,local_zdry_ldlschildren f
   where d.zjhm=f.zjhm
   and d.zjhm = '{0}'`;
   command.executesql(sqlstr.format(x),(x)=>{
       res.render("detail/local_ldlschildren",x);
   });
 });


//人民防线
router.get('/local_rmfx/:sfz/:keyid',function(req,res,next){
    let x=req.params.sfz;
    let y=req.params.keyid;
    let sqlstr=`select d.*,f.*,{1} typeid
from  population d, LOCAL_RMFX f
where  d.zjhm = f.zjhm  and d.zjhm = '{0}' and  instr(concat(',',f.keyid),',{1}')>0
`;
   command.executesql(sqlstr.format(x,y),(x)=>{
       res.render("detail/local_rmfx",x);
   });
 });


module.exports = router;