Merge branch 'dev' into 3.11_院后第二增量

This commit is contained in:
haown 2024-04-18 09:23:29 +08:00
commit 6641504c67
30 changed files with 2138 additions and 18 deletions

View File

@ -26,6 +26,8 @@ xinelu:
script-file-url: /scriptFileUrl
# 获取管理端富文本的上传路径
rich-text-picture-url: /richTextPictureUrl
# 资讯富文本的上传路径
info-rich-text-picture-url: /infoRichTextPictureUrl
# 开发环境配置
server:
@ -103,7 +105,7 @@ token:
# 令牌有效期默认30分钟
expireTime: 30
# 请求拦截白名单
ant-matchers: /postDischarge/**,/testMobile/**
ant-matchers: /postDischarge/**,/testMobile/**,/postDischargeApplet/**
## MyBatis-Plus配置
mybatis-plus:

View File

@ -71,6 +71,11 @@ public class SystemBusinessConfig {
*/
private String scriptFileUrl;
/**
* 资讯图片地址
*/
private String infoRichTextPictureUrl;
/**
* 获取管理端富文本的上传路径
*/
@ -206,4 +211,12 @@ public class SystemBusinessConfig {
public void setRichTextPictureUrl(String richTextPictureUrl) {
this.richTextPictureUrl = richTextPictureUrl;
}
public String getInfoRichTextPictureUrl() {
return infoRichTextPictureUrl;
}
public void setInfoRichTextPictureUrl(String infoRichTextPictureUrl) {
this.infoRichTextPictureUrl = infoRichTextPictureUrl;
}
}

View File

@ -283,4 +283,49 @@ public class Constants {
* 成功
*/
public static final int SUCCESS_ERROR_CODE = 0;
/**
* 院后微信小程序登录接口地址
*/
public static final String APPLET_LOGIN_URL = "https://api.weixin.qq.com/sns/jscode2session";
/**
* 微信小程序ACCESS_TOKEN前缀
*/
public static final String POST_DISCHARGE_APPLET_ACCESS_TOKEN = "POST_Discharge_APPLET_ACCESS_TOKEN_";
/**
* 返回成功状态码
*/
public static final int SUCCESS_CODE = 0;
/**
* 院后微信小程序获取用户手机号接口地址
*/
public static final String PHONE_NUMBER_URL = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=";
/**
* 获取微信小程序access_token错误码
*/
public static final int ERROR_ACCESS_CODE = 40001;
/**
* 返回成功状态码
*/
public static final String OK = "ok";
/**
* 资讯分类编码前缀
*/
public static final String INFO_CATEGORY_CODE = "ICC";
/**
* 资讯编码前缀
*/
public static final String INFO_CODE = "IC";
/**
* 科室编码前缀
*/
public static final String DEPARTMENT_CODE = "HDC";
}

View File

@ -4,6 +4,7 @@ import com.xinelu.common.config.SystemBusinessConfig;
import com.xinelu.common.utils.DateUtils;
import com.xinelu.common.utils.StringUtils;
import com.xinelu.common.utils.uuid.IdUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
@ -13,6 +14,10 @@ import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 文件处理工具类
@ -22,6 +27,16 @@ import java.nio.charset.StandardCharsets;
public class FileUtils {
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
/**
* 匹配content中的<img />标签
**/
private static final String PATTEN_IMG = "<(img|IMG)(.*?)(/>|></img>|>)";
/**
* 匹配<img />标签中的src
**/
private static final String PATTEN_SRC = "(src|SRC)=(\"|\')(.*?)(\"|\')";
/**
* 输出指定文件的byte数组
*
@ -243,4 +258,39 @@ public class FileUtils {
return baseName;
}
/**
* 获取img标签中的src值
*
* @param content img的内容
* @return List<String>
*/
public static List<String> getImgSrc(String content) {
if (StringUtils.isBlank(content)) {
return Lists.newArrayList();
}
List<String> list = new ArrayList<>();
//开始匹配content中的<img />标签
Pattern pImg = Pattern.compile(PATTEN_IMG);
Matcher mImg = pImg.matcher(content);
boolean resultImg = mImg.find();
if (resultImg) {
while (resultImg) {
//获取到匹配的<img />标签中的内容
String strImg = mImg.group(2);
//开始匹配<img />标签中的src
Pattern pSrc = Pattern.compile(PATTEN_SRC);
Matcher mSrc = pSrc.matcher(strImg);
if (mSrc.find()) {
String strSrc = mSrc.group(3);
if (StringUtils.isNotBlank(strSrc)) {
list.add(strSrc);
}
}
//匹配content中是否存在下一个<img />标签有则继续以上步骤匹配<img />标签中的src
resultImg = mImg.find();
}
}
return list;
}
}

View File

