|
|
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.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.entity.ConfigEntity;
|
|
|
import com.service.CommonService;
|
|
|
import com.service.ConfigService;
|
|
|
import com.utils.BaiduUtil;
|
|
|
import com.utils.FileUtil;
|
|
|
import com.utils.R;
|
|
|
import com.utils.CommonUtil;
|
|
|
/**
|
|
|
* 通用功能控制器
|
|
|
*
|
|
|
* <p>提供系统中跨模块的通用功能接口,包括:
|
|
|
* <ul>
|
|
|
* <li>数据字典联动接口</li>
|
|
|
* <li>审核状态管理</li>
|
|
|
* <li>数据统计与分析</li>
|
|
|
* <li>提醒功能</li>
|
|
|
* </ul>
|
|
|
*
|
|
|
* <p><b>设计原则:</b>
|
|
|
* <ol>
|
|
|
* <li>高复用性:避免重复功能代码</li>
|
|
|
* <li>灵活性:通过参数动态适配不同业务表</li>
|
|
|
* <li>安全性:合理使用 {@code @IgnoreAuth} 注解控制访问权限</li>
|
|
|
* </ol>
|
|
|
*
|
|
|
* @author YourName
|
|
|
* @version 1.0
|
|
|
* @since 2023-10-01
|
|
|
*/
|
|
|
|
|
|
@RestController
|
|
|
// 声明为RESTful控制器,所有方法返回JSON数据
|
|
|
|
|
|
public class CommonController{
|
|
|
@Autowired
|
|
|
private CommonService commonService;
|
|
|
|
|
|
private static AipFace client = null;
|
|
|
|
|
|
@Autowired
|
|
|
private ConfigService configService;
|
|
|
/**
|
|
|
* 获取数据字典选项(联动接口)
|
|
|
*
|
|
|
* <p><b>功能说明:</b>
|
|
|
* 根据表名和列名获取该列的所有去重值,常用于前端下拉框选项加载
|
|
|
*
|
|
|
* <p><b>使用场景:</b>
|
|
|
* <ul>
|
|
|
* <li>省市县三级联动</li>
|
|
|
* <li>动态筛选条件</li>
|
|
|
* <li>表单选项加载</li>
|
|
|
* </ul>
|
|
|
*
|
|
|
* <p><b>参数说明:</b>
|
|
|
* <table border="1">
|
|
|
* <tr><th>参数</th><th>类型</th><th>必填</th><th>说明</th></tr>
|
|
|
* <tr><td>tableName</td><td>路径参数</td><td>是</td><td>目标表名</td></tr>
|
|
|
* <tr><td>columnName</td><td>路径参数</td><td>是</td><td>目标列名</td></tr>
|
|
|
* <tr><td>level</td><td>请求参数</td><td>否</td><td>层级(用于多级联动)</td></tr>
|
|
|
* <tr><td>parent</td><td>请求参数</td><td>否</td><td>父级值(用于多级联动)</td></tr>
|
|
|
* <tr><td>conditionColumn</td><td>请求参数</td><td>否</td><td>附加条件列</td></tr>
|
|
|
* <tr><td>conditionValue</td><td>请求参数</td><td>否</td><td>附加条件值</td></tr>
|
|
|
* </table>
|
|
|
*
|
|
|
* @param tableName 表名(路径变量)
|
|
|
* @param columnName 列名(路径变量)
|
|
|
* @param conditionColumn 附加条件列(可选)
|
|
|
* @param conditionValue 附加条件值(可选)
|
|
|
* @param level 层级(可选)
|
|
|
* @param parent 父级值(可选)
|
|
|
* @return 包含选项列表的响应对象
|
|
|
*/
|
|
|
@IgnoreAuth// 允许未认证访问
|
|
|
@RequestMapping("/option/{tableName}/{columnName}")
|
|
|
public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,@RequestParam(required = false) String conditionColumn,@RequestParam(required = false) String conditionValue,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);
|
|
|
}
|
|
|
// 处理附加查询条件
|
|
|
|
|
|
if(StringUtils.isNotBlank(conditionColumn)) {
|
|
|
params.put("conditionColumn", conditionColumn);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(conditionValue)) {
|
|
|
params.put("conditionValue", conditionValue);
|
|
|
}
|
|
|
// 调用服务层获取数据
|
|
|
|
|
|
List<String> data = commonService.getOption(params);
|
|
|
return R.ok().put("data", data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据条件获取单条记录
|
|
|
*
|
|
|
* <p><b>功能说明:</b>
|
|
|
* 根据表名、列名和列值获取匹配的单条记录
|
|
|
*
|
|
|
* <p><b>典型应用:</b>
|
|
|
* <ul>
|
|
|
* <li>根据ID获取详情</li>
|
|
|
* <li>根据唯一编码获取记录</li>
|
|
|
* <li>快速检索</li>
|
|
|
* </ul>
|
|
|
*
|
|
|
* @param tableName 表名(路径变量)
|
|
|
* @param columnName 列名(路径变量)
|
|
|
* @param columnValue 列值(请求参数)
|
|
|
* @return 包含单条记录的响应对象
|
|
|
*/
|
|
|
|
|
|
@IgnoreAuth// 允许未认证访问
|
|
|
@RequestMapping("/follow/{tableName}/{columnName}")
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新审核状态
|
|
|
*
|
|
|
* <p><b>功能说明:</b>
|
|
|
* 修改指定表中记录的审核状态
|
|
|
*
|
|
|
* <p><b>参数要求:</b>
|
|
|
* 请求体必须包含以下字段:
|
|
|
* <ul>
|
|
|
* <li>id - 记录ID</li>
|
|
|
* <li>sfsh - 审核状态(如:通过/拒绝)</li>
|
|
|
* <li>shhf - 审核回复内容(可选)</li>
|
|
|
* </ul>
|
|
|
*
|
|
|
* @param tableName 表名(路径变量)
|
|
|
* @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();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取需要提醒的记录数量
|
|
|
*
|
|
|
* <p><b>功能说明:</b>
|
|
|
* 根据时间条件统计需要提醒的记录数量
|
|
|
*
|
|
|
* <p><b>参数说明:</b>
|
|
|
* <table border="1">
|
|
|
* <tr><th>参数</th><th>类型</th><th>必填</th><th>说明</th></tr>
|
|
|
* <tr><td>tableName</td><td>路径参数</td><td>是</td><td>目标表名</td></tr>
|
|
|
* <tr><td>columnName</td><td>路径参数</td><td>是</td><td>时间列名</td></tr>
|
|
|
* <tr><td>type</td><td>路径参数</td><td>是</td><td>统计类型(1:数字,2:日期)</td></tr>
|
|
|
* <tr><td>remindstart</td><td>请求参数</td><td>否</td><td>开始提醒天数偏移(负数表示之前)</td></tr>
|
|
|
* <tr><td>remindend</td><td>请求参数</td><td>否</td><td>结束提醒天数偏移</td></tr>
|
|
|
* </table>
|
|
|
*
|
|
|
* <p><b>日期类型处理逻辑:</b>
|
|
|
* 当类型为2(日期)时,会将remindstart/remindend参数转换为具体日期范围
|
|
|
*
|
|
|
* @param tableName 表名(路径变量)
|
|
|
* @param columnName 列名(路径变量)
|
|
|
* @param type 统计类型(路径变量)
|
|
|
* @param map 包含时间条件的请求参数
|
|
|
* @return 包含提醒数量的响应对象
|
|
|
*/
|
|
|
@IgnoreAuth
|
|
|
@RequestMapping("/remind/{tableName}/{columnName}/{type}")
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 单列数值计算(求和)
|
|
|
*
|
|
|
* <p><b>功能说明:</b>
|
|
|
* 对指定表中的数值列进行求和计算
|
|
|
*
|
|
|
* <p><b>典型应用:</b>
|
|
|
* <ul>
|
|
|
* <li>统计订单总金额</li>
|
|
|
* <li>计算库存总量</li>
|
|
|
* <li>汇总用户积分</li>
|
|
|
* </ul>
|
|
|
*
|
|
|
* @param tableName 表名(路径变量)
|
|
|
* @param columnName 列名(路径变量)
|
|
|
* @return 包含计算结果的响应对象
|
|
|
*/
|
|
|
@IgnoreAuth
|
|
|
@RequestMapping("/cal/{tableName}/{columnName}")
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 分组统计
|
|
|
*
|
|
|
* <p><b>功能说明:</b>
|
|
|
* 对指定表按指定列进行分组统计
|
|
|
*
|
|
|
* <p><b>输出格式:</b>
|
|
|
* <pre>
|
|
|
* [
|
|
|
* {"分组列值1": 统计结果1},
|
|
|
* {"分组列值2": 统计结果2},
|
|
|
* ...
|
|
|
* ]
|
|
|
* </pre>
|
|
|
*
|
|
|
* @param tableName 表名(路径变量)
|
|
|
* @param columnName 分组列名(路径变量)
|
|
|
* @return 包含分组统计结果的响应对象
|
|
|
*/
|
|
|
@IgnoreAuth
|
|
|
@RequestMapping("/group/{tableName}/{columnName}")
|
|
|
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);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
for(Map<String, Object> m : result) {
|
|
|
for(String k : m.keySet()) {
|
|
|
if(m.get(k) instanceof Date) {
|
|
|
m.put(k, sdf.format((Date)m.get(k)));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return R.ok().put("data", result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* (按值统计)
|
|
|
*/
|
|
|
@IgnoreAuth
|
|
|
@RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
|
|
|
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);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
for(Map<String, Object> m : result) {
|
|
|
for(String k : m.keySet()) {
|
|
|
if(m.get(k) instanceof Date) {
|
|
|
m.put(k, sdf.format((Date)m.get(k)));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return R.ok().put("data", result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* (按值统计)时间统计类型
|
|
|
*/
|
|
|
@IgnoreAuth
|
|
|
@RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}/{timeStatType}")
|
|
|
public R valueDay(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType) {
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
params.put("table", tableName);
|
|
|
params.put("xColumn", xColumnName);
|
|
|
params.put("yColumn", yColumnName);
|
|
|
params.put("timeStatType", timeStatType);
|
|
|
List<Map<String, Object>> result = commonService.selectTimeStatValue(params);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
for(Map<String, Object> m : result) {
|
|
|
for(String k : m.keySet()) {
|
|
|
if(m.get(k) instanceof Date) {
|
|
|
m.put(k, sdf.format((Date)m.get(k)));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return R.ok().put("data", result);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|