Althars123 3 năm trước cách đây
mục cha
commit
3796141c09

+ 110 - 0
twzd-admin/src/main/java/com/miaxis/pc/controller/wx/WxForeverCodeController.java

@@ -0,0 +1,110 @@
+package com.miaxis.pc.controller.wx;
+
+import com.miaxis.common.core.controller.BaseController;
+import com.miaxis.common.core.page.ResponsePageInfo;
+import com.miaxis.wx.domain.WxForeverCode;
+import com.miaxis.wx.service.IWxForeverCodeService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * 【微信永久二维码口令】Controller
+ *
+ * @author miaxis
+ * @date 2022-01-17
+ */
+@RestController
+@RequestMapping("/wx/code")
+@Api(tags={"【pc-微信永久二维码口令】"})
+public class WxForeverCodeController extends BaseController{
+    @Autowired
+    private IWxForeverCodeService wxForeverCodeService;
+
+    /**
+     * 查询微信永久二维码口令列表
+     */
+    @PreAuthorize("@ss.hasPermi('wx:code:list')")
+    @GetMapping("/list")
+    @ApiOperation("查询微信永久二维码口令列表")
+        @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
+            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
+    })
+    public ResponsePageInfo<WxForeverCode> list(@ModelAttribute WxForeverCode wxForeverCode){
+        startPage();
+        List<WxForeverCode> list = wxForeverCodeService.selectWxForeverCodeList(wxForeverCode);
+        return toResponsePageInfo(list);
+    }
+
+//    /**
+//     * 导出微信永久二维码口令列表
+//     */
+//    @PreAuthorize("@ss.hasPermi('wx:code:export')")
+//    @Log(title = "微信永久二维码口令", businessType = BusinessTypeEnum.EXPORT)
+//    @GetMapping("/export")
+//    @ApiOperation("导出微信永久二维码口令列表Excel")
+//    public Response<String> export(@ModelAttribute WxForeverCode wxForeverCode){
+//        List<WxForeverCode> list = wxForeverCodeService.selectWxForeverCodeList(wxForeverCode);
+//        ExcelUtil<WxForeverCode> util = new ExcelUtil<WxForeverCode>(WxForeverCode.class);
+//        return util.exportExcel(list, "code");
+//    }
+
+//    /**
+//     * 获取微信永久二维码口令详细信息
+//     */
+//    @PreAuthorize("@ss.hasPermi('wx:code:query')")
+//    @GetMapping(value = "/{id}")
+//    @ApiOperation("获取微信永久二维码口令详细信息")
+//    public Response<WxForeverCode> getInfo(
+//            @ApiParam(name = "id", value = "微信永久二维码口令参数", required = true)
+//            @PathVariable("id") Long id
+//    ){
+//        return Response.success(wxForeverCodeService.getById(id));
+//    }
+
+//    /**
+//     * 新增微信永久二维码口令
+//     */
+//    @PreAuthorize("@ss.hasPermi('wx:code:add')")
+//    @Log(title = "微信永久二维码口令", businessType = BusinessTypeEnum.INSERT)
+//    @PostMapping
+//    @ApiOperation("新增微信永久二维码口令")
+//    public Response<Integer> add(@RequestBody WxForeverCode wxForeverCode){
+//        return toResponse(wxForeverCodeService.save(wxForeverCode) ? 1 : 0);
+//    }
+//
+//    /**
+//     * 修改微信永久二维码口令
+//     */
+//    @PreAuthorize("@ss.hasPermi('wx:code:edit')")
+//    @Log(title = "微信永久二维码口令", businessType = BusinessTypeEnum.UPDATE)
+//    @PutMapping
+//    @ApiOperation("修改微信永久二维码口令")
+//    public Response<Integer> edit(@RequestBody WxForeverCode wxForeverCode){
+//        return toResponse(wxForeverCodeService.updateById(wxForeverCode) ? 1 : 0);
+//    }
+//
+//    /**
+//     * 删除微信永久二维码口令
+//     */
+//    @PreAuthorize("@ss.hasPermi('wx:code:remove')")
+//    @Log(title = "微信永久二维码口令", businessType = BusinessTypeEnum.DELETE)
+//	@DeleteMapping("/{ids}")
+//    @ApiOperation("删除微信永久二维码口令")
+//    public  Response<Integer> remove(
+//            @ApiParam(name = "ids", value = "微信永久二维码口令ids参数", required = true)
+//            @PathVariable Long[] ids
+//    ){
+//        return toResponse(wxForeverCodeService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+//    }
+}

