添加碳排放标签接口开发

This commit is contained in:
ChenQiaoWen 2025-02-26 23:29:59 +08:00
parent 1e67fc698a
commit 719c9eec2e
4 changed files with 23 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import net.carbon.model.request.LabelUpdateRequest;
import net.carbon.model.vo.LabelVO; import net.carbon.model.vo.LabelVO;
import net.carbon.result.Result; import net.carbon.result.Result;
import net.carbon.service.LabelService; import net.carbon.service.LabelService;
import net.carbon.utils.JsonData;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -67,5 +68,14 @@ public class LabelController {
return Result.error("删除失败"); return Result.error("删除失败");
} }
@PostMapping("/add")
public JsonData add(@RequestBody LabelUpdateRequest labelUpdateRequest){
int row = labelService.add(labelUpdateRequest);
if (row >0){
return JsonData.buildCodeAndMsg(1,"添加成功");
}
return JsonData.buildError("添加失败");
}
} }

View File

@ -2,6 +2,7 @@ package net.carbon.mapper;
import net.carbon.model.po.LabelDO; import net.carbon.model.po.LabelDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@ -15,4 +16,6 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface LabelMapper extends BaseMapper<LabelDO> { public interface LabelMapper extends BaseMapper<LabelDO> {
@Insert("insert into label (name, unit, data_value, attribute, is_system_date, is_delete) values (#{name},#{unit},#{dataValue},#{attribute},#{isSystemDate},#{isDeleted})")
int add(LabelDO labelDO);
} }

View File

@ -25,4 +25,5 @@ public interface LabelService extends IService<LabelDO> {
int updateById(LabelUpdateRequest labelUpdateReq); int updateById(LabelUpdateRequest labelUpdateReq);
int add(LabelUpdateRequest labelUpdateRequest);
} }

View File

@ -73,4 +73,13 @@ public class LabelServiceImpl extends ServiceImpl<LabelMapper, LabelDO> implemen
int row = labelMapper.updateById(labelDO); int row = labelMapper.updateById(labelDO);
return row; return row;
} }
@Override
public int add(LabelUpdateRequest labelUpdateRequest) {
LabelDO labelDO = new LabelDO();
BeanUtils.copyProperties(labelUpdateRequest,labelDO);
labelDO.setIsDeleted(0);
int row = labelMapper.add(labelDO);
return row;
}
} }