From 8aaeb980d61538202049959287f24e9d01b1a435 Mon Sep 17 00:00:00 2001 From: EricCheng <12955029+ericchengscut@user.noreply.gitee.com> Date: Mon, 22 Apr 2024 20:17:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9EInvoice=E7=B1=BB=E4=B8=8E?= =?UTF-8?q?=E6=8A=A5=E9=94=80=E8=B4=A6=E5=8D=95=E6=9C=89=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=8C=E4=BF=AE=E6=94=B9Task=E4=B8=8EInvoi?= =?UTF-8?q?ce=E7=9A=84Controller=E7=B1=BB=E7=9A=84=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E4=B8=BAResult=E3=80=82=E5=BC=95=E5=85=A5chatGPT?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enumeration/ReimburseStatusEnum.java | 9 ++ .../java/com/groupshell/entity/Invoice.java | 36 ++++-- .../entity/chatgpt/KeyRandomStrategy.java | 20 ++++ .../entity/chatgpt/TestChatGpt4.java | 72 ++++++++++++ .../entity/chatgpt/TestChatGpt5.java | 72 ++++++++++++ .../groupshell/controller/InvoiceCtrl.java | 107 ++++++++++++------ .../com/groupshell/controller/TaskCtrl.java | 54 +++++---- .../com/groupshell/mapper/InvoiceMapper.java | 35 +++--- .../groupshell/service/InvoiceService.java | 37 +++--- .../service/impl/InvoiceServiceImpl.java | 86 +++++++++----- .../main/resources/mapper/InvoiceMapper.xml | 97 ++++++++++++---- 11 files changed, 483 insertions(+), 142 deletions(-) create mode 100644 common/src/main/java/com/groupshell/enumeration/ReimburseStatusEnum.java create mode 100644 pojo/src/main/java/com/groupshell/entity/chatgpt/KeyRandomStrategy.java create mode 100644 pojo/src/main/java/com/groupshell/entity/chatgpt/TestChatGpt4.java create mode 100644 pojo/src/main/java/com/groupshell/entity/chatgpt/TestChatGpt5.java diff --git a/common/src/main/java/com/groupshell/enumeration/ReimburseStatusEnum.java b/common/src/main/java/com/groupshell/enumeration/ReimburseStatusEnum.java new file mode 100644 index 0000000..9747fb9 --- /dev/null +++ b/common/src/main/java/com/groupshell/enumeration/ReimburseStatusEnum.java @@ -0,0 +1,9 @@ +package com.groupshell.enumeration; + +public enum ReimburseStatusEnum { + + NO_NEED, // 无需报销 + PENDING, // 待报销 + IN_PROCESS, // 报销中 + REIMBURSED // 已报销 +} diff --git a/pojo/src/main/java/com/groupshell/entity/Invoice.java b/pojo/src/main/java/com/groupshell/entity/Invoice.java index 115fd0a..5a78e8f 100644 --- a/pojo/src/main/java/com/groupshell/entity/Invoice.java +++ b/pojo/src/main/java/com/groupshell/entity/Invoice.java @@ -1,15 +1,13 @@ package com.groupshell.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; + import com.groupshell.enumeration.InvoiceTypeEnum; +import com.groupshell.enumeration.ReimburseStatusEnum; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; -import java.io.Serializable; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -23,39 +21,57 @@ import java.time.LocalDateTime; @ToString @NoArgsConstructor @AllArgsConstructor -@TableName("invoice") -public class Invoice implements Serializable -{ +public class Invoice { /** * The unique identifier for the invoice. * 主键,自增 */ - @TableId(value="id", type=IdType.AUTO) private Integer id; + /** * The amount of the invoice. * 使用BigDecimal进行与财务相关的计算,避免出现浮点数运算误差 */ private BigDecimal amount; + + private InvoiceTypeEnum type; /** * 非空 */ + /** * The description of the invoice. */ - private String description; + private String description; //TODO:description数据库字段类型改为TEXT? + /** * The category of the invoice. */ private String category; + /** * The date and time when the invoice was created. */ private LocalDateTime createdTime; + + //TODO:更新时间,更新人 /** * The user ID associated with the invoice. * 外键引用user表的id */ - private Integer userId; + private Integer userId; //账单创建人 + + private String payMethod; //支付方式 + + private ReimburseStatusEnum reimburseStatus; + + private LocalDateTime reimburseRequestTime; // 报销申请时间 + + private LocalDateTime reimburseCompleteTime; // 报销完成时间 + + private Integer approverId; // 审批者ID + + private String reimburseNotes; // 报销备注 + } \ No newline at end of file diff --git a/pojo/src/main/java/com/groupshell/entity/chatgpt/KeyRandomStrategy.java b/pojo/src/main/java/com/groupshell/entity/chatgpt/KeyRandomStrategy.java new file mode 100644 index 0000000..f17fc57 --- /dev/null +++ b/pojo/src/main/java/com/groupshell/entity/chatgpt/KeyRandomStrategy.java @@ -0,0 +1,20 @@ +package com.groupshell.entity.chatgpt; + +import cn.hutool.core.util.RandomUtil; +import com.unfbx.chatgpt.function.KeyStrategyFunction; + +import java.util.List; + +/** + * 描述:随机策略 + * + * @author https:www.unfbx.com + * @since 2023-04-03 + */ +public class KeyRandomStrategy implements KeyStrategyFunction, String> { + + @Override + public String apply(List apiKeys) { + return RandomUtil.randomEle(apiKeys); + } +} \ No newline at end of file diff --git a/pojo/src/main/java/com/groupshell/entity/chatgpt/TestChatGpt4.java b/pojo/src/main/java/com/groupshell/entity/chatgpt/TestChatGpt4.java new file mode 100644 index 0000000..277a83c --- /dev/null +++ b/pojo/src/main/java/com/groupshell/entity/chatgpt/TestChatGpt4.java @@ -0,0 +1,72 @@ +package com.groupshell.entity.chatgpt; + +import com.unfbx.chatgpt.OpenAiStreamClient; +import com.unfbx.chatgpt.entity.chat.ChatCompletion; +import com.unfbx.chatgpt.entity.chat.ChatCompletionResponse; +import com.unfbx.chatgpt.entity.chat.Message; +import com.unfbx.chatgpt.sse.ConsoleEventSourceListener; + +import java.util.Arrays; +import java.util.concurrent.CountDownLatch; + +public class TestChatGpt4 { + public static void main(String[] args) { +// //日志拦截器 +// HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new OpenAILogger()); +// //!!!!千万别再生产或者测试环境打开BODY级别日志!!!! +// //!!!生产或者测试环境建议设置为这三种级别:NONE,BASIC,HEADERS,!!! +// httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); +// +// OkHttpClient okHttpClient = new OkHttpClient.Builder() +//// .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080))) // 设置代理 +// .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890))) // 设置代理 +// .addInterceptor(httpLoggingInterceptor) +// .connectTimeout(15, TimeUnit.SECONDS) +// .writeTimeout(15, TimeUnit.SECONDS) +// .readTimeout(15, TimeUnit.SECONDS) +// .build(); +// +// OpenAiClient client = OpenAiClient.builder() +// .apiKey(Arrays.asList("sk-OA8YqWsVOIIPeGWlD86eB41a9284495085Ab17A08c514b1e")) +// .keyStrategy(new KeyRandomStrategy()) +// .okHttpClient(okHttpClient) +//// .apiHost("https://pro.aiskt.com/") +//// .apiHost("https://one.aiskt.com") +// .apiHost("https://key.aiskt.com") +// .build(); +// +// +// List messages = new ArrayList<>(); +// messages.add(Message.builder().role(Message.Role.USER).content("您好,我想了解更多关于您的服务。").build()); +// +// ChatCompletion chatCompletion = ChatCompletion.builder().messages(messages).build(); +// ChatCompletionResponse response = client.chatCompletion(chatCompletion); +// +// System.out.println("响应:" + response.getChoices().get(0).getMessage().getContent()); + + + OpenAiStreamClient streamClient = OpenAiStreamClient.builder() + .apiKey(Arrays.asList("sk-OA8YqWsVOIIPeGWlD86eB41a9284495085Ab17A08c514b1e")) +// .apiKey(Arrays.asList("sk-pBE3MEC3Q6g0KcrpF043815cAe494f2682Ac180032C33bB5")) + .apiHost("https://pro.aiskt.com/") //支持GPT4 +// .apiHost("https://one.aiskt.com/") //不支持GPT4 + .build(); + //聊天模型:gpt-3.5 + ConsoleEventSourceListener eventSourceListener = new ConsoleEventSourceListener(); + Message message = Message.builder().role(Message.Role.USER).content("你好,你是谁?").build(); +// Message message = Message.builder().role(Message.Role.USER).content("你是GPT4吗?").build(); + ChatCompletion chatCompletion = ChatCompletion.builder().messages(Arrays.asList(message)).build(); + chatCompletion.setModel(ChatCompletion.Model.GPT_4.getName()); + streamClient.streamChatCompletion(chatCompletion, eventSourceListener); + + ChatCompletionResponse chatCompletionResponse = new ChatCompletionResponse(); + + CountDownLatch countDownLatch = new CountDownLatch(1); + + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/pojo/src/main/java/com/groupshell/entity/chatgpt/TestChatGpt5.java b/pojo/src/main/java/com/groupshell/entity/chatgpt/TestChatGpt5.java new file mode 100644 index 0000000..9fb0dc3 --- /dev/null +++ b/pojo/src/main/java/com/groupshell/entity/chatgpt/TestChatGpt5.java @@ -0,0 +1,72 @@ +package com.groupshell.entity.chatgpt; + +import com.unfbx.chatgpt.OpenAiStreamClient; +import com.unfbx.chatgpt.entity.chat.ChatCompletion; +import com.unfbx.chatgpt.entity.chat.ChatCompletionResponse; +import com.unfbx.chatgpt.entity.chat.Message; +import com.unfbx.chatgpt.sse.ConsoleEventSourceListener; + +import java.util.Arrays; +import java.util.concurrent.CountDownLatch; + +public class TestChatGpt5 { + public static void main(String[] args) { +// //日志拦截器 +// HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new OpenAILogger()); +// //!!!!千万别再生产或者测试环境打开BODY级别日志!!!! +// //!!!生产或者测试环境建议设置为这三种级别:NONE,BASIC,HEADERS,!!! +// httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); +// +// OkHttpClient okHttpClient = new OkHttpClient.Builder() +//// .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080))) // 设置代理 +// .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890))) // 设置代理 +// .addInterceptor(httpLoggingInterceptor) +// .connectTimeout(15, TimeUnit.SECONDS) +// .writeTimeout(15, TimeUnit.SECONDS) +// .readTimeout(15, TimeUnit.SECONDS) +// .build(); +// +// OpenAiClient client = OpenAiClient.builder() +// .apiKey(Arrays.asList("sk-OA8YqWsVOIIPeGWlD86eB41a9284495085Ab17A08c514b1e")) +// .keyStrategy(new KeyRandomStrategy()) +// .okHttpClient(okHttpClient) +//// .apiHost("https://pro.aiskt.com/") +//// .apiHost("https://one.aiskt.com") +// .apiHost("https://key.aiskt.com") +// .build(); +// +// +// List messages = new ArrayList<>(); +// messages.add(Message.builder().role(Message.Role.USER).content("您好,我想了解更多关于您的服务。").build()); +// +// ChatCompletion chatCompletion = ChatCompletion.builder().messages(messages).build(); +// ChatCompletionResponse response = client.chatCompletion(chatCompletion); +// +// System.out.println("响应:" + response.getChoices().get(0).getMessage().getContent()); + + + OpenAiStreamClient streamClient = OpenAiStreamClient.builder() + .apiKey(Arrays.asList("sk-OA8YqWsVOIIPeGWlD86eB41a9284495085Ab17A08c514b1e")) +// .apiKey(Arrays.asList("sk-pBE3MEC3Q6g0KcrpF043815cAe494f2682Ac180032C33bB5")) + .apiHost("https://pro.aiskt.com/") //支持GPT4 +// .apiHost("https://one.aiskt.com/") //不支持GPT4 + .build(); + //聊天模型:gpt-3.5 + ConsoleEventSourceListener eventSourceListener = new ConsoleEventSourceListener(); + Message message = Message.builder().role(Message.Role.USER).content("你好,你是谁?").build(); +// Message message = Message.builder().role(Message.Role.USER).content("你是GPT4吗?").build(); + ChatCompletion chatCompletion = ChatCompletion.builder().messages(Arrays.asList(message)).build(); + chatCompletion.setModel(ChatCompletion.Model.GPT_4.getName()); + streamClient.streamChatCompletion(chatCompletion, eventSourceListener); + + ChatCompletionResponse chatCompletionResponse = new ChatCompletionResponse(); + + CountDownLatch countDownLatch = new CountDownLatch(1); + + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/server/src/main/java/com/groupshell/controller/InvoiceCtrl.java b/server/src/main/java/com/groupshell/controller/InvoiceCtrl.java index eb055aa..7de561c 100644 --- a/server/src/main/java/com/groupshell/controller/InvoiceCtrl.java +++ b/server/src/main/java/com/groupshell/controller/InvoiceCtrl.java @@ -1,7 +1,10 @@ package com.groupshell.controller; import com.groupshell.entity.Invoice; +import com.groupshell.enumeration.ReimburseStatusEnum; +import com.groupshell.result.Result; import com.groupshell.service.InvoiceService; +import io.swagger.v3.oas.models.security.SecurityScheme; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -12,60 +15,98 @@ import java.util.Map; @RestController @RequestMapping("/api/invoice") -public class InvoiceCtrl -{ - private final InvoiceService invoiceService; - public InvoiceCtrl(InvoiceService invoiceService) {this.invoiceService=invoiceService;} +public class InvoiceCtrl { + + @Autowired + private InvoiceService invoiceService; + @PostMapping - public Invoice addInvoice(@RequestBody Invoice record) - { - return invoiceService.addInvoice(record); + public Result addInvoice(@RequestBody Invoice record) { + invoiceService.addInvoice(record); + return Result.success(Boolean.TRUE); } + // 根据ID获取发票信息 @GetMapping("/{id}") - public Invoice getInvoiceById(@PathVariable Integer id) - { - return invoiceService.getInvoiceById(id); + public Result getInvoiceById(@PathVariable Integer id) { + Invoice invoice = invoiceService.getInvoiceById(id); + return Result.success(invoice); } + @GetMapping - public List getAllInvoices() - { - return invoiceService.getAllInvoices(); + public Result> getAllInvoices() { + List invoices = invoiceService.getAllInvoices(); + return Result.success(invoices); } + @PutMapping("/{id}") - public Invoice updateInvoice(@PathVariable Integer id,@RequestBody Invoice record) - { - record.setId(id); - return invoiceService.updateInvoice(record); + public Result updateInvoice(@PathVariable Integer id, @RequestBody Invoice record) { + //record.setId(id); //TODO:这里的逻辑是不是有问题 + invoiceService.updateInvoice(record); + return Result.success(Boolean.TRUE); } + @DeleteMapping("/{id}") - public String deleteInvoice(@PathVariable Integer id) - { - return invoiceService.deleteInvoice(id); + public Result deleteInvoice(@PathVariable Integer id) { + invoiceService.deleteInvoice(id); + return Result.success(Boolean.TRUE); } + // 获取指定时间段内的总支出 @GetMapping("/expenses") - public BigDecimal getExpensesByTime(@RequestParam LocalDateTime start,@RequestParam LocalDateTime end) - { - return invoiceService.getExpensesByTime(start,end); + public Result getExpensesByTime(@RequestParam LocalDateTime start, @RequestParam LocalDateTime end) { + BigDecimal expense = invoiceService.getExpensesByTime(start, end); + return Result.success(expense); } + // 获取指定时间段内的总收入 @GetMapping("/incomes") - public BigDecimal getIncomesByTime(@RequestParam LocalDateTime start,@RequestParam LocalDateTime end) - { - return invoiceService.getIncomesByTime(start,end); + public Result getIncomesByTime(@RequestParam LocalDateTime start, @RequestParam LocalDateTime end) { + BigDecimal income = invoiceService.getIncomesByTime(start, end); + return Result.success(income); } + // 获取指定时间段内的净收入 @GetMapping("/netIncome") - public BigDecimal getNetIncomeByTime(@RequestParam LocalDateTime start,@RequestParam LocalDateTime end) - { - return invoiceService.getNetIncomeByTime(start,end); + public Result getNetIncomeByTime(@RequestParam LocalDateTime start, @RequestParam LocalDateTime end) { + BigDecimal netIncome = invoiceService.getNetIncomeByTime(start, end); + return Result.success(netIncome); } + // 获取指定类别和时间段内的支出汇总 @GetMapping("/expensesByCategory") - public Map getExpensesByCategory(@RequestParam String category, - @RequestParam LocalDateTime start,@RequestParam LocalDateTime end) - { - return invoiceService.getExpensesByCategory(category,start,end); + public Result> getExpensesByCategory(@RequestParam String category, + @RequestParam LocalDateTime start, + @RequestParam LocalDateTime end) { + Map expense = invoiceService.getExpensesByCategory(category, start, end); + return Result.success(expense); + } + + // 更新发票的报销状态 + @PutMapping("/{id}/reimburse") + public Result updateReimburseStatus(@PathVariable Integer id, @RequestParam ReimburseStatusEnum status) { + invoiceService.updateReimburseStatus(id, status); + return Result.success(Boolean.TRUE); + } + + // 根据报销状态查询发票 + @GetMapping("/reimburseStatus/{status}") + public Result> findInvoicesByReimbursementStatus(@PathVariable ReimburseStatusEnum status) { + List invoices = invoiceService.findInvoicesByReimburseStatus(status); + return Result.success(invoices); + } + + // 统计指定时间段内的报销金额 + @GetMapping("/reimburse/sum") + public Result sumReimbursementAmount(@RequestParam LocalDateTime start, @RequestParam LocalDateTime end) { + BigDecimal amount = invoiceService.sumReimburseAmount(start, end); + return Result.success(amount); + } + + // 查询特定用户的报销历史 + @GetMapping("/reimburse/user/{userId}") + public Result> findReimbursementsByUserId(@PathVariable Integer userId) { + List invoices = invoiceService.findReimburseByUserId(userId); + return Result.success(invoices); } } diff --git a/server/src/main/java/com/groupshell/controller/TaskCtrl.java b/server/src/main/java/com/groupshell/controller/TaskCtrl.java index d732cc6..5857a66 100644 --- a/server/src/main/java/com/groupshell/controller/TaskCtrl.java +++ b/server/src/main/java/com/groupshell/controller/TaskCtrl.java @@ -2,52 +2,60 @@ package com.groupshell.controller; import com.groupshell.entity.Task; import com.groupshell.enumeration.TaskStatusEnum; +import com.groupshell.result.Result; import com.groupshell.service.TaskService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/api/task") -public class TaskCtrl -{ - private final TaskService taskService; - public TaskCtrl(TaskService taskService) {this.taskService=taskService;} +public class TaskCtrl { + //TODO:crtl的返回值改为Result + @Autowired + private TaskService taskService; + // 创建任务 @PostMapping - public Task createTask(@RequestBody Task task) - { - return taskService.createTask(task); + public Result createTask(@RequestBody Task task) { + taskService.createTask(task); + return Result.success(Boolean.TRUE); } + // 更新任务 @PutMapping("/{id}") - public Task updateTask(@PathVariable Integer id,@RequestBody Task task) - { - task.setId(id); - return taskService.updateTask(task); + public Result updateTask(@PathVariable Long id, @RequestBody Task task) { + //task.setId(id); + taskService.updateTask(task); + return Result.success(Boolean.TRUE); } + // 删除任务 @DeleteMapping("/{id}") - public boolean deleteTask(@PathVariable Integer id) - { - return taskService.deleteTask(id); + public Result deleteTask(@PathVariable Integer id) { + taskService.deleteTask(id); + return Result.success(Boolean.TRUE); } + // 按创建者ID获取任务列表 @GetMapping("/creator/{creatorId}") - public List listTasksByCreator(@PathVariable Integer creatorId) - { - return taskService.listTasksByCreator(creatorId); + public Result> listTasksByCreator(@PathVariable Integer creatorId) { + List tasks = taskService.listTasksByCreator(creatorId); + return Result.success(tasks); } + // 按受托人ID获取任务列表 @GetMapping("/assignee/{assigneeId}") - public List listTasksByAssignee(@PathVariable Integer assigneeId) - { - return taskService.listTasksByAssignee(assigneeId); + public Result> listTasksByAssignee(@PathVariable Integer assigneeId) { + List tasks = taskService.listTasksByAssignee(assigneeId); + return Result.success(tasks); } + // 按状态获取任务列表 @GetMapping("/status") - public List listTasksByStatus(@RequestParam TaskStatusEnum status) - { - return taskService.listTasksByStatus(status); + public Result> listTasksByStatus(@RequestParam TaskStatusEnum status) { + List tasks = taskService.listTasksByStatus(status); + return Result.success(tasks); } } diff --git a/server/src/main/java/com/groupshell/mapper/InvoiceMapper.java b/server/src/main/java/com/groupshell/mapper/InvoiceMapper.java index 0b5e20a..d27d24b 100644 --- a/server/src/main/java/com/groupshell/mapper/InvoiceMapper.java +++ b/server/src/main/java/com/groupshell/mapper/InvoiceMapper.java @@ -2,30 +2,39 @@ package com.groupshell.mapper; import com.groupshell.entity.Invoice; import com.groupshell.enumeration.InvoiceTypeEnum; -import org.apache.ibatis.annotations.Insert; +import com.groupshell.enumeration.ReimburseStatusEnum; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.math.BigDecimal; import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.List; @Mapper -public interface InvoiceMapper -{ +public interface InvoiceMapper { Invoice insert(Invoice record); - + Invoice findById(@Param("id") Integer id); - + List findAllInvoice(); - + Invoice updateInvoiceById(Invoice record); - + String deleteById(@Param("id") Integer id); - - BigDecimal sumAmountByDate(@Param("type") InvoiceTypeEnum type,@Param("start") LocalDateTime start, - @Param("end") LocalDateTime end); - - List findByCategoryAndDate(@Param("category") String category,@Param("start") LocalDateTime start,@Param( - "end") LocalDateTime end); + + BigDecimal sumAmountByDate(@Param("type") InvoiceTypeEnum type, + @Param("start") LocalDateTime start, + @Param("end") LocalDateTime end); + + List findByCategoryAndDate(@Param("category") String category, + @Param("start") LocalDateTime start, + @Param("end") LocalDateTime end); + + + List findByReimburseStatus(ReimburseStatusEnum status); + + BigDecimal sumReimburseAmountByDate(LocalDateTime start, LocalDateTime end); + + List findReimbursementsByUserId(Integer userId); } diff --git a/server/src/main/java/com/groupshell/service/InvoiceService.java b/server/src/main/java/com/groupshell/service/InvoiceService.java index e223c3a..2ce95e0 100644 --- a/server/src/main/java/com/groupshell/service/InvoiceService.java +++ b/server/src/main/java/com/groupshell/service/InvoiceService.java @@ -1,6 +1,7 @@ package com.groupshell.service; import com.groupshell.entity.Invoice; +import com.groupshell.enumeration.ReimburseStatusEnum; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -9,23 +10,31 @@ import java.util.List; import java.util.Map; @Service -public interface InvoiceService -{ +public interface InvoiceService { + public Invoice addInvoice(Invoice record); - + public Invoice getInvoiceById(Integer id); - + public List getAllInvoices(); - + public Invoice updateInvoice(Invoice record); - + public String deleteInvoice(Integer id); - - public BigDecimal getExpensesByTime(LocalDateTime start,LocalDateTime end); - - BigDecimal getIncomesByTime(LocalDateTime start,LocalDateTime end); - - BigDecimal getNetIncomeByTime(LocalDateTime start,LocalDateTime end); - - Map getExpensesByCategory(String category,LocalDateTime start,LocalDateTime end); + + public BigDecimal getExpensesByTime(LocalDateTime start, LocalDateTime end); + + BigDecimal getIncomesByTime(LocalDateTime start, LocalDateTime end); + + BigDecimal getNetIncomeByTime(LocalDateTime start, LocalDateTime end); + + Map getExpensesByCategory(String category, LocalDateTime start, LocalDateTime end); + + Invoice updateReimburseStatus(Integer id, ReimburseStatusEnum status); + + List findInvoicesByReimburseStatus(ReimburseStatusEnum status); + + BigDecimal sumReimburseAmount(LocalDateTime start, LocalDateTime end); + + List findReimburseByUserId(Integer userId); } diff --git a/server/src/main/java/com/groupshell/service/impl/InvoiceServiceImpl.java b/server/src/main/java/com/groupshell/service/impl/InvoiceServiceImpl.java index 268f439..f43f8de 100644 --- a/server/src/main/java/com/groupshell/service/impl/InvoiceServiceImpl.java +++ b/server/src/main/java/com/groupshell/service/impl/InvoiceServiceImpl.java @@ -2,6 +2,7 @@ package com.groupshell.service.impl; import com.groupshell.entity.Invoice; import com.groupshell.enumeration.InvoiceTypeEnum; +import com.groupshell.enumeration.ReimburseStatusEnum; import com.groupshell.mapper.InvoiceMapper; import com.groupshell.service.InvoiceService; import org.springframework.beans.factory.annotation.Autowired; @@ -14,62 +15,87 @@ import java.util.Map; import java.util.stream.Collectors; @Service -public class InvoiceServiceImpl implements InvoiceService -{ - private final InvoiceMapper invoiceMapper; - public InvoiceServiceImpl(InvoiceMapper invoiceMapper) {this.invoiceMapper=invoiceMapper;} +public class InvoiceServiceImpl implements InvoiceService { + + @Autowired + private InvoiceMapper invoiceMapper; + @Override - public Invoice addInvoice(Invoice record) - { + public Invoice addInvoice(Invoice record) { return invoiceMapper.insert(record); } + //TODO:实现Controller类的函数 @Override - public Invoice getInvoiceById(Integer id) - { + public Invoice getInvoiceById(Integer id) { return invoiceMapper.findById(id); } + @Override - public List getAllInvoices() - { + public List getAllInvoices() { return invoiceMapper.findAllInvoice(); } + @Override - public Invoice updateInvoice(Invoice record) - { + public Invoice updateInvoice(Invoice record) { return invoiceMapper.updateInvoiceById(record); } + @Override - public String deleteInvoice(Integer id) - { + public String deleteInvoice(Integer id) { invoiceMapper.deleteById(id); return "Record deleted successfully!"; } + //TODO:实现Controller类的函数 @Override - public BigDecimal getExpensesByTime(LocalDateTime start,LocalDateTime end) - { - return invoiceMapper.sumAmountByDate(InvoiceTypeEnum.EXPENSE,start,end); + public BigDecimal getExpensesByTime(LocalDateTime start, LocalDateTime end) { + return invoiceMapper.sumAmountByDate(InvoiceTypeEnum.EXPENSE, start, end); } + @Override - public BigDecimal getIncomesByTime(LocalDateTime start,LocalDateTime end) - { - return invoiceMapper.sumAmountByDate(InvoiceTypeEnum.INCOME,start,end); + public BigDecimal getIncomesByTime(LocalDateTime start, LocalDateTime end) { + return invoiceMapper.sumAmountByDate(InvoiceTypeEnum.INCOME, start, end); } + @Override - public BigDecimal getNetIncomeByTime(LocalDateTime start,LocalDateTime end) - { - BigDecimal income=invoiceMapper.sumAmountByDate(InvoiceTypeEnum.INCOME,start,end); - BigDecimal expenses=invoiceMapper.sumAmountByDate(InvoiceTypeEnum.EXPENSE,start,end); + public BigDecimal getNetIncomeByTime(LocalDateTime start, LocalDateTime end) { + BigDecimal income = invoiceMapper.sumAmountByDate(InvoiceTypeEnum.INCOME, start, end); + BigDecimal expenses = invoiceMapper.sumAmountByDate(InvoiceTypeEnum.EXPENSE, start, end); return income.subtract(expenses); } + + //从数据库查询特定类别和时间范围内的发票,然后计算每个类别的总金额,并以Map形式返回结果 @Override - public Map getExpensesByCategory(String category,LocalDateTime start,LocalDateTime end) - { - List records=invoiceMapper.findByCategoryAndDate(category,start,end); - return records.stream() - .collect(Collectors.groupingBy(Invoice::getCategory,Collectors.reducing(BigDecimal.ZERO, - Invoice::getAmount,BigDecimal::add))); + public Map getExpensesByCategory(String category, LocalDateTime start, LocalDateTime end) { + List records = invoiceMapper.findByCategoryAndDate(category, start, end); + return records.stream().collect(Collectors.groupingBy(Invoice::getCategory, + Collectors.reducing(BigDecimal.ZERO, Invoice::getAmount, BigDecimal::add))); + } + + // 新增方法:更新报销状态 + public Invoice updateReimburseStatus(Integer invoiceId, ReimburseStatusEnum status) { + Invoice invoice = invoiceMapper.findById(invoiceId); + if (invoice != null) { + invoice.setReimburseStatus(status); + invoiceMapper.updateInvoiceById(invoice); + } + return invoice; + } + + // 新增方法:查询特定报销状态的账单 + public List findInvoicesByReimburseStatus(ReimburseStatusEnum status) { + return invoiceMapper.findByReimburseStatus(status); + } + + // 新增方法:统计特定时间段内的报销金额 + public BigDecimal sumReimburseAmount(LocalDateTime start, LocalDateTime end) { + return invoiceMapper.sumReimburseAmountByDate(start, end); + } + + // 新增方法:查询特定用户的报销历史 + public List findReimburseByUserId(Integer userId) { + return invoiceMapper.findReimbursementsByUserId(userId); } } diff --git a/server/src/main/resources/mapper/InvoiceMapper.xml b/server/src/main/resources/mapper/InvoiceMapper.xml index 92cfcb1..2f95c44 100644 --- a/server/src/main/resources/mapper/InvoiceMapper.xml +++ b/server/src/main/resources/mapper/InvoiceMapper.xml @@ -1,71 +1,130 @@ - + - - id, amount, type, description, category, created_time, user_id + + id, amount, type, description, category, created_time, user_id, pay_method, + reimburse_status, reimburse_request_time, reimburse_complete_time, + approver_id, reimburse_notes + + + #{id}, + #{amount}, + #{type}, + #{description}, + #{category}, + #{createdTime}, + #{userId}, + #{payMethod}, + #{reimburseStatus}, + #{reimburseRequestTime}, + #{reimburseCompleteTime}, + #{approverId}, + #{reimburseNotes} - - INSERT INTO invoice () - VALUES (#{id}, #{amount},#{type}, #{description}, #{category}, #{created_time}, #{user_id}) + + INSERT INTO invoice () + VALUES () - SELECT * FROM invoice WHERE id = #{id} - SELECT * FROM invoice -# WHERE user_id = #{userId} - + UPDATE invoice - + amount = #{amount}, - + type = #{type}, - + description = #{description}, - + category = #{category}, - + created_time = #{createdTime}, - + user_id = #{userId}, + + pay_method = #{payMethod}, + + + reimburse_status = #{reimburseStatus}, + + + reimburse_request_time = #{reimburseRequestTime}, + + + reimburse_complete_time = #{reimburseCompleteTime}, + + + approver_id = #{approverId}, + + + reimburse_notes = #{reimburseNotes}, + WHERE id = #{id} - + DELETE FROM invoice WHERE id = #{id} - SELECT SUM(amount) AS totalAmount FROM invoice WHERE type = #{type} AND created_time BETWEEN #{start} AND #{end} - SELECT * FROM invoice WHERE category = #{category} AND created_time BETWEEN #{start} AND #{end} + + + + + + + + + -- Gitee From 0848d4e54ec7ac11ac1b10b2e6958544dc78510d Mon Sep 17 00:00:00 2001 From: EricCheng <12955029+ericchengscut@user.noreply.gitee.com> Date: Mon, 22 Apr 2024 20:21:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AF=BC=E5=85=A5gpt=E6=8E=A5=E5=8F=A3mave?= =?UTF-8?q?n=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pojo/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pojo/pom.xml b/pojo/pom.xml index 7b45bb2..ee66ef9 100644 --- a/pojo/pom.xml +++ b/pojo/pom.xml @@ -27,6 +27,11 @@ lombok provided + + com.unfbx + chatgpt-java + 1.0.14-beta1 + com.groupshell common -- Gitee