新增 碳足迹接口相关文件和对象 从本次提交开始,数据库存在变动,请及时更新
This commit is contained in:
parent
3cc1616e72
commit
fd62c5e42e
@ -0,0 +1,46 @@
|
||||
package com.guaiguailang.harmony.controller;
|
||||
|
||||
import com.guaiguailang.harmony.domain.dto.ParamCarbonSavingRanking;
|
||||
import com.guaiguailang.harmony.service.CarbonService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@Tag(name="碳足迹相关接口")
|
||||
@RequestMapping("/carbon")
|
||||
public class CarbonController {
|
||||
@Autowired
|
||||
private CarbonService carbonService;
|
||||
@Operation(
|
||||
summary = "碳足迹计算标准",
|
||||
description = "包含了可计算碳足迹的数据标准",
|
||||
tags = {"碳足迹相关接口"}
|
||||
)
|
||||
@GetMapping("/standard")
|
||||
public ResponseEntity getCarbonStandard() {
|
||||
return ResponseEntity.ok(carbonService.getCarbonStandard());
|
||||
}
|
||||
@Operation(
|
||||
summary = "节碳排行榜",
|
||||
description = "节碳排行榜数据加载",
|
||||
tags = {"碳足迹相关接口"}
|
||||
)
|
||||
@GetMapping("/ranking")
|
||||
public ResponseEntity getCarbonRanking(@RequestParam(defaultValue = "50") int number) {
|
||||
return ResponseEntity.ok(carbonService.getCarbonRanking(number));
|
||||
}
|
||||
@Operation(
|
||||
summary = "节碳 用户数据新增",
|
||||
description = "节碳排行榜数据加载",
|
||||
tags = {"碳足迹相关接口"}
|
||||
)
|
||||
@PostMapping("add")
|
||||
public ResponseEntity getCarbonAdd(@RequestBody ParamCarbonSavingRanking addCarbonParam) {
|
||||
return ResponseEntity.ok(carbonService.addCarbonSavingRanking(addCarbonParam));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -46,19 +46,28 @@ public class UserController {
|
||||
public ResponseEntity getUserListNum(){
|
||||
return ResponseEntity.ok(userService.getUserListNum());
|
||||
}
|
||||
|
||||
@Operation(
|
||||
summary = "用户 新增用户可配分角色",
|
||||
description = "加载可以分配的角色,以供用户添加子用户",
|
||||
tags = {"用户相关接口"}
|
||||
)
|
||||
@PostMapping("/add/roleList")
|
||||
public ResponseEntity getRoleListWhenAddUser(@RequestParam String role){
|
||||
// System.out.println("当前用户权限:"+role);
|
||||
return ResponseEntity.ok(userService.getRoleListWhenAddUser(role));
|
||||
}
|
||||
@Operation(
|
||||
summary = "用户 新增子用户",
|
||||
description = "用户 新增 子用户",
|
||||
tags = {"用户相关接口"}
|
||||
)
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity addUser(@RequestBody ParamUserAdd userAddParam){
|
||||
return ResponseEntity.ok(userService.addUser(userAddParam));
|
||||
}
|
||||
|
||||
@Operation(
|
||||
summary = "注册",
|
||||
summary = "用户 注册",
|
||||
description = "用户自行注册",
|
||||
tags = {"用户相关接口"}
|
||||
)
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.guaiguailang.harmony.domain.dto;
|
||||
|
||||
import com.guaiguailang.harmony.domain.entity.CarbonSavingsranking;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ParamCarbonSavingRanking extends CarbonSavingsranking {
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.guaiguailang.harmony.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CarbonCalc {
|
||||
|
||||
private long id;
|
||||
private String category;
|
||||
private String itemName;
|
||||
private double unitValue;
|
||||
private String unitItem;
|
||||
private String about;
|
||||
private String unitResult;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.guaiguailang.harmony.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CarbonSavingsranking {
|
||||
|
||||
private long id;
|
||||
private long rank;
|
||||
private String entityName;
|
||||
private long entityId;
|
||||
private double carbonSaved;
|
||||
private String period;
|
||||
private String region;
|
||||
private String method;
|
||||
private long verification;
|
||||
private java.sql.Timestamp dateRecorded;
|
||||
private String notes;
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.guaiguailang.harmony.mapper;
|
||||
|
||||
import com.guaiguailang.harmony.domain.entity.CarbonCalc;
|
||||
import com.guaiguailang.harmony.domain.entity.CarbonSavingsranking;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CarbonMapper {
|
||||
|
||||
/**
|
||||
* 插入一条碳排放记录
|
||||
*
|
||||
* @param carbonCalc 碳排放记录对象
|
||||
*/
|
||||
void insertCarbonCalc(CarbonCalc carbonCalc);
|
||||
|
||||
/**
|
||||
* 查询所有碳排放记录
|
||||
*
|
||||
* @return 碳排放记录列表
|
||||
*/
|
||||
List<CarbonCalc> selectAllCarbonCalcs();
|
||||
|
||||
/**
|
||||
* 根据ID查询碳排放记录
|
||||
*
|
||||
* @param id 记录的ID
|
||||
* @return 碳排放记录对象
|
||||
*/
|
||||
CarbonCalc selectCarbonCalcById(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 更新碳排放记录
|
||||
*
|
||||
* @param carbonCalc 碳排放记录对象
|
||||
*/
|
||||
void updateCarbonCalc(CarbonCalc carbonCalc);
|
||||
|
||||
/**
|
||||
* 根据ID删除碳排放记录
|
||||
*
|
||||
* @param id 记录的ID
|
||||
*/
|
||||
void deleteCarbonCalcById(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 插入一条节碳排行榜记录
|
||||
*
|
||||
* @param carbonSavingsranking 节碳排行榜记录对象
|
||||
*/
|
||||
void insertCarbonSavingsranking(CarbonSavingsranking carbonSavingsranking);
|
||||
|
||||
/**
|
||||
* 查询所有节碳排行榜记录
|
||||
*
|
||||
* @return 节碳排行榜记录列表
|
||||
*/
|
||||
List<CarbonSavingsranking> selectAllCarbonSavingsrankings();
|
||||
|
||||
/**
|
||||
* 根据ID查询节碳排行榜记录
|
||||
*
|
||||
* @param id 记录的ID
|
||||
* @return 节碳排行榜记录对象
|
||||
*/
|
||||
CarbonSavingsranking selectCarbonSavingsrankingById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 更新节碳排行榜记录
|
||||
*
|
||||
* @param carbonSavingsranking 节碳排行榜记录对象
|
||||
*/
|
||||
void updateCarbonSavingsranking(CarbonSavingsranking carbonSavingsranking);
|
||||
|
||||
/**
|
||||
* 根据ID删除节碳排行榜记录
|
||||
*
|
||||
* @param id 记录的ID
|
||||
*/
|
||||
void deleteCarbonSavingsrankingById(@Param("id") Long id);
|
||||
|
||||
@Select("SELECT * from carbon_savingsranking order by carbon_saved desc limit #{number} ")
|
||||
List<CarbonSavingsranking> getCarbonRanking(int number);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.guaiguailang.harmony.service;
|
||||
|
||||
import com.guaiguailang.harmony.domain.dto.ParamCarbonSavingRanking;
|
||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||
|
||||
public interface CarbonService {
|
||||
ResponseResult getCarbonStandard();
|
||||
|
||||
ResponseResult getCarbonRanking(int number);
|
||||
|
||||
ResponseResult addCarbonSavingRanking(ParamCarbonSavingRanking addCarbonParam);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.guaiguailang.harmony.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.github.yitter.idgen.YitIdHelper;
|
||||
import com.guaiguailang.harmony.domain.dto.ParamCarbonSavingRanking;
|
||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||
import com.guaiguailang.harmony.mapper.CarbonMapper;
|
||||
import com.guaiguailang.harmony.service.CarbonService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class CarbonServiceImpl implements CarbonService {
|
||||
@Autowired
|
||||
private CarbonMapper carbonMapper;
|
||||
|
||||
@Override
|
||||
public ResponseResult getCarbonStandard() {
|
||||
|
||||
return ResponseResult.success(carbonMapper.selectAllCarbonCalcs());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseResult getCarbonRanking(int number) {
|
||||
return ResponseResult.success(carbonMapper.getCarbonRanking(number));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseResult addCarbonSavingRanking(ParamCarbonSavingRanking addCarbonParam) {
|
||||
Long uid = Long.parseLong(StpUtil.getLoginId().toString());
|
||||
addCarbonParam.setEntityId(uid);
|
||||
addCarbonParam.setId(YitIdHelper.nextId());
|
||||
return null;
|
||||
}
|
||||
}
|
39
src/main/resources/mapper/CarbonMapper.xml
Normal file
39
src/main/resources/mapper/CarbonMapper.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?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="com.guaiguailang.harmony.mapper.CarbonMapper">
|
||||
|
||||
<!-- 插入数据 -->
|
||||
<insert id="insertCarbonCalc" parameterType="com.guaiguailang.harmony.domain.entity.CarbonCalc">
|
||||
INSERT INTO carbon_calc (id, category, item_name, unit_value, unit_item, about, unit_result)
|
||||
VALUES (#{id}, #{category}, #{item_name}, #{unit_value}, #{unit_item}, #{about}, #{unit_result})
|
||||
</insert>
|
||||
|
||||
<!-- 查询所有数据 -->
|
||||
<select id="selectAllCarbonCalcs" resultType="com.guaiguailang.harmony.domain.entity.CarbonCalc">
|
||||
SELECT * FROM carbon_calc
|
||||
</select>
|
||||
|
||||
<!-- 根据ID查询数据 -->
|
||||
<select id="selectCarbonCalcById" resultType="com.guaiguailang.harmony.domain.entity.CarbonCalc" parameterType="int">
|
||||
SELECT * FROM carbon_calc WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<!-- 更新数据 -->
|
||||
<update id="updateCarbonCalc" parameterType="com.guaiguailang.harmony.domain.entity.CarbonCalc">
|
||||
UPDATE carbon_calc
|
||||
SET category = #{category},
|
||||
item_name = #{item_name},
|
||||
unit_value = #{unit_value},
|
||||
unit_item = #{unit_item},
|
||||
about = #{about},
|
||||
unit_result = #{unit_result}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 删除数据 -->
|
||||
<delete id="deleteCarbonCalcById" parameterType="int">
|
||||
DELETE FROM carbon_calc WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user