控制层编写

控制层编写

报销申请控制层

 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("删除申请")
     @GetMapping("/delete")
     public int removeInvoice(Integer id) {
         int code = invoiceService.remove(id);
         return code==1?200:404;
    }
 
 
     @ApiOperation("更改报销申请")
     @PostMapping("/update")
     public int updateInvoice(@RequestBody Invoice invoice){
         int update = invoiceService.update(BeanUtil.beanToMap(invoice));
         return update==1?200:404;
    }
 
 
     @ApiOperation("当前编辑记录id")
     @GetMapping("/detail")
     public Invoice getCurrInvoice(Integer id){
         return invoiceService.searchById(id);
    }
 
     @ApiOperation("所有申请列表")
     @PostMapping("list")
     public List<Invoice> getlist(){
         return invoiceService.findAll();
    }
 
 
     @ApiOperation("管理员审批同意")
     @GetMapping("/approve")
     public int approve(Integer id){
         Invoice invoice = invoiceService.searchById(id);
         System.out.println(invoice.getName());
         Users users = userSecurityDetailService.findByNickName(invoice.getName());
         Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
         Map<String,Object> map = BeanUtil.beanToMap(principal);
         String username =(String) map.get("username");
         Users operate = userSecurityDetailService.findByName(username);
         Reimburse reimburse = new Reimburse();
         reimburse.setUserId(users.getId());
         reimburse.setOperateId(operate.getId());
         reimburse.setCreateTime(invoice.getBillDate());
         reimburse.setEndTime(new Date());
         reimburse.setMoney(invoice.getMoney());
         int add = reimburseSevice.add(reimburse);
         return add==1?200:404;
    }
 }

用户控制

 package com.cao.frs.controller;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.StrUtil;
 import com.cao.frs.entities.Reimburse;
 import com.cao.frs.entities.Users;
 import com.cao.frs.service.ReimburseSeviceImpl;
 import com.cao.frs.service.UserSecurityDetailService;
 import com.cao.frs.utils.out.ReimOut;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiModel;
 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.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 @Api(tags = "报销记录")
 @RestController
 @RequestMapping("/reimburse")
 public class ReimburseController {
     @Autowired
     ReimburseSeviceImpl reimburseseviceimpl;
 
     @Autowired
     UserSecurityDetailService userSecurityDetailService;
 
     @ApiOperation("所有报销记录")
     @PostMapping("/list")
     public List<ReimOut> getlist(){
         List<ReimOut> reimOuts = new ArrayList<>();
         List<Reimburse> list = reimburseseviceimpl.findAll();
 
         for (Reimburse reimburse : list) {
             reimOuts.add(new ReimOut(reimburse.getId(),
                     userSecurityDetailService.findById(reimburse.getUserId()).getUsername()
                    ,reimburse.getCreateTime()
                    ,reimburse.getEndTime()
                    ,userSecurityDetailService.findById(reimburse.getOperateId()).getUsername()
                    ,reimburse.getMoney()));
        }
         //System.out.println(reimOuts);
         return reimOuts;
    }
 
     @ApiOperation("已完成报销记录")
     @PostMapping("/currlist")
     public List<ReimOut> getCurr(){
         Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
         Map<String,Object> map = BeanUtil.beanToMap(principal);
         String username =(String) map.get("username");
         String user = userSecurityDetailService.findByName(username).getUsername();
         List<Reimburse> list = reimburseseviceimpl.findAll();
         List<ReimOut> reimOuts = new ArrayList<>();
         for (Reimburse reimburse : list) {
             if (userSecurityDetailService.findById(reimburse.getUserId()).getUsername().equals(user)){
                     reimOuts.add(new ReimOut(reimburse.getId(),
                     userSecurityDetailService.findById(reimburse.getUserId()).getUsername()
                    ,reimburse.getCreateTime()
                    ,reimburse.getEndTime()
                    ,userSecurityDetailService.findById(reimburse.getOperateId()).getUsername()
                    ,reimburse.getMoney()));}
        }
         return reimOuts;
    }
 }
 

路由控制器

 package com.cao.frs.controller;
 
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 @Api(tags = "路由")
 @Controller
 public class RouteController {
 
     /**
      * 跳转登录
      */
     @ApiOperation("跳转登录页")
     @GetMapping({"/login","/","logout"})
     public String toLogin() {
         return "login";
    }
 
     /**
      * 跳转首页
      */
     @ApiOperation("跳转首页")
     @RequestMapping({"/index"})
     public String toIndex() {
         return "index";
    }
     /**
      * 跳转欢迎页面
      */
     @ApiOperation("跳转欢迎页面")
     @RequestMapping({"/welcome"})
     public String toWelcome() {
         return "welcome";
    }
 
     /**
      * 二级路由跳转
      * @param name 映射名称
      */
     @ApiOperation("二级路由跳转")
     @RequestMapping("/{filename}/{name}")
     public String change(@PathVariable String filename, @PathVariable String name) {
         return filename+"/"+name;
    }
 }
 

报销记录控制器

 package com.cao.frs.controller;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.StrUtil;
 import com.cao.frs.entities.Reimburse;
 import com.cao.frs.entities.Users;
 import com.cao.frs.service.ReimburseSeviceImpl;
 import com.cao.frs.service.UserSecurityDetailService;
 import com.cao.frs.utils.out.ReimOut;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiModel;
 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.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 @Api(tags = "报销记录")
 @RestController
 @RequestMapping("/reimburse")
 public class ReimburseController {
     @Autowired
     ReimburseSeviceImpl reimburseseviceimpl;
 
     @Autowired
     UserSecurityDetailService userSecurityDetailService;
 
     @ApiOperation("所有报销记录")
     @PostMapping("/list")
     public List<ReimOut> getlist(){
         List<ReimOut> reimOuts = new ArrayList<>();
         List<Reimburse> list = reimburseseviceimpl.findAll();
 
         for (Reimburse reimburse : list) {
             reimOuts.add(new ReimOut(reimburse.getId(),
                     userSecurityDetailService.findById(reimburse.getUserId()).getUsername()
                    ,reimburse.getCreateTime()
                    ,reimburse.getEndTime()
                    ,userSecurityDetailService.findById(reimburse.getOperateId()).getUsername()
                    ,reimburse.getMoney()));
        }
         //System.out.println(reimOuts);
         return reimOuts;
    }
 
     @ApiOperation("已完成报销记录")
     @PostMapping("/currlist")
     public List<ReimOut> getCurr(){
         Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
         Map<String,Object> map = BeanUtil.beanToMap(principal);
         String username =(String) map.get("username");
         String user = userSecurityDetailService.findByName(username).getUsername();
         List<Reimburse> list = reimburseseviceimpl.findAll();
         List<ReimOut> reimOuts = new ArrayList<>();
         for (Reimburse reimburse : list) {
             if (userSecurityDetailService.findById(reimburse.getUserId()).getUsername().equals(user)){
                     reimOuts.add(new ReimOut(reimburse.getId(),
                     userSecurityDetailService.findById(reimburse.getUserId()).getUsername()
                    ,reimburse.getCreateTime()
                    ,reimburse.getEndTime()
                    ,userSecurityDetailService.findById(reimburse.getOperateId()).getUsername()
                    ,reimburse.getMoney()));}
        }
         return reimOuts;
    }
 }
 

Dock文档

 FROM java:8
 
 COPY *.jar /app.jar
 
 CMD ["--server.port=8080"]
 
 EXPOSE 8080
 
 ENTRYPOINT ["java","-jar","/app.jar"]

 

posted on 2022-01-09 16:15  阿ming  阅读(44)  评论(0编辑  收藏  举报

导航