This commit is contained in:
xiangwb
2017-11-03 15:41:52 +08:00
commit 79549977df
58 changed files with 4342 additions and 0 deletions
@@ -0,0 +1,76 @@
package com.xwbing.controller;
import com.alibaba.fastjson.JSONObject;
import com.xwbing.service.MailService;
import com.xwbing.util.JSONObjResult;
import com.xwbing.util.RestMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 项目名称: sb-demo
* 创建时间: 2017/9/18 13:42
* 作者: xiangwb
* 说明:邮件测试控制层
*/
@RestController
@RequestMapping("/mail/")
public class MailTestControl {
@Autowired
private MailService mailService;
/**
* 发送纯文本邮件
*
* @return
*/
@GetMapping("sendSimpleMail")
public JSONObject sendSimpleMail() {
RestMessage restMessage = mailService.sendSimpleMail("786461501@qq.com", "测试邮件", "收到一个纯文本邮件");
return JSONObjResult.toJSONObj(restMessage);
}
/**
* 发送html格式邮件
*
* @return
*/
@GetMapping("sendHtmlMail")
public JSONObject sendHtmlMail() {
String content = "<html>" +
"<body>" +
"<h3>hello world ! 这是一封Html邮件!</h3>" +
"</body>" +
"</html>";
RestMessage restMessage = mailService.sendHtmlMail("786461501@qq.com", "html测试邮件", content);
return JSONObjResult.toJSONObj(restMessage);
}
/**
* 发送带附件邮件
*
* @return
*/
@GetMapping("sendAttachmentsMail")
public JSONObject sendAttachmentsMail() {
String path = "C:\\Users\\admin\\Desktop\\qq.txt";
RestMessage restMessage = mailService.sendAttachmentsMail("786461501@qq.com", "附件测试邮件", "收到一个带附件邮件", path);
return JSONObjResult.toJSONObj(restMessage);
}
/**
* 发送文本内嵌图片邮件
*
* @return
*/
@GetMapping("sendInlineResourceMail")
public JSONObject sendInlineResourceMail() {
String rscId = "pic";
String content = "<html><body>这是有图片的邮件:<img src=\'cid:" + rscId + "\'></body></html>";
String imgPath = "C:\\Users\\admin\\Desktop\\0000001.png";
RestMessage restMessage = mailService.sendInlineResourceMail("786461501@qq.com", "内嵌图片测试邮件", content, imgPath, rscId);
return JSONObjResult.toJSONObj(restMessage);
}
}
@@ -0,0 +1,78 @@
package com.xwbing.controller;
import com.alibaba.fastjson.JSONObject;
import com.xwbing.domain.SysConfig;
import com.xwbing.service.SysConfigService;
import com.xwbing.util.JSONObjResult;
import com.xwbing.util.RestMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Objects;
/**
* 说明: 系统配置控制层
* 项目名称: sbdemo
* 创建时间: 2017/5/10 16:36
* 作者: xiangwb
*/
@Api("系统配置")
@RestController
@RequestMapping("/config/")
public class SysConfigControl {
private static Logger log = LoggerFactory.getLogger(SysConfigControl.class);
@Autowired
private SysConfigService sysConfigService;
@ApiOperation(value = "新增", notes = "新增系统配置信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "code", value = "配置项的key,长度为1-50", paramType = "query", required = true, dataType = "string"),
@ApiImplicitParam(name = "value", value = "配置项的值", paramType = "query", required = true, dataType = "string"),
@ApiImplicitParam(name = "isEnable", value = "是否启用,格式为Y|N", paramType = "query", required = true, dataType = "string"),
@ApiImplicitParam(name = "name", value = "配置名称,长度为1-10", paramType = "query", required = true, dataType = "string")
})
@PostMapping("save")
public JSONObject save(@Valid SysConfig sysConfig) {
String logMsg = "新增系统配置信息";
log.info(logMsg);
RestMessage result = sysConfigService.save(sysConfig);
return JSONObjResult.toJSONObj(result);
}
@ApiOperation(value = "删除", notes = "根据code删除系统配置信息")
@ApiImplicitParam(name = "code", value = "配置项的code", paramType = "query", required = true, dataType = "string")
@PostMapping("removeByCode/{code}")
public JSONObject removeByCode(@PathVariable String code) {
String logMsg = "删除系统配置信息";
log.info(logMsg + " code:{}", code);
if (StringUtils.isEmpty(code)) {
return JSONObjResult.toJSONObj("code不能为空");
}
RestMessage result = sysConfigService.removeByCode(code);
return JSONObjResult.toJSONObj(result);
}
@ApiOperation(value = "查找", notes = "根据key查找系统配置信息")
@ApiImplicitParam(name = "code", value = "配置项的code", paramType = "query", required = true, dataType = "string")
@PostMapping("findByCode")
public JSONObject findByCode(@RequestParam String code) {
String logMsg = "根据code查找系统配置信息";
log.info(logMsg + " code:{}", code);
if (StringUtils.isEmpty(code)) {
return JSONObjResult.toJSONObj("code不能为空");
}
SysConfig one = sysConfigService.findByCode(code);
if (Objects.isNull(one)) {
return JSONObjResult.toJSONObj("该对象不存在");
}
return JSONObjResult.toJSONObj(one, true, "");
}
}
@@ -0,0 +1,40 @@
package com.xwbing.controller;
import com.xwbing.annotation.LogInfo;
import com.xwbing.redis.RedisService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 说明:
* 项目名称: sbdemo
* 创建时间: 2017/5/5 9:21
* 作者: xiangwb
*/
@RestController
@RequestMapping("/test/")
public class TestControl {
@Autowired
private RedisService redisService;
private final Logger logger = LoggerFactory.getLogger(TestControl.class);
@LogInfo("redisLog")
@GetMapping("redis")
public void redis() {
redisService.set("redis", "xwbing");
String s = redisService.get("redis");
System.out.println(s);
logger.info("获取的数据为:" + s);
}
@LogInfo("log")
@GetMapping("log")
public void log() {
logger.info("info");
logger.error("error");
}
}
@@ -0,0 +1,73 @@
package com.xwbing.controller;
import com.alibaba.fastjson.JSONObject;
import com.xwbing.domain.SysUser;
import com.xwbing.service.UserService;
import com.xwbing.util.JSONObjResult;
import com.xwbing.util.RestMessage;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;
/**
* 说明: user
* 项目名称: sbdemo
* 创建时间: 2017/5/10 16:36
* 作者: xiangwb
*/
@RestController
@RequestMapping("/user/")
public class UserControl {
private final static Logger log = LoggerFactory.getLogger(UserControl.class);
@Autowired
private UserService userService;
@PostMapping("save")
public JSONObject save(@Valid SysUser sysUser) {
RestMessage result = userService.save(sysUser);
return JSONObjResult.toJSONObj(result);
}
@PostMapping("removeById")
public JSONObject removeById(@RequestParam String id) {
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage result = userService.removeById(id);
return JSONObjResult.toJSONObj(result);
}
@PostMapping("update")
public JSONObject update(SysUser sysUser) {
if (StringUtils.isEmpty(sysUser.getId())) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage result = userService.update(sysUser);
return JSONObjResult.toJSONObj(result);
}
@GetMapping("findById")
public JSONObject findById(String id) {
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
SysUser sysUser = userService.findOne(id);
if (Objects.isNull(sysUser)) {
return JSONObjResult.toJSONObj("未查到该对象");
}
return JSONObjResult.toJSONObj(sysUser, true, "");
}
@GetMapping("findList")
public JSONObject findList() {
List<SysUser> list = userService.findList();
return JSONObjResult.toJSONObj(list, true, "");
}
}