diff --git a/src/main/java/com/guaiguailang/harmony/controller/CarbonController.java b/src/main/java/com/guaiguailang/harmony/controller/CarbonController.java new file mode 100644 index 0000000..0e52784 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/controller/CarbonController.java @@ -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)); + } + + +} diff --git a/src/main/java/com/guaiguailang/harmony/controller/UserController.java b/src/main/java/com/guaiguailang/harmony/controller/UserController.java index faa876a..c4d8cd8 100644 --- a/src/main/java/com/guaiguailang/harmony/controller/UserController.java +++ b/src/main/java/com/guaiguailang/harmony/controller/UserController.java @@ -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 = {"用户相关接口"} ) diff --git a/src/main/java/com/guaiguailang/harmony/domain/dto/ParamCarbonSavingRanking.java b/src/main/java/com/guaiguailang/harmony/domain/dto/ParamCarbonSavingRanking.java new file mode 100644 index 0000000..69999e8 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/dto/ParamCarbonSavingRanking.java @@ -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 { +} diff --git a/src/main/java/com/guaiguailang/harmony/domain/entity/CarbonCalc.java b/src/main/java/com/guaiguailang/harmony/domain/entity/CarbonCalc.java new file mode 100644 index 0000000..109654b --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/entity/CarbonCalc.java @@ -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; + + +} diff --git a/src/main/java/com/guaiguailang/harmony/domain/entity/CarbonSavingsranking.java b/src/main/java/com/guaiguailang/harmony/domain/entity/CarbonSavingsranking.java new file mode 100644 index 0000000..d43b9b3 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/entity/CarbonSavingsranking.java @@ -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; +} diff --git a/src/main/java/com/guaiguailang/harmony/mapper/CarbonMapper.java b/src/main/java/com/guaiguailang/harmony/mapper/CarbonMapper.java new file mode 100644 index 0000000..0cee2ef --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/mapper/CarbonMapper.java @@ -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 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 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 getCarbonRanking(int number); +} \ No newline at end of file diff --git a/src/main/java/com/guaiguailang/harmony/service/CarbonService.java b/src/main/java/com/guaiguailang/harmony/service/CarbonService.java new file mode 100644 index 0000000..9efb8a4 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/service/CarbonService.java @@ -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); +} diff --git a/src/main/java/com/guaiguailang/harmony/service/impl/CarbonServiceImpl.java b/src/main/java/com/guaiguailang/harmony/service/impl/CarbonServiceImpl.java new file mode 100644 index 0000000..e0dab04 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/service/impl/CarbonServiceImpl.java @@ -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; + } +} diff --git a/src/main/resources/mapper/CarbonMapper.xml b/src/main/resources/mapper/CarbonMapper.xml new file mode 100644 index 0000000..1d378a2 --- /dev/null +++ b/src/main/resources/mapper/CarbonMapper.xml @@ -0,0 +1,39 @@ + + + + + + + + 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}) + + + + + + + + + + + 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} + + + + + DELETE FROM carbon_calc WHERE id = #{id} + + + \ No newline at end of file