新增订单模块

This commit is contained in:
starrySky
2024-03-22 15:55:17 +08:00
parent 989f0210f2
commit 994f32a342
130 changed files with 2520 additions and 831 deletions

View File

@@ -62,12 +62,37 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--weixin-java-common-->
<dependency>
<groupId>com.starry</groupId>
<artifactId>play-weichat</artifactId>
<version>1.0</version>
<scope>compile</scope>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-common</artifactId>
</dependency>
<!--weixin-java-admin-->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
</dependency>
<!--weixin-java-miniapp-->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
</dependency>
<!--weixin-java-pay-->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-pay</artifactId>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@@ -6,7 +6,7 @@ import com.starry.admin.modules.system.entity.SysRoleEntity;
import com.starry.admin.modules.system.entity.SysUserEntity;
import com.starry.admin.utils.SecurityUtils;
import com.starry.common.annotation.DataScope;
import com.starry.common.context.SecurityContextHolder;
import com.starry.common.context.CustomSecurityContextHolder;
import com.starry.common.domain.BaseEntity;
import com.starry.common.utils.StringUtils;
import org.aspectj.lang.JoinPoint;
@@ -125,7 +125,7 @@ public class DataScopeAspect {
SysUserEntity currentUser = loginUser.getUser();
// 如果是超级管理员,则不过滤数据
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) {
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), SecurityContextHolder.getPermission());
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), CustomSecurityContextHolder.getPermission());
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
controllerDataScope.userAlias(), permission);
}

View File

