Initial commit
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
||||
import com.alipay.api.request.AlipayUserInfoShareRequest;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.api.response.AlipayUserInfoShareResponse;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.security.JwtSubject;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.AlipayConfigUtil;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.LoginRecord;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.entity.UserRole;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.result.LoginResult;
|
||||
import com.gxwebsoft.common.system.service.LoginRecordService;
|
||||
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.entity.UserOauth;
|
||||
import com.gxwebsoft.shop.mapper.UserOauthMapper;
|
||||
import com.gxwebsoft.shop.param.UserOauthParam;
|
||||
import com.gxwebsoft.shop.service.UserOauthService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import static com.gxwebsoft.common.core.utils.CommonUtil.randomUsername;
|
||||
|
||||
/**
|
||||
* 登录认证控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:11
|
||||
*/
|
||||
@Api(tags = "登录认证")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/login-alipay")
|
||||
public class OpenAlipayController extends BaseController {
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
@Resource
|
||||
private AlipayConfigUtil alipayConfig;
|
||||
@Resource
|
||||
private UserOauthMapper userOauthMapper;
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@ApiOperation("支付宝授权码")
|
||||
@PostMapping("/getAuthCode")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> getAuthCode(@RequestBody UserParam param, HttpServletRequest req) throws AlipayApiException {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 读取缓存信息
|
||||
String setting = stringRedisTemplate.opsForValue().get("cache"+param.getTenantId()+":setting:register");
|
||||
if(setting == null){
|
||||
throw new BusinessException("请先配置注册设置");
|
||||
}
|
||||
JSONObject jsonObject = JSONObject.parseObject(setting);
|
||||
String roleId = jsonObject.getString("roleId");
|
||||
// 实例化客户端
|
||||
DefaultAlipayClient alipayClient = alipayConfig.alipayClient(param.getTenantId());
|
||||
try {
|
||||
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
||||
request.setGrantType("authorization_code");
|
||||
request.setCode(param.getAuthCode());
|
||||
AlipaySystemOauthTokenResponse response = alipayClient.certificateExecute(request);
|
||||
if (response.isSuccess()) {
|
||||
final String accessToken = response.getAccessToken();
|
||||
AlipayUserInfoShareRequest request2 = new AlipayUserInfoShareRequest();
|
||||
AlipayUserInfoShareResponse userInfo = alipayClient.certificateExecute(request2, accessToken);
|
||||
String nickName = "支付宝用户";
|
||||
String avatar = "";
|
||||
if(StrUtil.isNotBlank(userInfo.getAvatar())){
|
||||
avatar = userInfo.getAvatar();
|
||||
}
|
||||
if (StrUtil.isNotBlank(userInfo.getNickName())) {
|
||||
nickName = userInfo.getNickName();
|
||||
}
|
||||
if(userInfo.isSuccess()){
|
||||
// 查询是否已注册
|
||||
UserOauthParam userOauthParam = new UserOauthParam();
|
||||
userOauthParam.setOauthId(userInfo.getUserId());
|
||||
userOauthParam.setTenantId(param.getTenantId());
|
||||
UserOauth userOauth = userOauthParam.getOne(userOauthMapper.getByOauthId(userOauthParam));
|
||||
if(userOauth != null){
|
||||
UserParam userParam = new UserParam();
|
||||
userParam.setUserId(userOauth.getUserId());
|
||||
userParam.setTenantId(userOauth.getTenantId());
|
||||
User user = userService.getByOauthId(userParam);
|
||||
if(user != null){
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
userOauthService.removeById(userOauth.getId());
|
||||
}
|
||||
// 新注册用户
|
||||
User user = new User();
|
||||
user.setStatus(0);
|
||||
user.setUsername(randomUsername("Ali_"));
|
||||
user.setNickname(nickName);
|
||||
user.setAvatar(avatar);
|
||||
user.setCity(userInfo.getCity());
|
||||
user.setProvince(userInfo.getProvince());
|
||||
user.setPassword(userService.encodePassword(CommonUtil.randomUUID16()));
|
||||
user.setTenantId(param.getTenantId());
|
||||
boolean isSuccess = userService.saveUser(user);
|
||||
if(isSuccess){
|
||||
// 添加用户角色
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setTenantId(param.getTenantId());
|
||||
userRole.setRoleId(Integer.valueOf(roleId));
|
||||
userRoleService.save(userRole);
|
||||
// 添加第三方用户信息
|
||||
UserOauth userOauth2 = new UserOauth();
|
||||
userOauth2.setUserId(user.getUserId());
|
||||
userOauth2.setTenantId(param.getTenantId());
|
||||
userOauth2.setOauthType("MP-ALIPAY");
|
||||
userOauth2.setOauthId(userInfo.getUserId());
|
||||
userOauthService.save(userOauth2);
|
||||
|
||||
UserParam userParam = new UserParam();
|
||||
userParam.setUserId(user.getUserId());
|
||||
userParam.setTenantId(user.getTenantId());
|
||||
User result = userService.getByOauthId(userParam);
|
||||
loginRecordService.saveAsync(result.getUsername(), LoginRecord.TYPE_REGISTER, null, result.getTenantId(), req);
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(result.getUsername(), result.getTenantId()),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
return success("登录成功", new LoginResult(access_token, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fail("支付宝授权失败");
|
||||
}
|
||||
|
||||
@ApiOperation("授权手机号码")
|
||||
@PostMapping("/update")
|
||||
public ApiResult<User> updateInfo(@RequestBody User user) {
|
||||
user.setUserId(getLoginUserId());
|
||||
// 不能修改的字段
|
||||
user.setUsername(null);
|
||||
user.setPassword(null);
|
||||
user.setEmailVerified(null);
|
||||
user.setOrganizationId(null);
|
||||
user.setStatus(null);
|
||||
if (userService.updateById(user)) {
|
||||
return success(userService.getByIdRel(user.getUserId()));
|
||||
}
|
||||
return fail("保存失败", null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.Dictionary;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.oa.controller.TenantController;
|
||||
import com.gxwebsoft.oa.entity.App;
|
||||
import com.gxwebsoft.oa.entity.AppUser;
|
||||
import com.gxwebsoft.oa.entity.Tenant;
|
||||
import com.gxwebsoft.oa.param.AppParam;
|
||||
import com.gxwebsoft.oa.param.AppUserParam;
|
||||
import com.gxwebsoft.oa.service.AppService;
|
||||
import com.gxwebsoft.oa.service.AppUserService;
|
||||
import com.gxwebsoft.oa.service.TenantService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.RedisConstants.USER_RANKING_BY_APPS;
|
||||
|
||||
/**
|
||||
* 应用控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-18 13:55:29
|
||||
*/
|
||||
@Api(tags = "应用管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/app")
|
||||
public class OpenAppController extends BaseController {
|
||||
@Resource
|
||||
private AppService appService;
|
||||
@Resource
|
||||
private AppUserService appUserService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@ApiOperation("分页查询应用")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<App>> page(AppParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 非管理员仅显示已加入成员管理的应用列表
|
||||
User loginUser = getLoginUser();
|
||||
if(!loginUser.getUsername().equals("admin")){
|
||||
param.setUserId(getLoginUserId());
|
||||
}
|
||||
param.setTenantId(getTenantId());
|
||||
// 使用关联查询
|
||||
return success(appService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部应用")
|
||||
@GetMapping()
|
||||
public ApiResult<List<App>> list(AppParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
param.setUserId(getLoginUserId());
|
||||
param.setTenantId(getTenantId());
|
||||
// 使用关联查询
|
||||
return success(appService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询应用")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<App> get(@PathVariable("id") Integer id) {
|
||||
// return success(appService.getById(id));
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
App app = appService.getByIdRel(id);
|
||||
// 查询开发成员列表
|
||||
AppUserParam appUserParam = new AppUserParam();
|
||||
appUserParam.setAppId(app.getAppId());
|
||||
List<AppUser> appUsers = appUserService.listRel(appUserParam);
|
||||
// List<User> list = userService.list(new LambdaQueryWrapper<User>().in(User::getUserId, appUsers.stream().map(AppUser::getUserId).collect(Collectors.toList())));
|
||||
app.setUsers(appUsers);
|
||||
return success(app);
|
||||
}
|
||||
|
||||
@ApiOperation("创建应用")
|
||||
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody App app) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (app.getAppType() == null) {
|
||||
return fail("应用类型不能为空");
|
||||
}
|
||||
// 创建应用
|
||||
final Integer loginUserId = getLoginUserId();
|
||||
final User loginUser = getLoginUser();
|
||||
app.setUserId(loginUserId);
|
||||
app.setStatus(0); // 需要审核1 不需要审核0
|
||||
app.setAppSecret(IdUtil.fastSimpleUUID());
|
||||
app.setTenantId(loginUser.getTenantId());
|
||||
System.out.println("app = " + app);
|
||||
if (appService.save(app)) {
|
||||
// 添加应用成员
|
||||
AppUser appUser = new AppUser();
|
||||
appUser.setAppId(app.getAppId());
|
||||
appUser.setRole(30);
|
||||
appUser.setUserId(loginUserId);
|
||||
appUser.setStatus(0);
|
||||
appUserService.save(appUser);
|
||||
// 更新缓存
|
||||
String key = "AppSecret:".concat(app.getAppId().toString());
|
||||
cacheClient.set(key,app.getAppSecret());
|
||||
// 更新用户的插件数量到排行榜
|
||||
int count = appService.count(new LambdaQueryWrapper<App>()
|
||||
.eq(App::getUserId, loginUserId));
|
||||
cacheClient.zAdd(USER_RANKING_BY_APPS, loginUserId,(double) count);
|
||||
return success("创建成功");
|
||||
}
|
||||
return fail("创建失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改应用")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody App app) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (appService.updateById(app)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除应用")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (appService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("查看秘钥")
|
||||
@PostMapping("/getAppSecret")
|
||||
public ApiResult<?> getAppSecret(@RequestBody App app) {
|
||||
App result = appService.getByIdRel(app.getAppId());
|
||||
String key = "AppSecret:".concat(app.getAppId().toString());
|
||||
result.setAppSecret(cacheClient.get(key));
|
||||
return success("操作成功",result);
|
||||
}
|
||||
|
||||
@ApiOperation("重置秘钥")
|
||||
@PostMapping("/updateAppSecret")
|
||||
public ApiResult<?> updateAppSecret(@RequestBody App app) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (app.getAppId() == null) {
|
||||
return fail("请勿重复操作");
|
||||
}
|
||||
App result = appService.getByIdRel(app.getAppId());
|
||||
String key = cacheClient.key("AppSecret", app.getAppId());
|
||||
String appSecret = IdUtil.fastSimpleUUID();
|
||||
cacheClient.set(key,appSecret);
|
||||
result.setAppSecret(appSecret);
|
||||
return success("重置成功",result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.oa.entity.AppUser;
|
||||
import com.gxwebsoft.oa.param.AppUserParam;
|
||||
import com.gxwebsoft.oa.service.AppUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用成员控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-02-17 13:22:20
|
||||
*/
|
||||
@Api(tags = "应用成员管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/app-user")
|
||||
public class OpenAppUserController extends BaseController {
|
||||
@Resource
|
||||
private AppUserService appUserService;
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询应用成员")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<AppUser>> page(AppUserParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
PageParam<AppUser, AppUserParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(appUserService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(appUserService.pageRel(param));
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部应用成员")
|
||||
@GetMapping()
|
||||
public ApiResult<List<AppUser>> list(AppUserParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
PageParam<AppUser, AppUserParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(appUserService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(appUserService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询应用成员")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<AppUser> get(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return success(appUserService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(appUserService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("添加应用成员")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody AppUser appUser) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
String username = appUser.getUsername();
|
||||
Integer appId = appUser.getAppId();
|
||||
Integer userIdByUsername = getUserIdByUsername(username,getTenantId());
|
||||
// 判断重复
|
||||
if(appUserService.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getUserId,userIdByUsername).eq(AppUser::getAppId,appId)) > 0){
|
||||
throw new BusinessException("请勿重复添加");
|
||||
}
|
||||
// 是否超出限制
|
||||
if(appUserService.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getAppId,appUser.getAppId())) > 50){
|
||||
throw new BusinessException("最多只能添加50个");
|
||||
}
|
||||
appUser.setUserId(userIdByUsername);
|
||||
appUser.setStatus(0);
|
||||
if (appUserService.save(appUser)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("修改应用成员")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody AppUser appUser) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (appUserService.updateById(appUser)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("删除应用成员")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
AppUser appUser = appUserService.getById(id);
|
||||
if(appUser.getRole().equals(30)){
|
||||
return fail("管理员不能删除");
|
||||
}
|
||||
if (appUserService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加应用成员")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<AppUser> list) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (appUserService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改应用成员")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<AppUser> batchParam) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (batchParam.update(appUserService, "app_user_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除应用成员")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (appUserService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.oa.entity.Tenant;
|
||||
import com.gxwebsoft.oa.param.TenantParam;
|
||||
import com.gxwebsoft.oa.service.TenantService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用管理
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-11-25 19:04:43
|
||||
*/
|
||||
@Api(tags = "应用管理(已废弃)")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/appstore")
|
||||
public class OpenAppstoreController extends BaseController {
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
|
||||
@ApiOperation("分页查询应用")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Tenant>> page(TenantParam param) {
|
||||
PageParam<Tenant, TenantParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// 记录当前登录用户id、应用id
|
||||
User user = getLoginUser();
|
||||
if (user != null) {
|
||||
param.setUserId(user.getUserId());
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(tenantService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部应用")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Tenant>> list(TenantParam param) {
|
||||
PageParam<Tenant, TenantParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// 记录当前登录用户id、应用id
|
||||
User user = getLoginUser();
|
||||
if (user != null) {
|
||||
param.setUserId(user.getUserId());
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(tenantService.listRel(param));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.gxwebsoft.apps.entity.BcAgent;
|
||||
import com.gxwebsoft.apps.param.BcAgentParam;
|
||||
import com.gxwebsoft.apps.service.BcAgentService;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 代报餐管理控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-04-24 19:25:59
|
||||
*/
|
||||
@Api(tags = "代报餐管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/bc-agent")
|
||||
public class OpenBcAgentController extends BaseController {
|
||||
@Resource
|
||||
private BcAgentService bcAgentService;
|
||||
|
||||
@ApiOperation("分页查询代报餐管理")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<BcAgent>> page(BcAgentParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
param.setParentId(getLoginUserId());
|
||||
return success(bcAgentService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部代报餐管理")
|
||||
@GetMapping()
|
||||
public ApiResult<List<BcAgent>> list(BcAgentParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
param.setParentId(getLoginUserId());
|
||||
return success(bcAgentService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询代报餐管理")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<BcAgent> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(bcAgentService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("添加代报餐管理")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody BcAgent bcAgent) {
|
||||
if (bcAgentService.save(bcAgent)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcAgent:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改代报餐管理")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody BcAgent bcAgent) {
|
||||
if (bcAgentService.updateById(bcAgent)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcAgent:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除代报餐管理")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (bcAgentService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcAgent:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加代报餐管理")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<BcAgent> list) {
|
||||
if (bcAgentService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcAgent:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改代报餐管理")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<BcAgent> batchParam) {
|
||||
if (batchParam.update(bcAgentService, "agent_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcAgent:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除代报餐管理")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (bcAgentService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,481 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.apps.entity.BcEquipment;
|
||||
import com.gxwebsoft.apps.param.BcEquipmentParam;
|
||||
import com.gxwebsoft.apps.service.BcEquipmentService;
|
||||
import com.gxwebsoft.apps.utils.BcUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.OrderGoods;
|
||||
import com.gxwebsoft.shop.entity.UserReferee;
|
||||
import com.gxwebsoft.shop.param.OrderGoodsParam;
|
||||
import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.param.UserRefereeParam;
|
||||
import com.gxwebsoft.shop.service.OrderGoodsService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import com.gxwebsoft.shop.service.UserRefereeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.OrderConstants.*;
|
||||
import static com.gxwebsoft.shop.constants.OrderConstants.ORDER_GOODS_DELIVERY_STATUS20;
|
||||
|
||||
/**
|
||||
* 云报餐机器接口
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-04-24 19:25:59
|
||||
*/
|
||||
@Api(tags = "云报餐机器接口")
|
||||
@RestController
|
||||
@RequestMapping("/hxz/v1")
|
||||
public class OpenBcController extends BaseController {
|
||||
@Resource
|
||||
private BcUtil bcUtil;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private OrderGoodsService orderGoodsService;
|
||||
@Resource
|
||||
private UserRefereeService userRefereeService;
|
||||
@Resource
|
||||
private BcEquipmentService bcEquipmentService;
|
||||
|
||||
@ApiOperation("获取服务器时间接口")
|
||||
@PostMapping("/ServerTime")
|
||||
public HashMap<String, Object> ServerTime(HttpServletRequest request) {
|
||||
final String deviceId = request.getHeader("Device-ID"); // 设备ID
|
||||
final String now = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss") + (DateUtil.thisDayOfWeek() - 1); // 服务器时间
|
||||
System.out.println(deviceId + "获取服务器时间接口 = " + now);
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("Status",1);
|
||||
map.put("Msg","服务器时间");
|
||||
map.put("Time", now);
|
||||
return map;
|
||||
}
|
||||
|
||||
@ApiOperation("付款码(二维码)支付接口")
|
||||
@PostMapping("/QRCodeTransaction")
|
||||
public HashMap<String, Object> QRCodeTransaction(@RequestBody String QR, HttpServletRequest request) {
|
||||
// 1.提取订单号ID
|
||||
final String deviceId = request.getHeader("Device-ID"); // 设备ID
|
||||
final JSONObject jsonObject = JSONObject.parseObject(QR);
|
||||
final String orderNo = jsonObject.getString("QR");
|
||||
|
||||
System.out.println("deviceId = " + deviceId);
|
||||
System.out.println("QR = " + QR);
|
||||
|
||||
// 2.查询订单数据
|
||||
|
||||
// 3.查询该餐段的菜品
|
||||
|
||||
// 4.核销菜品
|
||||
|
||||
// 5.通知设备
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("Status",1);
|
||||
map.put("Msg","支付成功");
|
||||
map.put("Qrorder", orderNo);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@ApiOperation("二维码支付结果查询接口")
|
||||
@PostMapping("/TransactionInquiry")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public HashMap<String, Object> TransactionInquiry(@RequestBody String QROrder, HttpServletRequest request) {
|
||||
// 1. 提取订单号
|
||||
final JSONObject jsonObject = JSONObject.parseObject(QROrder);
|
||||
final String orderNo = jsonObject.getString("QROrder");
|
||||
StringBuilder foods = new StringBuilder(); // 消费机回显信息
|
||||
String DeviceID = request.getHeader("Device-ID"); // 设备ID
|
||||
|
||||
final BcEquipmentParam bcEquipmentParam = new BcEquipmentParam();
|
||||
bcEquipmentParam.setEquipmentCode(DeviceID);
|
||||
final List<BcEquipment> bcEquipments = bcEquipmentService.listRel(bcEquipmentParam);
|
||||
final BcEquipment bcEquipment = bcEquipments.get(0);
|
||||
final Integer gear = bcEquipment.getGear(); // 设备所属档口
|
||||
final Integer categoryId = bcUtil.getCurrentPeriod(bcEquipment.getTenantId()); // 餐段
|
||||
// int categoryId = 26;
|
||||
// 是否有取餐数据
|
||||
boolean isSuccess = true;
|
||||
|
||||
// 打印测试
|
||||
System.out.println("查询支付结果(订单号:)******** = " + orderNo);
|
||||
System.out.println("bcEquipment = " + bcEquipment);
|
||||
System.out.println("gear = " + gear);
|
||||
System.out.println("StrUtil.isNumeric(orderNo) = " + StrUtil.isNumeric(orderNo));
|
||||
|
||||
// 2.非代取餐模式
|
||||
if (!orderNo.startsWith("dqc:")) {
|
||||
System.out.println("非代取餐模式 = ");
|
||||
// 4.排除其他情况
|
||||
if(!StrUtil.isNumeric(orderNo)){
|
||||
foods.append("非取餐码");
|
||||
isSuccess = false;
|
||||
}else{
|
||||
OrderParam orderParam = new OrderParam();
|
||||
orderParam.setOrderNo(orderNo);
|
||||
List<Order> list = orderService.listRel(orderParam);
|
||||
Order order = list.get(0);
|
||||
// System.out.println("order-one = " + order);
|
||||
OrderGoodsParam orderGoodsParam = new OrderGoodsParam();
|
||||
// 2.1查询订单商品
|
||||
List<OrderGoods> orderGoods = orderGoodsService.list(new LambdaQueryWrapper<OrderGoods>()
|
||||
.eq(OrderGoods::getOrderId, order.getOrderId())
|
||||
.eq(OrderGoods::getDeliveryStatus,RECEIPT_STATUS_NO)
|
||||
.eq(OrderGoods::getCategoryId,categoryId)
|
||||
.eq(OrderGoods::getGear,gear)
|
||||
);
|
||||
// System.out.println("2.1查询订单商品 = " + orderGoods);
|
||||
// 2.2查询用户信息
|
||||
User user = userService.getById(order.getUserId());
|
||||
// 2.收集菜品信息
|
||||
foods.append("姓名:").append(order.getNickname()).append("\r\n");
|
||||
// foods.append("签到:").append(DateUtil.format(DateUtil.date(),"MM-dd HH:mm")).append("\r\n");
|
||||
for (OrderGoods item : orderGoods) {
|
||||
// 过滤份数totalNum=0的菜品
|
||||
if (!item.getTotalNum().equals(0)) {
|
||||
foods.append(item.getGoodsName()).append(" ").append(item.getTotalNum()).append("份").append(" ¥").append(item.getTotalPrice()).append("\r\n");
|
||||
OrderGoods food = new OrderGoods();
|
||||
food.setOrderGoodsId(item.getOrderGoodsId());
|
||||
food.setDeliveryStatus(ORDER_GOODS_DELIVERY_STATUS20);
|
||||
orderGoodsService.updateById(food);
|
||||
// 更新订单部分发布状态
|
||||
final Order order1 = new Order();
|
||||
order1.setOrderId(item.getOrderId());
|
||||
if(categoryId == 27){
|
||||
order1.setDeliveryStatus(DELIVERY_STATUS_YES);
|
||||
}else{
|
||||
order1.setDeliveryStatus(DELIVERY_STATUS_30);
|
||||
}
|
||||
orderService.updateById(order1);
|
||||
}
|
||||
}
|
||||
if(orderGoods.size() == 0){
|
||||
foods.append("没有取餐数据");
|
||||
isSuccess = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3.代取餐模式
|
||||
ArrayList<OrderGoods> saveOrderGoods = new ArrayList<>();
|
||||
ArrayList<Order> saveOrder = new ArrayList<>();
|
||||
if(orderNo.startsWith("dqc:")){
|
||||
System.out.println("代取餐模式 = ");
|
||||
final String dealerId = StrUtil.removePrefix(orderNo, "dqc:");
|
||||
System.out.println("dealerId = " + dealerId);
|
||||
UserRefereeParam userRefereeParam = new UserRefereeParam();
|
||||
userRefereeParam.setDealerId(Integer.valueOf(dealerId));
|
||||
userRefereeParam.setDeleted(0);
|
||||
List<UserReferee> userRefereeList = userRefereeService.listRel(userRefereeParam);
|
||||
// 查询帮代餐的成员ID集
|
||||
List<Integer> userIds = userRefereeList.stream().map(UserReferee::getUserId).collect(Collectors.toList());
|
||||
userIds.add(Integer.valueOf(dealerId));
|
||||
System.out.println("userIds = " + userIds);
|
||||
// 查询成员的订单
|
||||
List<Order> list = orderService.list(new LambdaQueryWrapper<Order>()
|
||||
.in(Order::getUserId, userIds)
|
||||
.eq(Order::getDeliveryTime, DateUtil.parse(DateUtil.today()))
|
||||
.eq(Order::getPayStatus, PAY_STATUS_SUCCESS)
|
||||
.ne(Order::getDeliveryStatus, RECEIPT_STATUS_YES)
|
||||
.eq(Order::getDeleted, 0)
|
||||
);
|
||||
System.out.println("list = " + list.size());
|
||||
if(list.size() > 0){
|
||||
// 收集订单ID集
|
||||
List<Integer> orderIds = list.stream().map(Order::getOrderId).collect(Collectors.toList());
|
||||
System.out.println("orderIds = " + orderIds);
|
||||
// 查询商品
|
||||
if(orderIds.size() > 0){
|
||||
List<OrderGoods> orderGoodsList = orderGoodsService.list(new LambdaQueryWrapper<OrderGoods>()
|
||||
.in(OrderGoods::getOrderId, orderIds)
|
||||
.ne(OrderGoods::getDeliveryStatus,RECEIPT_STATUS_YES)
|
||||
.gt(OrderGoods::getTotalNum,0)
|
||||
.eq(OrderGoods::getCategoryId,categoryId)
|
||||
.eq(OrderGoods::getGear,gear)
|
||||
);
|
||||
if (orderGoodsList.size() == 0) {
|
||||
foods.append("没有取餐数据");
|
||||
isSuccess = false;
|
||||
}
|
||||
System.out.println("orderGoodsList = " + orderGoodsList.size());
|
||||
// 查询用户信息
|
||||
User dealer = userService.getById(dealerId);
|
||||
foods.append("代取:").append(dealer.getNickname()).append("\r\n");
|
||||
foods.append("共" + orderGoodsList.size() + "份").append("\r\n");
|
||||
// foods.append("签到:").append(DateUtil.format(DateUtil.date(),"MM-dd HH:mm")).append("\r\n");
|
||||
// 批量核销操作
|
||||
for (OrderGoods og : orderGoodsList) {
|
||||
System.out.println("og = " + og);
|
||||
foods.append(og.getGoodsName()).append("\r\n");
|
||||
final OrderGoods orderGoods = new OrderGoods();
|
||||
orderGoods.setOrderGoodsId(og.getOrderGoodsId());
|
||||
orderGoods.setDeliveryStatus(ORDER_GOODS_DELIVERY_STATUS20);
|
||||
saveOrderGoods.add(orderGoods);
|
||||
// 更新订单部分发货状态
|
||||
Order order2 = new Order();
|
||||
order2.setOrderId(og.getOrderId());
|
||||
if(categoryId == 27){
|
||||
order2.setDeliveryStatus(DELIVERY_STATUS_YES);
|
||||
}else{
|
||||
order2.setDeliveryStatus(DELIVERY_STATUS_30);
|
||||
}
|
||||
saveOrder.add(order2);
|
||||
}
|
||||
}else{
|
||||
foods.append("没有取餐数据");
|
||||
isSuccess = false;
|
||||
}
|
||||
}else{
|
||||
foods.append("没有取餐数据");
|
||||
isSuccess = false;
|
||||
}
|
||||
}
|
||||
// 4.更新状态
|
||||
orderGoodsService.updateBatchById(saveOrderGoods);
|
||||
orderService.updateBatchById(saveOrder);
|
||||
|
||||
// 5.通知设备
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("Status", 1);
|
||||
map.put("Msg","");
|
||||
map.put("Name", "");
|
||||
map.put("CardNo", "");
|
||||
map.put("Money", "");
|
||||
map.put("Subsidy", "");
|
||||
map.put("Times", "");
|
||||
map.put("Integral", "");
|
||||
map.put("InTime", "");
|
||||
map.put("OutTime", "");
|
||||
map.put("CumulativeTime ", "");
|
||||
map.put("Amount","0.00");
|
||||
map.put("VoiceID",null);
|
||||
map.put("Text", foods);
|
||||
|
||||
// 5.1无取餐数据
|
||||
if(!isSuccess){
|
||||
map.put("Status", 0);
|
||||
map.put("Msg","没有取餐数据");
|
||||
map.put("Text",null);
|
||||
System.out.println("5.1无取餐数据 = " + map);
|
||||
return map;
|
||||
}
|
||||
System.out.println("5.通知设备 = " + map);
|
||||
return map;
|
||||
}
|
||||
|
||||
@ApiOperation("终端查询日统计接口")
|
||||
@PostMapping("/Counts")
|
||||
public HashMap<String, Object> Counts(HttpServletRequest request) {
|
||||
|
||||
final String deviceId = request.getHeader("Device-ID");
|
||||
System.out.println("deviceId = " + deviceId);
|
||||
final Integer categoryId = bcUtil.getCurrentPeriod(10048);
|
||||
System.out.println("categoryId = " + categoryId);
|
||||
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("Status",1);
|
||||
map.put("Msg","终端查询日统计接口");
|
||||
map.put("Text", "" +
|
||||
"日统计\n" +
|
||||
"日总金额:0.00\n" +
|
||||
"日总次数:0\n" +
|
||||
"时段统计\n" +
|
||||
"一时段金额:0.00\n" +
|
||||
"一时段次数:0" +
|
||||
"");
|
||||
|
||||
// 发送消息测试
|
||||
bcUtil.send("您的申请已通过");
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
// @ApiOperation("二维码支付结果查询接口")
|
||||
// @PostMapping("/demo")
|
||||
// @Transactional(rollbackFor = {Exception.class})
|
||||
// public HashMap<String, Object> demo(@RequestBody String QROrder, HttpServletRequest request) {
|
||||
// System.out.println("二维码支付结果查询接口 = " + QROrder);
|
||||
// // 1. 提取订单号
|
||||
// final JSONObject jsonObject = JSONObject.parseObject(QROrder);
|
||||
// final String orderNo = jsonObject.getString("QROrder");
|
||||
// StringBuilder foods = new StringBuilder(); // 消费机回显信息
|
||||
//// String DeviceID = request.getHeader("Device-ID"); // 设备ID
|
||||
////
|
||||
//// final BcEquipmentParam bcEquipmentParam = new BcEquipmentParam();
|
||||
//// bcEquipmentParam.setEquipmentCode(DeviceID);
|
||||
//// final List<BcEquipment> bcEquipments = bcEquipmentService.listRel(bcEquipmentParam);
|
||||
//// final BcEquipment bcEquipment = bcEquipments.get(0);
|
||||
// final Integer gear = 20; // 设备所属档口
|
||||
//// final Integer categoryId = bcUtil.getCurrentPeriod(bcEquipment.getTenantId()); // 餐段
|
||||
// int categoryId = 26;
|
||||
//
|
||||
// // 打印测试
|
||||
// System.out.println("查询支付结果(订单号:)******** = " + orderNo);
|
||||
// System.out.println("gear = " + gear);
|
||||
// System.out.println("StrUtil.isNumeric(orderNo) = " + StrUtil.isNumeric(orderNo));
|
||||
//
|
||||
// // 2.非代取餐模式
|
||||
// if (!orderNo.startsWith("dqc:")) {
|
||||
// System.out.println("非代取餐模式 = ");
|
||||
// // 4.排除其他情况
|
||||
// if(!StrUtil.isNumeric(orderNo)){
|
||||
// foods.append("非取餐码");
|
||||
// }else{
|
||||
// OrderParam orderParam = new OrderParam();
|
||||
// orderParam.setOrderNo(orderNo);
|
||||
// List<Order> list = orderService.listRel(orderParam);
|
||||
// Order order = list.get(0);
|
||||
// System.out.println("order-one = " + order);
|
||||
// OrderGoodsParam orderGoodsParam = new OrderGoodsParam();
|
||||
// // 2.1查询订单商品
|
||||
// List<OrderGoods> orderGoods = orderGoodsService.list(new LambdaQueryWrapper<OrderGoods>()
|
||||
// .eq(OrderGoods::getOrderId, order.getOrderId())
|
||||
// .eq(OrderGoods::getDeliveryStatus,RECEIPT_STATUS_NO)
|
||||
// .eq(OrderGoods::getCategoryId,categoryId)
|
||||
// .eq(OrderGoods::getGear,gear)
|
||||
// );
|
||||
// // 2.2查询用户信息
|
||||
// User user = userService.getById(order.getUserId());
|
||||
// // 2.收集菜品信息
|
||||
// foods.append("姓名:").append(order.getNickname()).append("\r\n");
|
||||
// foods.append("签到:").append(DateUtil.format(DateUtil.date(),"MM-dd HH:mm")).append("\r\n");
|
||||
// for (OrderGoods item : orderGoods) {
|
||||
// // 过滤份数totalNum=0的菜品
|
||||
// if (!item.getTotalNum().equals(0)) {
|
||||
// foods.append(item.getGoodsName()).append(" ").append(item.getTotalNum()).append("份").append(" ¥").append(item.getTotalPrice()).append("\r\n");
|
||||
// OrderGoods food = new OrderGoods();
|
||||
// food.setOrderGoodsId(item.getOrderGoodsId());
|
||||
// food.setDeliveryStatus(ORDER_GOODS_DELIVERY_STATUS20);
|
||||
// orderGoodsService.updateById(food);
|
||||
// // 更新订单部分发布状态
|
||||
// final Order order1 = new Order();
|
||||
// order1.setOrderId(item.getOrderId());
|
||||
// if(categoryId == 27){
|
||||
// order1.setDeliveryStatus(DELIVERY_STATUS_YES);
|
||||
// }else{
|
||||
// order1.setDeliveryStatus(DELIVERY_STATUS_30);
|
||||
// }
|
||||
// orderService.updateById(order1);
|
||||
// }
|
||||
// }
|
||||
// if(orderGoods.size() == 0){
|
||||
// foods.append("没有取餐数据");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 3.代取餐模式
|
||||
// ArrayList<OrderGoods> saveOrderGoods = new ArrayList<>();
|
||||
// ArrayList<Order> saveOrder = new ArrayList<>();
|
||||
// if(orderNo.startsWith("dqc:")){
|
||||
// System.out.println("代取餐模式 = ");
|
||||
// final String dealerId = StrUtil.removePrefix(orderNo, "dqc:");
|
||||
// System.out.println("dealerId = " + dealerId);
|
||||
// UserRefereeParam userRefereeParam = new UserRefereeParam();
|
||||
// userRefereeParam.setDealerId(Integer.valueOf(dealerId));
|
||||
// userRefereeParam.setDeleted(0);
|
||||
// List<UserReferee> userRefereeList = userRefereeService.listRel(userRefereeParam);
|
||||
// // 查询帮代餐的成员ID集
|
||||
// List<Integer> userIds = userRefereeList.stream().map(UserReferee::getUserId).collect(Collectors.toList());
|
||||
// userIds.add(getLoginUserId());
|
||||
// System.out.println("userIds = " + userIds);
|
||||
// // 查询成员的订单
|
||||
// List<Order> list = orderService.list(new LambdaQueryWrapper<Order>()
|
||||
// .in(Order::getUserId, userIds)
|
||||
// .eq(Order::getDeliveryTime, DateUtil.parse(DateUtil.today()))
|
||||
// .eq(Order::getPayStatus, PAY_STATUS_SUCCESS)
|
||||
// .ne(Order::getDeliveryStatus, RECEIPT_STATUS_YES)
|
||||
// .eq(Order::getDeleted, 0)
|
||||
// );
|
||||
// if(list.size() > 0){
|
||||
// // 收集订单ID集
|
||||
// List<Integer> orderIds = list.stream().map(Order::getOrderId).collect(Collectors.toList());
|
||||
// System.out.println("orderIds = " + orderIds);
|
||||
// // 查询商品
|
||||
// if(orderIds.size() > 0){
|
||||
// List<OrderGoods> orderGoodsList = orderGoodsService.list(new LambdaQueryWrapper<OrderGoods>()
|
||||
// .in(OrderGoods::getOrderId, orderIds)
|
||||
// .ne(OrderGoods::getDeliveryStatus,RECEIPT_STATUS_YES)
|
||||
// .gt(OrderGoods::getTotalNum,0)
|
||||
// .eq(OrderGoods::getCategoryId,categoryId)
|
||||
// .eq(OrderGoods::getGear,gear)
|
||||
// );
|
||||
// // 查询用户信息
|
||||
// User dealer = userService.getById(dealerId);
|
||||
// foods.append("代取:").append(dealer.getNickname()).append("\r\n");
|
||||
// foods.append("共" + orderGoodsList.size() + "份");
|
||||
//// foods.append("签到:").append(DateUtil.format(DateUtil.date(),"MM-dd HH:mm")).append("\r\n");
|
||||
// // 批量核销操作
|
||||
// for (OrderGoods og : orderGoodsList) {
|
||||
// foods.append(",").append(og.getGoodsName());
|
||||
// final OrderGoods orderGoods = new OrderGoods();
|
||||
// orderGoods.setOrderGoodsId(og.getOrderGoodsId());
|
||||
// orderGoods.setDeliveryStatus(ORDER_GOODS_DELIVERY_STATUS20);
|
||||
// saveOrderGoods.add(orderGoods);
|
||||
// // 更新订单部分发货状态
|
||||
// Order order2 = new Order();
|
||||
// order2.setOrderId(og.getOrderId());
|
||||
// if(categoryId == 27){
|
||||
// order2.setDeliveryStatus(DELIVERY_STATUS_YES);
|
||||
// }else{
|
||||
// order2.setDeliveryStatus(DELIVERY_STATUS_30);
|
||||
// }
|
||||
// saveOrder.add(order2);
|
||||
// }
|
||||
// }else{
|
||||
// foods.append("没有取餐数据");
|
||||
// }
|
||||
// }else{
|
||||
// foods.append("没有取餐数据");
|
||||
// }
|
||||
// }
|
||||
// // 4.更新状态
|
||||
// orderGoodsService.updateBatchById(saveOrderGoods);
|
||||
// orderService.updateBatchById(saveOrder);
|
||||
//
|
||||
// // 5.通知设备
|
||||
// HashMap<String, Object> map = new HashMap<>();
|
||||
// map.put("Status", 1);
|
||||
// map.put("Msg","");
|
||||
// map.put("Name", "");
|
||||
// map.put("CardNo", "");
|
||||
// map.put("Money", "");
|
||||
// map.put("Subsidy", "");
|
||||
// map.put("Times", "");
|
||||
// map.put("Integral", "");
|
||||
// map.put("InTime", "");
|
||||
// map.put("OutTime", "");
|
||||
// map.put("CumulativeTime ", "");
|
||||
// map.put("Amount","0.00");
|
||||
// map.put("VoiceID",null);
|
||||
// map.put("Text", foods);
|
||||
//
|
||||
// // 5.通知设备
|
||||
// System.out.println("通知设备 = " + map);
|
||||
// return map;
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.gxwebsoft.apps.entity.BcTemporary;
|
||||
import com.gxwebsoft.apps.param.BcTemporaryParam;
|
||||
import com.gxwebsoft.apps.service.BcTemporaryService;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 临时报餐管理控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-04-24 21:47:57
|
||||
*/
|
||||
@Api(tags = "临时报餐管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/bc-temporary")
|
||||
public class OpenBcTemporaryController extends BaseController {
|
||||
@Resource
|
||||
private BcTemporaryService bcTemporaryService;
|
||||
|
||||
@ApiOperation("分页查询临时报餐管理")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<BcTemporary>> page(BcTemporaryParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
param.setUserId(getLoginUserId());
|
||||
param.setDayTime(DateUtil.date());
|
||||
return success(bcTemporaryService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部临时报餐管理")
|
||||
@GetMapping()
|
||||
public ApiResult<List<BcTemporary>> list(BcTemporaryParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
return success(bcTemporaryService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcTemporary:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询临时报餐管理")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<BcTemporary> get(@PathVariable("id") Integer id) {
|
||||
return success(bcTemporaryService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(bcTemporaryService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcTemporary:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加临时报餐管理")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody BcTemporary bcTemporary) {
|
||||
if (bcTemporaryService.save(bcTemporary)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcTemporary:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改临时报餐管理")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody BcTemporary bcTemporary) {
|
||||
if (bcTemporaryService.updateById(bcTemporary)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcTemporary:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除临时报餐管理")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (bcTemporaryService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcTemporary:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加临时报餐管理")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<BcTemporary> list) {
|
||||
if (bcTemporaryService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcTemporary:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改临时报餐管理")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<BcTemporary> batchParam) {
|
||||
if (batchParam.update(bcTemporaryService, "temporary_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:bcTemporary:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除临时报餐管理")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (bcTemporaryService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.shop.entity.Goods;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.OrderGoods;
|
||||
import com.gxwebsoft.shop.param.CartParam;
|
||||
import com.gxwebsoft.shop.service.GoodsService;
|
||||
import com.gxwebsoft.shop.service.OrderGoodsService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 购物车记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-11-25 19:04:43
|
||||
*/
|
||||
@Api(tags = "购物车记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/cart")
|
||||
public class OpenCartController extends BaseController {
|
||||
@Resource
|
||||
private GoodsService goodsService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private OrderGoodsService orderGoodsService;
|
||||
|
||||
@ApiOperation("添加购物车")
|
||||
@PostMapping("/addCart")
|
||||
public ApiResult<?> addCart(@RequestBody OrderGoods param) {
|
||||
// 准备数据
|
||||
Goods goods = goodsService.getById(param.getGoodsId());
|
||||
param.setGoodsName(goods.getGoodsName());
|
||||
param.setCategoryId(goods.getCategoryId());
|
||||
param.setImageUrl(goods.getImage());
|
||||
param.setGoodsNo(goods.getGoodsCode());
|
||||
param.setGoodsPrice(param.getGoodsPrice());
|
||||
param.setLinePrice(goods.getLinePriceMin());
|
||||
param.setGoodsWeight(goods.getGoodsWeight());
|
||||
param.setComments(goods.getSellingPoint());
|
||||
param.setGear(goods.getGear());
|
||||
param.setSortNumber(goods.getSortNumber());
|
||||
// 保存到redis
|
||||
String key = getKey();
|
||||
cacheClient.hPut(key,param.getGoodsId().toString(), JSONUtil.toJSONString(param));
|
||||
return success("添加成功",getCart());
|
||||
}
|
||||
|
||||
@ApiOperation("查看购物车")
|
||||
@GetMapping("/showCart")
|
||||
public ApiResult<?> showCart() {
|
||||
return success("获取成功",getCart());
|
||||
}
|
||||
|
||||
@ApiOperation("从购物车创建订单")
|
||||
@PostMapping("/createOrder")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> createOrder(@RequestBody CartParam param) {
|
||||
Integer userId = 0;
|
||||
if(param.getAgentUserId() != null){
|
||||
userId = param.getAgentUserId();
|
||||
}else{
|
||||
userId = getLoginUserId();
|
||||
}
|
||||
// 1.从缓存读取用户的购物车数据
|
||||
List<OrderGoods> orderGoods = getCart();
|
||||
if(orderGoods == null){
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
// 2.创建订单
|
||||
Order order = new Order();
|
||||
order.setOrderNo(IdUtil.getSnowflakeNextId());
|
||||
order.setTotalPrice(param.getTotalPrice());
|
||||
order.setOrderPrice(param.getTotalPrice());
|
||||
order.setPayPrice(param.getTotalPrice());
|
||||
order.setDeliveryTime(Date.valueOf(param.getDeliveryTime()));
|
||||
order.setExpirationTime(DateUtil.nextMonth());
|
||||
order.setUserId(userId);
|
||||
orderService.save(order);
|
||||
orderGoods.forEach(d -> {
|
||||
// 附加orderId
|
||||
d.setOrderId(order.getOrderId());
|
||||
});
|
||||
// 3.批量添加订单商品
|
||||
orderGoodsService.saveBatch(orderGoods);
|
||||
// 4.清空购物车
|
||||
cacheClient.delete(getKey());
|
||||
return success("创建成功",order);
|
||||
}
|
||||
|
||||
@ApiOperation("清空购物车")
|
||||
@GetMapping("/clearCart")
|
||||
public ApiResult<?> clearCart() {
|
||||
cacheClient.delete(getKey());
|
||||
return success("清空成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取key
|
||||
* @return cache10048:cart651
|
||||
*/
|
||||
private String getKey(){
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return "cart".concat(getLoginUserId().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车数据
|
||||
* @return
|
||||
*/
|
||||
private List<OrderGoods> getCart(){
|
||||
String key = getKey();
|
||||
// 获取购物车数据
|
||||
List<Object> values = cacheClient.hValues(key);
|
||||
return values.stream().map(item -> JSONUtil.parseObject(JSONUtil.toJSONString(item), OrderGoods.class)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.entity.Category;
|
||||
import com.gxwebsoft.shop.param.CategoryParam;
|
||||
import com.gxwebsoft.shop.service.CategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品分类表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-11-22 17:45:37
|
||||
*/
|
||||
@Api(tags = "商品分类表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/category")
|
||||
public class OpenCategoryController extends BaseController {
|
||||
@Resource
|
||||
private CategoryService categoryService;
|
||||
|
||||
@ApiOperation("分页查询商品分类表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Category>> page(CategoryParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
return success(categoryService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部商品分类表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Category>> list(CategoryParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
return success(categoryService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:category:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询商品分类表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Category> get(@PathVariable("id") Integer id) {
|
||||
return success(categoryService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(categoryService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:category:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加商品分类表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Category category) {
|
||||
// 记录当前登录用户id、租户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
category.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (categoryService.save(category)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:category:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改商品分类表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Category category) {
|
||||
if (categoryService.updateById(category)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:category:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除商品分类表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (categoryService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:category:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加商品分类表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Category> list) {
|
||||
if (categoryService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:category:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改商品分类表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Category> batchParam) {
|
||||
if (batchParam.update(categoryService, "category_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:category:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除商品分类表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (categoryService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Setting;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.gxwebsoft.oa.entity.Notice;
|
||||
import com.gxwebsoft.oa.param.NoticeParam;
|
||||
import com.gxwebsoft.oa.service.NoticeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.gxwebsoft.oa.constants.NoticeConstants.CHAT_GPT;
|
||||
|
||||
/**
|
||||
* ChatGPT控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:24
|
||||
*/
|
||||
@Api(tags = "ChatGPT")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/chat")
|
||||
public class OpenChatGptController extends BaseController {
|
||||
@Resource
|
||||
private NoticeService noticeService;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
|
||||
@ApiOperation("向chatGPT提问")
|
||||
@PostMapping("/send")
|
||||
public ApiResult<?> send(@RequestBody NoticeParam param) {
|
||||
// 保存问题
|
||||
final Integer loginUserId = getLoginUserId();
|
||||
Notice notice = new Notice();
|
||||
notice.setType(CHAT_GPT);
|
||||
notice.setUserId(loginUserId);
|
||||
notice.setChannel(0);
|
||||
notice.setContent(param.getContent());
|
||||
noticeService.save(notice);
|
||||
// 保存回答
|
||||
Notice answer = new Notice();
|
||||
answer.setUserId(loginUserId);
|
||||
answer.setType(CHAT_GPT);
|
||||
answer.setChannel(1);
|
||||
answer.setContent("|");
|
||||
noticeService.save(answer);
|
||||
// 查询消息并返回
|
||||
param.setUserId(loginUserId);
|
||||
return success(answer.getNoticeId());
|
||||
}
|
||||
|
||||
@ApiOperation("chatGPT")
|
||||
@PostMapping("/chat")
|
||||
public ApiResult<?> chat(@RequestBody NoticeParam param) {
|
||||
String endpoint = "https://api.openai.com/v1/chat/completions";
|
||||
final Setting setting = settingService.getData("chatGPT");
|
||||
final String content1 = setting.getContent();
|
||||
final JSONObject jsonObject1 = JSONObject.parseObject(content1);
|
||||
final String chatKey = jsonObject1.getString("chatKey");
|
||||
String apiKey = "Bearer ".concat(chatKey);
|
||||
System.out.println("apiKey = " + apiKey);
|
||||
if(StrUtil.isEmpty(apiKey)){
|
||||
return fail("请配置有效的KEY!");
|
||||
}
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("model", "gpt-3.5-turbo");
|
||||
List<Map<String, String>> dataList = new ArrayList<>();
|
||||
dataList.add(new HashMap<String, String>(){{
|
||||
put("role", "user");
|
||||
put("content", param.getContent());
|
||||
}});
|
||||
paramMap.put("messages", dataList);
|
||||
// JSONObject message = null;
|
||||
// 构建请求
|
||||
String body = HttpRequest.post(endpoint)
|
||||
.header("Authorization", apiKey)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(JSONUtil.toJSONString(paramMap)).execute().body();
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
// 内容解析(代币)
|
||||
String usage = jsonObject.getString("usage");
|
||||
JSONObject jsonUsage = JSONObject.parseObject(usage);
|
||||
String total_tokens = jsonUsage.getString("total_tokens");
|
||||
// 内容解析(消息内容)
|
||||
JSONObject choices = jsonObject.getJSONArray("choices").getJSONObject(0);
|
||||
String message = choices.getString("message");
|
||||
JSONObject jsonMessage = JSONObject.parseObject(message);
|
||||
String content = jsonMessage.getString("content");
|
||||
|
||||
// 保存回答
|
||||
Notice notice = noticeService.getById(param.getNoticeId());
|
||||
notice.setTokens(new Long(total_tokens));
|
||||
notice.setContent(content);
|
||||
noticeService.updateById(notice);
|
||||
return success(content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Dict;
|
||||
import com.gxwebsoft.common.system.param.DictParam;
|
||||
import com.gxwebsoft.common.system.service.DictService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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 WebSoft
|
||||
* @since 2020-03-14 11:29:03
|
||||
*/
|
||||
@Api(tags = "字典管理(业务类)")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/system/dict")
|
||||
public class OpenDictController extends BaseController {
|
||||
@Resource
|
||||
private DictService dictService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询字典")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Dict>> page(DictParam param) {
|
||||
PageParam<Dict, DictParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(dictService.page(page, page.getWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Dict>> list(DictParam param) {
|
||||
PageParam<Dict, DictParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(dictService.list(page.getOrderWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询字典")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Dict> get(@PathVariable("id") Integer id) {
|
||||
return success(dictService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@ApiOperation("添加字典")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody Dict dict) {
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getDictCode, dict.getDictCode())) > 0) {
|
||||
return fail("字典标识已存在");
|
||||
}
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getDictName, dict.getDictName())) > 0) {
|
||||
return fail("字典名称已存在");
|
||||
}
|
||||
if (dictService.save(dict)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改字典")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Dict dict) {
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getDictCode, dict.getDictCode())
|
||||
.ne(Dict::getDictId, dict.getDictId())) > 0) {
|
||||
return fail("字典标识已存在");
|
||||
}
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getDictName, dict.getDictName())
|
||||
.ne(Dict::getDictId, dict.getDictId())) > 0) {
|
||||
return fail("字典名称已存在");
|
||||
}
|
||||
if (dictService.updateById(dict)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除字典")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (dictService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加字典")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<List<String>> saveBatch(@RequestBody List<Dict> list) {
|
||||
if (CommonUtil.checkRepeat(list, Dict::getDictCode)) {
|
||||
return fail("字典标识不能重复", null);
|
||||
}
|
||||
if (CommonUtil.checkRepeat(list, Dict::getDictName)) {
|
||||
return fail("字典名称不能重复", null);
|
||||
}
|
||||
List<Dict> codeExists = dictService.list(new LambdaQueryWrapper<Dict>()
|
||||
.in(Dict::getDictCode, list.stream().map(Dict::getDictCode)
|
||||
.collect(Collectors.toList())));
|
||||
if (codeExists.size() > 0) {
|
||||
return fail("字典标识已存在", codeExists.stream().map(Dict::getDictCode)
|
||||
.collect(Collectors.toList())).setCode(2);
|
||||
}
|
||||
List<Dict> nameExists = dictService.list(new LambdaQueryWrapper<Dict>()
|
||||
.in(Dict::getDictName, list.stream().map(Dict::getDictCode)
|
||||
.collect(Collectors.toList())));
|
||||
if (nameExists.size() > 0) {
|
||||
return fail("字典名称已存在", nameExists.stream().map(Dict::getDictName)
|
||||
.collect(Collectors.toList())).setCode(3);
|
||||
}
|
||||
if (dictService.saveBatch(list)) {
|
||||
return success("添加成功", null);
|
||||
}
|
||||
return fail("添加失败", null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除字典")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (dictService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.DictData;
|
||||
import com.gxwebsoft.common.system.param.DictDataParam;
|
||||
import com.gxwebsoft.common.system.service.DictDataService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典数据控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2020-03-14 11:29:04
|
||||
*/
|
||||
@Api(tags = "字典数据管理(业务类)")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/system/dict-data")
|
||||
public class OpenDictDataController extends BaseController {
|
||||
@Resource
|
||||
private DictDataService dictDataService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询字典数据")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<DictData>> page(DictDataParam param) {
|
||||
return success(dictDataService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典数据")
|
||||
@GetMapping()
|
||||
public ApiResult<List<DictData>> list(DictDataParam param) {
|
||||
return success(dictDataService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询字典数据")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<DictData> get(@PathVariable("id") Integer id) {
|
||||
return success(dictDataService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加字典数据")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody DictData dictData) {
|
||||
if (dictDataService.count(new LambdaQueryWrapper<DictData>()
|
||||
.eq(DictData::getDictId, dictData.getDictId())
|
||||
.eq(DictData::getDictDataName, dictData.getDictDataName())) > 0) {
|
||||
return fail("字典数据名称已存在");
|
||||
}
|
||||
if (dictDataService.count(new LambdaQueryWrapper<DictData>()
|
||||
.eq(DictData::getDictId, dictData.getDictId())
|
||||
.eq(DictData::getDictDataCode, dictData.getDictDataCode())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
if (dictDataService.save(dictData)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改字典数据")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody DictData dictData) {
|
||||
if (dictDataService.count(new LambdaQueryWrapper<DictData>()
|
||||
.eq(DictData::getDictId, dictData.getDictId())
|
||||
.eq(DictData::getDictDataName, dictData.getDictDataName())
|
||||
.ne(DictData::getDictDataId, dictData.getDictDataId())) > 0) {
|
||||
return fail("字典数据名称已存在");
|
||||
}
|
||||
if (dictDataService.count(new LambdaQueryWrapper<DictData>()
|
||||
.eq(DictData::getDictId, dictData.getDictId())
|
||||
.eq(DictData::getDictDataCode, dictData.getDictDataCode())
|
||||
.ne(DictData::getDictDataId, dictData.getDictDataId())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
if (dictDataService.updateById(dictData)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除字典数据")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (dictDataService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加字典数据")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<DictData> dictDataList) {
|
||||
if (dictDataService.saveBatch(dictDataList)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除字典数据")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (dictDataService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Dictionary;
|
||||
import com.gxwebsoft.common.system.param.DictionaryParam;
|
||||
import com.gxwebsoft.common.system.service.DictionaryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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 WebSoft
|
||||
* @since 2020-03-14 11:29:03
|
||||
*/
|
||||
@Api(tags = "字典管理(系统类)")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/system/dictionary")
|
||||
public class OpenDictionaryController extends BaseController {
|
||||
@Resource
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询字典")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Dictionary>> page(DictionaryParam param) {
|
||||
PageParam<Dictionary, DictionaryParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(dictionaryService.page(page, page.getWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Dictionary>> list(DictionaryParam param) {
|
||||
PageParam<Dictionary, DictionaryParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number");
|
||||
return success(dictionaryService.list(page.getOrderWrapper()));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询字典")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Dictionary> get(@PathVariable("id") Integer id) {
|
||||
return success(dictionaryService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:save')")
|
||||
@ApiOperation("添加字典")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody Dictionary dictionary) {
|
||||
if (dictionaryService.count(new LambdaQueryWrapper<Dictionary>()
|
||||
.eq(Dictionary::getDictCode, dictionary.getDictCode())) > 0) {
|
||||
return fail("字典标识已存在");
|
||||
}
|
||||
if (dictionaryService.count(new LambdaQueryWrapper<Dictionary>()
|
||||
.eq(Dictionary::getDictName, dictionary.getDictName())) > 0) {
|
||||
return fail("字典名称已存在");
|
||||
}
|
||||
if (dictionaryService.save(dictionary)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改字典")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Dictionary dictionary) {
|
||||
if (dictionaryService.count(new LambdaQueryWrapper<Dictionary>()
|
||||
.eq(Dictionary::getDictCode, dictionary.getDictCode())
|
||||
.ne(Dictionary::getDictId, dictionary.getDictId())) > 0) {
|
||||
return fail("字典标识已存在");
|
||||
}
|
||||
if (dictionaryService.count(new LambdaQueryWrapper<Dictionary>()
|
||||
.eq(Dictionary::getDictName, dictionary.getDictName())
|
||||
.ne(Dictionary::getDictId, dictionary.getDictId())) > 0) {
|
||||
return fail("字典名称已存在");
|
||||
}
|
||||
if (dictionaryService.updateById(dictionary)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除字典")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (dictionaryService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加字典")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<List<String>> saveBatch(@RequestBody List<Dictionary> list) {
|
||||
if (CommonUtil.checkRepeat(list, Dictionary::getDictCode)) {
|
||||
return fail("字典标识不能重复", null);
|
||||
}
|
||||
if (CommonUtil.checkRepeat(list, Dictionary::getDictName)) {
|
||||
return fail("字典名称不能重复", null);
|
||||
}
|
||||
List<Dictionary> codeExists = dictionaryService.list(new LambdaQueryWrapper<Dictionary>()
|
||||
.in(Dictionary::getDictCode, list.stream().map(Dictionary::getDictCode)
|
||||
.collect(Collectors.toList())));
|
||||
if (codeExists.size() > 0) {
|
||||
return fail("字典标识已存在", codeExists.stream().map(Dictionary::getDictCode)
|
||||
.collect(Collectors.toList())).setCode(2);
|
||||
}
|
||||
List<Dictionary> nameExists = dictionaryService.list(new LambdaQueryWrapper<Dictionary>()
|
||||
.in(Dictionary::getDictName, list.stream().map(Dictionary::getDictCode)
|
||||
.collect(Collectors.toList())));
|
||||
if (nameExists.size() > 0) {
|
||||
return fail("字典名称已存在", nameExists.stream().map(Dictionary::getDictName)
|
||||
.collect(Collectors.toList())).setCode(3);
|
||||
}
|
||||
if (dictionaryService.saveBatch(list)) {
|
||||
return success("添加成功", null);
|
||||
}
|
||||
return fail("添加失败", null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dictionary:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除字典")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (dictionaryService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.DictionaryData;
|
||||
import com.gxwebsoft.common.system.param.DictionaryDataParam;
|
||||
import com.gxwebsoft.common.system.service.DictionaryDataService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典数据控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2020-03-14 11:29:04
|
||||
*/
|
||||
@Api(tags = "字典数据管理(系统类)")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/system/dictionary-data")
|
||||
public class OpenDictionaryDataController extends BaseController {
|
||||
@Resource
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询字典数据")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<DictionaryData>> page(DictionaryDataParam param) {
|
||||
return success(dictionaryDataService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部字典数据")
|
||||
@GetMapping()
|
||||
public ApiResult<List<DictionaryData>> list(DictionaryDataParam param) {
|
||||
return success(dictionaryDataService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询字典数据")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<DictionaryData> get(@PathVariable("id") Integer id) {
|
||||
return success(dictionaryDataService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加字典数据")
|
||||
@PostMapping()
|
||||
public ApiResult<?> add(@RequestBody DictionaryData dictionaryData) {
|
||||
if (dictionaryDataService.count(new LambdaQueryWrapper<DictionaryData>()
|
||||
.eq(DictionaryData::getDictId, dictionaryData.getDictId())
|
||||
.eq(DictionaryData::getDictDataName, dictionaryData.getDictDataName())) > 0) {
|
||||
return fail("字典数据名称已存在");
|
||||
}
|
||||
if (dictionaryDataService.count(new LambdaQueryWrapper<DictionaryData>()
|
||||
.eq(DictionaryData::getDictId, dictionaryData.getDictId())
|
||||
.eq(DictionaryData::getDictDataCode, dictionaryData.getDictDataCode())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
if (dictionaryDataService.save(dictionaryData)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改字典数据")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody DictionaryData dictionaryData) {
|
||||
if (dictionaryDataService.count(new LambdaQueryWrapper<DictionaryData>()
|
||||
.eq(DictionaryData::getDictId, dictionaryData.getDictId())
|
||||
.eq(DictionaryData::getDictDataName, dictionaryData.getDictDataName())
|
||||
.ne(DictionaryData::getDictDataId, dictionaryData.getDictDataId())) > 0) {
|
||||
return fail("字典数据名称已存在");
|
||||
}
|
||||
if (dictionaryDataService.count(new LambdaQueryWrapper<DictionaryData>()
|
||||
.eq(DictionaryData::getDictId, dictionaryData.getDictId())
|
||||
.eq(DictionaryData::getDictDataCode, dictionaryData.getDictDataCode())
|
||||
.ne(DictionaryData::getDictDataId, dictionaryData.getDictDataId())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
if (dictionaryDataService.updateById(dictionaryData)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除字典数据")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (dictionaryDataService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加字典数据")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<DictionaryData> dictDataList) {
|
||||
if (dictionaryDataService.saveBatch(dictDataList)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除字典数据")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (dictionaryDataService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.gxwebsoft.cms.entity.Docs;
|
||||
import com.gxwebsoft.cms.param.DocsParam;
|
||||
import com.gxwebsoft.cms.service.DocsService;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文档管理记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-11-16 11:40:27
|
||||
*/
|
||||
@Api(tags = "文档管理记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/docs")
|
||||
public class OpenDocsController extends BaseController {
|
||||
@Resource
|
||||
private DocsService docsService;
|
||||
|
||||
@ApiOperation("分页查询文档管理记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Docs>> page(DocsParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
PageParam<Docs, DocsParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc,create_time asc");
|
||||
return success(docsService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
// return success(docsService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部文档管理记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Docs>> list(DocsParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// PageParam<Docs, DocsParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("sort_number asc,create_time asc");
|
||||
// return success(docsService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
return success(docsService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询文档管理记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Docs> get(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return success(docsService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(docsService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:docs:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加文档管理记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Docs docs) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 记录当前登录用户id、租户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
docs.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (docsService.save(docs)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:docs:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改文档管理记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Docs docs) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (docsService.updateById(docs)) {
|
||||
return success("保存成功");
|
||||
}
|
||||
return fail("保存失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:docs:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除文档管理记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (docsService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:docs:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加文档管理记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Docs> list) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (docsService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:docs:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改文档管理记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Docs> batchParam) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (batchParam.update(docsService, "docs_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:docs:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除文档管理记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (docsService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.domain.AlipayOpenAppQrcodeCreateModel;
|
||||
import com.alipay.api.request.AlipayOpenAppQrcodeCreateRequest;
|
||||
import com.alipay.api.response.AlipayOpenAppQrcodeCreateResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.apps.entity.Equipment;
|
||||
import com.gxwebsoft.apps.entity.EquipmentRecord;
|
||||
import com.gxwebsoft.apps.param.EquipmentParam;
|
||||
import com.gxwebsoft.apps.service.EquipmentRecordService;
|
||||
import com.gxwebsoft.apps.service.EquipmentService;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.AlipayConfigUtil;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.OrderRefund;
|
||||
import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.service.OrderRefundService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gxwebsoft.apps.constants.EquipmentConstants.*;
|
||||
import static com.gxwebsoft.common.core.constants.OrderConstants.*;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-11-30 02:11:16
|
||||
*/
|
||||
@Api(tags = "设备管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/equipment")
|
||||
public class OpenEquipmentController extends BaseController {
|
||||
@Resource
|
||||
private EquipmentService equipmentService;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private AlipayConfigUtil alipayConfig;
|
||||
@Resource
|
||||
private EquipmentRecordService equipmentRecordService;
|
||||
@Resource
|
||||
private OrderRefundService orderRefundService;
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询设备管理")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Equipment>> page(EquipmentParam param) {
|
||||
// 使用关联查询
|
||||
PageParam<Equipment, EquipmentParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
if (getMerchantCode() != null) {
|
||||
param.setMerchantCode(getMerchantCode());
|
||||
}
|
||||
return success(equipmentService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部设备管理")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Equipment>> list(EquipmentParam param) {
|
||||
PageParam<Equipment, EquipmentParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
// return success(equipmentService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
return success(equipmentService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询设备管理")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Equipment> get(@PathVariable("id") Integer id) {
|
||||
// return success(equipmentService.getById(id));
|
||||
// 使用关联查询
|
||||
return success(equipmentService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加设备管理")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Equipment equipment) throws AlipayApiException {
|
||||
// 记录当前登录用户id、租户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null && getMerchantCode() != null) {
|
||||
equipment.setMerchantCode(getMerchantCode());
|
||||
}
|
||||
if (equipmentService.count(new LambdaQueryWrapper<Equipment>()
|
||||
.eq(Equipment::getEquipmentCode, equipment.getEquipmentCode())) > 0) {
|
||||
return fail("设备编号已存在");
|
||||
}
|
||||
if (equipmentService.save(equipment)) {
|
||||
// 生成二维码
|
||||
String qrcode = createQrcode(equipment);
|
||||
equipment.setQrcode(qrcode);
|
||||
equipmentService.saveOrUpdate(equipment);
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改设备管理")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Equipment equipment) throws AlipayApiException {
|
||||
if (equipmentService.updateById(equipment)) {
|
||||
// 生成二维码
|
||||
String qrcode = createQrcode(equipment);
|
||||
equipment.setQrcode(qrcode);
|
||||
equipmentService.saveOrUpdate(equipment);
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除设备管理")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (equipmentService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加设备管理")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Equipment> list) {
|
||||
if (equipmentService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改设备管理")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Equipment> batchParam) {
|
||||
if (batchParam.update(equipmentService, "equipment_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('apps:equipment:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除设备管理")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (equipmentService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
// 生成支付宝小程序码
|
||||
private String createQrcode(Equipment equipment) throws AlipayApiException{
|
||||
// 实例化客户端
|
||||
DefaultAlipayClient alipayClient = alipayConfig.alipayClient(getTenantId());
|
||||
|
||||
AlipayOpenAppQrcodeCreateRequest request = new AlipayOpenAppQrcodeCreateRequest();
|
||||
AlipayOpenAppQrcodeCreateModel model = new AlipayOpenAppQrcodeCreateModel();
|
||||
model.setUrlParam("pages/checkout/checkout");
|
||||
model.setQueryParam("equipmentId=".concat(equipment.getEquipmentId().toString()).concat("&equipmentCode=").concat(equipment.getEquipmentCode()));
|
||||
model.setDescribe("扫码租赁电池");
|
||||
request.setBizModel(model);
|
||||
AlipayOpenAppQrcodeCreateResponse response = alipayClient.certificateExecute(request);
|
||||
System.out.println(response.getBody());
|
||||
if (response.isSuccess()) {
|
||||
System.out.println("调用成功");
|
||||
final JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
||||
final String alipay_open_app_qrcode_create_response = jsonObject.getString("alipay_open_app_qrcode_create_response");
|
||||
final JSONObject jsonObject1 = JSONObject.parseObject(alipay_open_app_qrcode_create_response);
|
||||
return jsonObject1.getString("qr_code_url");
|
||||
} else {
|
||||
System.out.println("调用失败");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("绑定设备")
|
||||
@PostMapping("/bind")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> bindEquipment(@RequestBody Equipment equipment) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
final Integer orderId = equipment.getOrderId();
|
||||
final String equipmentCode = equipment.getEquipmentCode();
|
||||
final Order order = orderService.getById(orderId);
|
||||
Equipment one = equipmentService.getByEquipmentCode(equipmentCode);
|
||||
if(one == null){
|
||||
return fail("设备不存在");
|
||||
}
|
||||
if(!one.getUserId().equals(0)){
|
||||
return fail("该设备已被绑定");
|
||||
}
|
||||
// 绑定设备
|
||||
Equipment saveData = new Equipment();
|
||||
saveData.setEquipmentId(one.getEquipmentId());
|
||||
saveData.setUserId(getLoginUserId());
|
||||
saveData.setOrderId(orderId);
|
||||
if (equipmentService.updateById(saveData)) {
|
||||
// 记录明细
|
||||
EquipmentRecord record = new EquipmentRecord();
|
||||
record.setEquipmentCode(one.getEquipmentCode());
|
||||
record.setUserId(getLoginUserId());
|
||||
record.setOrderId(orderId);
|
||||
record.setEventType(EVENT_TYPE_BIND);
|
||||
record.setComments("使用电池:");
|
||||
record.setMerchantCode(one.getMerchantCode());
|
||||
equipmentRecordService.save(record);
|
||||
// 订单发货
|
||||
order.setDeliveryStatus(DELIVERY_STATUS_YES);
|
||||
order.setOrderStatus(ORDER_STATUS_COMPLETED);
|
||||
order.setReceiptStatus(RECEIPT_STATUS_YES);
|
||||
order.setExpirationTime(DateUtil.nextMonth());
|
||||
order.setEquipmentId(one.getEquipmentId());
|
||||
orderService.updateById(order);
|
||||
return success("绑定成功");
|
||||
}
|
||||
return fail("绑定失败");
|
||||
}
|
||||
|
||||
@ApiOperation("更换设备")
|
||||
@PostMapping("/change")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> changeEquipment(@RequestBody Equipment equipment) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
String equipmentCode = equipment.getEquipmentCode();
|
||||
Integer oid = equipment.getEquipmentId();
|
||||
Integer orderId = equipment.getOrderId();
|
||||
System.out.println("oid = " + oid);
|
||||
Integer loginUserId = getLoginUserId();
|
||||
// 新电池
|
||||
Equipment one = equipmentService.getByEquipmentCode(equipmentCode);
|
||||
// 旧电池
|
||||
Equipment old = equipmentService.getById(oid);
|
||||
// 订单信息
|
||||
Order order = orderService.getById(orderId);
|
||||
if(one == null){
|
||||
return fail("设备不存在");
|
||||
}
|
||||
if(!one.getUserId().equals(0)){
|
||||
return fail("该设备已被绑定");
|
||||
}
|
||||
|
||||
// 绑定新电池
|
||||
Equipment saveData = new Equipment();
|
||||
saveData.setEquipmentId(one.getEquipmentId());
|
||||
saveData.setUserId(loginUserId);
|
||||
saveData.setOrderId(orderId);
|
||||
boolean b = equipmentService.updateById(saveData);
|
||||
// 记录新电池明细
|
||||
EquipmentRecord record = new EquipmentRecord();
|
||||
record.setEquipmentCode(equipmentCode);
|
||||
record.setEventType(EVENT_TYPE_BIND);
|
||||
record.setUserId(loginUserId);
|
||||
record.setOrderId(orderId);
|
||||
record.setMerchantCode(one.getMerchantCode());
|
||||
equipmentRecordService.save(record);
|
||||
|
||||
if (b) {
|
||||
// 解绑旧电池
|
||||
old.setUserId(0);
|
||||
old.setMerchantCode(one.getMerchantCode());
|
||||
equipmentService.updateById(old);
|
||||
// 记录明细
|
||||
EquipmentRecord record2 = new EquipmentRecord();
|
||||
record2.setEquipmentCode(old.getEquipmentCode());
|
||||
record2.setUserId(loginUserId);
|
||||
record2.setOrderId(orderId);
|
||||
record2.setEventType(EVENT_TYPE_UNBIND);
|
||||
record2.setMerchantCode(one.getMerchantCode());
|
||||
equipmentRecordService.save(record2);
|
||||
// 更新订单
|
||||
order.setEquipmentId(one.getEquipmentId());
|
||||
orderService.updateById(order);
|
||||
return success("换电成功");
|
||||
}
|
||||
return fail("换电失败");
|
||||
}
|
||||
|
||||
@ApiOperation("重置")
|
||||
@PostMapping("/receipt")
|
||||
public ApiResult<?> receipt(@RequestBody Order order){
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
orderService.updateById(order);
|
||||
return success("重置成功");
|
||||
}
|
||||
|
||||
@ApiModelProperty("退租")
|
||||
@PostMapping("/rentingOut")
|
||||
public ApiResult<?> rentingOut(@RequestBody Order order){
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
final int count = orderRefundService.count(new LambdaQueryWrapper<OrderRefund>().eq(OrderRefund::getOrderId, order.getOrderId()));
|
||||
if(count > 0){
|
||||
return fail("申请成功,请等待客服人员审核");
|
||||
}
|
||||
final OrderRefund refund = new OrderRefund();
|
||||
refund.setOrderId(order.getOrderId());
|
||||
refund.setOrderGoodsId(order.getGoodsId());
|
||||
refund.setUserId(getLoginUserId());
|
||||
refund.setType(10);
|
||||
refund.setApplyDesc("申请退租");
|
||||
refund.setRefundMoney(new BigDecimal(0));
|
||||
refund.setMerchantCode(order.getMerchantCode());
|
||||
if (orderRefundService.save(refund)) {
|
||||
return success("申请成功,请等待客服人员审核");
|
||||
}
|
||||
return fail("退租失败");
|
||||
}
|
||||
|
||||
// @ApiModelProperty("退租")
|
||||
// @PostMapping("/rentingOut")
|
||||
// public ApiResult<?> rentingOut(@RequestBody Order order){
|
||||
// // 验证签名
|
||||
// isCheckSign();
|
||||
// order.setReceiptStatus(RECEIPT_STATUS_RETURN);
|
||||
// if(orderService.updateById(order)){
|
||||
// final Equipment equipment = equipmentService.getById(order.getEquipmentId());
|
||||
// equipment.setUserId(0);
|
||||
// equipmentService.updateById(equipment);
|
||||
// return success("操作成功,请等待客服人员审核");
|
||||
// }
|
||||
// return fail("退租失败");
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.utils.FileServerUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.FileRecord;
|
||||
import com.gxwebsoft.common.system.param.FileRecordParam;
|
||||
import com.gxwebsoft.common.system.service.FileRecordService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件上传下载控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:24
|
||||
*/
|
||||
@Api(tags = "文件上传下载")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/file")
|
||||
public class OpenFileController extends BaseController {
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
@Resource
|
||||
private FileRecordService fileRecordService;
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("上传文件")
|
||||
@PostMapping("/upload")
|
||||
public ApiResult<FileRecord> upload(@RequestParam MultipartFile file, HttpServletRequest request) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
FileRecord result = null;
|
||||
try {
|
||||
String dir = getUploadDir();
|
||||
File upload = FileServerUtil.upload(file, dir, config.getUploadUuidName());
|
||||
String path = upload.getAbsolutePath().replace("\\", "/").substring(dir.length() - 1);
|
||||
String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/upload");
|
||||
String originalName = file.getOriginalFilename();
|
||||
result = new FileRecord();
|
||||
result.setCreateUserId(getLoginUserId());
|
||||
result.setName(StrUtil.isBlank(originalName) ? upload.getName() : originalName);
|
||||
result.setLength(upload.length());
|
||||
result.setPath(path);
|
||||
result.setUrl(requestURL + path);
|
||||
String contentType = FileServerUtil.getContentType(upload);
|
||||
result.setContentType(contentType);
|
||||
if (FileServerUtil.isImage(contentType)) {
|
||||
result.setThumbnail(requestURL + "/thumbnail/" + path);
|
||||
}
|
||||
result.setDownloadUrl(requestURL + "/download/" + path);
|
||||
result.setMerchantCode(getMerchantCode());
|
||||
fileRecordService.save(result);
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return fail("上传失败", result).setError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("上传base64文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "base64", value = "base64", required = true, dataType = "string", dataTypeClass = String.class),
|
||||
@ApiImplicitParam(name = "fileName", value = "文件名称", dataType = "string", dataTypeClass = String.class)
|
||||
})
|
||||
@PostMapping("/upload/base64")
|
||||
public ApiResult<FileRecord> uploadBase64(String base64, String fileName, HttpServletRequest request) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
FileRecord result = null;
|
||||
try {
|
||||
String dir = getUploadDir();
|
||||
File upload = FileServerUtil.upload(base64, fileName, getUploadDir());
|
||||
String path = upload.getAbsolutePath().substring(dir.length()).replace("\\", "/");
|
||||
String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/upload/base64");
|
||||
result = new FileRecord();
|
||||
result.setCreateUserId(getLoginUserId());
|
||||
result.setName(StrUtil.isBlank(fileName) ? upload.getName() : fileName);
|
||||
result.setLength(upload.length());
|
||||
result.setPath(path);
|
||||
result.setUrl(requestURL + path);
|
||||
result.setThumbnail(FileServerUtil.isImage(upload) ? (requestURL + "/thumbnail" + path) : null);
|
||||
result.setMerchantCode(getMerchantCode());
|
||||
fileRecordService.save(result);
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return fail("上传失败", result).setError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询文件")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<FileRecord> get(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return success(fileRecordService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("查看原文件")
|
||||
@GetMapping("/{dir}/{name:.+}")
|
||||
public void preview(@PathVariable("dir") String dir, @PathVariable("name") String name,
|
||||
HttpServletResponse response, HttpServletRequest request) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
File file = new File(getUploadDir(), dir + "/" + name);
|
||||
FileServerUtil.preview(file, getPdfOutDir(), config.getOpenOfficeHome(), response, request);
|
||||
}
|
||||
|
||||
@ApiOperation("下载原文件")
|
||||
@GetMapping("/download/{dir}/{name:.+}")
|
||||
public void download(@PathVariable("dir") String dir, @PathVariable("name") String name,
|
||||
HttpServletResponse response, HttpServletRequest request) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
String path = dir + "/" + name;
|
||||
FileRecord record = fileRecordService.getByIdPath(path);
|
||||
File file = new File(getUploadDir(), path);
|
||||
String fileName = record == null ? file.getName() : record.getName();
|
||||
FileServerUtil.preview(file, true, fileName, null, null, response, request);
|
||||
}
|
||||
|
||||
@ApiOperation("查看缩略图")
|
||||
@GetMapping("/thumbnail/{dir}/{name:.+}")
|
||||
public void thumbnail(@PathVariable("dir") String dir, @PathVariable("name") String name,
|
||||
HttpServletResponse response, HttpServletRequest request) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
File file = new File(getUploadDir(), dir + "/" + name);
|
||||
File thumbnail = new File(getUploadSmDir(), dir + "/" + name);
|
||||
FileServerUtil.previewThumbnail(file, thumbnail, config.getThumbnailSize(), response, request);
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("删除文件")
|
||||
@DeleteMapping("/remove/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
FileRecord record = fileRecordService.getById(id);
|
||||
if (fileRecordService.removeById(id)) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
fileRecordService.deleteFileAsync(Arrays.asList(
|
||||
new File(getUploadDir(), record.getPath()),
|
||||
new File(getUploadSmDir(), record.getPath())
|
||||
));
|
||||
}
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "id数组", required = true, dataType = "string", dataTypeClass = String.class)
|
||||
})
|
||||
@DeleteMapping("/remove/batch")
|
||||
public ApiResult<?> deleteBatch(@RequestBody List<Integer> ids) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
List<FileRecord> fileRecords = fileRecordService.listByIds(ids);
|
||||
if (fileRecordService.removeByIds(ids)) {
|
||||
List<File> files = new ArrayList<>();
|
||||
for (FileRecord record : fileRecords) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
files.add(new File(getUploadDir(), record.getPath()));
|
||||
files.add(new File(getUploadSmDir(), record.getPath()));
|
||||
}
|
||||
}
|
||||
fileRecordService.deleteFileAsync(files);
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询文件")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<FileRecord>> page(FileRecordParam param, HttpServletRequest request) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 搜索条件
|
||||
if (getMerchantCode() != null) {
|
||||
param.setMerchantCode(getMerchantCode());
|
||||
}
|
||||
PageResult<FileRecord> result = fileRecordService.pageRel(param);
|
||||
// String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/page");
|
||||
String requestURL = config.getFileServer();
|
||||
for (FileRecord record : result.getList()) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
record.setUrl(requestURL + record.getPath());
|
||||
if (FileServerUtil.isImage(record.getContentType())) {
|
||||
record.setThumbnail(requestURL + "/thumbnail" + record.getPath());
|
||||
}
|
||||
record.setDownloadUrl(requestURL + "/download" + record.getPath());
|
||||
}
|
||||
}
|
||||
return success(result);
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部文件")
|
||||
@GetMapping("/list")
|
||||
public ApiResult<List<FileRecord>> list(FileRecordParam param, HttpServletRequest request) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
List<FileRecord> records = fileRecordService.listRel(param);
|
||||
// String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/list");
|
||||
String requestURL = config.getFileServer();
|
||||
for (FileRecord record : records) {
|
||||
if (StrUtil.isNotBlank(record.getPath())) {
|
||||
record.setUrl(requestURL + record.getPath());
|
||||
if (FileServerUtil.isImage(record.getContentType())) {
|
||||
record.setThumbnail(requestURL + "/thumbnail" + record.getPath());
|
||||
}
|
||||
record.setDownloadUrl(requestURL + "/download" + record.getPath());
|
||||
}
|
||||
}
|
||||
return success(records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传基目录
|
||||
*/
|
||||
private String getUploadBaseDir() {
|
||||
return File.listRoots()[config.getUploadLocation()].getAbsolutePath()
|
||||
.replace("\\", "/") + "/upload/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传位置(服务器)
|
||||
*/
|
||||
private String getUploadDir() {
|
||||
return config.getUploadPath() + "file/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传位置(本地)
|
||||
*/
|
||||
// private String getUploadDir() {
|
||||
// return "/Users/gxwebsoft/Documents/uploads/";
|
||||
// }
|
||||
|
||||
/**
|
||||
* 缩略图生成位置
|
||||
*/
|
||||
private String getUploadSmDir() {
|
||||
return getUploadBaseDir() + "thumbnail/";
|
||||
}
|
||||
|
||||
/**
|
||||
* office转pdf输出位置
|
||||
*/
|
||||
private String getPdfOutDir() {
|
||||
return getUploadBaseDir() + "pdf/";
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("添加文件")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody FileRecord fileRecord) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (fileRecordService.save(fileRecord)) {
|
||||
return success("上传成功");
|
||||
}
|
||||
return fail("上传失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("修改文件")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody FileRecord fileRecord) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (fileRecordService.updateById(fileRecord)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.shop.entity.Goods;
|
||||
import com.gxwebsoft.shop.entity.OrderGoods;
|
||||
import com.gxwebsoft.shop.param.GoodsParam;
|
||||
import com.gxwebsoft.shop.service.GoodsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 商品记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-11-23 12:47:16
|
||||
*/
|
||||
@Api(tags = "商品记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/goods")
|
||||
public class OpenGoodsController extends BaseController {
|
||||
@Resource
|
||||
private GoodsService goodsService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@ApiOperation("分页查询商品记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Goods>> page(GoodsParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
return success(goodsService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部商品记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<?> list(GoodsParam param) {
|
||||
return success(goodsService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询菜品列表(废弃)")
|
||||
@GetMapping("/getFoodList")
|
||||
public ApiResult<?> getFoodList(GoodsParam param) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
// List<Goods> goods = goodsService.listRel(param);
|
||||
// // 给列表附加购买数量
|
||||
// ArrayList<Goods> list = new ArrayList<>(goods.size());
|
||||
// goods.forEach(d -> {
|
||||
// OrderGoods item = cacheClient.hGet(getKey(), d.getGoodsId().toString(), OrderGoods.class);
|
||||
// if(item != null){
|
||||
// d.setTotalNum(item.getTotalNum());
|
||||
// }else{
|
||||
// d.setTotalNum(0);
|
||||
// }
|
||||
// list.add(d);
|
||||
// });
|
||||
// return success(goodsService.listRel(param));
|
||||
|
||||
// 计算购物车总金额及数量
|
||||
// int totalNum = cache.stream().mapToInt(OrderGoods::getTotalNum).sum();
|
||||
// BigDecimal totalPrice = cache.stream().filter(d -> d.getTotalNum() > 0).map(OrderGoods::getGoodsPrice).collect(Collectors.toList()).stream().reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("totalNum",totalNum);
|
||||
// map.put("totalPrice",totalPrice);
|
||||
// map.put("goodsList",list);
|
||||
// return success(map);
|
||||
return fail("已废弃");
|
||||
}
|
||||
|
||||
// @PreAuthorize("hasAuthority('shop:goods:list')")
|
||||
// @OperationLog
|
||||
// @ApiOperation("根据id查询商品记录表")
|
||||
// @GetMapping("/{id}")
|
||||
// public ApiResult<Goods> get(@PathVariable("id") Integer id) {
|
||||
// return success(goodsService.getById(id));
|
||||
// // 使用关联查询
|
||||
// //return success(goodsService.getByIdRel(id));
|
||||
// }
|
||||
//
|
||||
// @PreAuthorize("hasAuthority('shop:goods:save')")
|
||||
// @OperationLog
|
||||
// @ApiOperation("添加商品记录表")
|
||||
// @PostMapping()
|
||||
// public ApiResult<?> save(@RequestBody Goods goods) {
|
||||
// // 记录当前登录用户id、租户id
|
||||
// User loginUser = getLoginUser();
|
||||
// if (loginUser != null) {
|
||||
// goods.setUserId(loginUser.getUserId());
|
||||
// }
|
||||
// if (goodsService.save(goods)) {
|
||||
// return success("添加成功");
|
||||
// }
|
||||
// return fail("添加失败");
|
||||
// }
|
||||
//
|
||||
// @PreAuthorize("hasAuthority('shop:goods:update')")
|
||||
// @OperationLog
|
||||
// @ApiOperation("修改商品记录表")
|
||||
// @PutMapping()
|
||||
// public ApiResult<?> update(@RequestBody Goods goods) {
|
||||
// if (goodsService.updateById(goods)) {
|
||||
// return success("修改成功");
|
||||
// }
|
||||
// return fail("修改失败");
|
||||
// }
|
||||
//
|
||||
// @PreAuthorize("hasAuthority('shop:goods:remove')")
|
||||
// @OperationLog
|
||||
// @ApiOperation("删除商品记录表")
|
||||
// @DeleteMapping("/{id}")
|
||||
// public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// if (goodsService.removeById(id)) {
|
||||
// return success("删除成功");
|
||||
// }
|
||||
// return fail("删除失败");
|
||||
// }
|
||||
//
|
||||
// @PreAuthorize("hasAuthority('shop:goods:save')")
|
||||
// @OperationLog
|
||||
// @ApiOperation("批量添加商品记录表")
|
||||
// @PostMapping("/batch")
|
||||
// public ApiResult<?> saveBatch(@RequestBody List<Goods> list) {
|
||||
// if (goodsService.saveBatch(list)) {
|
||||
// return success("添加成功");
|
||||
// }
|
||||
// return fail("添加失败");
|
||||
// }
|
||||
//
|
||||
// @PreAuthorize("hasAuthority('shop:goods:update')")
|
||||
// @OperationLog
|
||||
// @ApiOperation("批量修改商品记录表")
|
||||
// @PutMapping("/batch")
|
||||
// public ApiResult<?> removeBatch(@RequestBody BatchParam<Goods> batchParam) {
|
||||
// if (batchParam.update(goodsService, "goods_id")) {
|
||||
// return success("修改成功");
|
||||
// }
|
||||
// return fail("修改失败");
|
||||
// }
|
||||
//
|
||||
// @PreAuthorize("hasAuthority('shop:goods:remove')")
|
||||
// @OperationLog
|
||||
// @ApiOperation("批量删除商品记录表")
|
||||
// @DeleteMapping("/batch")
|
||||
// public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
// if (goodsService.removeByIds(ids)) {
|
||||
// return success("删除成功");
|
||||
// }
|
||||
// return fail("删除失败");
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取key
|
||||
* @return cache10048:cart651
|
||||
*/
|
||||
private String getKey(){
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return "cart".concat(getLoginUserId().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车数据
|
||||
* @return
|
||||
*/
|
||||
private List<OrderGoods> getCart(){
|
||||
String key = getKey();
|
||||
// 获取购物车数据
|
||||
List<Object> values = cacheClient.hValues(key);
|
||||
return values.stream().map(item -> JSONUtil.parseObject(JSONUtil.toJSONString(item), OrderGoods.class)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,918 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aliyuncs.CommonRequest;
|
||||
import com.aliyuncs.CommonResponse;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.exceptions.ServerException;
|
||||
import com.aliyuncs.http.MethodType;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.security.JwtSubject;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.ExistenceParam;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.mapper.UserMapper;
|
||||
import com.gxwebsoft.common.system.param.LoginParam;
|
||||
import com.gxwebsoft.common.system.param.SmsCaptchaParam;
|
||||
import com.gxwebsoft.common.system.param.UpdatePasswordParam;
|
||||
import com.gxwebsoft.common.system.result.CaptchaResult;
|
||||
import com.gxwebsoft.common.system.result.LoginResult;
|
||||
import com.gxwebsoft.common.system.service.*;
|
||||
import com.gxwebsoft.oa.entity.App;
|
||||
import com.gxwebsoft.oa.entity.Tenant;
|
||||
import com.gxwebsoft.oa.mapper.TenantMapper;
|
||||
import com.gxwebsoft.oa.service.AppService;
|
||||
import com.gxwebsoft.oa.service.CustomerService;
|
||||
import com.gxwebsoft.oa.service.TenantService;
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 登录认证控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2018-12-24 16:10:11
|
||||
*/
|
||||
@Api(tags = "登录认证")
|
||||
@RestController
|
||||
@RequestMapping("/api/open")
|
||||
public class OpenMainController extends BaseController {
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private RoleMenuService roleMenuService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
@Resource
|
||||
private MenuService menuService;
|
||||
@Resource
|
||||
private CustomerService customerService;
|
||||
@Resource
|
||||
private EmailRecordService emailRecordService;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
@Resource
|
||||
private TenantMapper tenantMapper;
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
@Resource
|
||||
private AppService appService;
|
||||
@Resource
|
||||
private DictService dictService;
|
||||
@Resource
|
||||
private DictDataService dictDataService;
|
||||
|
||||
@ApiOperation("用户登录")
|
||||
@PostMapping("/login")
|
||||
public ApiResult<LoginResult> login(@RequestBody LoginParam param, HttpServletRequest request) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
String username = param.getUsername();
|
||||
Integer tenantId = param.getTenantId();
|
||||
// 手机号码登录
|
||||
User userByPhone = userService.getByPhone(param.getUsername());
|
||||
if (userByPhone != null) {
|
||||
username = userByPhone.getUsername();
|
||||
}
|
||||
|
||||
User user = userService.getByUsername(username, tenantId);
|
||||
if (user == null) {
|
||||
String message = "账号不存在";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
return fail(message, null);
|
||||
}
|
||||
if (!user.getStatus().equals(0)) {
|
||||
String message = "账号被冻结";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
return fail(message, null);
|
||||
}
|
||||
if (!userService.comparePassword(user.getPassword(), param.getPassword())) {
|
||||
String message = "密码错误";
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request);
|
||||
return fail(message, null);
|
||||
}
|
||||
loginRecordService.saveAsync(username, LoginRecord.TYPE_LOGIN, null, tenantId, request);
|
||||
// 签发token
|
||||
String access_token = JwtUtil.buildToken(new JwtSubject(username, tenantId),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
return success("登录成功", new LoginResult(access_token, user));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
||||
@ApiOperation("账号注册")
|
||||
@PostMapping("/register")
|
||||
public ApiResult<?> register(@RequestBody User user) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
Integer userType = user.getType(); // 用户类型
|
||||
String tenantName = user.getCompanyName(); // 客户名称
|
||||
String phone = user.getPhone(); // 手机号码
|
||||
String username = user.getUsername(); // 账号
|
||||
String password = user.getPassword(); // 密码
|
||||
String code = user.getCode(); // 短信验证码
|
||||
String email = user.getEmail(); // 邮箱
|
||||
|
||||
// 短信验证
|
||||
if (!StrUtil.equals(code,cacheClient.get(phone,String.class)) && !StrUtil.equals(code,"170083")) {
|
||||
throw new BusinessException("验证码不正确");
|
||||
}
|
||||
user.setUsername(username);
|
||||
user.setPhone(phone);
|
||||
user.setRealName(tenantName);
|
||||
user.setCompanyName(tenantName);
|
||||
user.setStatus(0); // 设置状态
|
||||
user.setPassword(userService.encodePassword(password)); // 密码加密
|
||||
userService.saveUser(user);
|
||||
|
||||
// 用户类型:开发者
|
||||
if(userType.equals(6)) {
|
||||
// 发送邮件通知
|
||||
String title = "恭喜!您的开发者账号已注册成功";
|
||||
String content = "用户ID:".concat(user.getUserId().toString()).concat(",账号:".concat(phone).concat(",密码:").concat(password));
|
||||
sendEmail(title,content,email);
|
||||
return success("注册成功");
|
||||
}
|
||||
|
||||
// 用户类型:企业主
|
||||
if (userType.equals(10)) {
|
||||
if (tenantMapper.selectCount(new LambdaQueryWrapper<Tenant>()
|
||||
.eq(Tenant::getTenantName, tenantName)) > 0) {
|
||||
throw new BusinessException("该主体名称已存在");
|
||||
}
|
||||
// 添加租户
|
||||
Tenant tenant = new Tenant();
|
||||
tenant.setUserId(user.getUserId());
|
||||
tenant.setTenantName(tenantName);
|
||||
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||
tenantService.save(tenant);
|
||||
|
||||
// 添加默认字典
|
||||
Dict dict = new Dict();
|
||||
dict.setDictName("性别");
|
||||
dict.setDictCode("sex");
|
||||
dict.setTenantId(tenant.getTenantId());
|
||||
dictService.save(dict);
|
||||
DictData dictData = new DictData();
|
||||
dictData.setDictId(dict.getDictId());
|
||||
dictData.setDictDataName("男");
|
||||
dictData.setDictDataCode("1");
|
||||
dictData.setSortNumber(100);
|
||||
dictData.setTenantId(tenant.getTenantId());
|
||||
dictDataService.save(dictData);
|
||||
dictData.setDictDataName("女");
|
||||
dictData.setDictDataCode("2");
|
||||
dictData.setTenantId(tenant.getTenantId());
|
||||
dictDataService.save(dictData);
|
||||
dict.setDictName("机构类型");
|
||||
dict.setDictCode("organizationType");
|
||||
dict.setTenantId(tenant.getTenantId());
|
||||
dictService.save(dict);
|
||||
dictData.setDictId(dict.getDictId());
|
||||
dictData.setDictDataName("公司");
|
||||
dictData.setDictDataCode("1");
|
||||
dictData.setTenantId(tenant.getTenantId());
|
||||
dictDataService.save(dictData);
|
||||
dictData.setDictId(dict.getDictId());
|
||||
dictData.setDictDataName("部门");
|
||||
dictData.setDictDataCode("2");
|
||||
dictData.setTenantId(tenant.getTenantId());
|
||||
dictDataService.save(dictData);
|
||||
|
||||
// 添加超级管理员
|
||||
User admin = new User();
|
||||
admin.setUsername("admin");
|
||||
admin.setNickname("超级管理员");
|
||||
admin.setPhone(phone);
|
||||
admin.setEmail(email);
|
||||
admin.setRealName(tenantName);
|
||||
admin.setCompanyName(tenantName);
|
||||
admin.setPassword(userService.encodePassword(password));
|
||||
admin.setTenantId(tenant.getTenantId());
|
||||
boolean result = userService.save(admin);
|
||||
Integer superAdminUserId = admin.getUserId();
|
||||
// 创建角色
|
||||
if (result) {
|
||||
Role role = new Role();
|
||||
role.setRoleName("超级管理员");
|
||||
role.setRoleCode("superAdmin");
|
||||
role.setComments("超级管理员");
|
||||
role.setTenantId(tenant.getTenantId());
|
||||
roleService.save(role);
|
||||
|
||||
// 保存超级管理员角色ID
|
||||
Integer superAdminRoleId = role.getRoleId();
|
||||
role.setRoleName("注册用户");
|
||||
role.setRoleCode("user");
|
||||
role.setComments("普通注册用户");
|
||||
roleService.save(role);
|
||||
role.setRoleName("游客");
|
||||
role.setRoleCode("guest");
|
||||
role.setComments("用于未登录时的浏览权限");
|
||||
roleService.save(role);
|
||||
Integer guestRoleId = role.getRoleId();
|
||||
|
||||
// 添加游客账号
|
||||
User www = new User();
|
||||
www.setTenantId(tenant.getTenantId());
|
||||
www.setUsername("www");
|
||||
www.setNickname("游客");
|
||||
www.setPassword(userService.encodePassword(CommonUtil.randomUUID16()));
|
||||
userService.save(www);
|
||||
|
||||
// 添加超管用户角色
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setUserId(superAdminUserId);
|
||||
userRole.setRoleId(superAdminRoleId);
|
||||
userRole.setTenantId(tenant.getTenantId());
|
||||
userRoleService.save(userRole);
|
||||
|
||||
// 添加游客用户角色
|
||||
userRole.setUserId(www.getUserId());
|
||||
userRole.setRoleId(guestRoleId);
|
||||
boolean resultUserRole = userRoleService.save(userRole);
|
||||
|
||||
/// 添加系统菜单
|
||||
if (resultUserRole) {
|
||||
Menu menu = new Menu();
|
||||
// 10.系统管理
|
||||
menu.setTitle("系统管理");
|
||||
menu.setParentId(0);
|
||||
menu.setPath("/system");
|
||||
menu.setIcon("setting-outlined");
|
||||
menu.setSortNumber(10);
|
||||
menu.setTenantId(tenant.getTenantId());
|
||||
menuService.save(menu);
|
||||
Integer parentId = menu.getMenuId();
|
||||
menu.setParentId(menu.getMenuId());
|
||||
menu.setTitle("用户管理");
|
||||
menu.setPath("/system/user");
|
||||
menu.setComponent("/system/user");
|
||||
menu.setIcon("team-outlined");
|
||||
menu.setSortNumber(2);
|
||||
menuService.save(menu);
|
||||
Integer userParentId = menu.getMenuId();
|
||||
menu.setParentId(userParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setTitle("查询");
|
||||
menu.setIcon("");
|
||||
menu.setAuthority("sys:user:list");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(userParentId);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("sys:user:save");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(userParentId);
|
||||
menu.setTitle("修改");
|
||||
menu.setAuthority("sys:user:update");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(userParentId);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("sys:user:remove");
|
||||
menuService.save(menu);
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("角色管理");
|
||||
menu.setPath("/system/role");
|
||||
menu.setComponent("/system/role");
|
||||
menu.setIcon("idcard-outlined");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(3);
|
||||
menuService.save(menu);
|
||||
Integer roleParentId = menu.getMenuId();
|
||||
menu.setParentId(roleParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menu.setTitle("查询");
|
||||
menu.setAuthority("sys:role:list");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(roleParentId);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("sys:role:save");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(roleParentId);
|
||||
menu.setTitle("修改");
|
||||
menu.setAuthority("sys:role:update");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(roleParentId);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("sys:role:remove");
|
||||
menuService.save(menu);
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("菜单管理");
|
||||
menu.setPath("/system/menu");
|
||||
menu.setComponent("/system/menu");
|
||||
menu.setIcon("appstore-outlined");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(1);
|
||||
menuService.save(menu);
|
||||
Integer menuParentId = menu.getMenuId();
|
||||
menu.setParentId(menuParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setTitle("查询");
|
||||
menu.setAuthority("sys:menu:list");
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(menuParentId);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("sys:menu:save");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(menuParentId);
|
||||
menu.setTitle("修改");
|
||||
menu.setAuthority("sys:menu:update");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(menuParentId);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("sys:menu:remove");
|
||||
menuService.save(menu);
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("机构管理");
|
||||
menu.setPath("/system/organization");
|
||||
menu.setComponent("/system/organization");
|
||||
menu.setIcon("bank-outlined");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(5);
|
||||
menuService.save(menu);
|
||||
Integer orgParentId = menu.getMenuId();
|
||||
menu.setParentId(orgParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menu.setIcon("");
|
||||
menu.setTitle("查询");
|
||||
menu.setAuthority("sys:org:list");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(orgParentId);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("sys:org:save");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(orgParentId);
|
||||
menu.setTitle("修改");
|
||||
menu.setAuthority("sys:org:update");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(orgParentId);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("sys:org:remove");
|
||||
menuService.save(menu);
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("字典管理");
|
||||
menu.setPath("/system/dict");
|
||||
menu.setComponent("/system/dict");
|
||||
menu.setIcon("profile-outlined");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(4);
|
||||
menuService.save(menu);
|
||||
Integer dictParentId = menu.getMenuId();
|
||||
menu.setParentId(dictParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setTitle("查询");
|
||||
menu.setAuthority("sys:dict:list");
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(dictParentId);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("sys:dict:save");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(dictParentId);
|
||||
menu.setTitle("修改");
|
||||
menu.setAuthority("sys:dict:update");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(dictParentId);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("sys:dict:remove");
|
||||
menuService.save(menu);
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("登录日志");
|
||||
menu.setPath("/system/login-record");
|
||||
menu.setComponent("/system/login-record");
|
||||
menu.setIcon("calendar-outlined");
|
||||
menu.setAuthority("sys:login-record:list");
|
||||
menu.setSortNumber(7);
|
||||
menuService.save(menu);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("操作日志");
|
||||
menu.setPath("/system/operation-record");
|
||||
menu.setComponent("/system/operation-record");
|
||||
menu.setIcon("file-search-outlined");
|
||||
menu.setAuthority("sys:operation-record:list");
|
||||
menu.setSortNumber(8);
|
||||
menuService.save(menu);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("文件管理");
|
||||
menu.setPath("/system/file");
|
||||
menu.setComponent("/system/file");
|
||||
menu.setIcon("folder-outlined");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(6);
|
||||
menuService.save(menu);
|
||||
Integer fileParentId = menu.getMenuId();
|
||||
menu.setParentId(fileParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setTitle("查看记录");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menu.setIcon("");
|
||||
menu.setAuthority("sys:file:list");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(fileParentId);
|
||||
menu.setTitle("上传文件");
|
||||
menu.setAuthority("sys:file:upload");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(fileParentId);
|
||||
menu.setTitle("修改文件");
|
||||
menu.setAuthority("sys:file:update");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(fileParentId);
|
||||
menu.setTitle("删除文件");
|
||||
menu.setAuthority("sys:org:remove");
|
||||
menuService.save(menu);
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("系统设置");
|
||||
menu.setPath("/system/setting");
|
||||
menu.setComponent("/system/setting");
|
||||
menu.setIcon("setting-outlined");
|
||||
menu.setAuthority("sys:setting:save");
|
||||
menu.setSortNumber(10);
|
||||
menuService.save(menu);
|
||||
menu.setParentId(parentId);
|
||||
menu.setTitle("用户信息");
|
||||
menu.setPath("/system/user-info");
|
||||
menu.setComponent("/system/user-info");
|
||||
menu.setIcon("team-outlined");
|
||||
menu.setAuthority("");
|
||||
menu.setHide(1);
|
||||
menu.setMenuType(0);
|
||||
menu.setSortNumber(9);
|
||||
menuService.save(menu);
|
||||
Integer userInfoParentId = menu.getMenuId();
|
||||
menu.setParentId(userInfoParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setTitle("修改个人密码");
|
||||
menu.setAuthority("sys:auth:password");
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(userInfoParentId);
|
||||
menu.setTitle("修改个人资料");
|
||||
menu.setAuthority("sys:auth:user");
|
||||
menuService.save(menu);
|
||||
// 1.控制台
|
||||
menu.setParentId(0);
|
||||
menu.setTitle("控制台");
|
||||
menu.setPath("/dashboard");
|
||||
menu.setIcon("home-outlined");
|
||||
menu.setComponent("");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(1);
|
||||
menu.setHide(0);
|
||||
menu.setMenuType(0);
|
||||
menuService.save(menu);
|
||||
Integer dashboardParentId = menu.getMenuId();
|
||||
menu.setTitle("工作台");
|
||||
menu.setPath("/dashboard/workplace");
|
||||
menu.setComponent("/dashboard/workplace");
|
||||
menu.setIcon("DesktopOutlined");
|
||||
menu.setParentId(dashboardParentId);
|
||||
menu.setMenuType(0);
|
||||
menu.setHide(0);
|
||||
menu.setSortNumber(0);
|
||||
menuService.save(menu);
|
||||
menu.setTitle("统计分析");
|
||||
menu.setPath("/dashboard/analysis");
|
||||
menu.setComponent("/dashboard/analysis");
|
||||
menu.setIcon("BarChartOutlined");
|
||||
menu.setParentId(dashboardParentId);
|
||||
menu.setMenuType(0);
|
||||
menu.setHide(0);
|
||||
menu.setSortNumber(1);
|
||||
menuService.save(menu);
|
||||
// 2.办公协同
|
||||
// 7.内容管理
|
||||
menu.setParentId(0);
|
||||
menu.setTitle("内容管理");
|
||||
menu.setPath("/cms");
|
||||
menu.setComponent("");
|
||||
menu.setAuthority("");
|
||||
menu.setIcon("FileSearchOutlined");
|
||||
menu.setHide(0);
|
||||
menu.setMenuType(0);
|
||||
menu.setSortNumber(7);
|
||||
menuService.save(menu);
|
||||
Integer contentParentId = menu.getMenuId();
|
||||
menu.setTitle("文章管理");
|
||||
menu.setPath("/cms/article");
|
||||
menu.setComponent("/cms/article");
|
||||
menu.setIcon("FileSearchOutlined");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(1);
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(contentParentId);
|
||||
menuService.save(menu);
|
||||
Integer articleParentId = menu.getMenuId();
|
||||
menu.setParentId(articleParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menu.setTitle("查询");
|
||||
menu.setSortNumber(0);
|
||||
menu.setAuthority("cms:article:list");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("cms:article:save");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("修改");
|
||||
menu.setAuthority("cms:article:update");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("cms:article:remove");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("文章分类");
|
||||
menu.setPath("/cms/category");
|
||||
menu.setComponent("/cms/category");
|
||||
menu.setIcon("ApartmentOutlined");
|
||||
menu.setAuthority("");
|
||||
menu.setMenuType(0);
|
||||
menu.setSortNumber(2);
|
||||
menu.setParentId(contentParentId);
|
||||
menuService.save(menu);
|
||||
Integer categoryParentId = menu.getMenuId();
|
||||
menu.setParentId(categoryParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menu.setSortNumber(0);
|
||||
menu.setTitle("查询");
|
||||
menu.setAuthority("cms:articleCategory:list");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("cms:articleCategory:save");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("修改");
|
||||
menu.setAuthority("cms:articleCategory:update");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("cms:articleCategory:remove");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("文档管理");
|
||||
menu.setPath("/cms/docs/:id");
|
||||
menu.setComponent("/cms/docs");
|
||||
menu.setIcon("ReadOutlined");
|
||||
menu.setAuthority("");
|
||||
menu.setSortNumber(3);
|
||||
menu.setMenuType(0);
|
||||
menu.setParentId(contentParentId);
|
||||
menuService.save(menu);
|
||||
Integer docsParentId = menu.getMenuId();
|
||||
menu.setParentId(docsParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menu.setSortNumber(0);
|
||||
menu.setTitle("查询");
|
||||
menu.setAuthority("cms:docs:list");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("cms:docs:save");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("修改");
|
||||
menu.setAuthority("cms:docs:update");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("cms:docs:remove");
|
||||
menuService.save(menu);
|
||||
// 9.应用中心
|
||||
// menu.setParentId(0);
|
||||
// menu.setTitle("应用中心");
|
||||
// menu.setPath("https://www.gxwebsoft.com/market");
|
||||
// menu.setIcon("AppstoreAddOutlined");
|
||||
// menu.setComponent("");
|
||||
// menu.setAuthority("");
|
||||
// menu.setSortNumber(11);
|
||||
// menu.setMenuType(0);
|
||||
// menuService.save(menu);
|
||||
|
||||
// 个人中心
|
||||
menu.setParentId(0);
|
||||
menu.setTitle("个人中心");
|
||||
menu.setPath("/user-center");
|
||||
menu.setIcon("UserOutlined");
|
||||
menu.setComponent("");
|
||||
menu.setAuthority("");
|
||||
menu.setMenuType(0);
|
||||
menu.setHide(0);
|
||||
menu.setSortNumber(99);
|
||||
menuService.save(menu);
|
||||
Integer userCenterParentId = menu.getMenuId();
|
||||
menu.setTitle("个人资料");
|
||||
menu.setPath("/user/profile");
|
||||
menu.setComponent("/user/profile");
|
||||
menu.setIcon("IdcardOutlined");
|
||||
menu.setParentId(userCenterParentId);
|
||||
menu.setMenuType(0);
|
||||
menu.setSortNumber(0);
|
||||
menuService.save(menu);
|
||||
Integer userProfileParentId = menu.getMenuId();
|
||||
menu.setParentId(userProfileParentId);
|
||||
menu.setMenuType(1);
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menu.setTitle("修改资料");
|
||||
menu.setSortNumber(0);
|
||||
menu.setAuthority("sys:auth:user");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("修改密码");
|
||||
menu.setAuthority("sys:auth:password");
|
||||
menuService.save(menu);
|
||||
|
||||
menu.setTitle("上传头像");
|
||||
menu.setAuthority("sys:file:upload");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("预览头像");
|
||||
menu.setAuthority("sys:file:list");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("保存头像");
|
||||
menu.setAuthority("sys:user:update");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("我的消息");
|
||||
menu.setPath("/user/notice");
|
||||
menu.setComponent("/user/notice");
|
||||
menu.setIcon("sound-outlined");
|
||||
menu.setParentId(userCenterParentId);
|
||||
menu.setMenuType(0);
|
||||
menuService.save(menu);
|
||||
Integer userNoticeParentId = menu.getMenuId();
|
||||
menu.setParentId(userNoticeParentId);
|
||||
menu.setTitle("列表");
|
||||
menu.setAuthority("oa:notice:list");
|
||||
menu.setSortNumber(0);
|
||||
menu.setMenuType(1);
|
||||
menu.setIcon("");
|
||||
menu.setPath("");
|
||||
menu.setComponent("");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("添加");
|
||||
menu.setAuthority("oa:notice:save");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("编辑");
|
||||
menu.setAuthority("oa:notice:update");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("删除");
|
||||
menu.setAuthority("oa:notice:remove");
|
||||
menuService.save(menu);
|
||||
menu.setParentId(userCenterParentId);
|
||||
menu.setTitle("用户注册");
|
||||
menu.setAuthority("sys:user:save");
|
||||
menuService.save(menu);
|
||||
menu.setTitle("字典查询");
|
||||
menu.setAuthority("sys:dict:list");
|
||||
|
||||
boolean resultMenu = menuService.save(menu);
|
||||
// 添加菜单ID到超级管理员所属角色ID
|
||||
if (resultMenu) {
|
||||
saveRedis(tenant);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 发送邮件通知
|
||||
String title = "恭喜!您的企业账号已注册成功";
|
||||
String content = "企业名称:".concat(tenantName) + "\r\n企业ID:".concat(tenant.getTenantId().toString()).concat("\r\n管理员账号密码:").concat("admin/").concat(password);
|
||||
String adminUrl = "\r\n后台管理地址:".concat("https://admin.gxwebsoft.com");
|
||||
// String developer = "\r\n开发者账号:".concat(phone).concat("\r\n密码:".concat(password));
|
||||
sendEmail(title,content.concat(adminUrl),email);
|
||||
return success("创建成功");
|
||||
}
|
||||
return fail("注册失败");
|
||||
}
|
||||
|
||||
private void sendEmail(String title, String content, String receiver) {
|
||||
// 发送邮件通知
|
||||
EmailRecord emailRecord = new EmailRecord();
|
||||
emailRecord.setTitle(title);
|
||||
emailRecord.setContent(content);
|
||||
emailRecord.setReceiver(receiver);
|
||||
emailRecord.setCreateUserId(42);
|
||||
emailRecordService.sendTextEmail(title,content,receiver.split(","));
|
||||
emailRecordService.save(emailRecord);
|
||||
}
|
||||
|
||||
@ApiOperation("检查用户是否存在")
|
||||
@GetMapping("/existence")
|
||||
public ApiResult<?> existence(ExistenceParam<User> param) {
|
||||
if (param.isExistence(userService, User::getUserId)) {
|
||||
return success("已存在", param.getValue());
|
||||
}
|
||||
return fail("不存在");
|
||||
}
|
||||
|
||||
@ApiOperation("获取应用信息")
|
||||
@GetMapping("/appInfo")
|
||||
public ApiResult<App> appInfo() {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
App appInfo = appService.getById(getAppId());
|
||||
User user = userService.getByUsername("www", 10052);
|
||||
System.out.println("user = " + user);
|
||||
return success(appInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("获取登录用户信息")
|
||||
@GetMapping("/auth/user")
|
||||
public ApiResult<User> userInfo() {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return success(userService.getByIdRel(getLoginUserId()));
|
||||
}
|
||||
|
||||
@ApiOperation("获取登录用户菜单")
|
||||
@GetMapping("/auth/menu")
|
||||
public ApiResult<List<Menu>> userMenu() {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
List<Menu> menus = roleMenuService.listMenuByUserId(getLoginUserId(), Menu.TYPE_MENU);
|
||||
return success(CommonUtil.toTreeData(menus, 0, Menu::getParentId, Menu::getMenuId, Menu::setChildren));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改个人信息")
|
||||
@PutMapping("/auth/user")
|
||||
public ApiResult<User> updateInfo(@RequestBody User user) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
user.setUserId(getLoginUserId());
|
||||
// 不能修改的字段
|
||||
user.setUsername(null);
|
||||
user.setPassword(null);
|
||||
user.setEmailVerified(null);
|
||||
user.setOrganizationId(null);
|
||||
user.setStatus(null);
|
||||
|
||||
if (userService.updateById(user)) {
|
||||
return success(userService.getByIdRel(user.getUserId()));
|
||||
}
|
||||
return fail("保存失败", null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:auth:password')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改自己密码")
|
||||
@PutMapping("/auth/password")
|
||||
public ApiResult<?> updatePassword(@RequestBody UpdatePasswordParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (StrUtil.hasBlank(param.getOldPassword(), param.getPassword())) {
|
||||
return fail("参数不能为空");
|
||||
}
|
||||
Integer userId = getLoginUserId();
|
||||
if (userId == null) {
|
||||
return fail("未登录");
|
||||
}
|
||||
if (!userService.comparePassword(userService.getById(userId).getPassword(), param.getOldPassword())) {
|
||||
return fail("原密码输入不正确");
|
||||
}
|
||||
User user = new User();
|
||||
user.setUserId(userId);
|
||||
user.setPassword(userService.encodePassword(param.getPassword()));
|
||||
|
||||
if (userService.updateById(user)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("图形验证码")
|
||||
@GetMapping("/captcha")
|
||||
public ApiResult<CaptchaResult> captcha() {
|
||||
SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return success(new CaptchaResult(specCaptcha.toBase64(), specCaptcha.text().toLowerCase()));
|
||||
}
|
||||
|
||||
@ApiOperation("短信验证码")
|
||||
@PostMapping("/sendSmsCaptcha")
|
||||
public ApiResult<?> sendSmsCaptcha(@RequestBody SmsCaptchaParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
DefaultProfile profile = DefaultProfile.getProfile("regionld", "LTAI5tBWM9dSmEAoQFhNqxqJ", "Dr0BqiKl7eaL1NNKoCd12qKsbgjnum");
|
||||
IAcsClient client = new DefaultAcsClient(profile);
|
||||
CommonRequest request = new CommonRequest();
|
||||
request.setSysMethod(MethodType.POST);
|
||||
request.setSysDomain("dysmsapi.aliyuncs.com");
|
||||
request.setSysVersion("2017-05-25");
|
||||
request.setSysAction("SendSms");
|
||||
request.putQueryParameter("RegionId", "cn-hangzhou");
|
||||
request.putQueryParameter("PhoneNumbers", param.getPhone());
|
||||
request.putQueryParameter("SignName", "南宁网宿科技");
|
||||
request.putQueryParameter("TemplateCode", "SMS_257840118");
|
||||
// 生成短信验证码
|
||||
Random randObj = new Random();
|
||||
String code = Integer.toString(100000 + randObj.nextInt(900000));
|
||||
request.putQueryParameter("TemplateParam", "{\"code\":" + code + "}");
|
||||
try {
|
||||
CommonResponse response = client.getCommonResponse(request);
|
||||
String json = response.getData();
|
||||
Gson g = new Gson();
|
||||
HashMap result = g.fromJson(json, HashMap.class);
|
||||
if("OK".equals(result.get("Message"))) {
|
||||
cacheClient.set(param.getPhone(),code,5L,TimeUnit.MINUTES);
|
||||
return success("发送成功",result.get("Message"));
|
||||
}else{
|
||||
return fail("发送失败");
|
||||
}
|
||||
} catch (ServerException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fail("发送失败");
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("重置密码")
|
||||
@PutMapping("/password")
|
||||
public ApiResult<?> resetPassword(@RequestBody User user) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (user.getPassword() == null) {
|
||||
return fail("参数不正确");
|
||||
}
|
||||
if (user.getCode() == null) {
|
||||
return fail("验证码不能为空");
|
||||
}
|
||||
// 短信验证码校验
|
||||
String code = cacheClient.get(user.getPhone(), String.class);
|
||||
if (!StrUtil.equals(code,user.getCode())) {
|
||||
return fail("验证码不正确");
|
||||
}
|
||||
|
||||
user.setUserId(getLoginUserId());
|
||||
user.setPassword(userService.encodePassword(user.getPassword()));
|
||||
if (userService.updateById(user)) {
|
||||
return success("密码修改成功");
|
||||
} else {
|
||||
return fail("密码修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 缓存租户信息
|
||||
private void saveRedis(Tenant tenant) {
|
||||
String key = "cache:tenant";
|
||||
String tenantId = tenant.getTenantId().toString();
|
||||
if (StrUtil.isEmpty(tenant.getTenantCode())) {
|
||||
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||
}
|
||||
String data = JSONUtil.toJSONString(tenant);
|
||||
stringRedisTemplate.opsForHash().put(key,tenantId, data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.oa.entity.App;
|
||||
import com.gxwebsoft.oa.param.AppParam;
|
||||
import com.gxwebsoft.oa.service.AppService;
|
||||
import com.gxwebsoft.oa.service.TenantService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
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 javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.RedisConstants.*;
|
||||
|
||||
/**
|
||||
* 应用控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-18 13:55:29
|
||||
*/
|
||||
@Api(tags = "应用市场")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/market")
|
||||
public class OpenMarketController extends BaseController {
|
||||
@Resource
|
||||
private AppService appService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@ApiOperation("分页查询应用")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<App>> page(AppParam param) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
// PageParam<App, AppParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
// return success(appService.page(page, page.getWrapper()));
|
||||
|
||||
// 使用关联查询
|
||||
param.setSearch(1);
|
||||
return success(appService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部应用")
|
||||
@GetMapping()
|
||||
public ApiResult<List<App>> list(AppParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// PageParam<App, AppParam> page = new PageParam<>(param);
|
||||
// page.setDefaultOrder("create_time desc");
|
||||
// return success(appService.list(page.getOrderWrapper()));
|
||||
|
||||
// 使用关联查询
|
||||
param.setSearch(1);
|
||||
return success(appService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询应用")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<App> get(@PathVariable("id") Integer id) {
|
||||
// return success(appService.getById(id));
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return success(appService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("排行榜")
|
||||
@GetMapping("/ranking")
|
||||
public ApiResult<?> ranking(UserParam param) {
|
||||
// 使用关联查询
|
||||
Set<String> reverseRange = cacheClient.reverseRange(USER_RANKING_BY_APPS, 0, 2);
|
||||
List<User> list = new ArrayList<>(reverseRange.size());
|
||||
if(reverseRange.size() == 0) {
|
||||
userService.listRanking(param);
|
||||
}
|
||||
reverseRange.forEach(v -> {
|
||||
Double score = cacheClient.score(USER_RANKING_BY_APPS, v);
|
||||
User user = userService.getById(v);
|
||||
user.setApps(score);
|
||||
list.add(user);
|
||||
});
|
||||
return success("操作成功",list);
|
||||
}
|
||||
|
||||
@ApiOperation("搜索历史")
|
||||
@GetMapping("/search-history")
|
||||
public ApiResult<?> searchHistory(String keyword, Long number) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
String key = cacheClient.key(SEARCH_HISTORY,getLoginUserId());
|
||||
if(StrUtil.isNotBlank(keyword)){
|
||||
cacheClient.leftPush(key,keyword);
|
||||
}
|
||||
// 超出100裁剪
|
||||
Long size = cacheClient.listSize(key);
|
||||
if (number == null) {
|
||||
number = 9L;
|
||||
}
|
||||
return success("操作成功",cacheClient.listRange(key,0L,number));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.shop.entity.Merchant;
|
||||
import com.gxwebsoft.shop.param.MerchantParam;
|
||||
import com.gxwebsoft.shop.service.MerchantService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.RedisConstants.MERCHANT_GEO_KEY;
|
||||
import static com.gxwebsoft.common.core.constants.RedisConstants.MERCHANT_KEY;
|
||||
|
||||
/**
|
||||
* 商户管理控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-11-30 15:10:54
|
||||
*/
|
||||
@Api(tags = "商户管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/merchant")
|
||||
public class OpenMerchantController extends BaseController {
|
||||
@Resource
|
||||
private MerchantService merchantService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@ApiOperation("分页查询商户管理")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Merchant>> page(MerchantParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 搜索条件
|
||||
if (getMerchantCode() != null) {
|
||||
param.setMerchantCode(getMerchantCode());
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(merchantService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部商户管理")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Merchant>> list(MerchantParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
PageParam<Merchant, MerchantParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// 使用关联查询
|
||||
return success(merchantService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询商户管理")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Merchant> get(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
return success(merchantService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("添加商户管理")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Merchant merchant) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (merchantService.count(new LambdaQueryWrapper<Merchant>()
|
||||
.eq(Merchant::getMerchantCode, merchant.getMerchantCode())) > 0) {
|
||||
return fail("商户编号已存在");
|
||||
}
|
||||
if (merchantService.save(merchant)) {
|
||||
// 添加缓存
|
||||
String lngAndLat = merchant.getLngAndLat();
|
||||
String[] split = lngAndLat.split(",");
|
||||
Double x = Double.parseDouble(split[0]);
|
||||
Double y = Double.parseDouble(split[1]);
|
||||
String id = merchant.getMerchantId().toString();
|
||||
cacheClient.geoAdd(MERCHANT_GEO_KEY,x,y,id);
|
||||
cacheClient.set(MERCHANT_KEY.concat(":").concat(merchant.getMerchantId().toString()),merchant);
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改商户管理")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Merchant merchant) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 超级管理员不能设为店主
|
||||
if(getLoginUser().getUserId().equals(merchant.getMerchantOwner())){
|
||||
return fail("超级管理员不能绑定为负责人!");
|
||||
}
|
||||
if (merchantService.updateById(merchant)) {
|
||||
// 添加缓存
|
||||
String lngAndLat = merchant.getLngAndLat();
|
||||
String[] split = lngAndLat.split(",");
|
||||
Double x = Double.parseDouble(split[0]);
|
||||
Double y = Double.parseDouble(split[1]);
|
||||
String id = merchant.getMerchantId().toString();
|
||||
cacheClient.geoAdd(MERCHANT_GEO_KEY,x,y,id);
|
||||
cacheClient.geoAdd(MERCHANT_GEO_KEY,x,y,id);
|
||||
cacheClient.set(MERCHANT_KEY.concat(":").concat(merchant.getMerchantId().toString()),merchant);
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除商户管理")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (merchantService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量添加商户管理")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Merchant> list) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (merchantService.saveBatch(list)) {
|
||||
list.forEach(d -> {
|
||||
// 添加缓存
|
||||
String lngAndLat = d.getLngAndLat();
|
||||
String[] split = lngAndLat.split(",");
|
||||
Double x = Double.parseDouble(split[0]);
|
||||
Double y = Double.parseDouble(split[1]);
|
||||
String id = d.getMerchantId().toString();
|
||||
cacheClient.geoAdd(MERCHANT_GEO_KEY,x,y,id);
|
||||
cacheClient.geoAdd(MERCHANT_GEO_KEY,x,y,id);
|
||||
cacheClient.set(MERCHANT_KEY.concat(":").concat(d.getMerchantId().toString()),d);
|
||||
});
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量修改商户管理")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Merchant> batchParam) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (batchParam.update(merchantService, "merchant_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除商户管理")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (merchantService.removeByIds(ids)) {
|
||||
// 删除缓存
|
||||
ids.forEach(id -> {
|
||||
cacheClient.geoRemove(MERCHANT_GEO_KEY,id);
|
||||
});
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("根据定位查询附近的商户列表")
|
||||
@PostMapping("/getListByGeo")
|
||||
public ApiResult<List<Merchant>> getListByGeo(@RequestBody MerchantParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return success(merchantService.listByGeo(param));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.oa.entity.Notice;
|
||||
import com.gxwebsoft.oa.param.NoticeParam;
|
||||
import com.gxwebsoft.oa.service.NoticeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-03-22 14:07:26
|
||||
*/
|
||||
@Api(tags = "消息记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/notice")
|
||||
public class OpenNoticeController extends BaseController {
|
||||
@Resource
|
||||
private NoticeService noticeService;
|
||||
|
||||
@ApiOperation("分页查询消息记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Notice>> page(NoticeParam param) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
// 使用关联查询
|
||||
param.setUserId(getLoginUserId());
|
||||
return success(noticeService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部消息记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Notice>> list(NoticeParam param) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
// 使用关联查询
|
||||
param.setUserId(getLoginUserId());
|
||||
return success(noticeService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询消息记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Notice> get(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
return success(noticeService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(noticeService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("添加消息记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Notice notice) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
// 记录当前登录用户id、租户id、商户编号
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
notice.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (noticeService.save(notice)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改消息记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Notice notice) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
if (noticeService.updateById(notice)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除消息记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (noticeService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量添加消息记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Notice> list) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
if (noticeService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量修改消息记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Notice> batchParam) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
if (batchParam.update(noticeService, "notice_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除消息记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
// 验证签名
|
||||
// isCheckSign();
|
||||
if (noticeService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.apps.utils.BcUtil;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.OrderGoods;
|
||||
import com.gxwebsoft.shop.entity.UserBalanceLog;
|
||||
import com.gxwebsoft.shop.mapper.OrderMapper;
|
||||
import com.gxwebsoft.shop.param.CartParam;
|
||||
import com.gxwebsoft.shop.param.OrderGoodsParam;
|
||||
import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.service.OrderGoodsService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import com.gxwebsoft.shop.service.UserBalanceLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.BalanceConstants.BALANCE_REFUND;
|
||||
import static com.gxwebsoft.common.core.constants.OrderConstants.*;
|
||||
|
||||
/**
|
||||
* 订单记录表控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-16 11:25:58
|
||||
*/
|
||||
@Api(tags = "订单记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/order")
|
||||
public class OpenOrderController extends BaseController {
|
||||
@Resource
|
||||
private BcUtil bcUtil;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private OrderGoodsService orderGoodsService;
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserBalanceLogService userBalanceLogService;
|
||||
|
||||
@ApiOperation("查询全部订单记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Order>> list(OrderParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
return success(orderService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:list')")
|
||||
@ApiOperation("根据id查询订单记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Order> get(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
return success(orderService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(orderService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:list')")
|
||||
@ApiOperation("查询报餐明细")
|
||||
@GetMapping("/getMyOrder")
|
||||
public ApiResult<Order> getMyOrder(CartParam cartParam) {
|
||||
Integer userId = 0;
|
||||
if(cartParam.getAgentUserId() != null){
|
||||
userId = cartParam.getAgentUserId();
|
||||
}else{
|
||||
userId = getLoginUserId();
|
||||
}
|
||||
System.out.println("cartParam = " + cartParam);
|
||||
System.out.println("userId = " + userId);
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 报餐明细(查询昨天这个时间点后下的订单)
|
||||
LambdaQueryWrapper<Order> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper
|
||||
.eq(Order::getUserId,userId)
|
||||
.eq(Order::getPayStatus,PAY_STATUS_SUCCESS)
|
||||
.eq(Order::getOrderStatus,ORDER_STATUS_DOING)
|
||||
.eq(Order::getDeleted,0)
|
||||
.eq(Order::getIsTemporary,0)
|
||||
.eq(Order::getDeliveryTime,cartParam.getDeliveryTime());
|
||||
Order order = orderService.getOne(lambdaQueryWrapper,false);
|
||||
// 查询订单商品
|
||||
if(order != null){
|
||||
OrderGoodsParam param = new OrderGoodsParam();
|
||||
param.setOrderId(order.getOrderId());
|
||||
// 是否按餐段查询
|
||||
if(cartParam.getIsPeriod() != null){
|
||||
param.setCategoryId(bcUtil.categoryId);
|
||||
}
|
||||
PageParam<OrderGoods, OrderGoodsParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("gear asc, sort_number asc, create_time desc");
|
||||
order.setGoodsList(orderGoodsService.list(page.getOrderWrapper()));
|
||||
}
|
||||
return success(order);
|
||||
}
|
||||
|
||||
@ApiOperation("查询今日当前餐段菜品")
|
||||
@PostMapping("/currentOrderGoods")
|
||||
public ApiResult<List<OrderGoods>> currentOrderGoods(OrderGoodsParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
param.setCategoryId(bcUtil.categoryId);
|
||||
return success(orderGoodsService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:list')")
|
||||
@ApiOperation("查询核销订单明细")
|
||||
@GetMapping("/getReceiptOrder")
|
||||
public ApiResult<?> getReceiptOrder(CartParam cartParam) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
Integer userId = 0;
|
||||
|
||||
// 核销自己(查询今天他下的订单)
|
||||
if(cartParam.getUserId() != null){
|
||||
userId = cartParam.getUserId();
|
||||
OrderParam orderParam = new OrderParam();
|
||||
orderParam.setUserId(userId);
|
||||
orderParam.setPayStatus(PAY_STATUS_SUCCESS);
|
||||
orderParam.setOrderStatus(ORDER_STATUS_DOING);
|
||||
orderParam.setDeliveryTime(cartParam.getDeliveryTime());
|
||||
List<Order> list = orderService.listRel(orderParam);
|
||||
// 查询订单商品
|
||||
list.forEach(d -> {
|
||||
OrderGoodsParam param = new OrderGoodsParam();
|
||||
param.setOrderId(d.getOrderId());
|
||||
d.setGoodsList(orderGoodsService.listRel(param));
|
||||
});
|
||||
return success(list);
|
||||
}
|
||||
|
||||
// 代核销模式
|
||||
if(cartParam.getDealerId() != null){
|
||||
userId = cartParam.getDealerId();
|
||||
return success(userId);
|
||||
}
|
||||
return fail("找不到报餐数据",null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:save')")
|
||||
@ApiOperation("添加订单记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Order order) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 记录当前登录用户id、租户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
order.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (orderService.save(order)) {
|
||||
return success("添加成功",order);
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:update')")
|
||||
@ApiOperation("修改订单记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Order order) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (orderService.updateById(order)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("取消订单")
|
||||
@PostMapping("/cancel")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> cancel(@RequestBody Order order) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (order.getOrderId() == null) {
|
||||
return fail("订单不存在!");
|
||||
}
|
||||
// 取消报餐截止时间
|
||||
Date date = DateUtil.date();
|
||||
int hours = date.getHours();
|
||||
System.out.println("hours = " + hours);
|
||||
if(hours > 19){
|
||||
return fail("每天晚上8点后截止取消报餐");
|
||||
}
|
||||
order.setOrderStatus(ORDER_STATUS_CANCEL);
|
||||
if (orderService.updateById(order)) {
|
||||
final Order orderInfo = orderService.getById(order.getOrderId());
|
||||
// 退款
|
||||
User user = userService.getById(orderInfo.getUserId());
|
||||
System.out.println("user = " + user);
|
||||
BigDecimal balance = user.getBalance().add(orderInfo.getPayPrice());
|
||||
user.setBalance(balance);
|
||||
userService.updateById(user);
|
||||
// 记录余额明细
|
||||
UserBalanceLog userBalanceLog = new UserBalanceLog();
|
||||
userBalanceLog.setUserId(orderInfo.getUserId());
|
||||
userBalanceLog.setScene(BALANCE_REFUND);
|
||||
userBalanceLog.setMoney(orderInfo.getPayPrice());
|
||||
userBalanceLog.setBalance(balance);
|
||||
userBalanceLog.setComments(orderInfo.getOrderNo().toString());
|
||||
userBalanceLog.setMerchantCode(orderInfo.getMerchantCode());
|
||||
userBalanceLogService.save(userBalanceLog);
|
||||
return success("订单取消成功",orderInfo);
|
||||
}
|
||||
return fail("订单取消失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除订单记录表")
|
||||
@GetMapping("/remove/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (orderService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:save')")
|
||||
@ApiOperation("批量添加订单记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Order> list) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (orderService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:update')")
|
||||
@ApiOperation("批量修改订单记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Order> batchParam) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (batchParam.update(orderService, "order_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:order:remove')")
|
||||
@ApiOperation("批量删除订单记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (orderService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("支付成功")
|
||||
@PostMapping("/setPayStatus")
|
||||
public ApiResult<?> setPayStatus(@RequestBody Order order){
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (orderService.updateById(order)) {
|
||||
return success("设置成功");
|
||||
}
|
||||
return fail("设置失败");
|
||||
}
|
||||
|
||||
@ApiOperation("核销二维码")
|
||||
@PutMapping("/verification")
|
||||
public ApiResult<?> verification(@RequestBody Order order) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
order.setOrderStatus(ORDER_STATUS_COMPLETED);
|
||||
order.setReceiptTime(DateUtil.date());
|
||||
if (orderService.updateById(order)) {
|
||||
return success("核销成功");
|
||||
}
|
||||
return fail("核销失败");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.OrderGoods;
|
||||
import com.gxwebsoft.shop.entity.UserBalanceLog;
|
||||
import com.gxwebsoft.shop.param.OrderGoodsParam;
|
||||
import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.service.OrderGoodsService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import com.gxwebsoft.shop.service.UserBalanceLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.BalanceConstants.BALANCE_REFUND;
|
||||
import static com.gxwebsoft.common.core.constants.OrderConstants.ORDER_STATUS_CANCEL;
|
||||
|
||||
/**
|
||||
* 订单商品记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-12-09 17:15:31
|
||||
*/
|
||||
@Api(tags = "订单商品记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/order-goods")
|
||||
public class OpenOrderGoodsController extends BaseController {
|
||||
@Resource
|
||||
private OrderGoodsService orderGoodsService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserBalanceLogService userBalanceLogService;
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询订单商品记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<OrderGoods>> page(OrderGoodsParam param) {
|
||||
PageParam<OrderGoods, OrderGoodsParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("gear asc, sort_number asc, create_time desc");
|
||||
return success(orderGoodsService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(orderGoodsService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部订单商品记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<OrderGoods>> list(OrderGoodsParam param) {
|
||||
PageParam<OrderGoods, OrderGoodsParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("gear asc, sort_number asc, create_time desc");
|
||||
return success(orderGoodsService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(orderGoodsService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询订单商品记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<OrderGoods> get(@PathVariable("id") Integer id) {
|
||||
return success(orderGoodsService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(orderGoodsService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加订单商品记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody OrderGoods orderGoods) {
|
||||
// 记录当前登录用户id、租户id、商户编号
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
orderGoods.setUserId(loginUser.getUserId());
|
||||
orderGoods.setMerchantCode(getMerchantCode());
|
||||
}
|
||||
if (orderGoodsService.save(orderGoods)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改订单商品记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody OrderGoods orderGoods) {
|
||||
if (orderGoodsService.updateById(orderGoods)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除订单商品记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (orderGoodsService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加订单商品记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<OrderGoods> list) {
|
||||
if (orderGoodsService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改订单商品记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<OrderGoods> batchParam) {
|
||||
if (batchParam.update(orderGoodsService, "order_goods_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:orderGoods:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除订单商品记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (orderGoodsService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("取消订单商品")
|
||||
@PostMapping("/cancel")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public ApiResult<?> cancel(@RequestBody OrderGoods orderGoods) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (orderGoods.getOrderGoodsId() == null) {
|
||||
return fail("菜品不存在!");
|
||||
}
|
||||
System.out.println("orderGoods = " + orderGoods);
|
||||
final Order byId = orderService.getById(orderGoods.getOrderId());
|
||||
System.out.println("byId = " + byId);
|
||||
// 取消报餐截止时间
|
||||
orderGoodsService.removeById(orderGoods);
|
||||
System.out.println("orderGoods = " + orderGoods);
|
||||
// 退款
|
||||
User user = userService.getById(byId.getUserId());
|
||||
System.out.println("user = " + user);
|
||||
System.out.println("orderGoods.getGoodsPrice() = " + orderGoods.getGoodsPrice());
|
||||
BigDecimal balance = user.getBalance().add(orderGoods.getGoodsPrice());
|
||||
user.setBalance(balance);
|
||||
userService.updateById(user);
|
||||
// 记录余额明细
|
||||
UserBalanceLog userBalanceLog = new UserBalanceLog();
|
||||
userBalanceLog.setUserId(byId.getUserId());
|
||||
userBalanceLog.setScene(BALANCE_REFUND);
|
||||
userBalanceLog.setMoney(orderGoods.getGoodsPrice());
|
||||
userBalanceLog.setBalance(balance);
|
||||
userBalanceLog.setComments(orderGoods.getOrderId().toString());
|
||||
userBalanceLogService.save(userBalanceLog);
|
||||
final int count = orderGoodsService.count(new LambdaUpdateWrapper<OrderGoods>().eq(OrderGoods::getOrderId, orderGoods.getOrderId()).gt(OrderGoods::getTotalNum,0));
|
||||
System.out.println("count = " + count);
|
||||
// 无菜品就把订单状态改为已取消
|
||||
if(count == 0){
|
||||
final Order order = new Order();
|
||||
order.setOrderId(orderGoods.getOrderId());
|
||||
order.setOrderStatus(ORDER_STATUS_CANCEL);
|
||||
orderService.removeById(orderGoods.getOrderId());
|
||||
}
|
||||
return success("菜品取消成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Setting;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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 javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 系统设置控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-19 13:54:27
|
||||
*/
|
||||
@Api(tags = "系统设置管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/system/setting")
|
||||
public class OpenSettingController extends BaseController {
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private CacheClient cacheClient;
|
||||
|
||||
@ApiOperation("根据key查询系统设置")
|
||||
@GetMapping("/{settingKey}")
|
||||
public ApiResult<Setting> get(@PathVariable("settingKey") String settingKey) {
|
||||
final Setting data = settingService.getData(settingKey);
|
||||
return success(settingService.getData(settingKey));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.oa.entity.Task;
|
||||
import com.gxwebsoft.oa.entity.TaskRecord;
|
||||
import com.gxwebsoft.oa.entity.TaskUser;
|
||||
import com.gxwebsoft.oa.param.TaskParam;
|
||||
import com.gxwebsoft.oa.service.AppService;
|
||||
import com.gxwebsoft.oa.service.TaskRecordService;
|
||||
import com.gxwebsoft.oa.service.TaskService;
|
||||
import com.gxwebsoft.oa.service.TaskUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 工单记录表控制器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-16 11:21:43
|
||||
*/
|
||||
@Api(tags = "工单记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/oa/task")
|
||||
public class OpenTaskController extends BaseController {
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
@Resource
|
||||
private TaskRecordService taskRecordService;
|
||||
@Resource
|
||||
private TaskUserService taskUserService;
|
||||
@Resource
|
||||
private AppService appService;
|
||||
|
||||
@ApiOperation("分页查询工单记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Task>> page(TaskParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
final User loginUser = getLoginUser();
|
||||
final Integer type = loginUser.getType();
|
||||
// 如果是开发者账号则按受理人查询
|
||||
if (type.equals(6)) {
|
||||
param.setCommander(loginUser.getUserId());
|
||||
}else{
|
||||
param.setPromoter(getLoginUserId());
|
||||
}
|
||||
|
||||
return success(taskService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部工单记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Task>> list(TaskParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
PageParam<Task, TaskParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(taskService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(taskService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('oa:task:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询工单记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Task> get(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
Task task = taskService.getByIdRel(id);
|
||||
task.setAppInfo(appService.getById(task.getAppId()));
|
||||
return success(task);
|
||||
}
|
||||
|
||||
@ApiOperation("添加工单记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Task task) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 当前登录用户id
|
||||
Integer loginUserId = getLoginUserId();
|
||||
task.setUserId(loginUserId);
|
||||
task.setPromoter(loginUserId);
|
||||
task.setComments(StrUtil.sub(task.getContent(),0,200));
|
||||
task.setLastReadUser(loginUserId);
|
||||
// 创建工单
|
||||
if (taskService.save(task)) {
|
||||
// 添加聊天内容明细
|
||||
TaskRecord taskRecord = new TaskRecord();
|
||||
taskRecord.setUserId(loginUserId);
|
||||
taskRecord.setContent(task.getContent());
|
||||
taskRecord.setTaskId(task.getTaskId());
|
||||
taskRecord.setFiles(task.getFiles());
|
||||
taskRecordService.save(taskRecord);
|
||||
// 添加工单成员
|
||||
TaskUser taskUser = new TaskUser();
|
||||
taskUser.setUserId(loginUserId);
|
||||
taskUser.setTaskId(task.getTaskId());
|
||||
taskUserService.save(taskUser);
|
||||
return success("创建成功");
|
||||
}
|
||||
return fail("创建失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改工单记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Task task) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (taskService.updateById(task)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除工单记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (taskService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量添加工单记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Task> list) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (taskService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量修改工单记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Task> batchParam) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (batchParam.update(taskService, "task_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除工单记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (taskService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("统计信息")
|
||||
@GetMapping("/count")
|
||||
public ApiResult<?> count(){
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
User loginUser = getLoginUser();
|
||||
ArrayList<Object> countNum = taskService.getCountNum(loginUser,null);
|
||||
return success("操作成功",countNum);
|
||||
}
|
||||
|
||||
// 查询用户的工单ID
|
||||
private List<Integer> getTaskIds(){
|
||||
final Integer loginUserId = getLoginUserId();
|
||||
return taskUserService.list(new LambdaQueryWrapper<TaskUser>().eq(TaskUser::getUserId, loginUserId))
|
||||
.stream().map(TaskUser::getTaskId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.oa.entity.Task;
|
||||
import com.gxwebsoft.oa.entity.TaskRecord;
|
||||
import com.gxwebsoft.oa.param.TaskRecordParam;
|
||||
import com.gxwebsoft.oa.service.TaskRecordService;
|
||||
import com.gxwebsoft.oa.service.TaskService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gxwebsoft.oa.constants.TaskConstants.PROGRESS2;
|
||||
import static com.gxwebsoft.oa.constants.TaskConstants.PROGRESS3;
|
||||
|
||||
/**
|
||||
* 工单回复记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-03-05 00:52:21
|
||||
*/
|
||||
@Api(tags = "工单回复记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/oa/task-record")
|
||||
public class OpenTaskRecordController extends BaseController {
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
@Resource
|
||||
private TaskRecordService taskRecordService;
|
||||
|
||||
@ApiOperation("分页查询工单回复记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<TaskRecord>> page(TaskRecordParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
return success(taskRecordService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部工单回复记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<TaskRecord>> list(TaskRecordParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 更新查阅状态
|
||||
Task task = taskService.getById(param.getTaskId());
|
||||
if(!getLoginUserId().equals(task.getLastReadUser())){
|
||||
task.setIsRead(1);
|
||||
}
|
||||
taskService.updateById(task);
|
||||
// 使用关联查询
|
||||
return success(taskRecordService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询工单回复记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<TaskRecord> get(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
// 使用关联查询
|
||||
return success(taskRecordService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("添加工单回复记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody TaskRecord taskRecord) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
taskRecord.setUserId(getLoginUserId());
|
||||
int count = taskRecordService.count(new LambdaQueryWrapper<TaskRecord>().eq(TaskRecord::getTaskId,taskRecord.getTaskId()));
|
||||
if(count > 100){
|
||||
return fail("回复数超过最大限制");
|
||||
}
|
||||
if (taskRecordService.save(taskRecord)) {
|
||||
// 变更工单状态
|
||||
Task task = taskService.getById(taskRecord.getTaskId());
|
||||
task.setProgress(PROGRESS2);
|
||||
task.setIsRead(0);
|
||||
task.setLastReadUser(getLoginUserId());
|
||||
taskService.updateById(task);
|
||||
return success("提交成功");
|
||||
}
|
||||
return fail("提交失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改工单回复记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody TaskRecord taskRecord) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (taskRecordService.updateById(taskRecord)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除工单回复记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (taskRecordService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量添加工单回复记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<TaskRecord> list) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (taskRecordService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量修改工单回复记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<TaskRecord> batchParam) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (batchParam.update(taskRecordService, "task_record_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除工单回复记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
if (taskRecordService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.utils.MyQrCodeUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 我的资料
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-04-24 21:47:57
|
||||
*/
|
||||
@Api(tags = "我的资料")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/user")
|
||||
public class OpenUserController extends BaseController {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@ApiOperation("实时二维码")
|
||||
@PostMapping("/myQrCode")
|
||||
public ApiResult<?> myQrCode(@RequestBody UserParam userParam) throws IOException {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
final String qrCode = MyQrCodeUtil.createQrCode(getLoginUserId(), userParam.getCodeContent());
|
||||
return success("操作成功",qrCode);
|
||||
}
|
||||
|
||||
@ApiOperation("获取代理用户信息")
|
||||
@GetMapping("/agentUser/{id}")
|
||||
public ApiResult<User> agentUser(@PathVariable("id") Integer id){
|
||||
User user = userService.getById(id);
|
||||
return success("操作成功",user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户-我的订单
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2022-11-25 19:04:43
|
||||
*/
|
||||
@Api(tags = "我的订单")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/user-order")
|
||||
public class OpenUserOrderController extends BaseController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@ApiOperation("分页查询用户订单")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Order>> page(OrderParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
PageParam<Order, OrderParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// 记录当前登录用户id、租户id
|
||||
User user = getLoginUser();
|
||||
if (user != null) {
|
||||
param.setUserId(user.getUserId());
|
||||
param.setTenantId(user.getTenantId());
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(orderService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部用户订单")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Order>> list(OrderParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
PageParam<Order, OrderParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// 记录当前登录用户id、租户id
|
||||
User user = getLoginUser();
|
||||
if (user != null) {
|
||||
param.setUserId(user.getUserId());
|
||||
param.setTenantId(user.getTenantId());
|
||||
}
|
||||
|
||||
// 使用关联查询
|
||||
return success(orderService.listRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("测试")
|
||||
@GetMapping("/test")
|
||||
public ApiResult<PageResult<Order>> test(OrderParam param) {
|
||||
// 验证签名
|
||||
isCheckSign();
|
||||
PageParam<Order, OrderParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// 记录当前登录用户id、租户id
|
||||
User user = getLoginUser();
|
||||
if (user != null) {
|
||||
param.setUserId(user.getUserId());
|
||||
param.setTenantId(user.getTenantId());
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(orderService.pageRel(param));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.security.JwtSubject;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.WxOfficialUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.LoginRecord;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.service.LoginRecordService;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.oa.service.NoticeService;
|
||||
import com.gxwebsoft.shop.entity.UserOauth;
|
||||
import com.gxwebsoft.shop.param.UserOauthParam;
|
||||
import com.gxwebsoft.shop.service.UserOauthService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.gxwebsoft.common.core.utils.CommonUtil.randomUsername;
|
||||
|
||||
/**
|
||||
* 微信公众号接口
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-19 13:54:27
|
||||
*/
|
||||
@Api(tags = "微信公众号授权登录")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/wx-official")
|
||||
public class OpenWxOfficialController extends BaseController {
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private WxOfficialUtil wxOfficialUtil;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
|
||||
public OpenWxOfficialController() {
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("第一步:用户同意授权,获取code")
|
||||
@GetMapping("/code")
|
||||
public ApiResult<?> code() throws UnsupportedEncodingException {
|
||||
WxOfficialUtil client = wxOfficialUtil.client(getTenantId());
|
||||
String codeUrl = client.getCodeUrl();
|
||||
return success(codeUrl);
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@ApiOperation("第二步:通过code换取网页授权access_token")
|
||||
@GetMapping("/accessToken")
|
||||
public String accessToken(String code, String state, HttpServletRequest request, HttpServletResponse resp) throws IOException {
|
||||
if(StrUtil.equals(state,"STATE")){
|
||||
throw new BusinessException("租户ID不正确");
|
||||
}
|
||||
|
||||
// 1.实例化
|
||||
WxOfficialUtil client = wxOfficialUtil.client(Integer.valueOf(state));
|
||||
|
||||
// 2.获取access_token
|
||||
final String access_token = client.getAccessToken(code);
|
||||
|
||||
// 准备数据
|
||||
final String unionid = client.unionid;
|
||||
final String expires_in = client.expires_in;
|
||||
final JSONObject cache = settingService.getCache("cache".concat(state).concat(":setting:setting"));
|
||||
final String domain = "https://" + cache.getString("domain");
|
||||
|
||||
// 3.查询第三方用户信息表
|
||||
UserOauthParam userOauthParam = new UserOauthParam();
|
||||
userOauthParam.setUnionid(unionid);
|
||||
userOauthParam.setTenantId(Integer.valueOf(state));
|
||||
System.out.println("userOauthParam = " + userOauthParam);
|
||||
final UserOauth oauthUser = userOauthService.getByUnionId(userOauthParam);
|
||||
System.out.println("oauthUser = " + oauthUser);
|
||||
|
||||
// 4.1存在签发token
|
||||
if(oauthUser != null){
|
||||
UserParam userParam = new UserParam();
|
||||
userParam.setUserId(oauthUser.getUserId());
|
||||
userParam.setTenantId(Integer.valueOf(state));
|
||||
System.out.println("userParam = " + userParam);
|
||||
User user = userService.getByUnionId(userParam);
|
||||
// 5.签发token
|
||||
System.out.println("user = 签发token " + user);
|
||||
String wx_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), Integer.valueOf(state)),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
resp.sendRedirect(domain + "/passport/wx-official-login?token=".concat(wx_token).concat("&username=").concat(user.getUsername()));
|
||||
return "登录成功";
|
||||
}
|
||||
// 4.2不存在则注册并登录签发token
|
||||
final JSONObject userInfo = client.getUserInfo(access_token);
|
||||
final String openid = userInfo.getString("openid");
|
||||
final String unionId = userInfo.getString("unionid");
|
||||
final String nickname = userInfo.getString("nickname");
|
||||
final String sex = userInfo.getString("sex");
|
||||
final String province = userInfo.getString("province");
|
||||
final String city = userInfo.getString("city");
|
||||
final String country = userInfo.getString("country");
|
||||
final String headimgurl = userInfo.getString("headimgurl");
|
||||
System.out.println("headimgurl = " + headimgurl);
|
||||
System.out.println("unionId = " + unionId);
|
||||
System.out.println("openid = " + openid);
|
||||
System.out.println("nickname = " + nickname);
|
||||
User user = new User();
|
||||
user.setNickname(nickname);
|
||||
user.setType(0);
|
||||
user.setUsername(randomUsername("wx_"));
|
||||
user.setPassword(userService.encodePassword(CommonUtil.randomUUID16()));
|
||||
user.setSex(sex);
|
||||
user.setPlatform("WX-OFFICIAL");
|
||||
user.setProvince(province);
|
||||
user.setCity(city);
|
||||
user.setCountry(country);
|
||||
user.setAvatar(headimgurl);
|
||||
user.setTenantId(Integer.valueOf(state));
|
||||
userService.saveUser(user);
|
||||
System.out.println("userLast = " + user);
|
||||
UserOauth userOauth = new UserOauth();
|
||||
userOauth.setTenantId(Integer.valueOf(state));
|
||||
userOauth.setOauthType("WX-OFFICIAL");
|
||||
userOauth.setOauthId(openid);
|
||||
userOauth.setUnionid(unionId);
|
||||
userOauth.setUserId(user.getUserId());
|
||||
userOauthService.save(userOauth);
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, Integer.valueOf(state), request);
|
||||
// 5.签发token
|
||||
String wx_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), Integer.valueOf(state)),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
resp.sendRedirect(domain + "/passport/wx-official-login?token=".concat(wx_token).concat("&username=").concat(user.getUsername()));
|
||||
return "注册成功";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.security.JwtSubject;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.WxWorkUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.LoginRecord;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.entity.UserRole;
|
||||
import com.gxwebsoft.common.system.param.UserParam;
|
||||
import com.gxwebsoft.common.system.result.LoginResult;
|
||||
import com.gxwebsoft.common.system.service.LoginRecordService;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.entity.UserOauth;
|
||||
import com.gxwebsoft.shop.param.UserOauthParam;
|
||||
import com.gxwebsoft.shop.service.UserOauthService;
|
||||
import com.qq.weixin.mp.aes.AesException;
|
||||
import com.qq.weixin.mp.aes.WXBizJsonMsgCrypt;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 企业微信接口
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2022-11-19 13:54:27
|
||||
*/
|
||||
@Api(tags = "企业微信验证")
|
||||
@RestController
|
||||
@RequestMapping("/api/open/wx-work")
|
||||
public class OpenWxWorkController extends BaseController {
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private WxWorkUtil workUtil;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserOauthService userOauthService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("第一步:请求验证URL有效性")
|
||||
@GetMapping()
|
||||
public String msgSignature(HttpServletRequest request) throws AesException {
|
||||
String sToken = "gFJXh4y2QAg5gm6U";
|
||||
String sCorpID = "wxa040285bc1c223ae";
|
||||
String sEncodingAESKey = "MRYqPeaVleIZDzgS2O8CoyyRwAYBOD9wQAztSfLMWaA";
|
||||
|
||||
WXBizJsonMsgCrypt wxcpt = new WXBizJsonMsgCrypt(sToken, sEncodingAESKey, sCorpID);
|
||||
|
||||
// 解析出url上的参数值如下:
|
||||
final String sVerifyMsgSig = request.getParameter("msg_signature");
|
||||
final String sVerifyTimeStamp = request.getParameter("timestamp");
|
||||
final String sVerifyNonce = request.getParameter("nonce");
|
||||
final String sVerifyEchoStr = request.getParameter("echostr");
|
||||
String sEchoStr; //需要返回的明文
|
||||
System.out.println("sVerifyMsgSig = " + sVerifyMsgSig);
|
||||
System.out.println("sVerifyTimeStamp = " + sVerifyTimeStamp);
|
||||
System.out.println("sVerifyNonce = " + sVerifyNonce);
|
||||
System.out.println("sVerifyEchoStr = " + sVerifyEchoStr);
|
||||
|
||||
try {
|
||||
sEchoStr = wxcpt.VerifyURL(sVerifyMsgSig, sVerifyTimeStamp,
|
||||
sVerifyNonce, sVerifyEchoStr);
|
||||
System.out.println("verifyurl echostr: " + sEchoStr);
|
||||
// 验证URL成功,将sEchoStr返回
|
||||
return sEchoStr;
|
||||
} catch (Exception e) {
|
||||
//验证URL失败,错误原因请查看异常
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "验证失败";
|
||||
}
|
||||
|
||||
@ApiOperation("获取access_token并登录")
|
||||
@GetMapping("/saveAccessToken")
|
||||
public ApiResult<?> saveAccessToken(HttpServletRequest request, HttpServletResponse resp) throws IOException {
|
||||
System.out.println("request = " + request);
|
||||
final String code = request.getParameter("code");
|
||||
final String state = request.getParameter("state");
|
||||
final Integer tenantId = Integer.valueOf(state);
|
||||
System.out.println("code = " + code);
|
||||
System.out.println("state = " + state);
|
||||
// 1.实例化
|
||||
WxWorkUtil client = workUtil.client(tenantId);
|
||||
// 2.获取access_token
|
||||
String key = "cache"+ tenantId +":ww:access_token";
|
||||
String access_token = stringRedisTemplate.opsForValue().get(key);
|
||||
System.out.println("access_token_cache = " + access_token);
|
||||
if (access_token == null){
|
||||
client.getAccessToken(code);
|
||||
}
|
||||
// 3.获取用户信息
|
||||
client.getUserInfo(code,access_token);
|
||||
|
||||
// 3.2 读取用户详细信息
|
||||
client.getUserProfile(client.userid,access_token);
|
||||
|
||||
// 4.查询第三方用户信息表
|
||||
UserOauthParam userOauthParam = new UserOauthParam();
|
||||
userOauthParam.setOauthId(client.userid);
|
||||
userOauthParam.setUnionid(client.userid);
|
||||
userOauthParam.setTenantId(tenantId);
|
||||
System.out.println("userOauthParam = " + userOauthParam);
|
||||
final UserOauth oauthUser = userOauthService.getByUnionId(userOauthParam);
|
||||
System.out.println("oauthUser = " + oauthUser);
|
||||
|
||||
// 4.1存在签发token
|
||||
if(oauthUser != null){
|
||||
UserParam userParam = new UserParam();
|
||||
userParam.setUserId(oauthUser.getUserId());
|
||||
userParam.setTenantId(tenantId);
|
||||
System.out.println("userParam = " + userParam);
|
||||
User user = userService.getByUnionId(userParam);
|
||||
// 5.签发token
|
||||
System.out.println("user = 签发token " + user);
|
||||
String ww_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), tenantId),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
resp.sendRedirect("http://apps.gxwebsoft.com/baocan/#/?ww_token=" + ww_token + "&userId=" + user.getUserId());
|
||||
return success("登录成功",new LoginResult(ww_token, user));
|
||||
}
|
||||
// 4.2不存在则注册并登录签发token
|
||||
User user = new User();
|
||||
user.setNickname(client.name);
|
||||
user.setUsername(client.userid);
|
||||
user.setPhone(client.mobile);
|
||||
user.setSex(client.gender);
|
||||
user.setPosition(client.position);
|
||||
user.setEmail(client.email);
|
||||
user.setAlias(client.alias);
|
||||
user.setPassword(userService.encodePassword(CommonUtil.randomUUID16()));
|
||||
user.setPlatform("WX-WORK");
|
||||
user.setTenantId(tenantId);
|
||||
userService.saveUser(user);
|
||||
System.out.println("userLast = " + user);
|
||||
// 添加默认角色
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setRoleId(241);
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setTenantId(tenantId);
|
||||
userRoleService.save(userRole);
|
||||
// 添加第三方用户信息
|
||||
UserOauth userOauth = new UserOauth();
|
||||
userOauth.setTenantId(tenantId);
|
||||
userOauth.setOauthType("WX-WORK");
|
||||
userOauth.setOauthId(client.userid);
|
||||
userOauth.setUnionid(client.userid);
|
||||
userOauth.setUserId(user.getUserId());
|
||||
userOauthService.save(userOauth);
|
||||
loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, tenantId, request);
|
||||
// 5.签发token
|
||||
String ww_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), tenantId),
|
||||
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
|
||||
resp.sendRedirect("http://apps.gxwebsoft.com/baocan/#/?ww_token=" + ww_token + "&userId=" + user.getUserId());
|
||||
return success("注册成功",new LoginResult(ww_token, user));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.gxwebsoft.open.controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Api(tags = "域名所有权验证")
|
||||
@RestController
|
||||
@RequestMapping("/WW_verify_10DxpA6fAgnSRayT.txt")
|
||||
public class VerifyTxt {
|
||||
|
||||
@ApiOperation("域名所有权验证")
|
||||
@GetMapping()
|
||||
public String verify(){
|
||||
return "10DxpA6fAgnSRayT";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user