| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- 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<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);
- }
- /** ==============================周边=================================== **/
- 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<Arounds> 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<Arounds> list = namedParameterJdbcTemplate.query(sql, sps,
- new BeanPropertyRowMapper<>(Arounds.class));
- if (list != null && list.size() > 0) {
- return list.get(0);
- }
- return null;
- }
- public List<Arounds> 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<Arounds> 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<Around_product> 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<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
- new BeanPropertyRowMapper<>(Around_product.class));
- if (list != null && list.size() > 0) {
- return list.get(0);
- }
- return null;
- }
- public List<Around_product> 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<Around_product> 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<Around_product> 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<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
- new BeanPropertyRowMapper<>(Around_product.class));
- if (list != null && list.size() > 0) {
- return list;
- }
- return null;
- }
- }
|