@ -0,0 +1,113 @@
package com.xinelu.manage.controller.info;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import com.xinelu.manage.service.infocategory.IInfoCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.manage.domain.info.Info;
import com.xinelu.manage.service.info.IInfoService;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
* 资讯信息Controller
*
* @author xinelu
* @date 2024-04-11
*/
@Slf4j
@RestController
@RequestMapping("/manage/info")
public class InfoController extends BaseController {
@Resource
private IInfoService infoService;
@Resource
private IInfoCategoryService infoCategoryService;
/**
* 查询资讯信息列表
*/
@PreAuthorize("@ss.hasPermi('manage:info:list')")
@GetMapping("/list")
public TableDataInfo list(Info info) {
startPage();
List<Info> list = infoService.selectInfoList(info);
return getDataTable(list);
}
/**
* 导出资讯信息列表
*/
@PreAuthorize("@ss.hasPermi('manage:info:export')")
@Log(title = "资讯信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Info info) {
List<Info> list = infoService.selectInfoList(info);
ExcelUtil<Info> util = new ExcelUtil<>(Info.class);
util.exportExcel(response, list, "资讯信息数据");
}
/**
* 获取资讯信息详细信息
*/
@PreAuthorize("@ss.hasPermi('manage:info:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(infoService.selectInfoById(id));
}
/**
* 新增资讯信息
*/
@PreAuthorize("@ss.hasPermi('manage:info:add')")
@Log(title = "资讯信息", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(@RequestBody Info info) {
return toAjax(infoService.insertInfo(info));
}
/**
* 修改资讯信息
*/
@PreAuthorize("@ss.hasPermi('manage:info:edit')")
@Log(title = "资讯信息", businessType = BusinessType.UPDATE)
@PutMapping("/edit")
public AjaxResult edit(@RequestBody Info info) {
return infoService.updateInfo(info);
}
/**
* 删除资讯信息
*/
@PreAuthorize("@ss.hasPermi('manage:info:remove')")
@Log(title = "资讯信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return infoService.deleteInfoByIds(ids);
}
@Log(title = "图片文件上传", businessType = BusinessType.OTHER)
@PostMapping("/picUpload")
public AjaxResult picUpload(@RequestBody MultipartFile file) {
return infoService.picUpload(file);
}
}

View File

@ -0,0 +1,104 @@
package com.xinelu.manage.controller.infocategory;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import com.xinelu.common.custominterface.Insert;
import com.xinelu.manage.dto.infocategory.InfoCategoryDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.manage.domain.infocategory.InfoCategory;
import com.xinelu.manage.service.infocategory.IInfoCategoryService;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.common.core.page.TableDataInfo;
/**
* 资讯分类Controller
*
* @author xinelu
* @date 2024-04-11
*/
@RestController
@RequestMapping("/manage/category")
public class InfoCategoryController extends BaseController {
@Resource
private IInfoCategoryService infoCategoryService;
/**
* 查询资讯分类列表
*/
@PreAuthorize("@ss.hasPermi('manage:category:list')")
@GetMapping("/list")
public TableDataInfo list(InfoCategory infoCategory) {
startPage();
List<InfoCategory> list = infoCategoryService.selectInfoCategoryList(infoCategory);
return getDataTable(list);
}
/**
* 导出资讯分类列表
*/
@PreAuthorize("@ss.hasPermi('manage:category:export')")
@Log(title = "资讯分类", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, InfoCategory infoCategory) {
List<InfoCategory> list = infoCategoryService.selectInfoCategoryList(infoCategory);
ExcelUtil<InfoCategory> util = new ExcelUtil<>(InfoCategory.class);
util.exportExcel(response, list, "资讯分类数据");
}
/**
* 获取资讯分类详细信息
*/
@PreAuthorize("@ss.hasPermi('manage:category:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(infoCategoryService.selectInfoCategoryById(id));
}
/**
* 新增资讯分类
*/
@PreAuthorize("@ss.hasPermi('manage:category:add')")
@Log(title = "资讯分类", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(@RequestBody @Validated(Insert.class) InfoCategoryDTO infoCategoryDTO) {
return infoCategoryService.insertInfoCategory(infoCategoryDTO);
}
/**
* 修改资讯分类
*/
@PreAuthorize("@ss.hasPermi('manage:category:edit')")
@Log(title = "资讯分类", businessType = BusinessType.UPDATE)
@PutMapping("/edit")
public AjaxResult edit(@RequestBody InfoCategory infoCategory) {
return infoCategoryService.updateInfoCategory(infoCategory);
}
/**
* 删除资讯分类
*/
@PreAuthorize("@ss.hasPermi('manage:category:remove')")
@Log(title = "资讯分类", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(infoCategoryService.deleteInfoCategoryByIds(ids));
}
}

View File

@ -0,0 +1,152 @@
package com.xinelu.manage.domain.info;
import java.time.LocalDateTime;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.xinelu.common.annotation.Excel;
import com.xinelu.common.core.domain.BaseEntity;
/**
* 资讯信息对象 info
*
* @author xinelu
* @date 2024-04-11
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "资讯信息对象", description = "info")
public class Info extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
private Long id;
/**
* 资讯所属分类id
*/
@ApiModelProperty(value = "资讯所属分类id")
@Excel(name = "资讯所属分类id")
private Long infoCategoryId;
/**
* 资讯所属分类id
*/
@ApiModelProperty(value = "资讯列别名称")
@Excel(name = "资讯类别名称")
private String infoCategoryName;
/**
* 资讯标题
*/
@ApiModelProperty(value = "资讯标题")
@Excel(name = "资讯标题")
private String infoTitle;
/**
* 资讯编码
*/
@ApiModelProperty(value = "资讯编码")
@Excel(name = "资讯编码")
private String infoCode;
/**
* 资讯图文内容富文本
*/
@ApiModelProperty(value = "资讯图文内容,富文本")
@Excel(name = "资讯图文内容,富文本")
private String infoContent;
/**
* 咨询点击次数
*/
@ApiModelProperty(value = "资讯点击次数")
@Excel(name = "咨询点击次数")
private Long infoClickCount;
/**
* 资讯跳转路径
*/
@ApiModelProperty(value = "资讯跳转路径")
@Excel(name = "资讯跳转路径")
private String infoJumpLink;
/**
* 资讯大图地址
*/
@ApiModelProperty(value = "资讯大图地址")
@Excel(name = "资讯大图地址")
private String infoLargePictureUrl;
/**
* 资讯排序
*/
@ApiModelProperty(value = "资讯排序")
@Excel(name = "资讯排序")
private Long infoSort;
/**
* 资讯创建人
*/
@ApiModelProperty(value = "资讯创建人")
@Excel(name = "资讯创建人")
private String infoCreator;
/**
* 资讯创建时间
*/
@ApiModelProperty(value = "资讯创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "资讯创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime infoCreateTime;
/**
* 资讯修改人
*/
@ApiModelProperty(value = "资讯修改人")
@Excel(name = "资讯修改人")
private String infoReviser;
/**
* 资讯修改时间
*/
@ApiModelProperty(value = "资讯修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "资讯修改时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime infoModifyTime;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("infoCategoryId", getInfoCategoryId())
.append("infoCategoryName", getInfoCategoryName())
.append("infoTitle", getInfoTitle())
.append("infoCode", getInfoCode())
.append("infoContent", getInfoContent())
.append("infoClickCount", getInfoClickCount())
.append("infoJumpLink", getInfoJumpLink())
.append("infoLargePictureUrl", getInfoLargePictureUrl())
.append("infoSort", getInfoSort())
.append("infoCreator", getInfoCreator())
.append("infoCreateTime", getInfoCreateTime())
.append("infoReviser", getInfoReviser())
.append("infoModifyTime", getInfoModifyTime())
.toString();
}
}

View File

@ -0,0 +1,81 @@
package com.xinelu.manage.domain.infocategory;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xinelu.common.annotation.Excel;
import com.xinelu.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.time.LocalDateTime;
import java.util.Date;
/**
* 资讯分类对象 info_category
*
* @author xinelu
* @date 2024-04-11
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "资讯分类对象", description = "info_category")
public class InfoCategory extends BaseEntity
{
private static final long serialVersionUID=1L;
/** 主键id */
private Long id;
/** 资讯分类编码 */
@ApiModelProperty(value = "资讯分类编码")
@Excel(name = "资讯分类编码")
private String infoCategoryCode;
/** 资讯分类名称 */
@ApiModelProperty(value = "资讯分类名称")
@Excel(name = "资讯分类名称")
private String infoCategoryName;
/** 资讯分类类型 */
@ApiModelProperty(value = "资讯分类类型")
@Excel(name = "资讯分类类型")
private String infoCategoryType;
/** 资讯分类排序 */
@ApiModelProperty(value = "资讯分类排序")
@Excel(name = "资讯分类排序")
private Long infoCategorySort;
/** 资讯创建人 */
@ApiModelProperty(value = "资讯创建人")
@Excel(name = "资讯创建人")
private String infoCategoryCreator;
/** 资讯创建时间 */
@ApiModelProperty(value = "资讯创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "资讯创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime infoCategoryCreateTime;
@Override
public String toString(){
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id",getId())
.append("infoCategoryCode",getInfoCategoryCode())
.append("infoCategoryName",getInfoCategoryName())
.append("infoCategoryType",getInfoCategoryType())
.append("infoCategorySort",getInfoCategorySort())
.append("infoCategoryCreator",getInfoCategoryCreator())
.append("infoCategoryCreateTime",getInfoCategoryCreateTime())
.toString();
}
}

View File

@ -0,0 +1,17 @@
package com.xinelu.manage.dto.infocategory;
import com.xinelu.manage.domain.infocategory.InfoCategory;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class InfoCategoryDTO implements Serializable {
/**
* 资讯分类对象传入集合
*/
private List<InfoCategory> infoCategoryList;
}

View File

@ -0,0 +1,72 @@
package com.xinelu.manage.mapper.info;
import java.util.List;
import com.xinelu.manage.domain.info.Info;
/**
* 资讯信息Mapper接口
*
* @author xinelu
* @date 2024-04-11
*/
public interface InfoMapper {
/**
* 查询资讯信息
*
* @param id 资讯信息主键
* @return 资讯信息
*/
Info selectInfoById(Long id);
/**
* 查询资讯信息列表
*
* @param info 资讯信息
* @return 资讯信息集合
*/
List<Info> selectInfoList(Info info);
/**
* 新增资讯信息
*
* @param info 资讯信息
* @return 结果
*/
int insertInfo(Info info);
/**
* 修改资讯信息
*
* @param info 资讯信息
* @return 结果
*/
int updateInfo(Info info);
/**
* 删除资讯信息
*
* @param id 资讯信息主键
* @return 结果
*/
int deleteInfoById(Long id);
/**
* 批量删除资讯信息
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
int deleteInfoByIds(Long[] ids);
/**
* 根据id数组查询资讯信息
*
* @param ids 数组
* @return List<Info>
*/
List<Info> selectInfoByIds(Long[] ids);
}

View File

@ -0,0 +1,94 @@
package com.xinelu.manage.mapper.infocategory;
import java.util.List;
import com.xinelu.manage.domain.infocategory.InfoCategory;
/**
* 资讯分类Mapper接口
*
* @author xinelu
* @date 2024-04-11
*/
public interface InfoCategoryMapper {
/**
* 查询资讯分类
*
* @param id 资讯分类主键
* @return 资讯分类
*/
InfoCategory selectInfoCategoryById(Long id);
/**
* 根据名称查询是否存在类型
* @param name
* @return
*/
InfoCategory selectInfoCategoryByName(String name);
/**
* 查询资讯分类列表
*
* @param infoCategory 资讯分类
* @return 资讯分类集合
*/
List<InfoCategory> selectInfoCategoryList(InfoCategory infoCategory);
/**
* 新增资讯分类
*
* @param infoCategory 资讯分类
* @return 结果
*/
int insertInfoCategory(InfoCategory infoCategory);
/**
* 修改资讯分类
*
* @param infoCategory 资讯分类
* @return 结果
*/
int updateInfoCategory(InfoCategory infoCategory);
/**
* 删除资讯分类
*
* @param id 资讯分类主键
* @return 结果
*/
int deleteInfoCategoryById(Long id);
/**
* 批量删除资讯分类
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
int deleteInfoCategoryByIds(Long[] ids);
/**
* 根据分类名称查询重复分类名称
*
* @param categoryNameList 资讯分类名称集合
* @return List<String>
*/
List<String> selectInfoCategoryName(List<String> categoryNameList);
/**
* 批量新增资讯分类
*
* @param infoCategoryList 资讯分类集合
* @return 数量
*/
int insertInfoCategoryList(List<InfoCategory> infoCategoryList);
/**
* 根据分类名称查询重复分类名称
*
* @param infoCategoryName 资讯分类名称
* @return int
**/
int selectInfoCategoryCount(String infoCategoryName);
}

View File

@ -1,6 +1,8 @@
package com.xinelu.manage.mapper.residentinfo;
import com.xinelu.manage.domain.residentinfo.ResidentInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -17,7 +19,7 @@ public interface ResidentInfoMapper {
* @param id 居民信息主键
* @return 居民信息
*/
public ResidentInfo selectResidentInfoById(Long id);
ResidentInfo selectResidentInfoById(Long id);
/**
* 查询居民信息列表
@ -58,4 +60,13 @@ public interface ResidentInfoMapper {
* @return 结果
*/
int deleteResidentInfoByIds(Long[] ids);
/**
* 根据电话号码和微信小程序openid查询居民基本信息
*
* @param phone 手机号
* @param openId 微信小程序openId
* @return 被护理人基本信息
*/
ResidentInfo getResidentInfoByPhoneAndOpenId(@Param("phone") String phone, @Param("openId") String openId);
}

View File

@ -0,0 +1,70 @@
package com.xinelu.manage.service.info;
import java.util.List;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.manage.domain.info.Info;
import org.springframework.web.multipart.MultipartFile;
/**
* 资讯信息Service接口
*
* @author xinelu
* @date 2024-04-11
*/
public interface IInfoService {
/**
* 查询资讯信息
*
* @param id 资讯信息主键
* @return 资讯信息
*/
Info selectInfoById(Long id);
/**
* 查询资讯信息列表
*
* @param info 资讯信息
* @return 资讯信息集合
*/
List<Info> selectInfoList(Info info);
/**
* 新增资讯信息
*
* @param info 资讯信息
* @return 结果
*/
int insertInfo(Info info);
/**
* 修改资讯信息
*
* @param info 资讯信息
* @return 结果
*/
AjaxResult updateInfo(Info info);
/**
* 批量删除资讯信息
*
* @param ids 需要删除的资讯信息主键集合
* @return 结果
*/
AjaxResult deleteInfoByIds(Long[] ids);
/**
* 删除资讯信息信息
*
* @param id 资讯信息主键
* @return 结果
*/
int deleteInfoById(Long id);
/**
* 图片文件上传
* @param file
* @return
*/
AjaxResult picUpload(MultipartFile file);
}

View File

@ -0,0 +1,225 @@
package com.xinelu.manage.service.info.impl;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import com.xinelu.common.config.SystemBusinessConfig;
import com.xinelu.common.constant.Constants;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.exception.ServiceException;
import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.common.utils.codes.GenerateSystemCodeUtil;
import com.xinelu.common.utils.file.FileUploadUtils;
import com.xinelu.common.utils.file.FileUtils;
import io.netty.util.internal.ObjectUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xinelu.manage.mapper.info.InfoMapper;
import com.xinelu.manage.domain.info.Info;
import com.xinelu.manage.service.info.IInfoService;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
/**
* 资讯信息Service业务层处理
*
* @author xinelu
* @date 2024-04-11
*/
@Service
public class InfoServiceImpl implements IInfoService {
@Resource
private InfoMapper infoMapper;
@Resource
private GenerateSystemCodeUtil generateSystemCodeUtil;
@Resource
private SystemBusinessConfig systemBusinessConfig;
/**
* 查询资讯信息
*
* @param id 资讯信息主键
* @return 资讯信息
*/
@Override
public Info selectInfoById(Long id) {
return infoMapper.selectInfoById(id);
}
/**
* 查询资讯信息列表
*
* @param info 资讯信息
* @return 资讯信息
*/
@Override
public List<Info> selectInfoList(Info info) {
return infoMapper.selectInfoList(info);
}
/**
* 新增资讯信息
*
* @param info 资讯信息
* @return 结果
*/
@Override
public int insertInfo(Info info) {
info.setInfoCreateTime(LocalDateTime.now());
info.setInfoCreator(SecurityUtils.getUsername());
info.setInfoCode(Constants.INFO_CODE + generateSystemCodeUtil.generateSystemCode(Constants.INFO_CODE));
return infoMapper.insertInfo(info);
}
/**
* 修改资讯信息
*
* @param info 资讯信息
* @return 结果
*/
@Override
public AjaxResult updateInfo(Info info) {
//根据id查询之前的数据
Info infoByID = infoMapper.selectInfoById(info.getId());
if (Objects.isNull(infoByID)) {
return AjaxResult.error("当前资讯信息不存在,无法修改,请联系管理员!");
}
//添加修改人 修改时间
info.setInfoReviser(SecurityUtils.getUsername());
info.setInfoModifyTime(LocalDateTime.now());
int count = infoMapper.updateInfo(info);
if (count <= 0) {
throw new ServiceException("修改资讯信息失败,请联系管理员!");
}
//如果两个图片不相等删除之前的图片
if (!info.getInfoLargePictureUrl().equals(infoByID.getInfoLargePictureUrl())) {
deletePictureUrl(infoByID.getInfoLargePictureUrl());
}
//遍历修改前后内容相不相等如果不为空且不相等寻找遍历前后图片的差集然后删除.
if (StringUtils.isNotBlank(info.getInfoContent()) && StringUtils.isNotBlank(infoByID.getInfoContent())
&& !info.getInfoContent().equals(infoByID.getInfoContent())) {
//获取图片地址
List<String> infoImgSrc = FileUtils.getImgSrc(info.getInfoContent());
List<String> infoByIDImgSrc = FileUtils.getImgSrc(infoByID.getInfoContent());
//遍历删除图片
List<String> subList = new ArrayList<>(CollectionUtils.subtract(infoImgSrc, infoByIDImgSrc));
for (String picUrl : subList) {
if (StringUtils.isBlank(picUrl)) { //删除富文本图片
continue;
}
//修改路径
String substring = picUrl.substring(picUrl.indexOf("/profile"));
//删除富文本图片
deletePictureUrl(substring);
}
}
return AjaxResult.success();
}
/**
* 批量删除资讯信息
*
* @param ids 需要删除的资讯信息主键
* @return 结果
*/
@Override
public AjaxResult deleteInfoByIds(Long[] ids) {
//查询删除之前数据
List<Info> infoList = infoMapper.selectInfoByIds(ids);
//删除表信息
int count = infoMapper.deleteInfoByIds(ids);
if (count <= 0) {
return AjaxResult.error("删除资讯信息失败!");
}
//筛选资讯主缩略图
List<String> largePicUrlList = infoList.stream().filter(Objects::nonNull).map(Info::getInfoLargePictureUrl).filter(StringUtils::isNotBlank).collect(Collectors.toList());
//删除主图
for (String picUrl : largePicUrlList) {
String substring = picUrl.substring(picUrl.indexOf("/profile"));
//删除富文本图片
deletePictureUrl(substring);
}
//筛选资讯内容
List<String> infoContentList = infoList.stream().filter(Objects::nonNull).map(Info::getInfoLargePictureUrl).filter(StringUtils::isNotBlank).collect(Collectors.toList());
//遍历获取富文本内容图片地址
for (String infoContent : infoContentList) {
List<String> picUrlList = FileUtils.getImgSrc(infoContent);
for (String picUrl : picUrlList) {
if (StringUtils.isBlank(picUrl)) {
continue;
}
//修改路径
String substring = picUrl.substring(picUrl.indexOf("/profile"));
//删除富文本图片
deletePictureUrl(substring);
}
}
return AjaxResult.success();
}
/**
* 删除资讯信息信息
*
* @param id 资讯信息主键
* @return 结果
*/
@Override
public int deleteInfoById(Long id) {
return infoMapper.deleteInfoById(id);
}
/**
* 图片文件上传
*
* @param file
* @return
*/
public AjaxResult picUpload(MultipartFile file) {
try {
return AjaxResult.success(FileUploadUtils.upload(
systemBusinessConfig.getProfile() + systemBusinessConfig.getInfoRichTextPictureUrl(), file));
} catch (IOException e) {
e.printStackTrace();
return AjaxResult.error();
}
}
/**
* 删除资讯站图片地址
*
* @param pictureUrl 资讯站图片地址
* @return void 资讯站图片地址
**/
private void deletePictureUrl(String pictureUrl) {
if (StringUtils.isBlank(pictureUrl)) {
return;
}
String picture = SystemBusinessConfig.getProfile() + systemBusinessConfig.getInfoRichTextPictureUrl() + pictureUrl.replaceAll("/profile", "");
File checkReportNameFile = new File(picture);
if (checkReportNameFile.exists()) {
boolean delete = checkReportNameFile.delete();
if (BooleanUtils.isFalse(delete)) {
throw new ServiceException("图片地址删除失败!");
}
}
}
}

View File

@ -0,0 +1,65 @@
package com.xinelu.manage.service.infocategory;
import java.util.List;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.manage.domain.infocategory.InfoCategory;
import com.xinelu.manage.dto.infocategory.InfoCategoryDTO;
import org.springframework.web.multipart.MultipartFile;
/**
* 资讯分类Service接口
*
* @author xinelu
* @date 2024-04-11
*/
public interface IInfoCategoryService {
/**
* 查询资讯分类
*
* @param id 资讯分类主键
* @return 资讯分类
*/
InfoCategory selectInfoCategoryById(Long id);
/**
* 查询资讯分类列表
*
* @param infoCategory 资讯分类
* @return 资讯分类集合
*/
List<InfoCategory> selectInfoCategoryList(InfoCategory infoCategory);
/**
* 新增资讯分类
*
* @param infoCategoryDTO 资讯分类
* @return 结果
*/
AjaxResult insertInfoCategory(InfoCategoryDTO infoCategoryDTO);
/**
* 修改资讯分类
*
* @param infoCategory 资讯分类
* @return 结果
*/
AjaxResult updateInfoCategory(InfoCategory infoCategory);
/**
* 批量删除资讯分类
*
* @param ids 需要删除的资讯分类主键集合
* @return 结果
*/
int deleteInfoCategoryByIds(Long[] ids);
/**
* 删除资讯分类信息
*
* @param id 资讯分类主键
* @return 结果
*/
int deleteInfoCategoryById(Long id);
}

View File

@ -0,0 +1,157 @@
package com.xinelu.manage.service.infocategory.impl;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import com.xinelu.common.constant.Constants;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.common.utils.codes.GenerateSystemCodeUtil;
import com.xinelu.common.utils.file.FileUploadUtils;
import com.xinelu.manage.dto.infocategory.InfoCategoryDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.xinelu.manage.mapper.infocategory.InfoCategoryMapper;
import com.xinelu.manage.domain.infocategory.InfoCategory;
import com.xinelu.manage.service.infocategory.IInfoCategoryService;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
/**
* 资讯分类Service业务层处理
*
* @author xinelu
* @date 2024-04-11
*/
@Service
public class InfoCategoryServiceImpl implements IInfoCategoryService {
@Resource
private InfoCategoryMapper infoCategoryMapper;
@Resource
private GenerateSystemCodeUtil generateSystemCodeUtil;
/**
* 查询资讯分类
*
* @param id 资讯分类主键
* @return 资讯分类
*/
@Override
public InfoCategory selectInfoCategoryById(Long id) {
return infoCategoryMapper.selectInfoCategoryById(id);
}
/**
* 查询资讯分类列表
*
* @param infoCategory 资讯分类
* @return 资讯分类
*/
@Override
public List<InfoCategory> selectInfoCategoryList(InfoCategory infoCategory) {
return infoCategoryMapper.selectInfoCategoryList(infoCategory);
}
/**
* 新增资讯分类
*
* @param infoCategoryDTO 资讯分类
* @return 结果
*/
@Override
public AjaxResult insertInfoCategory(InfoCategoryDTO infoCategoryDTO) {
//筛选不为空资讯分类名称
List<String> categoryNameList = infoCategoryDTO.getInfoCategoryList().stream().filter(Objects::nonNull).map(InfoCategory::getInfoCategoryName).collect(Collectors.toList());
//资讯分类名称去重
List<String> distinctNameList = infoCategoryDTO.getInfoCategoryList().stream().filter(Objects::nonNull).map(InfoCategory::getInfoCategoryName).distinct().collect(Collectors.toList());
//集合取差集
List<String> subtractNameList = new ArrayList<>(CollectionUtils.subtract(categoryNameList, distinctNameList));
if (subtractNameList.size() > 0) {
return AjaxResult.error("'" + subtractNameList.get(0) + "'重复,请修改后重新录入!");
}
//数据库查询资讯分类名称
List<String> existCategoryName = infoCategoryMapper.selectInfoCategoryName(categoryNameList);
List<String> existRetainAllNameList = new ArrayList<>(CollectionUtils.intersection(distinctNameList, existCategoryName));
if (existRetainAllNameList.size() > 0) {
return AjaxResult.error("'" + existRetainAllNameList.get(0) + "'已存在,请修改后重新录入!");
}
for (InfoCategory infocategory : infoCategoryDTO.getInfoCategoryList()) {
infocategory.setCreateTime(LocalDateTime.now());//设置添加时间
infocategory.setInfoCategoryCreator(SecurityUtils.getUsername());//设置当前的用户
infocategory.setInfoCategoryType(infocategory.getInfoCategoryName());//类型 无用 直接赋值和名称相同
infocategory.setInfoCategoryCode(Constants.INFO_CATEGORY_CODE + generateSystemCodeUtil.generateSystemCode(Constants.DEPARTMENT_CODE));
}
int insertCount = infoCategoryMapper.insertInfoCategoryList(infoCategoryDTO.getInfoCategoryList());
if (insertCount < 0) {
throw new RuntimeException("新增资讯分类信息失败,请联系管理员!");
}
return AjaxResult.success();
}
/**
* 修改资讯分类
*
* @param infoCategory 资讯分类
* @return 结果
*/
@Override
public AjaxResult updateInfoCategory(InfoCategory infoCategory) {
//根据咨询分类id查询数据库
// InfoCategory infoCategoryByName = infoCategoryMapper.selectInfoCategoryByName(infoCategory.getInfoCategoryName());
InfoCategory infoCategoryByName = infoCategoryMapper.selectInfoCategoryById(infoCategory.getId());
if (Objects.isNull(infoCategoryByName)) {
return AjaxResult.error("当前资讯分类信息不存在,无法修改,请联系管理员!");
}
//两名称都不为空且不相等
if (StringUtils.isNotBlank(infoCategory.getInfoCategoryName()) && StringUtils.isNotBlank(infoCategoryByName.getInfoCategoryName()) && !infoCategory.getInfoCategoryName().equals(infoCategoryByName.getInfoCategoryName())) {
int infoCategoryCount = infoCategoryMapper.selectInfoCategoryCount(infoCategory.getInfoCategoryName());//查找要修改的名称是否已经存在了
if (infoCategoryCount > 0) {
return AjaxResult.error("已有该资讯分类信息名称:" + infoCategory.getInfoCategoryName());
}
}
infoCategoryByName.setUpdateTime(LocalDateTime.now());//设置时间
infoCategoryByName.setInfoCategoryName(infoCategory.getInfoCategoryName());//设置名称为修改的名称
infoCategoryByName.setInfoCategorySort(infoCategory.getInfoCategorySort());//设置排序
infoCategoryByName.setUpdateBy(SecurityUtils.getUsername());//设置当前用户
infoCategoryByName.setInfoCategoryType(infoCategory.getInfoCategoryName());//类型
int updateInfoCategory = infoCategoryMapper.updateInfoCategory(infoCategoryByName);//更新到数据库
if (updateInfoCategory < 0) {
return AjaxResult.error("修改资讯分类信息失败,请联系管理员!");
}
return AjaxResult.success();
}
/**
* 批量删除资讯分类
*
* @param ids 需要删除的资讯分类主键
* @return 结果
*/
@Override
public int deleteInfoCategoryByIds(Long[] ids) {
return infoCategoryMapper.deleteInfoCategoryByIds(ids);
}
/**
* * 删除资讯分类信息
*
* @param id 资讯分类主键
* @return 结果
*/
@Override
public int deleteInfoCategoryById(Long id) {
return infoCategoryMapper.deleteInfoCategoryById(id);
}
}

View File

@ -0,0 +1,223 @@
<?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.xinelu.manage.mapper.info.InfoMapper">
<resultMap type="Info" id="InfoResult">
<result property="id" column="id"/>
<result property="infoCategoryId" column="info_category_id"/>
<result property="infoCategoryName" column="info_category_name"/>
<result property="infoTitle" column="info_title"/>
<result property="infoCode" column="info_code"/>
<result property="infoContent" column="info_content"/>
<result property="infoClickCount" column="info_click_count"/>
<result property="infoJumpLink" column="info_jump_link"/>
<result property="infoLargePictureUrl" column="info_large_picture_url"/>
<result property="infoSort" column="info_sort"/>
<result property="infoCreator" column="info_creator"/>
<result property="infoCreateTime" column="info_create_time"/>
<result property="infoReviser" column="info_reviser"/>
<result property="infoModifyTime" column="info_modify_time"/>
</resultMap>
<sql id="selectInfoVo">
select id,
info_category_id,
info_category_name,
info_title,
info_code,
info_content,
info_click_count,
info_jump_link,
info_large_picture_url,
info_sort,
info_creator,
info_create_time,
info_reviser,
info_modify_time
from info
</sql>
<select id="selectInfoList" parameterType="Info" resultMap="InfoResult">
<include refid="selectInfoVo"/>
<where>
<if test="infoCategoryId != null ">
and info_category_id = #{infoCategoryId}
</if>
<if test="infoCategoryName != null ">
and info_category_name = #{infoCategoryName}
</if>
<if test="infoTitle != null and infoTitle != ''">
and info_title = #{infoTitle}
</if>
<if test="infoCode != null and infoCode != ''">
and info_code = #{infoCode}
</if>
<if test="infoContent != null and infoContent != ''">
and info_content = #{infoContent}
</if>
<if test="infoClickCount != null ">
and info_click_count = #{infoClickCount}
</if>
<if test="infoJumpLink != null and infoJumpLink != ''">
and info_jump_link = #{infoJumpLink}
</if>
<if test="infoLargePictureUrl != null and infoLargePictureUrl != ''">
and info_large_picture_url = #{infoLargePictureUrl}
</if>
<if test="infoSort != null ">
and info_sort = #{infoSort}
</if>
<if test="infoCreator != null and infoCreator != ''">
and info_creator = #{infoCreator}
</if>
<if test="infoCreateTime != null ">
and info_create_time = #{infoCreateTime}
</if>
<if test="infoReviser != null and infoReviser != ''">
and info_reviser = #{infoReviser}
</if>
<if test="infoModifyTime != null ">
and info_modify_time = #{infoModifyTime}
</if>
</where>
order by info_sort
</select>
<select id="selectInfoById" parameterType="Long"
resultMap="InfoResult">
<include refid="selectInfoVo"/>
where id = #{id}
</select>
<insert id="insertInfo" parameterType="Info" useGeneratedKeys="true"
keyProperty="id">
insert into info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="infoCategoryId != null">info_category_id,
</if>
<if test="infoCategoryName != null">info_category_name,
</if>
<if test="infoTitle != null">info_title,
</if>
<if test="infoCode != null">info_code,
</if>
<if test="infoContent != null">info_content,
</if>
<if test="infoClickCount != null">info_click_count,
</if>
<if test="infoJumpLink != null">info_jump_link,
</if>
<if test="infoLargePictureUrl != null">info_large_picture_url,
</if>
<if test="infoSort != null">info_sort,
</if>
<if test="infoCreator != null">info_creator,
</if>
<if test="infoCreateTime != null">info_create_time,
</if>
<if test="infoReviser != null">info_reviser,
</if>
<if test="infoModifyTime != null">info_modify_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="infoCategoryId != null">#{infoCategoryId},
</if>
<if test="infoCategoryName != null">#{infoCategoryName},
</if>
<if test="infoTitle != null">#{infoTitle},
</if>
<if test="infoCode != null">#{infoCode},
</if>
<if test="infoContent != null">#{infoContent},
</if>
<if test="infoClickCount != null">#{infoClickCount},
</if>
<if test="infoJumpLink != null">#{infoJumpLink},
</if>
<if test="infoLargePictureUrl != null">#{infoLargePictureUrl},
</if>
<if test="infoSort != null">#{infoSort},
</if>
<if test="infoCreator != null">#{infoCreator},
</if>
<if test="infoCreateTime != null">#{infoCreateTime},
</if>
<if test="infoReviser != null">#{infoReviser},
</if>
<if test="infoModifyTime != null">#{infoModifyTime},
</if>
</trim>
</insert>
<update id="updateInfo" parameterType="Info">
update info
<trim prefix="SET" suffixOverrides=",">
<if test="infoCategoryId != null">info_category_id =
#{infoCategoryId},
</if>
<if test="infoCategoryName != null">info_category_name =
#{infoCategoryName},
</if>
<if test="infoTitle != null">info_title =
#{infoTitle},
</if>
<if test="infoCode != null">info_code =
#{infoCode},
</if>
<if test="infoContent != null">info_content =
#{infoContent},
</if>
<if test="infoClickCount != null">info_click_count =
#{infoClickCount},
</if>
<if test="infoJumpLink != null">info_jump_link =
#{infoJumpLink},
</if>
<if test="infoLargePictureUrl != null">info_large_picture_url =
#{infoLargePictureUrl},
</if>
<if test="infoSort != null">info_sort =
#{infoSort},
</if>
<if test="infoCreator != null">info_creator =
#{infoCreator},
</if>
<if test="infoCreateTime != null">info_create_time =
#{infoCreateTime},
</if>
<if test="infoReviser != null">info_reviser =
#{infoReviser},
</if>
<if test="infoModifyTime != null">info_modify_time =
#{infoModifyTime},
</if>
</trim>
where id = #{id}
</update>
<delete id="deleteInfoById" parameterType="Long">
delete
from info
where id = #{id}
</delete>
<delete id="deleteInfoByIds" parameterType="String">
delete from info where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectInfoByIds" resultMap="InfoResult">
<include refid="selectInfoVo"/>
where id in
<foreach item="ids" collection="array" open="(" separator="," close=")">
#{ids}
</foreach>
</select>
</mapper>

View File

@ -0,0 +1,166 @@
<?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.xinelu.manage.mapper.infocategory.InfoCategoryMapper">
<resultMap type="InfoCategory" id="InfoCategoryResult">
<result property="id" column="id"/>
<result property="infoCategoryCode" column="info_category_code"/>
<result property="infoCategoryName" column="info_category_name"/>
<result property="infoCategoryType" column="info_category_type"/>
<result property="infoCategorySort" column="info_category_sort"/>
<result property="infoCategoryCreator" column="info_category_creator"/>
<result property="infoCategoryCreateTime" column="info_category_create_time"/>
</resultMap>
<sql id="selectInfoCategoryVo">
select id, info_category_code, info_category_name, info_category_type, info_category_sort, info_category_creator, info_category_create_time from info_category
</sql>
<select id="selectInfoCategoryList" parameterType="InfoCategory" resultMap="InfoCategoryResult">
<include refid="selectInfoCategoryVo"/>
<where>
<if test="infoCategoryCode != null and infoCategoryCode != ''">
and info_category_code = #{infoCategoryCode}
</if>
<if test="infoCategoryName != null and infoCategoryName != ''">
and info_category_name like concat('%', #{infoCategoryName}, '%')
</if>
<if test="infoCategoryType != null and infoCategoryType != ''">
and info_category_type = #{infoCategoryType}
</if>
<if test="infoCategorySort != null ">
and info_category_sort = #{infoCategorySort}
</if>
<if test="infoCategoryCreator != null and infoCategoryCreator != ''">
and info_category_creator = #{infoCategoryCreator}
</if>
<if test="infoCategoryCreateTime != null ">
and info_category_create_time = #{infoCategoryCreateTime}
</if>
</where>
order by info_category_sort
</select>
<select id="selectInfoCategoryByName" parameterType="String" resultMap="InfoCategoryResult">
<include refid="selectInfoCategoryVo"/>
where info_category_name = #{info_category_name}
</select>
<select id="selectInfoCategoryById" parameterType="Long" resultMap="InfoCategoryResult">
<include refid="selectInfoCategoryVo"/>
where id = #{id}
</select>
<insert id="insertInfoCategory" parameterType="InfoCategory" useGeneratedKeys="true"
keyProperty="id">
insert into info_category
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="infoCategoryCode != null">info_category_code,
</if>
<if test="infoCategoryName != null">info_category_name,
</if>
<if test="e != null">info_category_type,
</if>
<if test="infoCategorySort != null">info_category_sort,
</if>
<if test="infoCategoryCreator != null">info_category_creator,
</if>
<if test="infoCategoryCreateTime != null">info_category_create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="infoCategoryCode != null">#{infoCategoryCode},
</if>
<if test="infoCategoryName != null">#{infoCategoryName},
</if>
<if test="infoCategoryType != null">#{infoCategoryType},
</if>
<if test="infoCategorySort != null">#{infoCategorySort},
</if>
<if test="infoCategoryCreator != null">#{infoCategoryCreator},
</if>
<if test="infoCategoryCreateTime != null">#{infoCategoryCreateTime},
</if>
</trim>
</insert>
<update id="updateInfoCategory" parameterType="InfoCategory">
update info_category
<trim prefix="SET" suffixOverrides=",">
<if test="infoCategoryCode != null">info_category_code =
#{infoCategoryCode},
</if>
<if test="infoCategoryName != null">info_category_name =
#{infoCategoryName},
</if>
<if test="infoCategoryType != null">info_category_type =
#{infoCategoryType},
</if>
<if test="infoCategorySort != null">info_category_sort =
#{infoCategorySort},
</if>
<if test="infoCategoryCreator != null">info_category_creator =
#{infoCategoryCreator},
</if>
<if test="infoCategoryCreateTime != null">info_category_create_time =
#{infoCategoryCreateTime},
</if>
</trim>
where id = #{id}
</update>
<delete id="deleteInfoCategoryById" parameterType="Long">
delete from info_category where id = #{id}
</delete>
<delete id="deleteInfoCategoryByIds" parameterType="String">
delete from info_category where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectInfoCategoryName" resultType="java.lang.String">
select info_category_name from info_category where info_category_name in
<foreach item="categoryNameList" collection="list" open="(" separator="," close=")">
#{categoryNameList}
</foreach>
</select>
<insert id="insertInfoCategoryList">
insert into info_category(
info_category_code,
info_category_name,
info_category_type,
info_category_sort,
info_category_creator,
info_category_create_time
)values
<foreach item="infoCategoryList" index="index" collection="list" separator=",">
(
#{infoCategoryList.infoCategoryCode},
#{infoCategoryList.infoCategoryName},
#{infoCategoryList.infoCategoryType},
#{infoCategoryList.infoCategorySort},
#{infoCategoryList.infoCategoryCreator},
#{infoCategoryList.infoCategoryCreateTime}
)
</foreach>
</insert>
<select id="selectInfoCategoryCount" resultType="int">
SELECT
count( 1 )
FROM
info_category
<where>
<if test="infoCategoryName != null and infoCategoryName != ''">
and info_category_name = #{infoCategoryName}
</if>
</where>
</select>
</mapper>

View File

@ -183,4 +183,18 @@
#{id}
</foreach>
</delete>
<select id="getResidentInfoByPhoneAndOpenId" parameterType="string"
resultType="com.xinelu.manage.domain.residentinfo.ResidentInfo">
<include refid="selectResidentInfoVo" />
<where>
del_flag = 0
<if test="phone != null and phone != ''">
and patient_phone = #{phone}
</if>
<if test="openId != null and openId != ''">
and open_id = #{openId}
</if>
</where>
</select>
</mapper>

View File

@ -0,0 +1,59 @@
package com.xinelu.mobile.controller.appletpersoncenter;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.mobile.service.appletpersoncenter.AppletPersonCenterService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @Description 院后小程序个人中心控制器
* @Author 纪寒
* @Date 2024-04-16 10:49:14
* @Version 1.0
*/
@RestController
@RequestMapping("/postDischargeApplet")
public class AppletPersonCenterController {
@Resource
private AppletPersonCenterService appletPersonCenterService;
/**
* 院后微信小程序一键登录接口
*
* @param loginCode 登录凭证
* @param phoneCode 获取手机号登录凭证
* @return 微信小程序用户登录信息
*/
@GetMapping("/appletLogin")
public AjaxResult appletLogin(@RequestParam("loginCode") String loginCode, @RequestParam("phoneCode") String phoneCode) {
if (StringUtils.isBlank(loginCode)) {
return AjaxResult.error("登录凭证编码不能为空!");
}
if (StringUtils.isBlank(phoneCode)) {
return AjaxResult.error("用户手机号凭证不存在");
}
return appletPersonCenterService.appletLogin(loginCode, phoneCode);
}
/**
* 根据居民表id查询患者个人信息
*
* @param residentId 居民表id
* @return 个人信息
*/
@GetMapping("/getResidentInfoById")
public AjaxResult getResidentInfoById(Long residentId) {
return appletPersonCenterService.getResidentInfoById(residentId);
}
@GetMapping("/test")
public void test() {
appletPersonCenterService.test();
}
}

View File

@ -0,0 +1,39 @@
package com.xinelu.mobile.controller.info;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.manage.domain.info.Info;
import com.xinelu.manage.service.info.IInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import static com.xinelu.common.utils.PageUtils.startPage;
/**
* 微信端获取资讯信息
* 资讯信息Controller
*/
@Slf4j
@RestController
@RequestMapping("/mobile/info")
public class MobileInfoController extends BaseController {
@Resource
private IInfoService infoService;
//@PreAuthorize("@ss.hasPermi('mobile:info:list')")
@GetMapping("/list")
public TableDataInfo list(Info info) {
startPage();
List<Info> list = infoService.selectInfoList(info);
return getDataTable(list);
}
}

View File

@ -0,0 +1,18 @@
package com.xinelu.mobile.mapper.appletpersoncenter;
import com.xinelu.manage.domain.residentinfo.ResidentInfo;
/**
* @Description 院后小程序个人中心Mapper层
* @Author 纪寒
* @Date 2024-04-16 10:49:14
* @Version 1.0
*/
public interface AppletPersonCenterMapper {
/**
* 查询居民信息
*
* @return 居民信息
*/
ResidentInfo selectResidentInfoTwo();
}

View File

@ -1,10 +0,0 @@
package com.xinelu.mobile.mapper.mobiletest;
/**
* @Description 测试 Mapper
* @Author 纪寒
* @Date 2024-02-18 16:59:30
* @Version 1.0
*/
public interface MobileTestMapper {
}

View File

@ -0,0 +1,31 @@
package com.xinelu.mobile.service.appletpersoncenter;
import com.xinelu.common.core.domain.AjaxResult;
/**
* @Description 院后小程序个人中心业务层
* @Author 纪寒
* @Date 2024-04-16 10:51:28
* @Version 1.0
*/
public interface AppletPersonCenterService {
/**
* 院后微信小程序一键登录接口
*
* @param loginCode 登录凭证
* @param phoneCode 获取手机号登录凭证
* @return 微信小程序用户登录信息
*/
AjaxResult appletLogin(String loginCode, String phoneCode);
/**
* 根据居民表id查询患者个人信息
*
* @param residentId 居民表id
* @return 个人信息
*/
AjaxResult getResidentInfoById(Long residentId);
void test();
}

View File

@ -0,0 +1,131 @@
package com.xinelu.mobile.service.appletpersoncenter.Impl;
import com.xinelu.common.config.WeChatAppletChatConfig;
import com.xinelu.common.constant.Constants;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.manage.domain.residentinfo.ResidentInfo;
import com.xinelu.manage.mapper.residentinfo.ResidentInfoMapper;
import com.xinelu.mobile.mapper.appletpersoncenter.AppletPersonCenterMapper;
import com.xinelu.mobile.service.appletpersoncenter.AppletPersonCenterService;
import com.xinelu.mobile.utils.WeChatAppletUtils;
import com.xinelu.mobile.vo.appletpersoncenter.PostDischargeAppletPhoneVO;
import com.xinelu.mobile.vo.appletpersoncenter.PostDischargeAppletVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* @Description 院后小程序个人中心业务层实现类
* @Author 纪寒
* @Date 2024-04-16 10:52:09
* @Version 1.0
*/
@Service
@Slf4j
public class AppletPersonCenterServiceImpl implements AppletPersonCenterService {
@Resource
private WeChatAppletUtils weChatAppletUtils;
@Resource
private WeChatAppletChatConfig weChatAppletChatConfig;
@Resource
private RedisTemplate<String, Object> redisTemplate;
@Resource
private ResidentInfoMapper residentInfoMapper;
@Resource
private AppletPersonCenterMapper appletPersonCenterMapper;
/**
* 院后微信小程序一键登录接口
*
* @param loginCode 登录凭证
* @param phoneCode 获取手机号登录凭证
* @return 微信小程序用户登录信息
*/
@Override
public AjaxResult appletLogin(String loginCode, String phoneCode) {
//根据code获取用户的微信unionId以及openId等信息
PostDischargeAppletVO appletLoginInfo = weChatAppletUtils.getPostDischargeAppletLogin(weChatAppletChatConfig.getAppletId(), weChatAppletChatConfig.getSecret(), loginCode, weChatAppletChatConfig.getGrantType());
if (Objects.isNull(appletLoginInfo)) {
return AjaxResult.error("获取院后微信小程序用户信息失败");
}
if (Objects.nonNull(appletLoginInfo.getErrcode()) && appletLoginInfo.getErrcode() != Constants.SUCCESS_CODE) {
return AjaxResult.error("获取院后微信小程序用户信息失败,失败信息为:" + appletLoginInfo.getErrmsg());
}
//获取微信accessToken
String accessToken;
String accessTokenKey = Constants.POST_DISCHARGE_APPLET_ACCESS_TOKEN + "accessToken";
//从Redis中取出accessToken
Object object = redisTemplate.opsForValue().get(accessTokenKey);
if (Objects.isNull(object)) {
accessToken = weChatAppletUtils.getWeChatAppletAccessToken();
} else {
accessToken = (String) object;
}
//获取用户手机号
PostDischargeAppletPhoneVO appletPhoneInfo = weChatAppletUtils.getPostDischargeAppletPhone(phoneCode, accessToken);
if (Objects.isNull(appletPhoneInfo)) {
return AjaxResult.error("获取用户手机号失败");
}
if (Objects.nonNull(appletPhoneInfo.getErrcode()) && appletPhoneInfo.getErrcode() == Constants.ERROR_ACCESS_CODE) {
//当前Redis缓存中的access_token无效直接删除
if (Objects.nonNull(object)) {
redisTemplate.delete(accessTokenKey);
//删除之后重新获取获取accessToken
accessToken = weChatAppletUtils.getWeChatAppletAccessToken();
appletPhoneInfo = weChatAppletUtils.getPostDischargeAppletPhone(phoneCode, accessToken);
if (Objects.isNull(appletPhoneInfo)) {
return AjaxResult.error("获取用户手机号失败");
}
if (Objects.nonNull(appletPhoneInfo.getErrcode()) && appletPhoneInfo.getErrcode() == Constants.ERROR_ACCESS_CODE) {
return AjaxResult.error("登录失败!");
}
}
}
if (StringUtils.isNotBlank(appletPhoneInfo.getErrmsg()) && !Constants.OK.equals(appletPhoneInfo.getErrmsg())) {
return AjaxResult.error("获取用户手机号失败,失败信息为:" + appletPhoneInfo.getErrmsg());
}
//根据手机号和微信小程序openid判断当前用户是否存在
String phone = StringUtils.isBlank(appletPhoneInfo.getPhoneInfo().getPhoneNumber()) ? "" : appletPhoneInfo.getPhoneInfo().getPhoneNumber();
String openId = StringUtils.isBlank(appletLoginInfo.getOpenid()) ? "" : appletLoginInfo.getOpenid();
ResidentInfo residentInfoByPhone = residentInfoMapper.getResidentInfoByPhoneAndOpenId(null, openId);
ResidentInfo residentInfo = new ResidentInfo();
//居民信息为空新增个人信息
if (Objects.isNull(residentInfoByPhone)) {
residentInfo.setOpenId(openId);
residentInfo.setPatientPhone(phone);
residentInfo.setCreateTime(LocalDateTime.now());
residentInfoMapper.insertResidentInfo(residentInfo);
residentInfo.setId(residentInfo.getId());
return AjaxResult.success(residentInfo);
}
//更新居民信息的openid等微信标识信息
residentInfo.setId(residentInfoByPhone.getId());
residentInfo.setOpenId(openId);
residentInfo.setPatientPhone(StringUtils.isBlank(residentInfoByPhone.getPatientPhone()) ? "" : residentInfoByPhone.getPatientPhone());
residentInfo.setUpdateTime(LocalDateTime.now());
residentInfoMapper.updateResidentInfo(residentInfo);
return AjaxResult.success(residentInfo);
}
/**
* 根据居民表id查询患者个人信息
*
* @param residentId 居民表id
* @return 个人信息
*/
@Override
public AjaxResult getResidentInfoById(Long residentId) {
return AjaxResult.success(residentInfoMapper.selectResidentInfoById(residentId));
}
@Override
public void test() {
appletPersonCenterMapper.selectResidentInfoTwo();
}
}

View File

@ -6,11 +6,15 @@ import com.xinelu.common.constant.Constants;
import com.xinelu.common.entity.AccessToken;
import com.xinelu.common.exception.ServiceException;
import com.xinelu.common.utils.http.HttpUtils;
import com.xinelu.mobile.vo.appletpersoncenter.PostDischargeAppletPhoneVO;
import com.xinelu.mobile.vo.appletpersoncenter.PostDischargeAppletVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@ -68,4 +72,50 @@ public class WeChatAppletUtils {
}
return accessToken;
}
/**
* 根据登录编码获取微信小程序用户信息
*
* @param appletId 小程序id
* @param secret 小程序秘钥
* @param code 登录凭证码
* @param grantType 授权类型
* @return 登录信息
*/
public PostDischargeAppletVO getPostDischargeAppletLogin(String appletId, String secret, String code, String grantType) {
//请求地址
String appletLoginUrl = Constants.APPLET_LOGIN_URL
+ "?appid=" + appletId
+ "&secret=" + secret
+ "&js_code=" + code
+ "&grant_type=" + grantType;
//发送请求
String result = HttpUtils.sendGet(appletLoginUrl);
if (StringUtils.isBlank(result)) {
throw new ServiceException("获取院后微信小程序用户信息失败", 201);
}
return JSON.parseObject(result, PostDischargeAppletVO.class);
}
/**
* 获取院后微信小程序的手机号码
*
* @param code 登录凭证
* @param accessToken 小程序accessToken
* @return 手机信息
*/
public PostDischargeAppletPhoneVO getPostDischargeAppletPhone(String code, String accessToken) {
//请求地址
String phoneUrl = Constants.PHONE_NUMBER_URL + accessToken;
//请求参数
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("code", code);
String param = JSON.toJSONString(paramMap);
//发送POST请求
String result = HttpUtils.sendPostJson(phoneUrl, param);
if (StringUtils.isBlank(result)) {
throw new ServiceException("获取院后微信小程序手机号失败", 201);
}
return JSON.parseObject(result, PostDischargeAppletPhoneVO.class);
}
}

View File

@ -0,0 +1,85 @@
package com.xinelu.mobile.vo.appletpersoncenter;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @Description 获取小程序用户手机号实体类
* @Author 纪寒
* @Date 2024-04-16 11:15:53
* @Version 1.0
*/
@NoArgsConstructor
@Data
public class PostDischargeAppletPhoneVO implements Serializable {
private static final long serialVersionUID = 7053513139462975391L;
/**
* 错误编码
* 0成功
* -1系统繁忙此时请开发者稍候再试
* 40029不合法的codecode不存在已过期或者使用过
*/
@JsonProperty("errcode")
private Integer errcode;
/**
* 返回提示信息ok成功
*/
@JsonProperty("errmsg")
private String errmsg;
/**
* 电话信息实体类
*/
@JsonProperty("phone_info")
private PhoneInfoDTO phoneInfo;
@NoArgsConstructor
@Data
public static class PhoneInfoDTO {
/**
* 用户绑定的手机号国外手机号会有区号
*/
@JsonProperty("phoneNumber")
private String phoneNumber;
/**
* 没有区号的手机号
*/
@JsonProperty("purePhoneNumber")
private String purePhoneNumber;
/**
* 区号
*/
@JsonProperty("countryCode")
private Integer countryCode;
/**
* 数据水印
*/
@JsonProperty("watermark")
private WatermarkDTO watermark;
@NoArgsConstructor
@Data
public static class WatermarkDTO {
/**
* 用户获取手机号操作的时间戳
*/
@JsonProperty("timestamp")
private Integer timestamp;
/**
* 小程序appid
*/
@JsonProperty("appid")
private String appid;
}
}
}

View File

@ -0,0 +1,39 @@
package com.xinelu.mobile.vo.appletpersoncenter;
import lombok.Data;
import java.io.Serializable;
/**
* @Description 院后微信小程序用户信息实体类
* @Author 纪寒
* @Date 2024-04-16 10:56:22
* @Version 1.0
*/
@Data
public class PostDischargeAppletVO implements Serializable {
private static final long serialVersionUID = 9163624256938346478L;
/**
* 小程序unionid
*/
private String unionid;
/**
* 小程序openid
*/
private String openid;
/**
* 错误状态码40029js_code无效45011API 调用太频繁请稍候再试
* 40226高风险等级用户小程序登录拦截 -1系统繁忙此时请开发者稍候再试
*/
private Integer errcode;
/**
* 状态信息取值有40029code 无效
* 45011api minute-quota reach limit mustslower retry next minute
* 40226code blocked
* -1system error
*/
private String errmsg;
}

View File

@ -0,0 +1,10 @@
<?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.xinelu.mobile.mapper.appletpersoncenter.AppletPersonCenterMapper">
<select id="selectResidentInfoTwo" resultType="residentInfo">
select id, patient_name, patient_phone from resident_info limit 1
</select>
</mapper>

View File

@ -1,6 +0,0 @@
<?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.xinelu.mobile.mapper.mobiletest.MobileTestMapper">
</mapper>