appAction.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. package com.happy.action;
  2. import com.google.gson.Gson;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.google.gson.reflect.TypeToken;
  5. import com.happy.Model.*;
  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.Model.weixin.*;
  10. import com.happy.Until.*;
  11. import com.happy.common.http.Get_airticle;
  12. import com.happy.common.http.HttpsClient;
  13. import com.happy.common.http.Message2;
  14. import com.happy.common.http.Message3;
  15. import com.happy.common.model.airticle.Content;
  16. import com.happy.common.model.airticle.Item_content;
  17. import com.happy.common.model.airticle.News_content;
  18. import com.happy.common.util.WechatUtil;
  19. import com.happy.common.wx.WxUtil;
  20. import com.happy.service.*;
  21. import com.opensymphony.xwork2.ActionSupport;
  22. import org.apache.struts2.ServletActionContext;
  23. import org.apache.struts2.interceptor.ServletRequestAware;
  24. import javax.annotation.Resource;
  25. import javax.servlet.http.HttpServletRequest;
  26. import javax.servlet.http.HttpServletResponse;
  27. import javax.servlet.http.HttpSession;
  28. import java.io.BufferedReader;
  29. import java.io.IOException;
  30. import java.io.PrintWriter;
  31. import java.io.UnsupportedEncodingException;
  32. import java.net.URLEncoder;
  33. import java.text.ParseException;
  34. import java.text.SimpleDateFormat;
  35. import java.util.*;
  36. public class appAction extends ActionSupport implements ServletRequestAware {
  37. private HttpServletRequest request;
  38. public HttpServletResponse response;
  39. @Resource
  40. public UserService userService;
  41. @Resource
  42. public BookService bookService;
  43. @Resource
  44. public HouseService houseService;
  45. @Resource
  46. public ConfigService configService;
  47. @Resource
  48. public AppService appService;
  49. public Integer id;
  50. public Integer aid;
  51. public String wxcode;
  52. public String state;
  53. public String code;
  54. public String order_num;
  55. public String card_number;
  56. public String phone;
  57. public String admin_name;
  58. public String password;
  59. public String openid;
  60. public int page; // 当前页
  61. public int rows;// 每页显示的行数rows
  62. public String rtype;
  63. public String rtown;
  64. public String key;
  65. public String title;
  66. public HttpServletRequest getRequest() {
  67. return request;
  68. }
  69. public void setRequest(HttpServletRequest request) {
  70. this.request = request;
  71. }
  72. public void setServletRequest(HttpServletRequest request) {
  73. this.request = request;
  74. }
  75. public HttpServletResponse getResponse() {
  76. return response;
  77. }
  78. public void setResponse(HttpServletResponse response) {
  79. this.response = response;
  80. }
  81. public String getState() {
  82. return state;
  83. }
  84. public void setState(String state) {
  85. this.state = state;
  86. }
  87. public String getWxcode() {
  88. return wxcode;
  89. }
  90. public void setWxcode(String wxcode) {
  91. this.wxcode = wxcode;
  92. }
  93. public String getCode() {
  94. return code;
  95. }
  96. public void setCode(String code) {
  97. this.code = code;
  98. }
  99. public String getOrder_num() {
  100. return order_num;
  101. }
  102. public void setOrder_num(String order_num) {
  103. this.order_num = order_num;
  104. }
  105. public String getCard_number() {
  106. return card_number;
  107. }
  108. public void setCard_number(String card_number) {
  109. this.card_number = card_number;
  110. }
  111. public String getPhone() {
  112. return phone;
  113. }
  114. public void setPhone(String phone) {
  115. this.phone = phone;
  116. }
  117. public String getAdmin_name() {
  118. return admin_name;
  119. }
  120. public void setAdmin_name(String admin_name) {
  121. this.admin_name = admin_name;
  122. }
  123. public String getPassword() {
  124. return password;
  125. }
  126. public void setPassword(String password) {
  127. this.password = password;
  128. }
  129. public String getOpenid() {
  130. return openid;
  131. }
  132. public void setOpenid(String openid) {
  133. this.openid = openid;
  134. }
  135. public int getPage() {
  136. return page;
  137. }
  138. public void setPage(int page) {
  139. this.page = page;
  140. }
  141. public int getRows() {
  142. return rows;
  143. }
  144. public void setRows(int rows) {
  145. this.rows = rows;
  146. }
  147. public Integer getId() {
  148. return id;
  149. }
  150. public void setId(Integer id) {
  151. this.id = id;
  152. }
  153. public Integer getAid() {
  154. return aid;
  155. }
  156. public void setAid(Integer aid) {
  157. this.aid = aid;
  158. }
  159. public String getRtype() {
  160. return rtype;
  161. }
  162. public void setRtype(String rtype) {
  163. this.rtype = rtype;
  164. }
  165. public String getRtown() {
  166. return rtown;
  167. }
  168. public void setRtown(String rtown) {
  169. this.rtown = rtown;
  170. }
  171. public String getKey() {
  172. return key;
  173. }
  174. public void setKey(String key) {
  175. this.key = key;
  176. }
  177. public String getTitle() {
  178. return title;
  179. }
  180. public void setTitle(String title) {
  181. this.title = title;
  182. }
  183. public String test() throws Exception {
  184. JSONObject resultJson = new JSONObject();
  185. String msg = Message2.send(openid,"20231011163520","总统套房",
  186. "2023-10-11","测试","测试","");
  187. resultJson.put("message", "返回成功");
  188. resultJson.put("code", 200);
  189. resultJson.put("data",msg);
  190. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  191. return null;
  192. }
  193. // 查询是否绑定
  194. public String getUser(){
  195. JSONObject resultJson = new JSONObject();
  196. if (code==null){
  197. resultJson.put("message", "code不能为空");
  198. resultJson.put("code", 205);
  199. resultJson.put("data","");
  200. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  201. return null;
  202. }
  203. JSONObject jsonObject = appService.getGCodeInfo(code);
  204. Admin admin = appService.queryByOpenid(jsonObject.get("openid").toString());
  205. if (admin==null){
  206. resultJson.put("message", "未绑定信息");
  207. resultJson.put("code", 205);
  208. resultJson.put("data","");
  209. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  210. return null;
  211. }
  212. resultJson.put("message", "返回成功");
  213. resultJson.put("code", 200);
  214. resultJson.put("data", admin);
  215. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  216. return null;
  217. }
  218. // 开始绑定
  219. public String code() throws IOException {
  220. JSONObject resultJson = new JSONObject();
  221. if (code==null || admin_name==null || password==null){
  222. resultJson.put("message", "参数不能为空");
  223. resultJson.put("code", 205);
  224. resultJson.put("data","");
  225. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  226. return null;
  227. }
  228. Admin login = appService.login(admin_name,password);
  229. if (login==null){
  230. resultJson.put("message", "账户或密码错误");
  231. resultJson.put("code", 205);
  232. resultJson.put("data","");
  233. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  234. return null;
  235. }
  236. JSONObject jsonObject = appService.getGCodeInfo(code);
  237. Admin admin = appService.queryByNameAndOpenid(admin_name,jsonObject.get("openid").toString());
  238. if (admin!=null){
  239. resultJson.put("message", "该账户已绑定,请勿重复绑定");
  240. resultJson.put("code", 205);
  241. resultJson.put("data",admin);
  242. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  243. return null;
  244. }
  245. int m = appService.updateOpenid(jsonObject.get("openid").toString(),admin_name);
  246. if (m>0){
  247. admin = appService.queryByNameAndOpenid(admin_name,jsonObject.get("openid").toString());
  248. resultJson.put("message", "绑定成功");
  249. resultJson.put("code", 200);
  250. resultJson.put("data",admin);
  251. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  252. return null;
  253. }
  254. return null;
  255. }
  256. // 解绑
  257. public String uncode(){
  258. JSONObject resultJson = new JSONObject();
  259. if (code==null || admin_name==null || password==null){
  260. resultJson.put("message", "参数不能为空");
  261. resultJson.put("code", 205);
  262. resultJson.put("data","");
  263. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  264. return null;
  265. }
  266. Admin login = appService.login(admin_name,password);
  267. if (login==null){
  268. resultJson.put("message", "账户或密码错误");
  269. resultJson.put("code", 205);
  270. resultJson.put("data","");
  271. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  272. return null;
  273. }
  274. JSONObject jsonObject = appService.getGCodeInfo(code);
  275. Admin admin = appService.queryByNameAndOpenid(admin_name,jsonObject.get("openid").toString());
  276. if (admin==null){
  277. resultJson.put("message", "输入信息与当前绑定账户不匹配");
  278. resultJson.put("code", 205);
  279. resultJson.put("data","");
  280. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  281. return null;
  282. }
  283. int m = appService.updateOpenidNull(jsonObject.get("openid").toString());
  284. if (m>0){
  285. resultJson.put("message", "解绑成功");
  286. resultJson.put("code", 200);
  287. resultJson.put("data","");
  288. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  289. return null;
  290. }
  291. resultJson.put("message", "解绑失败");
  292. resultJson.put("code", 205);
  293. resultJson.put("data","");
  294. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  295. return null;
  296. }
  297. /******************************商户绑定*******************************/
  298. public String get_user_ma(){
  299. JSONObject resultJson = new JSONObject();
  300. if (code==null){
  301. resultJson.put("message", "参数不能为空");
  302. resultJson.put("code", 205);
  303. resultJson.put("data","");
  304. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  305. return null;
  306. }
  307. JSONObject jsonObject = appService.getGCodeInfo(code);
  308. AdminManager admin = appService.queryMaByOpenid(jsonObject.get("openid").toString());
  309. if (admin==null){
  310. resultJson.put("message", "未绑定信息");
  311. resultJson.put("code", 205);
  312. resultJson.put("data","");
  313. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  314. return null;
  315. }
  316. resultJson.put("message", "返回成功");
  317. resultJson.put("code", 200);
  318. resultJson.put("data", admin);
  319. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  320. return null;
  321. }
  322. public String manage_code(){
  323. JSONObject resultJson = new JSONObject();
  324. if (code==null || admin_name==null || password==null){
  325. resultJson.put("message", "参数不能为空");
  326. resultJson.put("code", 205);
  327. resultJson.put("data","");
  328. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  329. return null;
  330. }
  331. AdminManager login = appService.login_ma(admin_name,password);
  332. if (login==null){
  333. resultJson.put("message", "账户或密码错误");
  334. resultJson.put("code", 205);
  335. resultJson.put("data","");
  336. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  337. return null;
  338. }
  339. if (login.getLevel().equals("1")){
  340. resultJson.put("message", "管理员无权限绑定");
  341. resultJson.put("code", 205);
  342. resultJson.put("data","");
  343. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  344. return null;
  345. }
  346. JSONObject jsonObject = appService.getGCodeInfo(code);
  347. AdminManager admin = appService.queryMaByNameAndOpenid(admin_name,jsonObject.get("openid").toString());
  348. if (admin!=null){
  349. resultJson.put("message", "该账户已绑定,请勿重复绑定");
  350. resultJson.put("code", 205);
  351. resultJson.put("data",admin);
  352. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  353. return null;
  354. }
  355. int m = appService.updateMaOpenid(jsonObject.get("openid").toString(),admin_name);
  356. if (m>0){
  357. admin = appService.queryMaByNameAndOpenid(admin_name,jsonObject.get("openid").toString());
  358. resultJson.put("message", "绑定成功");
  359. resultJson.put("code", 200);
  360. resultJson.put("data",admin);
  361. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  362. return null;
  363. }
  364. return null;
  365. }
  366. public String uncode_ma(){
  367. JSONObject resultJson = new JSONObject();
  368. if (code==null || admin_name==null || password==null){
  369. resultJson.put("message", "参数不能为空");
  370. resultJson.put("code", 205);
  371. resultJson.put("data","");
  372. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  373. return null;
  374. }
  375. AdminManager login = appService.login_ma(admin_name,password);
  376. if (login==null){
  377. resultJson.put("message", "账户或密码错误");
  378. resultJson.put("code", 205);
  379. resultJson.put("data","");
  380. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  381. return null;
  382. }
  383. JSONObject jsonObject = appService.getGCodeInfo(code);
  384. AdminManager admin = appService.queryMaByNameAndOpenid(admin_name,jsonObject.get("openid").toString());
  385. if (admin==null){
  386. resultJson.put("message", "输入信息与当前绑定账户不匹配");
  387. resultJson.put("code", 205);
  388. resultJson.put("data","");
  389. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  390. return null;
  391. }
  392. int m = appService.updateMaOpenidNull(jsonObject.get("openid").toString());
  393. if (m>0){
  394. resultJson.put("message", "解绑成功");
  395. resultJson.put("code", 200);
  396. resultJson.put("data","");
  397. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  398. return null;
  399. }
  400. resultJson.put("message", "解绑失败");
  401. resultJson.put("code", 205);
  402. resultJson.put("data","");
  403. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  404. return null;
  405. }
  406. /**=============================新闻资讯==============================**/
  407. public String autoInsertNews() throws Exception {
  408. int total = Get_airticle.getTotal();
  409. int rows = 10;
  410. int page = total % rows == 0 ? (total / rows)
  411. : (total / rows) + 1;
  412. for (int k = 0; k < page; k++) {
  413. List<Item_content> litem = appService.getNews(k,rows);
  414. for (int i = 0; i < litem.size(); i++) {
  415. Item_content ic = litem.get(i);
  416. Content content = ic.getContent();
  417. List<News_content> news_item = content.getNews_item();
  418. for (int j = 0; j < news_item.size(); j++) {
  419. News news = appService.queryByTit(news_item.get(j).getTitle());
  420. if (news==null){
  421. System.out.println("插入标题:"+news_item.get(j).getTitle());
  422. News nw = new News();
  423. nw.setTitle(news_item.get(j).getTitle());
  424. nw.setAuthor(news_item.get(j).getAuthor());
  425. nw.setContent(news_item.get(j).getContent());
  426. nw.setDigest(news_item.get(j).getDigest());
  427. nw.setContent_source_url(news_item.get(j).getContent_source_url());
  428. nw.setUpdate_time(TimeExchange.getTime());
  429. appService.insertNews(nw);
  430. }
  431. }
  432. }
  433. }
  434. return null;
  435. }
  436. public String newlist() {
  437. JSONObject resultJson = new JSONObject();
  438. StringBuilder s1 = new StringBuilder("");
  439. if (title!=null){
  440. s1.append(" and title like '%").append(this.title).append("%' ");
  441. }
  442. int total = appService.queryNewTotal(s1.toString());// 查询表中的总记录数
  443. List<News> listPage = appService.queryNewPage(page, rows,s1.toString());// 查询分页
  444. if (listPage == null) {
  445. resultJson.put("rows", "");
  446. resultJson.put("total", 0);
  447. } else {
  448. resultJson.put("code", 200);
  449. resultJson.put("rows", listPage);
  450. // int total = listAll.size();
  451. resultJson.put("total", total);// 总记录数
  452. int totalPage = total % rows == 0 ? (total / rows)
  453. : (total / rows) + 1;// 总页数
  454. resultJson.put("totalPage", totalPage);
  455. resultJson.put("currentPage", page);// 当前页
  456. resultJson.put("numPerPage", rows);// 每页数
  457. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  458. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  459. resultJson.put("hasPreviousPage", true);// 有上一页
  460. resultJson.put("hasNextPage", true);// 有下一页
  461. resultJson.put("firstPage", true);// 首页
  462. resultJson.put("lastPage", true);// 尾页
  463. }
  464. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  465. resultJson.toString());
  466. return null;
  467. }
  468. /** ==================================周边================================== **/
  469. public String insertArounds() {
  470. JSONObject resultjson = new JSONObject();
  471. Gson gson = new Gson();
  472. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  473. System.out.println(json);
  474. if (json == null) {
  475. resultjson.put("message", "请传入参数");
  476. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  477. return null;
  478. }
  479. Arounds arounds = null;
  480. try {
  481. arounds = gson.fromJson(json.toString(), new TypeToken<Arounds>() {}.getType());
  482. if (arounds == null) {
  483. resultjson.put("message", "数据为空");
  484. resultjson.put("code", 500);
  485. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  486. return null;
  487. }
  488. if (arounds.getRtype()==null || arounds.getRname()==null || arounds.getRtown()==null || arounds.getRadress()==null || arounds.getRphone()==null || arounds.getDetail()==null || arounds.getFirst_img()==null || arounds.getShow_video()==null || arounds.getDetail_img()==null){
  489. resultjson.put("message", "各参数不能为空");
  490. resultjson.put("code", 500);
  491. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  492. return null;
  493. }
  494. Arounds listc = appService.queryAroundByName(arounds.getRname());
  495. if (listc != null) {
  496. resultjson.put("message", "该周边已存在");
  497. resultjson.put("code", 500);
  498. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  499. return null;
  500. }
  501. arounds.setCnum(0);
  502. int m = appService.insertRound(arounds);
  503. if (m > 0) {
  504. resultjson.put("message", "添加成功");
  505. resultjson.put("code", 200);
  506. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  507. return null;
  508. } else {
  509. resultjson.put("message", "添加失败");
  510. resultjson.put("code", 502);
  511. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  512. return null;
  513. }
  514. } catch (Exception e) {
  515. e.printStackTrace();
  516. }
  517. resultjson.put("message", "未知异常");
  518. resultjson.put("code", 205);
  519. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  520. return null;
  521. }
  522. public String updateArounds() {
  523. JSONObject resultjson = new JSONObject();
  524. Gson gson = new Gson();
  525. JSONObject json = GetHttpParam.getHttpParam(request);
  526. System.out.println(json);
  527. if (json == null) {
  528. resultjson.put("message", "请传入参数");
  529. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  530. return null;
  531. }
  532. Arounds arounds = null;
  533. try {
  534. arounds = gson.fromJson(json.toString(), new TypeToken<Arounds>() {}.getType());
  535. if (arounds == null) {
  536. resultjson.put("message", "数据为空");
  537. resultjson.put("code", 500);
  538. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  539. return null;
  540. }
  541. if (arounds.getId()==null || arounds.getRtype()==null || arounds.getRname()==null || arounds.getRtown()==null || arounds.getRadress()==null || arounds.getRphone()==null || arounds.getDetail()==null || arounds.getFirst_img()==null || arounds.getShow_video()==null || arounds.getDetail_img()==null){
  542. resultjson.put("message", "各参数不能为空");
  543. resultjson.put("code", 500);
  544. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  545. return null;
  546. }
  547. Arounds listy = appService.queryAroundById(arounds.getId());
  548. if (listy==null){
  549. resultjson.put("message", "该条数据已删除");
  550. resultjson.put("code", 500);
  551. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  552. return null;
  553. }
  554. Arounds listc = appService.queryAroundByName(arounds.getRname());
  555. if (listc!=null && !Objects.equals(listc.getId(), arounds.getId())){
  556. resultjson.put("message", "周边已存在");
  557. resultjson.put("code", 500);
  558. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  559. return null;
  560. }
  561. int m = appService.updateRoundById(arounds);
  562. if (m > 0) {
  563. resultjson.put("message", "修改成功");
  564. resultjson.put("code", 200);
  565. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  566. return null;
  567. } else {
  568. resultjson.put("message", "修改失败");
  569. resultjson.put("code", 502);
  570. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  571. return null;
  572. }
  573. } catch (Exception e) {
  574. e.printStackTrace();
  575. }
  576. resultjson.put("message", "未知异常");
  577. resultjson.put("code", 205);
  578. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  579. return null;
  580. }
  581. public String delAround() {
  582. JSONObject resultjson = new JSONObject();
  583. if (id == null) {
  584. resultjson.put("message", "请传入id");
  585. resultjson.put("code", 500);
  586. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  587. return null;
  588. }
  589. Arounds arounds = appService.queryAroundById(id);
  590. if (arounds==null){
  591. resultjson.put("message", "该周边已删除");
  592. resultjson.put("code", 500);
  593. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  594. return null;
  595. }
  596. List<Around_product> aps = appService.queryAP(id, "");
  597. if (aps!=null){
  598. resultjson.put("message", "存在已关联产品不可删除");
  599. resultjson.put("code", 500);
  600. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  601. return null;
  602. }
  603. int m = appService.delAround(id);
  604. if (m > 0) {
  605. resultjson.put("message", "删除成功");
  606. resultjson.put("code", 200);
  607. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  608. return null;
  609. }
  610. resultjson.put("message", "未知异常");
  611. resultjson.put("code", 205);
  612. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  613. return null;
  614. }
  615. public String listAround() {
  616. JSONObject resultJson = new JSONObject();
  617. StringBuilder s1 = new StringBuilder("");
  618. if (rtype!=null){
  619. s1.append(" and rtype = '").append(this.rtype).append("' ");
  620. }
  621. if (rtown!=null){
  622. s1.append(" and rtown = '").append(this.rtown).append("' ");
  623. }
  624. if (key!=null){
  625. s1.append(" and ( rname like '%").append(this.key)
  626. .append("%' or rphone like '%").append(this.key)
  627. .append("%' or radress like '%").append(this.key).append("%' ) ");
  628. }
  629. int total = appService.queryAroundTotal(s1.toString()); // 查询表中的总记录数
  630. List<Arounds> listPage = appService.queryAroundPage(s1.toString(),page,rows); // 查询分页
  631. if (listPage == null) {
  632. resultJson.put("rows", "");
  633. resultJson.put("total", 0);
  634. } else {
  635. resultJson.put("code", 200);
  636. resultJson.put("rows", listPage);
  637. // int total = listAll.size();
  638. resultJson.put("total", total);// 总记录数
  639. int totalPage = total % rows == 0 ? (total / rows)
  640. : (total / rows) + 1;// 总页数
  641. resultJson.put("totalPage", totalPage);
  642. resultJson.put("currentPage", page);// 当前页
  643. resultJson.put("numPerPage", rows);// 每页数
  644. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  645. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  646. resultJson.put("hasPreviousPage", true);// 有上一页
  647. resultJson.put("hasNextPage", true);// 有下一页
  648. resultJson.put("firstPage", true);// 首页
  649. resultJson.put("lastPage", true);// 尾页
  650. }
  651. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  652. resultJson.toString());
  653. return null;
  654. }
  655. /** =========================产品============================== **/
  656. public String insertAroundPd() {
  657. JSONObject resultjson = new JSONObject();
  658. Gson gson = new Gson();
  659. com.alibaba.fastjson.JSONObject json = GetHttpParam.getHttpParam(request);
  660. System.out.println(json);
  661. if (json == null) {
  662. resultjson.put("message", "请传入参数");
  663. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  664. return null;
  665. }
  666. Around_product around_product = null;
  667. try {
  668. around_product = gson.fromJson(json.toString(), new TypeToken<Around_product>() {}.getType());
  669. if (around_product == null) {
  670. resultjson.put("message", "数据为空");
  671. resultjson.put("code", 500);
  672. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  673. return null;
  674. }
  675. if (around_product.getAid()==null || around_product.getProduct_name()==null || around_product.getProduct_desc()==null || around_product.getPrice()==null){
  676. resultjson.put("message", "各参数不能为空");
  677. resultjson.put("code", 500);
  678. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  679. return null;
  680. }
  681. Around_product listc = appService.queryAPByName(around_product.getAid(),around_product.getProduct_name());
  682. if (listc != null) {
  683. resultjson.put("message", "该产品已存在");
  684. resultjson.put("code", 500);
  685. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  686. return null;
  687. }
  688. Arounds arounds = appService.queryAroundById(around_product.getAid());
  689. if (arounds==null){
  690. resultjson.put("message", "关联周边已删除");
  691. resultjson.put("code", 500);
  692. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  693. return null;
  694. }
  695. arounds.setCnum(arounds.getCnum()+1);
  696. int n = appService.updateRoundCountById(arounds);
  697. int m = appService.insertProduct(around_product);
  698. if (m > 0 || n > 0) {
  699. resultjson.put("message", "添加成功");
  700. resultjson.put("code", 200);
  701. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  702. return null;
  703. } else {
  704. resultjson.put("message", "添加失败");
  705. resultjson.put("code", 502);
  706. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  707. return null;
  708. }
  709. } catch (Exception e) {
  710. e.printStackTrace();
  711. }
  712. resultjson.put("message", "未知异常");
  713. resultjson.put("code", 205);
  714. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  715. return null;
  716. }
  717. public String updateAround_pd() {
  718. JSONObject resultjson = new JSONObject();
  719. Gson gson = new Gson();
  720. JSONObject json = GetHttpParam.getHttpParam(request);
  721. System.out.println(json);
  722. if (json == null) {
  723. resultjson.put("message", "请传入参数");
  724. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  725. return null;
  726. }
  727. Around_product around_product = null;
  728. try {
  729. around_product = gson.fromJson(json.toString(), new TypeToken<Around_product>() {}.getType());
  730. if (around_product == null) {
  731. resultjson.put("message", "数据为空");
  732. resultjson.put("code", 500);
  733. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  734. return null;
  735. }
  736. if (around_product.getProduct_name()==null || around_product.getProduct_desc()==null || around_product.getPrice()==null){
  737. resultjson.put("message", "各参数不能为空");
  738. resultjson.put("code", 500);
  739. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  740. return null;
  741. }
  742. Around_product listy = appService.queryAPById(around_product.getId());
  743. if (listy==null){
  744. resultjson.put("message", "该条数据已删除");
  745. resultjson.put("code", 500);
  746. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  747. return null;
  748. }
  749. Around_product listc = appService.queryAPByName(listy.getAid(), around_product.getProduct_name());
  750. if (listc!=null && !Objects.equals(listc.getId(), around_product.getId())){
  751. resultjson.put("message", "产品已存在");
  752. resultjson.put("code", 500);
  753. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  754. return null;
  755. }
  756. int m = appService.updateProductById(around_product);
  757. if (m > 0) {
  758. resultjson.put("message", "修改成功");
  759. resultjson.put("code", 200);
  760. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  761. return null;
  762. } else {
  763. resultjson.put("message", "修改失败");
  764. resultjson.put("code", 502);
  765. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  766. return null;
  767. }
  768. } catch (Exception e) {
  769. e.printStackTrace();
  770. }
  771. resultjson.put("message", "未知异常");
  772. resultjson.put("code", 205);
  773. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  774. return null;
  775. }
  776. public String delAround_pd() {
  777. JSONObject resultjson = new JSONObject();
  778. if (id == null) {
  779. resultjson.put("message", "请传入id");
  780. resultjson.put("code", 500);
  781. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  782. return null;
  783. }
  784. Around_product around_product = appService.queryAPById(id);
  785. if (around_product==null){
  786. resultjson.put("message", "该产品已删除");
  787. resultjson.put("code", 500);
  788. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  789. return null;
  790. }
  791. Arounds arounds = appService.queryAroundById(around_product.getAid());
  792. if (arounds==null){
  793. resultjson.put("message", "关联周边已删除");
  794. resultjson.put("code", 500);
  795. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  796. return null;
  797. }
  798. arounds.setCnum(Math.max(arounds.getCnum() - 1, 0));
  799. int n = appService.updateRoundCountById(arounds);
  800. int m = appService.delAroundProduct(id);
  801. if (m > 0 || n > 0) {
  802. resultjson.put("message", "删除成功");
  803. resultjson.put("code", 200);
  804. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  805. return null;
  806. }
  807. resultjson.put("message", "未知异常");
  808. resultjson.put("code", 205);
  809. ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
  810. return null;
  811. }
  812. public String listAround_pd() {
  813. JSONObject resultJson = new JSONObject();
  814. int total = appService.queryAPTotal(aid,""); // 查询表中的总记录数
  815. List<Around_product> listPage = appService.queryAPPage(aid,"",page,rows); // 查询分页
  816. if (listPage == null) {
  817. resultJson.put("rows", "");
  818. resultJson.put("total", 0);
  819. } else {
  820. resultJson.put("code", 200);
  821. resultJson.put("rows", listPage);
  822. // int total = listAll.size();
  823. resultJson.put("total", total);// 总记录数
  824. int totalPage = total % rows == 0 ? (total / rows)
  825. : (total / rows) + 1;// 总页数
  826. resultJson.put("totalPage", totalPage);
  827. resultJson.put("currentPage", page);// 当前页
  828. resultJson.put("numPerPage", rows);// 每页数
  829. resultJson.put("nextPage", totalPage - page == 0 ? page : page + 1);// 下一页
  830. resultJson.put("previousPage", page - 0 == 1 ? page : page - 1);// 上一页
  831. resultJson.put("hasPreviousPage", true);// 有上一页
  832. resultJson.put("hasNextPage", true);// 有下一页
  833. resultJson.put("firstPage", true);// 首页
  834. resultJson.put("lastPage", true);// 尾页
  835. }
  836. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  837. resultJson.toString());
  838. return null;
  839. }
  840. }