协议新增分类

This commit is contained in:
SjS 2025-04-25 16:50:11 +08:00
parent 1236c24184
commit f3bcba15a6
16 changed files with 230 additions and 29 deletions

View File

@ -1,4 +1,4 @@
package com.ruoyi.bst.ad.enums;
package com.ruoyi.bst.ad.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package com.ruoyi.bst.ad.enums;
package com.ruoyi.bst.ad.domain.enums;
import com.ruoyi.common.utils.collection.CollectionUtils;
import lombok.AllArgsConstructor;

View File

@ -1,11 +1,7 @@
package com.ruoyi.bst.ad.service.impl;
import com.ruoyi.bst.ad.domain.Ad;
import com.ruoyi.bst.ad.domain.AdQuery;
import com.ruoyi.bst.ad.enums.AdBlong;
import com.ruoyi.bst.ad.service.AdConverter;
import com.ruoyi.bst.area.domain.Area;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;

View File

@ -5,14 +5,11 @@ import java.util.ArrayList;
import java.util.List;
import com.ruoyi.bst.ad.domain.AdVerifyDTO;
import com.ruoyi.bst.ad.enums.AdBlong;
import com.ruoyi.bst.ad.enums.AdVerifyStatus;
import com.ruoyi.bst.ad.domain.enums.AdBlong;
import com.ruoyi.bst.ad.domain.enums.AdVerifyStatus;
import com.ruoyi.bst.ad.service.AdConverter;
import com.ruoyi.bst.area.domain.AreaVO;
import com.ruoyi.bst.area.service.AreaService;
import com.ruoyi.bst.fault.domain.Fault;
import com.ruoyi.bst.fault.domain.FaultQuery;
import com.ruoyi.bst.fault.domain.enums.FaultStatus;
import com.ruoyi.bst.order.service.OrderService;
import com.ruoyi.common.core.domain.vo.UserVO;
import com.ruoyi.common.utils.DateUtils;

View File

@ -30,7 +30,6 @@ public class Agreement extends BaseEntity implements LogBizParam
@Excel(name = "运营区ID")
@ApiModelProperty("运营区ID")
@NotNull(message = "运营区ID不能为空",groups = {ValidGroup.Create.class})
private Long areaId;
@Excel(name = "标题")
@ -52,13 +51,14 @@ public class Agreement extends BaseEntity implements LogBizParam
@NotBlank(message = "协议类型不能为空",groups = {ValidGroup.Create.class})
private String agreementType;
@Excel(name = "内容类型:1-模板 2-正文")
@ApiModelProperty("内容类型:1-模板 2-正文")
@NotBlank(message = "内容类型不能为空",groups = {ValidGroup.Create.class})
private String contentType;
@Excel(name = "展示时间")
@ApiModelProperty("展示时间")
@NotNull(message = "展示时间不能为空",groups = {ValidGroup.Create.class})
private Integer duration;
@Override

View File

@ -0,0 +1,16 @@
package com.ruoyi.bst.agreement.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum AgreementContentType {
TEMPLATE("1", "模板"),
TEXT("2", "正文");
private final String code;
private final String name;
}

View File

@ -72,7 +72,7 @@ public interface AgreementMapper
*/
public int deleteAgreementByIds(@Param("array") List<Long> ids);
public AgreementVO selectDistinct(Agreement agreement);
public int selectDistinct(@Param("query") AgreementQuery agreement);
public AgreementVO selectLatest(AgreementQuery query);
}

View File

