赞
踩
基于ssm在线零食商城java web在线购物网站源码405
开发工具:idea 或eclipse
数据库mysql5.7+
数据库链接工具:navcat,小海豚等
- package com.controller;
-
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import javax.servlet.http.HttpServletRequest;
-
- import org.apache.commons.lang3.StringUtils;
- import org.json.JSONObject;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.util.ResourceUtils;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
-
- import com.annotation.IgnoreAuth;
- import com.baidu.aip.face.AipFace;
- import com.baidu.aip.face.MatchRequest;
- import com.baidu.aip.util.Base64Util;
- import com.baomidou.mybatisplus.mapper.EntityWrapper;
- import com.baomidou.mybatisplus.mapper.Wrapper;
- import com.entity.ConfigEntity;
- import com.service.CommonService;
- import com.service.ConfigService;
- import com.utils.BaiduUtil;
- import com.utils.FileUtil;
- import com.utils.R;
-
- /**
- * 閫氱敤鎺ュ彛
- */
- @RestController
- public class CommonController{
- private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
- @Autowired
- private CommonService commonService;
-
- @Autowired
- private ConfigService configService;
-
- private static AipFace client = null;
-
- private static String BAIDU_DITU_AK = null;
-
- @RequestMapping("/location")
- public R location(String lng,String lat) {
- if(BAIDU_DITU_AK==null) {
- BAIDU_DITU_AK = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "baidu_ditu_ak")).getValue();
- if(BAIDU_DITU_AK==null) {
- return R.error("璇峰湪閰嶇疆绠$悊涓纭厤缃産aidu_ditu_ak");
- }
- }
- Map<String, String> map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat);
- return R.ok().put("data", map);
- }
-
- /**
- * 浜鸿劯姣斿
- *
- * @param face1 浜鸿劯1
- * @param face2 浜鸿劯2
- * @return
- */
- @RequestMapping("/matchFace")
- public R matchFace(String face1, String face2, HttpServletRequest request) {
- if(client==null) {
- /*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
- String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue();
- String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue();
- String token = BaiduUtil.getAuth(APIKey, SecretKey);
- if(token==null) {
- return R.error("璇峰湪閰嶇疆绠$悊涓纭厤缃瓵PIKey鍜孲ecretKey");
- }
- client = new AipFace(null, APIKey, SecretKey);
- client.setConnectionTimeoutInMillis(2000);
- client.setSocketTimeoutInMillis(60000);
- }
- JSONObject res = null;
- try {
- File file1 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face1);
- File file2 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face2);
- String img1 = Base64Util.encode(FileUtil.FileToByte(file1));
- String img2 = Base64Util.encode(FileUtil.FileToByte(file2));
- MatchRequest req1 = new MatchRequest(img1, "BASE64");
- MatchRequest req2 = new MatchRequest(img2, "BASE64");
- ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
- requests.add(req1);
- requests.add(req2);
- res = client.match(requests);
- System.out.println(res.get("result"));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- return R.error("鏂囦欢涓嶅瓨鍦�");
- } catch (IOException e) {
- e.printStackTrace();
- }
- return R.ok().put("data", com.alibaba.fastjson.JSONObject.parse(res.get("result").toString()));
- }
-
- /**
- * 鑾峰彇table琛ㄤ腑鐨刢olumn鍒楄〃(鑱斿姩鎺ュ彛)
- * @return
- */
- @RequestMapping("/option/{tableName}/{columnName}")
- @IgnoreAuth
- public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("table", tableName);
- params.put("column", columnName);
- if(StringUtils.isNotBlank(level)) {
- params.put("level", level);
- }
- if(StringUtils.isNotBlank(parent)) {
- params.put("parent", parent);
- }
- List<String> data = commonService.getOption(params);
- return R.ok().put("data", data);
- }
-
- /**
- * 鏍规嵁table涓殑column鑾峰彇鍗曟潯璁板綍
- * @return
- */
- @RequestMapping("/follow/{tableName}/{columnName}")
- @IgnoreAuth
- public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("table", tableName);
- params.put("column", columnName);
- params.put("columnValue", columnValue);
- Map<String, Object> result = commonService.getFollowByOption(params);
- return R.ok().put("data", result);
- }
-
- /**
- * 淇敼table琛ㄧ殑sfsh鐘舵��
- * @param map
- * @return
- */
- @RequestMapping("/sh/{tableName}")
- public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) {
- map.put("table", tableName);
- commonService.sh(map);
- return R.ok();
- }
-
- /**
- * 鑾峰彇闇�瑕佹彁閱掔殑璁板綍鏁�
- * @param tableName
- * @param columnName
- * @param type 1:鏁板瓧 2:鏃ユ湡
- * @param map
- * @return
- */
- @RequestMapping("/remind/{tableName}/{columnName}/{type}")
- @IgnoreAuth
- public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
- @PathVariable("type") String type,@RequestParam Map<String, Object> map) {
- map.put("table", tableName);
- map.put("column", columnName);
- map.put("type", type);
-
- if(type.equals("2")) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- Calendar c = Calendar.getInstance();
- Date remindStartDate = null;
- Date remindEndDate = null;
- if(map.get("remindstart")!=null) {
- Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
- c.setTime(new Date());
- c.add(Calendar.DAY_OF_MONTH,remindStart);
- remindStartDate = c.getTime();
- map.put("remindstart", sdf.format(remindStartDate));
- }
- if(map.get("remindend")!=null) {
- Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
- c.setTime(new Date());
- c.add(Calendar.DAY_OF_MONTH,remindEnd);
- remindEndDate = c.getTime();
- map.put("remindend", sdf.format(remindEndDate));
- }
- }
-
- int count = commonService.remindCount(map);
- return R.ok().put("count", count);
- }
-
- /**
- * 鍦栬〃缁熻
- */
- @IgnoreAuth
- @RequestMapping("/group/{tableName}")
- public R group1(@PathVariable("tableName") String tableName, @RequestParam Map<String,Object> params) {
- params.put("table1", tableName);
- List<Map<String, Object>> result = commonService.chartBoth(params);
- return R.ok().put("data", result);
- }
-
-
- /**
- * 鍗曞垪姹傚拰
- */
- @RequestMapping("/cal/{tableName}/{columnName}")
- @IgnoreAuth
- public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("table", tableName);
- params.put("column", columnName);
- Map<String, Object> result = commonService.selectCal(params);
- return R.ok().put("data", result);
- }
-
- /**
- * 鍒嗙粍缁熻
- */
- @RequestMapping("/group/{tableName}/{columnName}")
- @IgnoreAuth
- public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("table", tableName);
- params.put("column", columnName);
- List<Map<String, Object>> result = commonService.selectGroup(params);
- return R.ok().put("data", result);
- }
-
- /**
- * 锛堟寜鍊肩粺璁★級
- */
- @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
- @IgnoreAuth
- public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("table", tableName);
- params.put("xColumn", xColumnName);
- params.put("yColumn", yColumnName);
- List<Map<String, Object>> result = commonService.selectValue(params);
- return R.ok().put("data", result);
- }
-
-
- /**
- * 涓嬮潰涓烘柊鍔犵殑
- *
- *
- *
- */
-
- /**
- * 鏌ヨ瀛楀吀琛ㄧ殑鍒嗙粍姹傚拰
- * @param tableName 琛ㄥ悕
- * @param groupColumn 鍒嗙粍瀛楁
- * @param sumCloum 缁熻瀛楁
- * @return
- */
- @RequestMapping("/sum/group/{tableName}/{groupColumn}/{sumCloum}")
- @IgnoreAuth
- public R newSelectGroupSum(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("sumCloum") String sumCloum) {
- logger.debug("newSelectGroupSum:,,Controller:{},,tableName:{},groupColumn:{},sumCloum:{}",this.getClass().getName(),tableName,groupColumn,sumCloum);
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("tableName", tableName);
- params.put("groupColumn", groupColumn);
- params.put("sumColumn", sumCloum);
- List<Map<String, Object>> result = commonService.newSelectGroupSum(params);
- return R.ok().put("data", result);
- }
-
- /**
- * 鏌ヨ瀛楀吀琛ㄧ殑鍒嗙粍缁熻鎬绘潯鏁�
- * @param tableName 琛ㄥ悕
- * @param groupColumn 鍒嗙粍瀛楁
- * @return
- */
- @RequestMapping("/count/group/{tableName}/{groupColumn}")
- @IgnoreAuth
- public R newSelectGroupCount(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn) {
- logger.debug("newSelectGroupCount:,,Controller:{},,tableName:{},groupColumn:{}",this.getClass().getName(),tableName,groupColumn);
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("tableName", tableName);
- params.put("groupColumn", groupColumn);
- List<Map<String, Object>> result = commonService.newSelectGroupCount(params);
- return R.ok().put("data", result);
- }
-
-
- /**
- * 褰撳墠琛ㄧ殑鏃ユ湡鍒嗙粍姹傚拰
- * @param tableName 琛ㄥ悕
- * @param groupColumn 鍒嗙粍瀛楁
- * @param sumCloum 缁熻瀛楁
- * @param dateFormatType 鏃ユ湡鏍煎紡鍖栫被鍨� 1:骞� 2:鏈� 3:鏃�
- * @return
- */
- @RequestMapping("/sum/group/{tableName}/{groupColumn}/{sumCloum}/{dateFormatType}")
- @IgnoreAuth
- public R newSelectDateGroupSum(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("sumCloum") String sumCloum, @PathVariable("dateFormatType") String dateFormatType) {
- logger.debug("newSelectDateGroupSum:,,Controller:{},,tableName:{},groupColumn:{},sumCloum:{},dateFormatType:{}",this.getClass().getName(),tableName,groupColumn,sumCloum,dateFormatType);
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("tableName", tableName);
- params.put("groupColumn", groupColumn);
- params.put("sumColumn", sumCloum);
- if("1".equals(dateFormatType)){
- params.put("dateFormat", "%Y");
- }else if("2".equals(dateFormatType)){
- params.put("dateFormat", "%Y-%m");
- }else if("3".equals(dateFormatType)){
- params.put("dateFormat", "%Y-%m-%d");
- }else{
- R.error("鏃ユ湡鏍煎紡鍖栦笉姝g‘");
- }
- List<Map<String, Object>> result = commonService.newSelectDateGroupSum(params);
- return R.ok().put("data", result);
- }
-
- /**
- *
- * 鏌ヨ瀛楀吀琛ㄧ殑鍒嗙粍缁熻鎬绘潯鏁�
- * @param tableName 琛ㄥ悕
- * @param groupColumn 鍒嗙粍瀛楁
- * @param dateFormatType 鏃ユ湡鏍煎紡鍖栫被鍨� 1:骞� 2:鏈� 3:鏃�
- * @return
- */
- @RequestMapping("/count/group/{tableName}/{groupColumn}/{dateFormatType}")
- @IgnoreAuth
- public R newSelectDateGroupCount(@PathVariable("tableName") String tableName, @PathVariable("groupColumn") String groupColumn, @PathVariable("dateFormatType") String dateFormatType) {
- logger.debug("newSelectDateGroupCount:,,Controller:{},,tableName:{},groupColumn:{},dateFormatType:{}",this.getClass().getName(),tableName,groupColumn,dateFormatType);
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("tableName", tableName);
- params.put("groupColumn", groupColumn);
- if("1".equals(dateFormatType)){
- params.put("dateFormat", "%Y");
- }else if("2".equals(dateFormatType)){
- params.put("dateFormat", "%Y-%m");
- }else if("3".equals(dateFormatType)){
- params.put("dateFormat", "%Y-%m-%d");
- }else{
- R.error("鏃ユ湡鏍煎紡鍖栫被鍨嬩笉姝g‘");
- }
- List<Map<String, Object>> result = commonService.newSelectDateGroupCount(params);
- return R.ok().put("data", result);
- }
-
- /**
- * 瀛楁鍔犳暟瀛�
- * @param tableName 琛ㄥ悕
- * @param id id
- * @param column 瀛楁
- * @param number 鏁伴噺
- * @return
- */
- @RequestMapping("/plus/{tableName}/{id}/{column}/{number}")
- public R plusCloumNumber(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("number") String number) {
- logger.debug("plusCloumNumber:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,number);
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("tableName", tableName);
- params.put("id", id);
- params.put("column", column);
- params.put("number", number);
- int i = commonService.plusCloumNumber(params);
- if(i>0){
- return R.ok();
- }
- return R.error("娣诲姞澶辫触");
- }
-
- /**
- * 瀛楁鍑忔暟瀛�
- * @param tableName
- * @param id
- * @param column
- * @param number
- * @return
- */
- @RequestMapping("/reduce/{tableName}/{id}/{column}/{number}")
- public R reduceCloumNumber(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("number") String number) {
- logger.debug("reduceCloumNumber:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,number);
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("tableName", tableName);
- params.put("id", id);
- params.put("column", column);
- params.put("number", number);
- int i = commonService.reduceCloumNumber(params);
- if(i>0){
- return R.ok();
- }
- return R.error("娣诲姞澶辫触");
- }
-
- @RequestMapping("/update/{tableName}/{id}/{column}/{value}")
- public R updateCloumValue(@PathVariable("tableName") String tableName, @PathVariable("id") Integer id, @PathVariable("column") String column, @PathVariable("value") String value) {
- logger.debug("updateCloumValue:,,Controller:{},,tableName:{},id:{},column:{},number:{}",this.getClass().getName(),tableName,id,column,value);
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("tableName", tableName);
- params.put("id", id);
- params.put("column", column);
- params.put("value", value);
- int i = commonService.updateCloumValue(params);
- if(i>0){
- return R.ok();
- }
- return R.error("娣诲姞澶辫触");
- }
-
-
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。