# Conflicts:
#	ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiNoticeService.java
This commit is contained in:
PQZ 2025-03-21 15:18:15 +08:00
commit 36be32db88
30 changed files with 738 additions and 106 deletions

View File

@ -0,0 +1,127 @@
package com.ruoyi.base.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseCity;
import com.ruoyi.base.service.IBaseCityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
/**
* 城市Controller
*
* @author vinjor-m
* @date 2025-03-18
*/
@RestController
@RequestMapping("/base/city")
public class BaseCityController extends BaseController
{
@Autowired
private IBaseCityService baseCityService;
/**
* 查询城市列表
*/
@PreAuthorize("@ss.hasPermi('base:city:list')")
@GetMapping("/list")
public AjaxResult list(BaseCity baseCity)
{
List<BaseCity> list = baseCityService.list();
return success(list);
}
/**
* 导出城市列表
*/
@PreAuthorize("@ss.hasPermi('base:city:export')")
@Log(title = "城市", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, BaseCity baseCity)
{
List<BaseCity> list = baseCityService.list();
ExcelUtil<BaseCity> util = new ExcelUtil<BaseCity>(BaseCity.class);
util.exportExcel(response, list, "城市数据");
}
/**
* 获取城市详细信息
*/
@PreAuthorize("@ss.hasPermi('base:city:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(baseCityService.getById(id));
}
/**
* 新增城市
*/
@PreAuthorize("@ss.hasPermi('base:city:add')")
@Log(title = "城市", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody BaseCity baseCity)
{
return toAjax(baseCityService.save(baseCity));
}
/**
* 修改城市
*/
@PreAuthorize("@ss.hasPermi('base:city:edit')")
@Log(title = "城市", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody BaseCity baseCity)
{
return toAjax(baseCityService.updateById(baseCity));
}
/**
* 删除城市
*/
@PreAuthorize("@ss.hasPermi('base:city:remove')")
@Log(title = "城市", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
List<Long> list = new ArrayList<>(Arrays.asList(ids));
return toAjax(baseCityService.removeByIds(list));
}
/**
* 查询子级城市
* @author vinjor-M
* @date 18:09 2025/3/18
* @param parentId 父级id
* @return com.ruoyi.common.core.domain.AjaxResult
**/
@GetMapping("/listByPid")
public AjaxResult listByPid(@RequestParam(value = "parentId",required = false) Long parentId)
{
if(null==parentId){
parentId = 0L;
}
List<BaseCity> list = baseCityService.list(new LambdaQueryWrapper<BaseCity>().eq(BaseCity::getParentId,parentId).orderByAsc(BaseCity::getAreaCode));
return success(list);
}
}

View File

@ -122,7 +122,7 @@ public class BaseConfigController extends BaseController
if(list.isEmpty()){
error("未查询到相关配置!");
}
return success(list.get(0));
return AjaxResult.ok(list.get(0).getJsonStr());
}
}

View File

@ -0,0 +1,67 @@
package com.ruoyi.base.domain;
import com.ruoyi.common.annotation.Excel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.common.core.domain.DlBaseEntity;
import lombok.*;
import com.ruoyi.common.core.domain.TreeEntity;
/**
* 城市对象 dl_base_city
*
* @author vinjor-m
* @date 2025-03-18
*/
@TableName("dl_base_city")
@Data
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BaseCity
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
@TableId(type = IdType.ASSIGN_UUID)
private Long id;
/** 城市id */
@Excel(name = "城市id")
private Long cityId;
/** 省市级别 */
@Excel(name = "省市级别")
private Long level;
/** 父级id */
@Excel(name = "父级id")
private Long parentId;
/** 区号 */
@Excel(name = "区号")
private String areaCode;
/** 名称 */
@Excel(name = "名称")
private String name;
/** 合并名称 */
@Excel(name = "合并名称")
private String mergerName;
/** 经度 */
@Excel(name = "经度")
private String lng;
/** 纬度 */
@Excel(name = "纬度")
private String lat;
/** 是否展示 */
@Excel(name = "是否展示")
private Integer isShow;
}

View File