@ -37,6 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.brief != null and query.brief != ''"> and bag.brief like concat('%', #{query.brief}, '%')</if>
<if test="query.content != null and query.content != ''"> and bag.content like concat('%', #{query.content}, '%')</if>
<if test="query.agreementType != null and query.agreementType != ''"> and bag.agreement_type = #{query.agreementType}</if>
<if test="query.contentType != null and query.contentType != ''"> and bag.content_type = #{query.contentType}</if>
<if test="query.userName != null and query.userName != ''"> and su.nick_name like concat('%', #{query.userName}, '%')</if>
<if test="query.duration != null "> and bag.duration = #{query.duration}</if>
<if test="query.ids != null and query.ids.size() > 0">
@ -66,10 +67,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectAgreementVo"/>
where bag.id = #{id}
</select>
<select id="selectDistinct" resultType="com.ruoyi.bst.agreement.domain.AgreementVO">
<include refid="selectAgreementVo"/>
where bag.area_id = #{areaId} and bag.agreement_type = #{agreementType} and (bag.id != #{id} or #{id} is null)
</select>
<!--查询最新的协议信息-->
<select id="selectLatest" resultType="com.ruoyi.bst.agreement.domain.AgreementVO">
@ -78,6 +75,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by create_time desc limit 1
</select>
<select id="selectDistinct" resultType="java.lang.Integer">
select count(1) from <include refid="searchTables"/>
<where>
<include refid="searchCondition"/>
and bag.id != #{query.id}
</where>
</select>
<insert id="insertAgreement" parameterType="Agreement" useGeneratedKeys="true" keyProperty="id">
insert into bst_agreement
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -0,0 +1,11 @@
package com.ruoyi.bst.agreement.service;
import com.ruoyi.bst.agreement.domain.Agreement;
public interface AgreementConverter {
Agreement toPoByCreate(Agreement agreement);
Agreement toPoByUpdate(Agreement agreement);
}

View File

@ -0,0 +1,60 @@
package com.ruoyi.bst.agreement.service.impl;
import com.ruoyi.bst.ad.domain.Ad;
import com.ruoyi.bst.ad.service.AdConverter;
import com.ruoyi.bst.agreement.domain.Agreement;
import com.ruoyi.bst.agreement.domain.enums.AgreementContentType;
import com.ruoyi.bst.agreement.service.AgreementConverter;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class AgreementConverterImpl implements AgreementConverter {
@Override
public Agreement toPoByCreate(Agreement data) {
if (data == null) {
return null;
}
Agreement po = new Agreement();
// 基础信息
if (Objects.equals(data.getContentType(), AgreementContentType.TEXT.getCode())){
po.setAreaId(data.getAreaId());
}
po.setTitle(data.getTitle());
if (SecurityUtils.isAdmin()){
po.setContentType(data.getContentType());
}else po.setContentType(AgreementContentType.TEXT.getCode());
po.setAgreementType(data.getAgreementType());
po.setBrief(data.getBrief());
po.setContent(data.getContent());
return po;
}
@Override
public Agreement toPoByUpdate(Agreement data) {
if (data == null) {
return null;
}
Agreement po = new Agreement();
// 基础信息
if (Objects.equals(data.getContentType(), AgreementContentType.TEXT.getCode())){
po.setAreaId(data.getAreaId());
}
po.setId(data.getId());
po.setTitle(data.getTitle());
if (SecurityUtils.isAdmin()){
po.setContentType(data.getContentType());
}else po.setContentType(AgreementContentType.TEXT.getCode());
po.setAgreementType(data.getAgreementType());
po.setBrief(data.getBrief());
po.setContent(data.getContent());
return po;
}
}

View File

@ -2,13 +2,17 @@ package com.ruoyi.bst.agreement.service.impl;
import java.util.List;
import com.ruoyi.bst.agreement.domain.enums.AgreementContentType;
import com.ruoyi.bst.area.domain.AreaQuery;
import com.ruoyi.bst.area.domain.AreaVO;
import com.ruoyi.bst.area.service.AreaService;
import com.ruoyi.bst.device.domain.DeviceVO;
import com.ruoyi.bst.model.domain.ModelVO;
import com.ruoyi.common.core.domain.vo.UserVO;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.system.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bst.agreement.mapper.AgreementMapper;
@ -16,6 +20,7 @@ import com.ruoyi.bst.agreement.domain.Agreement;
import com.ruoyi.bst.agreement.domain.AgreementVO;
import com.ruoyi.bst.agreement.domain.AgreementQuery;
import com.ruoyi.bst.agreement.service.AgreementService;
import org.springframework.transaction.support.TransactionTemplate;
/**
* 协议Service业务层处理
@ -32,6 +37,8 @@ public class AgreementServiceImpl implements AgreementService
private AreaService areaService;
@Autowired
private UserService userService;
@Autowired
private TransactionTemplate transactionTemplate;
/**
* 查询协议
@ -66,9 +73,21 @@ public class AgreementServiceImpl implements AgreementService
@Override
public int insertAgreement(Agreement agreement)
{
contentTypeAreaCheck(agreement);
agreement.setCreateTime(DateUtils.getNowDate());
distinct(agreement);
return agreementMapper.insertAgreement(agreement);
Integer result = transactionTemplate.execute(status -> {
// 创建设备
int insert = agreementMapper.insertAgreement(agreement);
ServiceUtil.assertion(insert != 1,"新增设备失败");
// 后校验
AgreementVO vo = this.selectAgreementById(agreement.getId());
distinct(vo);
return insert;
});
return result==null? 0 : result;
}
/**
@ -80,15 +99,40 @@ public class AgreementServiceImpl implements AgreementService
@Override
public int updateAgreement(Agreement agreement)
{
contentTypeAreaCheck(agreement);
agreement.setUpdateTime(DateUtils.getNowDate());
distinct(agreement);
return agreementMapper.updateAgreement(agreement);
if (agreement.getContentType().equals(AgreementContentType.TEMPLATE.getCode())){
agreement.setAreaId(null);
}
Integer result = transactionTemplate.execute(status -> {
// 更新主表
int update = agreementMapper.updateAgreement(agreement);
ServiceUtil.assertion(update != 1, "更新设备失败");
// 后校验
AgreementVO vo = this.selectAgreementById(agreement.getId());
distinct(vo);
return update;
});
return result == null ? 0 : result;
}
private void distinct(Agreement agreement) {
ServiceUtil.assertion(agreementMapper.selectDistinct(agreement)!= null,"当前运营区已存在同类协议");
private void distinct(AgreementVO agreement) {
AgreementQuery query = new AgreementQuery();
query.setContentType(agreement.getContentType());
query.setId(agreement.getId());
if (agreement.getAreaId() != null) {
query.setAreaId(agreement.getAreaId());
}
query.setAgreementType(agreement.getAgreementType());
ServiceUtil.assertion(agreementMapper.selectDistinct(query) > 0,"当前类型协议已存在");
}
private void contentTypeAreaCheck(Agreement agreement) {
ServiceUtil.assertion(agreement.getContentType().equals(AgreementContentType.TEXT.getCode())&&agreement.getAreaId()==null,"协议运营区不允许为空");
}
/**
* 批量删除协议
*

View File

@ -0,0 +1,24 @@
package com.ruoyi.common.validRule.contentArea;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
@Documented
@Target(ElementType.TYPE) // 注解作用在类上跨字段校验
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = ContentTypeAreaValidator.class) // 指定校验器
public @interface ContentTypeAreaCheck {
String message() default "协议运营区不能为空";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
// 以下为自定义属性指定字段名和条件值
String contentTypeField() default "contentType"; // contentType 字段名
int contentTypeValue() default 2; // 触发校验的 contentType 当为2时校验areaId
String areaIdField() default "areaId"; // areaId 字段名
}

View File

@ -0,0 +1,43 @@
package com.ruoyi.common.validRule.contentArea;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.lang.reflect.Field;
public class ContentTypeAreaValidator implements ConstraintValidator<ContentTypeAreaCheck, Object> {
private String contentTypeField; // contentType 字段名
private int contentTypeValue; // 触发校验的 contentType 2
private String areaIdField; // areaId 字段名
@Override
public void initialize(ContentTypeAreaCheck constraintAnnotation) {
// 初始化注解配置
contentTypeField = constraintAnnotation.contentTypeField();
contentTypeValue = constraintAnnotation.contentTypeValue();
areaIdField = constraintAnnotation.areaIdField();
}
@Override
public boolean isValid(Object object, ConstraintValidatorContext context) {
try {
Field contentTypeField = object.getClass().getDeclaredField(this.contentTypeField);
contentTypeField.setAccessible(true);
Integer contentType = (Integer) contentTypeField.get(object);
if (contentType == null || contentType != contentTypeValue) {
return true;
}
Field areaIdField = object.getClass().getDeclaredField(this.areaIdField);
areaIdField.setAccessible(true);
Object areaId = areaIdField.get(object);
return areaId != null && !areaId.toString().trim().isEmpty();
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException("校验字段不存在或无法访问", e);
}
}
}

View File

@ -1,7 +1,7 @@
package com.ruoyi.web.app;
import com.ruoyi.bst.ad.domain.AdQuery;
import com.ruoyi.bst.ad.enums.AdVerifyStatus;
import com.ruoyi.bst.ad.domain.enums.AdVerifyStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -20,8 +20,6 @@ import com.ruoyi.bst.ad.domain.Ad;
import com.ruoyi.bst.ad.domain.AdQuery;
import com.ruoyi.bst.ad.domain.AdVO;
import com.ruoyi.bst.ad.domain.AdVerifyDTO;
import com.ruoyi.bst.ad.enums.AdBlong;
import com.ruoyi.bst.ad.enums.AdVerifyStatus;
import com.ruoyi.bst.ad.service.AdConverter;
import com.ruoyi.bst.ad.service.AdService;
import com.ruoyi.bst.ad.service.AdValidator;

View File

@ -4,8 +4,11 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.bst.agreement.service.AgreementConverter;
import com.ruoyi.common.core.validate.ValidGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -42,6 +45,8 @@ public class AgreementController extends BaseController
private AgreementService agreementService;
@Autowired
private AgreementValidator agreementValidator;
@Autowired
private AgreementConverter agreementConverter;
/**
* 查询协议列表
@ -86,8 +91,9 @@ public class AgreementController extends BaseController
@PreAuthorize("@ss.hasPermi('bst:agreement:add')")
@Log(title = "新增协议", businessType = BusinessType.INSERT, bizIdName = "arg0", bizType = LogBizType.AGREEMENT)
@PostMapping
public AjaxResult add(@RequestBody Agreement agreement)
public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Agreement agreement)
{
agreementConverter.toPoByCreate(agreement);
return toAjax(agreementService.insertAgreement(agreement));
}
@ -97,11 +103,12 @@ public class AgreementController extends BaseController
@PreAuthorize("@ss.hasPermi('bst:agreement:edit')")
@Log(title = "修改协议", businessType = BusinessType.UPDATE, bizIdName = "arg0", bizType = LogBizType.AGREEMENT)
@PutMapping
public AjaxResult edit(@RequestBody Agreement agreement)
public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class)Agreement agreement)
{
if (!agreementValidator.canEdit(agreement.getId())) {
return AjaxResult.error("您没有权限修改ID为" + agreement.getId() + "的协议");
}
agreementConverter.toPoByUpdate(agreement);
return toAjax(agreementService.updateAgreement(agreement));
}