Files
pkAssistant/src/main/java/vvpkassistant/Anchors/AnchorsController.java

79 lines
2.9 KiB
Java
Raw Normal View History

2025-08-01 13:59:30 +08:00
package vvpkassistant.Anchors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vvpkassistant.Data.ResponseData;
import vvpkassistant.Data.ResponseInfo;
import vvpkassistant.pk.PkRecordDao;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("anchor")
public class AnchorsController {
@Autowired
private AnchorDao anchorDao;
@Autowired
private PkRecordDao recordDao;
// 添加新主播
@PostMapping("add")
public ResponseData<Object> addNewAnchor(@RequestBody AnchorModel model) {
//查询是否存在重复主播
int r = anchorDao.selectAnchorWithAnchorIdAndUserId(model.getAnchorId(), model.getCreateUserId());
if (r != 0) {
return ResponseData.error(ResponseInfo.ERROR,"该主播已存在");
}
int insert = anchorDao.insert(model);
return insert == 1 ? ResponseData.success("") : ResponseData.error(ResponseInfo.ERROR,"添加失败");
}
// 查询我的主播列表
@PostMapping("list")
public ResponseData<Object> myAnchorList(@RequestBody Map<String,Integer> map) {
Integer userId = map.get("id");
List<AnchorModel> anchorModels = anchorDao.selectMyAnchor(userId);
return ResponseData.success(anchorModels);
}
// 删除我的主播
@PostMapping("deleteMyAnchor")
public ResponseData<Object> deleteMyAnchor(@RequestBody Map<String,Integer> map) {
Integer id = map.get("id");
AnchorModel anchorModel = anchorDao.selectById(id);
try {
String anchorId = anchorModel.getAnchorId();
// 根据主播id查询该主播是否存在pk记录
int i = recordDao.existsPkRecordByAnchor(anchorId);
if (i > 0) {
return ResponseData.error(ResponseInfo.ERROR,"该主播已有pk记录。无法删除");
}
int r = anchorDao.deleteById(id);
return r == 1 ? ResponseData.success("") : ResponseData.error(ResponseInfo.ERROR,null);
} catch (Exception e) {
return ResponseData.error(ResponseInfo.ERROR,"非法数据,操作失败");
}
}
// 更新主播信息
@PostMapping("updateAnchorInfo")
public ResponseData<Object> updateAnchorInfo(@RequestBody AnchorModel model) {
// 查询该主播是否存在记录
int i = recordDao.existsPkRecordByAnchor(model.getAnchorId());
if (i > 0) {
return ResponseData.error(ResponseInfo.ERROR,"该主播已有pk记录。无法修改信息");
}
int r = anchorDao.updateById(model);
return r == 1 ? ResponseData.success("") : ResponseData.error(ResponseInfo.ERROR,null);
}
}