@ -0,0 +1,21 @@
package com.ruoyi.base.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.base.domain.BaseCity;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 城市Mapper接口
*
* @author vinjor-m
* @date 2025-03-18
*/
@Mapper
public interface BaseCityMapper extends BaseMapper<BaseCity>
{
IPage<BaseCity> queryListPage(@Param("entity") BaseCity entity, Page<BaseCity> page);
}

View File

@ -0,0 +1,18 @@
package com.ruoyi.base.service;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.base.domain.BaseCity;
/**
* 城市Service接口
*
* @author vinjor-m
* @date 2025-03-18
*/
public interface IBaseCityService extends IService<BaseCity>
{
IPage<BaseCity> queryListPage(BaseCity pageReqVO, Page<BaseCity> page);
}

View File

@ -0,0 +1,30 @@
package com.ruoyi.base.service.impl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.base.mapper.BaseCityMapper;
import com.ruoyi.base.domain.BaseCity;
import com.ruoyi.base.service.IBaseCityService;
/**
* 城市Service业务层处理
*
* @author vinjor-m
* @date 2025-03-18
*/
@Service
public class BaseCityServiceImpl extends ServiceImpl<BaseCityMapper,BaseCity> implements IBaseCityService
{
@Autowired
private BaseCityMapper baseCityMapper;
@Override
public IPage<BaseCity> queryListPage(BaseCity pageReqVO, Page<BaseCity> page) {
return baseCityMapper.queryListPage(pageReqVO, page);
}
}

View File

@ -6,6 +6,7 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.query.BusiNoticeQuery;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -28,7 +29,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
/**
* 通告Controller
*
*
* @author 朱春云
* @date 2025-03-17
*/
@ -44,12 +45,12 @@ public class BusiNoticeController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('busi:notice:list')")
@GetMapping("/list")
public AjaxResult list(BusiNotice busiNotice,
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize)
public AjaxResult list(BusiNoticeQuery query,
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize)
{
Page<BusiNotice> page = new Page<>(pageNum, pageSize);
IPage<BusiNotice> list = busiNoticeService.queryListPage(busiNotice,page);
IPage<BusiNotice> list = busiNoticeService.queryListPage(query,page);
return success(list);
}
@ -84,7 +85,8 @@ public class BusiNoticeController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody BusiNotice busiNotice)
{
return toAjax(busiNoticeService.save(busiNotice));
busiNoticeService.saveVo(busiNotice);
return success();
}
/**
@ -109,4 +111,7 @@ public class BusiNoticeController extends BaseController
List<String> list = new ArrayList<>(Arrays.asList(ids));
return toAjax(busiNoticeService.removeByIds(list));
}
}

View File

@ -12,9 +12,9 @@ import com.ruoyi.common.core.domain.DlBaseEntity;
/**
* 通告对象 dl_busi_notice
*
*
* @author 朱春云
* @date 2025-03-17
* @date 2025-03-18
*/
@TableName("dl_busi_notice")
@Data
@ -40,15 +40,14 @@ public class BusiNotice extends DlBaseEntity
private String title;
/** 平台 */
@Excel(name = "平台")
private String platformCode;
/** 平台名称 */
@Excel(name = "平台名称")
private String platformName;
/** 国家 */
@Excel(name = "国家")
private String country;
/** 省份 */
private String province;
/** 城市 */
private String city;
/** 稿费下限 */
@Excel(name = "稿费下限")
@ -99,12 +98,12 @@ public class BusiNotice extends DlBaseEntity
@Excel(name = "报名是否需符合粉丝要求(0否|1是)")
private Integer isEligible;
/** 图文/视频/不限 */
@Excel(name = "图文/视频/不限")
/** 内容形式 */
@Excel(name = "内容形式")
private String pic;
/** 单品/合集/不限 */
@Excel(name = "单品/合集/不限")
/** 展示形式 */
@Excel(name = "展示形式")
private String collect;
/** 通告明细 */

View File