+ 103 - 0
twzd-service/src/main/java/com/miaxis/wx/domain/WxForeverCode.java

@@ -0,0 +1,103 @@
+package com.miaxis.wx.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.miaxis.common.annotation.Excel;
+import com.miaxis.common.core.domain.BaseBusinessEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+/**
+ * 微信永久二维码口令对象 wx_forever_code
+ *
+ * @author miaxis
+ * @date 2022-01-17
+ */
+@Data
+@TableName("wx_forever_code")
+@ApiModel(value = "WxForeverCode", description = "微信永久二维码口令对象 wx_forever_code")
+public class WxForeverCode extends BaseBusinessEntity{
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */
+    @TableId(value = "id")
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    /** 用户唯一标识(微信) */
+    @Excel(name = "用户唯一标识(微信)")
+    @TableField("openid")
+    @ApiModelProperty(value = "用户唯一标识(微信)")
+    private String openid;
+
+    /** 6位口令 */
+    @Excel(name = "6位口令")
+    @TableField("code")
+    @ApiModelProperty(value = "6位口令")
+    private String code;
+
+    /** 微信昵称 */
+    @Excel(name = "微信昵称")
+    @TableField("nick_name")
+    @ApiModelProperty(value = "微信昵称")
+    private Long nickName;
+
+    /** 状态  1:有效(默认) 0:失效  */
+    @Excel(name = "状态  1:有效(默认) 0:失效 ")
+    @TableField("status")
+    @ApiModelProperty(value = "状态  1:有效(默认) 0:失效 ")
+    private Integer status;
+
+    public void setId(Long id){
+        this.id = id;
+    }
+
+    public Long getId(){
+        return id;
+    }
+    public void setOpenid(String openid){
+        this.openid = openid;
+    }
+
+    public String getOpenid(){
+        return openid;
+    }
+    public void setCode(String code){
+        this.code = code;
+    }
+
+    public String getCode(){
+        return code;
+    }
+    public void setNickName(Long nickName){
+        this.nickName = nickName;
+    }
+
+    public Long getNickName(){
+        return nickName;
+    }
+    public void setStatus(Integer status){
+        this.status = status;
+    }
+
+    public Integer getStatus(){
+        return status;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("id", getId())
+            .append("openid", getOpenid())
+            .append("code", getCode())
+            .append("nickName", getNickName())
+            .append("createTime", getCreateTime())
+            .append("updateTime", getUpdateTime())
+            .append("status", getStatus())
+            .toString();
+    }
+}

+ 23 - 0
twzd-service/src/main/java/com/miaxis/wx/mapper/WxForeverCodeMapper.java

@@ -0,0 +1,23 @@
+package com.miaxis.wx.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.miaxis.wx.domain.WxForeverCode;
+
+import java.util.List;
+
+/**
+ * 微信永久二维码口令Mapper接口
+ *
+ * @author miaxis
+ * @date 2022-01-17
+ */
+public interface WxForeverCodeMapper extends BaseMapper<WxForeverCode> {
+    /**
+     * 查询微信永久二维码口令列表
+     *
+     * @param wxForeverCode 微信永久二维码口令
+     * @return 微信永久二维码口令集合
+     */
+    public List<WxForeverCode> selectWxForeverCodeList(WxForeverCode wxForeverCode);
+
+}

+ 22 - 0
twzd-service/src/main/java/com/miaxis/wx/service/IWxForeverCodeService.java

@@ -0,0 +1,22 @@
+package com.miaxis.wx.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.miaxis.wx.domain.WxForeverCode;
+
+import java.util.List;
+
+/**
+ * 微信永久二维码口令Service接口
+ *
+ * @author miaxis
+ * @date 2022-01-17
+ */
+public interface IWxForeverCodeService extends IService<WxForeverCode>{
+    /**
+     * 查询微信永久二维码口令列表
+     *
+     * @param wxForeverCode 微信永久二维码口令
+     * @return 微信永久二维码口令集合
+     */
+    public List<WxForeverCode> selectWxForeverCodeList(WxForeverCode wxForeverCode);
+}

+ 85 - 0
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxForeverCodeServiceImpl.java

