dao

 <select id="selectShopInfo"  resultType="java.util.HashMap">
 SELECT  *   FROM shop_info  si  
<if test="datadate != null and datadate != '' ">  
         WHERE 
        DATE_FORMAT(#{datadate},'%Y-%m-%d')=DATE_FORMAT(ctime,'%Y-%m-%d')
   </if>
      </select> 
  
  
  
    <select id="selectCustomerInfo" resultType="java.util.HashMap">
     SELECT  *   FROM customer_info   ci 
    <if test="datadate != null and datadate != '' ">  
         WHERE 
        DATE_FORMAT(#{datadate},'%Y-%m-%d')=DATE_FORMAT(ctime,'%Y-%m-%d')
   </if>
  </select> 

 

dao

//获取门店信息
    public   List<HashMap<String, Object>> selectShopInfo(@Param("datadate")String datadate) throws Exception;
    
    //获取客户信息 
    public List<HashMap<String,Object>> selectCustomerInfo(@Param("datadate")String datadate) throws Exception;
     

 

service.impl

@Override
    public JSONObject selectInfo(String datadate) throws Exception {
        JSONObject object=new JSONObject();
         List<HashMap<String, Object>> shopInfo =interfaceDao.selectShopInfo(datadate);
         List<HashMap<String, Object>> customerInfo =interfaceDao.selectCustomerInfo(datadate);
            JSONArray shopArray=new JSONArray();
         for (int i = 0; i < shopInfo.size(); i++) {
             HashMap<String, Object> map=shopInfo.get(i);
             JSONObject shopObj=new JSONObject();
             Set set = map.keySet();
             Iterator iter = set.iterator();
             while (iter.hasNext()) {
             String key = (String) iter.next();
             
             if(  map.get(key)==null ) {
                 shopObj.accumulate(key,"");
             }else {
                 shopObj.accumulate(key,map.get(key).toString().equals("")?"":map.get(key).toString());
             }
        
             }
             shopArray.add(shopObj);
        }
         
         
         JSONArray customerArray=new JSONArray();
         for (int i = 0; i < customerInfo.size(); i++) {
             HashMap<String, Object> map=customerInfo.get(i);
             JSONObject customerObj=new JSONObject();
             Set set = map.keySet();
             Iterator iter = set.iterator();
             while (iter.hasNext()) {
             String key = (String) iter.next();
             
             if( map.get(key)==null ) {
                 customerObj.accumulate(key,"");
             }else {
                 customerObj.accumulate(key, map.get(key).toString().equals("")?"":map.get(key).toString());
             }
            
             }
             customerArray.add(customerObj);
        }
            object.accumulate("shopInfo", shopArray);
            object.accumulate("customerInfo", customerArray);
 
        return object;
    }

 

action

    public  void  getBasicInfo () {
        response.setHeader("Content-type", "application/json;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        JSONObject object=new JSONObject();
        String datadate=request.getParameter("datadate");
        try {
            object =interfaceService.selectInfo(datadate);
            object.accumulate("status",200);
        } catch (Exception e) {
            object.accumulate("error", e.getMessage());
            object.accumulate("status",500);
            e.printStackTrace();
        }
        WebPageUtil.writeBack(object.toString());
    }

 

jsp

{"shopInfo":[],"customerInfo":[],"status":200}
posted on 2019-02-27 16:03  Yusco  阅读(277)  评论(0编辑  收藏  举报