feat: 添加根据codeNo获取代理商公告的接口,更新公告相关数据库操作
This commit is contained in:
@@ -6,10 +6,13 @@ import com.gameplatform.server.model.dto.admin.AnnouncementResponse;
|
||||
import com.gameplatform.server.model.dto.common.PageResult;
|
||||
import com.gameplatform.server.model.entity.admin.Announcement;
|
||||
import com.gameplatform.server.service.admin.AnnouncementService;
|
||||
import com.gameplatform.server.service.admin.AnnouncementByCodeService;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -22,9 +25,14 @@ import java.util.List;
|
||||
@Tag(name = "公告管理", description = "系统公告的增删改查接口")
|
||||
public class AnnouncementController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AnnouncementController.class);
|
||||
|
||||
@Autowired
|
||||
private AnnouncementService announcementService;
|
||||
|
||||
@Autowired
|
||||
private AnnouncementByCodeService announcementByCodeService;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "创建公告", description = "创建新的系统公告,belongId会自动从JWT token中获取")
|
||||
public ResponseEntity<Object> createAnnouncement(@RequestBody AnnouncementRequest request, Authentication authentication) {
|
||||
@@ -239,4 +247,49 @@ public class AnnouncementController {
|
||||
.toList();
|
||||
return ResponseEntity.ok(responses);
|
||||
}
|
||||
|
||||
@GetMapping("/by-code/{codeNo}")
|
||||
@Operation(summary = "根据codeNo获取代理商公告", description = "根据链接编号获取对应代理商设置的启用公告")
|
||||
public ResponseEntity<Object> getAnnouncementsByCodeNo(
|
||||
@Parameter(description = "链接编号", example = "ABC123") @PathVariable String codeNo) {
|
||||
|
||||
logger.info("接收到根据codeNo获取代理商公告的请求: {}", codeNo);
|
||||
|
||||
try {
|
||||
logger.debug("调用服务方法获取公告列表: {}", codeNo);
|
||||
List<Announcement> announcements = announcementByCodeService.getAnnouncementsByCodeNo(codeNo);
|
||||
|
||||
logger.debug("转换公告实体为响应对象, 公告数量: {}", announcements.size());
|
||||
List<AnnouncementResponse> responses = announcements.stream()
|
||||
.map(AnnouncementConverter::toResponse)
|
||||
.toList();
|
||||
|
||||
final String finalCodeNo = codeNo;
|
||||
logger.info("成功获取代理商公告: codeNo={}, 公告数量={}", codeNo, responses.size());
|
||||
|
||||
return ResponseEntity.ok(new Object() {
|
||||
public final boolean success = true;
|
||||
public final String message = "查询成功";
|
||||
public final List<AnnouncementResponse> data = responses;
|
||||
public final String codeNo = finalCodeNo;
|
||||
});
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.warn("请求参数错误: codeNo={}, 错误信息={}", codeNo, e.getMessage());
|
||||
final String finalCodeNo = codeNo;
|
||||
return ResponseEntity.badRequest().body(new Object() {
|
||||
public final boolean success = false;
|
||||
public final String message = e.getMessage();
|
||||
public final String codeNo = finalCodeNo;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("根据codeNo获取代理商公告时发生系统错误: codeNo={}", codeNo, e);
|
||||
final String finalCodeNo = codeNo;
|
||||
return ResponseEntity.internalServerError().body(new Object() {
|
||||
public final boolean success = false;
|
||||
public final String message = "系统错误:" + e.getMessage();
|
||||
public final String codeNo = finalCodeNo;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,22 +303,7 @@ public class ScriptClient {
|
||||
.doOnError(e -> log.warn("获取目标分数失败: machineId={}, error={}", machineId, e.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置次数(生成链接时调用)- 使用 @RepeatCall 注解自动重复执行3次
|
||||
*/
|
||||
@RepeatCall(times = 3, description = "设置次数")
|
||||
public Mono<String> setTimes(String machineId, int times) {
|
||||
String url = String.format(apiBaseUrl + "/yijianwan_netfile/saveMsg?文件名=总次数&%s=%d", machineId, times);
|
||||
log.debug("设置次数: machineId={}, times={}, url={}", machineId, times, url);
|
||||
return webClient.post()
|
||||
.uri(url)
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.retrieve()
|
||||
.bodyToMono(String.class)
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.doOnSuccess(result -> log.debug("设置次数成功: machineId={}, times={}, result={}", machineId, times, result))
|
||||
.doOnError(e -> log.warn("设置次数失败: machineId={}, times={}, error={}", machineId, times, e.toString()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存总次数(使用f4参数格式)
|
||||
|
||||
@@ -872,8 +872,12 @@ public class LinkStatusService {
|
||||
if ("已上号".equals(loginResult) || "已登录".equals(loginResult)) {
|
||||
try {
|
||||
LinkBatch linkBatch = linkBatchMapper.findById(linkTask.getBatchId());
|
||||
log.info("=============================================");
|
||||
scriptClient.saveTotalTimes(deviceId,linkBatch.getTimes()).block();
|
||||
// saveTotalTimes方法已经包含了详细的日志记录
|
||||
log.info("codeNo:{},deviceId:{}",linkTask.getCodeNo(),deviceId);
|
||||
log.info("=============================================");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("保存总次数接口调用失败: {}", e.getMessage());
|
||||
// 不影响后续流程,只记录警告日志
|
||||
|
||||
@@ -7,20 +7,21 @@
|
||||
<result property="content" column="content" />
|
||||
<result property="enabled" column="enabled" />
|
||||
<result property="jumpUrl" column="jump_url" />
|
||||
<result property="belongId" column="belong_id" />
|
||||
<result property="createdAt" column="created_at" />
|
||||
<result property="updatedAt" column="updated_at" />
|
||||
</resultMap>
|
||||
|
||||
<select id="findById" parameterType="long" resultMap="AnnouncementMap">
|
||||
SELECT id, title, content, enabled, jump_url, created_at, updated_at
|
||||
SELECT id, title, content, enabled, jump_url, belong_id, created_at, updated_at
|
||||
FROM announcement
|
||||
WHERE id = #{id}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.gameplatform.server.model.entity.admin.Announcement" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO announcement (title, content, enabled, jump_url)
|
||||
VALUES (#{title}, #{content}, #{enabled}, #{jumpUrl})
|
||||
INSERT INTO announcement (title, content, enabled, jump_url, belong_id)
|
||||
VALUES (#{title}, #{content}, #{enabled}, #{jumpUrl}, #{belongId})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.gameplatform.server.model.entity.admin.Announcement">
|
||||
@@ -30,6 +31,7 @@
|
||||
<if test="content != null">content = #{content},</if>
|
||||
<if test="enabled != null">enabled = #{enabled},</if>
|
||||
<if test="jumpUrl != null">jump_url = #{jumpUrl},</if>
|
||||
<if test="belongId != null">belong_id = #{belongId},</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
@@ -39,7 +41,7 @@
|
||||
</delete>
|
||||
|
||||
<select id="findAll" resultMap="AnnouncementMap">
|
||||
SELECT id, title, content, enabled, jump_url, created_at, updated_at
|
||||
SELECT id, title, content, enabled, jump_url, belong_id, created_at, updated_at
|
||||
FROM announcement
|
||||
ORDER BY created_at DESC
|
||||
LIMIT #{size} OFFSET #{offset}
|
||||
@@ -50,7 +52,7 @@
|
||||
</select>
|
||||
|
||||
<select id="findByEnabled" resultMap="AnnouncementMap">
|
||||
SELECT id, title, content, enabled, jump_url, created_at, updated_at
|
||||
SELECT id, title, content, enabled, jump_url, belong_id, created_at, updated_at
|
||||
FROM announcement
|
||||
WHERE enabled = #{enabled}
|
||||
ORDER BY created_at DESC
|
||||
@@ -64,4 +66,28 @@
|
||||
<update id="updateEnabled">
|
||||
UPDATE announcement SET enabled = #{enabled} WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="findByBelongId" resultMap="AnnouncementMap">
|
||||
SELECT id, title, content, enabled, jump_url, belong_id, created_at, updated_at
|
||||
FROM announcement
|
||||
WHERE belong_id = #{belongId}
|
||||
ORDER BY created_at DESC
|
||||
LIMIT #{size} OFFSET #{offset}
|
||||
</select>
|
||||
|
||||
<select id="countByBelongId" resultType="long">
|
||||
SELECT COUNT(1) FROM announcement WHERE belong_id = #{belongId}
|
||||
</select>
|
||||
|
||||
<select id="findByBelongIdAndEnabled" resultMap="AnnouncementMap">
|
||||
SELECT id, title, content, enabled, jump_url, belong_id, created_at, updated_at
|
||||
FROM announcement
|
||||
WHERE belong_id = #{belongId} AND enabled = #{enabled}
|
||||
ORDER BY created_at DESC
|
||||
LIMIT #{size} OFFSET #{offset}
|
||||
</select>
|
||||
|
||||
<select id="countByBelongIdAndEnabled" resultType="long">
|
||||
SELECT COUNT(1) FROM announcement WHERE belong_id = #{belongId} AND enabled = #{enabled}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user