@ -4,18 +4,19 @@ import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.busi.domain.BusiNotice;
import com.ruoyi.query.BusiNoticeQuery;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 通告Mapper接口
*
*
* @author 朱春云
* @date 2025-03-17
*/
@Mapper
public interface BusiNoticeMapper extends BaseMapper<BusiNotice>
{
IPage<BusiNotice> queryListPage(@Param("entity") BusiNotice entity, Page<BusiNotice> page);
IPage<BusiNotice> queryListPage(@Param("entity") BusiNoticeQuery query, Page<BusiNotice> page);
}

View File

@ -5,16 +5,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.busi.domain.BusiNotice;
import com.ruoyi.query.BusiNoticeQuery;
/**
* 通告Service接口
*
*
* @author 朱春云
* @date 2025-03-17
*/
public interface IBusiNoticeService extends IService<BusiNotice>
{
IPage<BusiNotice> queryListPage(BusiNotice pageReqVO, Page<BusiNotice> page);
/**
* 通过用户id查询通告发布记录
@ -24,4 +24,6 @@ public interface IBusiNoticeService extends IService<BusiNotice>
* @return java.util.List<com.ruoyi.busi.domain.BusiNotice>
**/
List<BusiNotice> listByUserId(Long userId);
IPage<BusiNotice> queryListPage(BusiNoticeQuery query, Page<BusiNotice> page);
void saveVo(BusiNotice data);
}

View File

@ -8,6 +8,8 @@ import com.ruoyi.common.core.domain.DlBaseEntity;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.query.BusiNoticeQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -17,7 +19,7 @@ import com.ruoyi.busi.service.IBusiNoticeService;
/**
* 通告Service业务层处理
*
*
* @author 朱春云
* @date 2025-03-17
*/
@ -28,8 +30,15 @@ public class BusiNoticeServiceImpl extends ServiceImpl<BusiNoticeMapper,BusiNoti
private BusiNoticeMapper busiNoticeMapper;
@Override
public IPage<BusiNotice> queryListPage(BusiNotice pageReqVO, Page<BusiNotice> page) {
return busiNoticeMapper.queryListPage(pageReqVO, page);
public IPage<BusiNotice> queryListPage(BusiNoticeQuery query, Page<BusiNotice> page) {
return busiNoticeMapper.queryListPage(query, page);
}
@Override
public void saveVo(BusiNotice data) {
//获取当前登录用户
data.setUserId(SecurityUtils.getUserId());
this.save(data);
}
/**

View File

@ -0,0 +1,13 @@
package com.ruoyi.busi.vo;
import com.ruoyi.busi.domain.BusiNotice;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
@Data
public class BusiNoticeVo extends BusiNotice {
/**发布者名称**/
private String userNickName;
/** 平台名称 */
private String platformName;
}

View File

@ -0,0 +1,37 @@
package com.ruoyi.query;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
public class BusiNoticeQuery {
/**发布者名称**/
private String userNickName;
/** 标题 */
private String title;
/** 平台 */
private String platformCode;
/** 省份 */
private String province;
/** 城市 */
private String city;
/** 品牌 */
private String brand;
/** 内容形式 */
private String pic;
/** 展示形式 */
private String collect;
/** 是否使用通告券0 否|1是 */
private Integer isUseCoupon;
/** 审核状态 */
private String approvalStatus;
private String bloggerTypes;
/** 查询条件 */
private JSONObject params =new JSONObject();
}

View File

