package com.stylefeng.guns.modular.system.controller; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.intuit.oauth2.exception.InvalidRequestException; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.service.ITPriceService; import com.stylefeng.guns.modular.system.utils.InvoicesDataUploadUtil; import com.stylefeng.guns.modular.system.utils.RedisUtil; import com.stylefeng.guns.modular.system.utils.tips.ErrorTip; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.ITOrderService; import com.stylefeng.guns.modular.system.utils.tips.SuccessTip; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.cache.CacheProperties; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.View; import javax.annotation.Resource; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; @Controller @Api(tags = "财务信息") @RequestMapping("/api/tFinance") @Slf4j public class FinanceController { @Autowired private ITOrderService orderService; @Autowired private RedisUtil redisUtil; private final String INVOICE_DATA = "CARINVOICE:"; @ApiOperation(value = "卡车公司-应收报表列表",notes="卡车公司-应收报表列表") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "time", value = "时间 (时间 - 时间)", required = false, dataType = "String"), @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "String"), @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int"), }) @PostMapping(value = "/list") @ResponseBody public Object list(int pageNumber,int pageSize,String time,String name,int id) { Page receivableVoPage = new Page<>(pageNumber, pageSize); return new SuccessTip(orderService.getReceivable(receivableVoPage,time,name,id)); } @ApiOperation(value = "应付报表列表",notes="应付报表列表") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "time", value = "时间 (时间 - 时间)", required = false, dataType = "String"), @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "String"), @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int"), }) @PostMapping(value = "/payList") @ResponseBody public Object payList(int pageNumber,int pageSize,String time,String name,int id) { Page receivableVoPage = new Page<>(pageNumber, pageSize); return new SuccessTip(orderService.getPayList(receivableVoPage,time,name,id)); } @ApiOperation(value = "应收款票据列表",notes="应收款票据列表") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "time", value = "时间 (时间 - 时间)", required = false, dataType = "String"), @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "String"), @ApiImplicitParam(name = "invoicesId", value = "invoicesId", required = false, dataType = "Integer"), @ApiImplicitParam(name = "orderId", value = "orderId", required = false, dataType = "Integer"), @ApiImplicitParam(name = "state", value = "1未支付完 2已支付", required = false, dataType = "Integer"), @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer"), }) @PostMapping(value = "/listOfReceivables") @ResponseBody public Object listOfReceivables(int pageNumber,int pageSize,String time,String name,Integer invoicesId,Integer orderId,Integer state,Integer id) { Page receivableVoPage = new Page<>(pageNumber, pageSize); List receivablesLists = orderService.listOfReceivables(receivableVoPage, time, name, invoicesId, orderId, state,id); receivableVoPage.setRecords(receivablesLists); return new SuccessTip(receivableVoPage); } @ApiOperation(value = "应收款票据quickBooks",notes="应收款票据quickBooks") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @GetMapping(value = "/exportQuickBook") @ResponseBody public Object exportQuickBooks(int company){ redisUtil.setStrValue("quick","3"+"_"+company ); try { View view = InvoicesDataUploadUtil.connectToQuickBooks(); log.info("view:{}",view); return new SuccessTip(view); } catch (InvalidRequestException e) { e.printStackTrace(); } return new SuccessTip(); } @ApiOperation(value = "应付款票据quickBooks--bill",notes="应付款票据quickBooks--bill") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @GetMapping(value = "/exportQuickBookBill") @ResponseBody public Object exportQuickBookBill(int company){ redisUtil.setStrValue("quick","4"+"_"+company); try { View view = InvoicesDataUploadUtil.connectToQuickBooks(); log.info("view:{}",view); return new SuccessTip(view); } catch (InvalidRequestException e) { e.printStackTrace(); } return new SuccessTip(); } @ApiOperation(value = "应收款票据详情",notes="应收款票据详情") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "number", value = "订单id", required = true, dataType = "Long"), }) @GetMapping(value = "/listOfReceivablesInfo") @ResponseBody public Object listOfReceivablesInfo(Long number) { return new SuccessTip(orderService.listOfReceivablesInfoOne(number)); } @ApiOperation(value = "应收款票据详情--编辑",notes="应收款票据详情--编辑") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "number", value = "订单id", required = true, dataType = "Long"), }) @GetMapping(value = "/listOfReceivablesInfoUpdate") @ResponseBody public Object listOfReceivablesInfoUpdate(Long number) { return new SuccessTip(orderService.listOfReceivablesInfo(number)); } @Resource private ITPriceService priceService; @ApiOperation(value = "应收款票据详情--添加价格",notes="应收款票据详情--添加价格") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "number", value = "订单id", required = true, dataType = "Long"), @ApiImplicitParam(name = "type", value = "价格类型名称", required = true, dataType = "String"), @ApiImplicitParam(name = "price", value = "价格", required = true, dataType = "Double"), }) @GetMapping(value = "/addPrice") @ResponseBody public Object addPrice(Long number,String type,Double price) { TPrice tPrice = new TPrice(); tPrice.setOrderId(number); tPrice.setType(type); BigDecimal bigDecimal = new BigDecimal(price); tPrice.setPrice(bigDecimal); tPrice.setCarPrice(bigDecimal); tPrice.setCreateTime(new Date()); tPrice.setState("1"); try { priceService.insert(tPrice); return new SuccessTip(); }catch (Exception e){ e.printStackTrace(); } return new ErrorTip(500,"ERROR"); } @ApiOperation(value = "应收款票据详情--编辑价格",notes="应收款票据详情--编辑价格") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), }) @PostMapping(value = "/updatePrice") @ResponseBody public Object updatePrice(@RequestBody List prices,String note) { String randomString = ToolUtil.getRandomString(15); prices.forEach(e->e.setNumber(randomString)); priceService.insertBatch(prices); Long orderId = prices.get(0).getOrderId(); TOrder tOrder = orderService.selectById(orderId); tOrder.setChange(1); tOrder.setNote(note); return new SuccessTip(); } @ApiOperation(value = "应收款票据详情--删除价格",notes="应收款票据详情--删除价格") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "id", value = "价格id", required = true, dataType = "int"), }) @GetMapping(value = "/delPrice") @ResponseBody public Object delPrice(int id) { try { priceService.deleteById(id); return new SuccessTip(); }catch (Exception e){ e.printStackTrace(); } return new ErrorTip(500,"ERROR"); } @ApiOperation(value = "应付款票据列表",notes="应付款票据列表") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"), @ApiImplicitParam(name = "time", value = "时间 (时间 - 时间)", required = false, dataType = "String"), @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "String"), @ApiImplicitParam(name = "billId", value = "billId", required = false, dataType = "Integer"), @ApiImplicitParam(name = "orderId", value = "orderId", required = false, dataType = "Integer"), @ApiImplicitParam(name = "state", value = "1未支付完 2已支付", required = false, dataType = "Integer"), @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer"), }) @GetMapping(value = "/listOfPay") @ResponseBody public Object listOfPay(int pageNumber,int pageSize,String time,String name,Integer billId,Integer orderId,Integer state,Integer id) { Page receivableVoPage = new Page<>(pageNumber, pageSize); List payLists = orderService.listOfPay(receivableVoPage, time, name, billId, orderId, state,id); receivableVoPage.setRecords(payLists); return new SuccessTip(receivableVoPage); } @ApiOperation(value = "应付款票据详情",notes="应付款票据详情") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "number", value = "订单id", required = true, dataType = "Long"), }) @GetMapping(value = "/listOPayInfo") @ResponseBody public Object listOPayInfo(Long number) { return new SuccessTip(orderService.listOPayInfo(number)); } @ApiOperation(value = "应收款票据-Receive a payment",notes="应收款票据-Receive a payment") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), @ApiImplicitParam(name = "number", value = "票据号", required = true, dataType = "String"), }) @GetMapping(value = "/receivePayment") @ResponseBody public Object receivePayment(@RequestParam String number) { TOrder tOrder = orderService.selectOne(new EntityWrapper().eq("invoice_number", number).eq("status", 1)); tOrder.setPayStatus(1); tOrder.setSuccessTime(new Date()); boolean b = orderService.updateById(tOrder); return new SuccessTip(); } // @ApiOperation(value = "是否同意付款卡车公司",notes="是否同意付款卡车公司") // @ApiImplicitParams({ // @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), // }) // @PostMapping(value = "/agreeOfPayment") // @ResponseBody // public Object confirmationOfPayment(@RequestBody PaymentReq req) { // return new SuccessTip(orderService.confirmationOfPayment(req // .getNumber(),req.getType(),req.getRemark())); // } // // @ApiOperation(value = "卡车公司付款确认",notes="卡车公司付款确认") // @ApiImplicitParams({ // @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), // @ApiImplicitParam(name = "number", value = "订单id", required = true, dataType = "Long"), // }) // @GetMapping(value = "/confirmationOfPayment") // @ResponseBody // public Object confirmationOfPayment(@RequestParam Long number) { // return new SuccessTip(orderService.agreeOfPayment(number)); // } }