AppImplDao.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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,jingwei) values(:rtype,:rtown,:rname,:rphone,:radress,:cnum,:detail,:first_img,:show_video,:detail_img,:jingwei) ";
  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. sps.addValue("jingwei",arounds.getJingwei());
  222. int num = 0;
  223. try{
  224. num = namedParameterJdbcTemplate.update(sql, sps);
  225. }
  226. catch(Exception e){
  227. e.printStackTrace();
  228. }
  229. return num;
  230. }
  231. public int updateRoundById(Arounds arounds){
  232. 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 ";
  233. MapSqlParameterSource sps = new MapSqlParameterSource();
  234. sps.addValue("rtype", arounds.getRtype());
  235. sps.addValue("rtown", arounds.getRtown());
  236. sps.addValue("rname", arounds.getRname());
  237. sps.addValue("rphone", arounds.getRphone());
  238. sps.addValue("radress", arounds.getRadress());
  239. sps.addValue("detail", arounds.getDetail());
  240. sps.addValue("first_img", arounds.getFirst_img());
  241. sps.addValue("show_video", arounds.getShow_video());
  242. sps.addValue("detail_img", arounds.getDetail_img());
  243. sps.addValue("jingwei",arounds.getJingwei());
  244. sps.addValue("id", arounds.getId());
  245. int num = 0;
  246. try{
  247. num = namedParameterJdbcTemplate.update(sql, sps);
  248. }
  249. catch(Exception e){
  250. e.printStackTrace();
  251. }
  252. return num;
  253. }
  254. public int updateRoundCountById(Arounds arounds){
  255. String sql = "update `around` set cnum=:cnum where id=:id ";
  256. MapSqlParameterSource sps = new MapSqlParameterSource();
  257. sps.addValue("cnum", arounds.getCnum());
  258. sps.addValue("id", arounds.getId());
  259. int num = 0;
  260. try{
  261. num = namedParameterJdbcTemplate.update(sql, sps);
  262. }
  263. catch(Exception e){
  264. e.printStackTrace();
  265. }
  266. return num;
  267. }
  268. public int delAround(int id){
  269. String sql = "delete from `around` where id=:id ";
  270. MapSqlParameterSource sps = new MapSqlParameterSource();
  271. sps.addValue("id", id);
  272. int num = 0;
  273. try{
  274. num = namedParameterJdbcTemplate.update(sql, sps);
  275. }
  276. catch(Exception e){
  277. e.printStackTrace();
  278. }
  279. return num;
  280. }
  281. public Arounds queryAroundById(int id){
  282. String sql = "select * from `around` where id=:id ";
  283. MapSqlParameterSource sps = new MapSqlParameterSource();
  284. sps.addValue("id", id);
  285. List<Arounds> list = namedParameterJdbcTemplate.query(sql, sps,
  286. new BeanPropertyRowMapper<>(Arounds.class));
  287. if (list != null && list.size() > 0) {
  288. return list.get(0);
  289. }
  290. return null;
  291. }
  292. public Arounds queryAroundByName(String rname){
  293. String sql = "select * from `around` where rname=:rname ";
  294. MapSqlParameterSource sps = new MapSqlParameterSource();
  295. sps.addValue("rname", rname);
  296. List<Arounds> list = namedParameterJdbcTemplate.query(sql, sps,
  297. new BeanPropertyRowMapper<>(Arounds.class));
  298. if (list != null && list.size() > 0) {
  299. return list.get(0);
  300. }
  301. return null;
  302. }
  303. public List<Arounds> queryAroundPage(String sqlx, int page, int rows){
  304. int start = (page - 1) * rows;// 每页的起始下标
  305. String sql = "select * from `around` where 1=1 "+sqlx+" order by id desc limit :start,:rows ";
  306. MapSqlParameterSource sps = new MapSqlParameterSource();
  307. sps.addValue("start", start);
  308. sps.addValue("rows", rows);
  309. List<Arounds> list = namedParameterJdbcTemplate.query(sql, sps,
  310. new BeanPropertyRowMapper<>(Arounds.class));
  311. if (list != null && list.size() > 0) {
  312. return list;
  313. }
  314. return null;
  315. }
  316. public int queryAroundTotal(String sqlx) {
  317. String sql = "select count(*) from `around` where 1=1 "+sqlx;
  318. MapSqlParameterSource sps = new MapSqlParameterSource();
  319. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  320. }
  321. /** =========================产品============================== **/
  322. public int insertProduct(Around_product around_product){
  323. String sql = "insert into `around_product`(aid,product_name,product_desc,price) values(:aid,:product_name,:product_desc,:price) ";
  324. MapSqlParameterSource sps = new MapSqlParameterSource();
  325. sps.addValue("aid", around_product.getAid());
  326. sps.addValue("product_name", around_product.getProduct_name());
  327. sps.addValue("product_desc", around_product.getProduct_desc());
  328. sps.addValue("price", around_product.getPrice());
  329. int num = 0;
  330. try{
  331. num = namedParameterJdbcTemplate.update(sql, sps);
  332. }
  333. catch(Exception e){
  334. e.printStackTrace();
  335. }
  336. return num;
  337. }
  338. public int updateProductById(Around_product around_product){
  339. String sql = "update `around_product` set product_name=:product_name,product_desc=:product_desc,price=:price where id=:id ";
  340. MapSqlParameterSource sps = new MapSqlParameterSource();
  341. sps.addValue("product_name", around_product.getProduct_name());
  342. sps.addValue("product_desc", around_product.getProduct_desc());
  343. sps.addValue("price", around_product.getPrice());
  344. sps.addValue("id", around_product.getId());
  345. int num = 0;
  346. try{
  347. num = namedParameterJdbcTemplate.update(sql, sps);
  348. }
  349. catch(Exception e){
  350. e.printStackTrace();
  351. }
  352. return num;
  353. }
  354. public int delAroundProduct(int id){
  355. String sql = "delete from `around_product` where id=:id ";
  356. MapSqlParameterSource sps = new MapSqlParameterSource();
  357. sps.addValue("id", id);
  358. int num = 0;
  359. try{
  360. num = namedParameterJdbcTemplate.update(sql, sps);
  361. }
  362. catch(Exception e){
  363. e.printStackTrace();
  364. }
  365. return num;
  366. }
  367. public Around_product queryAPById(int id){
  368. String sql = "select * from `around_product` where id=:id ";
  369. MapSqlParameterSource sps = new MapSqlParameterSource();
  370. sps.addValue("id", id);
  371. List<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
  372. new BeanPropertyRowMapper<>(Around_product.class));
  373. if (list != null && list.size() > 0) {
  374. return list.get(0);
  375. }
  376. return null;
  377. }
  378. public Around_product queryAPByName(int aid,String product_name){
  379. String sql = "select * from `around_product` where aid=:aid and product_name=:product_name ";
  380. MapSqlParameterSource sps = new MapSqlParameterSource();
  381. sps.addValue("aid", aid);
  382. sps.addValue("product_name",product_name);
  383. List<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
  384. new BeanPropertyRowMapper<>(Around_product.class));
  385. if (list != null && list.size() > 0) {
  386. return list.get(0);
  387. }
  388. return null;
  389. }
  390. public List<Around_product> queryAPPage(int aid,String sqlx, int page, int rows){
  391. int start = (page - 1) * rows;// 每页的起始下标
  392. String sql = "select * from `around_product` where aid=:aid "+sqlx+" order by id desc limit :start,:rows ";
  393. MapSqlParameterSource sps = new MapSqlParameterSource();
  394. sps.addValue("aid", aid);
  395. sps.addValue("start", start);
  396. sps.addValue("rows", rows);
  397. List<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
  398. new BeanPropertyRowMapper<>(Around_product.class));
  399. if (list != null && list.size() > 0) {
  400. return list;
  401. }
  402. return null;
  403. }
  404. public int queryAPTotal(int aid,String sqlx) {
  405. String sql = "select count(*) from `around_product` where aid=:aid "+sqlx;
  406. MapSqlParameterSource sps = new MapSqlParameterSource();
  407. sps.addValue("aid", aid);
  408. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  409. }
  410. public List<Around_product> queryAP(int aid,String sqlx){
  411. String sql = "select * from `around_product` where aid=:aid "+sqlx+" order by id desc ";
  412. MapSqlParameterSource sps = new MapSqlParameterSource();
  413. sps.addValue("aid", aid);
  414. List<Around_product> list = namedParameterJdbcTemplate.query(sql, sps,
  415. new BeanPropertyRowMapper<>(Around_product.class));
  416. if (list != null && list.size() > 0) {
  417. return list;
  418. }
  419. return null;
  420. }
  421. }