123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- package com.jkcredit.invoice.controller.business;
- import cn.afterturn.easypoi.excel.ExcelImportUtil;
- import cn.afterturn.easypoi.excel.entity.ImportParams;
- import cn.com.taiji.sdk.model.comm.protocol.tts.invoice.server.B2BInvoiceListModel;
- import cn.com.taiji.sdk.model.comm.protocol.tts.trade.service.CardTradeModel;
- import com.alibaba.fastjson.JSON;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.jkcredit.invoice.annotation.LoginRequired;
- import com.jkcredit.invoice.mapper.customer.CustomerRecMapper;
- import com.jkcredit.invoice.model.entity.calculate.SelfCarCalculateInfor;
- import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
- import com.jkcredit.invoice.model.entity.customer.CustomerRec;
- import com.jkcredit.invoice.model.entity.invoice.SelfCarInvoice;
- import com.jkcredit.invoice.model.entity.waybill.SelfCarTrade;
- import com.jkcredit.invoice.service.calculateinfor.SelfCarCalculateInfoService;
- import com.jkcredit.invoice.service.customer.CustomerService;
- import com.jkcredit.invoice.service.lowerservice.SelfCarServiceL;
- import com.jkcredit.invoice.service.lowerservice.vo.*;
- import com.jkcredit.invoice.service.selfcar.SelfCarInvoiceService;
- import com.jkcredit.invoice.service.selfcar.SelfCarService;
- import com.jkcredit.invoice.service.selfcar.SelfCarTradeService;
- import com.jkcredit.invoice.util.RespR;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.*;
- @Api(tags = "自有车操作")
- @RestController
- @RequestMapping(value = {"/selfCar"})
- /**
- * @Description 自有车操作
- * @Author mashengyi
- * @Date 2022/2/8 18:18
- * @Param
- * @Return
- * @Exception
- *
- */
- public class SelfCarController {
- @Autowired
- SelfCarServiceL selfCarServiceL;
- @Autowired
- SelfCarService selfCarService;
- @Autowired
- SelfCarServiceL selfCarServicel;
- @Autowired
- SelfCarTradeService selfCarTradeService;
- @Autowired
- SelfCarInvoiceService selfCarInvoiceService;
- @Autowired
- SelfCarCalculateInfoService selfCarCalculateInfoService;
- @Autowired
- CustomerService customerService;
- /**
- * 解绑etc卡
- * @param etcNum 参数集
- * @return 用户集合
- */
- @PostMapping("/selfCarUnBind")
- @ApiOperation(value="解绑etc卡", notes="解绑etc卡")
- @LoginRequired
- public RespR selfCarUnBind(String etcNum) {
- try {
- RespR respR = selfCarService.selfCarUnBind(etcNum);
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询自有车交易信息
- *
- * @param page 参数集
- * @return 交易信息
- */
- @PostMapping("/findTrades")
- @ApiOperation(value="分页查询自有车交易信息", notes="分页查询自有车交易信息")
- @LoginRequired
- public RespR findTrades(Page page, SelfCarTrade selfCarTrade) {
- try {
- setTimeDue(selfCarTrade);
- RespR respR = new RespR(selfCarTradeService.findByPageAndTrade(page, selfCarTrade));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询自有车交易信息
- *
- * @param page 参数集
- * @return 交易信息
- */
- @PostMapping("/findTradesUpper")
- @ApiOperation(value="分页查询自有车交易信息", notes="分页查询自有车交易信息")
- @LoginRequired
- public RespR findTradesUpper(Page page, SelfCarTrade selfCarTrade) {
- try {
- setTimeDue(selfCarTrade);
- if(StringUtils.isEmpty(selfCarTrade.getCompanyName())){
- return new RespR(false,"需要输入公司名称");
- }
- if(StringUtils.isEmpty(selfCarTrade.getCardId())){
- return new RespR(false,"需要输入etc卡号");
- }
- if(StringUtils.isEmpty(selfCarTrade.getExTimeBegin())){
- return new RespR(false,"需要交易开始时间");
- }
- if(StringUtils.isEmpty(selfCarTrade.getExTimeEnd())){
- return new RespR(false,"需要输入交易结束时间");
- }
- //先更新查询信息
- TradeRequestVo tradeRequestVo = new TradeRequestVo();
- tradeRequestVo.setCustomerName(selfCarTrade.getCustomId());
- tradeRequestVo.setCompanyName(selfCarTrade.getCompanyName());
- tradeRequestVo.setStartTime(selfCarTrade.getExTimeBegin());
- tradeRequestVo.setEndTime(selfCarTrade.getExTimeEnd());
- tradeRequestVo.setEtcId(selfCarTrade.getCardId());
- tradeRequestVo.setTradeStatus(selfCarTrade.getStatus());
- tradeRequestVo.setInterType(1);//0 接口
- if(tradeRequestVo.getTradeStatus() ==null){
- tradeRequestVo.setTradeStatus(1);
- selfCarServiceL.getTradeList(tradeRequestVo);
- tradeRequestVo.setTradeStatus(2);
- selfCarServiceL.getTradeList(tradeRequestVo);
- tradeRequestVo.setTradeStatus(3);
- selfCarServiceL.getTradeList(tradeRequestVo);
- }else{
- selfCarServiceL.getTradeList(tradeRequestVo);
- }
- RespR respR = new RespR(selfCarTradeService.findByPageAndTrade(page, selfCarTrade));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询自有车交易信息
- *
- * @param selfCarTradesStr
- * @return 交易信息
- */
- @PostMapping("/updateTrades")
- @ApiOperation(value="更新交易id状态", notes="更新交易id状态")
- @LoginRequired
- public void updateTrades( String selfCarTradesStr) {
- try {
- List<SelfCarTrade> selfCarTrades = JSON.parseArray(selfCarTradesStr,SelfCarTrade.class);
- selfCarTradeService.updateTrades(selfCarTrades);
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- public void setTimeDue(SelfCarTrade selfCarTrade){
- if(!StringUtils.isEmpty(selfCarTrade.getAclTimeBegin()) && !"null".equals(selfCarTrade.getAclTimeBegin())){
- String [] res = selfCarTrade.getAclTimeBegin().split(",");
- selfCarTrade.setAclTimeBegin(res[0]);
- selfCarTrade.setAclTimeEnd(res[1].replace("00:00:00","23:59:59"));
- }else{
- selfCarTrade.setAclTimeBegin(null);
- }
- if(!StringUtils.isEmpty(selfCarTrade.getExTimeBegin()) && !"null".equals(selfCarTrade.getExTimeBegin())){
- String [] res = selfCarTrade.getExTimeBegin().split(",");
- selfCarTrade.setExTimeBegin(res[0]);
- selfCarTrade.setExTimeEnd(res[1].replace("00:00:00","23:59:59"));
- }else{
- selfCarTrade.setExTimeBegin(null);
- }
- }
- /**
- * 分页查询所有发票信息
- *
- * @param page 参数集
- * @return 交易信息
- */
- @PostMapping("/findSelfCarInvoices")
- @ApiOperation(value="分页查询自有车发票信息", notes="分页查询自有车发票信息")
- @LoginRequired
- public RespR findSelfCarInvoices(Page page, SelfCarInvoice selfCarInvoice) {
- try {
- if(!StringUtils.isEmpty(selfCarInvoice.getInvoiceMakeTime()) && !"null".equals(selfCarInvoice.getInvoiceMakeTime())){
- String [] res =selfCarInvoice.getInvoiceMakeTime().split(",");
- selfCarInvoice.setInvoiceMakeStart(res[0]);
- selfCarInvoice.setInvoiceMakeEnd(res[1].replace("00:00:00","23:59:59"));
- }
- RespR respR = new RespR(selfCarInvoiceService.findByPageAndInvoice(page, selfCarInvoice));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询自有车计费信息
- *
- * @param page 参数集
- * @return 用户集合
- */
- @PostMapping("/findSelfcarCalculateInfo")
- @ApiOperation(value="分页查询自有车计费信息", notes="分页查询自有车计费信息")
- @LoginRequired
- public RespR findSelfcarCalculateInfo(Page page, SelfCarCalculateInfor carCalculateInfor) {
- try {
- if(!StringUtils.isEmpty(carCalculateInfor.getCalTime()) && !"null".equals(carCalculateInfor.getCalTime())){
- String [] res =carCalculateInfor.getCalTime().split(",");
- carCalculateInfor.setCalTimeStart(res[0]);
- carCalculateInfor.setCalTimeEnd(res[1]);
- }
- RespR respR = new RespR(selfCarCalculateInfoService.findByPageAndCalculateInfor(page, carCalculateInfor));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 分页查询自有车计费信息
- *
- * @param carCalculateInfor
- * @return 用户集合
- */
- @PostMapping("/findSelfcarCalculateInfoSta")
- @ApiOperation(value="自有车计费统计信息", notes="自有车计费统计信息")
- @LoginRequired
- public RespR findSelfcarCalculateInfoSta(SelfCarCalculateInfor carCalculateInfor) {
- try {
- if(!StringUtils.isEmpty(carCalculateInfor.getCalTime()) && !"null".equals(carCalculateInfor.getCalTime())){
- String [] res =carCalculateInfor.getCalTime().split(",");
- carCalculateInfor.setCalTimeStart(res[0]);
- carCalculateInfor.setCalTimeEnd(res[1]);
- }
- RespR respR = new RespR(selfCarCalculateInfoService.findSelfcarCalculateInfoSta(carCalculateInfor));
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * @param tradeRequestCarNumVo
- * @return
- */
- @PostMapping("/getTradeList")
- @ApiOperation(value="获取需要开票的交易Id列表", notes="获取需要开票的交易Id列表")
- @LoginRequired
- public RespR getTradeList(@RequestBody TradeRequestCarNumVo tradeRequestCarNumVo){
- //通过车牌号查询所有的Etc卡号
- List<CustomerCarRec> customerCarRecs = selfCarService.getEtcsByCarNum(tradeRequestCarNumVo.getCarNum());
- if(customerCarRecs == null || customerCarRecs.size()<=0){
- return new RespR(false,"请输入有绑定ETC卡号的车牌");
- }
- //合并展示
- List<CardTradeModel> cardTradeModels = new ArrayList<>();
- customerCarRecs.forEach(customerCarRec -> {
- TradeRequestVo tradeRequestVo = new TradeRequestVo();
- tradeRequestVo.setCompanyName(tradeRequestCarNumVo.getCompanyName());
- tradeRequestVo.setCustomerName(tradeRequestCarNumVo.getCustomerName());
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- tradeRequestVo.setStartTime(format.format(new Date(Long.parseLong(tradeRequestCarNumVo.getStartTime()))));
- tradeRequestVo.setEndTime(format.format(new Date(Long.parseLong(tradeRequestCarNumVo.getEndTime()))));
- tradeRequestVo.setTradeStatus(1);
- tradeRequestVo.setEtcId(customerCarRec.getEtcNum());
- RespR<List<CardTradeModel>> respRbefore = selfCarServicel.getTradeList(tradeRequestVo);
- if(respRbefore.getCode() == 0){
- cardTradeModels.addAll(respRbefore.getData());
- }
- });
- return new RespR(cardTradeModels);
- }
- /**
- * @param tradeRequestCarNumVo
- * @return
- */
- @PostMapping("/applTradeList")
- @ApiOperation(value="根据车牌号进行开票操作", notes="根据车牌号进行开票操作")
- @LoginRequired
- public RespR applTradeList(@RequestBody TradeRequestCarNumVo tradeRequestCarNumVo){
- String [] cardAndTrades = tradeRequestCarNumVo.getCarIdStr().split(",");
- Map<String,InvoiceApplVo> map = new HashMap<>();
- for(int i = 0;i<cardAndTrades.length;i++){
- if(!StringUtils.isEmpty(cardAndTrades[i])){
- String [] cardAndTrade = cardAndTrades[i].split("#");
- InvoiceApplVo invoiceApplVo = map.get(cardAndTrade[0]);
- if(invoiceApplVo == null){
- invoiceApplVo.setCompanyName(tradeRequestCarNumVo.getCompanyName());
- invoiceApplVo.setCustomerName(tradeRequestCarNumVo.getCustomerName());
- invoiceApplVo.setCardId(cardAndTrade[0]);
- invoiceApplVo.setTradeIds(new ArrayList<String>());
- invoiceApplVo.getTradeIds().add(cardAndTrade[1]);
- map.put(cardAndTrade[0],invoiceApplVo);
- }else{
- invoiceApplVo.getTradeIds().add(cardAndTrade[1]);
- }
- }
- }
- StringBuffer stringBuffer = new StringBuffer();
- for(Map.Entry<String,InvoiceApplVo> elm:map.entrySet()){
- InvoiceApplVo invoiceApplVo = elm.getValue();
- RespR respR = selfCarServicel.applInvoice(invoiceApplVo);
- if(respR.getCode() == 1){
- stringBuffer.append(invoiceApplVo.getCardId()+"开票申请失败原因:"+respR.getMsg()+"#");
- }
- }
- if(StringUtils.isEmpty(stringBuffer.toString())){
- return new RespR(true);
- }else{
- return new RespR(false,stringBuffer.toString());
- }
- }
- @Autowired
- CustomerRecMapper customerRecMapper;
- /**
- * 查询已经开票信息
- *
- * @param
- * @return
- */
- @PostMapping("/findSelfcarInvoiceByTime")
- @ApiOperation(value="通过时间,车牌号查询开票信息", notes="通过时间,车牌号查询开票信息")
- @LoginRequired
- public RespR findSelfcarInvoiceByTime(@RequestBody SelfcarInvoiceByTimeVo selfcarInvoiceByTimeVo) {
- try {
- if(!customerService.checkMoneyEnough(selfcarInvoiceByTimeVo.getCustomerName())){
- return new RespR(false,"余额不足");
- }
- //通过车牌号查询所有的Etc卡号
- List<CustomerCarRec> customerCarRecs = selfCarService.getEtcsByCarNum(selfcarInvoiceByTimeVo.getCarNum());
- if(customerCarRecs == null || customerCarRecs.size()<=0){
- return new RespR(false,"请输入有绑定ETC卡号的车牌");
- }
- CustomerRec customerRec = new CustomerRec();
- customerRec.setCustomerName(selfcarInvoiceByTimeVo.getCustomerName());
- customerRec.setCompanyName(selfcarInvoiceByTimeVo.getCompanyName());
- CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompany(customerRec);
- if(customerRec1 == null || customerRec1.getRecStatus().intValue() !=1 ){
- return new RespR(false,"客户未备案");
- }
- List<B2BInvoiceListModel> allSelfInvocies = new ArrayList<>();
- customerCarRecs.forEach(customerCarRec -> {
- SelfCarDueQueryVo selfCarDueQueryVo = new SelfCarDueQueryVo();
- selfCarDueQueryVo.setCustomername(selfcarInvoiceByTimeVo.getCustomerName());
- selfCarDueQueryVo.setCompanyName(selfcarInvoiceByTimeVo.getCompanyName());
- selfCarDueQueryVo.setStartTime(selfcarInvoiceByTimeVo.getStartTime());
- selfCarDueQueryVo.setEndTime(selfcarInvoiceByTimeVo.getEndTime());
- selfCarDueQueryVo.setCardId(customerCarRec.getEtcNum());
- RespR<List<B2BInvoiceListModel>> respR = selfCarServicel.getSelfCarInvoicesByTime(selfCarDueQueryVo,customerRec1);
- if(respR.getCode() == 0){
- allSelfInvocies.addAll(respR.getData());
- }
- });
- return new RespR(allSelfInvocies);
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 批量查询自有车交易信息
- *
- * @param file 参数集
- * @return
- */
- @PostMapping("/batchImportSelfcarTrades")
- @ApiOperation(value="批量查询自有车交易信息", notes="批量查询自有车交易信息")
- @LoginRequired
- public RespR batchImportSelfcarTrades(@RequestParam("file") MultipartFile file) {
- try {
- ImportParams params = new ImportParams();
- params.setTitleRows(1);
- params.setHeadRows(1);
- List<SelfCarTrade> list = ExcelImportUtil.importExcel(file.getInputStream(), SelfCarTrade.class,params) ;
- RespR respR = selfCarTradeService.batchImportSelfcarTrades(list);
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- /**
- * 批量查询自有车发票信息
- *
- * @param file 参数集
- * @return
- */
- @PostMapping("/batchImportSelfcarInvoices")
- @ApiOperation(value="批量查询自有车发票信息", notes="批量查询自有车发票信息")
- @LoginRequired
- public RespR batchImportSelfcarInvoices(@RequestParam("file") MultipartFile file) {
- try {
- ImportParams params = new ImportParams();
- params.setTitleRows(1);
- params.setHeadRows(1);
- List<SelfCarInvoice> list = ExcelImportUtil.importExcel(file.getInputStream(), SelfCarInvoice.class,params) ;
- RespR respR = selfCarInvoiceService.findImportSelfcarInvoices(list);
- return respR;
- }catch (Exception e){
- e.printStackTrace();
- return new RespR(false,e.getMessage());
- }
- }
- }
|