12 changed files with 450 additions and 21 deletions
@ -0,0 +1,81 @@ |
|||
package cc.hiver.mall.legal.controller; |
|||
|
|||
import cc.hiver.core.common.utils.ResultUtil; |
|||
import cc.hiver.core.common.vo.Result; |
|||
import cc.hiver.mall.legal.entity.MallAgreementSetting; |
|||
import cc.hiver.mall.legal.pojo.AgreementSettingPageQuery; |
|||
import cc.hiver.mall.legal.service.MallAgreementSettingService; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@RestController |
|||
@Api(tags = "协议设置后台管理接口") |
|||
@RequestMapping("/hiver/mall/admin/agreementSetting") |
|||
@Transactional |
|||
public class AdminAgreementSettingController { |
|||
|
|||
@Autowired |
|||
private MallAgreementSettingService agreementSettingService; |
|||
|
|||
@RequestMapping(value = "/page", method = RequestMethod.GET) |
|||
@ApiOperation("分页获取协议设置") |
|||
public Result<IPage<MallAgreementSetting>> page(AgreementSettingPageQuery query) { |
|||
return new ResultUtil<IPage<MallAgreementSetting>>().setData(agreementSettingService.pageAgreementSettings(query)); |
|||
} |
|||
|
|||
@RequestMapping(value = "/get", method = RequestMethod.GET) |
|||
@ApiOperation("根据ID获取协议设置") |
|||
public Result<MallAgreementSetting> get(String id) { |
|||
if (StringUtils.isBlank(id)) { |
|||
return ResultUtil.error("协议ID不能为空"); |
|||
} |
|||
return new ResultUtil<MallAgreementSetting>().setData(agreementSettingService.getById(id)); |
|||
} |
|||
|
|||
@RequestMapping(value = "/save", method = RequestMethod.POST) |
|||
@ApiOperation("新增协议设置") |
|||
public Result<MallAgreementSetting> save(MallAgreementSetting setting) { |
|||
if (setting == null || StringUtils.isBlank(setting.getTitle())) { |
|||
return ResultUtil.error("协议标题不能为空"); |
|||
} |
|||
try { |
|||
return new ResultUtil<MallAgreementSetting>().setData(agreementSettingService.saveAgreementSetting(setting)); |
|||
} catch (IllegalArgumentException e) { |
|||
return ResultUtil.error(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@RequestMapping(value = "/edit", method = RequestMethod.POST) |
|||
@ApiOperation("编辑协议设置") |
|||
public Result<MallAgreementSetting> edit(MallAgreementSetting setting) { |
|||
if (setting == null || StringUtils.isBlank(setting.getId())) { |
|||
return ResultUtil.error("协议ID不能为空"); |
|||
} |
|||
if (StringUtils.isBlank(setting.getTitle())) { |
|||
return ResultUtil.error("协议标题不能为空"); |
|||
} |
|||
try { |
|||
MallAgreementSetting saved = agreementSettingService.editAgreementSetting(setting); |
|||
return saved == null ? ResultUtil.error("协议不存在") : new ResultUtil<MallAgreementSetting>().setData(saved); |
|||
} catch (IllegalArgumentException e) { |
|||
return ResultUtil.error(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@RequestMapping(value = "/delByIds", method = RequestMethod.POST) |
|||
@ApiOperation("批量删除协议设置") |
|||
public Result<Object> delByIds(String ids) { |
|||
if (StringUtils.isBlank(ids)) { |
|||
return ResultUtil.error("协议ID不能为空"); |
|||
} |
|||
boolean result = agreementSettingService.removeByIdsString(ids); |
|||
return result ? ResultUtil.success("删除成功") : ResultUtil.error("删除失败"); |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
package cc.hiver.mall.legal.controller; |
|||
|
|||
import cc.hiver.core.common.utils.ResultUtil; |
|||
import cc.hiver.core.common.vo.Result; |
|||
import cc.hiver.mall.legal.entity.MallAgreementSetting; |
|||
import cc.hiver.mall.legal.service.MallAgreementSettingService; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestMethod; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.List; |
|||
|
|||
@RestController |
|||
@Api(tags = "平台协议接口") |
|||
@RequestMapping("/hiver/app/agreementSetting") |
|||
public class AgreementSettingController { |
|||
|
|||
@Autowired |
|||
private MallAgreementSettingService agreementSettingService; |
|||
|
|||
@RequestMapping(value = "/list", method = RequestMethod.GET) |
|||
@ApiOperation("获取启用协议列表") |
|||
public Result<List<MallAgreementSetting>> list() { |
|||
LambdaQueryWrapper<MallAgreementSetting> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(MallAgreementSetting::getStatus, 1); |
|||
wrapper.orderByAsc(MallAgreementSetting::getSortOrder); |
|||
wrapper.orderByDesc(MallAgreementSetting::getCreateTime); |
|||
return new ResultUtil<List<MallAgreementSetting>>().setData(agreementSettingService.list(wrapper)); |
|||
} |
|||
|
|||
@RequestMapping(value = "/getByCode", method = RequestMethod.GET) |
|||
@ApiOperation("根据编码获取协议详情") |
|||
public Result<MallAgreementSetting> getByCode(String code) { |
|||
if (StringUtils.isBlank(code)) { |
|||
return ResultUtil.error("协议编码不能为空"); |
|||
} |
|||
MallAgreementSetting setting = agreementSettingService.getEnabledByCode(code); |
|||
return new ResultUtil<MallAgreementSetting>().setData(setting); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package cc.hiver.mall.legal.entity; |
|||
|
|||
import cc.hiver.core.base.HiverBaseEntity; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 平台协议配置。 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "平台协议配置") |
|||
@TableName(value = "t_mall_agreement_setting", autoResultMap = true) |
|||
public class MallAgreementSetting extends HiverBaseEntity { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "协议编码") |
|||
private String code; |
|||
|
|||
@ApiModelProperty(value = "协议标题") |
|||
private String title; |
|||
|
|||
@ApiModelProperty(value = "协议内容") |
|||
private String content; |
|||
|
|||
@ApiModelProperty(value = "排序") |
|||
private Integer sortOrder; |
|||
|
|||
@ApiModelProperty(value = "状态:0禁用,1启用") |
|||
private Integer status; |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
package cc.hiver.mall.legal.mapper; |
|||
|
|||
import cc.hiver.mall.legal.entity.MallAgreementSetting; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
@Repository |
|||
public interface MallAgreementSettingMapper extends BaseMapper<MallAgreementSetting> { |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
package cc.hiver.mall.legal.pojo; |
|||
|
|||
import cc.hiver.core.base.HiverBasePageQuery; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
@ApiModel("协议配置分页查询对象") |
|||
public class AgreementSettingPageQuery extends HiverBasePageQuery { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "兼容后台 pageNumber 参数") |
|||
private Integer pageNumber; |
|||
|
|||
@ApiModelProperty(value = "协议标题") |
|||
private String title; |
|||
|
|||
@ApiModelProperty(value = "协议编码") |
|||
private String code; |
|||
|
|||
@ApiModelProperty(value = "状态:0禁用,1启用") |
|||
private Integer status; |
|||
|
|||
public int currentPage() { |
|||
return pageNumber == null || pageNumber <= 0 ? getPageNum() : pageNumber; |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package cc.hiver.mall.legal.service; |
|||
|
|||
import cc.hiver.mall.legal.entity.MallAgreementSetting; |
|||
import cc.hiver.mall.legal.pojo.AgreementSettingPageQuery; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
|
|||
public interface MallAgreementSettingService extends IService<MallAgreementSetting> { |
|||
|
|||
IPage<MallAgreementSetting> pageAgreementSettings(AgreementSettingPageQuery query); |
|||
|
|||
MallAgreementSetting saveAgreementSetting(MallAgreementSetting setting); |
|||
|
|||
MallAgreementSetting editAgreementSetting(MallAgreementSetting setting); |
|||
|
|||
MallAgreementSetting getEnabledByCode(String code); |
|||
|
|||
boolean removeByIdsString(String ids); |
|||
} |
|||
@ -0,0 +1,149 @@ |
|||
package cc.hiver.mall.legal.service.impl; |
|||
|
|||
import cc.hiver.mall.legal.entity.MallAgreementSetting; |
|||
import cc.hiver.mall.legal.mapper.MallAgreementSettingMapper; |
|||
import cc.hiver.mall.legal.pojo.AgreementSettingPageQuery; |
|||
import cc.hiver.mall.legal.service.MallAgreementSettingService; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Service |
|||
public class MallAgreementSettingServiceImpl extends ServiceImpl<MallAgreementSettingMapper, MallAgreementSetting> implements MallAgreementSettingService { |
|||
|
|||
@Override |
|||
public IPage<MallAgreementSetting> pageAgreementSettings(AgreementSettingPageQuery query) { |
|||
if (query == null) { |
|||
query = new AgreementSettingPageQuery(); |
|||
} |
|||
Page<MallAgreementSetting> page = new Page<>(query.currentPage(), query.getPageSize()); |
|||
QueryWrapper<MallAgreementSetting> wrapper = new QueryWrapper<>(); |
|||
if (StrUtil.isNotBlank(query.getTitle())) { |
|||
wrapper.like("title", query.getTitle().trim()); |
|||
} |
|||
if (StrUtil.isNotBlank(query.getCode())) { |
|||
wrapper.eq("code", query.getCode().trim()); |
|||
} |
|||
if (query.getStatus() != null) { |
|||
wrapper.eq("status", query.getStatus()); |
|||
} |
|||
String sortColumn = resolveSortColumn(query.getSort()); |
|||
if (StrUtil.isNotBlank(sortColumn)) { |
|||
if ("desc".equalsIgnoreCase(query.getOrder())) { |
|||
wrapper.orderByDesc(sortColumn); |
|||
} else { |
|||
wrapper.orderByAsc(sortColumn); |
|||
} |
|||
} else { |
|||
wrapper.orderByAsc("sort_order").orderByDesc("create_time"); |
|||
} |
|||
return page(page, wrapper); |
|||
} |
|||
|
|||
@Override |
|||
public MallAgreementSetting saveAgreementSetting(MallAgreementSetting setting) { |
|||
fillDefaults(setting); |
|||
checkCodeUnique(setting); |
|||
save(setting); |
|||
return setting; |
|||
} |
|||
|
|||
@Override |
|||
public MallAgreementSetting editAgreementSetting(MallAgreementSetting setting) { |
|||
MallAgreementSetting old = getById(setting.getId()); |
|||
if (old == null) { |
|||
return null; |
|||
} |
|||
if (StrUtil.isBlank(setting.getCode())) { |
|||
setting.setCode(old.getCode()); |
|||
} |
|||
if (setting.getSortOrder() == null) { |
|||
setting.setSortOrder(old.getSortOrder()); |
|||
} |
|||
if (setting.getStatus() == null) { |
|||
setting.setStatus(old.getStatus()); |
|||
} |
|||
fillDefaults(setting); |
|||
checkCodeUnique(setting); |
|||
updateById(setting); |
|||
return getById(setting.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public MallAgreementSetting getEnabledByCode(String code) { |
|||
if (StrUtil.isBlank(code)) { |
|||
return null; |
|||
} |
|||
LambdaQueryWrapper<MallAgreementSetting> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(MallAgreementSetting::getCode, code.trim()); |
|||
wrapper.eq(MallAgreementSetting::getStatus, 1); |
|||
wrapper.last("limit 1"); |
|||
return getOne(wrapper, false); |
|||
} |
|||
|
|||
@Override |
|||
public boolean removeByIdsString(String ids) { |
|||
if (StrUtil.isBlank(ids)) { |
|||
return false; |
|||
} |
|||
List<String> idList = Arrays.stream(ids.split(",")) |
|||
.map(String::trim) |
|||
.filter(StrUtil::isNotBlank) |
|||
.collect(Collectors.toList()); |
|||
return !idList.isEmpty() && removeByIds(idList); |
|||
} |
|||
|
|||
private void fillDefaults(MallAgreementSetting setting) { |
|||
if (StrUtil.isBlank(setting.getCode())) { |
|||
setting.setCode("CUSTOM_" + setting.getId()); |
|||
} else { |
|||
setting.setCode(setting.getCode().trim()); |
|||
} |
|||
if (setting.getTitle() != null) { |
|||
setting.setTitle(setting.getTitle().trim()); |
|||
} |
|||
if (setting.getSortOrder() == null) { |
|||
setting.setSortOrder(0); |
|||
} |
|||
if (setting.getStatus() == null) { |
|||
setting.setStatus(1); |
|||
} |
|||
} |
|||
|
|||
private void checkCodeUnique(MallAgreementSetting setting) { |
|||
LambdaQueryWrapper<MallAgreementSetting> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(MallAgreementSetting::getCode, setting.getCode()); |
|||
if (StrUtil.isNotBlank(setting.getId())) { |
|||
wrapper.ne(MallAgreementSetting::getId, setting.getId()); |
|||
} |
|||
if (count(wrapper) > 0) { |
|||
throw new IllegalArgumentException("协议编码已存在"); |
|||
} |
|||
} |
|||
|
|||
private String resolveSortColumn(String sort) { |
|||
if (StrUtil.isBlank(sort)) { |
|||
return ""; |
|||
} |
|||
switch (sort) { |
|||
case "title": |
|||
return "title"; |
|||
case "createTime": |
|||
return "create_time"; |
|||
case "updateTime": |
|||
return "update_time"; |
|||
case "sortOrder": |
|||
return "sort_order"; |
|||
default: |
|||
return ""; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
CREATE TABLE IF NOT EXISTS `t_mall_agreement_setting` ( |
|||
`id` varchar(32) NOT NULL COMMENT '主键', |
|||
`create_by` varchar(255) DEFAULT NULL COMMENT '创建者', |
|||
`create_time` datetime DEFAULT NULL COMMENT '创建时间', |
|||
`update_by` varchar(255) DEFAULT NULL COMMENT '更新者', |
|||
`update_time` datetime DEFAULT NULL COMMENT '更新时间', |
|||
`del_flag` int(11) DEFAULT 0 COMMENT '删除标志', |
|||
`code` varchar(100) NOT NULL COMMENT '协议编码', |
|||
`title` varchar(120) NOT NULL COMMENT '协议标题', |
|||
`content` longtext COMMENT '协议内容', |
|||
`sort_order` int(11) DEFAULT 0 COMMENT '排序', |
|||
`status` int(11) DEFAULT 1 COMMENT '状态:0禁用,1启用', |
|||
PRIMARY KEY (`id`), |
|||
UNIQUE KEY `uk_mall_agreement_setting_code` (`code`), |
|||
KEY `idx_mall_agreement_setting_status_sort` (`status`, `sort_order`) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='平台协议配置'; |
|||
|
|||
INSERT INTO `t_mall_agreement_setting` |
|||
(`id`, `create_time`, `del_flag`, `code`, `title`, `content`, `sort_order`, `status`) |
|||
VALUES |
|||
('900000000000000001', NOW(), 0, 'USER_AGREEMENT', '用户协议', '', 10, 1), |
|||
('900000000000000002', NOW(), 0, 'PRIVACY_POLICY', '隐私政策', '', 20, 1), |
|||
('900000000000000003', NOW(), 0, 'STORE_CONSUME_SERVICE', '到店消费服务协议', '', 30, 1), |
|||
('900000000000000004', NOW(), 0, 'FOOD_SAFETY_MANAGEMENT', '餐饮安全管理办法', '', 40, 1), |
|||
('900000000000000005', NOW(), 0, 'CATERING_PROVIDER_REVIEW_REGISTRATION', '入网餐饮服务提供者审查登记规范', '', 50, 1), |
|||
('900000000000000006', NOW(), 0, 'FOOD_SAFETY_INCIDENT_DISPOSAL', '食品安全事故处置规范', '', 60, 1), |
|||
('900000000000000007', NOW(), 0, 'FOOD_SAFETY_COMPLAINT_REPORT', '食品安全投诉举报规范', '', 70, 1), |
|||
('900000000000000008', NOW(), 0, 'FOOD_SAFETY_VIOLATION_STOP_REPORT', '食品安全违法行为制止及报告规范', '', 80, 1), |
|||
('900000000000000009', NOW(), 0, 'PLATFORM_USER_REVIEW', '平台用户评价规范', '', 90, 1), |
|||
('900000000000000010', NOW(), 0, 'TAKEAWAY_MERCHANT_ENVIRONMENTAL_INITIATIVE', '外卖商家环保倡议书', '', 100, 1), |
|||
('900000000000000011', NOW(), 0, 'TAKEAWAY_USER_SERVICE_TERMS', '外卖用户服务条款', '', 110, 1), |
|||
('900000000000000012', NOW(), 0, 'SERIOUS_VIOLATION_SERVICE_STOP', '严重违法行为平台服务停止规范', '', 120, 1), |
|||
('900000000000000013', NOW(), 0, 'FOOD_SAFETY_AGREEMENT', '食品安全协议', '', 130, 1) |
|||
ON DUPLICATE KEY UPDATE |
|||
`title` = VALUES(`title`), |
|||
`sort_order` = VALUES(`sort_order`), |
|||
`status` = VALUES(`status`); |
|||
Loading…
Reference in new issue