package cn.com.countrygarden.bi.main.controller.microSatisfy;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageRowBounds;

import cn.com.countrygarden.bi.main.controller.microSatisfy.vo.UpdateQualityVO;
import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.core.ResultCode;
import cn.com.countrygarden.bi.main.exception.ServiceException;
import cn.com.countrygarden.bi.main.model.AccessToken;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.microSatisfy.MicroSatisfyModel;
import cn.com.countrygarden.bi.main.model.microSatisfy.MicroSatisfyOrganDetailModel;
import cn.com.countrygarden.bi.main.model.microSatisfy.MicroSatisfyRankModel;
import cn.com.countrygarden.bi.main.service.AccessTokenService;
import cn.com.countrygarden.bi.main.service.microSatisfy.MicroSatisfyService;

/**
 * 小业主满意度
 * @author shitong
 *
 */
@RestController
@RequestMapping("/api/microSatisfyController")
public class MicroSatisfyController {
	@Autowired
	private AccessTokenService accessTokenService;
	@Autowired
	private MicroSatisfyService microSatisfyService;
	
	/**
	 * @描述 导入调研数据
	 * @作者 张世通
	 * @时间 2018年6月21日
	 * @版本 
	 * @param multipartFile
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/dataImport", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result importSatisfyData(@RequestParam(value = "uploadfiles",required = false)MultipartFile multipartFile,HttpServletRequest request,
	        @RequestParam(name="timeStr",required = true)String timeStr){

		String accessToken = request.getParameter("AccessToken");
	    
		AccessToken token = accessTokenService.findByToken(accessToken);
		if(null  == multipartFile){
			throw new ServiceException("请选择需要上传的文件");
		}
		CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile) multipartFile;
		if (commonsMultipartFile.isEmpty()) {
			return Response.responseFail("上传文件为空文件");
		}
		String fileName = commonsMultipartFile.getOriginalFilename();

		if (fileName.indexOf(".xlsx") <= 0 && fileName.indexOf(".xls") <= 0) {
			return Response.responseFail("上传文件应为excel文件格式为：xlsx 或 xls");
		}
		//Map<String, Object> addSatisfyList = microSatisfyService.addSatisfyList(commonsMultipartFile,fileName,"007809",timeStr);
		Map<String, Object> addSatisfyList = microSatisfyService.addSatisfyList(commonsMultipartFile,fileName,token.getUserCode(),timeStr);
		
		 boolean msg =microSatisfyService.getMsg(addSatisfyList);
		 
		  if(!msg){
		      String jsonString = JSONObject.toJSONString(addSatisfyList);
		      return Response.responseFail(jsonString);
	        }else{ 
	            addSatisfyList.put("data", "导入成功");
	            String jsonString = JSONObject.toJSONString(addSatisfyList);
	         return Response.response(jsonString);
	        }
	}
	/**
	 * @描述 转换原始调研数据
	 * @作者 张世通
	 * @时间 2018年6月21日
	 * @版本 
	 * @param multipartFile
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/dataTransport", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result importSatisfyDataOrgin(@RequestParam(value = "uploadfiles",required = false)MultipartFile multipartFile,
	        @RequestParam(name="identifying",required = true)String identifying,HttpServletRequest request,HttpServletResponse response){
		//@RequestParam(name="identifierId",required = true)String identifierId,
	    
	    String userCode = getUserCode(request);
		if(null  == multipartFile){
			throw new ServiceException("请选择需要上传的文件");
		}
		CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile) multipartFile;
		if (commonsMultipartFile.isEmpty()) {
			return Response.responseFail("上传文件为空文件");
		}
		String fileName = commonsMultipartFile.getOriginalFilename();
		if (fileName.indexOf(".xlsx") <= 0 && fileName.indexOf(".xls") <= 0) {
			return Response.responseFail("上传文件应为excel文件格式为：xlsx 或 xls");
		}
		//String returnPath = microSatisfyService.addSatisfyListOrgin(null,null,token.getUserCode());
		Map<String,Object> returnPath = microSatisfyService.addSatisfyListOrgin(commonsMultipartFile,fileName,userCode,identifying,response);
		
		 boolean msg =microSatisfyService.getMsg(returnPath);
		
		  if(!msg){
              String jsonString = JSONObject.toJSONString(returnPath);
              return Response.responseFail(jsonString);
            }else{ 
                returnPath.put("data", "转换成功");
                String jsonString = JSONObject.toJSONString(returnPath);
             return Response.response(jsonString);
            }
	}
	
	
	   /**
	    * 下载CRM转换后的数据    
     */
    @RequestMapping(value = "/exportCrmData", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Result exportCrmData(HttpServletRequest request,HttpServletResponse response){
        //@RequestParam(name="identifierId",required = true)String identifierId,
        String userCode = getUserCode(request);
        
       Boolean flag = microSatisfyService.exportCrmData(userCode,response,request);

          if(!flag){
              return Response.responseFail("flase");
            }else{ 
             return Response.response(flag);
            }
    }
    
    
    
    @RequestMapping(value = "/exportTemplate", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result exportTemplate(@RequestParam(name="flag",required = true)String flag,HttpServletResponse response,HttpServletRequest request){
        String fileName="";
       if(flag.equals("1")){
           fileName="小业主源始CRM数据模板.xlsx";
       }else if(flag.equals("2")){
           fileName="小业主问题模板.xlsx";
       }else if(flag.equals("3")){
           fileName="小业主区域目标模板.xlsx";
       }
           
       Workbook workbook = microSatisfyService.getTemplate(fileName);
       boolean b = microSatisfyService.downLoad(response, workbook, fileName,request);
       
       if(!b){
           return Response.responseFail("flase");
         }else{ 
          return Response.response(b);
         }

    }
    
    @RequestMapping(value = "/ImportAnswerCode", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result ImportAnswerCode(@RequestParam(value = "uploadfiles",required = false)MultipartFile multipartFile,HttpServletRequest request){

       String accessToken = request.getParameter("AccessToken");
        
        AccessToken token = accessTokenService.findByToken(accessToken);
        if(null  == multipartFile){
            throw new ServiceException("请选择需要上传的文件");
        }
        CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile) multipartFile;
        if (commonsMultipartFile.isEmpty()) {
            return Response.responseFail("上传文件为空文件");
        }
        String fileName = commonsMultipartFile.getOriginalFilename();

        if (fileName.indexOf(".xlsx") <= 0 && fileName.indexOf(".xls") <= 0) {
            return Response.responseFail("上传文件应为excel文件格式为：xlsx 或 xls");
        }
        //Boolean code = microSatisfyService.ImportAnswerCode(commonsMultipartFile,fileName,"000054");
         Boolean code = microSatisfyService.ImportAnswerCode(commonsMultipartFile,fileName,token.getUserCode());
        
          if(!code){
              return Response.responseFail("false");
            }else{ 
             return Response.response(code);
            }
    }
    
    
    @RequestMapping(value = "/ImportRegionalObjectives", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result ImportRegionalObjectives(@RequestParam(value = "uploadfiles",required = false)MultipartFile multipartFile,HttpServletRequest request){

        CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile) multipartFile;
        if (commonsMultipartFile.isEmpty()) {
            return Response.responseFail("上传文件为空文件");
        }
        String fileName = commonsMultipartFile.getOriginalFilename();

        if (fileName.indexOf(".xlsx") <= 0 && fileName.indexOf(".xls") <= 0) {
            return Response.responseFail("上传文件应为excel文件格式为：xlsx 或 xls");
        }
        //Boolean code = microSatisfyService.ImportRegionalObjectives(commonsMultipartFile,fileName,"000054");
         Map<String,Object> map = microSatisfyService.ImportRegionalObjectives(commonsMultipartFile,fileName,"000054");
        
       return Response.response(map);

    }
    
    
    
    @RequestMapping(value = "/ImportCommObjectives", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result ImportCommObjectives(@RequestParam(value = "uploadfiles",required = false)MultipartFile multipartFile,HttpServletRequest request){

        CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile) multipartFile;
        if (commonsMultipartFile.isEmpty()) {
            return Response.responseFail("上传文件为空文件");
        }
        String fileName = commonsMultipartFile.getOriginalFilename();

        if (fileName.indexOf(".xlsx") <= 0 && fileName.indexOf(".xls") <= 0) {
            return Response.responseFail("上传文件应为excel文件格式为：xlsx 或 xls");
        }

         Map<String,Object> map = microSatisfyService.ImportCommObjectives(commonsMultipartFile,fileName,"000054");
        
       return Response.response(map);

    }
    
    
    
	
	/**
	 * @描述 按批次查询导入数据
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param pid
	 * @param year
	 * @param month
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryImportdata", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryImportData(@RequestParam(name="pid",required = false) String pid
			,@RequestParam(name="timeStr",required = false)String timeStr
			,@RequestParam(name = "pageSize",required = false, defaultValue="10") int pageSize
            ,@RequestParam(name = "pageIndex",required = false, defaultValue="1") int pageIndex
			,HttpServletRequest request){
		PageRowBounds pageRowBounds = new PageRowBounds(pageIndex,pageSize);
		pageRowBounds.setCount(true);
		List<Map<String, Object>> list = microSatisfyService.queryImportData(pid,timeStr,pageRowBounds);
	     PageData pageData;
         if(list!=null&&list.size()>0){
             pageData = new PageData(list,pageRowBounds);
         }else{
             pageData = new PageData();
         }

         return Response.response(pageData);
	}
	/**
	 * @描述 查询pid--批次号
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryPid", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryPid(HttpServletRequest request){
		List<Map<String,String>> list = microSatisfyService.queryPid();
		return Response.response(list);
	}
	/**
	 * @描述 查询当月管家满意度
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param size
	 * @param page
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryManagerSatisfy", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryManagerSatisfy(@RequestParam(name = "pageSize",required = false, defaultValue="10") int pageSize
            ,@RequestParam(name = "pageIndex",required = false, defaultValue="1")int pageIndex
            ,@RequestParam(name = "timeStr",required = true) String timeStr,HttpServletRequest request){
		PageRowBounds pageRowBounds = new PageRowBounds(pageIndex,pageSize);
		pageRowBounds.setCount(true);
		
		
		String userCode = getUserCode(request);

        String t = microSatisfyService.getUser(userCode);
        
        List<Map<String,String>> list =new ArrayList<>();
        if(!t.equals("")&&!t.equals("all")){
            list = microSatisfyService.queryManagerSatisfy(pageRowBounds,timeStr,t);
        }else if(t.equals("all")){
        
             list = microSatisfyService.queryManagerSatisfy(pageRowBounds,timeStr,null);
        
        }
		
        PageData pageData;
        if(list!=null&&list.size()>0){
            pageData = new PageData(list,pageRowBounds);
        }else{
            pageData = new PageData();
        }

        return Response.response(pageData);
	}
	/**
	 * @描述 查询当月管家满意度排名
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param size
	 * @param page
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryManagerSatisfyRank", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryManagerSatisfyRank(@RequestParam(name = "pageSize",required = false, defaultValue="10") int pageSize
            ,@RequestParam(name = "pageIndex",required = false, defaultValue="1")int pageIndex
            ,@RequestParam(name = "timeStr",required = false, defaultValue="") String timeStr
            ,@RequestParam(name = "organId",required = false, defaultValue="") String organId
            ,@RequestParam(name = "commId",required = false, defaultValue="") String commId
            ,HttpServletRequest request){
		PageRowBounds pageRowBounds = new PageRowBounds(pageIndex,pageSize);
		pageRowBounds.setCount(true);
		List<Map<String,String>> list = microSatisfyService.queryManagerSatisfyRank(pageRowBounds, timeStr, organId, commId);
	     PageData pageData;
         if(list!=null&&list.size()>0){
             pageData = new PageData(list,pageRowBounds);
         }else{
             pageData = new PageData();
         }

         return Response.response(pageData);
	}
	/**
	 * @描述 查询管家满意度折线图
	 * @作者 张世通
	 * @时间 2018年6月28日
	 * @版本 
	 * @param timeStr
	 * @param organId
	 * @param commId
	 * @param managerName
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryManagerScore", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryManagerScore(@RequestParam(name = "timeStr",required = false, defaultValue="") String timeStr
            ,@RequestParam(name = "organId",required = true) String organId
            ,@RequestParam(name = "commId",required = true) String commId
            ,HttpServletRequest request){
		Map<String,String> map= microSatisfyService.queryManagerScore(timeStr, organId, commId);
		return Response.response(map);
	}
	
	/**
	 * @描述 查询区域排名
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param size
	 * @param page
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryOrganRank", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryOrganRank(@RequestParam(name = "pageSize",required = false, defaultValue="10") int pageSize
            ,@RequestParam(name = "pageIndex",required = false, defaultValue="1") int pageIndex
            ,@RequestParam(name = "beginDate",required = true, defaultValue="") String beginDate
            ,@RequestParam(name = "endDate",required = true, defaultValue="") String endDate,
            @RequestParam(name = "cruentDate",required = false) String cruentDate,
            @RequestParam(name = "flag",required = true, defaultValue="") String flag,
            @RequestParam(name = "regionId",required = false) String regionId,
            HttpServletRequest request){
		PageRowBounds pageRowBounds = new PageRowBounds(pageIndex,pageSize);
		pageRowBounds.setCount(true);
		
	String userCode = getUserCode(request);
		
   String t = microSatisfyService.getUser(userCode);

	//String t="all";
    List<MicroSatisfyRankModel> queryOrganRank =new ArrayList<>();   
     
        if(!t.equals("")&&!t.equals("all")){
            queryOrganRank = microSatisfyService.queryOrganRank(pageRowBounds, beginDate,endDate,flag,cruentDate,t,regionId);
        }else if(t.equals("all")){
        
            queryOrganRank = microSatisfyService.queryOrganRank(pageRowBounds, beginDate,endDate,flag,cruentDate,null,regionId);
        
        }
		
        
        PageData pageData;
        if(queryOrganRank!=null&&queryOrganRank.size()>0){
            pageData = new PageData(queryOrganRank,pageRowBounds);
        }else{
            pageData = new PageData();
        }

		return Response.response(pageData);
	}
	/**
	 * @描述 查询区域排名
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param size
	 * @param page
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryCommRank", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryCommRank(@RequestParam(name = "pageSize",required = false, defaultValue="10") int pageSize
            ,@RequestParam(name = "pageIndex",required = false, defaultValue="1") int pageIndex
            ,@RequestParam(name = "beginDate",required = true, defaultValue="") String beginDate
            ,@RequestParam(name = "endDate",required = true, defaultValue="") String endDate,
            @RequestParam(name = "cruentDate",required = false) String cruentDate,
            @RequestParam(name = "flag",required = true, defaultValue="") String flag,
            @RequestParam(name = "regionId",required = true, defaultValue="") String regionId,
            @RequestParam(name = "projectId",required = true, defaultValue="") String projectId,
            HttpServletRequest request){
		PageRowBounds pageRowBounds = new PageRowBounds(pageIndex,pageSize);
		pageRowBounds.setCount(true);
		
		
		String userCode = getUserCode(request);
		String t = microSatisfyService.getUser(userCode);
	        
		  //String t="all";
		  
		  List<MicroSatisfyRankModel> queryCommRank =new ArrayList<>();  
		  
	        if(!t.equals("")&&!t.equals("all")){
	             queryCommRank = microSatisfyService.queryCommRank(pageRowBounds,beginDate,endDate,flag,cruentDate,t,regionId,projectId);
	        }else if(t.equals("all")){
	        
	            queryCommRank = microSatisfyService.queryCommRank(pageRowBounds,beginDate,endDate,flag,cruentDate,null,regionId,projectId);
	        
	        }
		
	        PageData pageData;
	        if(queryCommRank!=null&&queryCommRank.size()>0){
	            pageData = new PageData(queryCommRank,pageRowBounds);
	        }else{
	            pageData = new PageData();
	        }

	        return Response.response(pageData);
	}
	/**
	 * @描述 根据organId查询区域项目详情
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param size
	 * @param page
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/querySatisfyDetailByOrganId", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryOrganSatisfyDetailByOrganId(@RequestParam(name = "pageSize",required = false, defaultValue="10") int pageSize
            ,@RequestParam(name = "pageIndex",required = false, defaultValue="1") int pageIndex
            ,@RequestParam(name = "organId",required = true, defaultValue="") String organId
            ,@RequestParam(name = "beginDate",required = true, defaultValue="") String beginDate
            ,@RequestParam(name = "endDate",required = true, defaultValue="") String endDate
           ,HttpServletRequest request){
		PageRowBounds pageRowBounds = new PageRowBounds(pageIndex,pageSize);
		pageRowBounds.setCount(true);
		List<MicroSatisfyOrganDetailModel> list = microSatisfyService.queryOrganSatisfyDetailByOrganId(pageRowBounds, organId,beginDate,endDate);
		
		   PageData pageData;
           if(list!=null&&list.size()>0){
               pageData = new PageData(list,pageRowBounds);
           }else{
               pageData = new PageData();
           }

           return Response.response(pageData);
	
	}
	/**
	 * @描述 根据organId,commID查询项目详情
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/queryCommDetail", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryCommDetail(@RequestParam(name = "organId",required = true, defaultValue="") String organId
			,@RequestParam(name = "commId",required = true, defaultValue="") String commId
            ,@RequestParam(name = "timeStr",required = true, defaultValue="") String timeStr
            ,@RequestParam(name = "pid",required = false, defaultValue="") String pid,HttpServletRequest request){
		MicroSatisfyOrganDetailModel commDetail = microSatisfyService.queryCommDetail(organId, commId, timeStr, pid);
		return Response.response(commDetail);
	}
	
	/**
	 * @描述 豁免并锁定
	 * @作者 张世通
	 * @时间 2018年6月22日
	 * @版本 
	 * @param size
	 * @param page
	 * @param request
	 * @return
	 * @throws IOException 
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/updateOragnCommDetail", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result updateOragnCommDetail(@RequestParam(name = "dataList",required = false, defaultValue="") String dataList,HttpServletRequest request,
	        @RequestParam(name = "falg",required = true) String falg) throws IOException{
		List<Map<String,Object>> list= (List<Map<String, Object>>) JSON.parse(dataList);
		if(null ==list || list.size() == 0){
			return Response.response("未选择数据");
		}else{
			String accessToken = request.getParameter("AccessToken");
			AccessToken token = accessTokenService.findByToken(accessToken);
			microSatisfyService.updateOragnCommDetail(list,token.getUserCode(),falg);
			return Response.response("成功");
		}
		
	}
	/**
	 * @描述 查询当月批次统计信息
	 * @作者 张世通
	 * @时间 2018年6月28日
	 * @版本 
	 * @return
	 */
	@RequestMapping(value = "/queryDataCount", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryDataCount(@RequestParam(name = "beginDate",required = true) String beginDate
            ,@RequestParam(name = "endDate",required = true) String endDate,
            @RequestParam(name = "flag",required = false, defaultValue="") String flag,HttpServletRequest request
	        ){
	    
	    String userCode = getUserCode(request);
	    
	    String t = microSatisfyService.getUser(userCode);
	   //String t ="all";
	    Map<String,Object> map=new HashMap<>();
        if(!t.equals("")&&!t.equals("all")){
            map = microSatisfyService.queryDataCount(beginDate,endDate,flag,t);
        }else if(t.equals("all")){
        
            map = microSatisfyService.queryDataCount(beginDate,endDate,flag,null);
        
        }
		
		return Response.response(map);
	}
    private String getUserCode(HttpServletRequest request) {
        String accessToken = request.getParameter("AccessToken");
	    
	    AccessToken token = accessTokenService.findByToken(accessToken);
	       String userCode = token.getUserCode();
        return userCode;
    }
	/**
	 * @描述 查询区域当月批次统计信息
	 * @作者 张世通
	 * @时间 2018年6月28日
	 * @版本 
	 * @return
	 */
	@RequestMapping(value = "/queryOrganCount", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryOrganCount(@RequestParam(name = "timeStr",required = false, defaultValue="") String timeStr,
			@RequestParam(name = "organId",required = true, defaultValue="") String organId,
			@RequestParam(name = "pid",required = false, defaultValue="") String pid,HttpServletRequest request){
		Map<String,Object> map = microSatisfyService.queryOrganCount(timeStr,organId,pid);
		return Response.response(map);
	}
	/**
	 * @描述 查询项目当月批次统计信息
	 * @作者 张世通
	 * @时间 2018年6月28日
	 * @版本 
	 * @return
	 */
	@RequestMapping(value = "/queryCommCount", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryCommCount(@RequestParam(name = "pageSize",required = false, defaultValue="10") int pageSize
            ,@RequestParam(name = "pageIndex",required = false, defaultValue="1") int pageIndex
	       , @RequestParam(name = "beginDate",required = true, defaultValue="") String beginDate
            ,@RequestParam(name = "endDate",required = true, defaultValue="") String endDate,
			@RequestParam(name = "organId",required = true, defaultValue="") String organId,
			@RequestParam(name = "commId",required = true, defaultValue="") String commId,
           HttpServletRequest request){

        Map<String,Object> map = microSatisfyService.queryCommCount(beginDate, endDate,organId, commId);

		return Response.response(map);
	}
	/**
	 * @描述 查询全国走势图
	 * @作者 张世通
	 * @时间 2018年6月28日
	 * @版本 
	 * @return
	 */
	@RequestMapping(value = "/queryCountryScore", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryCountryScore(@RequestParam(name = "beginDate",required = true, defaultValue="") String beginDate
            ,@RequestParam(name = "endDate",required = true, defaultValue="") String endDate,
            @RequestParam(name = "flag",required = true, defaultValue="") String flag,
            HttpServletRequest request){
	   String userCode = getUserCode(request);
	    
	   String t = microSatisfyService.getUser(userCode);
	 //String  t="all";
	    Map<String,Object> map = new HashMap<>();
	    if(!t.equals("")&&!t.equals("all")){
	         map = microSatisfyService.queryCountryScore(beginDate,endDate,flag,t);
	    }else if(t.equals("all")){    
	        map = microSatisfyService.queryCountryScore(beginDate,endDate,flag,null);
	        }
		 
		return Response.response(map);
	}
	/**
	 * @描述 查询全国走势图
	 * @作者 张世通
	 * @时间 2018年6月28日
	 * @版本 
	 * @return
	 */
	@RequestMapping(value = "/queryOrganScore", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryOrganScore(@RequestParam(name = "timeStr",required = false, defaultValue="") String timeStr,
			@RequestParam(name = "organId",required = true, defaultValue="") String organId,
			@RequestParam(name = "pid",required = false, defaultValue="") String pid,HttpServletRequest request){
		Map<String,Object> map = microSatisfyService.queryOrganScore(timeStr, organId,pid);
		return Response.response(map);
	}
	/**
	 * @描述 查询项目走势图
	 * @作者 张世通
	 * @时间 2018年6月28日
	 * @版本 
	 * @return
	 */
	@RequestMapping(value = "/queryCommScore", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result queryCommScore(@RequestParam(name = "beginDate",required = true, defaultValue="") String beginDate
            ,@RequestParam(name = "endDate",required = true, defaultValue="") String endDate,
			@RequestParam(name = "organId",required = true, defaultValue="") String organId,
			@RequestParam(name = "commId",required = true, defaultValue="") String commId,
			@RequestParam(name = "flag",required = false, defaultValue="") String flag,HttpServletRequest request){
		Map<String,Object> map = microSatisfyService.queryCommScore(beginDate, endDate,organId, commId,flag);
		return Response.response(map);
	}
	/**
	 * 修改项目类型
	 * @param vo
	 * @return
	 */
    @ResponseBody
	@RequestMapping(value = "/updateQuality", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result updateQuality(
			@RequestParam(name = "organId",required = true) String organId,
			@RequestParam(name = "commId",required = true) Integer commId,
			@RequestParam(name = "cruentDate",required = true, defaultValue="") String cruentDate,
			@RequestParam(name = "quality",required = true) Integer quality) {
    	UpdateQualityVO vo = new UpdateQualityVO();
    	vo.organId = organId;
    	vo.commId = commId;
    
    	vo.cruentDate = cruentDate;
    	vo.quality = quality;
		microSatisfyService.updateQuality(vo);
		return Response.response(1);
	}
	
   /**
    * 得分统计
    * @param commId
    * @return
    */
    @ResponseBody
	@RequestMapping(value = "/scoreStatistics", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result scoreStatistics(
			@RequestParam(name = "commId",required = true, defaultValue="") String commId
			,@RequestParam(name = "organId",required = true, defaultValue="") String organId
			,@RequestParam(name = "beginDate",required = true, defaultValue="") String beginDate
            ,@RequestParam(name = "endDate",required = true, defaultValue="") String endDate
			) {
    	
		return Response.response(microSatisfyService.scoreStatistics(beginDate,endDate,organId,commId));
	}
	
    
    /**
	 * 业主心声
	 * @param commId
	 * @return
	 */
    @ResponseBody
   	@RequestMapping(value = "/selectVoice", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
	public Result selectVoice(@RequestParam(name = "commId",required = true) String commId
	           ,@RequestParam(name = "organId",required = true) String organId
	            ,@RequestParam(name = "beginDate",required = true) String beginDate
	            ,@RequestParam(name = "endDate",required = true) String endDate){
		
        //PageRowBounds pageRowBounds = new PageRowBounds(pageIndex,pageSize);
        //pageRowBounds.setCount(true);
        List<Map<String, Object>> list = microSatisfyService.selectVoice(beginDate,endDate,organId,commId);
        
   /*     PageData pageData;
        if(list!=null&&list.size()>0){
            pageData = new PageData(list,pageRowBounds);
        }else{
            pageData = new PageData();
        }*/

        return Response.response(list);
	}
    
    /**
     * @描述 获取问卷明细
     * @版本 
     * @return
     */
    @RequestMapping(value = "/queryQuestionnaire", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result queryQuestionnaire(@RequestParam(name = "pageSize",required = false, defaultValue="10") int pageSize
            ,@RequestParam(name = "pageIndex",required = false, defaultValue="1") int pageIndex
            ,@RequestParam(name = "beginDate",required = true) String beginDate
            ,@RequestParam(name = "endDate",required = true) String endDate,
            @RequestParam(name = "commId",required =false) String commId,
            @RequestParam(name = "organId",required = true) String organId,
            HttpServletRequest request){
        PageRowBounds pageRowBounds = new PageRowBounds(pageIndex,pageSize);
        pageRowBounds.setCount(true);
        
        List<MicroSatisfyOrganDetailModel> list = microSatisfyService.queryQuestionnaire(beginDate, endDate,organId,commId,pageRowBounds);

        PageData pageData;
        if(list!=null&&list.size()>0){
            pageData = new PageData(list,pageRowBounds);
        }else{
            pageData = new PageData();
        }

        return Response.response(pageData);
    }
    
    
    @ResponseBody
    @RequestMapping(value = "/querySatisfyQuestionnaireByType", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result querySatisfyQuestionnaireByType(HttpServletRequest request){
        String userCode = getUserCode(request);

        List<Map<String,String>> list = microSatisfyService.querySatisfyQuestionnaireByType(userCode);
        if(list==null){
            list=new ArrayList<>();
        }
        return Response.response(list);
    }
    
    

    @RequestMapping(value = "/comA1", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result comA1(){
//@RequestParam(name = "area",required = false) String area
      //  ,@RequestParam(name = "a",required = true) String a
        List<Map<String, Object>> comA1 = microSatisfyService.comA1();

        return Response.response(comA1);
    }
    
    @RequestMapping(value = "/getProjectName", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result getProjectName(@RequestParam(name = "area",required = false) String area
               ){

        List<Map<String, Object>> list = microSatisfyService.getProjectName(area);

        return Response.response(list);
    }
    
    @RequestMapping(value = "/querySatisfyDetailByCommId", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result querySatisfyDetailByCommId(
            @RequestParam(name = "organId",required = true) String organId
            ,@RequestParam(name = "commId",required = true) String commId
            ,@RequestParam(name = "beginDate",required = true) String beginDate
            ,@RequestParam(name = "endDate",required = true) String endDate
           ,HttpServletRequest request){

        MicroSatisfyOrganDetailModel mOrganDetailModel = microSatisfyService.querySatisfyDetailByCommId(organId,commId,beginDate,endDate);

           return Response.response(mOrganDetailModel);
    }
    
    @RequestMapping(value = "/queryRegionScore", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result queryRegionScore(@RequestParam(name = "beginDate",required = true) String beginDate
            ,@RequestParam(name = "endDate",required = true) String endDate,
            @RequestParam(name = "organId",required = true) String organId,
            @RequestParam(name = "flag",required = true) String flag,
            HttpServletRequest request){

        Map<String,Object> map = microSatisfyService.queryRegionScore(beginDate,endDate,organId,flag);
            
        return Response.response(map);
    }
    
    
    @RequestMapping(value = "/queryRegionCount", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
     public Result queryRegionCount(@RequestParam(name = "beginDate",required = true) String beginDate
             ,@RequestParam(name = "endDate",required = true) String endDate,
             @RequestParam(name = "organId",required = true) String organId,
             @RequestParam(name = "flag",required = false, defaultValue="") String flag,HttpServletRequest request
             ){

         Map<String,Object> map = microSatisfyService.queryRegionCount(beginDate,endDate,flag,organId);
         
         return Response.response(map);
     }

    @ResponseBody
    @RequestMapping(value = "/scoreStatisticsRegion", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result scoreStatisticsRegion(
            @RequestParam(name = "flag",required = true) String flag
            ,@RequestParam(name = "organId",required = true) String organId
            ,@RequestParam(name = "beginDate",required = true) String beginDate
            ,@RequestParam(name = "endDate",required = true) String endDate
            ) {
        
        return Response.response(microSatisfyService.scoreStatisticsRegion(beginDate,endDate,flag,organId));
    }


    @ResponseBody
    @RequestMapping(value = "/selectVoiceRegion", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Result selectVoiceRegion(@RequestParam(name = "flag",required = true) String flag
               ,@RequestParam(name = "organId",required = true) String organId
                ,@RequestParam(name = "beginDate",required = true) String beginDate
                ,@RequestParam(name = "endDate",required = true) String endDate){

        List<Map<String, Object>> list = microSatisfyService.selectVoiceRegion(beginDate,endDate,organId,flag);

        return Response.response(list);
    }

    
}
