package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.modular.system.controller.resp.TDriverResp;
|
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
|
import com.stylefeng.guns.modular.system.enums.TBillStateEnum;
|
import com.stylefeng.guns.modular.system.model.TDriver;
|
import com.stylefeng.guns.modular.system.model.TOrder;
|
import com.stylefeng.guns.modular.system.service.ITOrderService;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import com.stylefeng.guns.core.log.LogObjectHolder;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import com.stylefeng.guns.modular.system.model.TBill;
|
import com.stylefeng.guns.modular.system.service.ITBillService;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.OutputStream;
|
import java.math.BigDecimal;
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 控制器
|
*
|
* @author fengshuonan
|
* @Date 2023-03-14 15:15:19
|
*/
|
@Controller
|
@RequestMapping("/tBill")
|
public class TBillController extends BaseController {
|
|
private String PREFIX = "/system/tBill/";
|
|
@Autowired
|
private ITBillService tBillService;
|
@Autowired
|
private ITOrderService tOrderService;
|
|
/**
|
* 跳转到首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "tBill.html";
|
}
|
|
/**
|
* 跳转到添加
|
*/
|
@RequestMapping("/tBill_add")
|
public String tBillAdd() {
|
return PREFIX + "tBill_add.html";
|
}
|
|
/**
|
* 跳转到修改
|
*/
|
@RequestMapping("/tBill_update/{tBillId}")
|
public String tBillUpdate(@PathVariable Integer tBillId, Model model) {
|
TBill tBill = tBillService.selectById(tBillId);
|
model.addAttribute("item",tBill);
|
LogObjectHolder.me().set(tBill);
|
return PREFIX + "tBill_edit.html";
|
}
|
|
/**
|
* 获取列表
|
*/
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object list(String createTime,String addresseePhone,Integer state,Integer billType,Integer billHeaderType) {
|
EntityWrapper<TBill> wrapper = tBillService.getPageListWrapper(createTime,addresseePhone,state,billType,billHeaderType);
|
return tBillService.selectList(wrapper);
|
}
|
|
/**
|
* 确认通过发票
|
*/
|
@RequestMapping(value = "/confirm")
|
@ResponseBody
|
public Object confirm(Integer tBillId) {
|
TBill tBill = tBillService.selectById(tBillId);
|
tBill.setState(TBillStateEnum.FINISH_BILL.getCode());
|
tBillService.updateById(tBill);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 开通发票失败
|
*/
|
@RequestMapping(value = "/cancel")
|
@ResponseBody
|
public Object cancel(Integer tBillId) {
|
TBill tBill = tBillService.selectById(tBillId);
|
tBill.setState(TBillStateEnum.FAIL_BILL.getCode());
|
tBillService.updateById(tBill);
|
TOrder tOrder = tOrderService.selectById(tBill.getOrderId());
|
if(Objects.nonNull(tOrder)){
|
tOrder.setIsInvoice(0);
|
tOrderService.updateById(tOrder);
|
}
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 获取列表
|
*/
|
@RequestMapping(value = "/list-back")
|
@ResponseBody
|
public Object listBack(String condition) {
|
return tBillService.selectList(null);
|
}
|
|
/**
|
* 新增
|
*/
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
public Object add(TBill tBill) {
|
tBillService.insert(tBill);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 删除
|
*/
|
@RequestMapping(value = "/delete")
|
@ResponseBody
|
public Object delete(@RequestParam Integer tBillId) {
|
tBillService.deleteById(tBillId);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TBill tBill) {
|
tBillService.updateById(tBill);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 详情
|
*/
|
@RequestMapping(value = "/detail/{tBillId}")
|
@ResponseBody
|
public Object detail(@PathVariable("tBillId") Integer tBillId) {
|
return tBillService.selectById(tBillId);
|
}
|
|
@ApiOperation(value = "导出发票列表",notes="导出发票列表")
|
@RequestMapping(value = "/export")
|
@ResponseBody
|
public void export(String createTime,String addresseePhone,Integer state,Integer billType,Integer billHeaderType, HttpServletResponse response) {
|
try {
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String time1 = format.format(date);
|
String fileName = "BillInfo"+time1+".xls";
|
String[] title = new String[] {"申请时间","发票类型","抬头类型","发票抬头","公司税号","发票内容",
|
"发票金额","收件人姓名","收件人电话","收件人邮箱","开票状态"};
|
EntityWrapper<TBill> wrapper = tBillService.getPageListWrapper(createTime,addresseePhone,state,billType,billHeaderType);
|
List<TBill> tBills = tBillService.selectList(wrapper);
|
String[][] values = new String[tBills.size()][];
|
for (int i = 0; i < tBills.size(); i++) {
|
TBill d = tBills.get(i);
|
values[i] = new String[title.length];
|
values[i][0] = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d.getCreateTime());
|
Integer billType1 = d.getBillType();
|
if(1 == billType1){
|
values[i][1] = "电子发票";
|
}
|
Integer billHeaderType1 = d.getBillHeaderType();
|
if(1 == billHeaderType1){
|
values[i][2] = "公司";
|
} else if (2 == billHeaderType1) {
|
values[i][2] = "个人";
|
}
|
values[i][3] = d.getCompanyName();
|
values[i][4] = d.getCompanyTaxNumber();
|
values[i][5] = d.getBillContent();
|
values[i][6] = String.valueOf(Objects.nonNull(d.getBillAmount())?d.getBillAmount(): BigDecimal.ZERO);
|
values[i][7] = d.getAddresseeName();
|
values[i][8] = d.getAddresseePhone();
|
values[i][9] = d.getAddresseeEmail();
|
Integer state1 = d.getState();
|
if(1 == state1){
|
values[i][10] = "待开票";
|
} else if (2 == state1) {
|
values[i][10] = "已开票";
|
} else if (3 == state1) {
|
values[i][10] = "开票失败";
|
}
|
}
|
HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
|
ExcelUtil.setResponseHeader(response, fileName);
|
OutputStream os = response.getOutputStream();
|
wb.write(os);
|
os.flush();
|
os.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|