@@ -0,0 +1,85 @@
+package com.miaxis.wx.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.miaxis.wx.domain.WxForeverCode;
+import com.miaxis.wx.mapper.WxForeverCodeMapper;
+import com.miaxis.wx.service.IWxForeverCodeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+import java.util.Random;
+
+/**
+ * 微信永久二维码口令Service业务层处理
+ *
+ * @author miaxis
+ * @date 2022-01-17
+ */
+@Service
+public class WxForeverCodeServiceImpl extends ServiceImpl<WxForeverCodeMapper, WxForeverCode> implements IWxForeverCodeService {
+    @Autowired
+    private WxForeverCodeMapper wxForeverCodeMapper;
+
+    /**
+     * 查询微信永久二维码口令列表
+     *
+     * @param wxForeverCode 微信永久二维码口令
+     * @return 微信永久二维码口令
+     */
+    @Override
+    public List<WxForeverCode> selectWxForeverCodeList(WxForeverCode wxForeverCode){
+        List<WxForeverCode> wxForeverCodes = wxForeverCodeMapper.selectWxForeverCodeList(wxForeverCode);
+        // 若目前无数据,则创建一个
+        if (CollectionUtils.isEmpty(wxForeverCodes)){
+            creatNewCode();
+        }else{
+            //查询未被使用的口令个数,如果等于0 ,创建一个
+            long count = wxForeverCodes.stream().filter(o -> o.getOpenid() == null).count();
+            if (count == 0l){
+                creatNewCode();
+            }
+        }
+        return wxForeverCodeMapper.selectWxForeverCodeList(wxForeverCode);
+    }
+
+    private void creatNewCode() {
+        WxForeverCode newWxForeverCode = new WxForeverCode();
+        String code = null ;
+        do {
+            code  = getRandomString(6);
+        }while (isRepeat(code));
+        newWxForeverCode.setCode(code);
+        this.save(newWxForeverCode);
+    }
+
+    private boolean isRepeat(String code) {
+        QueryWrapper<WxForeverCode> wrapper = new QueryWrapper<WxForeverCode>();
+        wrapper.eq("code",code);
+        WxForeverCode one = this.getOne(wrapper);
+        return one!= null;
+    }
+
+
+    //length用户要求产生字符串的长度
+    public static String getRandomString(int length){
+        String str="abcdefghjkmnpqrstuvwxyz123456789";
+        Random random=new Random();
+        StringBuffer sb=new StringBuffer();
+        int bound = str.length();
+        for(int i=0;i<length;i++){
+            int number=random.nextInt(bound);
+            sb.append(str.charAt(number));
+        }
+        return sb.toString();
+    }
+
+    public static void main(String[] args) {
+        Random random=new Random();
+        for(int i =0 ;i <100;i++){
+            System.out.println(random.nextInt(1));
+        }
+    }
+}

+ 2 - 2
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxMessageEvenServiceImpl.java

@@ -123,7 +123,7 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
 
         //生成带参数二维码ticket(永久)
         WxQrTicket wxQrTicket = new WxQrTicket();
-        wxQrTicket.setExpire_seconds(259200);//3天
+        wxQrTicket.setExpire_seconds(2592000);//30
         wxQrTicket.setAction_name("QR_SCENE");//临时
         JSONObject jsonObject1 = new JSONObject();
         JSONObject jsonObject2 = new JSONObject();
@@ -166,7 +166,7 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
         );
 
         DateTime date = DateUtil.date();
-        Date newDate = DateUtil.offsetDay(date, 365);
+        Date newDate = DateUtil.offsetDay(date, 3);
         String dateStr = DateUtil.format(newDate, "yyyy-MM-dd");
         log.info(dateStr);
 

+ 32 - 0
twzd-service/src/main/resources/mapper/wx/WxForeverCodeMapper.xml

@@ -0,0 +1,32 @@
+<?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.miaxis.wx.mapper.WxForeverCodeMapper">
+
+    <resultMap type="WxForeverCode" id="WxForeverCodeResult">
+        <result property="id"    column="id"    />
+        <result property="openid"    column="openid"    />
+        <result property="code"    column="code"    />
+        <result property="nickName"    column="nick_name"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateTime"    column="update_time"    />
+        <result property="status"    column="status"    />
+    </resultMap>
+
+    <sql id="selectWxForeverCodeVo">
+        select * from wx_forever_code
+    </sql>
+
+    <select id="selectWxForeverCodeList" parameterType="WxForeverCode" resultMap="WxForeverCodeResult">
+        <include refid="selectWxForeverCodeVo"/>
+        <where>
+            <if test="openid != null  and openid != ''"> and openid = #{openid}</if>
+            <if test="code != null  and code != ''"> and code = #{code}</if>
+            <if test="nickName != null "> and nick_name like concat('%', #{nickName}, '%')</if>
+            <if test="status != null "> and status = #{status}</if>
+        </where>
+        order by create_time desc
+    </select>
+
+</mapper>