diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseCityController.java b/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseCityController.java new file mode 100644 index 0000000..001554c --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseCityController.java @@ -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 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 list = baseCityService.list(); + ExcelUtil util = new ExcelUtil(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 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 list = baseCityService.list(new LambdaQueryWrapper().eq(BaseCity::getParentId,parentId).orderByAsc(BaseCity::getAreaCode)); + return success(list); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseConfigController.java index 1afdfd4..6bf90a9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseConfigController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseConfigController.java @@ -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()); } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/domain/BaseCity.java b/ruoyi-admin/src/main/java/com/ruoyi/base/domain/BaseCity.java new file mode 100644 index 0000000..7836d61 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/base/domain/BaseCity.java @@ -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; + +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/mapper/BaseCityMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/base/mapper/BaseCityMapper.java new file mode 100644 index 0000000..eb3452c --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/base/mapper/BaseCityMapper.java @@ -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 +{ + IPage queryListPage(@Param("entity") BaseCity entity, Page page); +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/service/IBaseCityService.java b/ruoyi-admin/src/main/java/com/ruoyi/base/service/IBaseCityService.java new file mode 100644 index 0000000..aae511b --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/base/service/IBaseCityService.java @@ -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 +{ + IPage queryListPage(BaseCity pageReqVO, Page page); +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/service/impl/BaseCityServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/base/service/impl/BaseCityServiceImpl.java new file mode 100644 index 0000000..2c2c189 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/base/service/impl/BaseCityServiceImpl.java @@ -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 implements IBaseCityService +{ + @Autowired + private BaseCityMapper baseCityMapper; + + @Override + public IPage queryListPage(BaseCity pageReqVO, Page page) { + return baseCityMapper.queryListPage(pageReqVO, page); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/controller/BusiNoticeController.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/controller/BusiNoticeController.java index c9bbbfc..be9a62b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/controller/BusiNoticeController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/controller/BusiNoticeController.java @@ -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 page = new Page<>(pageNum, pageSize); - IPage list = busiNoticeService.queryListPage(busiNotice,page); + IPage 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 list = new ArrayList<>(Arrays.asList(ids)); return toAjax(busiNoticeService.removeByIds(list)); } + + + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/domain/BusiNotice.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/domain/BusiNotice.java index 5ba686f..caa33c5 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/domain/BusiNotice.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/domain/BusiNotice.java @@ -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; /** 通告明细 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/mapper/BusiNoticeMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/mapper/BusiNoticeMapper.java index eac253c..f4c8d3f 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/mapper/BusiNoticeMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/mapper/BusiNoticeMapper.java @@ -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 { - IPage queryListPage(@Param("entity") BusiNotice entity, Page page); + IPage queryListPage(@Param("entity") BusiNoticeQuery query, Page page); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiNoticeService.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiNoticeService.java index 9a5536f..0d00502 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiNoticeService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiNoticeService.java @@ -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 { - IPage queryListPage(BusiNotice pageReqVO, Page page); /** * 通过用户id查询通告发布记录 @@ -24,4 +24,6 @@ public interface IBusiNoticeService extends IService * @return java.util.List **/ List listByUserId(Long userId); + IPage queryListPage(BusiNoticeQuery query, Page page); + void saveVo(BusiNotice data); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiNoticeServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiNoticeServiceImpl.java index 7abca67..3ede425 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiNoticeServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiNoticeServiceImpl.java @@ -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 queryListPage(BusiNotice pageReqVO, Page page) { - return busiNoticeMapper.queryListPage(pageReqVO, page); + public IPage queryListPage(BusiNoticeQuery query, Page page) { + return busiNoticeMapper.queryListPage(query, page); + } + + @Override + public void saveVo(BusiNotice data) { + //获取当前登录用户 + data.setUserId(SecurityUtils.getUserId()); + this.save(data); } /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/vo/BusiNoticeVo.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/vo/BusiNoticeVo.java new file mode 100644 index 0000000..3528217 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/vo/BusiNoticeVo.java @@ -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; +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/query/BusiNoticeQuery.java b/ruoyi-admin/src/main/java/com/ruoyi/query/BusiNoticeQuery.java new file mode 100644 index 0000000..d6ea620 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/query/BusiNoticeQuery.java @@ -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(); +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index c0d4981..f1f4c2c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -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 roles = permissionService.getRolePermission(user); // 权限集合 Set 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 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; + } } diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 5208fa8..4ad19c1 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -146,3 +146,7 @@ xss: excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* +# 微信小程序配置 +wx-app: + appId: wxd8ef44a8268672e4 + appSecret: 30c18855ceb0ab0f9801407c998199c2 \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/mapper/base/BaseCityMapper.xml b/ruoyi-admin/src/main/resources/mapper/base/BaseCityMapper.xml new file mode 100644 index 0000000..75ffa3c --- /dev/null +++ b/ruoyi-admin/src/main/resources/mapper/base/BaseCityMapper.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + select id, city_id, level, parent_id, area_code, name, merger_name, lng, lat, is_show, create_time, update_time from dl_base_city + + + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/mapper/busi/BusiNoticeMapper.xml b/ruoyi-admin/src/main/resources/mapper/busi/BusiNoticeMapper.xml index 92c019c..24d55e9 100644 --- a/ruoyi-admin/src/main/resources/mapper/busi/BusiNoticeMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/busi/BusiNoticeMapper.xml @@ -1,72 +1,49 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - + 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 - and user_id like concat('%', #{entity.userId}, '%') - and title like concat('%', #{entity.title}, '%') - and platform_name like concat('%', #{entity.platformName}, '%') - and country = #{entity.country} - and fee_down = #{entity.feeDown} - and fee_up = #{entity.feeUp} - and is_self_price = #{entity.isSelfPrice} - and brand = #{entity.brand} - and is_show_brand = #{entity.isShowBrand} - and need_num = #{entity.needNum} - and fans_down = #{entity.fansDown} - and fans_up = #{entity.fansUp} - and is_eligible = #{entity.isEligible} - and pic = #{entity.pic} - and collect = #{entity.collect} - and detail = #{entity.detail} + main.del_flag = '0' + and uTable.nick_name like concat('%', #{entity.userNickName}, '%') + and main.province = #{entity.province} + and main.city = #{entity.city} + and main.title like concat('%', #{entity.title}, '%') + and main.platform_code = #{entity.platformCode} + + + and main.fee_down = ]]> #{entity.params.beginFeeDown} + + + and main.fee_down #{entity.params.endFeeDown} + + + + and main.fans_down = ]]> #{entity.params.beginFansDown} + + + and main.fans_down #{entity.params.endFansDown} + + and main.brand like concat('%', #{entity.brand}, '%') + and main.pic = #{entity.pic} + and main.collect = #{entity.collect} + and main.blogger_types = #{entity.bloggerTypes} + and main.is_use_coupon = #{entity.isUseCoupon} + and main.approval_status = #{entity.approvalStatus} + and main.create_time between #{entity.params.beginCreateTime} and #{entity.params.endCreateTime} - \ No newline at end of file + + diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/WxAppConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/WxAppConfig.java new file mode 100644 index 0000000..b71b960 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/WxAppConfig.java @@ -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; +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java index a685e06..c733e1f 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java @@ -113,7 +113,6 @@ public class BaseController { return AjaxResult.success(message); } - /** * 返回成功消息 */ diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java index a7abfe4..c62ba9c 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java @@ -79,6 +79,16 @@ public class AjaxResult extends HashMap return AjaxResult.success("操作成功", data); } + /** + * 返回成功数据 + * + * @return 成功消息 + */ + public static AjaxResult ok(Object data) + { + return AjaxResult.success("操作成功", data); + } + /** * 返回成功消息 * diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DlBaseEntity.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DlBaseEntity.java index 111bb46..259b629 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DlBaseEntity.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DlBaseEntity.java @@ -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(); + } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java index d169139..37a33a9 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java @@ -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) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java index 670e6b3..c648ea9 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java @@ -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() diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/WxLoginBody.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/WxLoginBody.java new file mode 100644 index 0000000..e6fac8f --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/WxLoginBody.java @@ -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 + '\'' + + '}'; + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java index 1d4dc1f..5f395fa 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ApplicationConfig.java @@ -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(); + } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 511842b..dde0769 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -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)) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index fe16427..7e6382d 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -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); + } + /** * 校验验证码 * diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index 680cab6..588d69d 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -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); } /** diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index 76e1c79..1ecdba9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -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); + } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index 5b2a7f2..e9f5f30 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -15,6 +15,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - 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" + + where u.del_flag = '0' + + and u.open_id = #{openId} + + + and u.user_name = #{phone} + + + \ No newline at end of file