当前位置:   article > 正文

基于ssm在线零食商城java web在线购物网站源码_javaweb网上商城源码

javaweb网上商城源码

基于ssm在线零食商城java web在线购物网站源码405

开发工具:idea 或eclipse
 数据库mysql5.7+
 数据库链接工具:navcat,小海豚等

  1. package com.controller;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ArrayList;
  7. import java.util.Calendar;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. import javax.servlet.http.HttpServletRequest;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.json.JSONObject;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.util.ResourceUtils;
  19. import org.springframework.web.bind.annotation.PathVariable;
  20. import org.springframework.web.bind.annotation.RequestBody;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import org.springframework.web.bind.annotation.RequestParam;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import com.annotation.IgnoreAuth;
  25. import com.baidu.aip.face.AipFace;
  26. import com.baidu.aip.face.MatchRequest;
  27. import com.baidu.aip.util.Base64Util;
  28. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  29. import com.baomidou.mybatisplus.mapper.Wrapper;
  30. import com.entity.ConfigEntity;
  31. import com.service.CommonService;
  32. import com.service.ConfigService;
  33. import com.utils.BaiduUtil;
  34. import com.utils.FileUtil;
  35. import com.utils.R;
  36. /**
  37. * 閫氱敤鎺ュ彛
  38. */
  39. @RestController
  40. public class CommonController{
  41. private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
  42. @Autowired
  43. private CommonService commonService;
  44. @Autowired
  45. private ConfigService configService;
  46. private static AipFace client = null;
  47. private static String BAIDU_DITU_AK = null;
  48. @RequestMapping("/location")
  49. public R location(String lng,String lat) {
  50. if(BAIDU_DITU_AK==null) {
  51. BAIDU_DITU_AK = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "baidu_ditu_ak")).getValue();
  52. if(BAIDU_DITU_AK==null) {
  53. return R.error("璇峰湪閰嶇疆绠$悊涓纭厤缃産aidu_ditu_ak");
  54. }
  55. }
  56. Map<String, String> map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat);
  57. return R.ok().put("data", map);
  58. }
  59. /**
  60. * 浜鸿劯姣斿
  61. *
  62. * @param face1 浜鸿劯1
  63. * @param face2 浜鸿劯2
  64. * @return
  65. */
  66. @RequestMapping("/matchFace")
  67. public R matchFace(String face1, String face2, HttpServletRequest request) {
  68. if(client==null) {
  69. /*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
  70. String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue();
  71. String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue();
  72. String token = BaiduUtil.getAuth(APIKey, SecretKey);
  73. if(token==null) {
  74. return R.error("璇峰湪閰嶇疆绠$悊涓纭厤缃瓵PIKey鍜孲ecretKey");
  75. }
  76. client = new AipFace(null, APIKey, SecretKey);
  77. client.setConnectionTimeoutInMillis(2000);
  78. client.setSocketTimeoutInMillis(60000);
  79. }
  80. JSONObject res = null;
  81. try {
  82. File file1 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face1);
  83. File file2 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face2);
  84. String img1 = Base64Util.encode(FileUtil.FileToByte(file1));
  85. String img2 = Base64Util.encode(FileUtil.FileToByte(file2));
  86. MatchRequest req1 = new MatchRequest(img1, "BASE64");
  87. MatchRequest req2 = new MatchRequest(img2, "BASE64");
  88. ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
  89. requests.add(req1);
  90. requests.add(req2);
  91. res = client.match(requests);
  92. System.out.println(res.get("result"));
  93. } catch (FileNotFoundException e) {
  94. e.printStackTrace();
  95. return R.error("鏂囦欢涓嶅瓨鍦�");
  96. } catch (IOException e) {
  97. e.printStackTrace();
  98. }
  99. return R.ok().put("data", com.alibaba.fastjson.JSONObject.parse(res.get("result").toString()));
  100. }
  101. /**
  102. * 鑾峰彇table琛ㄤ腑鐨刢olumn鍒楄〃(鑱斿姩鎺ュ彛)
  103. * @return
  104. */
  105. @RequestMapping("/option/{tableName}/{columnName}")
  106. @IgnoreAuth
  107. public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) {
  108. Map<String, Object> params = new HashMap<String, Object>();
  109. params.put("table", tableName);
  110. params.put("column", columnName);
  111. if(StringUtils.isNotBlank(level)) {
  112. params.put("level", level);
  113. }
  114. if(StringUtils.isNotBlank(parent)) {
  115. params.put("parent", parent);
  116. }
  117. List<String> data = commonService.getOption(params);
  118. return R.ok().put("data", data);
  119. }
  120. /**
  121. * 鏍规嵁table涓殑column鑾峰彇鍗曟潯璁板綍
  122. * @return
  123. */
  124. @RequestMapping("/follow/{tableName}/{columnName}")
  125. @IgnoreAuth
  126. public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) {
  127. Map<String, Object> params = new HashMap<String, Object>();
  128. params.put("table", tableName);
  129. params.put("column", columnName);
  130. params.put("columnValue", columnValue);
  131. Map<String, Object> result = commonService.getFollowByOption(params);
  132. return R.ok().put("data", result);
  133. }
  134. /**
  135. * 淇敼table琛ㄧ殑sfsh鐘舵��
  136. * @param map
  137. * @return
  138. */
  139. @RequestMapping("/sh/{tableName}")
  140. public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) {
  141. map.put("table", tableName);
  142. commonService.sh(map);
  143. return R.ok();
  144. }
  145. /**
  146. * 鑾峰彇闇�瑕佹彁閱掔殑璁板綍鏁�
  147. * @param tableName
  148. * @param columnName
  149. * @param type 1:鏁板瓧 2:鏃ユ湡
  150. * @param map
  151. * @return
  152. */
  153. @RequestMapping("/remind/{tableName}/{columnName}/{type}")
  154. @IgnoreAuth
  155. public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
  156. @PathVariable("type") String type,@RequestParam Map<String, Object> map) {
  157. map.put("table", tableName);
  158. map.put("column", columnName);
  159. map.put("type", type);
  160. if(type.equals("2")) {
  161. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  162. Calendar c = Calendar.getInstance();
  163. Date remindStartDate = null;
  164. Date remindEndDate = null;
  165. if(map.get("remindstart")!=null) {
  166. Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
  167. c.setTime(new Date());
  168. c.add(Calendar.DAY_OF_MONTH,remindStart);
  169. remindStartDate = c.getTime();
  170. map.put("remindstart", sdf.format(remindStartDate));
  171. }
  172. if(map.get("remindend")!=null) {
  173. Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
  174. c.setTime(new Date());
  175. c.add(Calendar.DAY_OF_MONTH,remindEnd);
  176. remindEndDate = c.getTime();
  177. map.put("remindend", sdf.format(remindEndDate));
  178. }
  179. }
  180. int count = commonService.remindCount(map);
  181. return R.ok().put("count", count);
  182. }
  183. /**
  184. * 鍦栬〃缁熻
  185. */
  186. @IgnoreAuth
  187. @RequestMapping("/group/{tableName}")
  188. public R group1(@PathVariable("tableName") String tableName, @RequestParam Map<String,Object> params) {
  189. params.put("table1", tableName);
  190. List<Map<String, Object>> result = commonService.chartBoth(params);
  191. return R.ok().put("data", result);
  192. }
  193. /**
  194. * 鍗曞垪姹傚拰
  195. */
  196. @RequestMapping("/cal/{tableName}/{columnName}")
  197. @IgnoreAuth
  198. public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
  199. Map<String, Object> params = new HashMap<String, Object>();
  200. params.put("table", tableName);
  201. params.put("column", columnName);
  202. Map<String, Object> result = commonService.selectCal(params);
  203. return R.ok().put("data", result);
  204. }
  205. /**
  206. * 鍒嗙粍缁熻
  207. */
  208. @RequestMapping("/group/{tableName}/{columnName}")
  209. @IgnoreAuth
  210. public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
  211. Map<String, Object> params = new HashMap<String, Object>();
  212. params.put("table", tableName);
  213. params.put("column", columnName);
  214. List<Map<String, Object>> result = commonService.selectGroup(params);
  215. return R.ok().put("data", result);
  216. }
  217. /**
  218. * 锛堟寜鍊肩粺璁★級
  219. */
  220. @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
  221. @IgnoreAuth
  222. public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) {
  223. Map<String, Object> params = new HashMap<String, Object>();
  224. params.put("table", tableName);
  225. params.put("xColumn", xColumnName);
  226. params.put("yColumn", yColumnName);
  227. List<Map<String, Object>> result = commonService.selectValue(params);
  228. return R.ok().put("data", result);
  229. }
  230. /**
  231. * 涓嬮潰涓烘柊鍔犵殑
  232. *
  233. *
  234. *
  235. */
  236. /**
  237. * 鏌ヨ瀛楀吀琛ㄧ殑鍒嗙粍姹傚拰
  238. * @param tableName 琛ㄥ悕
  239. * @param groupColumn 鍒嗙粍瀛楁
  240. * @param sumCloum 缁熻瀛楁
  241. * @return
  242. */
  243. @RequestMapping("/sum/group/{tableName}/{groupColumn}/{sumCloum}")
  244. @IgnoreAuth
  245. public R newSelectGroupSum(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("sumCloum") String sumCloum) {
  246. logger.debug("newSelectGroupSum:,,Controller:{},,tableName:{},groupColumn:{},sumCloum:{}",this.getClass().getName(),tableName,groupColumn,sumCloum);
  247. Map<String, Object> params = new HashMap<String, Object>();
  248. params.put("tableName", tableName);
  249. params.put("groupColumn", groupColumn);
  250. params.put("sumColumn", sumCloum);
  251. List<Map<String, Object>> result = commonService.newSelectGroupSum(params);
  252. return R.ok().put("data", result);
  253. }
  254. /**
  255. * 鏌ヨ瀛楀吀琛ㄧ殑鍒嗙粍缁熻鎬绘潯鏁�
  256. * @param tableName 琛ㄥ悕
  257. * @param groupColumn 鍒嗙粍瀛楁
  258. * @return
  259. */
  260. @RequestMapping("/count/group/{tableName}/{groupColumn}")
  261. @IgnoreAuth
  262. public R newSelectGroupCount(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn) {
  263. logger.debug("newSelectGroupCount:,,Controller:{},,tableName:{},groupColumn:{}",this.getClass().getName(),tableName,groupColumn);
  264. Map<String, Object> params = new HashMap<String, Object>();
  265. params.put("tableName", tableName);
  266. params.put("groupColumn", groupColumn);
  267. List<Map<String, Object>> result = commonService.newSelectGroupCount(params);
  268. return R.ok().put("data", result);
  269. }
  270. /**
  271. * 褰撳墠琛ㄧ殑鏃ユ湡鍒嗙粍姹傚拰
  272. * @param tableName 琛ㄥ悕
  273. * @param groupColumn 鍒嗙粍瀛楁
  274. * @param sumCloum 缁熻瀛楁
  275. * @param dateFormatType 鏃ユ湡鏍煎紡鍖栫被鍨� 1:骞� 2:鏈� 3:鏃�
  276. * @return
  277. */
  278. @RequestMapping("/sum/group/{tableName}/{groupColumn}/{sumCloum}/{dateFormatType}")
  279. @IgnoreAuth
  280. public R newSelectDateGroupSum(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("sumCloum") String sumCloum, @PathVariable("dateFormatType") String dateFormatType) {
  281. logger.debug("newSelectDateGroupSum:,,Controller:{},,tableName:{},groupColumn:{},sumCloum:{},dateFormatType:{}",this.getClass().getName(),tableName,groupColumn,sumCloum,dateFormatType);
  282. Map<String, Object> params = new HashMap<String, Object>();
  283. params.put("tableName", tableName);
  284. params.put("groupColumn", groupColumn);
  285. params.put("sumColumn", sumCloum);
  286. if("1".equals(dateFormatType)){
  287. params.put("dateFormat", "%Y");
  288. }else if("2".equals(dateFormatType)){
  289. params.put("dateFormat", "%Y-%m");
  290. }else if("3".equals(dateFormatType)){
  291. params.put("dateFormat", "%Y-%m-%d");
  292. }else{
  293. R.error("鏃ユ湡鏍煎紡鍖栦笉姝g‘");
  294. }
  295. List<Map<String, Object>> result = commonService.newSelectDateGroupSum(params);
  296. return R.ok().put("data", result);
  297. }
  298. /**
  299. *
  300. * 鏌ヨ瀛楀吀琛ㄧ殑鍒嗙粍缁熻鎬绘潯鏁�
  301. * @param tableName 琛ㄥ悕
  302. * @param groupColumn 鍒嗙粍瀛楁
  303. * @param dateFormatType 鏃ユ湡鏍煎紡鍖栫被鍨� 1:骞� 2:鏈� 3:鏃�
  304. * @return
  305. */
  306. @RequestMapping("/count/group/{tableName}/{groupColumn}/{dateFormatType}")
  307. @IgnoreAuth
  308. public R newSelectDateGroupCount(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("dateFormatType") String dateFormatType) {
  309. logger.debug("newSelectDateGroupCount:,,Controller:{},,tableName:{},groupColumn:{},dateFormatType:{}",this.getClass().getName(),tableName,groupColumn,dateFormatType);
  310. Map<String, Object> params = new HashMap<String, Object>();
  311. params.put("tableName", tableName);
  312. params.put("groupColumn", groupColumn);
  313. if("1".equals(dateFormatType)){
  314. params.put("dateFormat", "%Y");
  315. }else if("2".equals(dateFormatType)){
  316. params.put("dateFormat", "%Y-%m");
  317. }else if("3".equals(dateFormatType)){
  318. params.put("dateFormat", "%Y-%m-%d");
  319. }else{
  320. R.error("鏃ユ湡鏍煎紡鍖栫被鍨嬩笉姝g‘");
  321. }
  322. List<Map<String, Object>> result = commonService.newSelectDateGroupCount(params);
  323. return R.ok().put("data", result);
  324. }
  325. /**
  326. * 瀛楁鍔犳暟瀛�
  327. * @param tableName 琛ㄥ悕
  328. * @param id id
  329. * @param column 瀛楁
  330. * @param number 鏁伴噺
  331. * @return
  332. */
  333. @RequestMapping("/plus/{tableName}/{id}/{column}/{number}")
  334. public R plusCloumNumber(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("number") String number) {
  335. logger.debug("plusCloumNumber:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,number);
  336. Map<String, Object> params = new HashMap<String, Object>();
  337. params.put("tableName", tableName);
  338. params.put("id", id);
  339. params.put("column", column);
  340. params.put("number", number);
  341. int i = commonService.plusCloumNumber(params);
  342. if(i>0){
  343. return R.ok();
  344. }
  345. return R.error("娣诲姞澶辫触");
  346. }
  347. /**
  348. * 瀛楁鍑忔暟瀛�
  349. * @param tableName
  350. * @param id
  351. * @param column
  352. * @param number
  353. * @return
  354. */
  355. @RequestMapping("/reduce/{tableName}/{id}/{column}/{number}")
  356. public R reduceCloumNumber(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("number") String number) {
  357. logger.debug("reduceCloumNumber:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,number);
  358. Map<String, Object> params = new HashMap<String, Object>();
  359. params.put("tableName", tableName);
  360. params.put("id", id);
  361. params.put("column", column);
  362. params.put("number", number);
  363. int i = commonService.reduceCloumNumber(params);
  364. if(i>0){
  365. return R.ok();
  366. }
  367. return R.error("娣诲姞澶辫触");
  368. }
  369. @RequestMapping("/update/{tableName}/{id}/{column}/{value}")
  370. public R updateCloumValue(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("value") String value) {
  371. logger.debug("updateCloumValue:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,value);
  372. Map<String, Object> params = new HashMap<String, Object>();
  373. params.put("tableName", tableName);
  374. params.put("id", id);
  375. params.put("column", column);
  376. params.put("value", value);
  377. int i = commonService.updateCloumValue(params);
  378. if(i>0){
  379. return R.ok();
  380. }
  381. return R.error("娣诲姞澶辫触");
  382. }
  383. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/816974
推荐阅读
相关标签
  

闽ICP备14008679号