控制层编写
报销申请控制层
package com.cao.frs.controller;
import cn.hutool.core.bean.BeanUtil;
import com.cao.frs.entities.Invoice;
import com.cao.frs.entities.Reimburse;
import com.cao.frs.entities.Users;
import com.cao.frs.service.InvoiceServiceImpl;
import com.cao.frs.service.ReimburseSeviceImpl;
import com.cao.frs.service.UserSecurityDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Api(tags = "报销申请")
@RestController
@RequestMapping("/invoice")
public class InvoiceController {
@Autowired
InvoiceServiceImpl invoiceService;
@Autowired
UserSecurityDetailService userSecurityDetailService;
@Autowired
ReimburseSeviceImpl reimburseSevice;
@ApiOperation("添加一条申请")
@PostMapping("/add")
public int addInvoice(@RequestBody Invoice invoice){
int add = invoiceService.add(invoice);
return add==1?200:404;
}
@ApiOperation("当前用户申请记录")
@PostMapping("/currlist")
public List<Invoice> getCurrList(){
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Map<String,Object> map = BeanUtil.beanToMap(principal);
String username =(String) map.get("username");
Users users = userSecurityDetailService.findByName(username);
return invoiceService.searchByName(users.getNickname());
}
@ApiOperation("删除申请")