@@ -9,6 +9,7 @@ import com.starry.admin.common.security.entity.JwtUser;
import com.starry.common.constant.CacheConstants;
import com.starry.common.constant.Constants;
import com.starry.common.constant.SecurityConstants;
import com.starry.common.context.CustomSecurityContextHolder;
import com.starry.common.redis.RedisCache;
import com.starry.common.utils.ServletUtils;
import com.starry.common.utils.StringUtils;
@@ -312,8 +313,8 @@ public class JwtToken {
String uuid = (String) claims.get(SecurityConstants.USER_KEY);
String userKey = getTokenKey(uuid);
LoginUser loginUser = redisCache.getCacheObject(userKey);
com.starry.common.context.SecurityContextHolder.set(SecurityConstants.DETAILS_TENANT_ID, loginUser.getUser().getTenantId());
com.starry.common.context.SecurityContextHolder.set(SecurityConstants.LOGIN_USER, loginUser);
CustomSecurityContextHolder.set(SecurityConstants.DETAILS_TENANT_ID, loginUser.getUser().getTenantId());
CustomSecurityContextHolder.set(SecurityConstants.LOGIN_USER, loginUser);
return loginUser;
} catch (Exception e) {

View File

@@ -27,7 +27,7 @@ public class PermissionService {
*/
private static final String SUPER_ADMIN = "admin";
private static final String ROLE_DELIMETER = ",";
private static final String ROLE_DELIMITER = ",";
private static final String PERMISSION_DELIMETER = ",";
@@ -37,7 +37,7 @@ public class PermissionService {
* @param permission 权限字符串
* @return 用户是否具备某权限
*/
public boolean hasPermi(String permission) {
public boolean hasPermission(String permission) {
if (StringUtils.isEmpty(permission)) {
return false;
}
@@ -49,13 +49,13 @@ public class PermissionService {
}
/**
* 验证用户是否不具备某权限,与 hasPermi逻辑相反
* 验证用户是否不具备某权限,与 hasPermission逻辑相反
*
* @param permission 权限字符串
* @return 用户是否不具备某权限
*/
public boolean lacksPermi(String permission) {
return hasPermi(permission) != true;
public boolean lacksPermission(String permission) {
return hasPermission(permission) != true;
}
/**
@@ -64,7 +64,7 @@ public class PermissionService {
* @param permissions 以 PERMISSION_NAMES_DELIMETER 为分隔符的权限列表
* @return 用户是否具有以下任意一个权限
*/
public boolean hasAnyPermi(String permissions) {
public boolean hasAnyPermission(String permissions) {
if (StringUtils.isEmpty(permissions)) {
return false;
}
@@ -111,13 +111,13 @@ public class PermissionService {
* @return 用户是否不具备某角色
*/
public boolean lacksRole(String role) {
return hasRole(role) != true;
return !hasRole(role);
}
/**
* 验证用户是否具有以下任意一个角色
*
* @param roles 以 ROLE_NAMES_DELIMETER 为分隔符的角色列表
* @param roles 以 ROLE_NAMES_DELIMITER 为分隔符的角色列表
* @return 用户是否具有以下任意一个角色
*/
public boolean hasAnyRoles(String roles) {
@@ -128,7 +128,7 @@ public class PermissionService {
if (loginUser == null || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) {
return false;
}
for (String role : roles.split(ROLE_DELIMETER)) {
for (String role : roles.split(ROLE_DELIMITER)) {
if (hasRole(role)) {
return true;
}

View File

@@ -1,5 +1,6 @@
package com.starry.admin.common.mybatis.handler;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.starry.admin.utils.SecurityUtils;
import com.starry.common.utils.StringUtils;
@@ -33,8 +34,8 @@ public class MyTenantLineHandler implements TenantLineHandler {
@Override
public Expression getTenantId() {
// 取出当前请求的服务商ID通过解析器注入到SQL中。
Long tenantId = SecurityUtils.getTenantId();
if (tenantId == null) {
String tenantId = SecurityUtils.getTenantId();
if (StrUtil.isBlankIfStr(tenantId)) {
return new NullValue();
}
return new LongValue(tenantId);

View File

@@ -0,0 +1,85 @@
package com.starry.admin.modules.commodity.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.commodity.module.entity.CommodityInfoEntity;
import com.starry.admin.modules.commodity.service.ICommodityInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* 商品Controller
*
* @author admin
* @since 2024-03-22
*/
@RestController
@RequestMapping("/commodity/info")
public class CommodityInfoController {
@Resource
private ICommodityInfoService commodityInfoService;
/**
* 查询商品列表
*/
@PreAuthorize("@customSs.hasPermission('commodity:info:list')")
@GetMapping("/list")
public R list(CommodityInfoEntity commodityInfo) {
IPage<CommodityInfoEntity> list = commodityInfoService.selectCommodityInfoByPage(commodityInfo);
return R.ok(list);
}
/**
* 获取商品详细信息
*/
@PreAuthorize("@customSs.hasPermission('commodity:info:query')")
@GetMapping(value = "/{id}")
public R getInfo(@PathVariable("id") String id) {
return R.ok(commodityInfoService.selectCommodityInfoEntityById(id));
}
/**
* 新增商品
*/
@PreAuthorize("@customSs.hasPermission('commodity:info:create')")
@Log(title = "商品", businessType = BusinessType.INSERT)
@PostMapping("/create")
public R create(@RequestBody CommodityInfoEntity commodityInfo) {
boolean success = commodityInfoService.create(commodityInfo);
if (success) {
return R.ok();
}
return R.error("添加失败");
}
/**
* 修改商品
*/
@PreAuthorize("@customSs.hasPermission('commodity:info:edit')")
@Log(title = "商品", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update/{id}")
public R update(@PathVariable String id, @RequestBody CommodityInfoEntity commodityInfo) {
commodityInfo.setId(id);
boolean success = commodityInfoService.update(commodityInfo);
if (success) {
return R.ok();
}
return R.error("修改失败");
}
/**
* 删除商品
*/
@PreAuthorize("@customSs.hasPermission('commodity:info:remove')")
@Log(title = "商品", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R remove(@PathVariable String[] ids) {
return R.ok(commodityInfoService.deleteCommodityInfoEntityByIds(ids));
}
}

View File

@@ -0,0 +1,16 @@
package com.starry.admin.modules.commodity.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starry.admin.modules.commodity.module.entity.CommodityInfoEntity;
/**
* 商品Mapper接口
*
* @author admin
* @since 2024-03-22
*/
public interface CommodityInfoMapper extends BaseMapper<CommodityInfoEntity> {
}

View File

@@ -0,0 +1,24 @@
package com.starry.admin.modules.commodity.module.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.starry.common.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("commodity_info")
public class CommodityInfoEntity extends BaseEntity<CommodityInfoEntity> {
/**
* UUID
*/
private String id;
/**
* 价格
*/
private String money;
}

View File

@@ -0,0 +1,62 @@
package com.starry.admin.modules.commodity.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.commodity.module.entity.CommodityInfoEntity;
/**
* 商品Service接口
*
* @author admin
* @since 2024-03-22
*/
public interface ICommodityInfoService extends IService<CommodityInfoEntity> {
/**
* 查询商品
*
* @param id 商品主键
* @return 商品
*/
CommodityInfoEntity selectCommodityInfoEntityById(String id);
/**
* 查询商品列表
*
* @param CommodityInfoEntity 商品
* @return 商品集合
*/
IPage<CommodityInfoEntity> selectCommodityInfoByPage(CommodityInfoEntity CommodityInfoEntity);
/**
* 新增商品
*
* @param CommodityInfoEntity 商品
* @return 结果
*/
boolean create(CommodityInfoEntity CommodityInfoEntity);
/**
* 修改商品
*
* @param CommodityInfoEntity 商品
* @return 结果
*/
boolean update(CommodityInfoEntity CommodityInfoEntity);
/**
* 批量删除商品
*
* @param ids 需要删除的商品主键集合
* @return 结果
*/
int deleteCommodityInfoEntityByIds(String[] ids);
/**
* 删除商品信息
*
* @param id 商品主键
* @return 结果
*/
int deleteCommodityInfoEntityById(String id);
}

View File

@@ -0,0 +1,92 @@
package com.starry.admin.modules.commodity.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.commodity.mapper.CommodityInfoMapper;
import com.starry.admin.modules.commodity.module.entity.CommodityInfoEntity;
import com.starry.admin.modules.commodity.service.ICommodityInfoService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
/**
* 商品Service业务层处理
*
* @author admin
* @since 2024-03-22
*/
@Service
public class CommodityInfoServiceImpl extends ServiceImpl<CommodityInfoMapper, CommodityInfoEntity> implements ICommodityInfoService {
@Resource
private CommodityInfoMapper CommodityInfoMapper;
/**
* 查询商品
*
* @param id 商品主键
* @return 商品
*/
@Override
public CommodityInfoEntity selectCommodityInfoEntityById(String id) {
return this.baseMapper.selectById(id);
}
/**
* 查询商品列表
*
* @param CommodityInfoEntity 商品
* @return 商品
*/
@Override
public IPage<CommodityInfoEntity> selectCommodityInfoByPage(CommodityInfoEntity CommodityInfoEntity) {
Page<CommodityInfoEntity> page = new Page<>(1, 10);
return this.baseMapper.selectPage(page, new LambdaQueryWrapper<CommodityInfoEntity>());
}
/**
* 新增商品
*
* @param CommodityInfoEntity 商品
* @return 结果
*/
@Override
public boolean create(CommodityInfoEntity CommodityInfoEntity) {
return save(CommodityInfoEntity);
}
/**
* 修改商品
*
* @param CommodityInfoEntity 商品
* @return 结果
*/
@Override
public boolean update(CommodityInfoEntity CommodityInfoEntity) {
return updateById(CommodityInfoEntity);
}
/**
* 批量删除商品
*
* @param ids 需要删除的商品主键
* @return 结果
*/
@Override
public int deleteCommodityInfoEntityByIds(String[] ids) {
return CommodityInfoMapper.deleteBatchIds(Arrays.asList(ids));
}
/**
* 删除商品信息
*
* @param id 商品主键
* @return 结果
*/
@Override
public int deleteCommodityInfoEntityById(String id) {
return CommodityInfoMapper.deleteById(id);
}
}

View File

@@ -0,0 +1,85 @@
package com.starry.admin.modules.coupon.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.coupon.module.entity.CouponInfoEntity;
import com.starry.admin.modules.coupon.service.ICouponInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* 商品Controller
*
* @author admin
* @since 2024-03-22
*/
@RestController
@RequestMapping("/coupon/info")
public class CouponInfoController {
@Resource
private ICouponInfoService couponInfoService;
/**
* 查询商品列表
*/
@PreAuthorize("@customSs.hasPermission('coupon/infolist')")
@GetMapping("/list")
public R list(CouponInfoEntity couponInfo) {
IPage<CouponInfoEntity> list = couponInfoService.selectCouponInfoByPage(couponInfo);
return R.ok(list);
}
/**
* 获取商品详细信息
*/
@PreAuthorize("@customSs.hasPermission('coupon/infoquery')")
@GetMapping(value = "/{id}")
public R getInfo(@PathVariable("id") String id) {
return R.ok(couponInfoService.selectCouponInfoById(id));
}
/**
* 新增商品
*/
@PreAuthorize("@customSs.hasPermission('coupon/infocreate')")
@Log(title = "商品", businessType = BusinessType.INSERT)
@PostMapping("/create")
public R create(@RequestBody CouponInfoEntity couponInfo) {
boolean success = couponInfoService.create(couponInfo);
if (success) {
return R.ok();
}
return R.error("添加失败");
}
/**
* 修改商品
*/
@PreAuthorize("@customSs.hasPermission('coupon/infoedit')")
@Log(title = "商品", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update/{id}")
public R update(@PathVariable String id, @RequestBody CouponInfoEntity couponInfo) {
couponInfo.setId(id);
boolean success = couponInfoService.update(couponInfo);
if (success) {
return R.ok();
}
return R.error("修改失败");
}
/**
* 删除商品
*/
@PreAuthorize("@customSs.hasPermission('coupon/inforemove')")
@Log(title = "商品", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R remove(@PathVariable String[] ids) {
return R.ok(couponInfoService.deleteCouponInfoByIds(ids));
}
}

View File

@@ -0,0 +1,29 @@
package com.starry.admin.modules.coupon.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starry.admin.modules.coupon.module.entity.CouponInfoEntity;
import java.util.List;
/**
* 商品Mapper接口
*
* @author admin
* @since 2024-03-22
*/
public interface CouponInfoMapper extends BaseMapper<CouponInfoEntity> {
/**
* 查询商品
* @param id 商品主键
* @return 商品
*/
CouponInfoEntity selectCouponInfoById(String id);
/**
* 查询商品列表
* @param couponInfo 商品
* @return 商品集合
*/
List<CouponInfoEntity> selectCouponInfoList(CouponInfoEntity couponInfo);
}

View File

@@ -0,0 +1,25 @@
package com.starry.admin.modules.coupon.module.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.starry.common.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("coupon_info")
public class CouponInfoEntity extends BaseEntity<CouponInfoEntity> {
/**
* UUID
*/
private String id;
/**
* 价格
*/
private String money;
}

View File

@@ -0,0 +1,61 @@
package com.starry.admin.modules.coupon.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.coupon.module.entity.CouponInfoEntity;
/**
* 商品Service接口
*
* @author admin
* @since 2024-03-22
*/
public interface ICouponInfoService extends IService<CouponInfoEntity> {
/**
* 查询商品
*
* @param id 商品主键
* @return 商品
*/
CouponInfoEntity selectCouponInfoById(String id);
/**
* 查询商品列表
*
* @param couponInfo 商品
* @return 商品集合
*/
IPage<CouponInfoEntity> selectCouponInfoByPage(CouponInfoEntity couponInfo);
/**
* 新增商品
*
* @param couponInfo 商品
* @return 结果
*/
boolean create(CouponInfoEntity couponInfo);
/**
* 修改商品
*
* @param couponInfo 商品
* @return 结果
*/
boolean update(CouponInfoEntity couponInfo);
/**
* 批量删除商品
*
* @param ids 需要删除的商品主键集合
* @return 结果
*/
int deleteCouponInfoByIds(String[] ids);
/**
* 删除商品信息
*
* @param id 商品主键
* @return 结果
*/
int deleteCouponInfoById(String id);
}

View File

@@ -0,0 +1,86 @@
package com.starry.admin.modules.coupon.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.coupon.mapper.CouponInfoMapper;
import com.starry.admin.modules.coupon.module.entity.CouponInfoEntity;
import com.starry.admin.modules.coupon.service.ICouponInfoService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
/**
* 商品Service业务层处理
*
* @author admin
* @since 2024-03-22
*/
@Service
public class CouponInfoServiceImpl extends ServiceImpl<CouponInfoMapper, CouponInfoEntity> implements ICouponInfoService {
@Resource
private CouponInfoMapper couponInfoMapper;
/**
* 查询商品
* @param id 商品主键
* @return 商品
*/
@Override
public CouponInfoEntity selectCouponInfoById(String id) {
return this.baseMapper.selectById(id);
}
/**
* 查询商品列表
* @param couponInfo 商品
* @return 商品
*/
@Override
public IPage<CouponInfoEntity> selectCouponInfoByPage(CouponInfoEntity couponInfo) {
Page<CouponInfoEntity> page = new Page<>(1, 10);
return this.baseMapper.selectPage(page, new LambdaQueryWrapper<CouponInfoEntity>());
}
/**
* 新增商品
* @param couponInfo 商品
* @return 结果
*/
@Override
public boolean create(CouponInfoEntity couponInfo) {
return save(couponInfo);
}
/**
* 修改商品
* @param couponInfo 商品
* @return 结果
*/
@Override
public boolean update(CouponInfoEntity couponInfo) {
return updateById(couponInfo);
}
/**
* 批量删除商品
* @param ids 需要删除的商品主键
* @return 结果
*/
@Override
public int deleteCouponInfoByIds(String[] ids) {
return couponInfoMapper.deleteBatchIds(Arrays.asList(ids));
}
/**
* 删除商品信息
* @param id 商品主键
* @return 结果
*/
@Override
public int deleteCouponInfoById(String id) {
return couponInfoMapper.deleteById(id);
}
}

View File

@@ -33,7 +33,7 @@ public class CacheController {
CACHES.add(new Cache(CacheConstants.CAPTCHA_CODE_KEY, "验证码"));
}
@PreAuthorize("@customSs.hasPermi('monitor:cache:list')")
@PreAuthorize("@customSs.hasPermission('monitor:cache:list')")
@GetMapping()
public R getInfo() throws Exception {
Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) RedisServerCommands::info);
@@ -55,20 +55,20 @@ public class CacheController {
return R.ok(result);
}
@PreAuthorize("@customSs.hasPermi('monitor:cache:list')")
@PreAuthorize("@customSs.hasPermission('monitor:cache:list')")
@GetMapping("/getNames")
public R cache() {
return R.ok(CACHES);
}
@PreAuthorize("@customSs.hasPermi('monitor:cache:list')")
@PreAuthorize("@customSs.hasPermission('monitor:cache:list')")
@GetMapping("/getKeys/{cacheName}")
public R getCacheKeys(@PathVariable String cacheName) {
Set<String> cacheKeys = redisTemplate.keys(cacheName + "*");
return R.ok(cacheKeys);
}
@PreAuthorize("@customSs.hasPermi('monitor:cache:list')")
@PreAuthorize("@customSs.hasPermission('monitor:cache:list')")
@GetMapping("/getValue/{cacheName}/{cacheKey}")
public R getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey) {
String cacheValue = redisTemplate.opsForValue().get(cacheKey);
@@ -76,7 +76,7 @@ public class CacheController {
return R.ok(cache);
}
@PreAuthorize("@customSs.hasPermi('monitor:cache:list')")
@PreAuthorize("@customSs.hasPermission('monitor:cache:list')")
@DeleteMapping("/clearCacheName/{cacheName}")
public R clearCacheName(@PathVariable String cacheName) {
Collection<String> cacheKeys = redisTemplate.keys(cacheName + "*");
@@ -84,14 +84,14 @@ public class CacheController {
return R.ok();
}
@PreAuthorize("@customSs.hasPermi('monitor:cache:list')")
@PreAuthorize("@customSs.hasPermission('monitor:cache:list')")
@DeleteMapping("/clearCacheKey/{cacheKey}")
public R clearCacheKey(@PathVariable String cacheKey) {
redisTemplate.delete(cacheKey);
return R.ok();
}
@PreAuthorize("@customSs.hasPermi('monitor:cache:list')")
@PreAuthorize("@customSs.hasPermission('monitor:cache:list')")
@DeleteMapping("/clearCacheAll")
public R clearCacheAll() {
Collection<String> cacheKeys = redisTemplate.keys("*");

View File

@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/monitor/server")
public class ServerController {
@PreAuthorize("@customSs.hasPermi('monitor:server:list')")
@PreAuthorize("@customSs.hasPermission('monitor:server:list')")
@GetMapping()
public R getInfo() throws Exception {
Server server = new Server();

View File

@@ -34,7 +34,7 @@ public class UserOnlineController {
@Resource
private UserOnlineService userOnlineService;
@PreAuthorize("@customSs.hasPermi('monitor:online:list')")
@PreAuthorize("@customSs.hasPermission('monitor:online:list')")
@GetMapping("/list")
public R list(String ipaddr, String userName) {
Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
@@ -66,7 +66,7 @@ public class UserOnlineController {
/**
* 强退用户
*/
@PreAuthorize("@customSs.hasPermi('monitor:online:forceLogout')")
@PreAuthorize("@customSs.hasPermission('monitor:online:forceLogout')")
@Log(title = "在线用户", businessType = BusinessType.FORCE)
@DeleteMapping("/{tokenId}")
public R forceLogout(@PathVariable String tokenId) {

View File

@@ -0,0 +1,226 @@
package com.starry.admin.modules.order.controller;
import cn.hutool.core.util.IdUtil;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.commodity.module.entity.CommodityInfoEntity;
import com.starry.admin.modules.commodity.service.ICommodityInfoService;
import com.starry.admin.modules.coupon.module.entity.CouponInfoEntity;
import com.starry.admin.modules.coupon.service.ICouponInfoService;
import com.starry.admin.modules.order.module.entity.OrderDetailsInfoEntity;
import com.starry.admin.modules.order.module.entity.OrderInfoEntity;
import com.starry.admin.modules.order.module.entity.OrderLogInfoEntity;
import com.starry.admin.modules.order.module.vo.OrderInfoAddVo;
import com.starry.admin.modules.order.module.vo.OrderInfoQueryVo;
import com.starry.admin.modules.order.module.vo.OrderInfoRefundVo;
import com.starry.admin.modules.order.module.vo.OrderInfoRewardVo;
import com.starry.admin.modules.order.service.IOrderDetailsInfoService;
import com.starry.admin.modules.order.service.IOrderInfoService;
import com.starry.admin.modules.order.service.IOrderLogInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import com.starry.common.utils.ConvertUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
/**
* 订单管理
*
* @author admin
* @since 2024-03-20
*/
@RestController
@RequestMapping("/order/info")
public class OrderInfoController {
@Resource
private IOrderInfoService orderInfoService;
@Resource
private IOrderLogInfoService orderLogInfoService;
@Resource
private IOrderDetailsInfoService orderDetailsInfoService;
@Resource
private ICommodityInfoService commodityInfoService;
@Resource
private ICouponInfoService couponInfoService;
@PreAuthorize("@customSs.hasPermission('order/info/create')")
@Log(title = "新增打赏订单", businessType = BusinessType.INSERT)
@PostMapping("/reward")
public R reward(@RequestBody OrderInfoRewardVo addVo) {
//校验当前用户余额是否充足
// if (false) {
// throw new CustomException("余额不足,无法下单");
// }
// 新增陪玩余额
// 减少用户余额
// 新增订单记录(订单信息需完善)
OrderInfoEntity entity = ConvertUtil.entityToVo(addVo, OrderInfoEntity.class);
orderInfoService.create(entity);
// 新增订单处理日志(打赏单,订单直接完成)
orderLogInfoService.create(new OrderLogInfoEntity(entity.getId(), "1", new Date()));
orderLogInfoService.create(new OrderLogInfoEntity(entity.getId(), "4", new Date()));
return R.ok("成功");
}
/**
* 新增订单
*/
@PreAuthorize("@customSs.hasPermission('order/info/create')")
@Log(title = "新增普通订单", businessType = BusinessType.INSERT)
@PostMapping("/create")
public R create(@RequestBody OrderInfoAddVo addVo) {
//商品总价格
long commodityTotalMoney = 0;
//订单总价格
long orderTotalMoney = 0;
//校验商品是否存在
for (String commodityInfoId : addVo.getCommodityInfoIds()) {
CommodityInfoEntity commodityInfo = commodityInfoService.selectCommodityInfoEntityById(commodityInfoId);
if (commodityInfo == null) {
throw new CustomException("商品不存在");
}
}
//校验优惠券是否存在
for (String commodityInfoId : addVo.getCouponIds()) {
CouponInfoEntity couponInfo = couponInfoService.selectCouponInfoById(commodityInfoId);
if (couponInfo == null) {
throw new CustomException("优惠券不存在");
}
}
//校验当前用户余额是否充足
// if (false) {
// throw new CustomException("余额不足,无法下单");
// }
OrderInfoEntity entity = ConvertUtil.entityToVo(addVo, OrderInfoEntity.class);
entity.setId(IdUtil.fastSimpleUUID());
entity.setFirstOrder(true);
entity.setOrderMoney(String.valueOf(orderTotalMoney));
orderInfoService.create(entity);
// 记录订单日志
orderLogInfoService.create(new OrderLogInfoEntity(entity.getId(), "0", new Date()));
// 记录订单详细信息
for (String commodityInfoId : addVo.getCommodityInfoIds()) {
orderDetailsInfoService.create(new OrderDetailsInfoEntity(entity.getId(), commodityInfoId, "0"));
}
for (String commodityInfoId : addVo.getCouponIds()) {
orderDetailsInfoService.create(new OrderDetailsInfoEntity(entity.getId(), commodityInfoId, "1"));
}
// 发送通知给陪玩,等待陪玩接单
return R.ok("下单成功,等待接单");
}
/**
* 分页查询订单列表
*/
@PreAuthorize("@customSs.hasPermission('order/info/list')")
@GetMapping("/list")
public R list(OrderInfoQueryVo vo) {
return R.ok(orderInfoService.selectOrderInfoList(vo));
}
/**
* 根据ID查询订单
*/
@PreAuthorize("@customSs.hasPermission('order/info/query')")
@GetMapping(value = "/{id}")
public R getInfo(@PathVariable("id") String id) {
return R.ok(orderInfoService.selectOrderInfoById(id));
}
/**
* 根据ID修改订单信息
*/
@PreAuthorize("@customSs.hasPermission('order/info/edit')")
@Log(title = "修改普通订单", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update/{id}")
public R update(@PathVariable String id, @RequestBody OrderInfoEntity orderInfoEntity) {
orderInfoEntity.setId(id);
boolean success = orderInfoService.update(orderInfoEntity);
if (success) {
return R.ok();
}
return R.error("修改失败");
}
/**
* 根据ID进行订单退款
*/
@PreAuthorize("@customSs.hasPermission('order/info/edit')")
@Log(title = "发起订单退款申请", businessType = BusinessType.UPDATE)
@PostMapping(value = "/refund/{id}")
public R refund(@RequestBody OrderInfoRefundVo vo) {
OrderInfoEntity entity = orderInfoService.selectOrderInfoById(vo.getId());
if (entity == null) {
throw new CustomException("订单不存在");
}
if (!"0".equals(entity.getRefundType())) {
throw new CustomException("订单已退款,无法二次退款");
}
// 订单最终金额
long finalAmount = 0;
// 部分退款,计算退款金额是否小于订单金额
if ("1".equals(vo.getRefundType())) {
// 退款金额
long refundMoney = Long.getLong(vo.getRefundMoney());
// 订单金额
long orderMoney = Long.getLong(entity.getOrderMoney());
if (refundMoney <= 0) {
throw new CustomException("退款金额必须大于0");
}
if (orderMoney < refundMoney) {
throw new CustomException("退款金额必须小于订单总金额");
}
finalAmount = orderMoney - refundMoney;
}
// 减少陪玩余额
// 新增用户余额
// 修改订单信息
orderLogInfoService.create(new OrderLogInfoEntity(entity.getId(), "4", new Date()));
entity.setFinalAmount(String.valueOf(finalAmount));
entity.setRefundType(vo.getRefundType());
orderInfoService.update(entity);
// 增加订单处理日志
return R.ok("成功");
}
/**
* 删除订单
*/
@PreAuthorize("@customSs.hasPermission('order/info/remove')")
@Log(title = "删除订单", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R remove(@PathVariable String[] ids) {
return R.ok(orderInfoService.deleteOrderInfoByIds(ids));
}
}

View File

@@ -0,0 +1,31 @@
package com.starry.admin.modules.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starry.admin.modules.order.module.entity.OrderDetailsInfoEntity;
import java.util.List;
/**
* 订单详细Mapper接口
*
* @author admin
* @since 2024-03-20
*/
public interface OrderDetailsInfoMapper extends BaseMapper<OrderDetailsInfoEntity> {
/**
* 查询订单详细
*
* @param id 订单详细主键
* @return 订单详细
*/
OrderDetailsInfoEntity selectOrderDetailsInfoById(String id);
/**
* 查询订单详细列表
*
* @param orderDetailsInfo 订单详细
* @return 订单详细集合
*/
List<OrderDetailsInfoEntity> selectOrderDetailsInfoList(OrderDetailsInfoEntity orderDetailsInfo);
}

View File

@@ -0,0 +1,29 @@
package com.starry.admin.modules.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starry.admin.modules.order.module.entity.OrderInfoEntity;
import java.util.List;
/**
* 订单Mapper接口
*
* @author admin
* @since 2024-03-20
*/
public interface OrderInfoMapper extends BaseMapper<OrderInfoEntity> {
/**
* 查询订单
* @param id 订单主键
* @return 订单
*/
OrderInfoEntity selectOrderInfoById(String id);
/**
* 查询订单列表
* @param orderInfoEntity 订单
* @return 订单集合
*/
List<OrderInfoEntity> selectOrderInfoList(OrderInfoEntity orderInfoEntity);
}

View File

@@ -0,0 +1,15 @@
package com.starry.admin.modules.order.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starry.admin.modules.order.module.entity.OrderLogInfoEntity;
/**
* 【请填写功能名称】Mapper接口
*
* @author admin
* @since 2024-03-22
*/
public interface OrderLogInfoMapper extends BaseMapper<OrderLogInfoEntity> {
}

View File

@@ -0,0 +1,54 @@
package com.starry.admin.modules.order.module.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.starry.common.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 【请填写功能名称】对象 order_details_info
*
* @author admin
* @since 2024-03-20
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("order_details_info")
public class OrderDetailsInfoEntity extends BaseEntity<OrderDetailsInfoEntity> {
/**
* UUID
*/
private String id;
/**
* 订单ID
*/
private String orderId;
/**
* 商品ID
*/
private String commodityId;
/**
* 商品类型【0:1】
* 0服务
* 1优惠券
*/
private String commodityType;
/**
* 备注
*/
private String remake;
public OrderDetailsInfoEntity(String orderId, String commodityId, String commodityType) {
this.orderId = orderId;
this.commodityId = commodityId;
this.commodityType = commodityType;
}
}

View File

@@ -0,0 +1,101 @@
package com.starry.admin.modules.order.module.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.starry.common.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 【请填写功能名称】对象 order_info
*
* @author admin
* @since 2024-03-20
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("order_info")
public class OrderInfoEntity extends BaseEntity<OrderInfoEntity> {
/**
* uuid
*/
private String id;
/**
* 租户ID
*/
private String tenantId;
/**
* 订单状态【0:1:2:3:4:5】
* 0已下单
* 1已审核退款 或者 提现需要审核,其余不需要)
* 2已接单
* 3已开始
* 4已完成
* 5已取消
*/
private String orderStatus;
/**
* 订单类型【0充值订单1提现订单2普通订单】
*/
private String orderType;
/**
* 下单类型0指定单1随机单。2打赏单
*/
private String placeType;
/**
* 是否是首单【0不是。1是】
*/
private Boolean firstOrder;
/**
* 退款类型【0未退款1部分退款2全部退款】
*/
private String refundType;
/**
* 订单金额
*/
private String orderMoney;
/**
* 订单最终金额
*/
private String finalAmount;
/**
* 下单人
*/
private String purchaserBy;
/**
* 下单时间
*/
private Date purchaserTime;
/**
* 审核人
*/
private String reviewedBy;
/**
* 审核时间
*/
private Date reviewedTime;
/**
* 审核内容
*/
private String reviewedRemark;
}

View File

@@ -0,0 +1,59 @@
package com.starry.admin.modules.order.module.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.starry.common.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("order_log_info")
public class OrderLogInfoEntity extends BaseEntity<OrderLogInfoEntity> {
/**
* uuid
*/
private String id;
/**
* 租户ID
*/
private String tenantId;
/**
* 订单ID
*/
private String orderId;
/**
* 操作类型
* 0:下单
* 1:审核
* 2:接单
* 3:服务
* 4:退款
* 4:完成
* 6:取消
*/
private String operType;
/**
* 操作时间
*/
private Date operTime;
/**
* 备注
*/
private String remark;
public OrderLogInfoEntity(String orderId, String operType, Date operTime) {
this.orderId = orderId;
this.operType = operType;
this.operTime = operTime;
}
}

View File

@@ -0,0 +1,69 @@
package com.starry.admin.modules.order.module.vo;
import com.baomidou.mybatisplus.annotation.TableName;
import com.starry.common.annotation.EnumValue;
import com.starry.common.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 【请填写功能名称】对象 order_info
*
* @author admin
* @since 2024-03-20
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("order_info")
public class OrderInfoAddVo extends BaseEntity<OrderInfoAddVo> {
/**
* 租户ID
*/
@NotBlank(message = "租户ID不能为空")
private String tenantId;
/**
* 订单状态【0:1:2:3:4:5】
* 0已下单
* 1已审核退款 或者 提现需要审核,其余不需要)
* 2已接单
* 3已开始
* 4已完成
* 5已取消
*/
private String orderStatus = String.valueOf(0);
/**
* 订单类型【0充值订单1提现订单2普通订单】
*/
private String orderType = String.valueOf(2);
/**
* 下单类型0指定单1随机单。2打赏单
*/
@EnumValue(strValues = {"0", "1"}, message = "退款类型参数异常")
@NotBlank(message = "下单类型不能为空")
private String placeType;
/**
* 商品列表
*/
@NotNull(message = "商品不能为空")
private List<String> commodityInfoIds;
/**
* 优惠券ID列表
*/
private List<String> couponIds;
}

View File

@@ -0,0 +1,87 @@
package com.starry.admin.modules.order.module.vo;
import com.starry.common.domain.BasePageEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 【请填写功能名称】对象 order_info
*
* @author admin
* @since 2024-03-20
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class OrderInfoQueryVo extends BasePageEntity {
/**
* 租户ID
*/
private String tenantId;
/**
* 订单状态【0:1:2:3:4:5】
* 0已下单
* 1已审核退款 或者 提现需要审核,其余不需要)
* 2已接单
* 3已开始
* 4已完成
* 5已取消
*/
private String orderStatus;
/**
* 订单类型【0充值订单1提现订单2普通订单】
*/
private String orderType;
/**
* 下单类型0指定单1随机单。2打赏单
*/
private String placeType;
/**
* 是否是首单【0不是。1是】
*/
private Integer firstOrder;
/**
* 退款类型【0未退款1部分退款2全部退款】
*/
private String refundType;
/**
* 订单金额
*/
private String orderMoney;
/**
* 下单人
*/
private Date purchaserBy;
/**
* 下单时间
*/
private Date purchaserTime;
/**
* 审核人
*/
private String reviewedBy;
/**
* 审核时间
*/
private Date reviewedTime;
/**
* 审核内容
*/
private String reviewedRemark;
}

View File

@@ -0,0 +1,44 @@
package com.starry.admin.modules.order.module.vo;
import com.starry.common.annotation.EnumValue;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 【请填写功能名称】对象 order_info
*
* @author admin
* @since 2024-03-20
*/
@Data
public class OrderInfoRefundVo {
/**
* uuid
*/
@NotNull(message = "订单ID不能为空")
private String id;
/**
* 租户ID
*/
// @NotNull(message = "租户ID不能为空")
private String tenantId;
/**
* 退款类型【1部分退款2全部退款】
*/
@NotNull(message = "退款类型不能为空")
@EnumValue(strValues = {"1", "2"}, message = "退款类型参数异常")
private String refundType;
/**
* 退款金额,单位分
*/
private String refundMoney;
}

View File

@@ -0,0 +1,50 @@
package com.starry.admin.modules.order.module.vo;
import com.starry.common.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
/**
* 【请填写功能名称】对象 order_info
*
* @author admin
* @since 2024-03-20
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class OrderInfoRewardVo extends BaseEntity<OrderInfoRewardVo> {
/**
* 租户ID
*/
@NotBlank(message = "租户ID不能为空")
private String tenantId;
/**
* 用户ID
*/
@NotBlank(message = "打赏对象不能为空")
private String userId;
/**
* 订单类型【0充值订单1提现订单2普通订单】
*/
private String orderType = String.valueOf(2);
/**
* 下单类型0指定单1随机单。2打赏单
*/
@NotBlank(message = "下单类型不能为空")
private String placeType = "2";
/**
* 金额,单位分
*/
@NotBlank(message = "打赏金额不能为空")
private String money;
}

View File

@@ -0,0 +1,64 @@
package com.starry.admin.modules.order.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.order.module.entity.OrderDetailsInfoEntity;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 订单详细Service接口
*
* @author admin
* @since 2024-03-20
*/
@Service
public interface IOrderDetailsInfoService extends IService<OrderDetailsInfoEntity> {
/**
* 查询订单详细
*
* @param id 订单详细主键
* @return 订单详细
*/
OrderDetailsInfoEntity selectOrderDetailsInfoById(String id);
/**
* 查询订单详细列表
*
* @param orderDetailsInfo 订单详细
* @return 订单详细集合
*/
List<OrderDetailsInfoEntity> selectOrderDetailsInfoList(OrderDetailsInfoEntity orderDetailsInfo);
/**
* 新增订单详细
*
* @param orderDetailsInfo 订单详细
* @return 结果
*/
boolean create(OrderDetailsInfoEntity orderDetailsInfo);
/**
* 修改订单详细
*
* @param orderDetailsInfo 订单详细
* @return 结果
*/
boolean update(OrderDetailsInfoEntity orderDetailsInfo);
/**
* 批量删除订单详细
*
* @param ids 需要删除的订单详细主键集合
* @return 结果
*/
int deleteOrderDetailsInfoByIds(String[] ids);
/**
* 删除订单详细信息
*
* @param id 订单详细主键
* @return 结果
*/
int deleteOrderDetailsInfoById(String id);
}

View File

@@ -0,0 +1,64 @@
package com.starry.admin.modules.order.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.order.module.entity.OrderInfoEntity;
import com.starry.admin.modules.order.module.vo.OrderInfoQueryVo;
import org.springframework.stereotype.Service;
/**
* 订单Service接口
*
* @author admin
* @since 2024-03-20
*/
@Service
public interface IOrderInfoService extends IService<OrderInfoEntity> {
/**
* 查询订单
*
* @param id 订单主键
* @return 订单
*/
OrderInfoEntity selectOrderInfoById(String id);
/**
* 查询订单列表
*
* @param orderInfoEntity 订单
* @return 订单集合
*/
IPage<OrderInfoEntity> selectOrderInfoList(OrderInfoQueryVo orderInfoEntity);
/**
* 新增订单
*
* @param orderInfoEntity 订单
* @return 结果
*/
boolean create(OrderInfoEntity orderInfoEntity);
/**
* 修改订单
*
* @param orderInfoEntity 订单
* @return 结果
*/
boolean update(OrderInfoEntity orderInfoEntity);
/**
* 批量删除订单
*
* @param ids 需要删除的订单主键集合
* @return 结果
*/
int deleteOrderInfoByIds(String[] ids);
/**
* 删除订单信息
*
* @param id 订单主键
* @return 结果
*/
int deleteOrderInfoById(String id);
}

View File

@@ -0,0 +1,56 @@
package com.starry.admin.modules.order.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.order.module.entity.OrderLogInfoEntity;
/**
* 【请填写功能名称】Service接口
*
* @author admin
* @since 2024-03-22
*/
public interface IOrderLogInfoService extends IService<OrderLogInfoEntity> {
/**
* 查询【请填写功能名称】
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
OrderLogInfoEntity selectOrderLogInfoById(String id);
/**
* 查询【请填写功能名称】列表
* @param orderLogInfo 【请填写功能名称】
* @return 【请填写功能名称】集合
*/
IPage<OrderLogInfoEntity> selectOrderLogInfoByPage(OrderLogInfoEntity orderLogInfo);
/**
* 新增【请填写功能名称】
* @param orderLogInfo 【请填写功能名称】
* @return 结果
*/
boolean create(OrderLogInfoEntity orderLogInfo);
/**
* 修改【请填写功能名称】
* @param orderLogInfo 【请填写功能名称】
* @return 结果
*/
boolean update(OrderLogInfoEntity orderLogInfo);
/**
* 批量删除【请填写功能名称】
*
* @param ids 需要删除的【请填写功能名称】主键集合
* @return 结果
*/
int deleteOrderLogInfoByIds(String[] ids);
/**
* 删除【请填写功能名称】信息
*
* @param id 【请填写功能名称】主键
* @return 结果
*/
int deleteOrderLogInfoById(String id);
}

View File

@@ -0,0 +1,94 @@
package com.starry.admin.modules.order.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.order.mapper.OrderDetailsInfoMapper;
import com.starry.admin.modules.order.module.entity.OrderDetailsInfoEntity;
import com.starry.admin.modules.order.service.IOrderDetailsInfoService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
/**
* 订单详细Service业务层处理
*
* @author admin
* @since 2024-03-20
*/
@Service
public class OrderDetailsInfoServiceImpl extends ServiceImpl<OrderDetailsInfoMapper, OrderDetailsInfoEntity> implements IOrderDetailsInfoService {
@Resource
private OrderDetailsInfoMapper orderDetailsInfoMapper;
/**
* 查询订单详细
*
* @param id 订单详细主键
* @return 订单详细
*/
@Override
public OrderDetailsInfoEntity selectOrderDetailsInfoById(String id) {
return orderDetailsInfoMapper.selectOrderDetailsInfoById(id);
}
/**
* 查询订单详细列表
*
* @param orderDetailsInfo 订单详细
* @return 订单详细
*/
@Override
public List<OrderDetailsInfoEntity> selectOrderDetailsInfoList(OrderDetailsInfoEntity orderDetailsInfo) {
return orderDetailsInfoMapper.selectOrderDetailsInfoList(orderDetailsInfo);
}
/**
* 新增订单详细
*
* @param orderDetailsInfo 订单详细
* @return 结果
*/
@Override
public boolean create(OrderDetailsInfoEntity orderDetailsInfo) {
if (StrUtil.isBlankIfStr(orderDetailsInfo.getId())) {
orderDetailsInfo.setId(IdUtil.fastSimpleUUID());
}
return save(orderDetailsInfo);
}
/**
* 修改订单详细
*
* @param orderDetailsInfo 订单详细
* @return 结果
*/
@Override
public boolean update(OrderDetailsInfoEntity orderDetailsInfo) {
return updateById(orderDetailsInfo);
}
/**
* 批量删除订单详细
*
* @param ids 需要删除的订单详细主键
* @return 结果
*/
@Override
public int deleteOrderDetailsInfoByIds(String[] ids) {
return orderDetailsInfoMapper.deleteBatchIds(Arrays.asList(ids));
}
/**
* 删除订单详细信息
*
* @param id 订单详细主键
* @return 结果
*/
@Override
public int deleteOrderDetailsInfoById(String id) {
return orderDetailsInfoMapper.deleteById(id);
}
}

View File

@@ -0,0 +1,104 @@
package com.starry.admin.modules.order.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.order.mapper.OrderInfoMapper;
import com.starry.admin.modules.order.module.entity.OrderInfoEntity;
import com.starry.admin.modules.order.module.vo.OrderInfoQueryVo;
import com.starry.admin.modules.order.service.IOrderInfoService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
/**
* 订单Service业务层处理
*
* @author admin
* @since 2024-03-20
*/
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEntity> implements IOrderInfoService {
@Resource
private OrderInfoMapper orderInfoMapper;
/**
* 查询订单
*
* @param id 订单主键
* @return 订单
*/
@Override
public OrderInfoEntity selectOrderInfoById(String id) {
return orderInfoMapper.selectOrderInfoById(id);
}
/**
* 分页查询订单信息
*
* @param vo 订单分页查询对象
* @return 订单分页查询结果
*/
@Override
public IPage<OrderInfoEntity> selectOrderInfoList(OrderInfoQueryVo vo) {
Page<OrderInfoEntity> page = new Page<>(vo.getPageNum(), vo.getPageSize());
LambdaQueryWrapper<OrderInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
return this.baseMapper.selectPage(page, queryWrapper);
}
/**
* 新增订单
*
* @param orderInfo 订单
* @return 结果
*/
@Override
public boolean create(OrderInfoEntity orderInfo) {
if (StrUtil.isBlankIfStr(orderInfo.getId())) {
orderInfo.setId(IdUtil.fastSimpleUUID());
}
orderInfo.setPurchaserBy("sysadmin");
orderInfo.setPurchaserTime(new Date());
orderInfo.setReviewedBy("sysadmin");
orderInfo.setReviewedTime(new Date());
return save(orderInfo);
}
/**
* 修改订单
*
* @param orderInfo 订单
* @return 结果
*/
@Override
public boolean update(OrderInfoEntity orderInfo) {
return updateById(orderInfo);
}
/**
* 批量删除订单
*
* @param ids 需要删除的订单主键
* @return 结果
*/
@Override
public int deleteOrderInfoByIds(String[] ids) {
return orderInfoMapper.deleteBatchIds(Arrays.asList(ids));
}
/**
* 删除订单信息
*
* @param id 订单主键
* @return 结果
*/
@Override
public int deleteOrderInfoById(String id) {
return orderInfoMapper.deleteById(id);
}
}

View File

@@ -0,0 +1,92 @@
package com.starry.admin.modules.order.service.impl;
import java.util.Arrays;
import cn.hutool.core.util.IdUtil;
import javax.annotation.Resource;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.order.mapper.OrderLogInfoMapper;
import com.starry.admin.modules.order.module.entity.OrderLogInfoEntity;
import com.starry.admin.modules.order.service.IOrderLogInfoService;
import org.springframework.stereotype.Service;
/**
* 【请填写功能名称】Service业务层处理
*
* @author admin
* @since 2024-03-22
*/
@Service
public class OrderLogInfoServiceImpl extends ServiceImpl<OrderLogInfoMapper, OrderLogInfoEntity> implements IOrderLogInfoService {
@Resource
private OrderLogInfoMapper orderLogInfoMapper;
/**
* 查询【请填写功能名称】
* @param id 【请填写功能名称】主键
* @return 【请填写功能名称】
*/
@Override
public OrderLogInfoEntity selectOrderLogInfoById(String id) {
return this.baseMapper.selectById(id);
}
/**
* 查询【请填写功能名称】列表
* @param orderLogInfo 【请填写功能名称】
* @return 【请填写功能名称】
*/
@Override
public IPage<OrderLogInfoEntity> selectOrderLogInfoByPage(OrderLogInfoEntity orderLogInfo) {
Page<OrderLogInfoEntity> page = new Page<>(1, 10);
return this.baseMapper.selectPage(page, new LambdaQueryWrapper<OrderLogInfoEntity>());
}
/**
* 新增【请填写功能名称】
* @param orderLogInfo 【请填写功能名称】
* @return 结果
*/
@Override
public boolean create(OrderLogInfoEntity orderLogInfo) {
if (StrUtil.isBlankIfStr(orderLogInfo.getId())) {
orderLogInfo.setId(IdUtil.fastSimpleUUID());
}
return save(orderLogInfo);
}
/**
* 修改【请填写功能名称】
* @param orderLogInfo 【请填写功能名称】
* @return 结果
*/
@Override
public boolean update(OrderLogInfoEntity orderLogInfo) {
return updateById(orderLogInfo);
}
/**
* 批量删除【请填写功能名称】
* @param ids 需要删除的【请填写功能名称】主键
* @return 结果
*/
@Override
public int deleteOrderLogInfoByIds(String[] ids) {
return orderLogInfoMapper.deleteBatchIds(Arrays.asList(ids));
}
/**
* 删除【请填写功能名称】信息
* @param id 【请填写功能名称】主键
* @return 结果
*/
@Override
public int deleteOrderLogInfoById(String id) {
return orderLogInfoMapper.deleteById(id);
}
}

View File

@@ -32,7 +32,7 @@ public class SysTenantController {
/**
* 新增租户表
*/
@PreAuthorize("@customSs.hasPermi('platform:tenant:create')")
@PreAuthorize("@customSs.hasPermission('platform:tenant:create')")
@Log(title = "租户表", businessType = BusinessType.INSERT)
@PostMapping("/create")
public R create(@Valid @RequestBody SysTenantAddVo vo) {
@@ -46,7 +46,7 @@ public class SysTenantController {
/**
* 查询租户表列表
*/
@PreAuthorize("@customSs.hasPermi('platform:tenant:list')")
@PreAuthorize("@customSs.hasPermission('platform:tenant:list')")
@GetMapping("/list")
public R list(SysTenantQueryVo vo) {
return R.ok(sysTenantService.selectSysTenantList(vo));
@@ -55,7 +55,7 @@ public class SysTenantController {
/**
* 导出租户表列表
*/
@PreAuthorize("@customSs.hasPermi('platform:tenant:export')")
@PreAuthorize("@customSs.hasPermission('platform:tenant:export')")
@Log(title = "租户表", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SysTenantQueryVo sysTenantEntity) {
@@ -65,7 +65,7 @@ public class SysTenantController {
/**
* 获取租户表详细信息
*/
@PreAuthorize("@customSs.hasPermi('platform:tenant:query')")
@PreAuthorize("@customSs.hasPermission('platform:tenant:query')")
@GetMapping(value = "/{tenantId}")
public R getInfo(@PathVariable("tenantId") String tenantId) {
return R.ok(sysTenantService.selectSysTenantByTenantId(tenantId));
@@ -75,7 +75,7 @@ public class SysTenantController {
/**
* 修改租户表
*/
@PreAuthorize("@customSs.hasPermi('platform:tenant:edit')")
@PreAuthorize("@customSs.hasPermission('platform:tenant:edit')")
@Log(title = "租户表", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update/{tenantId}")
public R update(@PathVariable String tenantId, @RequestBody SysTenantEntity sysTenantEntity) {
@@ -85,7 +85,7 @@ public class SysTenantController {
/**
* 删除租户表
*/
@PreAuthorize("@customSs.hasPermi('platform:tenant:remove')")
@PreAuthorize("@customSs.hasPermission('platform:tenant:remove')")
@Log(title = "租户表", businessType = BusinessType.DELETE)
@DeleteMapping("/{tenantIds}")
public R remove(@PathVariable String[] tenantIds) {

View File

@@ -31,7 +31,7 @@ public class SysTenantPackageController {
/**
* 查询租户套餐表列表
*/
@PreAuthorize("@customSs.hasPermi('platform:package:list')")
@PreAuthorize("@customSs.hasPermission('platform:package:list')")
@GetMapping("/list")
public R list(SysTenantPackageVo sysTenantPackageEntity) {
return R.ok(SysTenantPackageService.selectSysTenantPackageList(sysTenantPackageEntity));
@@ -40,7 +40,7 @@ public class SysTenantPackageController {
/**
* 导出租户套餐表列表
*/
@PreAuthorize("@customSs.hasPermi('platform:package:export')")
@PreAuthorize("@customSs.hasPermission('platform:package:export')")
@Log(title = "租户套餐表", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SysTenantPackageVo sysTenantPackageEntity) {
@@ -50,7 +50,7 @@ public class SysTenantPackageController {
/**
* 获取租户套餐表详细信息
*/
@PreAuthorize("@customSs.hasPermi('platform:package:query')")
@PreAuthorize("@customSs.hasPermission('platform:package:query')")
@GetMapping(value = "/{packageId}")
public R getInfo(@PathVariable("packageId") String packageId) {
return R.ok(SysTenantPackageService.selectSysTenantPackageByPackageId(packageId));
@@ -59,7 +59,7 @@ public class SysTenantPackageController {
/**
* 新增租户套餐表
*/
@PreAuthorize("@customSs.hasPermi('platform:package:create')")
@PreAuthorize("@customSs.hasPermission('platform:package:create')")
@Log(title = "租户套餐表", businessType = BusinessType.INSERT)
@PostMapping("/create")
public R create(@RequestBody SysTenantPackageEntity vo) {
@@ -74,7 +74,7 @@ public class SysTenantPackageController {
/**
* 修改租户套餐表
*/
@PreAuthorize("@customSs.hasPermi('platform:package:edit')")
@PreAuthorize("@customSs.hasPermission('platform:package:edit')")
@Log(title = "租户套餐表", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update/{packageId}")
public R update(@PathVariable String packageId, @RequestBody SysTenantPackageEntity sysTenantPackageEntity) {
@@ -90,7 +90,7 @@ public class SysTenantPackageController {
/**
* 删除租户套餐表
*/
@PreAuthorize("@customSs.hasPermi('platform:package:remove')")
@PreAuthorize("@customSs.hasPermission('platform:package:remove')")
@Log(title = "租户套餐表", businessType = BusinessType.DELETE)
@DeleteMapping("/{packageIds}")
public R remove(@PathVariable String[] packageIds) {

View File

@@ -30,7 +30,7 @@ public class SysDeptController {
private SysDeptService deptService;
@ApiOperation("获取部门列表")
@PreAuthorize("@customSs.hasPermi('system:dept:list')")
@PreAuthorize("@customSs.hasPermission('system:dept:list')")
@GetMapping("/list")
public R list(SysDeptEntity dept) {
List<SysDeptEntity> depts = deptService.selectDeptList(dept);
@@ -38,7 +38,7 @@ public class SysDeptController {
}
@ApiOperation("添加部门")
@PreAuthorize("@customSs.hasPermi('system:dept:create')")
@PreAuthorize("@customSs.hasPermission('system:dept:create')")
@PostMapping("/create")
public R creat(@RequestBody SysDeptEntity dept) {
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
@@ -52,7 +52,7 @@ public class SysDeptController {
}
@ApiOperation("修改部门")
@PreAuthorize("@customSs.hasPermi('system:dept:edit')")
@PreAuthorize("@customSs.hasPermission('system:dept:edit')")
@PostMapping("/update/{id}")
public R update(@PathVariable Long id, @RequestBody SysDeptEntity dept) {
dept.setDeptId(id);
@@ -69,7 +69,7 @@ public class SysDeptController {
}
@ApiOperation("删除部门")
@PreAuthorize("@customSs.hasPermi('system:dept:delete')")
@PreAuthorize("@customSs.hasPermission('system:dept:delete')")
@PostMapping(value = "/delete/{id}")
public R delete(@PathVariable("id") Long deptId) {
if (deptService.hasChildByDeptId(deptId)) {

View File

@@ -28,7 +28,7 @@ public class SysDictController {
/**
* 查询字典表列表
*/
@PreAuthorize("@customSs.hasPermi('system:dict:list')")
@PreAuthorize("@customSs.hasPermission('system:dict:list')")
@GetMapping("/list")
public R list(SysDictVo dictVo) {
Page<SysDictEntity> list = xlDictService.selectXlDictList(dictVo);
@@ -39,7 +39,7 @@ public class SysDictController {
/**
* 获取字典表详细信息
*/
@PreAuthorize("@customSs.hasPermi('system:dict:query')")
@PreAuthorize("@customSs.hasPermission('system:dict:query')")
@GetMapping(value = "/{dictId}")
public R getInfo(@PathVariable("dictId") Long dictId) {
return R.ok(xlDictService.selectXlDictByDictId(dictId));
@@ -48,7 +48,7 @@ public class SysDictController {
/**
* 新增字典表
*/
@PreAuthorize("@customSs.hasPermi('system:dict:create')")
@PreAuthorize("@customSs.hasPermission('system:dict:create')")
@Log(title = "字典表", businessType = BusinessType.INSERT)
@PostMapping("/create")
public R create(@RequestBody SysDictEntity sysDictEntity) {
@@ -62,7 +62,7 @@ public class SysDictController {
/**
* 修改字典表
*/
@PreAuthorize("@customSs.hasPermi('system:dict:edit')")
@PreAuthorize("@customSs.hasPermission('system:dict:edit')")
@Log(title = "字典表", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update/{dictId}")
public R update(@PathVariable Long dictId, @RequestBody SysDictEntity sysDictEntity) {
@@ -77,7 +77,7 @@ public class SysDictController {
/**
* 删除字典表
*/
@PreAuthorize("@customSs.hasPermi('system:dict:remove')")
@PreAuthorize("@customSs.hasPermission('system:dict:remove')")
@Log(title = "字典表", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictIds}")
public R remove(@PathVariable Long[] dictIds) {
@@ -93,7 +93,7 @@ public class SysDictController {
/**
* 刷新字典缓存
*/
@PreAuthorize("@customSs.hasPermi('system:dict:remove')")
@PreAuthorize("@customSs.hasPermission('system:dict:remove')")
@Log(title = "字典类型", businessType = BusinessType.CLEAN)
@DeleteMapping("/refreshCache")
public R refreshCache() {

View File

@@ -29,7 +29,7 @@ public class SysDictDataController {
/**
* 查询字典数据表列表
*/
@PreAuthorize("@customSs.hasPermi('system:dict:list')")
@PreAuthorize("@customSs.hasPermission('system:dict:list')")
@GetMapping("/list")
public R list(SysDictDataVo sysDictDataEntity) {
return R.ok(xlDictDataService.selectXlDictDataList(sysDictDataEntity));
@@ -39,7 +39,7 @@ public class SysDictDataController {
/**
* 获取字典数据表详细信息
*/
@PreAuthorize("@customSs.hasPermi('system:dict:query')")
@PreAuthorize("@customSs.hasPermission('system:dict:query')")
@GetMapping(value = "/{dictDataId}")
public R getInfo(@PathVariable("dictDataId") Long dictDataId) {
return R.ok(xlDictDataService.selectXlDictDataByDictDataId(dictDataId));
@@ -48,7 +48,7 @@ public class SysDictDataController {
/**
* 新增字典数据表
*/
@PreAuthorize("@customSs.hasPermi('system:dict:create')")
@PreAuthorize("@customSs.hasPermission('system:dict:create')")
@Log(title = "字典数据表", businessType = BusinessType.INSERT)
@PostMapping("/create")
public R create(@RequestBody SysDictDataEntity sysDictDataEntity) {
@@ -62,7 +62,7 @@ public class SysDictDataController {
/**
* 修改字典数据表
*/
@PreAuthorize("@customSs.hasPermi('system:dict:edit')")
@PreAuthorize("@customSs.hasPermission('system:dict:edit')")
@Log(title = "字典数据表", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update/{dictDataId}")
public R update(@PathVariable Long dictDataId, @RequestBody SysDictDataEntity sysDictDataEntity) {
@@ -77,7 +77,7 @@ public class SysDictDataController {
/**
* 删除字典数据表
*/
@PreAuthorize("@customSs.hasPermi('system:dict:remove')")
@PreAuthorize("@customSs.hasPermission('system:dict:remove')")
@Log(title = "字典数据表", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictDataIds}")
public R remove(@PathVariable Long[] dictDataIds) {

View File

@@ -30,7 +30,7 @@ public class SysLoginLogController {
/**
* 查询系统访问日志表列表
*/
@PreAuthorize("@customSs.hasPermi('system:loginlog:list')")
@PreAuthorize("@customSs.hasPermission('system:loginlog:list')")
@GetMapping("/list")
public R list(SysLoginLogVo vo) {
IPage<SysLoginLogEntity> list = xlLoginLogService.selectXlLoginLogList(vo);
@@ -40,7 +40,7 @@ public class SysLoginLogController {
/**
* 导出系统访问日志表列表
*/
@PreAuthorize("@customSs.hasPermi('system:loginlog:export')")
@PreAuthorize("@customSs.hasPermission('system:loginlog:export')")
@Log(title = "登录日志", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SysLoginLogVo vo) {
@@ -51,7 +51,7 @@ public class SysLoginLogController {
/**
* 获取系统访问日志表详细信息
*/
@PreAuthorize("@customSs.hasPermi('system:log:query')")
@PreAuthorize("@customSs.hasPermission('system:log:query')")
@GetMapping(value = "/{loginId}")
public R getInfo(@PathVariable("loginId") Long loginId) {
return R.ok(xlLoginLogService.selectXlLoginLogByLoginId(loginId));
@@ -60,14 +60,14 @@ public class SysLoginLogController {
/**
* 删除系统访问日志表
*/
@PreAuthorize("@customSs.hasPermi('system:loginlog:remove')")
@PreAuthorize("@customSs.hasPermission('system:loginlog:remove')")
@Log(title = "登录日志", businessType = BusinessType.DELETE)
@DeleteMapping("/{loginIds}")
public R remove(@PathVariable Long[] loginIds) {
return R.ok(xlLoginLogService.deleteXlLoginLogByLoginIds(loginIds));
}
@PreAuthorize("@customSs.hasPermi('monitor:logininfor:clean')")
@PreAuthorize("@customSs.hasPermission('monitor:logininfor:clean')")
@Log(title = "登录日志", businessType = BusinessType.CLEAN)
@DeleteMapping("/clean")
public R clean() {

View File

@@ -37,7 +37,7 @@ public class SysMenuController {
@ApiOperation("获取菜单列表")
@PreAuthorize("@customSs.hasPermi('system:menu:list')")
@PreAuthorize("@customSs.hasPermission('system:menu:list')")
@GetMapping("/list")
public R list(SysMenuEntity menu) {
// 获取登录人的userId;
@@ -56,7 +56,7 @@ public class SysMenuController {
}
@ApiOperation("添加菜单")
@PreAuthorize("@customSs.hasPermi('system:menu:create')")
@PreAuthorize("@customSs.hasPermission('system:menu:create')")
@PostMapping("/create")
public R create(@RequestBody SysMenuEntity menu) {
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
@@ -72,7 +72,7 @@ public class SysMenuController {
}
@ApiOperation("修改菜单")
@PreAuthorize("@customSs.hasPermi('system:menu:edit')")
@PreAuthorize("@customSs.hasPermission('system:menu:edit')")
@PostMapping("/update/{id}")
public R update(@PathVariable Long id, @RequestBody SysMenuEntity menu) {
menu.setMenuId(id);
@@ -91,7 +91,7 @@ public class SysMenuController {
}
@ApiOperation("删除菜单")
@PreAuthorize("@customSs.hasPermi('system:menu:delete')")
@PreAuthorize("@customSs.hasPermission('system:menu:delete')")
@PostMapping(value = "/delete/{id}")
public R delete(@PathVariable("id") Long menuId) {
if (menuService.hasChildByMenuId(menuId)) {
@@ -112,7 +112,7 @@ public class SysMenuController {
return R.ok(tree);
}
@PreAuthorize("@customSs.hasPermi('system:menu:query')")
@PreAuthorize("@customSs.hasPermission('system:menu:query')")
@ApiOperation("根据菜单编号获取详细信息")
@GetMapping(value = "/{menuId}")
public R getInfo(@PathVariable Long menuId) {

View File

@@ -30,7 +30,7 @@ public class SysOperationLogController {
/**
* 查询操作日志表列表
*/
@PreAuthorize("@customSs.hasPermi('system:operlog:list')")
@PreAuthorize("@customSs.hasPermission('system:operlog:list')")
@GetMapping("/list")
public R list(SysOperationLogVo sysOperationLogEntity) {
return R.ok(xlOperLogService.selectXlOperLogList(sysOperationLogEntity));
@@ -39,7 +39,7 @@ public class SysOperationLogController {
/**
* 获取操作日志表详细信息
*/
@PreAuthorize("@customSs.hasPermi('system:operlog:query')")
@PreAuthorize("@customSs.hasPermission('system:operlog:query')")
@GetMapping(value = "/{operId}")
public R getInfo(@PathVariable("operId") Long operId) {
return R.ok(xlOperLogService.selectXlOperLogByOperId(operId));
@@ -48,7 +48,7 @@ public class SysOperationLogController {
/**
* 新增操作日志表
*/
@PreAuthorize("@customSs.hasPermi('system:operlog:create')")
@PreAuthorize("@customSs.hasPermission('system:operlog:create')")
@Log(title = "操作日志表", businessType = BusinessType.INSERT)
@PostMapping
public R create(@RequestBody SysOperationLogEntity sysOperationLogEntity) {
@@ -62,7 +62,7 @@ public class SysOperationLogController {
/**
* 修改操作日志表
*/
@PreAuthorize("@customSs.hasPermi('system:operlog:edit')")
@PreAuthorize("@customSs.hasPermission('system:operlog:edit')")
@Log(title = "操作日志表", businessType = BusinessType.UPDATE)
@PostMapping(value = "/update/{operId}")
public R update(@PathVariable Long operId, @RequestBody SysOperationLogEntity sysOperationLogEntity) {
@@ -77,7 +77,7 @@ public class SysOperationLogController {
/**
* 删除操作日志表
*/
@PreAuthorize("@customSs.hasPermi('system:operlog:remove')")
@PreAuthorize("@customSs.hasPermission('system:operlog:remove')")
@Log(title = "操作日志表", businessType = BusinessType.DELETE)
@DeleteMapping("/{operIds}")
public R remove(@PathVariable Long[] operIds) {
@@ -87,7 +87,7 @@ public class SysOperationLogController {
/**
* 导出操作日志表
*/
@PreAuthorize("@customSs.hasPermi('system:operlog:export')")
@PreAuthorize("@customSs.hasPermission('system:operlog:export')")
@Log(title = "操作日志", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SysOperationLogVo sysOperationLogEntity) {

View File

@@ -49,7 +49,7 @@ public class SysRoleController {
private SysUserService userService;
@ApiOperation("添加角色")
@PreAuthorize("@customSs.hasPermi('system:role:create')")
@PreAuthorize("@customSs.hasPermission('system:role:create')")
@PostMapping("/create")
public R create(@Valid @RequestBody SysRoleAddVo roleAddVo) {
SysRoleEntity role = new SysRoleEntity();
@@ -67,7 +67,7 @@ public class SysRoleController {
}
@ApiOperation("修改角色")
@PreAuthorize("@customSs.hasPermi('system:role:edit')")
@PreAuthorize("@customSs.hasPermission('system:role:edit')")
@PostMapping("/update/{id}")
public R update(@PathVariable Long id, @RequestBody SysRoleEntity role) {
role.setRoleId(id);
@@ -86,7 +86,7 @@ public class SysRoleController {
}
@ApiOperation("批量删除角色")
@PreAuthorize("@customSs.hasPermi('system:role:remove')")
@PreAuthorize("@customSs.hasPermission('system:role:remove')")
@DeleteMapping("/{roleIds}")
public R delete(@PathVariable Long[] roleIds) {
boolean success = roleService.delete(roleIds);
@@ -111,7 +111,7 @@ public class SysRoleController {
}
@ApiOperation("修改角色状态")
@PreAuthorize("@customSs.hasPermi('system:role:edit')")
@PreAuthorize("@customSs.hasPermission('system:role:edit')")
@PostMapping("/update-status/{id}")
public R updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status) {
SysRoleEntity role = new SysRoleEntity();
@@ -125,7 +125,7 @@ public class SysRoleController {
}
@ApiOperation("分配菜单权限")
@PreAuthorize("@customSs.hasPermi('system:role:auth')")
@PreAuthorize("@customSs.hasPermission('system:role:auth')")
@PostMapping("/auth-role-menu")
public R authRoleMenu(@RequestBody SysRoleEntity role) {
boolean success = roleService.authRoleMenu(role);
@@ -138,7 +138,7 @@ public class SysRoleController {
/**
* 根据角色编号获取详细信息
*/
@PreAuthorize("@customSs.hasPermi('system:role:query')")
@PreAuthorize("@customSs.hasPermission('system:role:query')")
@GetMapping(value = "/{roleId}")
public R getInfo(@PathVariable Long roleId) {
roleService.checkRoleDataScope(roleId);
@@ -149,7 +149,7 @@ public class SysRoleController {
* 获取对应角色部门树列表
*/
@ApiOperation("获取对应角色部门树列表")
@PreAuthorize("@customSs.hasPermi('system:role:query')")
@PreAuthorize("@customSs.hasPermission('system:role:query')")
@GetMapping(value = "/deptTree/{roleId}")
public R deptTree(@PathVariable("roleId") Long roleId) {
Map<String, Object> resultMap = new HashMap<>(8);
@@ -162,7 +162,7 @@ public class SysRoleController {
* 修改保存数据权限
*/
@ApiOperation("修改保存数据权限")
@PreAuthorize("@customSs.hasPermi('system:role:query')")
@PreAuthorize("@customSs.hasPermission('system:role:query')")
@Log(title = "角色管理-保存数据权限", businessType = BusinessType.UPDATE)
@PostMapping("/dataScope")
public R dataScope(@RequestBody SysRoleEntity role) {
@@ -175,7 +175,7 @@ public class SysRoleController {
* 查询已分配用户角色列表
*/
@ApiOperation("查询已分配用户角色列表")
@PreAuthorize("@customSs.hasPermi('system:role:list')")
@PreAuthorize("@customSs.hasPermission('system:role:list')")
@GetMapping("/authUser/allocatedList")
public R allocatedList(SysUserQueryVo user) {
IPage<RoleUserResultVo> list = userService.selectAllocatedList(user);
@@ -186,7 +186,7 @@ public class SysRoleController {
* 查询未分配用户角色列表
*/
@ApiOperation("查询未分配用户角色列表")
@PreAuthorize("@customSs.hasPermi('system:role:list')")
@PreAuthorize("@customSs.hasPermission('system:role:list')")
@GetMapping("/authUser/unallocatedList")
public R unallocatedList(SysUserQueryVo user) {
return R.ok(userService.selectUnallocatedList(user));
@@ -196,7 +196,7 @@ public class SysRoleController {
* 取消授权用户
*/
@ApiOperation("取消授权用户")
@PreAuthorize("@customSs.hasPermi('system:role:edit')")
@PreAuthorize("@customSs.hasPermission('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PutMapping("/authUser/cancel")
public R cancelAuthUser(@RequestBody SysUserRoleEntity userRole) {
@@ -207,7 +207,7 @@ public class SysRoleController {
* 批量取消授权用户
*/
@ApiOperation("批量取消授权用户")
@PreAuthorize("@customSs.hasPermi('system:role:edit')")
@PreAuthorize("@customSs.hasPermission('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PutMapping("/authUser/cancelAll")
public R cancelAuthUserAll(Long roleId, String[] userIds) {
@@ -218,7 +218,7 @@ public class SysRoleController {
* 批量选择用户授权
*/
@ApiOperation("批量选择用户授权")
@PreAuthorize("@customSs.hasPermi('system:role:edit')")
@PreAuthorize("@customSs.hasPermission('system:role:edit')")
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PutMapping("/authUser/selectAll")
public R selectAuthUserAll(Long roleId, String[] userIds) {

View File

@@ -0,0 +1,13 @@
package com.starry.admin.modules.weichat.builder;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
/**
* @author admin
*/
public abstract class AbstractBuilder {
public abstract WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage, WxMpService service);
}

View File

@@ -0,0 +1,22 @@
package com.starry.admin.modules.weichat.builder;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
/**
* @author admin
*/
public class ImageBuilder extends AbstractBuilder {
@Override
public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage,
WxMpService service) {
return WxMpXmlOutMessage.IMAGE().mediaId(content)
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
.build();
}
}

View File

@@ -0,0 +1,23 @@
package com.starry.admin.modules.weichat.builder;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage;
/**
* @author admin
*/
public class TextBuilder extends AbstractBuilder {
@Override
public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage,
WxMpService service) {
WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content(content)
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
.build();
return m;
}
}

View File

@@ -0,0 +1,25 @@
package com.starry.admin.modules.weichat.config;
/**
* @author admin
*/
public interface CommonConstants {
/**
* 是
*/
String YES = "1";
/**
* 否
*/
String NO = "0";
/**
* 树形父类ID
*/
String PARENT_ID = "0";
/**
* 编码
*/
String UTF8 = "UTF-8";
}

View File

@@ -0,0 +1,36 @@
package com.starry.admin.modules.weichat.config;
import com.starry.admin.modules.weichat.interceptor.ThirdSessionInterceptor;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* web配置
*
* @author admin
*/
@Configuration
@AllArgsConstructor
public class WebConfig implements WebMvcConfigurer {
/**
* 拦截器
*
* @param registry InterceptorRegistry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
/*
进入ThirdSession拦截器
*/
registry.addInterceptor(new ThirdSessionInterceptor())
// 拦截/api/**接口
.addPathPatterns("/weixin/api/**")
// 放行接口
.excludePathPatterns("/weixin/api/ma/wxuser/login",
"/weixin/api/ma/orderinfo/notify-order", "/weixin/api/ma/orderinfo/notify-logisticsr",
"/weixin/api/ma/orderinfo/notify-refunds");
}
}

View File

@@ -0,0 +1,111 @@
package com.starry.admin.modules.weichat.config;
import cn.hutool.core.util.StrUtil;
import com.starry.admin.modules.weichat.entity.CustomWxMpProperties;
import com.starry.admin.modules.weichat.handler.*;
import com.starry.admin.modules.weichat.utils.WxMpPropertiesUtils;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
import static me.chanjar.weixin.common.api.WxConsts.EventType.SUBSCRIBE;
import static me.chanjar.weixin.common.api.WxConsts.EventType.UNSUBSCRIBE;
import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType.EVENT;
import static me.chanjar.weixin.mp.constant.WxMpEventConstants.CustomerService.*;
import static me.chanjar.weixin.mp.constant.WxMpEventConstants.POI_CHECK_NOTIFY;
/**
* wechat mp configuration
*
* @author admin
*/
@AllArgsConstructor
@Configuration
public class WxMpConfiguration {
private final LogHandler logHandler;
private final NullHandler nullHandler;
private final KfSessionHandler kfSessionHandler;
private final StoreCheckNotifyHandler storeCheckNotifyHandler;
private final LocationHandler locationHandler;
private final MenuHandler menuHandler;
private final MsgHandler msgHandler;
private final UnsubscribeHandler unsubscribeHandler;
private final SubscribeHandler subscribeHandler;
private final ScanHandler scanHandler;
@Bean
public WxMpService wxMpService() {
CustomWxMpProperties customWxMpProperties = WxMpPropertiesUtils.getWeiChatProperties();
if (StrUtil.isBlankIfStr(customWxMpProperties.getAppid()) || StrUtil.isBlankIfStr(customWxMpProperties.getAppid()) || StrUtil.isBlankIfStr(customWxMpProperties.getAppid()) || StrUtil.isBlankIfStr(customWxMpProperties.getAppid())) {
throw new RuntimeException("微信配置文件出错");
}
return getWxMpService(customWxMpProperties);
}
private static WxMpService getWxMpService(CustomWxMpProperties customWxMpProperties) {
Map<String, WxMpConfigStorage> multiConfigStorages = new HashMap<>(16);
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
configStorage.setAppId(customWxMpProperties.getAppid());
configStorage.setSecret(customWxMpProperties.getSecret());
configStorage.setToken(customWxMpProperties.getToken());
configStorage.setAesKey(customWxMpProperties.getAesKey());
WxMpService mpService = new WxMpServiceImpl();
mpService.setMultiConfigStorages(multiConfigStorages);
return mpService;
}
@Bean
public WxMpMessageRouter messageRouter(WxMpService wxMpService) {
final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService);
// 记录所有事件的日志 (异步执行)
newRouter.rule().handler(this.logHandler).next();
// 接收客服会话管理事件
newRouter.rule().async(false).msgType(EVENT).event(KF_CREATE_SESSION).handler(this.kfSessionHandler).end();
newRouter.rule().async(false).msgType(EVENT).event(KF_CLOSE_SESSION).handler(this.kfSessionHandler).end();
newRouter.rule().async(false).msgType(EVENT).event(KF_SWITCH_SESSION).handler(this.kfSessionHandler).end();
// 门店审核事件
newRouter.rule().async(false).msgType(EVENT).event(POI_CHECK_NOTIFY).handler(this.storeCheckNotifyHandler).end();
// 自定义菜单事件
newRouter.rule().async(false).msgType(EVENT).event(WxConsts.EventType.CLICK).handler(this.menuHandler).end();
// 点击菜单连接事件
newRouter.rule().async(false).msgType(EVENT).event(WxConsts.EventType.VIEW).handler(this.nullHandler).end();
// 关注事件
newRouter.rule().async(false).msgType(EVENT).event(SUBSCRIBE).handler(this.subscribeHandler).end();
// 取消关注事件
newRouter.rule().async(false).msgType(EVENT).event(UNSUBSCRIBE).handler(this.unsubscribeHandler).end();
// 上报地理位置事件
newRouter.rule().async(false).msgType(EVENT).event(WxConsts.EventType.LOCATION).handler(this.locationHandler).end();
// 接收地理位置消息
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.LOCATION).handler(this.locationHandler).end();
// 扫码事件
newRouter.rule().async(false).msgType(EVENT).event(WxConsts.EventType.SCAN).handler(this.scanHandler).end();
// 默认
newRouter.rule().async(false).handler(this.msgHandler).end();
return newRouter;
}
}

View File

@@ -0,0 +1,85 @@
package com.starry.admin.modules.weichat.constant;
/**
* 全局常量
*
* @author admin
* 2019年1月21日
*/
public interface ConfigConstant {
// 订阅状态0已订阅1未订阅2网页授权用户
/**
* 0未订阅取消订阅
*/
String SUBSCRIBE_TYPE_NO = "0";
/**
* 1已订阅
*/
String SUBSCRIBE_TYPE_YES = "1";
/**
* 2网页授权用户
*/
String SUBSCRIBE_TYPE_WEBLIEN = "2";
/**
* 应用类型 1:小程序
*/
String WX_APP_TYPE_1 = "1";
/**
* 应用类型 2:公众号
*/
String WX_APP_TYPE_2 = "2";
/**
* 消息自动回复类型1、关注时回复2、消息回复3、关键词回复
*/
String WX_AUTO_REPLY_TYPE_1 = "1";
String WX_AUTO_REPLY_TYPE_2 = "2";
String WX_AUTO_REPLY_TYPE_3 = "3";
/**
* 回复类型文本匹配类型1、全匹配2、半匹配
*/
String WX_REP_MATE_1 = "1";
String WX_REP_MATE_2 = "2";
/**
* 消息分类1、用户发给公众号2、公众号发给用户
*/
String WX_MSG_TYPE_1 = "1";
String WX_MSG_TYPE_2 = "2";
/**
* 群发消息发送类型1、分组发2、选择用户发
*/
String WX_MASS_SEND_TYPE_1 = "1";
String WX_MASS_SEND_TYPE_2 = "2";
/**
* 群发消息发送后的状态(SUB_SUCCESS提交成功SUB_FAIL提交失败SEND_SUCCESS发送成功SENDING发送中SEND_FAIL发送失败DELETE已删除)
*/
String WX_MASS_STATUS_SUB_SUCCESS = "SUB_SUCCESS";
String WX_MASS_STATUS_SUB_FAIL = "SUB_FAIL";
String WX_MASS_STATUS_SEND_SUCCESS = "SEND_SUCCESS";
String WX_MASS_STATUS_SENDING = "SENDING";
String WX_MASS_STATUS_SEND_FAIL = "SEND_FAIL";
String WX_MASS_STATUS_DELETE = "DELETE";
/**
* 菜单类型(1:普通菜单2:个性化菜单)
*/
String WX_MENU_TYPE_1 = "1";
String WX_MENU_TYPE_2 = "2";
/**
* header中的app-id
*/
String HEADER_APP_ID = "app-id";
/**
* header中的third-session
*/
String HEADER_THIRDSESSION = "third-session";
}

View File

@@ -0,0 +1,57 @@
package com.starry.admin.modules.weichat.constant;
/**
* 全局返回码
* 小程序用6开头例60001
*
* @author admin
* 2019年7月25日
*/
public enum MyReturnCode {
// 其它错误
ERR_60000(60000, "系统错误,请稍候再试") {},
ERR_60001(60001, "登录超时,请重新登录") {},
ERR_60002(60002, "session不能为空") {},
ERR_70001(70001, "该状态订单不允许操作") {},
ERR_70002(70002, "请选择付款方式") {},
ERR_70003(70003, "没有符合下单条件的规格商品,商品已下架或库存不足") {},
ERR_70004(70004, "只有未支付的详单能发起支付") {},
ERR_70005(70005, "无效订单") {},
ERR_80004(80004, "该商品已删除") {},
;
private int code;
private String msg;
MyReturnCode(int code, String msg) {
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
@Override
public String toString() {
return "MyReturnCode{" + "code='" + code + '\'' + "msg='" + msg + '\'' + '}';
}
}

View File

@@ -0,0 +1,12 @@
package com.starry.admin.modules.weichat.constant;
/**
* @author admin
*/
public interface WebSocketConstant {
String USER_DESTINATION_PREFIX = "/weixin/";
String WX_MSG = "wx_msg";
}

View File

@@ -0,0 +1,17 @@
package com.starry.admin.modules.weichat.constant;
/**
* @author admin
*/
public interface WxMaConstants {
/**
* redis中3rd_session过期时间(单位:小时)
*/
long TIME_OUT_SESSION = 6;
/**
* redis中3rd_session拼接前缀
*/
String THIRD_SESSION_BEGIN = "wx:ma:3rd_session";
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,127 @@
package com.starry.admin.modules.weichat.controller;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.starry.admin.modules.weichat.constant.ConfigConstant;
import com.starry.admin.modules.weichat.entity.WxAutoReply;
import com.starry.admin.modules.weichat.service.WxAutoReplyService;
import com.starry.common.result.R;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 消息自动回复
*
* @author admin
* @since 2019-04-18 15:40:39
*/
@RestController
@AllArgsConstructor
@RequestMapping("/wxautoreply")
public class WxAutoReplyController {
@Resource
WxAutoReplyService wxAutoReplyService;
/**
* 分页查询
* @param page 分页对象
* @param wxAutoReply 消息自动回复
* @return
*/
@GetMapping("/page")
@PreAuthorize("@customSs.hasPermission('wxmp:wxautoreply:index')")
public R getWxAutoReplyPage(Page page, WxAutoReply wxAutoReply) {
return R.ok(wxAutoReplyService.page(page,Wrappers.query(wxAutoReply)));
}
/**
* 通过id查询消息自动回复
* @param id id
* @return R
*/
@GetMapping("/{id}")
@PreAuthorize("@customSs.hasPermission('wxmp:wxautoreply:get')")
public R getById(@PathVariable("id") String id){
return R.ok(wxAutoReplyService.getById(id));
}
/**
* 新增消息自动回复
* @param wxAutoReply 消息自动回复
* @return R
*/
@PostMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxautoreply:add')")
public R save(@RequestBody WxAutoReply wxAutoReply){
this.jude(wxAutoReply);
return R.ok(wxAutoReplyService.save(wxAutoReply));
}
/**
* 修改消息自动回复
* @param wxAutoReply 消息自动回复
* @return R
*/
@PutMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxautoreply:edit')")
public R updateById(@RequestBody WxAutoReply wxAutoReply){
this.jude(wxAutoReply);
return R.ok(wxAutoReplyService.updateById(wxAutoReply));
}
/**
* 通过id删除消息自动回复
* @param id id
* @return R
*/
@DeleteMapping("/{id}")
@PreAuthorize("@customSs.hasPermission('wxmp:wxautoreply:del')")
public R removeById(@PathVariable String id){
return R.ok(wxAutoReplyService.removeById(id));
}
/**
* //校验参数
* @param wxAutoReply
*/
public void jude(WxAutoReply wxAutoReply){
if(ConfigConstant.WX_AUTO_REPLY_TYPE_2.equals(wxAutoReply.getType())){
Wrapper<WxAutoReply> queryWrapper = Wrappers.<WxAutoReply>lambdaQuery()
.eq(WxAutoReply::getReqType,wxAutoReply.getReqType());
List<WxAutoReply> list = wxAutoReplyService.list(queryWrapper);
if(StringUtils.isNotBlank(wxAutoReply.getId())){
if(list != null && list.size() == 1){
if(!list.get(0).getId().equals(wxAutoReply.getId())){
throw new RuntimeException("请求消息类型重复");
}
}
if(list != null && list.size()>1){
throw new RuntimeException("请求消息类型重复");
}
}
}
if(ConfigConstant.WX_AUTO_REPLY_TYPE_3.equals(wxAutoReply.getType())){
Wrapper<WxAutoReply> queryWrapper = Wrappers.<WxAutoReply>lambdaQuery()
.eq(WxAutoReply::getReqKey,wxAutoReply.getReqKey())
.eq(WxAutoReply::getRepType,wxAutoReply.getRepMate());
List<WxAutoReply> list = wxAutoReplyService.list(queryWrapper);
if(list != null && list.size() == 1){
if(!list.get(0).getId().equals(wxAutoReply.getId())){
throw new RuntimeException("关键词重复");
}
}
if(list != null && list.size()>1){
throw new RuntimeException("关键词重复");
}
}
}
}

View File

@@ -0,0 +1,129 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.starry.common.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpDraftService;
import me.chanjar.weixin.mp.api.WxMpFreePublishService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.draft.WxMpAddDraft;
import me.chanjar.weixin.mp.bean.draft.WxMpDraftArticles;
import me.chanjar.weixin.mp.bean.draft.WxMpUpdateDraft;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 微信草稿箱
*
* @author admin
* @since 2022-03-10 21:26:35
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxdraft")
@Api(value = "wxdraft", tags = "微信草稿箱")
public class WxDraftController {
@Resource
WxMpService wxService;
/**
* 新增图文消息
*
* @param data
* @return
*/
@ApiOperation(value = "新增草稿箱")
@PostMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxdraft:add')")
public R add(@RequestBody JSONObject data) throws Exception {
JSONArray jSONArray = data.getJSONArray("articles");
List<WxMpDraftArticles> articles = jSONArray.toList(WxMpDraftArticles.class);
WxMpAddDraft wxMpAddDraft = new WxMpAddDraft();
wxMpAddDraft.setArticles(articles);
WxMpDraftService wxMpDraftService = wxService.getDraftService();
String rs = wxMpDraftService.addDraft(wxMpAddDraft);
return R.ok(rs);
}
/**
* 修改微信草稿箱
*
* @param data
* @return
*/
@ApiOperation(value = "修改微信草稿箱")
@PutMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxdraft:edit')")
public R edit(@RequestBody JSONObject data) throws Exception {
String mediaId = data.getStr("mediaId");
JSONArray jSONArray = data.getJSONArray("articles");
List<WxMpDraftArticles> articles = jSONArray.toList(WxMpDraftArticles.class);
WxMpDraftService wxMpDraftService = wxService.getDraftService();
WxMpUpdateDraft wxMpUpdateDraft = new WxMpUpdateDraft();
wxMpUpdateDraft.setMediaId(mediaId);
int index = 0;
for (WxMpDraftArticles article : articles) {
wxMpUpdateDraft.setIndex(index);
wxMpUpdateDraft.setArticles(article);
wxMpDraftService.updateDraft(wxMpUpdateDraft);
index++;
}
return R.ok();
}
/**
* 通过id删除微信草稿箱
*
* @param
* @return R
*/
@ApiOperation(value = "通过id删除微信草稿箱")
@DeleteMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxdraft:del')")
public R del(String id) throws Exception {
WxMpDraftService wxMpDraftService = wxService.getDraftService();
return R.ok(wxMpDraftService.delDraft(id));
}
/**
* 分页查询
*
* @param page 分页对象
* @param
* @return
*/
@ApiOperation(value = "分页查询")
@GetMapping("/page")
@PreAuthorize("@customSs.hasPermission('wxmp:wxdraft:index')")
public R getPage(Page page) throws Exception {
WxMpDraftService wxMpDraftService = wxService.getDraftService();
int count = (int) page.getSize();
int offset = (int) page.getCurrent() * count - count;
return R.ok(wxMpDraftService.listDraft(offset, count));
}
/**
* 发布草稿箱
* @param id
* @return
*/
@ApiOperation(value = "发布草稿箱")
@PostMapping("/publish/{id}")
@PreAuthorize("@customSs.hasPermission('wxmp:wxdraft:publish')")
public R publish(@PathVariable String id) throws Exception {
WxMpFreePublishService wxMpFreePublishService = wxService.getFreePublishService();
wxMpFreePublishService.submit(id);
return R.ok();
}
}

View File

@@ -0,0 +1,67 @@
package com.starry.admin.modules.weichat.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.starry.common.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpFreePublishService;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 微信发布
*
* @author admin
* @since 2022-03-10 21:26:35
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/freepublish")
@Api(value = "freepublish", tags = "微信发布")
public class WxFreePublishController {
@Resource
WxMpService wxService;
/**
* 删除发布
*
* @param
* @return R
*/
@ApiOperation(value = "删除发布")
@DeleteMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxfreepublish:del')")
public R del(String id) throws Exception {
WxMpFreePublishService wxMpFreePublishService = wxService.getFreePublishService();
return R.ok(wxMpFreePublishService.deletePushAllArticle(id));
}
/**
* 获取成功发布列表
*
* @param page 获取成功发布列表
* @param
* @return
*/
@ApiOperation(value = "获取成功发布列表")
@GetMapping("/page")
@PreAuthorize("@customSs.hasPermission('wxmp:wxfreepublish:index')")
public R getPage(Page page) throws Exception {
WxMpFreePublishService wxMpFreePublishService = wxService.getFreePublishService();
int count = (int) page.getSize();
int offset = (int) page.getCurrent() * count - count;
return R.ok(wxMpFreePublishService.getPublicationRecords(offset, count));
}
}

View File

@@ -0,0 +1,239 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.starry.admin.modules.weichat.entity.ImageManager;
import com.starry.admin.modules.weichat.utils.FileUtils;
import com.starry.common.result.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpMaterialService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult;
import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialFileBatchGetResult;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 微信素材
*
* @author admin
* @since 2019-03-23 21:26:35
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxmaterial")
public class WxMaterialController {
@Resource
WxMpService wxService;
/**
* 上传非图文微信素材
* @param mulFile
* @param mediaType
* @return
*/
@PostMapping("/materialFileUpload")
// @PreAuthorize("@customSs.hasPermission('wxmp:wxmaterial:add')")
public R materialFileUpload(@RequestParam("file") MultipartFile mulFile,
@RequestParam("title") String title,
@RequestParam("introduction") String introduction,
@RequestParam("mediaType") String mediaType) {
try {
WxMpMaterial material = new WxMpMaterial();
material.setName(mulFile.getOriginalFilename());
if(WxConsts.MediaFileType.VIDEO.equals(mediaType)){
material.setVideoTitle(title);
material.setVideoIntroduction(introduction);
}
File file = FileUtils.multipartFileToFile(mulFile);
material.setFile(file);
WxMpMaterialService wxMpMaterialService = wxService.getMaterialService();
WxMpMaterialUploadResult wxMpMaterialUploadResult = wxMpMaterialService.materialFileUpload(mediaType,material);
WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem wxMpMaterialFileBatchGetResult = new WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem();
wxMpMaterialFileBatchGetResult.setName(file.getName());
wxMpMaterialFileBatchGetResult.setMediaId(wxMpMaterialUploadResult.getMediaId());
wxMpMaterialFileBatchGetResult.setUrl(wxMpMaterialUploadResult.getUrl());
return R.ok(wxMpMaterialFileBatchGetResult);
} catch (WxErrorException e) {
log.error("上传非图文微信素材失败" + e);
return R.error(e.getMessage());
} catch (Exception e) {
log.error("上传失败", e);
return R.error(e.getLocalizedMessage());
}
}
/**
* 上传图文消息内的图片获取URL
* @param mulFile
* @return
*/
@PostMapping("/newsImgUpload")
// @PreAuthorize("@customSs.hasPermission('wxmp:wxmaterial:add')")
public String newsImgUpload(@RequestParam("file") MultipartFile mulFile) throws Exception {
File file = FileUtils.multipartFileToFile(mulFile);
WxMpMaterialService wxMpMaterialService = wxService.getMaterialService();
WxMediaImgUploadResult wxMediaImgUploadResult = wxMpMaterialService.mediaImgUpload(file);
Map<Object, Object> responseData = new HashMap<>();
responseData.put("link", wxMediaImgUploadResult.getUrl());
return JSONUtil.toJsonStr(responseData);
}
/**
* 通过id删除微信素材
* @param
* @return R
*/
@DeleteMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxmaterial:del')")
public R materialDel(String id){
WxMpMaterialService wxMpMaterialService = wxService.getMaterialService();
try {
return R.ok(wxMpMaterialService.materialDelete(id));
} catch (WxErrorException e) {
log.error("删除微信素材失败", e);
return R.error(e.getMessage());
}
}
/**
* 分页查询
* @param page 分页对象
* @param type
* @return
*/
@GetMapping("/page")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmaterial:index')")
public R getWxMaterialPage(Page page, String type) {
try {
WxMpMaterialService wxMpMaterialService = wxService.getMaterialService();
int count = (int)page.getSize();
int offset = (int)page.getCurrent()*count-count;
if(WxConsts.MaterialType.NEWS.equals(type)){
return R.ok(wxMpMaterialService.materialNewsBatchGet(offset,count));
}else{
return R.ok(wxMpMaterialService.materialFileBatchGet(type,offset,count));
}
} catch (WxErrorException e) {
log.error("查询素材失败", e);
return R.error(e.getMessage());
}
}
/**
* 分页查询2
* @param type
* @return
*/
@GetMapping("/page-manager")
// @PreAuthorize("@customSs.hasPermission('wxmp:wxmaterial:index')")
public String getWxMaterialPageManager(Integer count, Integer offset, String type) throws WxErrorException {
List<ImageManager> listImageManager = new ArrayList<>();
WxMpMaterialService wxMpMaterialService = wxService.getMaterialService();
List<WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem> list = wxMpMaterialService.materialFileBatchGet(type,offset,count).getItems();
list.forEach(wxMaterialFileBatchGetNewsItem -> {
ImageManager imageManager = new ImageManager();
imageManager.setName(wxMaterialFileBatchGetNewsItem.getMediaId());
imageManager.setUrl(wxMaterialFileBatchGetNewsItem.getUrl());
imageManager.setThumb(wxMaterialFileBatchGetNewsItem.getUrl());
listImageManager.add(imageManager);
});
return JSONUtil.toJsonStr(listImageManager);
}
/**
* 获取微信视频素材
* @param
* @return R
*/
@GetMapping("/materialVideo")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmaterial:get')")
public R getMaterialVideo(String mediaId){
WxMpMaterialService wxMpMaterialService = wxService.getMaterialService();
try {
return R.ok(wxMpMaterialService.materialVideoInfo(mediaId));
} catch (WxErrorException e) {
log.error("获取微信视频素材失败", e);
return R.error(e.getMessage());
}
}
/**
* 获取微信素材直接文件
* @param
* @return R
*/
@GetMapping("/materialOther")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmaterial:get')")
public ResponseEntity<byte[]> getMaterialOther(String mediaId, String fileName) throws Exception {
try {
WxMpMaterialService wxMpMaterialService = wxService.getMaterialService();
//获取文件
InputStream is = wxMpMaterialService.materialImageOrVoiceDownload(mediaId);
byte[] body = new byte[is.available()];
is.read(body);
HttpHeaders headers = new HttpHeaders();
//设置文件类型
headers.add("Content-Disposition", "attchement;filename=" + URLEncoder.encode(fileName, "UTF-8"));
headers.add("Content-Type", "application/octet-stream");
HttpStatus statusCode = HttpStatus.OK;
//返回数据
return new ResponseEntity<>(body, headers, statusCode);
} catch (WxErrorException e) {
log.error("获取微信素材直接文件失败", e);
return null;
}
}
/**
* 获取微信临时素材直接文件
* @param
* @return R
*/
@GetMapping("/tempMaterialOther")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmsg:index')")
public ResponseEntity<byte[]> getTempMaterialOther(String mediaId, String fileName) throws Exception {
WxMpMaterialService wxMpMaterialService = wxService.getMaterialService();
try (InputStream is = Files.newInputStream(wxMpMaterialService.mediaDownload(mediaId).toPath())){
byte[] body = new byte[is.available()];
is.read(body);
HttpHeaders headers = new HttpHeaders();
//设置文件类型
headers.add("Content-Disposition", "attchement;filename=" + URLEncoder.encode(fileName, "UTF-8"));
headers.add("Content-Type", "application/octet-stream");
HttpStatus statusCode = HttpStatus.OK;
//返回数据
return new ResponseEntity<>(body, headers, statusCode);
} catch (WxErrorException e) {
log.error("获取微信素材直接文件失败", e);
return null;
}
}
}

View File

@@ -0,0 +1,64 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.starry.admin.modules.weichat.service.WxMenuService;
import com.starry.common.result.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* 自定义菜单
*
* @author admin
* @since 2019-03-27 16:52:10
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxmenu")
public class WxMenuController {
@Resource
WxMenuService wxMenuService;
/**
* 通过appId查询自定义菜单
*
* @return R
*/
@GetMapping("/list")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmenu:get')")
public R getWxMenuButton() {
return R.ok(wxMenuService.getWxMenuButton());
}
/**
* 保存并发布菜单
*
* @param
* @return R
*/
@PostMapping("/release")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmenu:add')")
public R saveAndRelease(@RequestBody String data) {
JSONObject jSONObject = JSONUtil.parseObj(data);
String strWxMenu = jSONObject.getStr("strWxMenu");
String appId = jSONObject.getStr("appId");
try {
wxMenuService.saveAndRelease(strWxMenu);
return R.ok();
} catch (WxErrorException e) {
log.error("发布自定义菜单失败appID:" + appId + ":" + e.getMessage());
return R.error(e.getMessage());
}
}
}

View File

@@ -0,0 +1,210 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.starry.admin.modules.weichat.config.CommonConstants;
import com.starry.admin.modules.weichat.constant.ConfigConstant;
import com.starry.admin.modules.weichat.entity.WxMsg;
import com.starry.admin.modules.weichat.entity.WxMsgVO;
import com.starry.admin.modules.weichat.entity.WxUser;
import com.starry.admin.modules.weichat.service.WxMsgService;
import com.starry.admin.modules.weichat.service.WxUserService;
import com.starry.common.result.R;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpKefuService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
* 微信消息
*
* @author admin
* @since 2019-05-28 16:12:10
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxmsg")
@Api(value = "wxmsg", tags = "wxmsg管理")
public class WxMsgController {
@Resource
WxMsgService wxMsgService;
@Resource
WxUserService wxUserService;
@Resource
WxMpService wxService;
/**
* 分页查询
*
* @param page 分页对象
* @param wxMsgVO 微信消息
* @return
*/
@GetMapping("/page")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmsg:index')")
public R getWxMsgPage(Page<WxMsg> page, WxMsgVO wxMsgVO) {
if (StringUtils.isNotBlank(wxMsgVO.getNotInRepType())) {
return R.ok(wxMsgService.listWxMsgMapGroup(page, wxMsgVO));
}
//标记为已读
if (StringUtils.isNotBlank(wxMsgVO.getWxUserId())) {
WxMsg wxMsg = new WxMsg();
wxMsg.setReadFlag(CommonConstants.YES);
Wrapper<WxMsg> queryWrapper = Wrappers.<WxMsg>lambdaQuery().eq(WxMsg::getWxUserId, wxMsgVO.getWxUserId()).eq(WxMsg::getReadFlag, CommonConstants.NO);
wxMsgService.update(wxMsg, queryWrapper);
}
return R.ok(wxMsgService.page(page, Wrappers.query(wxMsgVO)));
}
/**
* 通过id查询微信消息
*
* @param id id
* @return R
*/
@GetMapping("/{id}")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmsg:get')")
public R getById(@PathVariable("id") String id) {
return R.ok(wxMsgService.getById(id));
}
/**
* 新增微信消息
*
* @param wxMsg 微信消息
* @return R
*/
@PostMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxmsg:add')")
public R save(@RequestBody WxMsg wxMsg) {
try {
WxUser wxUser = wxUserService.getById(wxMsg.getWxUserId());
//入库
wxMsg.setNickName(wxUser.getNickName());
wxMsg.setHeadimgUrl(wxUser.getHeadimgUrl());
wxMsg.setCreateTime(LocalDateTime.now());
wxMsg.setType(ConfigConstant.WX_MSG_TYPE_2);
WxMpKefuMessage wxMpKefuMessage = null;
if (WxConsts.KefuMsgType.TEXT.equals(wxMsg.getRepType())) {
wxMsg.setRepContent(wxMsg.getRepContent());
wxMpKefuMessage = WxMpKefuMessage.TEXT().build();
wxMpKefuMessage.setContent(wxMsg.getRepContent());
}
if (WxConsts.KefuMsgType.IMAGE.equals(wxMsg.getRepType())) {//图片
wxMsg.setRepName(wxMsg.getRepName());
wxMsg.setRepUrl(wxMsg.getRepUrl());
wxMsg.setRepMediaId(wxMsg.getRepMediaId());
wxMpKefuMessage = WxMpKefuMessage.IMAGE().build();
wxMpKefuMessage.setMediaId(wxMsg.getRepMediaId());
}
if (WxConsts.KefuMsgType.VOICE.equals(wxMsg.getRepType())) {
wxMsg.setRepName(wxMsg.getRepName());
wxMsg.setRepUrl(wxMsg.getRepUrl());
wxMsg.setRepMediaId(wxMsg.getRepMediaId());
wxMpKefuMessage = WxMpKefuMessage.VOICE().build();
wxMpKefuMessage.setMediaId(wxMsg.getRepMediaId());
}
if (WxConsts.KefuMsgType.VIDEO.equals(wxMsg.getRepType())) {
wxMsg.setRepName(wxMsg.getRepName());
wxMsg.setRepDesc(wxMsg.getRepDesc());
wxMsg.setRepUrl(wxMsg.getRepUrl());
wxMsg.setRepMediaId(wxMsg.getRepMediaId());
wxMpKefuMessage = WxMpKefuMessage.VIDEO().build();
wxMpKefuMessage.setMediaId(wxMsg.getRepMediaId());
wxMpKefuMessage.setTitle(wxMsg.getRepName());
wxMpKefuMessage.setDescription(wxMsg.getRepDesc());
}
if (WxConsts.KefuMsgType.MUSIC.equals(wxMsg.getRepType())) {
wxMsg.setRepName(wxMsg.getRepName());
wxMsg.setRepDesc(wxMsg.getRepDesc());
wxMsg.setRepUrl(wxMsg.getRepUrl());
wxMsg.setRepHqUrl(wxMsg.getRepHqUrl());
wxMpKefuMessage = WxMpKefuMessage.MUSIC().build();
wxMpKefuMessage.setTitle(wxMsg.getRepName());
wxMpKefuMessage.setDescription(wxMsg.getRepDesc());
wxMpKefuMessage.setMusicUrl(wxMsg.getRepUrl());
wxMpKefuMessage.setHqMusicUrl(wxMsg.getRepHqUrl());
wxMpKefuMessage.setThumbMediaId(wxMsg.getRepThumbMediaId());
}
if (WxConsts.KefuMsgType.NEWS.equals(wxMsg.getRepType())) {
List<WxMpKefuMessage.WxArticle> list = new ArrayList<>();
JSONArray jSONArray = wxMsg.getContent().getJSONArray("articles");
WxMpKefuMessage.WxArticle t;
for (Object object : jSONArray) {
JSONObject jSONObject = JSONUtil.parseObj(JSONUtil.toJsonStr(object));
t = new WxMpKefuMessage.WxArticle();
t.setTitle(jSONObject.getStr("title"));
t.setDescription(jSONObject.getStr("digest"));
t.setPicUrl(jSONObject.getStr("thumbUrl"));
t.setUrl(jSONObject.getStr("url"));
list.add(t);
}
wxMsg.setRepName(wxMsg.getRepName());
wxMsg.setRepDesc(wxMsg.getRepDesc());
wxMsg.setRepUrl(wxMsg.getRepUrl());
wxMsg.setRepMediaId(wxMsg.getRepMediaId());
wxMsg.setContent(wxMsg.getContent());
wxMpKefuMessage = WxMpKefuMessage.NEWS().build();
wxMpKefuMessage.setArticles(list);
}
if (wxMpKefuMessage != null) {
WxMpKefuService wxMpKefuService = wxService.getKefuService();
wxMpKefuMessage.setToUser(wxUser.getOpenId());
wxMpKefuService.sendKefuMessage(wxMpKefuMessage);
wxMsgService.save(wxMsg);
return R.ok(wxMsg);
} else {
return R.error("非法消息类型");
}
} catch (WxErrorException e) {
log.error("新增微信消息失败" + e.getMessage());
return R.error(e.getMessage());
}
}
/**
* 修改微信消息
*
* @param wxMsg 微信消息
* @return R
*/
@PutMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxmsg:edit')")
public R updateById(@RequestBody WxMsg wxMsg) {
return R.ok(wxMsgService.updateById(wxMsg));
}
/**
* 通过id删除微信消息
*
* @param id id
* @return R
*/
@DeleteMapping("/{id}")
@PreAuthorize("@customSs.hasPermission('wxmp:wxmsg:del')")
public R removeById(@PathVariable String id) {
return R.ok(wxMsgService.removeById(id));
}
}

View File

@@ -0,0 +1,112 @@
package com.starry.admin.modules.weichat.controller;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @author admin
*/
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/weixin/portal/{appid}")
public class WxPortalController {
@Resource
private final WxMpService wxService;
@Resource
private final WxMpMessageRouter messageRouter;
@GetMapping(produces = "text/plain;charset=utf-8")
public String authGet(@PathVariable String appid,
@RequestParam(name = "signature", required = false) String signature,
@RequestParam(name = "timestamp", required = false) String timestamp,
@RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr) {
log.info("\n接收到来自微信服务器的认证消息[{}, {}, {}, {}]", signature,
timestamp, nonce, echostr);
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
throw new IllegalArgumentException("请求参数非法,请核实!");
}
if (!this.wxService.switchover(appid)) {
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
}
if (wxService.checkSignature(timestamp, nonce, signature)) {
return echostr;
}
return "非法请求";
}
@PostMapping(produces = "application/xml; charset=UTF-8")
public String post(@PathVariable String appid,
@RequestBody String requestBody,
@RequestParam("signature") String signature,
@RequestParam("timestamp") String timestamp,
@RequestParam("nonce") String nonce,
@RequestParam("openid") String openid,
@RequestParam(name = "encrypt_type", required = false) String encType,
@RequestParam(name = "msg_signature", required = false) String msgSignature) {
log.info("\n接收微信请求[openid=[{}], [signature=[{}], encType=[{}], msgSignature=[{}],"
+ " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ",
openid, signature, encType, msgSignature, timestamp, nonce, requestBody);
if (!this.wxService.switchover(appid)) {
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
}
if (!wxService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
}
String out = null;
if (encType == null) {
// 明文传输的消息
WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);
WxMpXmlOutMessage outMessage = this.route(inMessage);
if (outMessage == null) {
return "";
}
out = outMessage.toXml();
} else if ("aes".equalsIgnoreCase(encType)) {
// aes加密的消息
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxService.getWxMpConfigStorage(),
timestamp, nonce, msgSignature);
log.debug("\n消息解密后内容为\n{} ", inMessage.toString());
WxMpXmlOutMessage outMessage = this.route(inMessage);
if (outMessage == null) {
return "";
}
out = outMessage.toEncryptedXml(wxService.getWxMpConfigStorage());
}
log.debug("\n组装回复信息{}", out);
return out;
}
private WxMpXmlOutMessage route(WxMpXmlMessage message) {
try {
return this.messageRouter.route(message);
} catch (Exception e) {
log.error("路由消息时出现异常!", e);
}
return null;
}
}

View File

@@ -0,0 +1,109 @@
package com.starry.admin.modules.weichat.controller;
import com.starry.common.result.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpDataCubeService;
import me.chanjar.weixin.mp.api.WxMpService;
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.text.SimpleDateFormat;
/**
* 微信账号配置
*
* @author admin
* @since 2019-03-23 21:26:35
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxsummary")
public class WxSummaryController {
@Resource
WxMpService wxService;
/**
* 获取用户增减数据
*
* @param appId
* @param startDate
* @param endDate
* @return
*/
@GetMapping("/usersummary")
// @PreAuthorize("@customSs.hasPermission('wxmp:wxsummary:index')")
public R getUsersummary(String appId, String startDate, String endDate) {
try {
WxMpDataCubeService wxMpDataCubeService = wxService.getDataCubeService();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return R.ok(wxMpDataCubeService.getUserSummary(sdf.parse(startDate), sdf.parse(endDate)));
} catch (WxErrorException e) {
log.error("获取用户增减数据失败", e);
return R.error(e.getMessage());
} catch (Exception e) {
log.error("获取用户增减数据失败", e);
return R.error("获取用户增减数据失败");
}
}
/**
* 获取累计用户数据
*
* @param appId
* @param startDate
* @param endDate
* @return
*/
@GetMapping("/usercumulate")
// @PreAuthorize("@customSs.hasPermission('wxmp:wxsummary:index')")
public R getUserCumulate(String appId, String startDate, String endDate) {
try {
WxMpDataCubeService wxMpDataCubeService = wxService.getDataCubeService();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return R.ok(wxMpDataCubeService.getUserCumulate(sdf.parse(startDate), sdf.parse(endDate)));
} catch (WxErrorException e) {
log.error("获取累计用户数据失败", e);
return R.error(e.getMessage());
} catch (Exception e) {
log.error("获取用户增减数据失败", e);
return R.error("获取用户增减数据失败");
}
}
/**
* 获取接口分析数据
*
* @param appId
* @param startDate
* @param endDate
* @return
*/
@GetMapping("/interfacesummary")
// @PreAuthorize("@customSs.hasPermission('wxmp:wxsummary:index')")
public R getInterfaceSummary(String appId, String startDate, String endDate) {
try {
WxMpDataCubeService wxMpDataCubeService = wxService.getDataCubeService();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return R.ok(wxMpDataCubeService.getInterfaceSummary(sdf.parse(startDate), sdf.parse(endDate)));
} catch (WxErrorException e) {
log.error("获取接口分析数据失败", e);
return R.error(e.getMessage());
} catch (Exception e) {
log.error("获取接口分析数据失败", e);
return R.error("获取接口分析数据失败");
}
}
}

View File

@@ -0,0 +1,175 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.starry.admin.modules.weichat.entity.WxUser;
import com.starry.admin.modules.weichat.service.WxUserService;
import com.starry.common.result.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* 微信用户
*
* @author admin
* @since 2019-03-25 15:39:39
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxuser")
public class WxUserController {
@Resource
WxUserService wxUserService;
/**
* 分页查询
*
* @param page 分页对象
* @param wxUser 微信用户
* @return
*/
@GetMapping("/page")
@PreAuthorize("@customSs.hasPermission('wxmp:wxuser:index')")
public R getWxUserPage(Page page, WxUser wxUser, String tagId) {
Wrapper<WxUser> queryWrapper;
if (StringUtils.isNotBlank(tagId)) {
queryWrapper = Wrappers.lambdaQuery(wxUser)
.and(wrapper -> wrapper
.eq(WxUser::getTagidList, "[" + tagId + "]")
.or()
.like(WxUser::getTagidList, "," + tagId + ",")
.or()
.likeRight(WxUser::getTagidList, "[" + tagId + ",")
.or()
.likeLeft(WxUser::getTagidList, "," + tagId + "]"));
} else if (StrUtil.isNotBlank(wxUser.getNickName())) {
String nickName = wxUser.getNickName();
wxUser.setNickName(null);
queryWrapper = Wrappers.lambdaQuery(wxUser)
.like(WxUser::getNickName, nickName);
} else {
queryWrapper = Wrappers.lambdaQuery(wxUser);
}
return R.ok(wxUserService.page(page, queryWrapper));
}
/**
* 通过id查询微信用户
*
* @param id id
* @return R
*/
@GetMapping("/{id}")
@PreAuthorize("@customSs.hasPermission('wxmp:wxuser:get')")
public R getById(@PathVariable("id") String id) {
return R.ok(wxUserService.getById(id));
}
/**
* 新增微信用户
*
* @param wxUser 微信用户
* @return R
*/
@PostMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxuser:add')")
public R save(@RequestBody WxUser wxUser) {
return R.ok(wxUserService.save(wxUser));
}
/**
* 修改微信用户
*
* @param wxUser 微信用户
* @return R
*/
@PutMapping
@PreAuthorize("@customSs.hasPermission('wxmp:wxuser:edit')")
public R updateById(@RequestBody WxUser wxUser) {
return R.ok(wxUserService.updateById(wxUser));
}
/**
* 通过id删除微信用户
*
* @param id id
* @return R
*/
@DeleteMapping("/{id}")
@PreAuthorize("@customSs.hasPermission('wxmp:wxuser:del')")
public R removeById(@PathVariable String id) {
return R.ok(wxUserService.removeById(id));
}
@PostMapping("/synchron")
@PreAuthorize("@customSs.hasPermission('wxmp:wxuser:synchro')")
public R synchron() {
try {
wxUserService.synchroWxUser();
return R.ok();
} catch (WxErrorException e) {
log.error("同步微信用户失败", e);
return R.error(e.getMessage());
}
}
/**
* 修改微信用户备注
*
* @param wxUser
* @return
*/
@PutMapping("/remark")
@PreAuthorize("@customSs.hasPermission('wxmp:wxuser:edit:remark')")
public R remark(@RequestBody WxUser wxUser) {
try {
return R.ok(wxUserService.updateRemark(wxUser));
} catch (WxErrorException e) {
log.error("修改微信用户备注失败", e);
return R.error(e.getMessage());
}
}
/**
* 打标签
*
* @param data
* @return
*/
@PutMapping("/tagid-list")
@PreAuthorize("@customSs.hasPermission('wxmp:wxuser:tagging')")
public R tagidList(@RequestBody JSONObject data) {
try {
String appId = data.getStr("appId");
String taggingType = data.getStr("taggingType");
JSONArray tagIdsArray = data.getJSONArray("tagIds");
JSONArray openIdsArray = data.getJSONArray("openIds");
String[] openIds = openIdsArray.toArray(new String[0]);
for (Object tagId : tagIdsArray) {
wxUserService.tagging(taggingType, Long.valueOf(String.valueOf(tagId)), openIds);
}
return R.ok();
} catch (WxErrorException e) {
log.error("修改微信用户备注失败", e);
return R.error(e.getMessage());
}
}
}

View File

@@ -0,0 +1,155 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.starry.admin.modules.weichat.entity.WxUser;
import com.starry.admin.modules.weichat.entity.WxUserTagsDict;
import com.starry.admin.modules.weichat.service.WxUserService;
import com.starry.common.result.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpUserTagService;
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
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;
/**
* 微信用户标签
*
* @author admin
* @since 2019-03-25 15:39:39
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxusertags")
public class WxUserTagsController {
@Resource
WxMpService wxService;
@Resource
WxUserService wxUserService;
/**
* 获取微信用户标签
* @return
*/
@PreAuthorize("@customSs.hasPermission('wxmp:wxusertags:list')")
@GetMapping("/list")
public R getWxUserList(String appId) {
WxMpUserTagService wxMpUserTagService = wxService.getUserTagService();
try {
List<WxUserTag> listWxUserTag = wxMpUserTagService.tagGet();
return R.ok(listWxUserTag);
} catch (WxErrorException e) {
log.error("获取微信用户标签失败", e);
return R.error(e.getMessage());
}
}
/**
* 获取微信用户标签字典
* @param appId
* @return
*/
@PreAuthorize("@customSs.hasPermission('wxmp:wxusertags:list')")
@GetMapping("/dict")
public R getWxUserTagsDict(String appId) {
WxMpUserTagService wxMpUserTagService = wxService.getUserTagService();
try {
List<WxUserTag> listWxUserTag = wxMpUserTagService.tagGet();
List<WxUserTagsDict> listWxUserTagsDict = new ArrayList<>();
WxUserTagsDict wxUserTagsDict;
for(WxUserTag wxUserTag : listWxUserTag){
wxUserTagsDict = new WxUserTagsDict();
wxUserTagsDict.setName(wxUserTag.getName());
wxUserTagsDict.setValue(wxUserTag.getId());
listWxUserTagsDict.add(wxUserTagsDict);
}
return R.ok(listWxUserTagsDict);
} catch (WxErrorException e) {
log.error("获取微信用户标签字典失败", e);
return R.error(e.getMessage());
}
}
/**
* 新增微信用户标签
* @return
*/
@PreAuthorize("@customSs.hasPermission('wxmp:wxusertags:add')")
@PostMapping
public R save(@RequestBody JSONObject data){
String appId = data.getStr("appId");
String name = data.getStr("name");
WxMpUserTagService wxMpUserTagService = wxService.getUserTagService();
try {
return R.ok(wxMpUserTagService.tagCreate(name));
} catch (WxErrorException e) {
log.error("新增微信用户标签失败", e);
return R.error(e.getMessage());
}
}
/**
* 修改微信用户标签
* @return
*/
@PreAuthorize("@customSs.hasPermission('wxmp:wxusertags:edit')")
@PutMapping
public R updateById(@RequestBody JSONObject data){
String appId = data.getStr("appId");
Long id = data.getLong("id");
String name = data.getStr("name");
WxMpUserTagService wxMpUserTagService = wxService.getUserTagService();
try {
return R.ok(wxMpUserTagService.tagUpdate(id,name));
} catch (WxErrorException e) {
log.error("修改微信用户标签失败", e);
return R.error(e.getMessage());
}
}
/**
* 删除微信用户标签
* @param id
* @param appId
* @return
*/
@PreAuthorize("@customSs.hasPermission('wxmp:wxusertags:del')")
@DeleteMapping
public R removeById(Long id,String appId){
int count = (int) wxUserService.count(Wrappers.<WxUser>lambdaQuery()
.and(wrapper -> wrapper
.eq(WxUser::getTagidList,"["+id+"]")
.or()
.like(WxUser::getTagidList,","+id+",")
.or()
.likeRight(WxUser::getTagidList,"["+id+",")
.or()
.likeLeft(WxUser::getTagidList,","+id+"]")));
if(count>0){
return R.error("该标签下有用户存在,无法删除");
}
WxMpUserTagService wxMpUserTagService = wxService.getUserTagService();
try {
return R.ok(wxMpUserTagService.tagDelete(id));
} catch (WxErrorException e) {
log.error("删除微信用户标签失败", e);
return R.error(e.getMessage());
}
}
}

View File

@@ -0,0 +1,29 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
@Data
public class CustomWxMpProperties {
/**
* 微信APPID
*/
public String appid;
/**
* 微信公众号的app secret
*/
public String secret;
/**
* 微信公众号的token
*/
public String token;
/**
* 微信公众号的EncodingAESKey
*/
public String aesKey;
}

View File

@@ -0,0 +1,23 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import java.io.Serializable;
/**
* imageManager
*
* @author admin
* @since 2019-03-23 21:26:35
*/
@Data
public class ImageManager implements Serializable {
private static final long serialVersionUID = 1L;
private String url;
private String thumb;
private String tag;
private String name;
private Integer id;
}

View File

@@ -0,0 +1,41 @@
package com.starry.admin.modules.weichat.entity;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import me.chanjar.weixin.common.bean.menu.WxMenuRule;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 自定义菜单模型
*
* @author admin
*/
@Data
public class Menu implements Serializable {
private static final long serialVersionUID = -7083914585539687746L;
private List<MenuButton> button = new ArrayList<>();
private WxMenuRule matchrule;
/**
* 反序列化
*/
public static Menu fromJson(String json) {
return JSONUtil.parseObj(json).toBean(Menu.class);
}
public String toJson() {
return JSONUtil.toJsonStr(this);
}
@Override
public String toString() {
return this.toJson();
}
}

View File

@@ -0,0 +1,69 @@
package com.starry.admin.modules.weichat.entity;
import cn.hutool.json.JSONObject;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 自定义菜单模型
*
* @author admin
*/
@Data
public class MenuButton implements Serializable {
private String type;
private String name;
private String key;
private String url;
private String media_id;
private String appid;
private String pagepath;
private List<MenuButton> sub_button = new ArrayList<>();
/**
* content内容
*/
private JSONObject content;
private String repContent;
/**
* 消息类型
*/
private String repType;
/**
* 消息名
*/
private String repName;
/**
* 视频和音乐的描述
*/
private String repDesc;
/**
* 视频和音乐的描述
*/
private String repUrl;
/**
* 高质量链接
*/
private String repHqUrl;
/**
* 缩略图的媒体id
*/
private String repThumbMediaId;
/**
* 缩略图url
*/
private String repThumbUrl;
private String article_id;
}

View File

@@ -0,0 +1,29 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import java.io.Serializable;
/**
* @author admin
*/
@Data
public class ThirdSession implements Serializable {
/**
* 微信用户ID
*/
private String wxUserId;
/**
* 配置项ID
*/
private String appId;
/**
* 微信sessionKey
*/
private String sessionKey;
/**
* 用户标识
*/
private String openId;
}

View File

@@ -0,0 +1,120 @@
package com.starry.admin.modules.weichat.entity;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.starry.common.config.typehandler.JsonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.type.JdbcType;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
/**
* 消息自动回复
*
* @author admin
* @since 2019-04-18 15:40:39
*/
@Data
@TableName("wx_auto_reply")
@EqualsAndHashCode(callSuper = true)
public class WxAutoReply extends Model<WxAutoReply> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 创建者
*/
private String createId;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新者
*/
private String updateId;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 备注
*/
private String remark;
/**
* 逻辑删除标记0显示1隐藏
*/
private String delFlag;
/**
* 类型1、关注时回复2、消息回复3、关键词回复
*/
@NotNull(message = "类型不能为空")
private String type;
/**
* 关键词
*/
private String reqKey;
/**
* 请求消息类型text文本image图片voice语音video视频shortvideo小视频location地理位置
*/
private String reqType;
/**
* 回复消息类型text文本image图片voice语音video视频music音乐news图文
*/
@NotNull(message = "回复消息类型不能为空")
private String repType;
/**
* 回复类型文本匹配类型1、全匹配2、半匹配
*/
private String repMate;
/**
* 回复类型文本保存文字
*/
private String repContent;
/**
* 回复的素材名、视频和音乐的标题
*/
private String repName;
/**
* 回复类型imge、voice、news、video的mediaID或音乐缩略图的媒体id
*/
private String repMediaId;
/**
* 视频和音乐的描述
*/
private String repDesc;
/**
* 链接
*/
private String repUrl;
/**
* 高质量链接
*/
private String repHqUrl;
/**
* 缩略图的媒体id
*/
private String repThumbMediaId;
/**
* 缩略图url
*/
private String repThumbUrl;
/**
* 图文消息的内容
*/
@TableField(typeHandler = JsonTypeHandler.class, jdbcType = JdbcType.VARCHAR)
private JSONObject content;
}

View File

@@ -0,0 +1,118 @@
package com.starry.admin.modules.weichat.entity;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.starry.common.config.typehandler.JsonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.type.JdbcType;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
/**
* 自定义菜单
*
* @author admin
* @since 2019-03-27 16:52:10
*/
@Data
@TableName("wx_menu")
@EqualsAndHashCode(callSuper = true)
public class WxMenu extends Model<WxMenu> {
private static final long serialVersionUID = 1L;
/**
* 菜单IDclick、scancode_push、scancode_waitmsg、pic_sysphoto、pic_photo_or_album、pic_weixin、location_select保存key
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 父菜单ID
*/
private String parentId;
/**
* 排序值
*/
private Integer sort;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 逻辑删除标记0显示1隐藏
*/
private String delFlag;
/**
* 菜单类型click、view、miniprogram、scancode_push、scancode_waitmsg、pic_sysphoto、pic_photo_or_album、pic_weixin、location_select、media_id、view_limited等
*/
@NotNull(message = "菜单类型不能为空")
private String type;
/**
* 菜单名
*/
@NotNull(message = "菜单名不能为空")
private String name;
/**
* View保存链接到url
*/
private String url;
/**
* Img、voice、News保存mediaID
*/
private String repMediaId;
/**
* 回复消息类型text文本image图片voice语音video视频music音乐news图文
*/
private String repType;
/**
* 素材名、视频和音乐的标题
*/
private String repName;
/**
* Text:保存文字
*/
private String repContent;
/**
* 小程序的appid
*/
private String maAppId;
/**
* 小程序的页面路径
*/
private String maPagePath;
/**
* 视频和音乐的描述
*/
private String repDesc;
/**
* 视频和音乐的描述
*/
private String repUrl;
/**
* 高质量链接
*/
private String repHqUrl;
/**
* 缩略图的媒体id
*/
private String repThumbMediaId;
/**
* 缩略图url
*/
private String repThumbUrl;
/**
* 图文消息的内容
*/
@TableField(typeHandler = JsonTypeHandler.class, jdbcType = JdbcType.VARCHAR)
private JSONObject content;
}

View File

@@ -0,0 +1,146 @@
package com.starry.admin.modules.weichat.entity;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.starry.common.config.typehandler.JsonTypeHandler;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.type.JdbcType;
import java.time.LocalDateTime;
/**
* 微信消息
*
* @author admin
* @since 2019-05-28 16:12:10
*/
@Data
@TableName("wx_msg")
@EqualsAndHashCode(callSuper = true)
@ApiModel(description = "微信消息")
public class WxMsg extends Model<WxMsg> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 创建者
*/
private String createId;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新者
*/
private String updateId;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 备注
*/
private String remark;
/**
* 逻辑删除标记0显示1隐藏
*/
private String delFlag;
/**
* 公众号名称
*/
private String appName;
/**
* 公众号logo
*/
private String appLogo;
/**
* 微信用户ID
*/
private String wxUserId;
/**
* 昵称
*/
private String nickName;
/**
* 头像
*/
private String headimgUrl;
/**
* 消息分类1、用户发给公众号2、公众号发给用户
*/
private String type;
/**
* 消息类型text文本image图片voice语音video视频shortvideo小视频location地理位置music音乐news图文event推送事件
*/
private String repType;
/**
* 事件类型subscribe关注unsubscribe取关CLICK、VIEW菜单事件
*/
private String repEvent;
/**
* 回复类型文本保存文字
*/
private String repContent;
/**
* 回复类型imge、voice、news、video的mediaID或音乐缩略图的媒体id
*/
private String repMediaId;
/**
* 回复的素材名、视频和音乐的标题
*/
private String repName;
/**
* 视频和音乐的描述
*/
private String repDesc;
/**
* 链接
*/
private String repUrl;
/**
* 高质量链接
*/
private String repHqUrl;
/**
* 图文消息的内容
*/
@TableField(typeHandler = JsonTypeHandler.class, jdbcType = JdbcType.VARCHAR)
private JSONObject content;
/**
* 缩略图的媒体id
*/
private String repThumbMediaId;
/**
* 缩略图url
*/
private String repThumbUrl;
/**
* 地理位置维度
*/
private Double repLocationX;
/**
* 地理位置经度
*/
private Double repLocationY;
/**
* 地图缩放大小
*/
private Double repScale;
/**
* 已读标记01
*/
private String readFlag;
}

View File

@@ -0,0 +1,28 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 微信消息
*
* @author admin
* @since 2019-05-28 16:12:10
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class WxMsgVO extends WxMsg {
private static final long serialVersionUID = 1L;
/**
* 数量
*/
private Integer countMsg;
/**
* repType not in筛选
*/
private String notInRepType;
}

View File

@@ -0,0 +1,19 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
/**
* 微信开发数据
* @author admin
*/
@Data
public class WxOpenDataDTO {
private String appId;
private String userId;
private String encryptedData;
private String errMsg;
private String iv;
private String rawData;
private String signature;
private String sessionKey;
}

View File

@@ -0,0 +1,154 @@
package com.starry.admin.modules.weichat.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.starry.common.config.typehandler.ArrayLongTypeHandler;
import com.starry.common.sensitive.Sensitive;
import com.starry.common.sensitive.SensitiveTypeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.type.JdbcType;
import java.time.LocalDateTime;
/**
* 微信用户
*
* @author admin
* @since 2019-03-25 15:39:39
*/
@Data
@TableName("wx_user")
@EqualsAndHashCode(callSuper = true)
public class WxUser extends Model<WxUser> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
* 创建者
*/
private String createId;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新者
*/
private String updateId;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 备注信息
*/
private String remark;
/**
* 逻辑删除标记0显示1隐藏
*/
private String delFlag;
/**
* 应用类型(1:小程序2:公众号)
*/
private String appType;
/**
* 是否订阅012网页授权用户
*/
private String subscribe;
/**
* 返回用户关注的渠道来源ADD_SCENE_SEARCH 公众号搜索ADD_SCENE_ACCOUNT_MIGRATION 公众号迁移ADD_SCENE_PROFILE_CARD 名片分享ADD_SCENE_QR_CODE 扫描二维码ADD_SCENEPROFILE LINK 图文页内名称点击ADD_SCENE_PROFILE_ITEM 图文页右上角菜单ADD_SCENE_PAID 支付后关注ADD_SCENE_OTHERS 其他
*/
private String subscribeScene;
/**
* 关注时间
*/
private LocalDateTime subscribeTime;
/**
* 关注次数
*/
private Integer subscribeNum;
/**
* 取消关注时间
*/
private LocalDateTime cancelSubscribeTime;
/**
* 用户标识
*/
private String openId;
/**
* 昵称
*/
private String nickName;
/**
* 性别120未知
*/
private String sex;
/**
* 所在城市
*/
private String city;
/**
* 所在国家
*/
private String country;
/**
* 所在省份
*/
private String province;
/**
* 手机号码
*/
@Sensitive(type = SensitiveTypeEnum.MOBILE_PHONE)
private String phone;
/**
* 用户语言
*/
private String language;
/**
* 头像
*/
private String headimgUrl;
/**
* union_id
*/
private String unionId;
/**
* 用户组
*/
private String groupId;
/**
* 标签列表
*/
@TableField(typeHandler = ArrayLongTypeHandler.class, jdbcType = JdbcType.VARCHAR)
private Long[] tagidList;
/**
* 二维码扫码场景
*/
private String qrSceneStr;
/**
* 地理位置纬度
*/
private Double latitude;
/**
* 地理位置经度
*/
private Double longitude;
/**
* 地理位置精度
*/
@TableField(value = "`precision`")
private Double precision;
/**
* 会话密钥
*/
private String sessionKey;
}

View File

@@ -0,0 +1,13 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
/**
* @author admin
*/
@Data
public class WxUserTagsDict {
private String name;
private Long value;
}

View File

@@ -0,0 +1,13 @@
package com.starry.admin.modules.weichat.handler;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author admin
*/
public abstract class AbstractHandler implements WxMpMessageHandler {
protected Logger logger = LoggerFactory.getLogger(getClass());
}

View File

@@ -0,0 +1,26 @@
package com.starry.admin.modules.weichat.handler;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author admin
*/
@Component
public class KfSessionHandler extends AbstractHandler {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService wxMpService,
WxSessionManager sessionManager) {
// TODO 对会话做处理
return null;
}
}

View File

@@ -0,0 +1,45 @@
package com.starry.admin.modules.weichat.handler;
import com.starry.admin.modules.weichat.builder.TextBuilder;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;
import java.util.Map;
import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType;
/**
* @author admin
*/
@Component
public class LocationHandler extends AbstractHandler {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService wxMpService,
WxSessionManager sessionManager) {
if (wxMessage.getMsgType().equals(XmlMsgType.LOCATION)) {
// TODO 接收处理用户发送的地理位置消息
try {
String content = "感谢反馈,您的的地理位置已收到!";
return new TextBuilder().build(content, wxMessage, null);
} catch (Exception e) {
this.logger.error("位置消息接收处理失败", e);
return null;
}
}
// 上报地理位置事件
this.logger.info("上报地理位置,纬度 : {},经度 : {},精度 : {}",
wxMessage.getLatitude(), wxMessage.getLongitude(), wxMessage.getPrecision());
// TODO 可以将用户地理位置信息保存到本地数据库,以便以后使用
return null;
}
}

View File

@@ -0,0 +1,40 @@
package com.starry.admin.modules.weichat.handler;
import cn.hutool.core.util.StrUtil;
import com.starry.admin.modules.weichat.utils.JsonUtils;
import com.starry.common.utils.HttpUtils;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author admin
*/
@Component
public class LogHandler extends AbstractHandler {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService wxMpService,
WxSessionManager sessionManager) {
this.logger.info("\n接收到请求消息内容{}", JsonUtils.toJson(wxMessage));
// 以下为测试代码,自行删除不影响系统功能
if (wxMessage.getMsgType().equals(WxConsts.XmlMsgType.EVENT)) {
if (wxMessage.getEvent().equals(WxConsts.EventType.SUBSCRIBE) ||
wxMessage.getEvent().equals(WxConsts.EventType.SCAN)) {
if (wxMessage.getEventKey().contains("jl-wiki")) {
String openId = wxMessage.getFromUser();
String sceneStr = StrUtil.split(wxMessage.getEventKey(), ":").get(1);
String rs = HttpUtils.sendPost("http://127.0.0.1:8083/joolun-open/user", StrUtil.format("openId={}&sceneStr={}", openId, sceneStr));
}
}
}
return null;
}
}

View File

@@ -0,0 +1,173 @@
package com.starry.admin.modules.weichat.handler;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.starry.admin.modules.weichat.config.CommonConstants;
import com.starry.admin.modules.weichat.constant.ConfigConstant;
import com.starry.admin.modules.weichat.entity.WxMenu;
import com.starry.admin.modules.weichat.entity.WxMsg;
import com.starry.admin.modules.weichat.entity.WxUser;
import com.starry.admin.modules.weichat.mapper.WxMenuMapper;
import com.starry.admin.modules.weichat.mapper.WxMsgMapper;
import com.starry.admin.modules.weichat.mapper.WxUserMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.builder.outxml.*;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author admin
*/
@Slf4j
@Component
@AllArgsConstructor
public class MenuHandler extends AbstractHandler {
private final WxMenuMapper wxMenuMapper;
private final WxUserMapper wxUserMapper;
private final WxMsgMapper wxMsgMapper;
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService weixinService,
WxSessionManager sessionManager) throws WxErrorException {
// 消息记录
WxMenu wxMenu;
if (WxConsts.EventType.CLICK.equals(wxMessage.getEvent())
|| WxConsts.EventType.SCANCODE_WAITMSG.equals(wxMessage.getEvent())) {
wxMenu = wxMenuMapper.selectById(wxMessage.getEventKey());
if (wxMenu == null) {// 菜单过期
return new TextBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).content("非常抱歉,该菜单已删除!").build();
}
} else {
wxMenu = new WxMenu();
}
WxUser wxUser = wxUserMapper.selectOne(Wrappers.<WxUser>lambdaQuery()
.eq(WxUser::getOpenId, wxMessage.getFromUser()));
if (wxUser == null) {// 库中无此用户
WxMpUser userWxInfo = weixinService.getUserService()
.userInfo(wxMessage.getFromUser(), null);
wxUser = new WxUser();
wxUser.setSubscribeNum(1);
SubscribeHandler.setWxUserValue(wxUser, userWxInfo);
wxUserMapper.insert(wxUser);
}
// 组装菜单回复消息
return getWxMpXmlOutMessage(wxMessage, wxMenu, wxUser);
}
/**
* 组装菜单回复消息
*
* @param wxMessage
* @param wxMenu
* @return
*/
public WxMpXmlOutMessage getWxMpXmlOutMessage(WxMpXmlMessage wxMessage, WxMenu wxMenu, WxUser wxUser) {
WxMpXmlOutMessage wxMpXmlOutMessage = null;
// 记录接收消息
WxMsg wxMsg = new WxMsg();
// wxMsg.setTenantId(wxApp.getTenantId());
wxMsg.setWxUserId(wxUser.getId());
wxMsg.setNickName(wxUser.getNickName());
wxMsg.setHeadimgUrl(wxUser.getHeadimgUrl());
wxMsg.setType(ConfigConstant.WX_MSG_TYPE_1);
wxMsg.setRepEvent(wxMessage.getEvent());
wxMsg.setRepType(wxMessage.getMsgType());
wxMsg.setRepName(wxMenu.getName());
if (WxConsts.EventType.VIEW.equals(wxMessage.getEvent())) {
wxMsg.setRepUrl(wxMessage.getEventKey());
}
if (WxConsts.EventType.SCANCODE_WAITMSG.equals(wxMessage.getEvent())) {
wxMsg.setRepContent(wxMessage.getScanCodeInfo().getScanResult());
}
wxMsg.setReadFlag(CommonConstants.NO);
LocalDateTime now = LocalDateTime.now();
wxMsg.setCreateTime(now);
wxMsgMapper.insert(wxMsg);
if (WxConsts.MenuButtonType.CLICK.equals(wxMenu.getType())
|| WxConsts.MenuButtonType.SCANCODE_WAITMSG.equals(wxMenu.getType())) {
// 记录回复消息
wxMsg = new WxMsg();
wxMsg.setWxUserId(wxUser.getId());
wxMsg.setNickName(wxUser.getNickName());
wxMsg.setHeadimgUrl(wxUser.getHeadimgUrl());
wxMsg.setCreateTime(now.plusSeconds(1));
wxMsg.setType(ConfigConstant.WX_MSG_TYPE_2);
wxMsg.setRepType(wxMenu.getRepType());
if (WxConsts.KefuMsgType.TEXT.equals(wxMenu.getRepType())) {
wxMsg.setRepContent(wxMenu.getRepContent());
wxMpXmlOutMessage = new TextBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).content(wxMenu.getRepContent()).build();
}
if (WxConsts.KefuMsgType.IMAGE.equals(wxMenu.getRepType())) {
wxMsg.setRepName(wxMenu.getRepName());
wxMsg.setRepUrl(wxMenu.getRepUrl());
wxMsg.setRepMediaId(wxMenu.getRepMediaId());
wxMpXmlOutMessage = new ImageBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).mediaId(wxMenu.getRepMediaId()).build();
}
if (WxConsts.KefuMsgType.VOICE.equals(wxMenu.getRepType())) {
wxMsg.setRepName(wxMenu.getRepName());
wxMsg.setRepUrl(wxMenu.getRepUrl());
wxMsg.setRepMediaId(wxMenu.getRepMediaId());
wxMpXmlOutMessage = new VoiceBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).mediaId(wxMenu.getRepMediaId()).build();
}
if (WxConsts.KefuMsgType.VIDEO.equals(wxMenu.getRepType())) {
wxMsg.setRepName(wxMenu.getRepName());
wxMsg.setRepDesc(wxMenu.getRepDesc());
wxMsg.setRepUrl(wxMenu.getRepUrl());
wxMsg.setRepMediaId(wxMenu.getRepMediaId());
wxMpXmlOutMessage = new VideoBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).mediaId(wxMenu.getRepMediaId())
.title(wxMenu.getRepName()).description(wxMenu.getRepDesc()).build();
}
if (WxConsts.KefuMsgType.MUSIC.equals(wxMenu.getRepType())) {
wxMsg.setRepName(wxMenu.getRepName());
wxMsg.setRepDesc(wxMenu.getRepDesc());
wxMsg.setRepUrl(wxMenu.getRepUrl());
wxMsg.setRepHqUrl(wxMenu.getRepHqUrl());
wxMsg.setRepThumbMediaId(wxMenu.getRepThumbMediaId());
wxMsg.setRepThumbUrl(wxMenu.getRepThumbUrl());
wxMpXmlOutMessage = new MusicBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
.thumbMediaId(wxMenu.getRepThumbMediaId())
.title(wxMenu.getRepName()).description(wxMenu.getRepDesc())
.musicUrl(wxMenu.getRepUrl()).hqMusicUrl(wxMenu.getRepHqUrl()).build();
}
if (WxConsts.KefuMsgType.NEWS.equals(wxMenu.getRepType())) {
List<WxMpXmlOutNewsMessage.Item> list = new ArrayList<>();
List<JSONObject> listJSONObject = JSONUtil.toList(wxMenu.getContent().getJSONArray("articles"), JSONObject.class);
WxMpXmlOutNewsMessage.Item t;
for (JSONObject jSONObject : listJSONObject) {
t = new WxMpXmlOutNewsMessage.Item();
t.setTitle(jSONObject.getStr("title"));
t.setDescription(jSONObject.getStr("digest"));
t.setPicUrl(jSONObject.getStr("thumbUrl"));
t.setUrl(jSONObject.getStr("url"));
list.add(t);
}
wxMsg.setRepName(wxMenu.getRepName());
wxMsg.setRepDesc(wxMenu.getRepDesc());
wxMsg.setRepUrl(wxMenu.getRepUrl());
wxMsg.setRepMediaId(wxMenu.getRepMediaId());
wxMsg.setContent(wxMenu.getContent());
wxMpXmlOutMessage = new NewsBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).articles(list).build();
}
wxMsgMapper.insert(wxMsg);
}
return wxMpXmlOutMessage;
}
}

View File

@@ -0,0 +1,195 @@
package com.starry.admin.modules.weichat.handler;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.starry.admin.modules.weichat.config.CommonConstants;
import com.starry.admin.modules.weichat.constant.ConfigConstant;
import com.starry.admin.modules.weichat.constant.WebSocketConstant;
import com.starry.admin.modules.weichat.entity.WxAutoReply;
import com.starry.admin.modules.weichat.entity.WxMsg;
import com.starry.admin.modules.weichat.entity.WxUser;
import com.starry.admin.modules.weichat.mapper.WxUserMapper;
import com.starry.admin.modules.weichat.service.WxAutoReplyService;
import com.starry.admin.modules.weichat.service.WxMsgService;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage;
import me.chanjar.weixin.mp.builder.outxml.*;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType;
/**
* @author admin
*/
@Component
@AllArgsConstructor
public class MsgHandler extends AbstractHandler {
private final WxAutoReplyService wxAutoReplyService;
private final WxUserMapper wxUserMapper;
private final WxMsgService wxMsgService;
/**
* 组装回复消息,并记录消息
*
* @param wxMessage
* @param listWxAutoReply
* @return
*/
public static WxMpXmlOutMessage getWxMpXmlOutMessage(WxMpXmlMessage wxMessage, List<WxAutoReply> listWxAutoReply, WxUser wxUser, WxMsgService wxMsgService) {
WxMpXmlOutMessage wxMpXmlOutMessage = null;
// 记录接收消息
WxMsg wxMsg = new WxMsg();
wxMsg.setWxUserId(wxUser.getId());
wxMsg.setNickName(wxUser.getNickName());
wxMsg.setHeadimgUrl(wxUser.getHeadimgUrl());
wxMsg.setType(ConfigConstant.WX_MSG_TYPE_1);
wxMsg.setRepEvent(wxMessage.getEvent());
wxMsg.setRepType(wxMessage.getMsgType());
wxMsg.setRepMediaId(wxMessage.getMediaId());
if (XmlMsgType.TEXT.equals(wxMessage.getMsgType())) {
wxMsg.setRepContent(wxMessage.getContent());
}
if (XmlMsgType.VOICE.equals(wxMessage.getMsgType())) {
wxMsg.setRepName(wxMessage.getMediaId() + "." + wxMessage.getFormat());
wxMsg.setRepContent(wxMessage.getRecognition());
}
if (XmlMsgType.IMAGE.equals(wxMessage.getMsgType())) {
wxMsg.setRepUrl(wxMessage.getPicUrl());
}
if (XmlMsgType.LINK.equals(wxMessage.getMsgType())) {
wxMsg.setRepName(wxMessage.getTitle());
wxMsg.setRepDesc(wxMessage.getDescription());
wxMsg.setRepUrl(wxMessage.getUrl());
}
if (WxConsts.MediaFileType.FILE.equals(wxMessage.getMsgType())) {
wxMsg.setRepName(wxMessage.getTitle());
wxMsg.setRepDesc(wxMessage.getDescription());
}
if (XmlMsgType.VIDEO.equals(wxMessage.getMsgType())) {
wxMsg.setRepThumbMediaId(wxMessage.getThumbMediaId());
}
if (XmlMsgType.LOCATION.equals(wxMessage.getMsgType())) {
wxMsg.setRepLocationX(wxMessage.getLocationX());
wxMsg.setRepLocationY(wxMessage.getLocationY());
wxMsg.setRepScale(wxMessage.getScale());
wxMsg.setRepContent(wxMessage.getLabel());
}
wxMsg.setReadFlag(CommonConstants.NO);
LocalDateTime now = LocalDateTime.now();
wxMsg.setCreateTime(now);
wxMsgService.save(wxMsg);
// 推送websocket
String destination = WebSocketConstant.USER_DESTINATION_PREFIX + WebSocketConstant.WX_MSG + wxMsg.getWxUserId();
if (listWxAutoReply != null && !listWxAutoReply.isEmpty()) {
WxAutoReply wxAutoReply = listWxAutoReply.get(0);
// 记录回复消息
wxMsg = new WxMsg();
wxMsg.setWxUserId(wxUser.getId());
wxMsg.setNickName(wxUser.getNickName());
wxMsg.setHeadimgUrl(wxUser.getHeadimgUrl());
wxMsg.setCreateTime(now.plusSeconds(1));
wxMsg.setType(ConfigConstant.WX_MSG_TYPE_2);
wxMsg.setRepType(wxAutoReply.getRepType());
if (WxConsts.KefuMsgType.TEXT.equals(wxAutoReply.getRepType())) {// 文本
wxMsg.setRepContent(wxAutoReply.getRepContent());
wxMpXmlOutMessage = new TextBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).content(wxAutoReply.getRepContent()).build();
}
if (WxConsts.KefuMsgType.IMAGE.equals(wxAutoReply.getRepType())) {// 图片
wxMsg.setRepName(wxAutoReply.getRepName());
wxMsg.setRepUrl(wxAutoReply.getRepUrl());
wxMsg.setRepMediaId(wxAutoReply.getRepMediaId());
wxMpXmlOutMessage = new ImageBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).mediaId(wxAutoReply.getRepMediaId()).build();
}
if (WxConsts.KefuMsgType.VOICE.equals(wxAutoReply.getRepType())) {
wxMsg.setRepName(wxAutoReply.getRepName());
wxMsg.setRepUrl(wxAutoReply.getRepUrl());
wxMsg.setRepMediaId(wxAutoReply.getRepMediaId());
wxMpXmlOutMessage = new VoiceBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).mediaId(wxAutoReply.getRepMediaId()).build();
}
if (WxConsts.KefuMsgType.VIDEO.equals(wxAutoReply.getRepType())) {
wxMsg.setRepName(wxAutoReply.getRepName());
wxMsg.setRepDesc(wxAutoReply.getRepDesc());
wxMsg.setRepUrl(wxAutoReply.getRepUrl());
wxMsg.setRepMediaId(wxAutoReply.getRepMediaId());
wxMpXmlOutMessage = new VideoBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).mediaId(wxAutoReply.getRepMediaId()).title(wxAutoReply.getRepName()).description(wxAutoReply.getRepDesc()).build();
}
if (WxConsts.KefuMsgType.MUSIC.equals(wxAutoReply.getRepType())) {
wxMsg.setRepName(wxAutoReply.getRepName());
wxMsg.setRepDesc(wxAutoReply.getRepDesc());
wxMsg.setRepUrl(wxAutoReply.getRepUrl());
wxMsg.setRepHqUrl(wxAutoReply.getRepHqUrl());
wxMsg.setRepThumbMediaId(wxAutoReply.getRepThumbMediaId());
wxMsg.setRepThumbUrl(wxAutoReply.getRepThumbUrl());
wxMpXmlOutMessage = new MusicBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).thumbMediaId(wxAutoReply.getRepThumbMediaId()).title(wxAutoReply.getRepName()).description(wxAutoReply.getRepDesc()).musicUrl(wxAutoReply.getRepUrl()).hqMusicUrl(wxAutoReply.getRepHqUrl()).build();
}
if (WxConsts.KefuMsgType.NEWS.equals(wxAutoReply.getRepType())) {
List<WxMpXmlOutNewsMessage.Item> list = new ArrayList<>();
List<JSONObject> listJSONObject = wxAutoReply.getContent().getJSONArray("articles").toList(JSONObject.class);
WxMpXmlOutNewsMessage.Item t;
for (JSONObject jSONObject : listJSONObject) {
t = new WxMpXmlOutNewsMessage.Item();
t.setTitle(jSONObject.getStr("title"));
t.setDescription(jSONObject.getStr("digest"));
t.setPicUrl(jSONObject.getStr("thumbUrl"));
t.setUrl(jSONObject.getStr("url"));
list.add(t);
}
wxMsg.setRepName(wxAutoReply.getRepName());
wxMsg.setRepDesc(wxAutoReply.getRepDesc());
wxMsg.setRepUrl(wxAutoReply.getRepUrl());
wxMsg.setRepMediaId(wxAutoReply.getRepMediaId());
wxMsg.setContent(wxAutoReply.getContent());
wxMpXmlOutMessage = new NewsBuilder().fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).articles(list).build();
}
wxMsgService.save(wxMsg);
}
return wxMpXmlOutMessage;
}
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) {
// 组装回复消息
if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
WxMpXmlOutMessage rs;
// TODO 可以选择将消息保存到本地
WxUser wxUser = wxUserMapper.selectOne(Wrappers.<WxUser>lambdaQuery().eq(WxUser::getOpenId, wxMessage.getFromUser()));
if (WxConsts.KefuMsgType.TEXT.equals(wxMessage.getMsgType())) {// 1、先处理是否有文本关键字回复
// 先全匹配
List<WxAutoReply> listWxAutoReply = wxAutoReplyService.list(Wrappers.<WxAutoReply>query().lambda().eq(WxAutoReply::getType, ConfigConstant.WX_AUTO_REPLY_TYPE_3).eq(WxAutoReply::getRepMate, ConfigConstant.WX_REP_MATE_1).eq(WxAutoReply::getReqKey, wxMessage.getContent()));
if (listWxAutoReply != null && !listWxAutoReply.isEmpty()) {
rs = this.getWxMpXmlOutMessage(wxMessage, listWxAutoReply, wxUser, wxMsgService);
if (rs != null) {
return rs;
}
}
// 再半匹配
listWxAutoReply = wxAutoReplyService.list(Wrappers.<WxAutoReply>query().lambda().eq(WxAutoReply::getType, ConfigConstant.WX_AUTO_REPLY_TYPE_3).eq(WxAutoReply::getRepMate, ConfigConstant.WX_REP_MATE_2).like(WxAutoReply::getReqKey, wxMessage.getContent()));
if (listWxAutoReply != null && !listWxAutoReply.isEmpty()) {
rs = this.getWxMpXmlOutMessage(wxMessage, listWxAutoReply, wxUser, wxMsgService);
if (rs != null) {
return rs;
}
}
}
// 2、再处理消息回复
List<WxAutoReply> listWxAutoReply = wxAutoReplyService.list(Wrappers.<WxAutoReply>query().lambda().eq(WxAutoReply::getType, ConfigConstant.WX_AUTO_REPLY_TYPE_2).eq(WxAutoReply::getReqType, wxMessage.getMsgType()));
rs = this.getWxMpXmlOutMessage(wxMessage, listWxAutoReply, wxUser, wxMsgService);
return rs;
}
return null;
}
}

View File

@@ -0,0 +1,25 @@
package com.starry.admin.modules.weichat.handler;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author admin
*/
@Component
public class NullHandler extends AbstractHandler {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService wxMpService,
WxSessionManager sessionManager) {
return null;
}
}

View File

@@ -0,0 +1,25 @@
package com.starry.admin.modules.weichat.handler;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author admin
*/
@Component
public class ScanHandler extends AbstractHandler {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> map,
WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
// 扫码事件处理
return null;
}
}

View File

@@ -0,0 +1,28 @@
package com.starry.admin.modules.weichat.handler;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* 门店审核事件处理
*
* @author admin
*/
@Component
public class StoreCheckNotifyHandler extends AbstractHandler {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService wxMpService,
WxSessionManager sessionManager) {
// TODO 处理门店审核事件
return null;
}
}

View File

@@ -0,0 +1,85 @@
package com.starry.admin.modules.weichat.handler;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.starry.admin.modules.weichat.constant.ConfigConstant;
import com.starry.admin.modules.weichat.entity.WxAutoReply;
import com.starry.admin.modules.weichat.entity.WxUser;
import com.starry.admin.modules.weichat.mapper.WxUserMapper;
import com.starry.admin.modules.weichat.service.WxAutoReplyService;
import com.starry.admin.modules.weichat.service.WxMsgService;
import com.starry.admin.modules.weichat.utils.LocalDateTimeUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* @author admin
*/
@Slf4j
@Component
@AllArgsConstructor
public class SubscribeHandler extends AbstractHandler {
private final WxAutoReplyService wxAutoReplyService;
private final WxUserMapper wxUserMapper;
private final WxMsgService wxMsgService;
public static void setWxUserValue(WxUser wxUser, WxMpUser userWxInfo) {
wxUser.setAppType(ConfigConstant.WX_APP_TYPE_2);
wxUser.setSubscribe(ConfigConstant.SUBSCRIBE_TYPE_YES);
wxUser.setSubscribeScene(userWxInfo.getSubscribeScene());
if (null != userWxInfo.getSubscribeTime()) {
wxUser.setSubscribeTime(LocalDateTimeUtils.timestamToDatetime(userWxInfo.getSubscribeTime() * 1000));
}
wxUser.setOpenId(userWxInfo.getOpenId());
wxUser.setLanguage(userWxInfo.getLanguage());
wxUser.setRemark(userWxInfo.getRemark());
wxUser.setUnionId(userWxInfo.getUnionId());
wxUser.setGroupId(JSONUtil.toJsonStr(userWxInfo.getGroupId()));
wxUser.setTagidList(userWxInfo.getTagIds());
wxUser.setQrSceneStr(userWxInfo.getQrSceneStr());
}
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService weixinService, WxSessionManager sessionManager) {
log.info("新关注用户 OPENID: " + wxMessage.getFromUser());
// 获取微信用户基本信息
try {
WxMpUser userWxInfo = weixinService.getUserService().userInfo(wxMessage.getFromUser(), null);
if (userWxInfo != null) {
// TODO 添加关注用户到本地数据库
WxUser wxUser = wxUserMapper.selectOne(Wrappers.<WxUser>lambdaQuery().eq(WxUser::getOpenId, userWxInfo.getOpenId()));
if (wxUser == null) {
// 第一次关注
wxUser = new WxUser();
wxUser.setSubscribeNum(1);
setWxUserValue(wxUser, userWxInfo);
// wxUser.setTenantId(wxApp.getTenantId());
wxUserMapper.insert(wxUser);
} else {
// 曾经关注过
wxUser.setSubscribeNum(wxUser.getSubscribeNum() + 1);
setWxUserValue(wxUser, userWxInfo);
// wxUser.setTenantId(wxApp.getTenantId());
wxUserMapper.updateById(wxUser);
}
// 发送关注消息
List<WxAutoReply> listWxAutoReply = wxAutoReplyService.list(Wrappers.<WxAutoReply>query().lambda().eq(WxAutoReply::getType, ConfigConstant.WX_AUTO_REPLY_TYPE_1));
return MsgHandler.getWxMpXmlOutMessage(wxMessage, listWxAutoReply, wxUser, wxMsgService);
}
} catch (Exception e) {
log.error("用户关注出错:" + e.getMessage());
}
return null;
}
}

View File

@@ -0,0 +1,49 @@
package com.starry.admin.modules.weichat.handler;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.starry.admin.modules.weichat.constant.ConfigConstant;
import com.starry.admin.modules.weichat.entity.WxUser;
import com.starry.admin.modules.weichat.mapper.WxUserMapper;
import com.starry.admin.modules.weichat.service.WxMsgService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Map;
/**
* @author admin
*/
@Slf4j
@Component
@AllArgsConstructor
public class UnsubscribeHandler extends AbstractHandler {
private final WxMsgService wxMsgService;
private final WxUserMapper wxUserMapper;
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService wxMpService,
WxSessionManager sessionManager) {
String openId = wxMessage.getFromUser();
log.info("取消关注用户 OPENID: " + openId);
WxUser wxUser = wxUserMapper.selectOne(Wrappers.<WxUser>lambdaQuery()
.eq(WxUser::getOpenId, openId));
if (wxUser != null) {
wxUser.setSubscribe(ConfigConstant.SUBSCRIBE_TYPE_NO);
wxUser.setCancelSubscribeTime(LocalDateTime.now());
wxUserMapper.updateById(wxUser);
// 消息记录
MsgHandler.getWxMpXmlOutMessage(wxMessage, null, wxUser, wxMsgService);
}
return null;
}
}

View File

@@ -0,0 +1,72 @@
package com.starry.admin.modules.weichat.interceptor;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.starry.admin.modules.weichat.config.CommonConstants;
import com.starry.admin.modules.weichat.constant.ConfigConstant;
import com.starry.admin.modules.weichat.constant.MyReturnCode;
import com.starry.admin.modules.weichat.constant.WxMaConstants;
import com.starry.admin.modules.weichat.entity.ThirdSession;
import com.starry.admin.modules.weichat.utils.ThirdSessionHolder;
import com.starry.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* ThirdSession拦截器校验每个请求的ThirdSession
*
* @author admin
*/
@Slf4j
@Component
public class ThirdSessionInterceptor implements HandlerInterceptor {
@Resource
RedisTemplate<String, Object> redisTemplate;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 获取header中的thirdSession
String thirdSessionHeader = request.getHeader(ConfigConstant.HEADER_THIRDSESSION);
if (StrUtil.isNotBlank(thirdSessionHeader)) {
// 获取缓存中的ThirdSession
String key = WxMaConstants.THIRD_SESSION_BEGIN + ":" + thirdSessionHeader;
Object thirdSessionObj = redisTemplate.opsForValue().get(key);
if (thirdSessionObj == null) {
// session过期
R r = R.error(MyReturnCode.ERR_60001.getCode(), MyReturnCode.ERR_60001.getMsg());
this.writerPrint(response, r);
return Boolean.FALSE;
} else {
String thirdSessionStr = String.valueOf(thirdSessionObj);
ThirdSession thirdSession = JSONUtil.toBean(thirdSessionStr, ThirdSession.class);
// 设置thirdSession
ThirdSessionHolder.setThirdSession(thirdSession);
}
} else {
R r = R.error(MyReturnCode.ERR_60002.getCode(), MyReturnCode.ERR_60002.getMsg());
this.writerPrint(response, r);
return Boolean.FALSE;
}
return Boolean.TRUE;
}
private void writerPrint(HttpServletResponse response, R r) throws IOException {
// 返回超时错误码,触发小程序重新登录
response.setCharacterEncoding(CommonConstants.UTF8);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
PrintWriter writer = response.getWriter();
writer.print(JSONUtil.parseObj(r));
writer.close();
}
}

View File

@@ -0,0 +1,16 @@
package com.starry.admin.modules.weichat.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starry.admin.modules.weichat.entity.WxAutoReply;
/**
* 消息自动回复
*
* @author admin
* @since 2019-04-18 15:40:39
*/
public interface WxAutoReplyMapper extends BaseMapper<WxAutoReply> {
}

View File

@@ -0,0 +1,15 @@
package com.starry.admin.modules.weichat.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starry.admin.modules.weichat.entity.WxMenu;
/**
* 自定义菜单
*
* @author admin
* @since 2019-03-27 16:52:10
*/
public interface WxMenuMapper extends BaseMapper<WxMenu> {
}

View File

@@ -0,0 +1,28 @@
package com.starry.admin.modules.weichat.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.starry.admin.modules.weichat.entity.WxMsg;
import com.starry.admin.modules.weichat.entity.WxMsgVO;
import org.apache.ibatis.annotations.Param;
/**
* 微信消息
*
* @author admin
* @since 2019-05-28 16:12:10
*/
public interface WxMsgMapper extends BaseMapper<WxMsg> {
/**
* 获取分组后的消息列表
*
* @param page
* @param wxMsgVO
* @return
*/
IPage listWxMsgMapGroup(Page<WxMsg> page, @Param("query") WxMsgVO wxMsgVO);
}

View File

@@ -0,0 +1,15 @@
package com.starry.admin.modules.weichat.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starry.admin.modules.weichat.entity.WxUser;
/**
* 微信用户
*
* @author admin
* @since 2019-03-25 15:39:39
*/
public interface WxUserMapper extends BaseMapper<WxUser> {
}

View File

@@ -0,0 +1,15 @@
package com.starry.admin.modules.weichat.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.weichat.entity.WxAutoReply;
/**
* 消息自动回复
*
* @author admin
* @since 2019-04-18 15:40:39
*/
public interface WxAutoReplyService extends IService<WxAutoReply> {
}

View File

@@ -0,0 +1,29 @@
package com.starry.admin.modules.weichat.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.weichat.entity.WxMenu;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 自定义菜单
*
* @author admin
* @since 2019-03-27 16:52:10
*/
public interface WxMenuService extends IService<WxMenu> {
/***
* 获取WxApp下的菜单
* @return
*/
String getWxMenuButton();
/**
* 保存并发布菜单
*
* @param
*/
void saveAndRelease(String strWxMenu) throws WxErrorException;
}

View File

@@ -0,0 +1,26 @@
package com.starry.admin.modules.weichat.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.weichat.entity.WxMsg;
import com.starry.admin.modules.weichat.entity.WxMsgVO;
/**
* 微信消息
*
* @author admin
* @since 2019-05-28 16:12:10
*/
public interface WxMsgService extends IService<WxMsg> {
/**
* 获取分组后的消息列表
*
* @param page
* @param wxMsgVO
* @return
*/
IPage<WxMsg> listWxMsgMapGroup(Page<WxMsg> page, WxMsgVO wxMsgVO);
}

View File

@@ -0,0 +1,46 @@
package com.starry.admin.modules.weichat.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.starry.admin.modules.weichat.entity.WxUser;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 微信用户
*
* @author admin
* @since 2019-03-25 15:39:39
*/
public interface WxUserService extends IService<WxUser> {
/**
* 同步微信用户
*/
void synchroWxUser() throws WxErrorException;
/**
* 修改用户备注
*
* @param entity
* @return
*/
boolean updateRemark(WxUser entity) throws WxErrorException;
/**
* 认识标签
*
* @param taggingType
* @param tagId
* @param openIds
* @throws WxErrorException
*/
void tagging(String taggingType, Long tagId, String[] openIds) throws WxErrorException;
/**
* 根据openId获取用户
*
* @param openId
* @return
*/
WxUser getByOpenId(String openId);
}

View File

@@ -0,0 +1,19 @@
package com.starry.admin.modules.weichat.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.weichat.entity.WxAutoReply;
import com.starry.admin.modules.weichat.mapper.WxAutoReplyMapper;
import com.starry.admin.modules.weichat.service.WxAutoReplyService;
import org.springframework.stereotype.Service;
/**
* 消息自动回复
*
* @author admin
* @since 2019-04-18 15:40:39
*/
@Service
public class WxAutoReplyServiceImpl extends ServiceImpl<WxAutoReplyMapper, WxAutoReply> implements WxAutoReplyService {
}

View File

@@ -0,0 +1,164 @@
package com.starry.admin.modules.weichat.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.weichat.config.CommonConstants;
import com.starry.admin.modules.weichat.entity.Menu;
import com.starry.admin.modules.weichat.entity.MenuButton;
import com.starry.admin.modules.weichat.entity.WxMenu;
import com.starry.admin.modules.weichat.mapper.WxMenuMapper;
import com.starry.admin.modules.weichat.service.WxMenuService;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* 自定义菜单
*
* @author admin
* @since 2019-03-27 16:52:10
*/
@Service
@AllArgsConstructor
public class WxMenuServiceImpl extends ServiceImpl<WxMenuMapper, WxMenu> implements WxMenuService {
private final WxMpService wxService;
/***
* 获取WxApp下的菜单树结构
* @return
*/
@Override
public String getWxMenuButton() {
// 查出一级菜单
List<WxMenu> listWxMenu = baseMapper.selectList(Wrappers
.<WxMenu>query().lambda()
.eq(WxMenu::getParentId, CommonConstants.PARENT_ID).orderByAsc(WxMenu::getSort));
Menu menu = new Menu();
List<MenuButton> listMenuButton = new ArrayList<>();
MenuButton menuButton;
List<MenuButton> subButtons;
MenuButton subButton;
if (listWxMenu != null && !listWxMenu.isEmpty()) {
for (WxMenu wxMenu : listWxMenu) {
menuButton = new MenuButton();
menuButton.setName(wxMenu.getName());
String type = wxMenu.getType();
if (StringUtils.isNotBlank(type)) {// 无二级菜单
menuButton.setType(type);
setButtonValue(menuButton, wxMenu);
} else {// 有二级菜单
// 查出二级菜单
List<WxMenu> listWxMenu1 = baseMapper.selectList(Wrappers
.<WxMenu>query().lambda()
.eq(WxMenu::getParentId, wxMenu.getId()).orderByAsc(WxMenu::getSort));
subButtons = new ArrayList<>();
for (WxMenu wxMenu1 : listWxMenu1) {
subButton = new MenuButton();
String type1 = wxMenu1.getType();
subButton.setName(wxMenu1.getName());
subButton.setType(type1);
setButtonValue(subButton, wxMenu1);
subButtons.add(subButton);
}
menuButton.setSub_button(subButtons);
}
listMenuButton.add(menuButton);
}
}
menu.setButton(listMenuButton);
return menu.toString();
}
void setButtonValue(MenuButton menuButton, WxMenu wxMenu) {
menuButton.setKey(wxMenu.getId());
menuButton.setUrl(wxMenu.getUrl());
menuButton.setContent(wxMenu.getContent());
menuButton.setRepContent(wxMenu.getRepContent());
menuButton.setMedia_id(wxMenu.getRepMediaId());
menuButton.setRepType(wxMenu.getRepType());
menuButton.setRepName(wxMenu.getRepName());
menuButton.setAppid(wxMenu.getMaAppId());
menuButton.setPagepath(wxMenu.getMaPagePath());
menuButton.setUrl(wxMenu.getUrl());
menuButton.setRepUrl(wxMenu.getRepUrl());
menuButton.setRepHqUrl(wxMenu.getRepHqUrl());
menuButton.setRepDesc(wxMenu.getRepDesc());
menuButton.setRepThumbMediaId(wxMenu.getRepThumbMediaId());
menuButton.setRepThumbUrl(wxMenu.getRepThumbUrl());
}
/**
* 保存并发布菜单
*
* @param
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void saveAndRelease(String strWxMenu) throws WxErrorException {
Menu menu = Menu.fromJson(strWxMenu);
List<MenuButton> buttons = menu.getButton();
// 先删除
baseMapper.delete(Wrappers
.<WxMenu>query().lambda());
WxMenu wxMenu = null;
WxMenu wxMenu1 = null;
int sort1 = 1;
int sort2 = 1;
// 入库
for (MenuButton menuButton : buttons) {
wxMenu = new WxMenu();
setWxMenuValue(wxMenu, menuButton);
wxMenu.setSort(sort1);
wxMenu.setParentId(CommonConstants.PARENT_ID);
baseMapper.insert(wxMenu);
menuButton.setKey(wxMenu.getId());
sort1++;
for (MenuButton menuButton1 : menuButton.getSub_button()) {
wxMenu1 = new WxMenu();
setWxMenuValue(wxMenu1, menuButton1);
wxMenu1.setSort(sort2);
wxMenu1.setParentId(wxMenu.getId());
baseMapper.insert(wxMenu1);
menuButton1.setKey(wxMenu1.getId());
sort2++;
}
}
// 创建菜单
wxService.getMenuService().menuCreate(menu.toString());
}
void setWxMenuValue(WxMenu wxMenu, MenuButton menuButton) {
wxMenu.setId(menuButton.getKey());
wxMenu.setType(menuButton.getType());
wxMenu.setName(menuButton.getName());
wxMenu.setUrl(menuButton.getUrl());
wxMenu.setRepMediaId(menuButton.getMedia_id());
wxMenu.setRepType(menuButton.getRepType());
wxMenu.setRepName(menuButton.getRepName());
wxMenu.setMaAppId(menuButton.getAppid());
wxMenu.setMaPagePath(menuButton.getPagepath());
wxMenu.setRepContent(menuButton.getRepContent());
wxMenu.setContent(menuButton.getContent());
wxMenu.setRepUrl(menuButton.getRepUrl());
wxMenu.setRepHqUrl(menuButton.getRepHqUrl());
wxMenu.setRepDesc(menuButton.getRepDesc());
wxMenu.setRepThumbMediaId(menuButton.getRepThumbMediaId());
wxMenu.setRepThumbUrl(menuButton.getRepThumbUrl());
menuButton.setRepUrl(null);
menuButton.setRepDesc(null);
menuButton.setRepHqUrl(null);
menuButton.setContent(null);
menuButton.setRepContent(null);
menuButton.setRepType(null);
menuButton.setRepName(null);
menuButton.setRepThumbMediaId(null);
menuButton.setRepThumbUrl(null);
}
}

View File

@@ -0,0 +1,38 @@
package com.starry.admin.modules.weichat.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.weichat.entity.WxMsg;
import com.starry.admin.modules.weichat.entity.WxMsgVO;
import com.starry.admin.modules.weichat.mapper.WxMsgMapper;
import com.starry.admin.modules.weichat.service.WxMsgService;
import org.springframework.stereotype.Service;
/**
* 微信消息
*
* @author admin
* @since 2019-05-28 16:12:10
*/
@Service
public class WxMsgServiceImpl extends ServiceImpl<WxMsgMapper, WxMsg> implements WxMsgService {
@Override
public IPage listWxMsgMapGroup(Page<WxMsg> page, WxMsgVO vo) {
// LambdaQueryWrapper<WxMsg> queryWrapper = new LambdaQueryWrapper<>();
// if (StrUtil.isBlankIfStr(vo.getType())) {
// queryWrapper.eq(WxMsg::getType, vo.getType());
// }
// if (StrUtil.isBlankIfStr(vo.getReadFlag())) {
// queryWrapper.eq(WxMsg::getReadFlag, vo.getReadFlag());
// }
// if (StrUtil.isBlankIfStr(vo.getRepType())) {
// queryWrapper.eq(WxMsg::getRepType, vo.getRepType());
// }
return baseMapper.listWxMsgMapGroup(page, vo);
}
}

Some files were not shown because too many files have changed in this diff Show More