@ -1,7 +1,19 @@
package com.ruoyi.web.controller.system;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.config.WxAppConfig;
import com.ruoyi.common.core.domain.model.WxLoginBody;
import com.ruoyi.common.utils.StringUtils;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -18,6 +30,14 @@ import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.framework.web.service.SysPermissionService;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.service.ISysMenuService;
import org.springframework.web.client.RestTemplate;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
* 登录验证
@ -27,6 +47,11 @@ import com.ruoyi.system.service.ISysMenuService;
@RestController
public class SysLoginController
{
@Autowired
private RestTemplate restTemplate;
@Autowired
private WxAppConfig wxAppConfig;
@Autowired
private SysLoginService loginService;
@ -38,6 +63,45 @@ public class SysLoginController
@Autowired
private TokenService tokenService;
@PostMapping("/wxLogin")
public AjaxResult wxLogin(@RequestBody WxLoginBody wxLoginBody)
{
//获取登录凭证 只能用一次
String code = wxLoginBody.getCode();
//秘钥
String encryptedIv = wxLoginBody.getEncryptedIv();
//加密数据
String encryptedData = wxLoginBody.getEncryptedData();
//想微信服务器发送请求获取用户信息
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxAppConfig.getAppId() + "&secret=" + wxAppConfig.getAppSecret() + "&js_code=" + code + "&grant_type=authorization_code";
String res = restTemplate.getForObject(url, String.class);
JSONObject jsonObject = JSONObject.parseObject(res);
//获取session_key和openid
String sessionKey = jsonObject.getString("session_key");
String openid = jsonObject.getString("openid");
//解密
String decryptResult = "";
try {
//如果没有绑定微信开放平台解析结果是没有unionid的
decryptResult = decrypt(sessionKey,encryptedIv,encryptedData);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("微信登录失败!");
}
if (StringUtils.hasText(decryptResult)){
//如果解析成功,获取token
String token = loginService.wxLogin(openid,decryptResult);
AjaxResult ajax = AjaxResult.success();
ajax.put(Constants.TOKEN, token);
return ajax;
}else{
return AjaxResult.error("微信登录失败!");
}
}
/**
* 登录方法
@ -70,7 +134,7 @@ public class SysLoginController
Set<String> roles = permissionService.getRolePermission(user);
// 权限集合
Set<String> permissions = permissionService.getMenuPermission(user);
if (!loginUser.getPermissions().equals(permissions))
if (null!=loginUser.getPermissions() && !loginUser.getPermissions().equals(permissions))
{
loginUser.setPermissions(permissions);
tokenService.refreshToken(loginUser);
@ -94,4 +158,50 @@ public class SysLoginController
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
return AjaxResult.success(menuService.buildMenus(menus));
}
/**
* AES解密
* @param sessionKey
* @param encryptedIv
* @param encryptedData
*/
public String decrypt(String sessionKey,String encryptedIv,String encryptedData) throws Exception{
// 转化为字节数组
byte[] key = com.sun.org.apache.xerces.internal.impl.dv.util.Base64.decode(sessionKey);
byte[] iv = com.sun.org.apache.xerces.internal.impl.dv.util.Base64.decode(encryptedIv);
byte[] encData = Base64.decode(encryptedData);
// 如果密钥不足16位那么就补足
int base =16;
if (key.length % base !=0) {
int groups = key.length / base +(key.length % base != 0 ? 1 : 0);
byte[] temp = new byte[groups * base];
Arrays.fill(temp,(byte) 0);
System.arraycopy(key,0,temp,0,key.length);
key = temp;
}
// 如果初始向量不足16位也补足
if (iv.length % base !=0) {
int groups = iv.length / base +(iv.length % base != 0 ? 1 : 0);
byte[] temp = new byte[groups * base];
Arrays.fill(temp,(byte) 0);
System.arraycopy(iv,0,temp,0,iv.length);
iv = temp;
}
AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
String resultStr = null;
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(key,"AES");
cipher.init(Cipher.DECRYPT_MODE,keySpec,ivSpec);
resultStr = new String(cipher.doFinal(encData),"UTF-8");
} catch (Exception e){
// logger.info("解析错误");
e.printStackTrace();
}
// 解析加密后的字符串
return resultStr;
}
}

View File

