tx
This commit is contained in:
parent
207e524185
commit
962075ddb8
@ -7,11 +7,6 @@
|
|||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="ignoredFiles">
|
|
||||||
<set>
|
|
||||||
<option value="$PROJECT_DIR$/pojo/pom.xml" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package net.carbon.controller;
|
||||||
|
|
||||||
|
import net.carbon.bean.PageResponse;
|
||||||
|
import net.carbon.model.request.TimelyWarningRequest;
|
||||||
|
import net.carbon.model.vo.TimelyWarningVO;
|
||||||
|
import net.carbon.result.Result;
|
||||||
|
import net.carbon.service.TimelyWarningService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
|
public class TimelyWarningController {
|
||||||
|
private TimelyWarningService timelyWarningService;
|
||||||
|
|
||||||
|
@GetMapping("/TimelyWarning")
|
||||||
|
public Result<PageResponse<TimelyWarningVO>> get(@RequestParam("pageSize") Long pageSize, @RequestParam("page") Long page) {
|
||||||
|
return Result.success(timelyWarningService.getList(pageSize, page));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("warn/delete")
|
||||||
|
public Result<Boolean> delete(@RequestParam("id") Long id) {
|
||||||
|
int row = timelyWarningService.delete(id);
|
||||||
|
if (row > 0) {
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
return Result.error("删除失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("warn/edit")
|
||||||
|
public Result update(@RequestBody TimelyWarningRequest timelyWarningRequest) {
|
||||||
|
int row = timelyWarningService.updateById(timelyWarningRequest);
|
||||||
|
if (row > 0) {
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
return Result.error("修改失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("warn/add")
|
||||||
|
public Result add(@RequestBody TimelyWarningRequest timelyWarningRequest) {
|
||||||
|
timelyWarningService.add(timelyWarningRequest);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package net.carbon.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import net.carbon.model.po.TimelyWarningDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface TimelyWarningMapper extends BaseMapper<TimelyWarningDO> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package net.carbon.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("timely_warning")
|
||||||
|
public class TimelyWarningDO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableField("id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField("name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("unit")
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
@TableField("data")
|
||||||
|
private Double data;
|
||||||
|
|
||||||
|
@TableField("direction")
|
||||||
|
private String direction;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package net.carbon.model.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TimelyWarningRequest {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
private Double data;
|
||||||
|
|
||||||
|
private String direction;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package net.carbon.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TimelyWarningVO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
private Double data;
|
||||||
|
|
||||||
|
private String direction;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package net.carbon.service;
|
||||||
|
|
||||||
|
import net.carbon.bean.PageResponse;
|
||||||
|
import net.carbon.model.request.TimelyWarningRequest;
|
||||||
|
import net.carbon.model.vo.TimelyWarningVO;
|
||||||
|
|
||||||
|
public interface TimelyWarningService {
|
||||||
|
PageResponse<TimelyWarningVO> getList(Long pageSize, Long page);
|
||||||
|
|
||||||
|
int delete(Long id);
|
||||||
|
|
||||||
|
int updateById(TimelyWarningRequest timelyWarningRequest);
|
||||||
|
|
||||||
|
void add(TimelyWarningRequest timelyWarningRequest);
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package net.carbon.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import net.carbon.bean.PageResponse;
|
||||||
|
import net.carbon.mapper.TimelyWarningMapper;
|
||||||
|
import net.carbon.model.po.TimelyWarningDO;
|
||||||
|
import net.carbon.model.request.TimelyWarningRequest;
|
||||||
|
import net.carbon.model.vo.TimelyWarningVO;
|
||||||
|
import net.carbon.service.TimelyWarningService;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TimelyWarningServiceImpl implements TimelyWarningService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TimelyWarningMapper timelyWarningMapper;
|
||||||
|
@Override
|
||||||
|
public PageResponse<TimelyWarningVO> getList(Long pageSize, Long page) {
|
||||||
|
Page<TimelyWarningDO> pageInfo = new Page<>(page, pageSize);
|
||||||
|
IPage<TimelyWarningDO> TimelyWarningDOPage = timelyWarningMapper.selectPage(pageInfo, new LambdaQueryWrapper<TimelyWarningDO>());
|
||||||
|
|
||||||
|
PageResponse<TimelyWarningVO> pageResponse = new PageResponse<>();
|
||||||
|
|
||||||
|
List<TimelyWarningVO> TimelyWarningVOS = TimelyWarningDOPage.getRecords().stream().map(obj -> {
|
||||||
|
TimelyWarningVO timelyWarningVO = new TimelyWarningVO();
|
||||||
|
BeanUtils.copyProperties(obj, timelyWarningVO);
|
||||||
|
return timelyWarningVO;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
pageResponse.setPageSize(TimelyWarningDOPage.getSize());
|
||||||
|
pageResponse.setCurrent(TimelyWarningDOPage.getCurrent());
|
||||||
|
pageResponse.setTotal(TimelyWarningDOPage.getTotal());
|
||||||
|
pageResponse.setRecords(TimelyWarningVOS);
|
||||||
|
return pageResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int delete(Long id) {
|
||||||
|
LambdaQueryWrapper<TimelyWarningDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(TimelyWarningDO::getId, id);
|
||||||
|
return timelyWarningMapper.delete(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateById(TimelyWarningRequest timelyWarningRequest) {
|
||||||
|
TimelyWarningDO timelyWarningDO = new TimelyWarningDO();
|
||||||
|
BeanUtils.copyProperties(timelyWarningRequest, timelyWarningDO);
|
||||||
|
int row = timelyWarningMapper.updateById(timelyWarningDO);
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(TimelyWarningRequest timelyWarningRequest) {
|
||||||
|
TimelyWarningDO timelyWarningDO = new TimelyWarningDO();
|
||||||
|
BeanUtils.copyProperties(timelyWarningRequest, timelyWarningDO);
|
||||||
|
timelyWarningMapper.insert(timelyWarningDO);
|
||||||
|
}
|
||||||
|
}
|
7
server/src/main/resources/mapper/TimelyWarningMapper.xml
Normal file
7
server/src/main/resources/mapper/TimelyWarningMapper.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?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="net.carbon.mapper.TimelyWarningMapper">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue
Block a user