Commit 5d0ae785 by xinla

init

1 parent a002f12a
Showing 1000 changed files with 0 additions and 4867 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
No preview for this file type
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
#!/bin/bash
########################################################
############### LinkWeChat Docker 部署脚本 ##############
########################################################
LOG=$1
PROJ_HOME=$PWD
echo "$PROJ_HOME"
CLEAN_BUILD="clean"
BUILD_CODE="install"
BUILD_DOCKER="docker:build"
showLog(){
if [ "$1" == '--log' -o "$1" == '-l' ]; then
$PROJ_HOME/mvnw "$2"
else
$PROJ_HOME/mvnw "$2" > /dev/null
fi
}
cd "$PROJ_HOME"
echo '开始从代码构建LinkWeChat'
showLog "$LOG" "$CLEAN_BUILD"
showLog "$LOG" "$BUILD_CODE"
echo '构建完成'
cd "$PROJ_HOME"/linkwe-admin
echo '开始构建Docker镜像'
showLog "$LOG" "$BUILD_DOCKER"
echo 'Docker镜像构建完成'
\ No newline at end of file
version: '3.3'
# 如需配置变量,请在environment中进行变量配置
services:
api:
image: linkwechat
container_name: linkwechat
environment:
- JAVA_OPTS=-Xms4096m -Xmx4096m -Duser.timezone=Asia/Shanghai
- TZ=Asia/Shanghai
- NACOS_SERVER
# 如果使用nacos,以下变量可以不进行配置
- ES_ADDRESS
- DB_HOST
- DB_PORT
- DB_NAME
- DB_USER
- DB_PASS
- REDIS_HOST
- REDIS_PORT
ports:
- 8090
volumes:
- ./logs:/logs
# 上传文件地址,请根据实际${ruoyi.profile}自行修改映射
- ./pic:/app/project/pic
- ./tmp:/tmp
restart: always
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>linkwechat</artifactId>
<groupId>com.linkwechat</groupId>
<version>3.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>linkwe-admin</artifactId>
<description>
web服务入口
</description>
<dependencies>
<!-- spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 表示依赖不会传递 -->
</dependency>
<!-- 参数校验 -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<!-- swagger2-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<!-- Mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 核心模块-->
<dependency>
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-framework</artifactId>
</dependency>
<!-- 定时任务-->
<dependency>
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-quartz</artifactId>
</dependency>
<!-- 代码生成-->
<dependency>
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-generator</artifactId>
</dependency>
<!-- 企业微信模块-->
<dependency>
<groupId>com.linkwechat</groupId>
<artifactId>linkwe-wecom</artifactId>
</dependency>
<!--腾讯云-->
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>5.6.24</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>io.github.leejoker</groupId>
<artifactId>linkwechat-nacos-starter</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
<configuration>
<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<imageName>${parent.artifactId}</imageName>
<dockerDirectory>${basedir}/src/main/docker</dockerDirectory>
<imageTags>
<imageTag>${parent.version}</imageTag>
</imageTags>
<buildArgs>
<!--指定参数jar-->
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>
\ No newline at end of file
FROM openjdk:8-alpine
RUN set -xe && apk --no-cache add ttf-dejavu fontconfig
# 设置时区
ADD Shanghai /usr/share/zoneinfo/Asia/
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
VOLUME /tmp
#设置字符集
ENV LANG en_US.UTF-8
ARG JAR_FILE
ADD $JAR_FILE app.jar
ENTRYPOINT ["sh","-c","java -server $JAVA_OPTS -jar /app.jar"]
\ No newline at end of file
No preview for this file type
package com.linkwechat;
import com.dtflys.forest.springboot.annotation.ForestScan;
import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.scheduling.annotation.EnableAsync;
/**
* 启动程序
*
* @author ruoyi
*/
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, PageHelperAutoConfiguration.class})
@MapperScan("com.linkwechat.*.mapper")
@ForestScan(basePackages = {"com.linkwechat.wecom.client", "com.linkwechat.wecom.wxclient"})
@EnableAsync
public class LinkWeChatApplication {
public static void main(String[] args) {
SpringApplication.run(LinkWeChatApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ LinkWeChat启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" +
" | _ _ \\ \\ \\ / / \n" +
" | ( ' ) | \\ _. / ' \n" +
" |(_ o _) / _( )_ .' \n" +
" | (_,_).' __ ___(_ o _)' \n" +
" | |\\ \\ | || |(_,_)' \n" +
" | | \\ `' /| `-' / \n" +
" | | \\ / \\ / \n" +
" ''-' `'-' `-..-' ");
}
}
package com.linkwechat;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* web容器中进行部署
*
* @author ruoyi
*/
public class LinkWeChatServletInitializer extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(LinkWeChatApplication.class);
}
}
package com.linkwechat.web.controller.common;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.google.code.kaptcha.Producer;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.utils.sign.Base64;
import com.linkwechat.common.utils.uuid.IdUtils;
/**
* 验证码操作处理
*
* @author ruoyi
*/
@RestController
public class CaptchaController
{
@Resource(name = "captchaProducer")
private Producer captchaProducer;
@Resource(name = "captchaProducerMath")
private Producer captchaProducerMath;
@Autowired
private RedisCache redisCache;
// 验证码类型
@Value("${ruoyi.captchaType}")
private String captchaType;
/**
* 生成验证码
*/
@GetMapping("/captchaImage")
public AjaxResult getCode(HttpServletResponse response) throws IOException
{
// 保存验证码信息
String uuid = IdUtils.simpleUUID();
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
String capStr = null, code = null;
BufferedImage image = null;
// 生成验证码
if ("math".equals(captchaType))
{
String capText = captchaProducerMath.createText();
capStr = capText.substring(0, capText.lastIndexOf("@"));
code = capText.substring(capText.lastIndexOf("@") + 1);
image = captchaProducerMath.createImage(capStr);
}
else if ("char".equals(captchaType))
{
capStr = code = captchaProducer.createText();
image = captchaProducer.createImage(capStr);
}
redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
// 转换流信息写出
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
try
{
ImageIO.write(image, "jpg", os);
}
catch (IOException e)
{
return AjaxResult.error(e.getMessage());
}
AjaxResult ajax = AjaxResult.success();
ajax.put("uuid", uuid);
ajax.put("img", Base64.encode(os.toByteArray()));
return ajax;
}
}
package com.linkwechat.web.controller.common;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.config.ServerConfig;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.FileVo;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.framework.web.domain.server.SysFile;
import com.linkwechat.framework.web.service.FileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 通用请求处理
*
* @author ruoyi
*/
@RestController
public class CommonController {
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
@Autowired
private ServerConfig serverConfig;
@Autowired
private FileService fileService;
/**
* 通用下载请求
*
* @param fileName 文件名称
* @param delete 是否删除
*/
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
try {
if (!FileUtils.isValidFilename(fileName)) {
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = RuoYiConfig.getDownloadPath() + fileName;
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
FileUtils.writeBytes(filePath, response.getOutputStream());
if (delete) {
FileUtils.deleteFile(filePath);
}
} catch (Exception e) {
log.error("下载文件失败", e);
}
}
/**
* 通用上传请求
*/
@PostMapping("/common/upload")
public AjaxResult uploadFile(MultipartFile file) throws Exception {
try {
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName;
AjaxResult ajax = AjaxResult.success();
ajax.put("fileName", fileName);
ajax.put("url", url);
return ajax;
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
}
}
/**
* 本地资源通用下载
*/
@GetMapping("/common/download/resource")
public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception {
// 本地资源路径
String localPath = RuoYiConfig.getProfile();
// 数据库资源地址
String downloadPath = localPath + StringUtils.substringAfter(name, Constants.RESOURCE_PREFIX);
// 下载名称
String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
FileUtils.writeBytes(downloadPath, response.getOutputStream());
}
/**
* 网络资源通用下载
*/
@GetMapping("/common/download/url")
public void webResourceDownload(String url, HttpServletRequest request, HttpServletResponse response) throws Exception {
FileUtils.downloadFile(url, response.getOutputStream());
}
/**
* 通用上传请求
*/
@PostMapping("/common/uploadFile2Cos")
public AjaxResult uploadFile2Cos(MultipartFile file){
try {
SysFile sysFile
= fileService.upload(file);
return AjaxResult.success(
FileVo.builder()
.fileName(sysFile.getFileName())
.url(sysFile.getImgUrlPrefix()+sysFile.getFileName())
.build()
);
} catch (Exception e) {
return AjaxResult.error("不支持当前文件上传或文件过大建议传20MB以内的文件");
}
}
/**
* 获取图片
*/
@GetMapping("/common/findImage")
public void findImage(HttpServletResponse response,String fileName){
fileService.findImage(fileName,response);
}
}
package com.linkwechat.web.controller.monitor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.framework.web.domain.Server;
/**
* 服务器监控
*
* @author ruoyi
*/
@RestController
@RequestMapping("/monitor/server")
public class ServerController extends BaseController
{
@PreAuthorize("@ss.hasPermi('monitor:server:list')")
@GetMapping()
public AjaxResult getInfo() throws Exception
{
Server server = new Server();
server.copyTo();
return AjaxResult.success(server);
}
}
package com.linkwechat.web.controller.monitor;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.system.domain.SysLogininfor;
import com.linkwechat.system.service.ISysLogininforService;
/**
* 系统访问记录
*
* @author ruoyi
*/
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLogininforController extends BaseController
{
@Autowired
private ISysLogininforService logininforService;
@PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
@GetMapping("/list")
public TableDataInfo list(SysLogininfor logininfor)
{
startPage();
List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
return getDataTable(list);
}
@Log(title = "登陆日志", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
@GetMapping("/export")
public AjaxResult export(SysLogininfor logininfor)
{
List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
return util.exportExcel(list, "登陆日志");
}
@PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
@Log(title = "登陆日志", businessType = BusinessType.DELETE)
@DeleteMapping("/{infoIds}")
public AjaxResult remove(@PathVariable Long[] infoIds)
{
return toAjax(logininforService.deleteLogininforByIds(infoIds));
}
@PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
@Log(title = "登陆日志", businessType = BusinessType.CLEAN)
@DeleteMapping("/clean")
public AjaxResult clean()
{
logininforService.cleanLogininfor();
return AjaxResult.success();
}
}
package com.linkwechat.web.controller.monitor;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.system.domain.SysOperLog;
import com.linkwechat.system.service.ISysOperLogService;
/**
* 操作日志记录
*
* @author ruoyi
*/
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController
{
@Autowired
private ISysOperLogService operLogService;
@PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
@GetMapping("/list")
public TableDataInfo list(SysOperLog operLog)
{
startPage();
List<SysOperLog> list = operLogService.selectOperLogList(operLog);
return getDataTable(list);
}
@Log(title = "操作日志", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
@GetMapping("/export")
public AjaxResult export(SysOperLog operLog)
{
List<SysOperLog> list = operLogService.selectOperLogList(operLog);
ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
return util.exportExcel(list, "操作日志");
}
@PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
@DeleteMapping("/{operIds}")
public AjaxResult remove(@PathVariable Long[] operIds)
{
return toAjax(operLogService.deleteOperLogByIds(operIds));
}
@Log(title = "操作日志", businessType = BusinessType.CLEAN)
@PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
@DeleteMapping("/clean")
public AjaxResult clean()
{
operLogService.cleanOperLog();
return AjaxResult.success();
}
}
package com.linkwechat.web.controller.monitor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.system.domain.SysUserOnline;
import com.linkwechat.system.service.ISysUserOnlineService;
/**
* 在线用户监控
*
* @author ruoyi
*/
@RestController
@RequestMapping("/monitor/online")
public class SysUserOnlineController extends BaseController
{
@Autowired
private ISysUserOnlineService userOnlineService;
@Autowired
private RedisCache redisCache;
@PreAuthorize("@ss.hasPermi('monitor:online:list')")
@GetMapping("/list")
public TableDataInfo list(String ipaddr, String userName)
{
Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*");
List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
for (String key : keys)
{
LoginUser user = redisCache.getCacheObject(key);
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
{
if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername()))
{
userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
}
}
else if (StringUtils.isNotEmpty(ipaddr))
{
if (StringUtils.equals(ipaddr, user.getIpaddr()))
{
userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
}
}
else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser()))
{
if (StringUtils.equals(userName, user.getUsername()))
{
userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
}
}
else
{
userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
}
}
Collections.reverse(userOnlineList);
userOnlineList.removeAll(Collections.singleton(null));
return getDataTable(userOnlineList);
}
/**
* 强退用户
*/
@PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')")
@Log(title = "在线用户", businessType = BusinessType.FORCE)
@DeleteMapping("/{tokenId}")
public AjaxResult forceLogout(@PathVariable String tokenId)
{
redisCache.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId);
return AjaxResult.success();
}
}
package com.linkwechat.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.annotation.RepeatSubmit;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.system.domain.SysConfig;
import com.linkwechat.system.service.ISysConfigService;
/**
* 参数配置 信息操作处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/config")
public class SysConfigController extends BaseController
{
@Autowired
private ISysConfigService configService;
/**
* 获取参数配置列表
*/
@PreAuthorize("@ss.hasPermi('system:config:list')")
@GetMapping("/list")
public TableDataInfo list(SysConfig config)
{
startPage();
List<SysConfig> list = configService.selectConfigList(config);
return getDataTable(list);
}
@Log(title = "参数管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:config:export')")
@GetMapping("/export")
public AjaxResult export(SysConfig config)
{
List<SysConfig> list = configService.selectConfigList(config);
ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class);
return util.exportExcel(list, "参数数据");
}
/**
* 根据参数编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:config:query')")
@GetMapping(value = "/{configId}")
public AjaxResult getInfo(@PathVariable Long configId)
{
return AjaxResult.success(configService.selectConfigById(configId));
}
/**
* 根据参数键名查询参数值
*/
@GetMapping(value = "/configKey/{configKey}")
public AjaxResult getConfigKey(@PathVariable String configKey)
{
return AjaxResult.success(configService.selectConfigByKey(configKey));
}
/**
* 新增参数配置
*/
@PreAuthorize("@ss.hasPermi('system:config:add')")
@Log(title = "参数管理", businessType = BusinessType.INSERT)
@PostMapping
@RepeatSubmit
public AjaxResult add(@Validated @RequestBody SysConfig config)
{
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
{
return AjaxResult.error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setCreateBy(SecurityUtils.getUsername());
return toAjax(configService.insertConfig(config));
}
/**
* 修改参数配置
*/
@PreAuthorize("@ss.hasPermi('system:config:edit')")
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysConfig config)
{
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
{
return AjaxResult.error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setUpdateBy(SecurityUtils.getUsername());
return toAjax(configService.updateConfig(config));
}
/**
* 删除参数配置
*/
@PreAuthorize("@ss.hasPermi('system:config:remove')")
@Log(title = "参数管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{configIds}")
public AjaxResult remove(@PathVariable Long[] configIds)
{
return toAjax(configService.deleteConfigByIds(configIds));
}
/**
* 清空缓存
*/
@PreAuthorize("@ss.hasPermi('system:config:remove')")
@Log(title = "参数管理", businessType = BusinessType.CLEAN)
@DeleteMapping("/clearCache")
public AjaxResult clearCache()
{
configService.clearCache();
return AjaxResult.success();
}
}
package com.linkwechat.web.controller.system;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysDept;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.system.service.ISysDeptService;
/**
* 部门信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/dept")
public class SysDeptController extends BaseController
{
@Autowired
private ISysDeptService deptService;
/**
* 获取部门列表
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list")
public AjaxResult list(SysDept dept)
{
List<SysDept> depts = deptService.selectDeptList(dept);
return AjaxResult.success(depts);
}
/**
* 查询部门列表(排除节点)
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list/exclude/{deptId}")
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
{
List<SysDept> depts = deptService.selectDeptList(new SysDept());
Iterator<SysDept> it = depts.iterator();
while (it.hasNext())
{
SysDept d = (SysDept) it.next();
if (d.getDeptId().intValue() == deptId
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
{
it.remove();
}
}
return AjaxResult.success(depts);
}
/**
* 根据部门编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:dept:query')")
@GetMapping(value = "/{deptId}")
public AjaxResult getInfo(@PathVariable Long deptId)
{
return AjaxResult.success(deptService.selectDeptById(deptId));
}
/**
* 获取部门下拉树列表
*/
@GetMapping("/treeselect")
public AjaxResult treeselect(SysDept dept)
{
List<SysDept> depts = deptService.selectDeptList(dept);
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
}
/**
* 加载对应角色部门列表树
*/
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
{
List<SysDept> depts = deptService.selectDeptList(new SysDept());
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
ajax.put("depts", deptService.buildDeptTreeSelect(depts));
return ajax;
}
/**
* 新增部门
*/
@PreAuthorize("@ss.hasPermi('system:dept:add')")
@Log(title = "部门管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysDept dept)
{
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
dept.setCreateBy(SecurityUtils.getUsername());
return toAjax(deptService.insertDept(dept));
}
/**
* 修改部门
*/
@PreAuthorize("@ss.hasPermi('system:dept:edit')")
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysDept dept)
{
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
else if (dept.getParentId().equals(dept.getDeptId()))
{
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
}
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
&& deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
{
return AjaxResult.error("该部门包含未停用的子部门!");
}
dept.setUpdateBy(SecurityUtils.getUsername());
return toAjax(deptService.updateDept(dept));
}
/**
* 删除部门
*/
@PreAuthorize("@ss.hasPermi('system:dept:remove')")
@Log(title = "部门管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{deptId}")
public AjaxResult remove(@PathVariable Long deptId)
{
if (deptService.hasChildByDeptId(deptId))
{
return AjaxResult.error("存在下级部门,不允许删除");
}
if (deptService.checkDeptExistUser(deptId))
{
return AjaxResult.error("部门存在用户,不允许删除");
}
return toAjax(deptService.deleteDeptById(deptId));
}
}
package com.linkwechat.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysDictData;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.system.service.ISysDictDataService;
import com.linkwechat.system.service.ISysDictTypeService;
/**
* 数据字典信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController
{
@Autowired
private ISysDictDataService dictDataService;
@Autowired
private ISysDictTypeService dictTypeService;
@PreAuthorize("@ss.hasPermi('system:dict:list')")
@GetMapping("/list")
public TableDataInfo list(SysDictData dictData)
{
startPage();
List<SysDictData> list = dictDataService.selectDictDataList(dictData);
return getDataTable(list);
}
@Log(title = "字典数据", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:dict:export')")
@GetMapping("/export")
public AjaxResult export(SysDictData dictData)
{
List<SysDictData> list = dictDataService.selectDictDataList(dictData);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
return util.exportExcel(list, "字典数据");
}
/**
* 查询字典数据详细
*/
@PreAuthorize("@ss.hasPermi('system:dict:query')")
@GetMapping(value = "/{dictCode}")
public AjaxResult getInfo(@PathVariable Long dictCode)
{
return AjaxResult.success(dictDataService.selectDictDataById(dictCode));
}
/**
* 根据字典类型查询字典数据信息
*/
@GetMapping(value = "/type/{dictType}")
public AjaxResult dictType(@PathVariable String dictType)
{
return AjaxResult.success(dictTypeService.selectDictDataByType(dictType));
}
/**
* 新增字典类型
*/
@PreAuthorize("@ss.hasPermi('system:dict:add')")
@Log(title = "字典数据", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysDictData dict)
{
dict.setCreateBy(SecurityUtils.getUsername());
return toAjax(dictDataService.insertDictData(dict));
}
/**
* 修改保存字典类型
*/
@PreAuthorize("@ss.hasPermi('system:dict:edit')")
@Log(title = "字典数据", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysDictData dict)
{
dict.setUpdateBy(SecurityUtils.getUsername());
return toAjax(dictDataService.updateDictData(dict));
}
/**
* 删除字典类型
*/
@PreAuthorize("@ss.hasPermi('system:dict:remove')")
@Log(title = "字典类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictCodes}")
public AjaxResult remove(@PathVariable Long[] dictCodes)
{
return toAjax(dictDataService.deleteDictDataByIds(dictCodes));
}
}
package com.linkwechat.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysDictType;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.system.service.ISysDictTypeService;
/**
* 数据字典信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/dict/type")
public class SysDictTypeController extends BaseController
{
@Autowired
private ISysDictTypeService dictTypeService;
@PreAuthorize("@ss.hasPermi('system:dict:list')")
@GetMapping("/list")
public TableDataInfo list(SysDictType dictType)
{
startPage();
List<SysDictType> list = dictTypeService.selectDictTypeList(dictType);
return getDataTable(list);
}
@Log(title = "字典类型", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:dict:export')")
@GetMapping("/export")
public AjaxResult export(SysDictType dictType)
{
List<SysDictType> list = dictTypeService.selectDictTypeList(dictType);
ExcelUtil<SysDictType> util = new ExcelUtil<SysDictType>(SysDictType.class);
return util.exportExcel(list, "字典类型");
}
/**
* 查询字典类型详细
*/
@PreAuthorize("@ss.hasPermi('system:dict:query')")
@GetMapping(value = "/{dictId}")
public AjaxResult getInfo(@PathVariable Long dictId)
{
return AjaxResult.success(dictTypeService.selectDictTypeById(dictId));
}
/**
* 新增字典类型
*/
@PreAuthorize("@ss.hasPermi('system:dict:add')")
@Log(title = "字典类型", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysDictType dict)
{
if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
{
return AjaxResult.error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
dict.setCreateBy(SecurityUtils.getUsername());
return toAjax(dictTypeService.insertDictType(dict));
}
/**
* 修改字典类型
*/
@PreAuthorize("@ss.hasPermi('system:dict:edit')")
@Log(title = "字典类型", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysDictType dict)
{
if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
{
return AjaxResult.error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
dict.setUpdateBy(SecurityUtils.getUsername());
return toAjax(dictTypeService.updateDictType(dict));
}
/**
* 删除字典类型
*/
@PreAuthorize("@ss.hasPermi('system:dict:remove')")
@Log(title = "字典类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictIds}")
public AjaxResult remove(@PathVariable Long[] dictIds)
{
return toAjax(dictTypeService.deleteDictTypeByIds(dictIds));
}
/**
* 清空缓存
*/
@PreAuthorize("@ss.hasPermi('system:dict:remove')")
@Log(title = "字典类型", businessType = BusinessType.CLEAN)
@DeleteMapping("/clearCache")
public AjaxResult clearCache()
{
dictTypeService.clearCache();
return AjaxResult.success();
}
/**
* 获取字典选择框列表
*/
@GetMapping("/optionselect")
public AjaxResult optionselect()
{
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll();
return AjaxResult.success(dictTypes);
}
}
package com.linkwechat.web.controller.system;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysDept;
import com.linkwechat.common.core.domain.entity.SysMenu;
import com.linkwechat.common.core.domain.entity.SysUser;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.domain.model.LoginBody;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.utils.ServletUtils;
import com.linkwechat.framework.web.service.SysLoginService;
import com.linkwechat.framework.web.service.SysPermissionService;
import com.linkwechat.framework.web.service.TokenService;
import com.linkwechat.system.service.ISysDeptService;
import com.linkwechat.system.service.ISysMenuService;
import com.linkwechat.system.service.ISysUserService;
import com.linkwechat.wecom.client.WeUserClient;
import com.linkwechat.wecom.domain.dto.WeLoginUserInfoDto;
import com.linkwechat.wecom.domain.dto.WeUserInfoDto;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Set;
/**
* 登录验证
*
* @author ruoyi
*/
@RestController
public class SysLoginController
{
@Autowired
private SysLoginService loginService;
@Autowired
private ISysMenuService menuService;
@Autowired
private SysPermissionService permissionService;
@Autowired
private TokenService tokenService;
@Autowired
private IWeCorpAccountService iWxCorpAccountService;
@Autowired
private WeUserClient weUserClient;
@Autowired
private ISysDeptService iSysDeptService;
@Autowired
private ISysUserService sysUserService;
/**
* 登录方法
*
* @param loginBody 登录信息
* @return 结果
*/
@PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody)
{
AjaxResult ajax = AjaxResult.success();
// 生成令牌
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
loginBody.getUuid());
ajax.put(Constants.TOKEN, token);
return ajax;
}
/**
* 获取用户信息
*
* @return 用户信息
*/
@GetMapping("getInfo")
public AjaxResult getInfo()
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
SysUser user = loginUser.getUser();
// 角色集合
Set<String> roles = permissionService.getRolePermission(user);
// 权限集合
Set<String> permissions = permissionService.getMenuPermission(user);
List<SysDept> sysDepts = iSysDeptService.selectDeptList(SysDept.builder().parentId(new Long(0)).build());
if(!CollectionUtils.isEmpty(sysDepts)){
user.setCompanyName(
sysDepts.stream().findFirst().get().getDeptName()
);
}
//校验用户是否拥有可用corpid
WeCorpAccount wxCorpAccount
= iWxCorpAccountService.findValidWeCorpAccount();
if(null != wxCorpAccount){
user.setValidCropId(true);
}
AjaxResult ajax = AjaxResult.success();
ajax.put("user", user);
ajax.put("roles", roles);
ajax.put("permissions", permissions);
return ajax;
}
/**
* 获取路由信息
*
* @return 路由信息
*/
@GetMapping("getRouters")
public AjaxResult getRouters()
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
// 用户信息
SysUser user = loginUser.getUser();
List<SysMenu> menus = menuService.selectMenuTreeByUserId(user.getUserId());
return AjaxResult.success(menuService.buildMenus(menus));
}
// /**
// * 获取企业扫码登录相关参数
// * @return
// */
// @GetMapping("/findWxQrLoginInfo")
// public AjaxResult findQrLoginParm(){
//
// WeCorpAccount validWeCorpAccount
// = iWxCorpAccountService.findValidWeCorpAccount();
// if(null != validWeCorpAccount){
// validWeCorpAccount.setContactSecret(null);
// validWeCorpAccount.setCorpSecret(null);
// validWeCorpAccount.setProviderSecret(null);
// }
//
// return AjaxResult.success(validWeCorpAccount);
// }
// /**
// * 扫码登录微信端回调
// * @param auth_code 授权code
// * @param agentId 应用id
// * @return
// */
// @GetMapping("/wxQrLogin")
// public AjaxResult wxQrLogin(String auth_code, String agentId){
//
// AjaxResult ajax = AjaxResult.success();
//
// WeUserInfoDto userInfo = weUserClient.getUserInfo(auth_code, agentId);
// if( null != userInfo){
// SysUser sysUser = sysUserService.selectUserByCorpUserId(userInfo.getUserId());
// if (null != sysUser){
// String token = loginService.noPwdLogin(sysUser.getUserName());
// ajax.put(Constants.TOKEN, token);
// }else {
// return AjaxResult.error("请绑定后再登录");
// }
// }
// return ajax;
// }
// /**
// * 通过企业id和企业密钥登录
// * @param corpId
// * @param corpSecret
// * @return
// */
// @GetMapping("/corpLogin")
// public AjaxResult corpLogin(String corpId,String corpSecret){
//
// WeCorpAccount weCorpAccount = iWxCorpAccountService.getOne(new LambdaQueryWrapper<WeCorpAccount>()
// .eq(WeCorpAccount::getCorpId, corpId)
// .eq(WeCorpAccount::getCorpSecret, corpSecret)
// .eq(WeCorpAccount::getDelFlag, Constants.NORMAL_CODE));
//
//
// if(weCorpAccount == null){
//
// return AjaxResult.error("当前企业id与企业密码不匹配或不存在");
// }
//
// return AjaxResult.success(
// loginService.noPwdLogin(weCorpAccount.getCorpAccount())
// );
// }
}
package com.linkwechat.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysMenu;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.ServletUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.framework.web.service.TokenService;
import com.linkwechat.system.service.ISysMenuService;
/**
* 菜单信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController
{
@Autowired
private ISysMenuService menuService;
@Autowired
private TokenService tokenService;
/**
* 获取菜单列表
*/
@PreAuthorize("@ss.hasPermi('system:menu:list')")
@GetMapping("/list")
public AjaxResult list(SysMenu menu)
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
Long userId = loginUser.getUser().getUserId();
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
return AjaxResult.success(menus);
}
/**
* 根据菜单编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:menu:query')")
@GetMapping(value = "/{menuId}")
public AjaxResult getInfo(@PathVariable Long menuId)
{
return AjaxResult.success(menuService.selectMenuById(menuId));
}
/**
* 获取菜单下拉树列表
*/
@GetMapping("/treeselect")
public AjaxResult treeselect(SysMenu menu)
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
Long userId = loginUser.getUser().getUserId();
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
return AjaxResult.success(menuService.buildMenuTreeSelect(menus));
}
/**
* 加载对应角色菜单列表树
*/
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId)
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
List<SysMenu> menus = menuService.selectMenuList(loginUser.getUser().getUserId());
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId));
ajax.put("menus", menuService.buildMenuTreeSelect(menus));
return ajax;
}
/**
* 新增菜单
*/
@PreAuthorize("@ss.hasPermi('system:menu:add')")
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysMenu menu)
{
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
{
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
}
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
&& !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS))
{
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
}
menu.setCreateBy(SecurityUtils.getUsername());
return toAjax(menuService.insertMenu(menu));
}
/**
* 修改菜单
*/
@PreAuthorize("@ss.hasPermi('system:menu:edit')")
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysMenu menu)
{
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
{
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
}
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
&& !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS))
{
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
}
else if (menu.getMenuId().equals(menu.getParentId()))
{
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
}
menu.setUpdateBy(SecurityUtils.getUsername());
return toAjax(menuService.updateMenu(menu));
}
/**
* 删除菜单
*/
@PreAuthorize("@ss.hasPermi('system:menu:remove')")
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{menuId}")
public AjaxResult remove(@PathVariable("menuId") Long menuId)
{
if (menuService.hasChildByMenuId(menuId))
{
return AjaxResult.error("存在子菜单,不允许删除");
}
if (menuService.checkMenuExistRole(menuId))
{
return AjaxResult.error("菜单已分配,不允许删除");
}
return toAjax(menuService.deleteMenuById(menuId));
}
}
\ No newline at end of file
package com.linkwechat.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.system.domain.SysNotice;
import com.linkwechat.system.service.ISysNoticeService;
/**
* 公告 信息操作处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController
{
@Autowired
private ISysNoticeService noticeService;
/**
* 获取通知公告列表
*/
@PreAuthorize("@ss.hasPermi('system:notice:list')")
@GetMapping("/list")
public TableDataInfo list(SysNotice notice)
{
startPage();
List<SysNotice> list = noticeService.selectNoticeList(notice);
return getDataTable(list);
}
/**
* 根据通知公告编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:notice:query')")
@GetMapping(value = "/{noticeId}")
public AjaxResult getInfo(@PathVariable Long noticeId)
{
return AjaxResult.success(noticeService.selectNoticeById(noticeId));
}
/**
* 新增通知公告
*/
@PreAuthorize("@ss.hasPermi('system:notice:add')")
@Log(title = "通知公告", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysNotice notice)
{
notice.setCreateBy(SecurityUtils.getUsername());
return toAjax(noticeService.insertNotice(notice));
}
/**
* 修改通知公告
*/
@PreAuthorize("@ss.hasPermi('system:notice:edit')")
@Log(title = "通知公告", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysNotice notice)
{
notice.setUpdateBy(SecurityUtils.getUsername());
return toAjax(noticeService.updateNotice(notice));
}
/**
* 删除通知公告
*/
@PreAuthorize("@ss.hasPermi('system:notice:remove')")
@Log(title = "通知公告", businessType = BusinessType.DELETE)
@DeleteMapping("/{noticeIds}")
public AjaxResult remove(@PathVariable Long[] noticeIds)
{
return toAjax(noticeService.deleteNoticeByIds(noticeIds));
}
}
package com.linkwechat.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.system.domain.SysPost;
import com.linkwechat.system.service.ISysPostService;
/**
* 岗位信息操作处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/post")
public class SysPostController extends BaseController
{
@Autowired
private ISysPostService postService;
/**
* 获取岗位列表
*/
@PreAuthorize("@ss.hasPermi('system:post:list')")
@GetMapping("/list")
public TableDataInfo list(SysPost post)
{
startPage();
List<SysPost> list = postService.selectPostList(post);
return getDataTable(list);
}
@Log(title = "岗位管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:post:export')")
@GetMapping("/export")
public AjaxResult export(SysPost post)
{
List<SysPost> list = postService.selectPostList(post);
ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
return util.exportExcel(list, "岗位数据");
}
/**
* 根据岗位编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:post:query')")
@GetMapping(value = "/{postId}")
public AjaxResult getInfo(@PathVariable Long postId)
{
return AjaxResult.success(postService.selectPostById(postId));
}
/**
* 新增岗位
*/
@PreAuthorize("@ss.hasPermi('system:post:add')")
@Log(title = "岗位管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysPost post)
{
if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
{
return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
{
return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
}
post.setCreateBy(SecurityUtils.getUsername());
return toAjax(postService.insertPost(post));
}
/**
* 修改岗位
*/
@PreAuthorize("@ss.hasPermi('system:post:edit')")
@Log(title = "岗位管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysPost post)
{
if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
{
return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
{
return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
}
post.setUpdateBy(SecurityUtils.getUsername());
return toAjax(postService.updatePost(post));
}
/**
* 删除岗位
*/
@PreAuthorize("@ss.hasPermi('system:post:remove')")
@Log(title = "岗位管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{postIds}")
public AjaxResult remove(@PathVariable Long[] postIds)
{
return toAjax(postService.deletePostByIds(postIds));
}
/**
* 获取岗位选择框列表
*/
@GetMapping("/optionselect")
public AjaxResult optionselect()
{
List<SysPost> posts = postService.selectPostAll();
return AjaxResult.success(posts);
}
}
package com.linkwechat.web.controller.system;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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 org.springframework.web.multipart.MultipartFile;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysUser;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.ServletUtils;
import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.framework.web.service.TokenService;
import com.linkwechat.system.service.ISysUserService;
/**
* 个人信息 业务处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/user/profile")
public class SysProfileController extends BaseController
{
@Autowired
private ISysUserService userService;
@Autowired
private TokenService tokenService;
@Autowired
private RuoYiConfig ruoYiConfig;
/**
* 个人信息
*/
@GetMapping
public AjaxResult profile()
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
SysUser user = loginUser.getUser();
AjaxResult ajax = AjaxResult.success(user);
ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername()));
ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername()));
return ajax;
}
/**
* 修改用户
*/
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult updateProfile(@RequestBody SysUser user)
{
if (userService.updateUserProfile(user) > 0)
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
// 更新缓存用户信息
loginUser.getUser().setNickName(user.getNickName());
loginUser.getUser().setPhonenumber(user.getPhonenumber());
loginUser.getUser().setEmail(user.getEmail());
loginUser.getUser().setSex(user.getSex());
tokenService.setLoginUser(loginUser);
return AjaxResult.success();
}
return AjaxResult.error("修改个人信息异常,请联系管理员");
}
/**
* 重置密码
*/
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
public AjaxResult updatePwd(String oldPassword, String newPassword)
{
if(ruoYiConfig.isEditPwd()){
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
String userName = loginUser.getUsername();
String password = loginUser.getPassword();
if (!SecurityUtils.matchesPassword(oldPassword, password))
{
return AjaxResult.error("修改密码失败,旧密码错误");
}
if (SecurityUtils.matchesPassword(newPassword, password))
{
return AjaxResult.error("新密码不能与旧密码相同");
}
if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0)
{
// 更新缓存用户密码
loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
tokenService.setLoginUser(loginUser);
return AjaxResult.success();
}
return AjaxResult.error("修改密码异常,请联系管理员");
}else{
return AjaxResult.error("当前环境密码不可修改");
}
}
/**
* 头像上传
*/
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
@PostMapping("/avatar")
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException
{
if (!file.isEmpty())
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
{
AjaxResult ajax = AjaxResult.success();
ajax.put("imgUrl", avatar);
// 更新缓存用户头像
loginUser.getUser().setAvatar(avatar);
tokenService.setLoginUser(loginUser);
return ajax;
}
}
return AjaxResult.error("上传图片异常,请联系管理员");
}
}
package com.linkwechat.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysRole;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.ServletUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.framework.web.service.SysPermissionService;
import com.linkwechat.framework.web.service.TokenService;
import com.linkwechat.system.service.ISysRoleService;
import com.linkwechat.system.service.ISysUserService;
/**
* 角色信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/role")
public class SysRoleController extends BaseController
{
@Autowired
private ISysRoleService roleService;
@Autowired
private TokenService tokenService;
@Autowired
private SysPermissionService permissionService;
@Autowired
private ISysUserService userService;
@PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/list")
public TableDataInfo list(SysRole role)
{
startPage();
List<SysRole> list = roleService.selectRoleList(role);
return getDataTable(list);
}
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:role:export')")
@GetMapping("/export")
public AjaxResult export(SysRole role)
{
List<SysRole> list = roleService.selectRoleList(role);
ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
return util.exportExcel(list, "角色数据");
}
/**
* 根据角色编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:role:query')")
@GetMapping(value = "/{roleId}")
public AjaxResult getInfo(@PathVariable Long roleId)
{
return AjaxResult.success(roleService.selectRoleById(roleId));
}
/**
* 新增角色
*/
@PreAuthorize("@ss.hasPermi('system:role:add')")
@Log(title = "角色管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysRole role)
{
if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
{
return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
{
return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
role.setCreateBy(SecurityUtils.getUsername());
return toAjax(roleService.insertRole(role));
}
/**
* 修改保存角色
*/
@PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysRole role)
{
roleService.checkRoleAllowed(role);
if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
{
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
{
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
}
role.setUpdateBy(SecurityUtils.getUsername());
if (roleService.updateRole(role) > 0)
{
// 更新缓存用户权限
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
{
loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
tokenService.setLoginUser(loginUser);
}
return AjaxResult.success();
}
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
}
/**
* 修改保存数据权限
*/
@PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PutMapping("/dataScope")
public AjaxResult dataScope(@RequestBody SysRole role)
{
roleService.checkRoleAllowed(role);
return toAjax(roleService.authDataScope(role));
}
/**
* 状态修改
*/
@PreAuthorize("@ss.hasPermi('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PutMapping("/changeStatus")
public AjaxResult changeStatus(@RequestBody SysRole role)
{
roleService.checkRoleAllowed(role);
role.setUpdateBy(SecurityUtils.getUsername());
return toAjax(roleService.updateRoleStatus(role));
}
/**
* 删除角色
*/
@PreAuthorize("@ss.hasPermi('system:role:remove')")
@Log(title = "角色管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{roleIds}")
public AjaxResult remove(@PathVariable Long[] roleIds)
{
return toAjax(roleService.deleteRoleByIds(roleIds));
}
/**
* 获取角色选择框列表
*/
@PreAuthorize("@ss.hasPermi('system:role:query')")
@GetMapping("/optionselect")
public AjaxResult optionselect()
{
return AjaxResult.success(roleService.selectRoleAll());
}
}
package com.linkwechat.web.controller.system;
import cn.hutool.core.collection.CollectionUtil;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.UserConstants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysRole;
import com.linkwechat.common.core.domain.entity.SysUser;
import com.linkwechat.common.core.domain.model.LoginUser;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.ServletUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.framework.web.service.TokenService;
import com.linkwechat.system.service.ISysPostService;
import com.linkwechat.system.service.ISysRoleService;
import com.linkwechat.system.service.ISysUserService;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.service.IWeUserService;
import io.swagger.annotations.ApiOperation;
import io.vertx.ext.auth.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;
/**
* 用户信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/user")
public class SysUserController extends BaseController
{
@Autowired
private ISysUserService userService;
@Autowired
private ISysRoleService roleService;
@Autowired
private ISysPostService postService;
@Autowired
private TokenService tokenService;
@Autowired
private IWeUserService iWeUserService;
/**
* 获取用户列表
*/
@PreAuthorize("@ss.hasPermi('system:user:list')")
@GetMapping("/list")
public TableDataInfo list(SysUser user)
{
startPage();
List<SysUser> list = userService.selectUserList(user);
return getDataTable(list);
}
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('system:user:export')")
@GetMapping("/export")
public AjaxResult export(SysUser user)
{
List<SysUser> list = userService.selectUserList(user);
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
return util.exportExcel(list, "用户数据");
}
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
@PreAuthorize("@ss.hasPermi('system:user:import')")
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
{
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
List<SysUser> userList = util.importExcel(file.getInputStream());
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
String operName = loginUser.getUsername();
String message = userService.importUser(userList, updateSupport, operName);
return AjaxResult.success(message);
}
@GetMapping("/importTemplate")
public AjaxResult importTemplate()
{
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
return util.importTemplateExcel("用户数据");
}
/**
* 根据用户编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:user:query')")
@GetMapping(value = { "/", "/{userId}" })
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
{
AjaxResult ajax = AjaxResult.success();
List<SysRole> roles = roleService.selectRoleAll();
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
ajax.put("posts", postService.selectPostAll());
if (StringUtils.isNotNull(userId))
{
ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId));
ajax.put("postIds", postService.selectPostListByUserId(userId));
ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
}
return ajax;
}
/**
* 新增用户
*/
@PreAuthorize("@ss.hasPermi('system:user:add')")
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysUser user)
{
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName())))
{
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
{
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
}
user.setCreateBy(SecurityUtils.getUsername());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
return toAjax(userService.insertUser(user));
}
/**
* 修改用户
*/
@PreAuthorize("@ss.hasPermi('system:user:edit')")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysUser user)
{
userService.checkUserAllowed(user);
if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
}
else if (UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
{
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
}
user.setUpdateBy(SecurityUtils.getUsername());
return toAjax(userService.updateUser(user));
}
/**
* 删除用户
*/
@PreAuthorize("@ss.hasPermi('system:user:remove')")
@Log(title = "用户管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{userIds}")
public AjaxResult remove(@PathVariable Long[] userIds)
{
return toAjax(userService.deleteUserByIds(userIds));
}
/**
* 重置密码
*/
@PreAuthorize("@ss.hasPermi('system:user:edit')")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/resetPwd")
public AjaxResult resetPwd(@RequestBody SysUser user)
{
userService.checkUserAllowed(user);
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
user.setUpdateBy(SecurityUtils.getUsername());
return toAjax(userService.resetPwd(user));
}
/**
* 状态修改
*/
@PreAuthorize("@ss.hasPermi('system:user:edit')")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/changeStatus")
public AjaxResult changeStatus(@RequestBody SysUser user)
{
userService.checkUserAllowed(user);
user.setUpdateBy(SecurityUtils.getUsername());
return toAjax(userService.updateUserStatus(user));
}
@GetMapping("/findCurrentLoginUser")
public AjaxResult findCurrentLoginUser(HttpServletRequest request){
String userId="";
LoginUser loginUser = tokenService.getLoginUser(request);
if(null != loginUser){
SysUser user = loginUser.getUser();
if(null != user){
List<WeUser> weUsers = iWeUserService.getList(WeUser.builder()
.mobile(user.getPhonenumber())
.build());
if(CollectionUtil.isNotEmpty(weUsers)){
userId=weUsers.get(0).getUserId();
}
}
}
return AjaxResult.success(userId);
}
}
package com.linkwechat.web.controller.tool;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.linkwechat.common.core.controller.BaseController;
/**
* swagger 接口
*
* @author ruoyi
*/
@Controller
@RequestMapping("/tool/swagger")
public class SwaggerController extends BaseController
{
@PreAuthorize("@ss.hasPermi('tool:swagger:view')")
@GetMapping()
public String index()
{
return redirect("/swagger-ui.html");
}
}
package com.linkwechat.web.controller.wecom;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.utils.wecom.WxCryptUtil;
import com.linkwechat.web.controller.common.CommonController;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import com.linkwechat.wecom.service.event.WeEventPublisherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
/**
* @author danmo
* @description 企微回调通知接口
* @date 2020/11/6 17:31
**/
@Api(tags = "企微回调通知")
@Slf4j
@RestController
@RequestMapping("/wecom/callback")
public class WeCallBackController extends CommonController {
@Autowired
private WeEventPublisherService weEventPublisherService;
@Autowired
private IWeCorpAccountService weCorpAccountService;
@ApiModelProperty("post数据接收")
@PostMapping(value = "/recive/{corpId}")
public String recive(@RequestBody String msg, @RequestParam(name = "msg_signature") String signature,
String timestamp, String nonce,@PathVariable("corpId") String corpId) {
WeCorpAccount corpAccount = weCorpAccountService.getCorpAccountByCorpId(corpId);
WxCryptUtil wxCryptUtil = new WxCryptUtil(corpAccount.getToken(), corpAccount.getEncodingAesKey(), corpId);
try {
String decrypt = wxCryptUtil.decrypt(signature, timestamp, nonce, msg);
weEventPublisherService.register(decrypt);
return decrypt;
} catch (Exception e) {
e.printStackTrace();;
String sRespData = WxCryptUtil.getTextRespData("success");
return wxCryptUtil.encrypt(sRespData);
}
}
@ApiModelProperty("get数据校验")
@GetMapping(value = "/recive/{corpId}")
public String recive(HttpServletRequest request,@PathVariable("corpId") String corpId) {
// 微信加密签名
String sVerifyMsgSig = request.getParameter("msg_signature");
// 时间戳
String sVerifyTimeStamp = request.getParameter("timestamp");
// 随机数
String sVerifyNonce = request.getParameter("nonce");
// 随机字符串
String sVerifyEchoStr = request.getParameter("echostr");
WeCorpAccount corpAccount = weCorpAccountService.getCorpAccountByCorpId(corpId);
WxCryptUtil wxCryptUtil = new WxCryptUtil(corpAccount.getToken(), corpAccount.getEncodingAesKey(), corpId);
try {
return wxCryptUtil.verifyURL(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, sVerifyEchoStr);
} catch (Exception e) {
return "error";
}
}
}
package com.linkwechat.web.controller.wecom;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.Tree;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.domain.WeCategory;
import com.linkwechat.wecom.domain.vo.WeCategoryVo;
import com.linkwechat.wecom.service.IWeCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* 企业微信素材分类Controller
*
* @author KEWEN
* @date 2020-10-08
*/
@RestController
@RequestMapping("/wecom/category")
@Api(tags = "企业微信素材分类")
public class WeCategoryController extends BaseController {
@Autowired
private IWeCategoryService weCategoryService;
// @PreAuthorize("@ss.hasPermi('wechat:category:list')")
@GetMapping("/list")
@ApiOperation("类目树")
public AjaxResult<WeCategoryVo> list(@RequestParam("mediaType") String mediaType) {
return AjaxResult.success(weCategoryService.findWeCategoryByMediaType(mediaType));
}
/**
* 通过id查询类目详细信息
*/
// @PreAuthorize("@ss.hasPermi('wechat:category:query')")
@GetMapping(value = "/{id}")
@ApiOperation("通过id查询类目详细信息")
public AjaxResult<WeCategoryVo> getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(weCategoryService.getById(id));
}
/**
* 添加类目
*/
// @PreAuthorize("@ss.hasPermi('wechat:category:add')")
@Log(title = "添加类目", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("添加类目")
public AjaxResult add(@Validated @RequestBody WeCategory category) {
weCategoryService.insertWeCategory(category);
return AjaxResult.success();
}
/**
* 更新目录
*/
// @PreAuthorize("@ss.hasPermi('wechat:category:edit')")
@Log(title = "更新目录", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("更新目录")
public AjaxResult edit(@Validated @RequestBody WeCategory category) {
weCategoryService.updateWeCategory(category);
return AjaxResult.success();
}
/**
* 删除类目
*/
// @PreAuthorize("@ss.hasPermi('wechat:category:remove')") Constants.DELETE_CODE
@Log(title = "删除类目", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
@ApiOperation("删除类目")
public AjaxResult remove(@PathVariable Long[] ids) {
weCategoryService.deleteWeCategoryById(ids);
// List<WeCategory> categorys=new ArrayList<>();
// for (Long id:ids) {
// categorys.add(
// WeCategory.builder()
// .id(id)
// .delFlag("55")
// .build()
// );
// }
// weCategoryService.updateBatchById(categorys);
return AjaxResult.success();
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.domain.dto.WeChatCollectionDto;
import com.linkwechat.wecom.domain.vo.WeChatSideVo;
import com.linkwechat.wecom.service.IWeChatCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 聊天工具 侧边栏栏 素材收藏
*
* @author kwen
*/
@RequestMapping(value = "/wecom/chat/collection")
@RestController
public class WeChatCollectionController extends BaseController {
@Autowired
private IWeChatCollectionService weChatCollectionService;
/**
* 添加收藏
*/
//@PreAuthorize("@ss.hasPermi('chat:collection:add')")
@Log(title = "添加收藏", businessType = BusinessType.INSERT)
@PostMapping("addCollection")
public AjaxResult addCollection(@RequestBody WeChatCollectionDto chatCollectionDto) {
boolean b =
weChatCollectionService.addCollection(chatCollectionDto.getMaterialId(), chatCollectionDto.getUserId());
if(weChatCollectionService.addCollection(chatCollectionDto.getMaterialId(), chatCollectionDto.getUserId())){
return AjaxResult.success();
}
return AjaxResult.success("当前素材不可重复收藏");
}
/**
* 取消收藏
*/
// @PreAuthorize("@ss.hasPermi('chat:collection:delete')")
// @Log(title = "取消收藏", businessType = BusinessType.UPDATE)
@PostMapping(value = "cancleCollection")
public AjaxResult cancleCollection(@RequestBody WeChatCollectionDto chatCollectionDto) {
return toAjax(weChatCollectionService.cancleCollection(chatCollectionDto.getMaterialId(), chatCollectionDto.getUserId()));
}
/**
* 收藏列表
*/
// @PreAuthorize("@ss.hasPermi('chat:collection:list')")
@GetMapping("/list")
public TableDataInfo list(@RequestParam(value = "userId") String userId,@RequestParam(value = "keyword",required = false) String keyword) {
startPage();
List<WeChatSideVo> collections = weChatCollectionService.collections(userId,keyword);
return getDataTable(collections);
}
}
package com.linkwechat.web.controller.wecom;
import com.alibaba.fastjson.JSONObject;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.wecom.domain.WeChatContactMsg;
import com.linkwechat.wecom.domain.vo.WeChatContactMsgVo;
import com.linkwechat.wecom.service.IWeChatContactMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* 会话消息Controller
*
* @author ruoyi
* @date 2021-07-28
*/
@Api(tags = "会话存档管理")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/chat/msg" )
public class WeChatContactMsgController extends BaseController {
private final IWeChatContactMsgService iWeChatContactMsgService;
/**
* 查询会话消息列表
*/
@ApiOperation("查询会话消息列表")
@PreAuthorize("@ss.hasPermi('linkwechat:msg:list')")
@GetMapping("/list")
public TableDataInfo<List<WeChatContactMsg>> list(WeChatContactMsg weChatContactMsg) {
startPage();
List<WeChatContactMsg> list = iWeChatContactMsgService.queryList(weChatContactMsg);
return getDataTable(list);
}
/**
* 导出会话消息列表
*/
@ApiOperation("导出会话消息列表")
@PreAuthorize("@ss.hasPermi('linkwechat:msg:export')" )
@Log(title = "会话消息" , businessType = BusinessType.EXPORT)
@GetMapping("/export" )
public AjaxResult export(WeChatContactMsg weChatContactMsg) {
List<WeChatContactMsg> list = iWeChatContactMsgService.queryList(weChatContactMsg);
ExcelUtil<WeChatContactMsg> util = new ExcelUtil<WeChatContactMsg>(WeChatContactMsg.class);
return util.exportExcel(list, "msg" );
}
/**
* 获取会话消息详细信息
*/
@ApiOperation("获取会话消息详细信息")
@PreAuthorize("@ss.hasPermi('linkwechat:msg:query')" )
@GetMapping(value = "/{id}" )
public AjaxResult<WeChatContactMsg> getInfo(@PathVariable("id" ) Long id) {
return AjaxResult.success(iWeChatContactMsgService.getById(id));
}
/**
* 新增会话消息
*/
@ApiOperation("新增会话消息")
@PreAuthorize("@ss.hasPermi('linkwechat:msg:add')" )
@Log(title = "会话消息" , businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody WeChatContactMsg weChatContactMsg) {
return toAjax(iWeChatContactMsgService.save(weChatContactMsg) ? 1 : 0);
}
/**
* 修改会话消息
*/
@ApiOperation("修改会话消息")
@PreAuthorize("@ss.hasPermi('linkwechat:msg:edit')" )
@Log(title = "会话消息" , businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody WeChatContactMsg weChatContactMsg) {
return toAjax(iWeChatContactMsgService.updateById(weChatContactMsg) ? 1 : 0);
}
/**
* 删除会话消息
*/
@ApiOperation("删除会话消息")
@PreAuthorize("@ss.hasPermi('linkwechat:msg:remove')" )
@Log(title = "会话消息" , businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}" )
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(iWeChatContactMsgService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
}
/**
* 外部联系人/单聊 会话列表
*/
@ApiOperation("外部联系人 会话列表")
@Log(title = "外部联系人 会话列表" , businessType = BusinessType.OTHER)
@GetMapping("/selectExternalChatList/{fromId}" )
public AjaxResult<List<WeChatContactMsgVo>> selectExternalChatList(@PathVariable("fromId") String fromId) {
return AjaxResult.success(iWeChatContactMsgService.selectExternalChatList(fromId));
}
/**
* 外部联系人/单聊 会话列表
*/
@ApiOperation("单聊 会话列表")
@Log(title = "单聊 会话列表" , businessType = BusinessType.OTHER)
@GetMapping("/selectAloneChatList" )
public AjaxResult<List<WeChatContactMsgVo>> selectAloneChatList(WeChatContactMsg weChatContactMsg) {
return AjaxResult.success(iWeChatContactMsgService.selectAloneChatList(weChatContactMsg));
}
/**
* 内部联系人 会话列表
*/
@ApiOperation("内部联系人 会话列表")
@Log(title = "内部联系人 会话列表" , businessType = BusinessType.OTHER)
@GetMapping("/selectInternalChatList/{fromId}" )
public AjaxResult<List<WeChatContactMsgVo>> selectInternalChatList(@PathVariable("fromId") String fromId) {
return AjaxResult.success(iWeChatContactMsgService.selectInternalChatList(fromId));
}
/**
* 群聊 会话列表
*/
@ApiOperation("群聊 会话列表")
@Log(title = "群聊 会话列表" , businessType = BusinessType.OTHER)
@GetMapping("/selectGroupChatList/{fromId}" )
public AjaxResult<List<WeChatContactMsgVo>> selectGroupChatList(@PathVariable("fromId") String fromId) {
return AjaxResult.success(iWeChatContactMsgService.selectGroupChatList(fromId));
}
/**
* 全文检索 会话列表
*/
@ApiOperation("全文检索 会话列表")
@Log(title = "全文检索 会话列表" , businessType = BusinessType.OTHER)
@GetMapping("/selectFullSearchChatList" )
public TableDataInfo<List<WeChatContactMsgVo>> selectFullSearchChatList(WeChatContactMsg weChatContactMsg) {
startPage();
List<WeChatContactMsgVo> list = iWeChatContactMsgService.selectFullSearchChatList(weChatContactMsg);
return getDataTable(list);
}
/**
* 全文检索 会话列表
*/
@ApiOperation("全文检索 导出列表")
@Log(title = "全文检索 导出列表" , businessType = BusinessType.OTHER)
@GetMapping("/selectFullSearchChatList/export" )
public AjaxResult fullSearchChatListExport(WeChatContactMsg weChatContactMsg) {
List<WeChatContactMsgVo> list = iWeChatContactMsgService.selectFullSearchChatList(weChatContactMsg);
ExcelUtil<WeChatContactMsgVo> util = new ExcelUtil<WeChatContactMsgVo>(WeChatContactMsgVo.class);
return util.exportExcel(list, "msg" );
}
}
package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.enums.MediaType;
import com.linkwechat.wecom.domain.WeChatItem;
import com.linkwechat.wecom.domain.WeMaterial;
import com.linkwechat.wecom.domain.dto.WeChatItemDto;
import com.linkwechat.wecom.domain.vo.WeChatSideVo;
import com.linkwechat.wecom.service.IWeChatItemService;
import com.linkwechat.wecom.service.IWeMaterialService;
import com.linkwechat.wecom.service.IWePosterService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 聊天工具侧边栏
*
* @author kewen
*/
@RequestMapping(value = "/wecom/chat/item")
@RestController
public class WeChatItemController extends BaseController {
@Autowired
private IWeChatItemService weChatItemService;
@Autowired
private IWeMaterialService materialService;
@Resource
private IWePosterService wePosterService;
// @PreAuthorize("@ss.hasPermi('wecom:material:list')")
@GetMapping("/mList")
@ApiOperation("获取侧边栏选中或者未选中素材")
public TableDataInfo mList(@RequestParam(value = "categoryId", required = false) String categoryId
, @RequestParam(value = "search", required = false) String search,@RequestParam(value = "mediaType") String mediaType) {
startPage();
List<WeMaterial> list;
if(StringUtils.isNotBlank(mediaType) && mediaType.equals(MediaType.POSTER.getType())){
list = wePosterService.list(StringUtils.isBlank(categoryId)?null:Long.valueOf(categoryId),search).stream().map(wePoster -> {
WeMaterial weMaterial = new WeMaterial();
weMaterial.setMaterialName(wePoster.getTitle());
weMaterial.setMaterialUrl(wePoster.getSampleImgPath());
weMaterial.setCategoryId(wePoster.getCategoryId());
weMaterial.setId(wePoster.getId());
return weMaterial;
}).collect(Collectors.toList());
}else {
list = materialService.findWeMaterials(categoryId, search,mediaType);
}
if(CollectionUtil.isNotEmpty(list)){
List<WeChatItem> weChatItems = weChatItemService.list(new LambdaQueryWrapper<WeChatItem>()
.in(WeChatItem::getMaterialId,list.stream().map(WeMaterial::getId).collect(Collectors.toList())));
if(CollectionUtil.isNotEmpty(weChatItems)){
list.stream().forEach(k->{
k.setIsCheck(
weChatItems.stream().filter(item -> item.getMaterialId()
.equals(k.getId())).findFirst().isPresent()?true:false
);
});
}
}
return getDataTable(list);
}
/**
* 侧边栏抓取素材
*/
// @PreAuthorize("@ss.hasPermi('chat:item:add')")
@Log(title = "侧边栏抓取素材", businessType = BusinessType.INSERT)
@PutMapping
public AjaxResult add(@RequestBody WeChatItemDto chatItemDto) {
return toAjax(weChatItemService.checkItems(chatItemDto));
}
/**
* h5素材列表
*/
//@PreAuthorize("@ss.hasPermi('chat:item:list')")
@GetMapping("/list")
public TableDataInfo list(@RequestParam(value = "sideId") Long sideId
, @RequestParam(value = "keyword", required = false) String keyword,@RequestParam(value = "mediaType") String mediaType,@RequestParam(value = "userId") String userId) {
startPage();
List<WeChatSideVo> weChatSideVos;
if(mediaType.equals("5")){
weChatSideVos=weChatItemService.findChatPostsItems(sideId,keyword,mediaType,userId);
}else{
weChatSideVos
= weChatItemService.chatItems(sideId,keyword,mediaType,userId);
}
return getDataTable(weChatSideVos);
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.domain.WeChatSide;
import com.linkwechat.wecom.service.IWeChatSideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 聊天工具侧边栏
*
* @author kewen
*/
@RequestMapping(value = "/wecom/chat/side")
@RestController
public class WeChatSideController extends BaseController {
@Autowired
public IWeChatSideService weChatSideService;
/**
* 群发侧边栏列表
*/
// @PreAuthorize("@ss.hasPermi('chat:side:list')")
@GetMapping("/list")
public TableDataInfo list() {
startPage();
List<WeChatSide> weChatSides = weChatSideService.chatSides("0");
return getDataTable(weChatSides);
}
/**
* 更新侧边栏信息
*/
// @PreAuthorize("@ss.hasPermi('chat:side:edit')")
@Log(title = "更新侧边栏信息", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody WeChatSide weChatSide) {
return toAjax(weChatSideService.updateWeChatSide(weChatSide));
}
/**
* 群发侧边栏列表
*/
@GetMapping("/h5List")
public TableDataInfo h5List() {
startPage();
List<WeChatSide> weChatSides = weChatSideService.chatSides("1");
return getDataTable(weChatSides);
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.constant.HttpStatus;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.wecom.domain.WeGroupSop;
import com.linkwechat.wecom.domain.dto.WeGroupSopDto;
import com.linkwechat.wecom.domain.vo.WeGroupSopVo;
import com.linkwechat.wecom.service.IWeGroupSopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 社区运营 - 群sop controller
*/
@Api(description = "新客自动拉群 Controller")
@RestController
@RequestMapping(value = "/wecom/communityGroupSop")
public class WeCommunityGroupSopController extends BaseController {
@Autowired
private IWeGroupSopService groupSopService;
/**
* 通过过滤条件获取群sop列表
*
* @param ruleName 规则名称
* @param createBy 创建者
* @param beginTime 创建区间 - 开始时间
* @param endTime 创建区间 - 结束时间
* @return 群sop规则列表
*/
@ApiOperation(value = "通过过滤条件获取群sop列表", httpMethod = "GET")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:list')")
@GetMapping(path = "/list")
public TableDataInfo<List<WeGroupSopVo>> getSopList(
@RequestParam(value = "ruleName", required = false) String ruleName,
@RequestParam(value = "createBy", required = false) String createBy,
@RequestParam(value = "beginTime", required = false) String beginTime,
@RequestParam(value = "endTime", required = false) String endTime
)
{
startPage();
List<WeGroupSopVo> groupSopVoList = groupSopService.getGroupSopList(ruleName, createBy, beginTime, endTime);
return getDataTable(groupSopVoList);
}
/**
* 新增SOP规则
*
* @param groupSopDto 更新数据
* @return 结果
*/
@ApiOperation(value = "新增SOP规则", httpMethod = "POST")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:add')")
@PostMapping(path = "/")
public AjaxResult addGroupSop(@Validated @RequestBody WeGroupSopDto groupSopDto) {
WeGroupSop weGroupSop = new WeGroupSop();
BeanUtils.copyProperties(groupSopDto, weGroupSop);
if (groupSopService.isNameOccupied(weGroupSop)) {
return AjaxResult.error(HttpStatus.BAD_REQUEST, "规则名称已存在");
}
weGroupSop.setCreateBy(SecurityUtils.getUsername());
// 群聊id列表
List<String> groupIdList = groupSopDto.getChatIdList();
// 素材URL
List<Long> materialIdList = groupSopDto.getMaterialIdList();
// 上传的图片的URl列表
List<String> picList = groupSopDto.getPicList();
int affectedRows = groupSopService.addGroupSop(weGroupSop, groupIdList, materialIdList, picList);
if (affectedRows > 0) {
// 添加成功后进行异步消息推送
groupSopService.sendMessage(groupIdList);
}
return toAjax(affectedRows);
}
/**
* 通过规则id获取sop规则
*
* @param ruleId 规则id
* @return 结果
*/
@ApiOperation(value = "通过规则id获取sop规则详情", httpMethod = "GET")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:query')")
@GetMapping(path = "/{ruleId}")
public AjaxResult getGroupSop(@PathVariable("ruleId") Long ruleId) {
WeGroupSopVo groupSopVo = groupSopService.getGroupSopById(ruleId);
if (null == groupSopVo) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "该群SOP规则不存在");
}
return AjaxResult.success(groupSopVo);
}
/**
* 更改SOP规则
*
* @param ruleId SOP规则 id
* @param groupSopDto 更新数据
* @return 结果
*/
@ApiOperation(value = "更改SOP规则", httpMethod = "PUT")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:edit')")
@PutMapping(path = "/{ruleId}")
public AjaxResult updateGroupSop(@PathVariable Long ruleId, @Validated @RequestBody WeGroupSopDto groupSopDto) {
// 校验是否存在
if (null == groupSopService.getGroupSopById(ruleId)) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "该群SOP规则不存在");
}
WeGroupSop weGroupSop = new WeGroupSop();
weGroupSop.setRuleId(ruleId);
BeanUtils.copyProperties(groupSopDto, weGroupSop);
// 校验规则名是否可用
if (groupSopService.isNameOccupied(weGroupSop)) {
return AjaxResult.error(HttpStatus.BAD_REQUEST, "规则名称已存在");
}
weGroupSop.setUpdateBy(SecurityUtils.getUsername());
// 群聊id列表
List<String> groupIdList = groupSopDto.getChatIdList();
// 素材id列表
List<Long> materialIdList = groupSopDto.getMaterialIdList();
// 上传的图片的URl列表
List<String> picList = groupSopDto.getPicList();
return toAjax(groupSopService.updateGroupSop(weGroupSop, groupIdList, materialIdList, picList));
}
/**
* 根据id列表批量删除群sop规则
*
* @param ids 群sop规则列表
* @return 结果
*/
@ApiOperation(value = "根据id列表批量删除群sop规则", httpMethod = "DELETE")
// @PreAuthorize("@ss.hasPermi('wecom:communityGroupSop:remove')")
@DeleteMapping(path = "/{ids}")
public AjaxResult batchDeleteSopRule(@PathVariable("ids") Long[] ids) {
return toAjax(groupSopService.batchRemoveGroupSopByIds(ids));
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.SysUser;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.CommunityTaskType;
import com.linkwechat.system.service.ISysUserService;
import com.linkwechat.wecom.domain.WeKeywordGroupTask;
import com.linkwechat.wecom.service.IWeCommunityKeywordToGroupService;
import com.linkwechat.wecom.service.IWeGroupSopService;
import com.linkwechat.wecom.service.IWePresTagGroupTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* 社区运营H5接口
*
* @Author Hang
* @Date 2021/3/24 10:54
*/
@RestController
@RequestMapping(value = "/wecom/community/h5")
public class WeCommunityH5Controller extends BaseController {
@Autowired
IWePresTagGroupTaskService tagGroupTaskService;
@Autowired
IWeGroupSopService sopService;
@Autowired
IWeCommunityKeywordToGroupService keywordToGroupService;
@Autowired
ISysUserService userService;
/**
* 获取任务对应的执行人列表
* @param taskId 任务id
* @param type 任务类型 1:标签建群任务 2:sop任务
* @return
*/
@GetMapping("/scope/{taskId}")
public AjaxResult getTaskScopeList(@PathVariable("taskId") Long taskId, @RequestParam(value = "type") Integer type) {
if (type.equals(CommunityTaskType.TAG.getType())) {
return AjaxResult.success(tagGroupTaskService.getScopeListByTaskId(taskId));
} else {
return AjaxResult.success(sopService.getScopeListByRuleId(taskId));
}
}
/**
* h5页面根据员工id获取老客标签建群和群sop任务信息
*
* @param emplId 员工id
* @param type 数据类型,0:全部数据 1:老客标签建群数据 2:群SOP数据
* @return
*/
@GetMapping("/{emplId}")
public AjaxResult getEmplTask(@PathVariable("emplId") String emplId, @RequestParam(value = "type") Integer type) {
AjaxResult res = AjaxResult.success();
if (type.equals(CommunityTaskType.TAG.getType())) {
// 老客标签建群数据
res.put("todo", tagGroupTaskService.getFollowerTaskList(emplId, 0));
res.put("done", tagGroupTaskService.getFollowerTaskList(emplId, 1));
} else if (type.equals(CommunityTaskType.SOP.getType())) {
// 群SOP数据
res.put("todo", sopService.getEmplTaskList(emplId, false));
res.put("done", sopService.getEmplTaskList(emplId, true));
} else {
// 全部数据
List todoList = new ArrayList();
List doneList = new ArrayList();
todoList.addAll(tagGroupTaskService.getFollowerTaskList(emplId, 0));
todoList.addAll(sopService.getEmplTaskList(emplId, false));
res.put("todo", todoList);
doneList.addAll(tagGroupTaskService.getFollowerTaskList(emplId, 1));
doneList.addAll(sopService.getEmplTaskList(emplId, true));
res.put("done", doneList);
}
SysUser user = userService.selectUserByUserName(emplId);
boolean isAdmin = user != null && user.isAdmin();
res.put("isAdmin", isAdmin);
return res;
}
/**
* 员工发送老客标签建群任务信息或者发送sop到其客户群之后,变更其任务状态
*
* @param taskId 老客标签建群时代表任务id,sop时,代表规则id
* @param emplId 老客标签建群时代表员工id,sop时,代表群主
* @param type 类型 0:老客标签建群 1:sop
* @return 结果
*/
@GetMapping("/changeStatus")
public AjaxResult changeStatus(@RequestParam("taskId") Long taskId, @RequestParam("emplId") String emplId, @RequestParam("type") Integer type) {
if (type.equals(0)) {
return toAjax(tagGroupTaskService.updateFollowerTaskStatus(taskId, emplId));
} else {
return toAjax(sopService.updateChatSopStatus(taskId, emplId));
}
}
/**
* 用于支持H5页面的名称和关键字检索
*
* @param word 过滤字符
* @return 结果
*/
@GetMapping(path = "/filter")
public TableDataInfo filter(@RequestParam("word") String word) {
startPage();
List<WeKeywordGroupTask> taskList = keywordToGroupService.filterByNameOrKeyword(word);
return getDataTable(taskList);
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.wecom.domain.WeKeywordGroupTask;
import com.linkwechat.wecom.service.IWeCommunityKeywordToGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
* 关键词拉群controller
*/
@Api(tags = "关键词拉群")
@RestController
@RequestMapping(value = "/wecom/communityKeywordGroup")
public class WeCommunityKeywordGroupController extends BaseController {
@Autowired
private IWeCommunityKeywordToGroupService service;
/**
* 根据过滤条件获取关键词拉群任务列表
*/
@ApiOperation(value = "获取关键词拉群任务列表")
// @PreAuthorize("@ss.hasPermi('wecom:communityKeyword:list')")
@GetMapping(path = "/list")
public TableDataInfo<List<WeKeywordGroupTask>> list(WeKeywordGroupTask task) {
startPage();
List<WeKeywordGroupTask> taskList = service.getTaskList(task);
return getDataTable(taskList);
}
/**
* 根据id获取任务详情
*
* @param taskId 任务id
* @return 任务详情
*/
@ApiOperation(value = "获取任务详情")
// @PreAuthorize("@ss.hasPermi('wecom:communityKeyword:query')")
@GetMapping(path = "/{taskId}")
public AjaxResult getTask(@ApiParam("任务id") @PathVariable("taskId") Long taskId) {
return AjaxResult.success(service.getTaskById(taskId));
}
/**
* 添加新任务
*
* @param task 添加任务所需的数据
* @return 结果
*/
@ApiOperation(value = "添加新任务")
// @PreAuthorize("@ss.hasPermi('wecom:communityKeyword:add')")
@PostMapping(path = "/")
public AjaxResult addTask(@RequestBody @Validated WeKeywordGroupTask task) {
if (service.isNameOccupied(task)) {
return AjaxResult.error("关键词拉群任务名称"+ task.getTaskName() +"已存在");
}
task.setCreateBy(SecurityUtils.getUsername());
task.setCreateTime(new Date());
return toAjax(service.addTask(task));
}
/**
* 根据id及更新数据对指定任务进行更新
*/
@ApiOperation(value = "更新任务")
// @PreAuthorize("@ss.hasPermi('wecom:communityKeyword:edit')")
@PutMapping("/{taskId}")
public AjaxResult updateTask(
@ApiParam("任务id") @PathVariable("taskId") Long taskId, @RequestBody @Validated WeKeywordGroupTask task) {
task.setTaskId(taskId);
task.setUpdateBy(SecurityUtils.getUsername());
task.setUpdateTime(new Date());
return toAjax(service.updateTask(task));
}
/**
* 通过id列表批量删除任务
*
* @param ids id列表
* @return 结果
*/
@ApiOperation(value = "批量删除任务")
// @PreAuthorize("@ss.hasPermi('wecom:communityKeyword:remove')")
@DeleteMapping(path = "/{ids}")
public AjaxResult batchDeleteTask(@ApiParam("待删除任务id数组") @PathVariable("ids") Long[] ids) {
return toAjax(service.batchRemoveTaskByIds(ids));
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.HttpStatus;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.wecom.domain.WeCommunityNewGroup;
import com.linkwechat.wecom.domain.WeEmpleCode;
import com.linkwechat.wecom.domain.dto.WeCommunityNewGroupDto;
import com.linkwechat.wecom.domain.vo.WeCommunityNewGroupVo;
import com.linkwechat.wecom.service.IWeCommunityNewGroupService;
import com.linkwechat.wecom.service.IWeEmpleCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 社群运营 新客自动拉群 Controller
*
* @author kewen
* @date 2021-02-19
*/
@Api(tags = "新客自动拉群 Controller")
@RestController
@RequestMapping(value = "/wecom/communityNewGroup")
public class WeCommunityNewGroupController extends BaseController {
@Autowired
private IWeCommunityNewGroupService weCommunityNewGroupService;
@Autowired
private IWeEmpleCodeService weEmpleCodeService;
/**
* 新增新客自动拉群
*/
@ApiOperation(value = "新增新客自动拉群", httpMethod = "POST")
// @PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:add')")
@Log(title = "新客自动拉群", businessType = BusinessType.INSERT)
@PostMapping("/")
public AjaxResult add(@RequestBody @Validated WeCommunityNewGroupDto communityNewGroupDto) {
return toAjax(weCommunityNewGroupService.add(communityNewGroupDto));
}
/**
* 单个下载
*
* @param id 待下载员工活码
* @param request 请求
* @param response 响应
*/
@ApiOperation(value = "员工活码下载", httpMethod = "GET")
// @PreAuthorize("@ss.hasPermi('wecom:code:download')")
@Log(title = "员工活码下载", businessType = BusinessType.OTHER)
@GetMapping("/download")
public void download(String id, HttpServletRequest request, HttpServletResponse response) {
Optional<WeCommunityNewGroupVo> communityNewGroupVo = weCommunityNewGroupService.selectWeCommunityNewGroupById(Long.valueOf(id));
communityNewGroupVo.ifPresent(e -> {
try {
WeEmpleCode empleCode = weEmpleCodeService.selectWeEmpleCodeById(e.getEmplCodeId());
FileUtils.downloadFile(empleCode.getQrCode(), response.getOutputStream());
} catch (IOException exc) {
exc.printStackTrace();
}
});
}
/**
* 员工活码批量下载
*
* @param ids 新客自动拉群ids
* @param request 请求
* @param response 输出
*/
@ApiOperation(value = "员工活码批量下载", httpMethod = "GET")
// @PreAuthorize("@ss.hasPermi('wecom:code:downloadBatch')")
@Log(title = "员工活码批量下载", businessType = BusinessType.OTHER)
@GetMapping("/downloadBatch")
public void downloadBatch(Long[] ids, HttpServletRequest request, HttpServletResponse response) {
List<Map<String, String>> fileList = weCommunityNewGroupService
.selectWeCommunityNewGroupByIds(Arrays.asList(ids))
.stream()
.map(e -> {
WeEmpleCode code = weEmpleCodeService.getById(e.getEmplCodeId());
Map<String, String> fileMap = new HashMap<>();
fileMap.put("fileName", code.getScenario()+".jpg");
fileMap.put("url", code.getQrCode());
return fileMap;
})
.collect(Collectors.toList());
try {
FileUtils.batchDownloadFile(fileList, response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 查询新客自动拉群列表
*/
@ApiOperation(value = "查询新客自动拉群列表", httpMethod = "GET")
// @PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:list')")
@GetMapping("/list")
public TableDataInfo<List<WeCommunityNewGroupVo>> list(WeCommunityNewGroup weCommunityNewGroup) {
startPage();
List<WeCommunityNewGroupVo> communityNewGroupVos = weCommunityNewGroupService.selectWeCommunityNewGroupList(weCommunityNewGroup);
return getDataTable(communityNewGroupVos);
}
/**
* 获取新客自动拉群详细信息
*/
@ApiOperation(value = "获取新客自动拉群详细信息", httpMethod = "GET")
// @PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:query')")
@GetMapping(value = "/{id}")
public AjaxResult<WeCommunityNewGroupVo> getInfo(@PathVariable("id") @ApiParam("主键ID") String id) {
Optional<WeCommunityNewGroupVo> communityNewGroupVo = weCommunityNewGroupService.selectWeCommunityNewGroupById(Long.valueOf(id));
if (communityNewGroupVo.isPresent()) {
return AjaxResult.success(communityNewGroupVo);
}
return AjaxResult.error(HttpStatus.NOT_FOUND, "新客拉群信息不存在");
}
/**
* 修改新客自动拉群
*/
@ApiOperation(value = "修改新客自动拉群", httpMethod = "PUT")
// @PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:edit')")
@Log(title = "新客自动拉群", businessType = BusinessType.UPDATE)
@PutMapping("/{id}")
public AjaxResult edit(@PathVariable("id") String id, @RequestBody @Validated WeCommunityNewGroupDto communityNewGroupDto) {
return toAjax(weCommunityNewGroupService.updateWeCommunityNewGroup(Long.valueOf(id), communityNewGroupDto));
}
/**
* 删除新客自动拉群
*/
@ApiOperation(value = "删除新客自动拉群", httpMethod = "DELETE")
// @PreAuthorize("@ss.hasPermi('wecom:communityNewGroup:remove')")
@Log(title = "新客自动拉群", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(weCommunityNewGroupService.batchRemoveWeCommunityNewGroupByIds(Arrays.asList(ids)));
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.constant.HttpStatus;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.WePresTagGroupTask;
import com.linkwechat.wecom.domain.WePresTagGroupTaskStat;
import com.linkwechat.wecom.domain.vo.WePresTagGroupTaskVo;
import com.linkwechat.wecom.domain.vo.WePresTagTaskListVO;
import com.linkwechat.wecom.service.IWePresTagGroupTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
@Api("老客标签建群接口")
@RestController
@RequestMapping(value = "/wecom/communityPresTagGroup")
public class WeCommunityPresTagGroupController extends BaseController {
@Autowired
IWePresTagGroupTaskService taskService;
/**
* 获取老客标签建群列表数据
*/
// @PreAuthorize("@ss.hasPermi('wecom:communitytagGroup:list')")
@GetMapping(path = "/list")
@ApiOperation(value = "获取老客标签建群任务分页数据", httpMethod = "GET")
public TableDataInfo<List<WePresTagTaskListVO>> getPage(
@RequestParam(value = "taskName", required = false) String taskName,
@RequestParam(value = "sendType", required = false) Integer sendType,
@RequestParam(value = "createBy", required = false) String createBy,
@RequestParam(value = "beginTime", required = false) String beginTime,
@RequestParam(value = "endTime", required = false) String endTime) {
startPage();
List<WePresTagTaskListVO> result = taskService.selectTaskList(taskName, sendType, createBy, beginTime, endTime);
return getDataTable(result);
}
/**
* 新建老客标签建群任务
*/
// @PreAuthorize("@ss.hasPermi('wecom:communitytagGroup:add')")
@PostMapping
@ApiOperation(value = "新建老客标签建群任务", httpMethod = "POST")
public AjaxResult add(@RequestBody @Validated WePresTagGroupTask task) {
// 检测任务名是否可用
if (taskService.isNameOccupied(task)) {
return AjaxResult.error("任务名已存在");
}
task.setCreateBy(SecurityUtils.getUsername());
int affectedRows = taskService.add(task);
// 再发送消息
if (affectedRows > 0) taskService.sendMessage(task);
return toAjax(affectedRows);
}
/**
* 根据获取任务详细信息
*/
// @PreAuthorize("@ss.hasPermi('wecom:communitytagGroup:query')")
@GetMapping(path = "/{id}")
@ApiOperation(value = "根据获取任务详细信息", httpMethod = "GET")
public AjaxResult getInfo(@PathVariable("id") Long id) {
WePresTagGroupTaskVo taskVo = taskService.getTaskById(id);
if (StringUtils.isNull(taskVo)) {
return AjaxResult.error(HttpStatus.NOT_FOUND, "群活码不存在");
}
return AjaxResult.success(taskVo);
}
/**
* 更新任务信息
*/
// @PreAuthorize("@ss.hasPermi('wecom:communitytagGroup:edit')")
@PutMapping(path = "/{id}")
@ApiOperation(value = "更新任务信息", httpMethod = "PUT")
public AjaxResult update(@PathVariable("id") Long id, @RequestBody @Validated WePresTagGroupTask task) {
try {
// 保存新任务
task.setTaskId(id);
task.setUpdateBy(SecurityUtils.getUsername());
task.setUpdateTime(new Date());
taskService.updateTaskAndSendMsg(task);
}catch (Exception e){
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success();
}
/**
* 批量删除老客标签建群任务
*/
// @PreAuthorize("@ss.hasPermi('wecom:communitytagGroup:remove')")
@DeleteMapping(path = "/{ids}")
@ApiOperation(value = "批量删除老客标签建群任务", httpMethod = "DELETE")
public AjaxResult batchRemove(@PathVariable("ids") Long[] ids) {
return toAjax(taskService.batchRemoveTaskByIds(ids));
}
/**
* 根据老客标签建群id及过滤条件,获取其统计信息
*/
// @PreAuthorize("@ss.hasPermi('wecom:communitytagGroup:query')")
@GetMapping(path = "/stat/{id}")
public TableDataInfo<List<WePresTagGroupTaskStat>> getStatInfo(
@PathVariable("id") Long id,
@RequestParam(value = "customerName", required = false) String customerName,
@RequestParam(value = "isInGroup", required = false) Integer isInGroup,
@RequestParam(value = "isSent", required = false) Integer isSent
) {
WePresTagGroupTask task = taskService.getById(id);
startPage();
List<WePresTagGroupTaskStat> stats = taskService.getTaskStat(id, customerName, isInGroup, isSent, task.getSendType());
return getDataTable(stats);
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/wecom/corp")
public class WeCorpAccountController {
@Autowired
private IWeCorpAccountService iWeCorpAccountService;
/**
* 获取当前企业可用密钥
* @return
*/
@GetMapping("/findCurrentCorpAccount")
public AjaxResult findCurrentCorpAccount(){
return AjaxResult.success(
iWeCorpAccountService.findValidWeCorpAccount()
);
}
/**
* 新增或更新企业配置相关
* @param weCorpAccount
* @return
*/
@Log(title = "新增或更新企业配置相关", businessType = BusinessType.INSERT)
@PostMapping("/addOrUpdate")
public AjaxResult addOrUpdate(@RequestBody WeCorpAccount weCorpAccount)
{
iWeCorpAccountService.saveOrUpdate(weCorpAccount);
return AjaxResult.success();
}
/**
* 客户流失通知开关
* @param status
* @return
*/
@Log(title = "客户流失通知开关", businessType = BusinessType.UPDATE)
@PutMapping("/startCustomerChurnNoticeSwitch/{status}")
public AjaxResult startCustomerChurnNoticeSwitch(@PathVariable String status)
{
iWeCorpAccountService.startCustomerChurnNoticeSwitch(status);
return AjaxResult.success();
}
/**
* 客户流失通知开关查询
* @return
*/
@Log(title = "客户流失通知开关查询", businessType = BusinessType.OTHER)
@GetMapping("/getCustomerChurnNoticeSwitch")
public AjaxResult getCustomerChurnNoticeSwitch()
{
return AjaxResult.success("操作成功",iWeCorpAccountService.getCustomerChurnNoticeSwitch());
}
}
package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.enums.TrackState;
import com.linkwechat.common.enums.TrajectoryType;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.constants.SynchRecordConstants;
import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo;
import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import com.linkwechat.wecom.domain.vo.WeOnTheJobCustomerVo;
import com.linkwechat.wecom.service.IWeCustomerService;
import com.linkwechat.wecom.service.IWeCustomerTrajectoryService;
import com.linkwechat.wecom.service.IWeSynchRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
* 企业微信客户Controller
*
* @author ruoyi
* @date 2020-09-13
*/
@RestController
@RequestMapping("/wecom/customer")
public class WeCustomerController extends BaseController
{
@Autowired
@Lazy
private IWeCustomerService weCustomerService;
@Autowired
private IWeCustomerTrajectoryService iWeCustomerTrajectoryService;
@Autowired
private IWeSynchRecordService iWeSynchRecordService;
/**********************************************************************************
**************************************客户列表*************************************
*********************************************************************************/
/**
* 查询企业微信客户列表(分页)
*/
@GetMapping("/findWeCustomerList")
@ApiOperation("查询企业微信客户列表")
public TableDataInfo findWeCustomerList(WeCustomerList weCustomerList)
{
startPage();
List<WeCustomerList> list = weCustomerService.findWeCustomerList(weCustomerList);
TableDataInfo dataTable = getDataTable(list);
dataTable.setLastSyncTime(
iWeSynchRecordService.findUpdateLatestTime(SynchRecordConstants.SYNCH_CUSTOMER)
);//最近同步时间
dataTable.setNoRepeatCustomerTotal(
weCustomerService.noRepeatCountCustomer(weCustomerList)
);//去重客户数
return dataTable;
}
/**
* 查询企业微信客户列表(不分页)
*/
@GetMapping("/findAllWeCustomerList")
@ApiOperation("查询企业微信客户列表")
public AjaxResult findAllWeCustomerList(WeCustomerList weCustomerList)
{
return AjaxResult.success(
weCustomerService.findWeCustomerList(weCustomerList)
);
}
/**
* 客户同步接口
* @return
*/
@Log(title = "企业微信客户同步接口", businessType = BusinessType.DELETE)
@GetMapping("/synchWeCustomer")
public AjaxResult synchWeCustomer() {
try {
weCustomerService.synchWeCustomer();
}catch (CustomException e){
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success(WeConstans.SYNCH_TIP);
}
/**
* 客户打标签
* @param weMakeCustomerTag
* @return
*/
@Log(title = "客户打标签", businessType = BusinessType.UPDATE)
@PostMapping("/makeLabel")
public AjaxResult makeLabel(@RequestBody WeMakeCustomerTag weMakeCustomerTag){
weCustomerService.makeLabel(weMakeCustomerTag);
return AjaxResult.success();
}
/**
* 在职继承
* @param weOnTheJobCustomerVo
* @return
*/
@Log(title="在职继承",businessType = BusinessType.UPDATE)
@PostMapping("/jobExtends")
public AjaxResult jobExtends(@RequestBody WeOnTheJobCustomerVo weOnTheJobCustomerVo){
try {
weCustomerService.allocateOnTheJobCustomer(
weOnTheJobCustomerVo
);
}catch (Exception e){
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success();
}
/**********************************************************************************
**************************************客户详情*************************************
*********************************************************************************/
/**
* 客户详情基础(基础信息+社交关系)
* @param externalUserid
* @param userId
* @param
* @return
*/
@GetMapping("/findWeCustomerBaseInfo")
public AjaxResult findWeCustomerBaseInfo(String externalUserid,String userId,@RequestParam(defaultValue = "0") Integer delFlag){
return AjaxResult.success(
weCustomerService.findWeCustomerDetail(externalUserid,userId,delFlag)
);
}
/**
* 客户画像汇总
* @param externalUserid
* @return
*/
@GetMapping("/findWeCustomerInfoSummary")
public AjaxResult findWeCustomerInfoSummary(String externalUserid,@RequestParam(defaultValue = "0") Integer delFlag){
return AjaxResult.success(
weCustomerService.findWeCustomerInfoSummary(externalUserid,null,delFlag)
);
}
/**
* 单个跟进人客户
* @param externalUserid
* @param userId
* @return
*/
@GetMapping("/findWeCustomerInfoByUserId")
public AjaxResult findWeCustomerInfoByUserId(String externalUserid,String userId,@RequestParam(defaultValue = "0") Integer delFlag){
return AjaxResult.success(
weCustomerService.findWeCustomerInfoByUserId(externalUserid,userId,delFlag)
);
}
/**
* 跟进记录
* @param externalUserid
* @param userId
* @return
*/
@GetMapping("/followUpRecord")
public TableDataInfo followUpRecord(String externalUserid,String userId,Integer trajectoryType){
startPage();
List<WeCustomerTrajectory> weCustomerTrajectories = iWeCustomerTrajectoryService
.followUpRecord(externalUserid, userId, trajectoryType);
return getDataTable(weCustomerTrajectories);
}
/**
* 客户轨迹
* @param externalUserid
* @param userId
* @param trajectoryType 轨迹类型:1:信息动态;2:社交动态;3:活动规则;4:待办动态
* @return
*/
@GetMapping("/findTrajectory")
public AjaxResult findTrajectory(String externalUserid,String userId,Integer trajectoryType){
List<WeCustomerTrajectory> weCustomerTrajectories = iWeCustomerTrajectoryService
.list(new LambdaQueryWrapper<WeCustomerTrajectory>()
.eq(StringUtils.isNotEmpty(externalUserid),WeCustomerTrajectory::getExternalUserid, externalUserid)
.eq(StringUtils.isNotEmpty(userId),WeCustomerTrajectory::getUserId, userId)
.eq(trajectoryType !=null,WeCustomerTrajectory::getTrajectoryType,trajectoryType)
);
return AjaxResult.success(weCustomerTrajectories);
}
}
package com.linkwechat.web.controller.wecom;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.domain.dto.message.AsyncResultDto;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.vo.CustomerMessagePushVo;
import com.linkwechat.wecom.domain.vo.WeCustomerMessageResultVo;
import com.linkwechat.wecom.service.IWeCustomerMessageOriginalService;
import com.linkwechat.wecom.service.IWeCustomerMessagePushService;
import com.linkwechat.wecom.service.IWeCustomerMessgaeResultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.List;
/**
* @description: 企业微信 群发消息 controller
* @author: KeWen
* @create: 2020-12-01 20:23
**/
@Slf4j
@RestController
@RequestMapping("/wecom/customerMessagePush")
public class WeCustomerMessagePushController extends BaseController {
@Autowired
private IWeCustomerMessagePushService weCustomerMessagePushService;
@Autowired
private IWeCustomerMessageOriginalService weCustomerMessageOriginalService;
@Autowired
private IWeCustomerMessgaeResultService weCustomerMessgaeResultService;
/**
* 新增群发消息发送
*/
// @PreAuthorize("@ss.hasPermi('customerMessagePush:push:add')")
@Log(title = "新增群发消息发送", businessType = BusinessType.INSERT)
@PostMapping(value = "add")
public AjaxResult add(@RequestBody CustomerMessagePushDto customerMessagePushDto) {
try {
weCustomerMessagePushService.addWeCustomerMessagePush(customerMessagePushDto);
} catch (JsonProcessingException | ParseException | CloneNotSupportedException e) {
e.printStackTrace();
return AjaxResult.error("群发失败");
}
return AjaxResult.success();
}
/**
* 群发消息列表
*/
// @PreAuthorize("@ss.hasPermi('customerMessagePush:push:list')")
@GetMapping(value = "/list")
public TableDataInfo list(@RequestParam(value = "sender", required = false) String sender
, @RequestParam(value = "content", required = false) String content
, @RequestParam(value = "pushType", required = false) String pushType
, @RequestParam(value = "beginTime", required = false) String beginTime
, @RequestParam(value = "endTime", required = false) String endTime) {
startPage();
List<CustomerMessagePushVo> list = weCustomerMessagePushService.customerMessagePushs(sender, content, pushType, beginTime, endTime);
return getDataTable(list);
}
/**
* 群发消息详情
*/
// @PreAuthorize("@ss.hasPermi('customerMessagePush:push:view')")
@GetMapping(value = "/getInfo")
public AjaxResult getInfo(@RequestParam(value = "messageId") Long messageId) {
CustomerMessagePushVo customerMessagePushVo = weCustomerMessageOriginalService.CustomerMessagePushDetail(messageId);
return AjaxResult.success(customerMessagePushVo);
}
/**
* 群发消息结果列表
*/
// @PreAuthorize("@ss.hasPermi('customerMessagePush:push:pushResults')")
@GetMapping(value = "/pushResults")
public TableDataInfo customerMessagePushResult(@RequestParam(value = "messageId") Long messageId, @RequestParam(value = "status") String status) {
startPage();
List<WeCustomerMessageResultVo> weCustomerMessageResuls = weCustomerMessgaeResultService.customerMessagePushs(messageId, status);
return getDataTable(weCustomerMessageResuls);
}
/**
* 同步消息发送结果
*/
// @PreAuthorize("@ss.hasPermi('customerMessagePush:push:asyncResult')")
@PostMapping(value = "asyncResult")
public AjaxResult asyncResult(@RequestBody AsyncResultDto asyncResultDto) throws JsonProcessingException {
weCustomerMessageOriginalService.asyncResult(asyncResultDto);
return AjaxResult.success();
}
}
package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.Constants;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.wecom.domain.*;
import com.linkwechat.wecom.domain.vo.WeMakeCustomerTag;
import com.linkwechat.wecom.service.*;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @description: 客户画像相关controller
* @author: HaoN
* @create: 2021-03-03 15:10
**/
@RestController
@RequestMapping("/wecom/portrait")
public class WeCustomerPortraitController extends BaseController {
@Autowired
private IWeCustomerService iWeCustomerService;
@Autowired
private IWeTagService iWeTagService;
@Autowired
private IWeTagGroupService iWeTagGroupService;
@Autowired
private IWeUserService iWeUserService;
@Autowired
private IWeGroupService iWeGroupService;
@Autowired
private IWeCustomerTrajectoryService iWeCustomerTrajectoryService;
@Autowired
IWeMomentsService iWeMomentsService;
/**
* 根据客户id和当前企业员工id获取客户详细信息
* @param externalUserid
* @param userId
* @return
*/
@GetMapping(value = "/findWeCustomerInfo")
public AjaxResult findWeCustomerInfo(String externalUserid, String userId) throws Exception {
return AjaxResult.success(
iWeCustomerService.findCustomerByOperUseridAndCustomerId(externalUserid,userId)
);
}
/**
* 客户画像资料更新
* @param weCustomerPortrait
* @return
*/
@PostMapping(value = "/updateWeCustomerInfo")
public AjaxResult updateWeCustomerInfo(@RequestBody WeCustomerPortrait weCustomerPortrait){
iWeCustomerService.updateWeCustomerPortrait(weCustomerPortrait);
return AjaxResult.success();
}
/**
* 获取当前系统所有可用标签
* @param userId 员工id
* @return
*/
@GetMapping(value = "/findAllTags")
public AjaxResult findAllTags(Integer groupTagType,String userId){
if(groupTagType.equals(new Integer(1))){//企业标签
return AjaxResult.success(
iWeTagGroupService.selectWeTagGroupList(
WeTagGroup.builder()
.groupTagType(1)
.build()
)
);
}
return AjaxResult.success(
iWeTagService.list(
new LambdaQueryWrapper<WeTag>()
.eq(WeTag::getDelFlag,new Integer(0))
.eq(WeTag::getOwner,userId)
)
);
}
/**
* 客户画像个人标签库新增
* @param weTagGroup
* @return
*/
@PostMapping("/addOrUpdatePersonTags")
public AjaxResult addOrUpdatePersonTags(@RequestBody WeTagGroup weTagGroup){
List<WeTag> weTags = weTagGroup.getWeTags();
if(CollectionUtil.isNotEmpty(weTags)){
weTags.stream().forEach(k->{
k.setGroupId(weTagGroup.getGroupId());
k.setTagType(new Integer(3));
});
iWeTagService.saveOrUpdateBatch(weTags);
}
return AjaxResult.success();
}
/**
* 个人标签删除
* @param ids
* @return
*/
@DeleteMapping("/deletePersonTag/{ids}")
public AjaxResult deletePersonTag(@PathVariable String[] ids){
iWeTagService.removeByIds(CollectionUtil.newArrayList(ids));
return AjaxResult.success();
}
/**
* 更新客户画像标签
* @param weMakeCustomerTag
* @return
*/
@PostMapping(value = "/updateWeCustomerPorTraitTag")
public AjaxResult updateWeCustomerPorTraitTag(@RequestBody WeMakeCustomerTag weMakeCustomerTag){
iWeCustomerService.makeLabel(weMakeCustomerTag);
return AjaxResult.success();
}
/**
* 查看客户添加的员工
* @param externalUserid
* @return
*/
@GetMapping(value = "/findAddaddEmployes/{externalUserid}")
public AjaxResult findaddEmployes(@PathVariable String externalUserid){
return AjaxResult.success(
iWeUserService.findWeUserByCustomerId(externalUserid)
);
}
/**
* 获取用户添加的群
* @param externalUserid
* @param userId
* @return
*/
@GetMapping(value = "/findAddGroupNum")
public AjaxResult findAddGroupNum(String externalUserid,String userId){
return AjaxResult.success(
iWeGroupService.findWeGroupByCustomer(userId,externalUserid)
);
}
/**
* 获取轨迹信息
* @param trajectoryType
* @return
*/
@GetMapping(value = "/findTrajectory")
public TableDataInfo findTrajectory(String userId,String externalUserid,Integer trajectoryType){
startPage();
LambdaQueryWrapper<WeCustomerTrajectory> ne = new LambdaQueryWrapper<WeCustomerTrajectory>()
.ne(WeCustomerTrajectory::getStatus, Constants.DELETE_CODE)
.eq(WeCustomerTrajectory::getUserId,userId)
.eq(WeCustomerTrajectory::getExternalUserid,externalUserid)
.orderByDesc(WeCustomerTrajectory::getCreateTime);
if(trajectoryType != null){
ne.eq(WeCustomerTrajectory::getTrajectoryType, trajectoryType);
}
return getDataTable(
iWeCustomerTrajectoryService.list(ne)
);
}
/**
*编辑跟进动态
* @param trajectory
* @return
*/
@PostMapping(value = "/addOrEditWaitHandle")
public AjaxResult addOrEditWaitHandle(@RequestBody WeCustomerTrajectory trajectory){
iWeCustomerService.addOrEditWaitHandle(trajectory);
return AjaxResult.success();
}
/**
* 删除轨迹
* @param trajectoryId
* @return
*/
@DeleteMapping(value = "/removeTrajectory/{trajectoryId}")
public AjaxResult removeTrajectory(@PathVariable String trajectoryId){
iWeCustomerTrajectoryService.updateById(WeCustomerTrajectory.builder()
.id(trajectoryId)
.status(Constants.DELETE_CODE)
.build());
return AjaxResult.success();
}
/**
* 完成待办
* @param trajectoryId
* @return
*/
@DeleteMapping(value = "/handleWait/{trajectoryId}")
public AjaxResult handleWait(@PathVariable String trajectoryId){
iWeCustomerTrajectoryService.updateById(WeCustomerTrajectory.builder()
.id(trajectoryId)
.status(Constants.HANDLE_SUCCESS)
.build());
return AjaxResult.success();
}
/**
* 个人朋友圈互动数据同步
* @param userId
* @return
*/
@GetMapping("/synchMomentsInteracte/{userId}")
public AjaxResult synchMomentsInteracte(@PathVariable String userId){
iWeMomentsService.synchMomentsInteracte(CollectionUtil.newArrayList(userId));
return AjaxResult.success(WeConstans.SYNCH_TIP);
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.wecom.domain.WeDepartment;
import com.linkwechat.wecom.service.IWeDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 企业微信组织架构相关Controller
*
* @author ruoyi
* @date 2020-09-01
*/
@Api(tags = "微信组织架构相关接口")
@RestController
@RequestMapping("/wecom/department")
public class WeDepartmentController extends BaseController {
@Autowired
private IWeDepartmentService weDepartmentService;
/**
* 查询企业微信组织架构相关列表
*/
// @PreAuthorize("@ss.hasPermi('contacts:organization:list')")
@GetMapping("/list")
@ApiOperation("获取部门列表")
public AjaxResult<List<WeDepartment>> list() {
List<WeDepartment> list = weDepartmentService.getList();
return AjaxResult.success(list);
}
/**
* 新增企业微信组织架构相关
*/
// @PreAuthorize("@ss.hasPermi('contacts:organization:addMember')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation("添加部门")
public AjaxResult add(@Validated @RequestBody WeDepartment weDepartment) {
weDepartmentService.insert(weDepartment);
return AjaxResult.success();
}
/**
* 修改企业微信组织架构相关
*/
// @PreAuthorize("@ss.hasPermi('contacts:organization:editDep')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation("更新部门")
public AjaxResult edit(@RequestBody WeDepartment weDepartment) {
weDepartmentService.update(weDepartment);
return AjaxResult.success();
}
/**
* 删除企业微信组织架构相关
*/
// @PreAuthorize("@ss.hasPermi('wecom:department:remove')")
@Log(title = "企业微信组织架构相关", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
weDepartmentService.deleteByIds(ids);
return AjaxResult.success();
}
}
package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.wecom.domain.WeEmpleCode;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import com.linkwechat.wecom.service.IWeEmpleCodeService;
import com.linkwechat.wecom.service.IWeFlowerCustomerRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
/**
* 员工活码Controller
*
* @author ruoyi
* @date 2020-10-04
*/
@RestController
@RequestMapping("/wecom/code")
public class WeEmpleCodeController extends BaseController {
@Autowired
private IWeEmpleCodeService weEmpleCodeService;
@Autowired
private IWeFlowerCustomerRelService weFlowerCustomerRelService;
/**
* 查询员工活码列表
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:list')")
@GetMapping("/list")
public TableDataInfo list(WeEmpleCode weEmpleCode) {
startPage();
List<WeEmpleCode> list = weEmpleCodeService.selectWeEmpleCodeList(weEmpleCode);
return getDataTable(list);
}
/**
* 获取员工活码详细信息
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(weEmpleCodeService.selectWeEmpleCodeById(id));
}
/**
* 新增员工活码
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:add')")
@Log(title = "员工活码", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(@RequestBody @Validated WeEmpleCode weEmpleCode) {
try {
weEmpleCodeService.insertWeEmpleCode(weEmpleCode);
return AjaxResult.success();
} catch (Exception e) {
e.printStackTrace();
if (e instanceof WeComException){
return AjaxResult.error(e.getMessage());
}else {
return AjaxResult.error("请求接口异常!");
}
}
}
/**
* 批量新增员工活码
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:batchAdd')")
@Log(title = "批量新增员工活码", businessType = BusinessType.INSERT)
@PostMapping("/batchAdd")
public AjaxResult batchAdd(@RequestBody @Validated WeEmpleCode weEmpleCode) {
try {
weEmpleCodeService.insertWeEmpleCodeBatch(weEmpleCode);
return AjaxResult.success();
} catch (Exception e) {
e.printStackTrace();
if (e instanceof WeComException){
return AjaxResult.error(e.getMessage());
}else {
return AjaxResult.error("请求接口异常!");
}
}
}
/**
* 修改员工活码
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:edit')")
@Log(title = "员工活码", businessType = BusinessType.UPDATE)
@PutMapping("/update")
public AjaxResult edit(@RequestBody WeEmpleCode weEmpleCode) {
weEmpleCodeService.updateWeEmpleCode(weEmpleCode);
return AjaxResult.success();
}
/**
* 删除员工活码
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:remove')")
@Log(title = "员工活码", businessType = BusinessType.DELETE)
@DeleteMapping("/delete/{ids}")
public AjaxResult remove(@PathVariable String ids) {
List<String> idList = Arrays.stream(StringUtils.split(ids, ",")).collect(Collectors.toList());
return toAjax(weEmpleCodeService.batchRemoveWeEmpleCodeIds(idList));
}
/**
* 获取员工二维码
* @param userIds 员工id
* @param departmentIds 部门id
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:qrcode')")
@Log(title = "获取员工二维码", businessType = BusinessType.DELETE)
@GetMapping("/getQrcode")
public AjaxResult getQrcode(String userIds, String departmentIds) {
return AjaxResult.success(weEmpleCodeService.getQrcode(userIds,departmentIds));
}
/**
* 员工活码批量下载
*
* @param ids 员工活码ids
* @param request 请求
* @param response 输出
* @throws Exception
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:downloadBatch')")
@Log(title = "员工活码批量下载", businessType = BusinessType.OTHER)
@GetMapping("/downloadBatch")
public void downloadBatch(String ids, HttpServletRequest request, HttpServletResponse response){
List<Map<String, String>> fileList = Arrays
.stream(Optional.ofNullable(ids).orElse("").split(","))
.filter(StringUtils::isNotEmpty)
.map(id -> {
WeEmpleCode code = weEmpleCodeService.getById(id);
Map<String, String> fileMap = new HashMap<>();
fileMap.put("fileName", code.getUseUserName() + "-" + code.getScenario()+".jpg");
fileMap.put("url", code.getQrCode());
return fileMap;})
.collect(Collectors.toList());
try {
FileUtils.batchDownloadFile(fileList, response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
}
// @PreAuthorize("@ss.hasPermi('wecom:code:download')")
@Log(title = "员工活码下载", businessType = BusinessType.OTHER)
@GetMapping("/download")
public void download(String id, HttpServletRequest request, HttpServletResponse response){
WeEmpleCode weEmpleCode = weEmpleCodeService.selectWeEmpleCodeById(Long.valueOf(id));
if (StringUtils.isEmpty(weEmpleCode.getQrCode())){
throw new CustomException("活码不存在");
}else {
try {
FileUtils.downloadFile(weEmpleCode.getQrCode(), response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 成员添加客户统计
* @return
*/
// @PreAuthorize("@ss.hasPermi('wecom:code:getUserAddCustomerStat')")
@Log(title = "成员添加客户统计", businessType = BusinessType.OTHER)
@GetMapping("/getUserAddCustomerStat")
public AjaxResult getUserAddCustomerStat(WeFlowerCustomerRel weFlowerCustomerRel){
return AjaxResult.success(weFlowerCustomerRelService.getUserAddCustomerStat(weFlowerCustomerRel));
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!