AppImplDao.java 18 KB

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