@ -146,3 +146,7 @@ xss:
excludes: /system/notice
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
# 微信小程序配置
wx-app:
appId: wxd8ef44a8268672e4
appSecret: 30c18855ceb0ab0f9801407c998199c2

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.base.mapper.BaseCityMapper">
<resultMap type="BaseCity" id="BaseCityResult">
<result property="id" column="id" />
<result property="cityId" column="city_id" />
<result property="level" column="level" />
<result property="parentId" column="parent_id" />
<result property="areaCode" column="area_code" />
<result property="name" column="name" />
<result property="mergerName" column="merger_name" />
<result property="lng" column="lng" />
<result property="lat" column="lat" />
<result property="isShow" column="is_show" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectBaseCityVo">
select id, city_id, level, parent_id, area_code, name, merger_name, lng, lat, is_show, create_time, update_time from dl_base_city
</sql>
<select id="queryListPage" parameterType="BaseCity" resultMap="BaseCityResult">
<include refid="selectBaseCityVo"/>
<where>
<if test="entity.cityId != null "> and city_id = #{entity.cityId}</if>
<if test="entity.level != null "> and level = #{entity.level}</if>
<if test="entity.parentId != null "> and parent_id = #{entity.parentId}</if>
<if test="entity.areaCode != null and entity.areaCode != ''"> and area_code = #{entity.areaCode}</if>
<if test="entity.name != null and entity.name != ''"> and name like concat('%', #{entity.name}, '%')</if>
<if test="entity.mergerName != null and entity.mergerName != ''"> and merger_name like concat('%', #{entity.mergerName}, '%')</if>
<if test="entity.lng != null and entity.lng != ''"> and lng = #{entity.lng}</if>
<if test="entity.lat != null and entity.lat != ''"> and lat = #{entity.lat}</if>
<if test="entity.isShow != null "> and is_show = #{entity.isShow}</if>
</where>
</select>
</mapper>

View File

@ -1,72 +1,49 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.busi.mapper.BusiNoticeMapper">
<resultMap type="BusiNotice" id="BusiNoticeResult">
<result property="id" column="id" />
<result property="userId" column="user_id" />
<result property="title" column="title" />
<result property="platformCode" column="platform_code" />
<result property="platformName" column="platform_name" />
<result property="country" column="country" />
<result property="feeDown" column="fee_down" />
<result property="feeUp" column="fee_up" />
<result property="isSelfPrice" column="is_self_price" />
<result property="giftDetail" column="gift_detail" />
<result property="giftPrice" column="gift_price" />
<result property="endDate" column="end_date" />
<result property="brand" column="brand" />
<result property="isShowBrand" column="is_show_brand" />
<result property="needNum" column="need_num" />
<result property="fansDown" column="fans_down" />
<result property="fansUp" column="fans_up" />
<result property="isEligible" column="is_eligible" />
<result property="pic" column="pic" />
<result property="collect" column="collect" />
<result property="detail" column="detail" />
<result property="images" column="images" />
<result property="bloggerTypes" column="blogger_types" />
<result property="isShowTel" column="is_show_tel" />
<result property="wechat" column="wechat" />
<result property="tel" column="tel" />
<result property="groupImage" column="group_image" />
<result property="isUseCoupon" column="is_use_coupon" />
<result property="approvalStatus" column="approval_status" />
<result property="approvalUserId" column="approval_user_id" />
<result property="approvalTime" column="approval_time" />
<result property="approvalRemark" column="approval_remark" />
<result property="creator" column="creator" />
<result property="createTime" column="create_time" />
<result property="updater" column="updater" />
<result property="updateTime" column="update_time" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="selectBusiNoticeVo">
select id, user_id, title, platform_code, platform_name, country, fee_down, fee_up, is_self_price, gift_detail, gift_price, end_date, brand, is_show_brand, need_num, fans_down, fans_up, is_eligible, pic, collect, detail, images, blogger_types, is_show_tel, wechat, tel, group_image, is_use_coupon, approval_status, approval_user_id, approval_time, approval_remark, creator, create_time, updater, update_time, del_flag from dl_busi_notice
</sql>
<select id="queryListPage" parameterType="BusiNotice" resultMap="BusiNoticeResult">
<include refid="selectBusiNoticeVo"/>
<select id="queryListPage" parameterType="BusiNotice" resultType="com.ruoyi.busi.vo.BusiNoticeVo">
select main.id, main.user_id, main.title, main.platform_code, main.province, main.city, main.fee_down, main.fee_up, main.is_self_price, main.gift_detail,
main.gift_price, main.end_date, main.brand, main.is_show_brand, main.need_num, main.fans_down, main.fans_up, main.is_eligible, main.pic, main.collect, main.detail, main.images,
main.blogger_types, main.is_show_tel, main.wechat, main.tel, main.group_image, main.is_use_coupon, main.approval_status, main.approval_user_id, main.approval_time,
main.approval_remark, main.creator, main.create_time, main.updater, main.update_time, main.del_flag,
uTable.nick_name as userNickName,
bTable.title as platformName
from dl_busi_notice main
left join sys_user uTable on main.user_id = uTable.user_id
left join dl_base_category bTable on main.platform_code = bTable.code
<where>
<if test="entity.userId != null "> and user_id like concat('%', #{entity.userId}, '%')</if>
<if test="entity.title != null and entity.title != ''"> and title like concat('%', #{entity.title}, '%')</if>
<if test="entity.platformName != null and entity.platformName != ''"> and platform_name like concat('%', #{entity.platformName}, '%')</if>
<if test="entity.country != null and entity.country != ''"> and country = #{entity.country}</if>
<if test="entity.feeDown != null "> and fee_down = #{entity.feeDown}</if>
<if test="entity.feeUp != null "> and fee_up = #{entity.feeUp}</if>
<if test="entity.isSelfPrice != null "> and is_self_price = #{entity.isSelfPrice}</if>
<if test="entity.brand != null and entity.brand != ''"> and brand = #{entity.brand}</if>
<if test="entity.isShowBrand != null "> and is_show_brand = #{entity.isShowBrand}</if>
<if test="entity.needNum != null "> and need_num = #{entity.needNum}</if>
<if test="entity.fansDown != null "> and fans_down = #{entity.fansDown}</if>
<if test="entity.fansUp != null "> and fans_up = #{entity.fansUp}</if>
<if test="entity.isEligible != null "> and is_eligible = #{entity.isEligible}</if>
<if test="entity.pic != null and entity.pic != ''"> and pic = #{entity.pic}</if>
<if test="entity.collect != null and entity.collect != ''"> and collect = #{entity.collect}</if>
<if test="entity.detail != null and entity.detail != ''"> and detail = #{entity.detail}</if>
main.del_flag = '0'
<if test="entity.userNickName != null "> and uTable.nick_name like concat('%', #{entity.userNickName}, '%')</if>
<if test="entity.province != null "> and main.province = #{entity.province}</if>
<if test="entity.city != null "> and main.city = #{entity.city}</if>
<if test="entity.title != null and entity.title != ''"> and main.title like concat('%', #{entity.title}, '%')</if>
<if test="entity.platformCode != null and entity.platformCode != ''"> and main.platform_code = #{entity.platformCode}</if>
<if test="entity.params.beginFeeDown != null and entity.params.beginFeeDown != ''">
and main.fee_down <![CDATA[>= ]]> #{entity.params.beginFeeDown}
</if>
<if test=" entity.params.endFeeDown != null and entity.params.endFeeDown != ''">
and main.fee_down <![CDATA[<= ]]> #{entity.params.endFeeDown}
</if>
<if test="entity.params.beginFansDown != null and entity.params.beginFansDown != ''">
and main.fans_down <![CDATA[>= ]]> #{entity.params.beginFansDown}
</if>
<if test=" entity.params.endFansDown != null and entity.params.endFansDown != ''">
and main.fans_down <![CDATA[<= ]]> #{entity.params.endFansDown}
</if>
<if test="entity.brand != null and entity.brand != ''"> and main.brand like concat('%', #{entity.brand}, '%')</if>
<if test="entity.pic != null and entity.pic != ''"> and main.pic = #{entity.pic}</if>
<if test="entity.collect != null and entity.collect != ''"> and main.collect = #{entity.collect}</if>
<if test="entity.bloggerTypes != null and entity.bloggerTypes != ''"> and main.blogger_types = #{entity.bloggerTypes}</if>
<if test="entity.isUseCoupon != null "> and main.is_use_coupon = #{entity.isUseCoupon}</if>
<if test="entity.approvalStatus != null and entity.approvalStatus != ''"> and main.approval_status = #{entity.approvalStatus}</if>
<if test="entity.params.beginCreateTime != null and entity.params.beginCreateTime != '' and entity.params.endCreateTime != null and entity.params.endCreateTime != ''"> and main.create_time between #{entity.params.beginCreateTime} and #{entity.params.endCreateTime}</if>
</where>
</select>
</mapper>
</mapper>

View File

@ -0,0 +1,16 @@
package com.ruoyi.common.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "wx-app")
@Data
public class WxAppConfig {
/** AppId */
private String appId;
/** AppSecret */
private String appSecret;
}

View File

@ -113,7 +113,6 @@ public class BaseController
{
return AjaxResult.success(message);
}
/**
* 返回成功消息
*/

View File

@ -79,6 +79,16 @@ public class AjaxResult extends HashMap<String, Object>
return AjaxResult.success("操作成功", data);
}
/**
* 返回成功数据
*
* @return 成功消息
*/
public static AjaxResult ok(Object data)
{
return AjaxResult.success("操作成功", data);
}
/**
* 返回成功消息
*

View File

@ -1,5 +1,6 @@
package com.ruoyi.common.core.domain;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
@ -12,7 +13,7 @@ import java.util.Date;
/**
* Entity基类--点亮
*
*
* @author ruoyi
*/
@Data
@ -43,4 +44,8 @@ public class DlBaseEntity implements Serializable
@TableLogic
private String delFlag;
/** 查询条件 */
@TableField(exist = false)
private JSONObject params =new JSONObject();
}

View File

@ -70,6 +70,9 @@ public class SysUser extends BaseEntity
@Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
private Date loginDate;
/** openId */
private String openId;
/** 部门对象 */
@Excels({
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
@ -297,6 +300,13 @@ public class SysUser extends BaseEntity
this.roleId = roleId;
}
public String getOpenId() {
return openId;
}
public void setOpenId(String openId) {
this.openId = openId;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

View File

@ -71,6 +71,9 @@ public class LoginUser implements UserDetails
*/
private SysUser user;
/** openId */
private String openId;
public LoginUser()
{
}
@ -119,6 +122,14 @@ public class LoginUser implements UserDetails
this.token = token;
}
public String getOpenId() {
return openId;
}
public void setOpenId(String openId) {
this.openId = openId;
}
@JSONField(serialize = false)
@Override
public String getPassword()

View File

@ -0,0 +1,24 @@
package com.ruoyi.common.core.domain.model;
import lombok.Data;
@Data
public class WxLoginBody {
/** 临时登录凭证 code 只能使用一次 */
private String code;
/** 偏移量 */
private String encryptedIv;
/** 加密数据 */
private String encryptedData;
@Override
public String toString() {
return "WxLoginBody{" +
"code='" + code + '\'' +
", encryptedIv='" + encryptedIv + '\'' +
", encryptedData='" + encryptedData + '\'' +
'}';
}
}

View File

@ -6,6 +6,7 @@ import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilde
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.client.RestTemplate;
/**
* 程序注解配置
@ -27,4 +28,13 @@ public class ApplicationConfig
{
return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
}
/**
* 远程调用
* @return
*/
@Bean
public RestTemplate restTemplate()
{
return new RestTemplate();
}
}

View File

@ -111,12 +111,14 @@ public class SecurityConfig
.authorizeHttpRequests((requests) -> {
permitAllUrl.getUrls().forEach(url -> requests.antMatchers(url).permitAll());
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
requests.antMatchers("/login", "/register", "/captchaImage").permitAll()
// 静态资源可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();
requests.antMatchers("/login","/wxLogin", "/register", "/captchaImage").permitAll()
//相关配置参数可匿名访问
.antMatchers("/base/config/getConfigByCode").permitAll()
// 静态资源可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();
})
// 添加Logout filter
.logout(logout -> logout.logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler))

View File

@ -1,6 +1,10 @@
package com.ruoyi.framework.web.service;
import javax.annotation.Resource;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
@ -48,6 +52,8 @@ public class SysLoginService
@Autowired
private ISysUserService userService;
@Autowired
private SysUserMapper userMapper;
@Autowired
private ISysConfigService configService;
@ -100,6 +106,62 @@ public class SysLoginService
return tokenService.createToken(loginUser);
}
/**
* 微信登录
*
* @param decryptResult 登录凭证 只能用一次
* @return
*/
public String wxLogin(String openid,String decryptResult){
//字符串转json
JSONObject jsonObject = JSONObject.parseObject(decryptResult);
//手机号
String phone = jsonObject.getString("phoneNumber");
//根据openid判断数据库中是否有该用户
//根据openid查询用户信息
SysUser wxUser = userMapper.selectWxUserByOpenIdOrPhone(openid,null);
if(null==wxUser){
//根据openId没查到再根据手机号查
wxUser = userMapper.selectWxUserByOpenIdOrPhone(null,phone);
}
//如果查不到则新增查到了则更新
SysUser user = new SysUser();
if (wxUser == null) {
// 新增
// 设置姓名 默认使用昵称+随机数防止重复姓名的发生 数据库中把username的长度修改的长一点
user.setUserName(phone);
user.setNickName("微信用户");
user.setOpenId(openid);
user.setPhonenumber(phone);
user.setSex("2");
user.setCreateTime(DateUtils.getNowDate());
//新增 用户
userMapper.insertUser(user);
}else {
//,查到了
if(!"0".equals(wxUser.getStatus())){
//非正常状态无法登录
throw new ServiceException("账号状态异常");
}
// 更新
user = wxUser;
if(!openid.equals(user.getOpenId())){
user.setOpenId(openid);
user.setUpdateTime(DateUtils.getNowDate());
userMapper.updateUser(user);
}
}
//组装token信息
LoginUser loginUser = new LoginUser();
loginUser.setOpenId(openid);
loginUser.setUser(user);
loginUser.setUserId(user.getUserId());
// 生成token
return tokenService.createToken(loginUser);
}
/**
* 校验验证码
*

View File

@ -151,7 +151,9 @@ public class TokenService
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
// 根据uuid将loginUser缓存
String userKey = getTokenKey(loginUser.getToken());
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
// redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
/* vinjor 永不过期,适配小程序*/
redisCache.setCacheObject(userKey, loginUser);
}
/**

View File

@ -124,4 +124,12 @@ public interface SysUserMapper
* @return 结果
*/
public SysUser checkEmailUnique(String email);
/**
* 根据openId或手机号查询用户信息
* @param openId
* @return
*/
public SysUser selectWxUserByOpenIdOrPhone(@Param("openId") String openId,@Param("phone") String phone);
}

View File

@ -15,6 +15,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="avatar" column="avatar" />
<result property="password" column="password" />
<result property="status" column="status" />
<result property="openId" column="open_id" />
<result property="delFlag" column="del_flag" />
<result property="loginIp" column="login_ip" />
<result property="loginDate" column="login_date" />
@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectUserVo">
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status,u.open_id, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
from sys_user u
@ -57,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status,u.open_id, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
where u.del_flag = '0'
<if test="userId != null and userId != 0">
@ -86,7 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status,u.open_id, u.create_time
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id
@ -103,7 +104,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status,u.open_id, u.create_time
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id
@ -154,6 +155,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sex != null and sex != ''">sex,</if>
<if test="password != null and password != ''">password,</if>
<if test="status != null and status != ''">status,</if>
<if test="openId != null and openId != ''">open_id,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
create_time
@ -168,6 +170,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sex != null and sex != ''">#{sex},</if>
<if test="password != null and password != ''">#{password},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="openId != null and openId != ''">#{openId},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate()
@ -185,6 +188,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
<if test="password != null and password != ''">password = #{password},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="openId != null and openId != ''">open_id = #{openId},</if>
<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
<if test="loginDate != null">login_date = #{loginDate},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
@ -216,5 +220,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{userId}
</foreach>
</delete>
</mapper>
<select id="selectWxUserByOpenIdOrPhone" parameterType="String" resultMap="SysUserResult">
<include refid="selectUserVo"/>
where u.del_flag = '0'
<if test="openId!=null and openId!=''">
and u.open_id = #{openId}
</if>
<if test="phone!=null and phone!=''">
and u.user_name = #{phone}
</if>
</select>
</mapper>