Add configurable contact page management
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.ruoyi.app.domain;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 小程序联系页面联系方式对象 app_contact_item。
|
||||
*/
|
||||
public class AppContactItem extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
private String type;
|
||||
private String label;
|
||||
private String value;
|
||||
private String iconUrl;
|
||||
private String qrCodeUrl;
|
||||
/** copy复制,qrcode查看二维码 */
|
||||
private String actionType;
|
||||
/** 0启用,1停用 */
|
||||
private String status;
|
||||
private Integer sort;
|
||||
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
public String getLabel() { return label; }
|
||||
public void setLabel(String label) { this.label = label; }
|
||||
public String getValue() { return value; }
|
||||
public void setValue(String value) { this.value = value; }
|
||||
public String getIconUrl() { return iconUrl; }
|
||||
public void setIconUrl(String iconUrl) { this.iconUrl = iconUrl; }
|
||||
public String getQrCodeUrl() { return qrCodeUrl; }
|
||||
public void setQrCodeUrl(String qrCodeUrl) { this.qrCodeUrl = qrCodeUrl; }
|
||||
public String getActionType() { return actionType; }
|
||||
public void setActionType(String actionType) { this.actionType = actionType; }
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public Integer getSort() { return sort; }
|
||||
public void setSort(Integer sort) { this.sort = sort; }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.ruoyi.app.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 小程序联系页面配置对象 app_contact_page。
|
||||
*/
|
||||
public class AppContactPage extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
private String avatarUrl;
|
||||
private String nickname;
|
||||
private String bio;
|
||||
private String backgroundUrl;
|
||||
private List<AppContactItem> contacts = new ArrayList<>();
|
||||
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
public String getAvatarUrl() { return avatarUrl; }
|
||||
public void setAvatarUrl(String avatarUrl) { this.avatarUrl = avatarUrl; }
|
||||
public String getNickname() { return nickname; }
|
||||
public void setNickname(String nickname) { this.nickname = nickname; }
|
||||
public String getBio() { return bio; }
|
||||
public void setBio(String bio) { this.bio = bio; }
|
||||
public String getBackgroundUrl() { return backgroundUrl; }
|
||||
public void setBackgroundUrl(String backgroundUrl) { this.backgroundUrl = backgroundUrl; }
|
||||
public List<AppContactItem> getContacts() { return contacts; }
|
||||
public void setContacts(List<AppContactItem> contacts) { this.contacts = contacts; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ruoyi.app.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.app.domain.AppContactItem;
|
||||
import com.ruoyi.app.domain.AppContactPage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface AppContactMapper
|
||||
{
|
||||
AppContactPage selectAppContactPage();
|
||||
|
||||
List<AppContactItem> selectAppContactItemList(@Param("status") String status);
|
||||
|
||||
int upsertAppContactPage(AppContactPage page);
|
||||
|
||||
int deleteAllAppContactItems();
|
||||
|
||||
int insertAppContactItem(AppContactItem item);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ruoyi.app.service;
|
||||
|
||||
import com.ruoyi.app.domain.AppContactPage;
|
||||
|
||||
public interface IAppContactService
|
||||
{
|
||||
/** 查询后台维护用的完整配置。 */
|
||||
AppContactPage selectAdminContactPage();
|
||||
|
||||
/** 查询小程序展示用的启用配置。 */
|
||||
AppContactPage selectPublicContactPage();
|
||||
|
||||
/** 保存页面资料及完整联系方式列表。 */
|
||||
int updateContactPage(AppContactPage page);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.ruoyi.app.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.ruoyi.app.domain.AppContactItem;
|
||||
import com.ruoyi.app.domain.AppContactPage;
|
||||
import com.ruoyi.app.mapper.AppContactMapper;
|
||||
import com.ruoyi.app.service.IAppContactService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class AppContactServiceImpl implements IAppContactService
|
||||
{
|
||||
private static final int MAX_CONTACTS = 30;
|
||||
|
||||
@Autowired
|
||||
private AppContactMapper contactMapper;
|
||||
|
||||
@Override
|
||||
public AppContactPage selectAdminContactPage()
|
||||
{
|
||||
return buildContactPage(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppContactPage selectPublicContactPage()
|
||||
{
|
||||
return buildContactPage("0");
|
||||
}
|
||||
|
||||
private AppContactPage buildContactPage(String status)
|
||||
{
|
||||
AppContactPage page = contactMapper.selectAppContactPage();
|
||||
if (page == null)
|
||||
{
|
||||
page = defaultPage();
|
||||
}
|
||||
page.setContacts(contactMapper.selectAppContactItemList(status));
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateContactPage(AppContactPage page)
|
||||
{
|
||||
if (page == null)
|
||||
{
|
||||
throw new ServiceException("页面配置不能为空");
|
||||
}
|
||||
normalizePage(page);
|
||||
List<AppContactItem> contacts = page.getContacts();
|
||||
if (contacts == null)
|
||||
{
|
||||
contacts = new ArrayList<>();
|
||||
page.setContacts(contacts);
|
||||
}
|
||||
if (contacts.size() > MAX_CONTACTS)
|
||||
{
|
||||
throw new ServiceException("联系方式最多可配置" + MAX_CONTACTS + "条");
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
page.setId(1L);
|
||||
page.setUpdateTime(now);
|
||||
contactMapper.upsertAppContactPage(page);
|
||||
contactMapper.deleteAllAppContactItems();
|
||||
|
||||
int index = 0;
|
||||
for (AppContactItem item : contacts)
|
||||
{
|
||||
normalizeItem(item, index++);
|
||||
item.setId(null);
|
||||
item.setCreateBy(page.getUpdateBy());
|
||||
item.setUpdateBy(page.getUpdateBy());
|
||||
item.setCreateTime(now);
|
||||
item.setUpdateTime(now);
|
||||
contactMapper.insertAppContactItem(item);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private void normalizePage(AppContactPage page)
|
||||
{
|
||||
page.setAvatarUrl(trimAndCheck(page.getAvatarUrl(), 500, "头像地址"));
|
||||
page.setNickname(trimAndCheck(page.getNickname(), 100, "昵称"));
|
||||
page.setBio(trimAndCheck(page.getBio(), 500, "个人简介"));
|
||||
page.setBackgroundUrl(trimAndCheck(page.getBackgroundUrl(), 500, "背景图地址"));
|
||||
if (StringUtils.isEmpty(page.getNickname()))
|
||||
{
|
||||
throw new ServiceException("昵称不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
private void normalizeItem(AppContactItem item, int index)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new ServiceException("第" + (index + 1) + "条联系方式不能为空");
|
||||
}
|
||||
item.setType(trimAndCheck(item.getType(), 30, "联系方式类型"));
|
||||
item.setLabel(trimAndCheck(item.getLabel(), 50, "联系方式名称"));
|
||||
item.setValue(trimAndCheck(item.getValue(), 500, "联系方式内容"));
|
||||
item.setIconUrl(trimAndCheck(item.getIconUrl(), 500, "图标地址"));
|
||||
item.setQrCodeUrl(trimAndCheck(item.getQrCodeUrl(), 500, "二维码地址"));
|
||||
if (StringUtils.isEmpty(item.getType()))
|
||||
{
|
||||
item.setType("custom");
|
||||
}
|
||||
if (StringUtils.isEmpty(item.getLabel()))
|
||||
{
|
||||
throw new ServiceException("第" + (index + 1) + "条联系方式名称不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(item.getValue()))
|
||||
{
|
||||
throw new ServiceException("第" + (index + 1) + "条联系方式内容不能为空");
|
||||
}
|
||||
if (!"qrcode".equals(item.getActionType()) || StringUtils.isEmpty(item.getQrCodeUrl()))
|
||||
{
|
||||
item.setActionType("copy");
|
||||
}
|
||||
item.setStatus("1".equals(item.getStatus()) ? "1" : "0");
|
||||
if (item.getSort() == null || item.getSort() < 0)
|
||||
{
|
||||
item.setSort((index + 1) * 10);
|
||||
}
|
||||
}
|
||||
|
||||
private String trimAndCheck(String value, int maxLength, String fieldName)
|
||||
{
|
||||
String result = StringUtils.trim(value);
|
||||
if (result != null && result.length() > maxLength)
|
||||
{
|
||||
throw new ServiceException(fieldName + "不能超过" + maxLength + "个字符");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private AppContactPage defaultPage()
|
||||
{
|
||||
AppContactPage page = new AppContactPage();
|
||||
page.setId(1L);
|
||||
page.setAvatarUrl("https://img.yidaima.cn/%E5%A4%B4%E5%83%8F/9b889964f97e4d0c8f52f7b9ec0d04da.jpg");
|
||||
page.setNickname("Nan Yin");
|
||||
page.setBio("如果爱意难平,那就把它藏在心底吧!");
|
||||
return page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.app.mapper.AppContactMapper">
|
||||
|
||||
<resultMap type="AppContactPage" id="AppContactPageResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="avatarUrl" column="avatar_url" />
|
||||
<result property="nickname" column="nickname" />
|
||||
<result property="bio" column="bio" />
|
||||
<result property="backgroundUrl" column="background_url" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="AppContactItem" id="AppContactItemResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="type" column="type" />
|
||||
<result property="label" column="label" />
|
||||
<result property="value" column="contact_value" />
|
||||
<result property="iconUrl" column="icon_url" />
|
||||
<result property="qrCodeUrl" column="qr_code_url" />
|
||||
<result property="actionType" column="action_type" />
|
||||
<result property="status" column="status" />
|
||||
<result property="sort" column="sort" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAppContactPage" resultMap="AppContactPageResult">
|
||||
select id, avatar_url, nickname, bio, background_url,
|
||||
create_by, create_time, update_by, update_time
|
||||
from app_contact_page
|
||||
where id = 1
|
||||
</select>
|
||||
|
||||
<select id="selectAppContactItemList" resultMap="AppContactItemResult">
|
||||
select id, type, label, contact_value, icon_url, qr_code_url, action_type,
|
||||
status, sort, create_by, create_time, update_by, update_time
|
||||
from app_contact_item
|
||||
<if test="status != null and status != ''">where status = #{status}</if>
|
||||
order by sort asc, id asc
|
||||
</select>
|
||||
|
||||
<insert id="upsertAppContactPage" parameterType="AppContactPage">
|
||||
insert into app_contact_page
|
||||
(id, avatar_url, nickname, bio, background_url, create_by, create_time, update_by, update_time)
|
||||
values
|
||||
(1, #{avatarUrl}, #{nickname}, #{bio}, #{backgroundUrl},
|
||||
#{updateBy}, #{updateTime}, #{updateBy}, #{updateTime})
|
||||
on duplicate key update
|
||||
avatar_url = values(avatar_url), nickname = values(nickname), bio = values(bio),
|
||||
background_url = values(background_url), update_by = values(update_by),
|
||||
update_time = values(update_time)
|
||||
</insert>
|
||||
|
||||
<delete id="deleteAllAppContactItems">
|
||||
delete from app_contact_item
|
||||
</delete>
|
||||
|
||||
<insert id="insertAppContactItem" parameterType="AppContactItem" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into app_contact_item
|
||||
(type, label, contact_value, icon_url, qr_code_url, action_type, status, sort,
|
||||
create_by, create_time, update_by, update_time)
|
||||
values
|
||||
(#{type}, #{label}, #{value}, #{iconUrl}, #{qrCodeUrl}, #{actionType}, #{status}, #{sort},
|
||||
#{createBy}, #{createTime}, #{updateBy}, #{updateTime})
|
||||
</insert>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user