zhangjinli 3 years ago
commit 460df01518

@ -0,0 +1,44 @@
package com.zh.project0512.controller.wxApp;
import com.zh.project0512.model.dto.AppMessageListDTO;
import com.zh.project0512.model.vo.AppMessageListVo;
import com.zh.project0512.service.IAppMessageService;
import com.zh.project0512.utils.JwtUtil;
import com.zh.project0512.utils.result.ResultPageInfo;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* <p>
* app
* </p>
*
* @author zh
* @since 2022-05-26
*/
@RestController
@RequestMapping("/wxApp/appMessage")
@Tag(name = "app消息")
public class AppMessageController {
@Resource
IAppMessageService appMessageService;
/**
* app
* @param appMessageListDTO app list DTO
* @return app
*/
@GetMapping("/list")
public ResultPageInfo<AppMessageListVo> list(AppMessageListDTO appMessageListDTO,@RequestHeader(value = "token") @Parameter(name = "登录token") String token){
String openid = new JwtUtil().parseOpenid(token);
return ResultPageInfo.success(appMessageService.list(appMessageListDTO,openid),"请求成功");
}
}

@ -0,0 +1,7 @@
package com.zh.project0512.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zh.project0512.model.AppMessage;
public interface AppMessageMapper extends BaseMapper<AppMessage> {
}

@ -0,0 +1,65 @@
package com.zh.project0512.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* app
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("appMessage")
public class AppMessage implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId(value = "id", type = IdType.AUTO)
@TableField("id")
private Integer id;
/**
*
*/
@TableField("type")
private Integer type;
/**
*
*/
@TableField("title")
private String title;
/**
*
*/
@TableField("describe")
private String describe;
/**
* url
*/
@TableField("url")
private String url;
/**
* openid
*/
@TableField("sendId")
private String sendOpenId;
/**
* openid
*/
@TableField("receiverId")
private String receiverOpenId;
/**
*
*/
@TableField("createDate")
private Date createDate;
}

@ -0,0 +1,30 @@
package com.zh.project0512.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* app list DTO
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppMessageListDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
private int pageNum;
/**
*
*/
private int pageSize;
/**
*
*/
private Integer type;
}

@ -0,0 +1,38 @@
package com.zh.project0512.model.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* app list Vo
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppMessageListVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private Integer id;
/**
*
*/
private Integer type;
/**
*
*/
private String title;
/**
*
*/
private String describe;
/**
* url
*/
private String url;
}

@ -0,0 +1,15 @@
package com.zh.project0512.service;
import com.zh.project0512.model.dto.AppMessageListDTO;
import com.zh.project0512.model.vo.AppMessageListVo;
import com.zh.project0512.utils.page.PageInfo;
public interface IAppMessageService {
/**
* app
* @param appMessageListDTO app list DTO
* @param openid openid
* @return app list Vo
*/
PageInfo<AppMessageListVo> list(AppMessageListDTO appMessageListDTO, String openid);
}

@ -0,0 +1,46 @@
package com.zh.project0512.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.project0512.mapper.AppMessageMapper;
import com.zh.project0512.model.AdminRole;
import com.zh.project0512.model.AppMessage;
import com.zh.project0512.model.dto.AppMessageListDTO;
import com.zh.project0512.model.vo.AdminRoleListVo;
import com.zh.project0512.model.vo.AppMessageListVo;
import com.zh.project0512.service.IAppMessageService;
import com.zh.project0512.utils.PropertyUtils;
import com.zh.project0512.utils.page.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class AppMessageServiceImpl implements IAppMessageService {
@Resource
AppMessageMapper appMessageMapper;
@Override
public PageInfo<AppMessageListVo> list(AppMessageListDTO appMessageListDTO, String openid) {
ArrayList<AppMessageListVo> appMessageListVos = new ArrayList<>();
QueryWrapper<AppMessage> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(appMessageListDTO.getType() != null,"type", appMessageListDTO.getType());
Page<AppMessage> page = new Page<>(appMessageListDTO.getPageNum(), appMessageListDTO.getPageSize());
IPage<AppMessage> appMessageIPage = appMessageMapper.selectPage(page, queryWrapper);
List<AppMessage> records = appMessageIPage.getRecords();
if (records != null && records.size()>0){
for (AppMessage record : records) {
AppMessageListVo appMessageListVo = new AppMessageListVo();
PropertyUtils.copyProperties(record, appMessageListVo);
appMessageListVos.add(appMessageListVo);
}
}
return new PageInfo<>(appMessageIPage.getPages(), appMessageListVos, appMessageIPage.getTotal());
}
}

@ -0,0 +1,46 @@
package com.zh.project0512.utils;
import com.zh.project0512.mapper.AppMessageMapper;
import com.zh.project0512.model.AppMessage;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Date;
/**
* app
*/
@Component
public class AppMessageUtil {
@Resource
AppMessageMapper appMessageMapper;
//解决工具类无法调用Dao层数据数据为null
//静态初始化当前类
private static AppMessageUtil appMessageUtil;
//在方法上加上注解@PostConstruct,这样方法就会在bean初始化之后被spring容器执行
@PostConstruct
public void init(){
//声明的静态类=this
appMessageUtil=this;
}
public static Boolean sendMessage(Integer type,String title,String describe,String url,String sendOpenId,String receiverOpenId){
AppMessage appMessage = new AppMessage();
appMessage.setType(type);
appMessage.setTitle(title);
appMessage.setDescribe(describe);
appMessage.setUrl(url);
appMessage.setSendOpenId(sendOpenId);
appMessage.setReceiverOpenId(receiverOpenId);
return sendMessage(appMessage);
}
public static Boolean sendMessage(AppMessage appMessage){
appMessage.setId(null);
appMessage.setCreateDate(new Date());
int insert = appMessageUtil.appMessageMapper.insert(appMessage);
return insert > 0;
}
}
Loading…
Cancel
Save