拦截器显示ip,完善小程序注册,用户手机号不再唯一
This commit is contained in:
parent
a405b4e80e
commit
42d3c2c828
126
doc/代码约定.md
Normal file
126
doc/代码约定.md
Normal file
@ -0,0 +1,126 @@
|
||||
# 代码约定
|
||||
|
||||
#### 1.类文件名以大写驼峰开始,内部主类(class)保持与文件名一致,方便查询。
|
||||
|
||||
#### 2.每个类请标注注释 (特别是拼音缩写起名的类把拼音字母所对应的汉字请标注上)
|
||||
|
||||
```
|
||||
【例】
|
||||
//用于xxx的一个类
|
||||
class MyClass {
|
||||
}
|
||||
```
|
||||
|
||||
#### 3.如果是页面尽量用 xxPage命名,功能拥有复数页面的时候,其首页尽量用xxIndexPage命名。
|
||||
|
||||
```
|
||||
【例】
|
||||
HomePage //首页
|
||||
NewsIndexPage //新闻首页
|
||||
NewsInfoPage //新闻咨询页
|
||||
```
|
||||
|
||||
#### 4.变量命名
|
||||
|
||||
①布尔值请用can/is标记开头命名
|
||||
②int double 如不是width height count等能容易联想到的名字,尽量命名成xxxNum等容易联想的形式.
|
||||
③String型同理 如果不是name title lable等容易联想到的名字,尽量命名成xxxStr/xxxText等容易联想的名字。
|
||||
④类成员变量请用private(小写驼峰命名)
|
||||
|
||||
```
|
||||
【例】
|
||||
int count;
|
||||
var myPage;
|
||||
```
|
||||
|
||||
如是固定参数用,不会改变的变量请在初始化前使用final const开头以区分
|
||||
|
||||
|
||||
```
|
||||
【例】
|
||||
const Color clRed = Colors(0xFFFF0000);
|
||||
final List<String> pageValueList = ["第一","第二","第三"]
|
||||
```
|
||||
|
||||
#### 5.if文等逻辑表达式 判断条件如有两个表达式的时候 请将两个表达式分别用小括号引上
|
||||
|
||||
```
|
||||
【例】
|
||||
错误例: if ( a+1==b && b+2==c) {} ❌
|
||||
正确例: if ((a+1==b) && (b+2==c)) {} ✅
|
||||
|
||||
```
|
||||
|
||||
如更复杂三个及以上表达式的时候请整理各结果方便事后查阅
|
||||
|
||||
```
|
||||
【反例】
|
||||
if ((a=b) && (b=c) || (c=a)) {}
|
||||
```
|
||||
|
||||
```
|
||||
【推荐例】
|
||||
bool isAEqualB = (a==b);
|
||||
bool isBEqualC = (b==c);
|
||||
bool isAEqualC = (a==c);
|
||||
bool isResult = isAEqualB && isBEqualC && isAEqualC;
|
||||
if (isResult) {}
|
||||
```
|
||||
|
||||
#### 6.代码if/for嵌套花括号的层级不要太深(尽量控制在两层之内):
|
||||
|
||||
```
|
||||
【反例】
|
||||
if (isA) {
|
||||
if (isB) {
|
||||
if (isC) {
|
||||
处理1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
处理2
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
【正例】
|
||||
if (!isA) {
|
||||
处理2
|
||||
return
|
||||
}
|
||||
if (!isB) {
|
||||
return
|
||||
}
|
||||
if (isC) {
|
||||
处理1
|
||||
}
|
||||
```
|
||||
|
||||
#### 7.为防止bug,禁止浮点变量用“==”或“!=”与任何数字比较。
|
||||
【禁止用int和double不同变量做等于==”或“!=”判断】
|
||||
(会因为精度不同导致结果误差,如比较请同时转成int或者double,具体请百度)
|
||||
|
||||
#### 8.表示状态的迁移变化的变量 尽量使用enum
|
||||
|
||||
```
|
||||
【不推荐例】
|
||||
int currentPage = 1;
|
||||
changePage(int pageNum)
|
||||
```
|
||||
|
||||
```
|
||||
【推荐例】
|
||||
enum PageType {
|
||||
PAGE1,
|
||||
PAGE2
|
||||
}
|
||||
PageType currentPage = PageType.PAGE1;
|
||||
changePage(PageType pageType)
|
||||
```
|
||||
|
||||
#### 9.每个函数Widget函数的原则不建议超过40行.超过了请整理各要素和封装逻辑,以便维护。(防止行对齐都到屏幕外面去了)
|
||||
|
||||
#### 10.异步类方法/函数(async/Future<T>等)起名时候加定冠词do/run等方便识别.
|
||||
|
||||
#### 11.代码每个函数尽量控制到30行以内,超过30行请尝试封装重构
|
||||
|
0
doc/积分设计.md
Normal file
0
doc/积分设计.md
Normal file
@ -6,6 +6,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.util.SignUtils;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
@ -24,6 +25,7 @@ import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.winery.config.wx.WxMiniProperties;
|
||||
import com.ruoyi.winery.controller.winery.WineryMauserController;
|
||||
import com.ruoyi.winery.domain.winery.WineryMauser;
|
||||
import com.ruoyi.winery.service.IWineryMauserService;
|
||||
|
||||
@ -81,57 +83,85 @@ public class MiniComponent {
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@Autowired
|
||||
private IWineryMauserService iWineryMauserService;
|
||||
|
||||
public WxMaJscode2SessionResult login(String code) throws WxErrorException {
|
||||
|
||||
public WxMaJscode2SessionResult login(String code, Long deptId) throws WxErrorException {
|
||||
|
||||
WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(code);
|
||||
|
||||
WineryMauser user = wineryMauserService.getById(sessionInfo.getOpenid());
|
||||
WineryMauser user = wineryMauserService.getOne(
|
||||
new LambdaQueryWrapper<WineryMauser>()
|
||||
.eq(WineryMauser::getDeptId, deptId)
|
||||
.eq(WineryMauser::getOpenId, sessionInfo.getOpenid())
|
||||
);
|
||||
String key = sessionInfo.getOpenid();
|
||||
redisCache.setCacheObject(key, sessionInfo.getSessionKey(), 7200, TimeUnit.SECONDS);
|
||||
if (user == null) {
|
||||
user = new WineryMauser();
|
||||
user.setOpenId(sessionInfo.getOpenid());
|
||||
user.setDeptId(deptId);
|
||||
log.info("新增user:{}", user);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(sessionInfo.getUnionid())) {
|
||||
user.setUnionId(sessionInfo.getUnionid());
|
||||
}
|
||||
|
||||
user.setStatus(0);
|
||||
wineryMauserService.saveOrUpdate(user);
|
||||
|
||||
return sessionInfo;
|
||||
}
|
||||
|
||||
public AjaxResult registration(String openid, String mobile) {
|
||||
|
||||
public AjaxResult registration(String openid, String mobile, String nickName, Long deptId) {
|
||||
|
||||
SysUser user = new SysUser();
|
||||
|
||||
user.setUserName(openid);
|
||||
String userName = MINI_USER_SYMBOL + openid + "-" + deptId;
|
||||
user.setUserName(userName);
|
||||
user.setPhonenumber(mobile);
|
||||
|
||||
user.setNickName(mobile);
|
||||
user.setDeptId(MINI_DEPTID);
|
||||
user.setNickName(nickName);
|
||||
user.setDeptId(deptId);
|
||||
user.setPassword(MINI_DEFUALT_PASSWORD);
|
||||
user.setRoleIds(new Long[]{MINI_DEFUALT_ROLEID});
|
||||
user.setPostIds(new Long[]{MINI_DEFUALT_POSTID});
|
||||
|
||||
|
||||
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) {
|
||||
return AjaxResult.error("新增用户" + user.getUserName() + "失败,登录账号已存在");
|
||||
} else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
||||
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
} else if (StringUtils.isNotEmpty(user.getEmail())
|
||||
}
|
||||
|
||||
//
|
||||
// else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
||||
// && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
|
||||
// return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
// }
|
||||
|
||||
else if (StringUtils.isNotEmpty(user.getEmail())
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
|
||||
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
}
|
||||
user.setCreateBy(MINI_MANAGE_USER);
|
||||
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
||||
return userService.insertUser(user) > 0 ? AjaxResult.success(user) : AjaxResult.error();
|
||||
|
||||
|
||||
// 创建查找小程序用户
|
||||
WineryMauser wineryMauser = iWineryMauserService.getOne(
|
||||
new LambdaQueryWrapper<WineryMauser>()
|
||||
.eq(WineryMauser::getOpenId, openid)
|
||||
.eq(WineryMauser::getDeptId, user.getDeptId()));
|
||||
|
||||
if (wineryMauser == null) {
|
||||
wineryMauser = new WineryMauser(user);
|
||||
}
|
||||
|
||||
if (userService.insertUser(user) > 0 && iWineryMauserService.saveOrUpdate(wineryMauser)) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put(Constants.TOKEN, loginByMini(userName));
|
||||
return ajax;
|
||||
} else {
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,23 +170,23 @@ public class MiniComponent {
|
||||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
public String loginByMini(String openId) {
|
||||
public String loginByMini(String userName) {
|
||||
// 用户验证
|
||||
Authentication authentication = null;
|
||||
try {
|
||||
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
||||
authentication = authenticationManager
|
||||
.authenticate(new UsernamePasswordAuthenticationToken(openId, MINI_DEFUALT_PASSWORD));
|
||||
.authenticate(new UsernamePasswordAuthenticationToken(userName, MINI_DEFUALT_PASSWORD));
|
||||
} catch (Exception e) {
|
||||
if (e instanceof BadCredentialsException) {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(openId, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||
throw new UserPasswordNotMatchException();
|
||||
} else {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(openId, Constants.LOGIN_FAIL, e.getMessage()));
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGIN_FAIL, e.getMessage()));
|
||||
throw new CustomException(e.getMessage());
|
||||
}
|
||||
}
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(openId, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||
// 生成token
|
||||
return tokenService.createToken(loginUser);
|
||||
@ -172,7 +202,12 @@ public class MiniComponent {
|
||||
public String getMobile(JSONObject json) {
|
||||
|
||||
String openid = json.getStr("openid");
|
||||
WineryMauser user = wineryMauserService.getById(openid);
|
||||
String deptId = json.getStr("deptId");
|
||||
// 创建查找小程序用户
|
||||
WineryMauser user = iWineryMauserService.getOne(
|
||||
new LambdaQueryWrapper<WineryMauser>()
|
||||
.eq(WineryMauser::getOpenId, openid)
|
||||
.eq(WineryMauser::getDeptId, deptId));
|
||||
|
||||
JSONObject detail = json.getJSONObject("detail");
|
||||
String encryptedData = detail.getStr("encryptedData");
|
||||
@ -210,7 +245,6 @@ public class MiniComponent {
|
||||
|
||||
Map<String, String> params = json.toBean(HashMap.class);
|
||||
|
||||
|
||||
json.set("sign", SignUtils.createSign(params, "HMAC-SHA256", wxMiniProperties.getMchKey(), (String[]) null));
|
||||
|
||||
|
||||
|
@ -28,6 +28,9 @@ import com.ruoyi.winery.service.INewsContentService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getDeptId;
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getUsername;
|
||||
|
||||
/**
|
||||
* 新闻资讯Controller
|
||||
*
|
||||
@ -50,7 +53,7 @@ public class NewsContentController extends BaseController {
|
||||
startPage();
|
||||
LambdaQueryWrapper<NewsContent> lqw = Wrappers.lambdaQuery(newsContent);
|
||||
|
||||
lqw.eq(NewsContent::getDeptId, getDeptId(token));
|
||||
lqw.eq(NewsContent::getDeptId, getDeptId());
|
||||
|
||||
if (StringUtils.isNotBlank(newsContent.getNewsTitle())) {
|
||||
lqw.eq(NewsContent::getNewsTitle, newsContent.getNewsTitle());
|
||||
@ -100,7 +103,8 @@ public class NewsContentController extends BaseController {
|
||||
@Log(title = "新闻资讯", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(UsernamePasswordAuthenticationToken token, @RequestBody NewsContent newsContent) {
|
||||
newsContent.setDeptId(getDeptId(token));
|
||||
newsContent.setDeptId(getDeptId());
|
||||
newsContent.setCreateBy(getUsername());
|
||||
return toAjax(iNewsContentService.save(newsContent) ? 1 : 0);
|
||||
}
|
||||
|
||||
@ -111,6 +115,7 @@ public class NewsContentController extends BaseController {
|
||||
@Log(title = "新闻资讯", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody NewsContent newsContent) {
|
||||
newsContent.setUpdateBy(getUsername());
|
||||
return toAjax(iNewsContentService.updateById(newsContent) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@ -28,6 +29,8 @@ import com.ruoyi.winery.service.IGoodsMainService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.*;
|
||||
|
||||
/**
|
||||
* 商品信息Controller
|
||||
*
|
||||
@ -50,7 +53,7 @@ public class GoodsMainController extends BaseController {
|
||||
startPage();
|
||||
LambdaQueryWrapper<GoodsMain> lqw = Wrappers.lambdaQuery(goodsMain);
|
||||
|
||||
lqw.eq(GoodsMain::getDeptId, getDeptId(token));
|
||||
lqw.eq(!isAdmin(), GoodsMain::getDeptId, getDeptId());
|
||||
|
||||
if (StringUtils.isNotBlank(goodsMain.getGoodsName())) {
|
||||
lqw.like(GoodsMain::getGoodsName, goodsMain.getGoodsName());
|
||||
@ -106,7 +109,7 @@ public class GoodsMainController extends BaseController {
|
||||
@Log(title = "商品信息", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(UsernamePasswordAuthenticationToken token, @RequestBody GoodsMain goodsMain) {
|
||||
goodsMain.setDeptId(getDeptId(token));
|
||||
goodsMain.setDeptId(getDeptId());
|
||||
return toAjax(iWineryGoodsService.save(goodsMain) ? 1 : 0);
|
||||
}
|
||||
|
||||
@ -117,6 +120,7 @@ public class GoodsMainController extends BaseController {
|
||||
@Log(title = "商品信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody GoodsMain goodsMain) {
|
||||
goodsMain.setUpdateBy(getUsername());
|
||||
return toAjax(iWineryGoodsService.updateById(goodsMain) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.winery.domain.goods.GoodsMain;
|
||||
import com.ruoyi.winery.domain.goods.GoodsSpec;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@ -28,6 +29,8 @@ import com.ruoyi.winery.service.IGoodsSpecService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.*;
|
||||
|
||||
/**
|
||||
* 商品规格Controller
|
||||
*
|
||||
@ -51,7 +54,7 @@ public class GoodsSpecController extends BaseController {
|
||||
|
||||
LambdaQueryWrapper<GoodsSpec> lqw = Wrappers.lambdaQuery(goodsSpec);
|
||||
|
||||
lqw.eq(GoodsSpec::getDeptId, getDeptId(token));
|
||||
lqw.eq(!isAdmin(), GoodsSpec::getDeptId, getDeptId());
|
||||
|
||||
if (StringUtils.isNotBlank(goodsSpec.getSpecName())) {
|
||||
lqw.like(GoodsSpec::getSpecName, goodsSpec.getSpecName());
|
||||
@ -101,7 +104,7 @@ public class GoodsSpecController extends BaseController {
|
||||
@Log(title = "商品规格", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(UsernamePasswordAuthenticationToken token, @RequestBody GoodsSpec goodsSpec) {
|
||||
goodsSpec.setDeptId(getDeptId(token));
|
||||
goodsSpec.setDeptId(getDeptId());
|
||||
return toAjax(iWineryGoodsSpecService.save(goodsSpec) ? 1 : 0);
|
||||
}
|
||||
|
||||
@ -112,6 +115,7 @@ public class GoodsSpecController extends BaseController {
|
||||
@Log(title = "商品规格", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody GoodsSpec goodsSpec) {
|
||||
goodsSpec.setUpdateBy(getUsername());
|
||||
return toAjax(iWineryGoodsSpecService.updateById(goodsSpec) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
@ -23,14 +24,16 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ruoyi.winery.define.MiniDefine.MINI_USER_SYMBOL;
|
||||
|
||||
/**
|
||||
* @author tottimctj
|
||||
* @since 2020-11-10
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/winery/mini")
|
||||
@RequestMapping("/winery/mini/user")
|
||||
@Slf4j
|
||||
public class MiniController {
|
||||
public class MiniUserController {
|
||||
|
||||
|
||||
@Autowired
|
||||
@ -66,35 +69,31 @@ public class MiniController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过微信api授权获取手机号并注册
|
||||
* 小程序进行注册用户
|
||||
*
|
||||
* @param json
|
||||
* @return
|
||||
*/
|
||||
@Log(title = "发送小程序手机号码并注册", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/registrationByMiniMobile")
|
||||
@Log(title = "小程序进行注册用户", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/registrationByMini")
|
||||
@RepeatSubmit
|
||||
AjaxResult postMobileRegistration(@RequestBody JSONObject json) {
|
||||
|
||||
String mobile = miniComponent.getMobile(json);
|
||||
if (StrUtil.isBlank(mobile)) {
|
||||
return AjaxResult.error("获取失败!");
|
||||
}
|
||||
JSONObject rsp = new JSONObject();
|
||||
rsp.set("mobile", mobile);
|
||||
String openid = json.getStr("openid");
|
||||
return miniComponent.registration(openid, mobile);
|
||||
String mobile = json.getStr("mobile");
|
||||
Long deptId = json.getLong("deptId");
|
||||
String nickName = json.getJSONObject("userInfo").getStr("nickName");
|
||||
return miniComponent.registration(openid, mobile, nickName, deptId);
|
||||
}
|
||||
|
||||
|
||||
@Log(title = "微信小程序登录", businessType = BusinessType.OTHER)
|
||||
@Log(title = "微信小程序登录换取openid", businessType = BusinessType.OTHER)
|
||||
@GetMapping("/getSession")
|
||||
public AjaxResult getSession(@RequestParam("code") String code) throws WxErrorException {
|
||||
|
||||
WxMaJscode2SessionResult sessionInfo = miniComponent.login(code);
|
||||
|
||||
public AjaxResult getSession(@RequestParam("code") String code, @RequestParam("deptId") Long deptId) throws WxErrorException {
|
||||
WxMaJscode2SessionResult sessionInfo = miniComponent.login(code, deptId);
|
||||
JSONObject json = new JSONObject();
|
||||
json.set("openid", sessionInfo.getOpenid());
|
||||
log.info("微信小程序获取openid信息成功");
|
||||
log.info("微信小程序获取openid信息成功:{}", sessionInfo.getOpenid());
|
||||
|
||||
return AjaxResult.success(json);
|
||||
}
|
||||
@ -104,8 +103,9 @@ public class MiniController {
|
||||
@PostMapping("/loginByMini")
|
||||
public AjaxResult loginByMini(@RequestBody JSONObject json) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
String userAccount = MINI_USER_SYMBOL + json.getStr("openid") + "-" + json.getLong("deptId");
|
||||
// 生成令牌
|
||||
String token = miniComponent.loginByMini(json.getStr("openid"));
|
||||
String token = miniComponent.loginByMini(userAccount);
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
return ajax;
|
||||
}
|
@ -1,97 +1,97 @@
|
||||
package com.ruoyi.winery.controller.mini;
|
||||
|
||||
import com.itextpdf.io.font.FontProgram;
|
||||
import com.itextpdf.io.font.FontProgramFactory;
|
||||
import com.itextpdf.io.font.PdfEncodings;
|
||||
import com.itextpdf.io.image.ImageDataFactory;
|
||||
import com.itextpdf.kernel.font.PdfFont;
|
||||
import com.itextpdf.kernel.font.PdfFontFactory;
|
||||
import com.itextpdf.kernel.geom.PageSize;
|
||||
import com.itextpdf.kernel.geom.Rectangle;
|
||||
import com.itextpdf.kernel.pdf.PdfDocument;
|
||||
import com.itextpdf.kernel.pdf.PdfWriter;
|
||||
import com.itextpdf.kernel.pdf.xobject.PdfImageXObject;
|
||||
import com.itextpdf.layout.Document;
|
||||
import com.itextpdf.layout.element.Paragraph;
|
||||
import com.itextpdf.layout.element.Text;
|
||||
import com.itextpdf.layout.property.BackgroundImage;
|
||||
import com.itextpdf.layout.property.TextAlignment;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* @author tottimctj
|
||||
* @since 2020-11-10
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/winery/test")
|
||||
@Slf4j
|
||||
public class TestController {
|
||||
|
||||
public static final String REGULAR =
|
||||
"classpath:/fonts/PingFang_Heavy.ttf";
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
FontProgram fontProgram =
|
||||
FontProgramFactory.createFont(REGULAR);
|
||||
|
||||
|
||||
String path = "/Users/tottimctj/Downloads/temp.pdf";
|
||||
|
||||
PdfFont font = PdfFontFactory.createFont("STSongStd-Light", "UniGB-UCS2-H", false);
|
||||
PdfFont font2 = PdfFontFactory.createFont(
|
||||
fontProgram, PdfEncodings.IDENTITY_H, true);
|
||||
|
||||
PdfWriter writer = new PdfWriter(new FileOutputStream(new File(path)));
|
||||
PdfDocument pdf = new PdfDocument(writer);
|
||||
Document document = new Document(pdf, new PageSize(500f,505f));
|
||||
document.setMargins(0, 0, 0, 0);
|
||||
Paragraph p = new Paragraph();
|
||||
p.setMarginTop(0);
|
||||
p.setHeight(500);
|
||||
p.setWidth(500);
|
||||
p.setFontSize(25);
|
||||
// Text text1 = new Text("字体1希望软件!").setFont(font);
|
||||
//package com.ruoyi.winery.controller.mini;
|
||||
//
|
||||
// text1.setTextAlignment(TextAlignment.CENTER);
|
||||
// text1.setRelativePosition(200, 200, 200, 200);
|
||||
// p.add(text1);
|
||||
|
||||
Text text2 = new Text("字体2希望软件!").setFont(font2);
|
||||
text2.setTextAlignment(TextAlignment.CENTER);
|
||||
text2.setRelativePosition(0, 200, 0, 0);
|
||||
p.add(text2);
|
||||
|
||||
// p.setBorder(new SolidBorder(DeviceGray.BLACK,0.5f));//边框
|
||||
// p.setBackgroundColor(ColorConstants.GREEN);//绿色你懂的
|
||||
|
||||
|
||||
// Image image = new Image(ImageDataFactory.create("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=28918940,1444141489&fm=26&gp=0.jpg"));
|
||||
// image.setHeight(300);
|
||||
// image.setWidth(200);
|
||||
// BackgroundSize backgroundSize = new BackgroundSize();
|
||||
|
||||
|
||||
PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.create("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=28918940,1444141489&fm=26&gp=0.jpg"));
|
||||
|
||||
BackgroundImage backgroundImage = new BackgroundImage(imageXObject);
|
||||
p.setBackgroundImage(backgroundImage);
|
||||
|
||||
|
||||
document.add(p);
|
||||
|
||||
|
||||
document.close();
|
||||
writer.close();
|
||||
pdf.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//import com.itextpdf.io.font.FontProgram;
|
||||
//import com.itextpdf.io.font.FontProgramFactory;
|
||||
//import com.itextpdf.io.font.PdfEncodings;
|
||||
//import com.itextpdf.io.image.ImageDataFactory;
|
||||
//import com.itextpdf.kernel.font.PdfFont;
|
||||
//import com.itextpdf.kernel.font.PdfFontFactory;
|
||||
//import com.itextpdf.kernel.geom.PageSize;
|
||||
//import com.itextpdf.kernel.geom.Rectangle;
|
||||
//import com.itextpdf.kernel.pdf.PdfDocument;
|
||||
//import com.itextpdf.kernel.pdf.PdfWriter;
|
||||
//import com.itextpdf.kernel.pdf.xobject.PdfImageXObject;
|
||||
//import com.itextpdf.layout.Document;
|
||||
//import com.itextpdf.layout.element.Paragraph;
|
||||
//import com.itextpdf.layout.element.Text;
|
||||
//import com.itextpdf.layout.property.BackgroundImage;
|
||||
//import com.itextpdf.layout.property.TextAlignment;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.FileOutputStream;
|
||||
//
|
||||
///**
|
||||
// * @author tottimctj
|
||||
// * @since 2020-11-10
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("/winery/test")
|
||||
//@Slf4j
|
||||
//public class TestController {
|
||||
//
|
||||
// public static final String REGULAR =
|
||||
// "classpath:/fonts/PingFang_Heavy.ttf";
|
||||
//
|
||||
//
|
||||
// public static void main(String[] args) throws Exception {
|
||||
//
|
||||
// FontProgram fontProgram =
|
||||
// FontProgramFactory.createFont(REGULAR);
|
||||
//
|
||||
//
|
||||
// String path = "/Users/tottimctj/Downloads/temp.pdf";
|
||||
//
|
||||
// PdfFont font = PdfFontFactory.createFont("STSongStd-Light", "UniGB-UCS2-H", false);
|
||||
// PdfFont font2 = PdfFontFactory.createFont(
|
||||
// fontProgram, PdfEncodings.IDENTITY_H, true);
|
||||
//
|
||||
// PdfWriter writer = new PdfWriter(new FileOutputStream(new File(path)));
|
||||
// PdfDocument pdf = new PdfDocument(writer);
|
||||
// Document document = new Document(pdf, new PageSize(500f,505f));
|
||||
// document.setMargins(0, 0, 0, 0);
|
||||
// Paragraph p = new Paragraph();
|
||||
// p.setMarginTop(0);
|
||||
// p.setHeight(500);
|
||||
// p.setWidth(500);
|
||||
// p.setFontSize(25);
|
||||
//// Text text1 = new Text("字体1希望软件!").setFont(font);
|
||||
////
|
||||
//// text1.setTextAlignment(TextAlignment.CENTER);
|
||||
//// text1.setRelativePosition(200, 200, 200, 200);
|
||||
//// p.add(text1);
|
||||
//
|
||||
// Text text2 = new Text("字体2希望软件!").setFont(font2);
|
||||
// text2.setTextAlignment(TextAlignment.CENTER);
|
||||
// text2.setRelativePosition(0, 200, 0, 0);
|
||||
// p.add(text2);
|
||||
//
|
||||
//// p.setBorder(new SolidBorder(DeviceGray.BLACK,0.5f));//边框
|
||||
//// p.setBackgroundColor(ColorConstants.GREEN);//绿色你懂的
|
||||
//
|
||||
//
|
||||
//// Image image = new Image(ImageDataFactory.create("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=28918940,1444141489&fm=26&gp=0.jpg"));
|
||||
//// image.setHeight(300);
|
||||
//// image.setWidth(200);
|
||||
//// BackgroundSize backgroundSize = new BackgroundSize();
|
||||
//
|
||||
//
|
||||
// PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.create("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=28918940,1444141489&fm=26&gp=0.jpg"));
|
||||
//
|
||||
// BackgroundImage backgroundImage = new BackgroundImage(imageXObject);
|
||||
// p.setBackgroundImage(backgroundImage);
|
||||
//
|
||||
//
|
||||
// document.add(p);
|
||||
//
|
||||
//
|
||||
// document.close();
|
||||
// writer.close();
|
||||
// pdf.close();
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -27,6 +27,9 @@ import com.ruoyi.winery.service.IWineryFoodSafetyService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getDeptId;
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getUsername;
|
||||
|
||||
/**
|
||||
* 食品安全详情Controller
|
||||
*
|
||||
@ -118,6 +121,8 @@ public class WineryFoodSafetyController extends BaseController {
|
||||
@Log(title = "食品安全详情" , businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody WineryFoodSafety wineryFoodSafety) {
|
||||
wineryFoodSafety.setCreateBy(getUsername());
|
||||
wineryFoodSafety.setDeptId(getDeptId());
|
||||
return toAjax(iWineryFoodSafetyService.save(wineryFoodSafety) ? 1 : 0);
|
||||
}
|
||||
|
||||
@ -128,6 +133,7 @@ public class WineryFoodSafetyController extends BaseController {
|
||||
@Log(title = "食品安全详情" , businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody WineryFoodSafety wineryFoodSafety) {
|
||||
wineryFoodSafety.setUpdateBy(getUsername());
|
||||
return toAjax(iWineryFoodSafetyService.updateById(wineryFoodSafety) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
@ -27,15 +27,18 @@ import com.ruoyi.winery.service.IWineryMauserService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getDeptId;
|
||||
import static com.ruoyi.common.utils.SecurityUtils.isAdmin;
|
||||
|
||||
/**
|
||||
* 小程序用户Controller
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2020-12-17
|
||||
*/
|
||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||
@RestController
|
||||
@RequestMapping("/winery/winery_mauser" )
|
||||
@RequestMapping("/winery/winery_mauser")
|
||||
public class WineryMauserController extends BaseController {
|
||||
|
||||
private final IWineryMauserService iWineryMauserService;
|
||||
@ -45,28 +48,31 @@ public class WineryMauserController extends BaseController {
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(WineryMauser wineryMauser)
|
||||
{
|
||||
public TableDataInfo list(WineryMauser wineryMauser) {
|
||||
startPage();
|
||||
LambdaQueryWrapper<WineryMauser> lqw = Wrappers.lambdaQuery(wineryMauser);
|
||||
if (StringUtils.isNotBlank(wineryMauser.getStatus())){
|
||||
lqw.eq(WineryMauser::getStatus ,wineryMauser.getStatus());
|
||||
|
||||
lqw.eq(!isAdmin(),WineryMauser::getDeptId, getDeptId());
|
||||
|
||||
if (wineryMauser.getStatus() != null) {
|
||||
lqw.eq(WineryMauser::getStatus, wineryMauser.getStatus());
|
||||
}
|
||||
if (StringUtils.isNotBlank(wineryMauser.getMobile())){
|
||||
lqw.eq(WineryMauser::getMobile ,wineryMauser.getMobile());
|
||||
if (StringUtils.isNotBlank(wineryMauser.getMobile())) {
|
||||
lqw.eq(WineryMauser::getMobile, wineryMauser.getMobile());
|
||||
}
|
||||
if (StringUtils.isNotBlank(wineryMauser.getNickName())){
|
||||
lqw.like(WineryMauser::getNickName ,wineryMauser.getNickName());
|
||||
if (StringUtils.isNotBlank(wineryMauser.getNickName())) {
|
||||
lqw.like(WineryMauser::getNickName, wineryMauser.getNickName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(wineryMauser.getUnionId())){
|
||||
lqw.eq(WineryMauser::getUnionId ,wineryMauser.getUnionId());
|
||||
if (StringUtils.isNotBlank(wineryMauser.getUnionId())) {
|
||||
lqw.eq(WineryMauser::getUnionId, wineryMauser.getUnionId());
|
||||
}
|
||||
if (wineryMauser.getCreateTime() != null){
|
||||
lqw.eq(WineryMauser::getCreateTime ,wineryMauser.getCreateTime());
|
||||
}
|
||||
if (StringUtils.isNotBlank(wineryMauser.getDeptId())){
|
||||
lqw.eq(WineryMauser::getDeptId ,wineryMauser.getDeptId());
|
||||
if (wineryMauser.getCreateTime() != null) {
|
||||
lqw.eq(WineryMauser::getCreateTime, wineryMauser.getCreateTime());
|
||||
}
|
||||
|
||||
|
||||
lqw.eq(!isAdmin(), WineryMauser::getDeptId, getDeptId());
|
||||
|
||||
List<WineryMauser> list = iWineryMauserService.list(lqw);
|
||||
return getDataTable(list);
|
||||
}
|
||||
@ -74,40 +80,40 @@ public class WineryMauserController extends BaseController {
|
||||
/**
|
||||
* 导出小程序用户列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:export')" )
|
||||
@Log(title = "小程序用户" , businessType = BusinessType.EXPORT)
|
||||
@GetMapping("/export" )
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:export')")
|
||||
@Log(title = "小程序用户", businessType = BusinessType.EXPORT)
|
||||
@GetMapping("/export")
|
||||
public AjaxResult export(WineryMauser wineryMauser) {
|
||||
LambdaQueryWrapper<WineryMauser> lqw = new LambdaQueryWrapper<WineryMauser>(wineryMauser);
|
||||
List<WineryMauser> list = iWineryMauserService.list(lqw);
|
||||
ExcelUtil<WineryMauser> util = new ExcelUtil<WineryMauser>(WineryMauser. class);
|
||||
return util.exportExcel(list, "winery_mauser" );
|
||||
ExcelUtil<WineryMauser> util = new ExcelUtil<WineryMauser>(WineryMauser.class);
|
||||
return util.exportExcel(list, "winery_mauser");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小程序用户详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:query')" )
|
||||
@GetMapping(value = "/{openId}" )
|
||||
public AjaxResult getInfo(@PathVariable("openId" ) String openId) {
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:query')")
|
||||
@GetMapping(value = "/{openId}")
|
||||
public AjaxResult getInfo(@PathVariable("openId") String openId) {
|
||||
return AjaxResult.success(iWineryMauserService.getById(openId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增小程序用户
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:add')" )
|
||||
@Log(title = "小程序用户" , businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody WineryMauser wineryMauser) {
|
||||
return toAjax(iWineryMauserService.save(wineryMauser) ? 1 : 0);
|
||||
}
|
||||
// /**
|
||||
// * 新增小程序用户
|
||||
// */
|
||||
// @PreAuthorize("@ss.hasPermi('winery:winery_mauser:add')")
|
||||
// @Log(title = "小程序用户", businessType = BusinessType.INSERT)
|
||||
// @PostMapping
|
||||
// public AjaxResult add(@RequestBody WineryMauser wineryMauser) {
|
||||
// return toAjax(iWineryMauserService.save(wineryMauser) ? 1 : 0);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 修改小程序用户
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:edit')" )
|
||||
@Log(title = "小程序用户" , businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:edit')")
|
||||
@Log(title = "小程序用户", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody WineryMauser wineryMauser) {
|
||||
return toAjax(iWineryMauserService.updateById(wineryMauser) ? 1 : 0);
|
||||
@ -116,9 +122,9 @@ public class WineryMauserController extends BaseController {
|
||||
/**
|
||||
* 删除小程序用户
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:remove')" )
|
||||
@Log(title = "小程序用户" , businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{openIds}" )
|
||||
@PreAuthorize("@ss.hasPermi('winery:winery_mauser:remove')")
|
||||
@Log(title = "小程序用户", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{openIds}")
|
||||
public AjaxResult remove(@PathVariable String[] openIds) {
|
||||
return toAjax(iWineryMauserService.removeByIds(Arrays.asList(openIds)) ? 1 : 0);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.winery.domain.goods.GoodsSpec;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -27,6 +28,8 @@ import com.ruoyi.winery.service.IWineryOrdersService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.*;
|
||||
|
||||
/**
|
||||
* 客户订单Controller
|
||||
*
|
||||
@ -49,9 +52,9 @@ public class WineryOrdersController extends BaseController {
|
||||
{
|
||||
startPage();
|
||||
LambdaQueryWrapper<WineryOrders> lqw = Wrappers.lambdaQuery(wineryOrders);
|
||||
if (wineryOrders.getDeptId() != null){
|
||||
lqw.eq(WineryOrders::getDeptId ,wineryOrders.getDeptId());
|
||||
}
|
||||
|
||||
lqw.eq(!isAdmin(), WineryOrders::getDeptId, getDeptId());
|
||||
|
||||
if (wineryOrders.getGoodsId() != null){
|
||||
lqw.eq(WineryOrders::getGoodsId ,wineryOrders.getGoodsId());
|
||||
}
|
||||
@ -109,6 +112,8 @@ public class WineryOrdersController extends BaseController {
|
||||
@Log(title = "客户订单" , businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody WineryOrders wineryOrders) {
|
||||
wineryOrders.setCreateBy(getUsername());
|
||||
wineryOrders.setDeptId(getDeptId());
|
||||
return toAjax(iWineryOrdersService.save(wineryOrders) ? 1 : 0);
|
||||
}
|
||||
|
||||
@ -119,6 +124,7 @@ public class WineryOrdersController extends BaseController {
|
||||
@Log(title = "客户订单" , businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody WineryOrders wineryOrders) {
|
||||
wineryOrders.setUpdateBy(getUsername());
|
||||
return toAjax(iWineryOrdersService.updateById(wineryOrders) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,9 @@ import com.ruoyi.winery.service.IWineryWineSpecDetailService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getDeptId;
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getUsername;
|
||||
|
||||
/**
|
||||
* 葡萄酒规格详情Controller
|
||||
*
|
||||
@ -121,6 +124,8 @@ public class WineryWineSpecDetailController extends BaseController {
|
||||
@Log(title = "葡萄酒规格详情" , businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody WineryWineSpecDetail wineryWineSpecDetail) {
|
||||
wineryWineSpecDetail.setCreateBy(getUsername());
|
||||
wineryWineSpecDetail.setDeptId(getDeptId());
|
||||
return toAjax(iWineryWineSpecDetailService.save(wineryWineSpecDetail) ? 1 : 0);
|
||||
}
|
||||
|
||||
@ -131,6 +136,7 @@ public class WineryWineSpecDetailController extends BaseController {
|
||||
@Log(title = "葡萄酒规格详情" , businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody WineryWineSpecDetail wineryWineSpecDetail) {
|
||||
wineryWineSpecDetail.setUpdateBy(getUsername());
|
||||
return toAjax(iWineryWineSpecDetailService.updateById(wineryWineSpecDetail) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ public class MiniDefine {
|
||||
|
||||
public static final String MINI_MANAGE_USER = "admin";
|
||||
|
||||
public static final String MINI_USER_SYMBOL = "mini-";
|
||||
|
||||
public static final Long MINI_DEPTID = 100L;
|
||||
|
||||
public static final String MINI_DEFUALT_PASSWORD = "Xiao4rHospSoft";
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.ruoyi.winery.domain.winery;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -32,14 +33,17 @@ public class WineryMauser implements Serializable {
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
|
||||
/** 小程序userid */
|
||||
@TableId(value = "id",type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
/** 小程序userid */
|
||||
@Excel(name = "小程序userid")
|
||||
@TableId(value = "open_id")
|
||||
private String openId;
|
||||
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
private String status;
|
||||
private Integer status;
|
||||
|
||||
/** 手机号 */
|
||||
@Excel(name = "手机号")
|
||||
@ -63,5 +67,15 @@ private static final long serialVersionUID=1L;
|
||||
|
||||
/** 租户id */
|
||||
@Excel(name = "租户id")
|
||||
private String deptId;
|
||||
private Long deptId;
|
||||
|
||||
|
||||
public WineryMauser(SysUser user) {
|
||||
this.openId = user.getUserName();
|
||||
this.deptId = user.getDeptId();
|
||||
this.nickName = user.getNickName();
|
||||
this.mobile = user.getPhonenumber();
|
||||
this.status = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.ruoyi.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -34,13 +35,12 @@ import com.ruoyi.system.service.ISysUserService;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/user")
|
||||
public class SysUserController extends BaseController
|
||||
{
|
||||
public class SysUserController extends BaseController {
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@ -58,8 +58,7 @@ public class SysUserController extends BaseController
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:user:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysUser user)
|
||||
{
|
||||
public TableDataInfo list(SysUser user) {
|
||||
startPage();
|
||||
List<SysUser> list = userService.selectUserList(user);
|
||||
return getDataTable(list);
|
||||
@ -68,8 +67,7 @@ public class SysUserController extends BaseController
|
||||
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
||||
@PreAuthorize("@ss.hasPermi('system:user:export')")
|
||||
@GetMapping("/export")
|
||||
public AjaxResult export(SysUser user)
|
||||
{
|
||||
public AjaxResult export(SysUser user) {
|
||||
List<SysUser> list = userService.selectUserList(user);
|
||||
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
||||
return util.exportExcel(list, "用户数据");
|
||||
@ -78,8 +76,7 @@ public class SysUserController extends BaseController
|
||||
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||
@PreAuthorize("@ss.hasPermi('system:user:import')")
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
|
||||
{
|
||||
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());
|
||||
@ -89,8 +86,7 @@ public class SysUserController extends BaseController
|
||||
}
|
||||
|
||||
@GetMapping("/importTemplate")
|
||||
public AjaxResult importTemplate()
|
||||
{
|
||||
public AjaxResult importTemplate() {
|
||||
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
||||
return util.importTemplateExcel("用户数据");
|
||||
}
|
||||
@ -99,15 +95,13 @@ public class SysUserController extends BaseController
|
||||
* 根据用户编号获取详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:user:query')")
|
||||
@GetMapping(value = { "/", "/{userId}" })
|
||||
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
|
||||
{
|
||||
@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))
|
||||
{
|
||||
if (StringUtils.isNotNull(userId)) {
|
||||
ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId));
|
||||
ajax.put("postIds", postService.selectPostListByUserId(userId));
|
||||
ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
|
||||
@ -121,20 +115,17 @@ public class SysUserController extends BaseController
|
||||
@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())))
|
||||
{
|
||||
public AjaxResult add(@Validated @RequestBody SysUser user) {
|
||||
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName()))) {
|
||||
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
||||
/* else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
||||
{
|
||||
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
}
|
||||
}*/
|
||||
else if (StringUtils.isNotEmpty(user.getEmail())
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
||||
{
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
|
||||
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
}
|
||||
user.setCreateBy(SecurityUtils.getUsername());
|
||||
@ -148,17 +139,16 @@ public class SysUserController extends BaseController
|
||||
@PreAuthorize("@ss.hasPermi('system:user:edit')")
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody SysUser user)
|
||||
{
|
||||
public AjaxResult edit(@Validated @RequestBody SysUser user) {
|
||||
userService.checkUserAllowed(user);
|
||||
if (StringUtils.isNotEmpty(user.getPhonenumber())
|
||||
/* if (StringUtils.isNotEmpty(user.getPhonenumber())
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
||||
{
|
||||
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(user.getEmail())
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
||||
{
|
||||
else*/
|
||||
if (StringUtils.isNotEmpty(user.getEmail())
|
||||
&& UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
|
||||
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||
}
|
||||
user.setUpdateBy(SecurityUtils.getUsername());
|
||||
@ -171,8 +161,7 @@ public class SysUserController extends BaseController
|
||||
@PreAuthorize("@ss.hasPermi('system:user:remove')")
|
||||
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{userIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] userIds)
|
||||
{
|
||||
public AjaxResult remove(@PathVariable Long[] userIds) {
|
||||
return toAjax(userService.deleteUserByIds(userIds));
|
||||
}
|
||||
|
||||
@ -182,8 +171,7 @@ public class SysUserController extends BaseController
|
||||
@PreAuthorize("@ss.hasPermi('system:user:resetPwd')")
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/resetPwd")
|
||||
public AjaxResult resetPwd(@RequestBody SysUser user)
|
||||
{
|
||||
public AjaxResult resetPwd(@RequestBody SysUser user) {
|
||||
userService.checkUserAllowed(user);
|
||||
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
||||
user.setUpdateBy(SecurityUtils.getUsername());
|
||||
@ -196,8 +184,7 @@ public class SysUserController extends BaseController
|
||||
@PreAuthorize("@ss.hasPermi('system:user:edit')")
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public AjaxResult changeStatus(@RequestBody SysUser user)
|
||||
{
|
||||
public AjaxResult changeStatus(@RequestBody SysUser user) {
|
||||
userService.checkUserAllowed(user);
|
||||
user.setUpdateBy(SecurityUtils.getUsername());
|
||||
return toAjax(userService.updateUserStatus(user));
|
||||
|
@ -96,19 +96,4 @@ public class BaseController
|
||||
return StringUtils.format("redirect:{}", url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取部门Id
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public Long getDeptId(UsernamePasswordAuthenticationToken token) {
|
||||
JSONObject json = (JSONObject) JSONUtil.parse(token.getPrincipal());
|
||||
|
||||
Long deptId = json.getJSONObject("user")
|
||||
.getJSONObject("dept")
|
||||
.getLong("deptId");
|
||||
|
||||
return deptId;
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,17 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 防止XSS攻击的过滤器
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Slf4j
|
||||
public class XssFilter implements Filter
|
||||
{
|
||||
/**
|
||||
@ -57,6 +61,7 @@ public class XssFilter implements Filter
|
||||
{
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
HttpServletResponse resp = (HttpServletResponse) response;
|
||||
|
||||
if (handleExcludeURL(req, resp))
|
||||
{
|
||||
chain.doFilter(request, response);
|
||||
@ -94,4 +99,6 @@ public class XssFilter implements Filter
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -9,22 +9,17 @@ import com.ruoyi.common.exception.CustomException;
|
||||
|
||||
/**
|
||||
* 安全服务工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SecurityUtils
|
||||
{
|
||||
public class SecurityUtils {
|
||||
/**
|
||||
* 获取用户账户
|
||||
**/
|
||||
public static String getUsername()
|
||||
{
|
||||
try
|
||||
{
|
||||
public static String getUsername() {
|
||||
try {
|
||||
return getLoginUser().getUsername();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
@ -32,14 +27,10 @@ public class SecurityUtils
|
||||
/**
|
||||
* 获取用户
|
||||
**/
|
||||
public static LoginUser getLoginUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
public static LoginUser getLoginUser() {
|
||||
try {
|
||||
return (LoginUser) getAuthentication().getPrincipal();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
@ -47,8 +38,7 @@ public class SecurityUtils
|
||||
/**
|
||||
* 获取Authentication
|
||||
*/
|
||||
public static Authentication getAuthentication()
|
||||
{
|
||||
public static Authentication getAuthentication() {
|
||||
return SecurityContextHolder.getContext().getAuthentication();
|
||||
}
|
||||
|
||||
@ -58,8 +48,7 @@ public class SecurityUtils
|
||||
* @param password 密码
|
||||
* @return 加密字符串
|
||||
*/
|
||||
public static String encryptPassword(String password)
|
||||
{
|
||||
public static String encryptPassword(String password) {
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.encode(password);
|
||||
}
|
||||
@ -67,24 +56,44 @@ public class SecurityUtils
|
||||
/**
|
||||
* 判断密码是否相同
|
||||
*
|
||||
* @param rawPassword 真实密码
|
||||
* @param rawPassword 真实密码
|
||||
* @param encodedPassword 加密后字符
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean matchesPassword(String rawPassword, String encodedPassword)
|
||||
{
|
||||
public static boolean matchesPassword(String rawPassword, String encodedPassword) {
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.matches(rawPassword, encodedPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为管理员
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
public static boolean isAdmin(Long userId) {
|
||||
return userId != null && 1L == userId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否为管理员
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean isAdmin() {
|
||||
return getLoginUser().getUser() != null && 1L == getLoginUser().getUser().getUserId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户账户
|
||||
**/
|
||||
public static Long getDeptId() {
|
||||
try {
|
||||
return getLoginUser().getUser().getDeptId();
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("获取用户部门信息异常", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
||||
.antMatchers("/webjars/**").anonymous()
|
||||
.antMatchers("/*/api-docs").anonymous()
|
||||
.antMatchers("/druid/**").anonymous()
|
||||
.antMatchers("/winery/mini/**").anonymous()
|
||||
.antMatchers("/winery/mini/user/**").permitAll()
|
||||
// 除上面外的所有请求全部需要鉴权认证
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
@ -125,6 +125,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
||||
// 添加CORS filter
|
||||
httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class);
|
||||
httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,6 +3,9 @@ package com.ruoyi.framework.interceptor;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
@ -17,11 +20,15 @@ import com.ruoyi.common.utils.ServletUtils;
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter
|
||||
{
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
|
||||
{
|
||||
|
||||
log.info("访问:{},来自:{}", request.getRequestURI(), getRequestIp(request));
|
||||
|
||||
if (handler instanceof HandlerMethod)
|
||||
{
|
||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||
@ -52,4 +59,35 @@ public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract boolean isRepeatSubmit(HttpServletRequest request);
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求的源ip
|
||||
*
|
||||
* @param request http请求
|
||||
* @return 请求的源ip
|
||||
*/
|
||||
private String getRequestIp(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
String unknown = "unknown";
|
||||
if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
|
@ -63,13 +63,13 @@
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
v-hasPermi="['winery:winery_mauser:add']"
|
||||
>新增</el-button>
|
||||
<!-- <el-button-->
|
||||
<!-- type="primary"-->
|
||||
<!-- icon="el-icon-plus"-->
|
||||
<!-- size="mini"-->
|
||||
<!-- @click="handleAdd"-->
|
||||
<!-- v-hasPermi="['winery:winery_mauser:add']"-->
|
||||
<!-- >新增</el-button>-->
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
|
Loading…
x
Reference in New Issue
Block a user