AppImplDao.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. package com.happy.dao.impl;
  2. import com.happy.Model.*;
  3. import com.happy.Model.app.Around_product;
  4. import com.happy.Model.app.Arounds;
  5. import com.happy.Model.app.News;
  6. import com.happy.Model.app.Tongji;
  7. import com.happy.common.http.Get_airticle;
  8. import com.happy.common.model.airticle.Item_content;
  9. import com.happy.dao.AppDao;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  12. import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  13. import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
  14. import org.springframework.stereotype.Repository;
  15. import java.util.List;
  16. @Repository("AppDao")
  17. public class AppImplDao implements AppDao {
  18. @Autowired
  19. private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
  20. public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
  21. return namedParameterJdbcTemplate;
  22. }
  23. public void setNamedParameterJdbcTemplate(
  24. NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
  25. this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
  26. }
  27. // 登录
  28. public Admin login(String admin_name,String password) {
  29. String sql = "select * from `admin` where admin_name=:admin_name and password=:password ";
  30. MapSqlParameterSource sps = new MapSqlParameterSource();
  31. sps.addValue("admin_name",admin_name);
  32. sps.addValue("password",password);
  33. List<Admin> list = namedParameterJdbcTemplate.query(sql, sps,
  34. new BeanPropertyRowMapper<>(Admin.class));
  35. if (list != null && list.size() > 0) {
  36. return list.get(0);
  37. }
  38. return null;
  39. }
  40. public Admin queryByOpenid(String openid) {
  41. String sql = "select * from `admin` where openid=:openid ";
  42. MapSqlParameterSource sps = new MapSqlParameterSource();
  43. sps.addValue("openid",openid);
  44. List<Admin> list = namedParameterJdbcTemplate.query(sql, sps,
  45. new BeanPropertyRowMapper<>(Admin.class));
  46. if (list != null && list.size() > 0) {
  47. return list.get(0);
  48. }
  49. return null;
  50. }
  51. public Admin queryByNameAndOpenid(String admin_name,String openid) {
  52. String sql = "select * from `admin` where admin_name=:admin_name and openid=:openid ";
  53. MapSqlParameterSource sps = new MapSqlParameterSource();
  54. sps.addValue("admin_name",admin_name);
  55. sps.addValue("openid",openid);
  56. List<Admin> list = namedParameterJdbcTemplate.query(sql, sps,
  57. new BeanPropertyRowMapper<>(Admin.class));
  58. if (list != null && list.size() > 0) {
  59. return list.get(0);
  60. }
  61. return null;
  62. }
  63. public int updateOpenid(String openid,String admin_name){
  64. String sql = "update `admin` set openid=:openid where admin_name=:admin_name ";
  65. MapSqlParameterSource sps = new MapSqlParameterSource();
  66. sps.addValue("openid",openid);
  67. sps.addValue("admin_name",admin_name);
  68. int num = 0;
  69. try{
  70. num = namedParameterJdbcTemplate.update(sql, sps);
  71. }
  72. catch(Exception e){
  73. e.printStackTrace();
  74. }
  75. return num;
  76. }
  77. public int updateOpenidNull(String openid){
  78. String sql = "update `admin` set openid=null where openid=:openid ";
  79. MapSqlParameterSource sps = new MapSqlParameterSource();
  80. sps.addValue("openid",openid);
  81. int num = 0;
  82. try{
  83. num = namedParameterJdbcTemplate.update(sql, sps);
  84. }
  85. catch(Exception e){
  86. e.printStackTrace();
  87. }
  88. return num;
  89. }
  90. /**********************
  91. * ********商户绑定**********
  92. * ********************/
  93. public AdminManager login_ma(String admin_name, String password) {
  94. String sql = "select * from `admin_manager` where admin_name=:admin_name and password=:password ";
  95. MapSqlParameterSource sps = new MapSqlParameterSource();
  96. sps.addValue("admin_name",admin_name);
  97. sps.addValue("password",password);
  98. List<AdminManager> list = namedParameterJdbcTemplate.query(sql, sps,
  99. new BeanPropertyRowMapper<>(AdminManager.class));
  100. if (list != null && list.size() > 0) {
  101. return list.get(0);
  102. }
  103. return null;
  104. }
  105. public AdminManager queryMaByOpenid(String openid) {
  106. String sql = "select * from `admin_manager` where openid=:openid ";
  107. MapSqlParameterSource sps = new MapSqlParameterSource();
  108. sps.addValue("openid",openid);
  109. List<AdminManager> list = namedParameterJdbcTemplate.query(sql, sps,
  110. new BeanPropertyRowMapper<>(AdminManager.class));
  111. if (list != null && list.size() > 0) {
  112. return list.get(0);
  113. }
  114. return null;
  115. }
  116. public AdminManager queryMaByNameAndOpenid(String admin_name,String openid) {
  117. String sql = "select * from `admin_manager` where admin_name=:admin_name and openid=:openid ";
  118. MapSqlParameterSource sps = new MapSqlParameterSource();
  119. sps.addValue("admin_name",admin_name);
  120. sps.addValue("openid",openid);
  121. List<AdminManager> list = namedParameterJdbcTemplate.query(sql, sps,
  122. new BeanPropertyRowMapper<>(AdminManager.class));
  123. if (list != null && list.size() > 0) {
  124. return list.get(0);
  125. }
  126. return null;
  127. }
  128. public int updateMaOpenid(String openid,String admin_name){
  129. String sql = "update `admin_manager` set openid=:openid where admin_name=:admin_name ";
  130. MapSqlParameterSource sps = new MapSqlParameterSource();
  131. sps.addValue("openid",openid);
  132. sps.addValue("admin_name",admin_name);
  133. int num = 0;
  134. try{
  135. num = namedParameterJdbcTemplate.update(sql, sps);
  136. }
  137. catch(Exception e){
  138. e.printStackTrace();
  139. }
  140. return num;
  141. }
  142. public int updateMaOpenidNull(String openid){
  143. String sql = "update `admin_manager` set openid=null where openid=:openid ";
  144. MapSqlParameterSource sps = new MapSqlParameterSource();
  145. sps.addValue("openid",openid);
  146. int num = 0;
  147. try{
  148. num = namedParameterJdbcTemplate.update(sql, sps);
  149. }
  150. catch(Exception e){
  151. e.printStackTrace();
  152. }
  153. return num;
  154. }
  155. /** ================================资讯============================= **/
  156. public int insertNews(News news){
  157. String sql = "insert into `news`(media_id,title,author,digest,content,content_source_url,url,update_time,first_img,state,is_top) values(:media_id,:title,:author,:digest,:content,:content_source_url,:url,:update_time,:first_img,:state,:is_top) ";
  158. MapSqlParameterSource sps = new MapSqlParameterSource();
  159. sps.addValue("media_id",news.getMedia_id());
  160. sps.addValue("title", news.getTitle());
  161. sps.addValue("author", news.getAuthor());
  162. sps.addValue("digest", news.getDigest());
  163. sps.addValue("content", news.getContent());
  164. sps.addValue("content_source_url", news.getContent_source_url());
  165. sps.addValue("url", news.getUrl());
  166. sps.addValue("update_time", news.getUpdate_time());
  167. sps.addValue("first_img",news.getFirst_img());
  168. sps.addValue("state",news.getState());
  169. sps.addValue("is_top",news.getIs_top());
  170. int num = 0;
  171. try{
  172. num = namedParameterJdbcTemplate.update(sql, sps);
  173. }
  174. catch(Exception e){
  175. e.printStackTrace();
  176. }
  177. return num;
  178. }
  179. public int delNews(int id){
  180. String sql = "update `news` set state=0 where id=:id ";
  181. MapSqlParameterSource sps = new MapSqlParameterSource();
  182. sps.addValue("id",id);
  183. int num = 0;
  184. try{
  185. num = namedParameterJdbcTemplate.update(sql, sps);
  186. }
  187. catch(Exception e){
  188. e.printStackTrace();
  189. }
  190. return num;
  191. }
  192. public int updateNews(News news){
  193. String sql = "update `news` set title=:title,author=:author,digest=:digest,content=:content where id=:id ";
  194. MapSqlParameterSource sps = new MapSqlParameterSource();
  195. sps.addValue("title", news.getTitle());
  196. sps.addValue("author", news.getAuthor());
  197. sps.addValue("digest", news.getDigest());
  198. sps.addValue("content", news.getContent());
  199. sps.addValue("id",news.getId());
  200. int num = 0;
  201. try{
  202. num = namedParameterJdbcTemplate.update(sql, sps);
  203. }
  204. catch(Exception e){
  205. e.printStackTrace();
  206. }
  207. return num;
  208. }
  209. public int updateTop(News news){
  210. String sql = "update `news` set is_top=:is_top,top_time=:top_time where id=:id ";
  211. MapSqlParameterSource sps = new MapSqlParameterSource();
  212. sps.addValue("is_top", news.getIs_top());
  213. sps.addValue("top_time", news.getTop_time());
  214. sps.addValue("id",news.getId());
  215. int num = 0;
  216. try{
  217. num = namedParameterJdbcTemplate.update(sql, sps);
  218. }
  219. catch(Exception e){
  220. e.printStackTrace();
  221. }
  222. return num;
  223. }
  224. public News queryByTit(String title){
  225. String sql = "select * from `news` where title=:title ";
  226. MapSqlParameterSource sps = new MapSqlParameterSource();
  227. sps.addValue("title", title);
  228. List<News> list = namedParameterJdbcTemplate.query(sql, sps,
  229. new BeanPropertyRowMapper<>(News.class));
  230. if (list != null && list.size() > 0) {
  231. return list.get(0);
  232. }
  233. return null;
  234. }
  235. public News queryById(int id){
  236. String sql = "select * from `news` where id=:id ";
  237. MapSqlParameterSource sps = new MapSqlParameterSource();
  238. sps.addValue("id", id);
  239. List<News> list = namedParameterJdbcTemplate.query(sql, sps,
  240. new BeanPropertyRowMapper<>(News.class));
  241. if (list != null && list.size() > 0) {
  242. return list.get(0);
  243. }
  244. return null;
  245. }
  246. public List<News> queryNewPage(int page, int rows, String sqlx){
  247. int start = (page - 1) * rows;// 每页的起始下标
  248. String sql = "select * from `news` where state=1 "+sqlx+" limit :start,:rows ";
  249. MapSqlParameterSource sps = new MapSqlParameterSource();
  250. sps.addValue("start", start);
  251. sps.addValue("rows", rows);
  252. List<News> list = namedParameterJdbcTemplate.query(sql, sps,
  253. new BeanPropertyRowMapper<>(News.class));
  254. if (list != null && list.size() > 0) {
  255. return list;
  256. }
  257. return null;
  258. }
  259. // 查询用户表中的总记录数
  260. public int queryNewTotal(String sqlx) {
  261. String sql = "select count(*) from `news` where state=1 "+sqlx;
  262. MapSqlParameterSource sps = new MapSqlParameterSource();
  263. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  264. }
  265. /** ==============================周边=================================== **/
  266. public int insertRound(Arounds arounds){
  267. String sql = "insert into `around`(rtype,rtown,rname,rphone,radress,cnum,detail,first_img,show_video,detail_img,jingwei) values(:rtype,:rtown,:rname,:rphone,:radress,:cnum,:detail,:first_img,:show_video,:detail_img,:jingwei) ";
  268. MapSqlParameterSource sps = new MapSqlParameterSource();
  269. sps.addValue("rtype", arounds.getRtype());
  270. sps.addValue("rtown", arounds.getRtown());
  271. sps.addValue("rname", arounds.getRname());
  272. sps.addValue("rphone", arounds.getRphone());
  273. sps.addValue("radress", arounds.getRadress());
  274. sps.addValue("cnum", arounds.getCnum());
  275. sps.addValue("detail", arounds.getDetail());
  276. sps.addValue("first_img", arounds.getFirst_img());
  277. sps.addValue("show_video", arounds.getShow_video());
  278. sps.addValue("detail_img", arounds.getDetail_img());
  279. sps.addValue("jingwei",arounds.getJingwei());
  280. int num = 0;
  281. try{
  282. num = namedParameterJdbcTemplate.update(sql, sps);
  283. }
  284. catch(Exception e){
  285. e.printStackTrace();
  286. }
  287. return num;
  288. }
  289. public int updateRoundById(Arounds arounds){
  290. 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,jingwei=:jingwei where id=:id ";
  291. MapSqlParameterSource sps = new MapSqlParameterSource();
  292. sps.addValue("rtype", arounds.getRtype());
  293. sps.addValue("rtown", arounds.getRtown());
  294. sps.addValue("rname", arounds.getRname());
  295. sps.addValue("rphone", arounds.getRphone());
  296. sps.addValue("radress", arounds.getRadress());
  297. sps.addValue("detail", arounds.getDetail());
  298. sps.addValue("first_img", arounds.getFirst_img());
  299. sps.addValue("show_video", arounds.getShow_video());
  300. sps.addValue("detail_img", arounds.getDetail_img());
  301. sps.addValue("jingwei",arounds.getJingwei());
  302. sps.addValue("id", arounds.getId());
  303. int num = 0;
  304. try{
  305. num = namedParameterJdbcTemplate.update(sql, sps);
  306. }
  307. catch(Exception e){
  308. e.printStackTrace();
  309. }
  310. return num;
  311. }
  312. public int updateRoundCountById(Arounds arounds){
  313. String sql = "update `around` set cnum=:cnum where id=:id ";
  314. MapSqlParameterSource sps = new MapSqlParameterSource();
  315. sps.addValue("cnum", arounds.getCnum());
  316. sps.addValue("id", arounds.getId());
  317. int num = 0;
  318. try{
  319. num = namedParameterJdbcTemplate.update(sql, sps);
  320. }
  321. catch(Exception e){
  322. e.printStackTrace();
  323. }
  324. return num;
  325. }
  326. public int delAround(int id){
  327. String sql = "delete from `around` where id=:id ";
  328. MapSqlParameterSource sps = new MapSqlParameterSource();
  329. sps.addValue("id", id);
  330. int num = 0;
  331. try{
  332. num = namedParameterJdbcTemplate.update(sql, sps);
  333. }
  334. catch(Exception e){
  335. e.printStackTrace();
  336. }
  337. return num;
  338. }
  339. public Arounds queryAroundById(int id){
  340. String sql = "select * from `around` where id=:id ";
  341. MapSqlParameterSource sps = new MapSqlParameterSource();
  342. sps.addValue("id", id);
  343. List<Arounds> list = namedParameterJdbcTemplate.query(sql, sps,
  344. new BeanPropertyRowMapper<>(Arounds.class));
  345. if (list != null && list.size() > 0) {
  346. return list.get(0);
  347. }
  348. return null;
  349. }
  350. public Arounds queryAroundByName(String rname){
  351. String sql = "select * from `around` where rname=:rname ";
  352. MapSqlParameterSource sps = new MapSqlParameterSource();
  353. sps.addValue("rname", rname);
  354. List<Arounds> list = namedParameterJdbcTemplate.query(sql, sps,
  355. new BeanPropertyRowMapper<>(Arounds.class));
  356. if (list != null && list.size() > 0) {
  357. return list.get(0);
  358. }
  359. return null;
  360. }
  361. public List<Arounds> queryAroundPage(String sqlx, int page, int rows){
  362. int start = (page - 1) * rows;// 每页的起始下标
  363. String sql = "select * from `around` where 1=1 "+sqlx+" order by id desc limit :start,:rows ";
  364. MapSqlParameterSource sps = new MapSqlParameterSource();
  365. sps.addValue("start", start);
  366. sps.addValue("rows", rows);
  367. List<Arounds> list = namedParameterJdbcTemplate.query(sql, sps,
  368. new BeanPropertyRowMapper<>(Arounds.class));
  369. if (list != null && list.size() > 0) {
  370. return list;
  371. }
  372. return null;
  373. }
  374. public int queryAroundTotal(String sqlx) {
  375. String sql = "select count(*) from `around` where 1=1 "+sqlx;
  376. MapSqlParameterSource sps = new MapSqlParameterSource();
  377. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  378. }
  379. /** =========================产品============================== **/
  380. public int insertProduct(Around_product around_product){
  381. String sql = "insert into `around_product`(aid,product_name,product_desc,price) values(:aid,:product_name,:product_desc,:price) ";
  382. MapSqlParameterSource sps = new MapSqlParameterSource();
  383. sps.addValue("aid", around_product.getAid());
  384. sps.addValue("product_name", around_product.getProduct_name());
  385. sps.addValue("product_desc", around_product.getProduct_desc());
  386. sps.addValue("price", around_product.getPrice());
  387. int num = 0;
  388. try{
  389. num = namedParameterJdbcTemplate.update(sql, sps);
  390. }
  391. catch(Exception e){
  392. e.printStackTrace();
  393. }
  394. return num;
  395. }
  396. public int updateProductById(Around_product around_product){
  397. String sql = "update `around_product` set product_name=:product_name,product_desc=:product_desc,price=:price where id=:id ";
  398. MapSqlParameterSource sps = new MapSqlParameterSource();
  399. sps.addValue("product_name", around_product.getProduct_name());
  400. sps.addValue("product_desc", around_product.getProduct_desc());
  401. sps.addValue("price", around_product.getPrice());
  402. sps.addValue("id", around_product.getId());
  403. int num = 0;
  404. try{
  405. num = namedParameterJdbcTemplate.update(sql, sps);
  406. }
  407. catch(Exception e){
  408. e.printStackTrace();
  409. }
  410. return num;
  411. }
  412. public int delAroundProduct(int id){
  413. String sql = "delete from `around_product` where id=:id ";
  414. MapSqlParameterSource sps = new MapSqlParameterSource();
  415. sps.addValue("id", id);
  416. int num = 0;
  417. try{
  418. num = namedParameterJdbcTemplate.update(sql, sps);
  419. }
  420. catch(Exception e){
  421. e.printStackTrace();
  422. }
  423. return num;
  424. }
  425. public Around_product queryAPById(int id){
  426. String sql = "select * from `around_product` where id=:id ";
  427. MapSqlParameterSource sps = new MapSqlParameterSource();
  428. sps.addValue("id", id);
  429. List<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
  430. new BeanPropertyRowMapper<>(Around_product.class));
  431. if (list != null && list.size() > 0) {
  432. return list.get(0);
  433. }
  434. return null;
  435. }
  436. public Around_product queryAPByName(int aid,String product_name){
  437. String sql = "select * from `around_product` where aid=:aid and product_name=:product_name ";
  438. MapSqlParameterSource sps = new MapSqlParameterSource();
  439. sps.addValue("aid", aid);
  440. sps.addValue("product_name",product_name);
  441. List<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
  442. new BeanPropertyRowMapper<>(Around_product.class));
  443. if (list != null && list.size() > 0) {
  444. return list.get(0);
  445. }
  446. return null;
  447. }
  448. public List<Around_product> queryAPPage(int aid,String sqlx, int page, int rows){
  449. int start = (page - 1) * rows;// 每页的起始下标
  450. String sql = "select * from `around_product` where aid=:aid "+sqlx+" order by id desc limit :start,:rows ";
  451. MapSqlParameterSource sps = new MapSqlParameterSource();
  452. sps.addValue("aid", aid);
  453. sps.addValue("start", start);
  454. sps.addValue("rows", rows);
  455. List<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
  456. new BeanPropertyRowMapper<>(Around_product.class));
  457. if (list != null && list.size() > 0) {
  458. return list;
  459. }
  460. return null;
  461. }
  462. public int queryAPTotal(int aid,String sqlx) {
  463. String sql = "select count(*) from `around_product` where aid=:aid "+sqlx;
  464. MapSqlParameterSource sps = new MapSqlParameterSource();
  465. sps.addValue("aid", aid);
  466. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  467. }
  468. public List<Around_product> queryAP(int aid,String sqlx){
  469. String sql = "select * from `around_product` where aid=:aid "+sqlx+" order by id desc ";
  470. MapSqlParameterSource sps = new MapSqlParameterSource();
  471. sps.addValue("aid", aid);
  472. List<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
  473. new BeanPropertyRowMapper<>(Around_product.class));
  474. if (list != null && list.size() > 0) {
  475. return list;
  476. }
  477. return null;
  478. }
  479. public List<Hotel> queryMs(String town){
  480. String sql = "select a.*,b.name from (select a.*,b.hotel_township from `hotel` a left join `admin_manager` b on a.`manager_id`=b.`manager_id` where a.`status`=1 ) a left join `hotel_dict` b on a.hotel_township=b.`id` where b.name=:town ";
  481. MapSqlParameterSource sps = new MapSqlParameterSource();
  482. sps.addValue("town", town);
  483. List<Hotel> list = namedParameterJdbcTemplate.query(sql, sps,
  484. new BeanPropertyRowMapper<>(Hotel.class));
  485. if (list != null && list.size() > 0) {
  486. return list;
  487. }
  488. return null;
  489. }
  490. }