package com.happy.dao.impl; import com.happy.Model.Admin; import com.happy.Model.AdminManager; import com.happy.Model.Booking; import com.happy.Model.House; import com.happy.Model.app.Around_product; import com.happy.Model.app.Arounds; 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 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 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 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 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 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 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 list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(News.class)); if (list != null && list.size() > 0) { return list.get(0); } return null; } public List 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 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); } /** ==============================周边=================================== **/ public int insertRound(Arounds arounds){ String sql = "insert into `around`(rtype,rtown,rname,rphone,radress,cnum,detail,first_img,show_video,detail_img) values(:rtype,:rtown,:rname,:rphone,:radress,:cnum,:detail,:first_img,:show_video,:detail_img) "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("rtype", arounds.getRtype()); sps.addValue("rtown", arounds.getRtown()); sps.addValue("rname", arounds.getRname()); sps.addValue("rphone", arounds.getRphone()); sps.addValue("radress", arounds.getRadress()); sps.addValue("cnum", arounds.getCnum()); sps.addValue("detail", arounds.getDetail()); sps.addValue("first_img", arounds.getFirst_img()); sps.addValue("show_video", arounds.getShow_video()); sps.addValue("detail_img", arounds.getDetail_img()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public int updateRoundById(Arounds arounds){ String sql = "update `around` set rtype=:rtype,rtown=:rtown,rname=:rname,rphone=:rphone,radress=:radress,detail=:detail,first_img=:first_img,show_video=:show_video,detail_img=:detail_img where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("rtype", arounds.getRtype()); sps.addValue("rtown", arounds.getRtown()); sps.addValue("rname", arounds.getRname()); sps.addValue("rphone", arounds.getRphone()); sps.addValue("radress", arounds.getRadress()); sps.addValue("detail", arounds.getDetail()); sps.addValue("first_img", arounds.getFirst_img()); sps.addValue("show_video", arounds.getShow_video()); sps.addValue("detail_img", arounds.getDetail_img()); sps.addValue("id", arounds.getId()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public int updateRoundCountById(Arounds arounds){ String sql = "update `around` set cnum=:cnum where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("cnum", arounds.getCnum()); sps.addValue("id", arounds.getId()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public int delAround(int id){ String sql = "delete from `around` where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("id", id); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public Arounds queryAroundById(int id){ String sql = "select * from `around` where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("id", id); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(Arounds.class)); if (list != null && list.size() > 0) { return list.get(0); } return null; } public Arounds queryAroundByName(String rname){ String sql = "select * from `around` where rname=:rname "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("rname", rname); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(Arounds.class)); if (list != null && list.size() > 0) { return list.get(0); } return null; } public List queryAroundPage(String sqlx, int page, int rows){ int start = (page - 1) * rows;// 每页的起始下标 String sql = "select * from `around` where 1=1 "+sqlx+" order by id desc limit :start,:rows "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("start", start); sps.addValue("rows", rows); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(Arounds.class)); if (list != null && list.size() > 0) { return list; } return null; } public int queryAroundTotal(String sqlx) { String sql = "select count(*) from `around` where 1=1 "+sqlx; MapSqlParameterSource sps = new MapSqlParameterSource(); return namedParameterJdbcTemplate.queryForInt(sql, sps); } /** =========================产品============================== **/ public int insertProduct(Around_product around_product){ String sql = "insert into `around_product`(aid,product_name,product_desc,price) values(:aid,:product_name,:product_desc,:price) "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("aid", around_product.getAid()); sps.addValue("product_name", around_product.getProduct_name()); sps.addValue("product_desc", around_product.getProduct_desc()); sps.addValue("price", around_product.getPrice()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public int updateProductById(Around_product around_product){ String sql = "update `around_product` set product_name=:product_name,product_desc=:product_desc,price=:price where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("product_name", around_product.getProduct_name()); sps.addValue("product_desc", around_product.getProduct_desc()); sps.addValue("price", around_product.getPrice()); sps.addValue("id", around_product.getId()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public int delAroundProduct(int id){ String sql = "delete from `around_product` where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("id", id); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public Around_product queryAPById(int id){ String sql = "select * from `around_product` where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("id", id); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(Around_product.class)); if (list != null && list.size() > 0) { return list.get(0); } return null; } public Around_product queryAPByName(int aid,String product_name){ String sql = "select * from `around_product` where aid=:aid and product_name=:product_name "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("aid", aid); sps.addValue("product_name",product_name); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(Around_product.class)); if (list != null && list.size() > 0) { return list.get(0); } return null; } public List queryAPPage(int aid,String sqlx, int page, int rows){ int start = (page - 1) * rows;// 每页的起始下标 String sql = "select * from `around_product` where aid=:aid "+sqlx+" order by id desc limit :start,:rows "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("aid", aid); sps.addValue("start", start); sps.addValue("rows", rows); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(Around_product.class)); if (list != null && list.size() > 0) { return list; } return null; } public int queryAPTotal(int aid,String sqlx) { String sql = "select count(*) from `around_product` where aid=:aid "+sqlx; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("aid", aid); return namedParameterJdbcTemplate.queryForInt(sql, sps); } public List queryAP(int aid,String sqlx){ String sql = "select * from `around_product` where aid=:aid "+sqlx+" order by id desc "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("aid", aid); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(Around_product.class)); if (list != null && list.size() > 0) { return list; } return null; } }