陈士柏 2 år sedan
förälder
incheckning
53c8d2ed24
1 ändrade filer med 223 tillägg och 0 borttagningar
  1. 223 0
      mhotel/src/com/happy/dao/impl/AppImplDao.java

+ 223 - 0
mhotel/src/com/happy/dao/impl/AppImplDao.java

@@ -0,0 +1,223 @@
+package com.happy.dao.impl;
+
+import com.happy.Model.Admin;
+import com.happy.Model.AdminManager;
+import com.happy.Model.app.News;
+import com.happy.common.http.Get_airticle;
+import com.happy.common.model.airticle.Item_content;
+import com.happy.dao.AppDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository("AppDao")
+public class AppImplDao implements AppDao {
+
+    @Autowired
+    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
+
+    public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
+        return namedParameterJdbcTemplate;
+    }
+
+    public void setNamedParameterJdbcTemplate(
+            NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
+        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
+    }
+
+    // 登录
+    public Admin login(String admin_name,String password) {
+        String sql = "select * from `admin` where admin_name=:admin_name and password=:password ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("admin_name",admin_name);
+        sps.addValue("password",password);
+        List<Admin> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(Admin.class));
+        if (list != null && list.size() > 0) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    public Admin queryByOpenid(String openid) {
+        String sql = "select * from `admin` where openid=:openid ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("openid",openid);
+        List<Admin> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(Admin.class));
+        if (list != null && list.size() > 0) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    public Admin queryByNameAndOpenid(String admin_name,String openid) {
+        String sql = "select * from `admin` where admin_name=:admin_name and openid=:openid ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("admin_name",admin_name);
+        sps.addValue("openid",openid);
+        List<Admin> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(Admin.class));
+        if (list != null && list.size() > 0) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    public int updateOpenid(String openid,String admin_name){
+        String sql = "update `admin` set openid=:openid where admin_name=:admin_name ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("openid",openid);
+        sps.addValue("admin_name",admin_name);
+        int num = 0;
+        try{
+            num = namedParameterJdbcTemplate.update(sql, sps);
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        return num;
+    }
+
+    public int updateOpenidNull(String openid){
+        String sql = "update `admin` set openid=null where openid=:openid ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("openid",openid);
+        int num = 0;
+        try{
+            num = namedParameterJdbcTemplate.update(sql, sps);
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        return num;
+    }
+
+    /**********************
+     * ********商户绑定**********
+     * ********************/
+    public AdminManager login_ma(String admin_name, String password) {
+        String sql = "select * from `admin_manager` where admin_name=:admin_name and password=:password ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("admin_name",admin_name);
+        sps.addValue("password",password);
+        List<AdminManager> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(AdminManager.class));
+        if (list != null && list.size() > 0) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    public AdminManager queryMaByOpenid(String openid) {
+        String sql = "select * from `admin_manager` where openid=:openid ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("openid",openid);
+        List<AdminManager> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(AdminManager.class));
+        if (list != null && list.size() > 0) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    public AdminManager queryMaByNameAndOpenid(String admin_name,String openid) {
+        String sql = "select * from `admin_manager` where admin_name=:admin_name and openid=:openid ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("admin_name",admin_name);
+        sps.addValue("openid",openid);
+        List<AdminManager> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(AdminManager.class));
+        if (list != null && list.size() > 0) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    public int updateMaOpenid(String openid,String admin_name){
+        String sql = "update `admin_manager` set openid=:openid where admin_name=:admin_name ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("openid",openid);
+        sps.addValue("admin_name",admin_name);
+        int num = 0;
+        try{
+            num = namedParameterJdbcTemplate.update(sql, sps);
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        return num;
+    }
+
+    public int updateMaOpenidNull(String openid){
+        String sql = "update `admin_manager` set openid=null where openid=:openid ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("openid",openid);
+        int num = 0;
+        try{
+            num = namedParameterJdbcTemplate.update(sql, sps);
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        return num;
+    }
+
+    public int insertNews(News news){
+        String sql = "insert into `news`(title,author,digest,content,content_source_url,url,update_time) values(:title,:author,:digest,:content,:content_source_url,:url,:update_time) ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("title", news.getTitle());
+        sps.addValue("author", news.getAuthor());
+        sps.addValue("digest", news.getDigest());
+        sps.addValue("content", news.getContent());
+        sps.addValue("content_source_url", news.getContent_source_url());
+        sps.addValue("url", news.getUrl());
+        sps.addValue("update_time", news.getUpdate_time());
+        int num = 0;
+        try{
+            num = namedParameterJdbcTemplate.update(sql, sps);
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        return num;
+    }
+
+    public News queryByTit(String title){
+        String sql = "select * from `news` where title=:title ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("title", title);
+        List<News> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(News.class));
+        if (list != null && list.size() > 0) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    public List<News> queryNewPage(int page, int rows, String sqlx){
+        int start = (page - 1) * rows;// 每页的起始下标
+        String sql = "select * from `news` where 1=1 "+sqlx+" order by id desc limit :start,:rows ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("start", start);
+        sps.addValue("rows", rows);
+        List<News> list = namedParameterJdbcTemplate.query(sql, sps,
+                new BeanPropertyRowMapper<>(News.class));
+        if (list != null && list.size() > 0) {
+            return list;
+        }
+        return null;
+    }
+
+    // 查询用户表中的总记录数
+    public int queryNewTotal(String sqlx) {
+        String sql = "select count(*) from `news` where 1=1 "+sqlx;
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        return namedParameterJdbcTemplate.queryForInt(sql, sps);
+    }
+
+}