Browse Source

开票优化

LAPTOP-FO2T5SIU\35838 8 months ago
parent
commit
8cdd1ca7b2

+ 60 - 29
pro-base/src/main/java/com/idea/invoice/controller/InvoiceManageController.java

@@ -1,5 +1,6 @@
 package com.idea.invoice.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
 import com.idea.invoice.dto.InvoiceManageDto;
 import com.idea.invoice.model.InvoiceBank;
@@ -16,14 +17,16 @@ import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 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.ResponseBody;
 
+import java.util.Date;
 import java.util.List;
 
 @Controller
 @RequestMapping(value = "InvoiceManageController")
-@Api(value="开票管理")
+@Api(value = "开票管理")
 public class InvoiceManageController extends BaseController {
 
     @Autowired
@@ -31,68 +34,72 @@ public class InvoiceManageController extends BaseController {
 
     /**
      * 预收款发票
+     *
      * @param tablepar
      * @param model
      * @param dt
      * @return
      */
-    @PostMapping(value = "advancePaymentInvoiceList",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "advancePaymentInvoiceList", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public Object advancePaymentInvoiceList(Tablepar tablepar, InvoiceManageDto model, DateTrans dt){
-        PageInfo<InvoiceManageDto> page= modelService.advancePaymentInvoiceList(tablepar,model,dt);
+    public Object advancePaymentInvoiceList(Tablepar tablepar, InvoiceManageDto model, DateTrans dt) {
+        PageInfo<InvoiceManageDto> page = modelService.advancePaymentInvoiceList(tablepar, model, dt);
         return new TableSplitResult<>(page.getPageNum(), page.getTotal(), page.getList());
     }
 
     /**
      * 正式发票
+     *
      * @param tablepar
      * @param model
      * @param dt
      * @return
      */
-    @PostMapping(value = "formalInvoiceList",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "formalInvoiceList", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public Object formalInvoiceList(Tablepar tablepar, InvoiceManageDto model, DateTrans dt){
-        PageInfo<InvoiceManageDto> page= modelService.formalInvoiceList(tablepar,model,dt);
+    public Object formalInvoiceList(Tablepar tablepar, InvoiceManageDto model, DateTrans dt) {
+        PageInfo<InvoiceManageDto> page = modelService.formalInvoiceList(tablepar, model, dt);
         return new TableSplitResult<>(page.getPageNum(), page.getTotal(), page.getList());
     }
 
     /**
      * 新增预收款发票
+     *
      * @param record
      * @return
      */
-    @PostMapping(value = "add",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "add", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public AjaxResult add(InvoiceManageDto record){
+    public AjaxResult add(InvoiceManageDto record) {
         int result = modelService.add(record);
         return result(result);
     }
 
-    @PostMapping(value = "getById",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "getById", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public Object getById(String id){
+    public Object getById(String id) {
         InvoiceManageDto result = modelService.getById(id);
         return result;
     }
 
 
-    @PostMapping(value = "getByContractId",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "getByContractId", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public Object getInfoByContract(String id,String invoiceGoodsName,Integer payType){
-        InvoiceManageDto result = modelService.getInfoByContract(id,invoiceGoodsName,payType);
+    public Object getInfoByContract(String id, String invoiceGoodsName, Integer payType) {
+        InvoiceManageDto result = modelService.getInfoByContract(id, invoiceGoodsName, payType);
         return result;
     }
 
     /**
      * 查询对应的银行
+     *
      * @param id
      * @return
      */
-    @PostMapping(value = "getBankTaxRateByFloor",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "getBankTaxRateByFloor", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
     public Object getBankTaxRateByFloor(String id) {
-        if(!StringUtils.isNotEmpty(id)){
+        if (!StringUtils.isNotEmpty(id)) {
             return AjaxResult.error(503, "参数不能为空");
         }
         return modelService.getBankTaxRateByFloor(id);
@@ -100,47 +107,71 @@ public class InvoiceManageController extends BaseController {
 
     /**
      * 查询对应的银行
+     *
      * @param contractId
      * @param paymentType
      * @return
      */
-    @PostMapping(value = "getBankTaxRateByFloor_2",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "getBankTaxRateByFloor_2", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public Object getBankTaxRateByFloor(String contractId,String paymentType) {
-        if(!StringUtils.isNotEmpty(contractId)){
+    public Object getBankTaxRateByFloor(String contractId, String paymentType) {
+        if (!StringUtils.isNotEmpty(contractId)) {
             return AjaxResult.error(503, "参数不能为空");
         }
-        return modelService.getBankTaxRateByFloor(contractId,paymentType);
+        return modelService.getBankTaxRateByFloor(contractId, paymentType);
     }
 
 
-    @PostMapping(value = "batchListVo",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "batchListVo", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public List<InvoiceManageDto> batchListVo(String invoiceManages){
+    public List<InvoiceManageDto> batchListVo(String invoiceManages) {
         return modelService.batchListVo(invoiceManages);
     }
 
 
     /**
      * 推送开票
-     * @param record
+     *
+     * @param model
      * @return
      */
-    @PostMapping(value = "sendInvoice",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "sendInvoice", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public AjaxResult sendInvoice(InvoiceManageDto record){
-        return modelService.sendInvoice(record);
+    public AjaxResult sendInvoice(InvoiceManageDto model) {
+
+        String result;
+        try {
+            result = modelService.sendInvoice(model);
+        } catch (Exception e) {
+            return AjaxResult.error(504, e.getMessage());
+        }
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        String success = jsonObject.getString("success");
+        if ("true".equals(success)) {
+            String code = jsonObject.getJSONObject("data").getJSONObject("ar_recbill").getString("code");
+            model.setSendStatus("1");
+            model.setSubmitTime(new Date());
+            model.setSubmitUser(ShiroUtils.getUserId());
+            model.setNcJson(result);
+            model.setNcCode(code);
+            modelService.updateByPrimaryKeySelective(model);
+        } else if ("false".equals(success)) {
+            return AjaxResult.error(504, jsonObject.getString("message"));
+        }
+
+        return AjaxResult.success();
     }
 
     /**
      * 批量推送开票
+     *
      * @param list
      * @return
      */
-    @PostMapping(value = "batchSendInvoice",produces = {"application/json;charset=UTF-8"})
+    @PostMapping(value = "batchSendInvoice", produces = {"application/json;charset=UTF-8"})
     @ResponseBody
-    public AjaxResult batchSendInvoice(List<InvoiceManageDto> list){
-        return  modelService.batchSendInvoice(list);
+    public AjaxResult batchSendInvoice(@RequestBody List<InvoiceManageDto> list) {
+        return modelService.batchSendInvoice(list);
     }
 
 }

+ 45 - 48
pro-base/src/main/java/com/idea/invoice/service/InvoiceManageService.java

@@ -172,12 +172,30 @@ public class InvoiceManageService implements BaseService<InvoiceManage, InvoiceM
         model.setInvoiceStatus("0");
         model.setCreateTime(new Date());
         model.setCreateUser(ShiroUtils.getUserId());
+        model.setSendStatus("0");
         int result = insertWithoutId(model);
+
         // 预收款发票 新增后 推送用友
         if (model.getType().equals("1")) {
-            sendInvoice(model);
+            try {
+                String resultJson = sendInvoice(model);
+                JSONObject jsonObject = JSONObject.parseObject(resultJson);
+                String success = jsonObject.getString("success");
+                if ("true".equals(success)) {
+                    String code = jsonObject.getJSONObject("data").getJSONObject("ar_recbill").getString("code");
+                    model.setSendStatus("1");
+                    model.setSubmitTime(new Date());
+                    model.setSubmitUser(ShiroUtils.getUserId());
+                    model.setNcJson(resultJson);
+                    model.setNcCode(code);
+                    updateByPrimaryKeySelective(model);
+                } else if ("false".equals(success)) {
+                    throw new Exception(jsonObject.getString("message"));
+                }
+            }catch (Exception e){
+                log.error("推送预收款发票失败", e);
+            }
         }
-
         return result;
     }
 
@@ -381,25 +399,17 @@ public class InvoiceManageService implements BaseService<InvoiceManage, InvoiceM
      *
      * @param model
      */
-    @Transactional
-    public AjaxResult sendInvoice(InvoiceManageDto model) {
+    public String sendInvoice(InvoiceManageDto model) throws Exception {
 
         // 查询客户管理信息
         CustomerManagement customerManagement = customerManagementMapper.selectByPrimaryKey(model.getCustomerManagementId());
         // 查询小区信息
         ParkInfo parkInfo = parkInfoMapper.selectByPrimaryKey(customerManagement.getGroupId());
-//        // 查询买受人信息
-//        BuyerExample buyerExample = new BuyerExample();
-//        buyerExample.setOrderByClause("order_num asc");
-//        buyerExample.createCriteria().andCustomerManagementIdEqualTo(customerManagement.getId());
-//        List<Buyer> buyers = buyerMapper.selectByExample(buyerExample);
-//        Buyer buyer = buyers.get(0);
         // 查询房间信息
         ParkRoom parkRoom = parkRoomMapper.selectByPrimaryKey(customerManagement.getHouseId());
 
         String address = parkInfo.getAddress();
-//        String identityCard = buyer.getIdentityCard();
-        int invoiceTax = Integer.parseInt(model.getInvoiceTax()) * 100;
+        Double invoiceTax = Double.parseDouble(model.getInvoiceTax()) * 100;
 
         JSONObject json = new JSONObject();
 
@@ -434,28 +444,9 @@ public class InvoiceManageService implements BaseService<InvoiceManage, InvoiceM
         ar_recitem.add(ar_recitemJson);
         json.put("ar_recitem", ar_recitem);
 
-        try {
-            String result = InvoiceUtil.recbillAdd(json);
-            JSONObject jsonObject = JSONObject.parseObject(result);
-            String success = jsonObject.getString("success");
-            if (success.equals("true")) {
-                String code = jsonObject.getJSONObject("data").getJSONObject("ar_recbill").getString("code");
-                model.setSendStatus("1");
-                model.setSubmitTime(new Date());
-                model.setSubmitUser(ShiroUtils.getUserId());
-                model.setNcJson(result);
-                model.setNcCode(code);
-                updateByPrimaryKeySelective(model);
-                return AjaxResult.success();
-            } else if (success.equals("false")) {
-                return AjaxResult.error(jsonObject.getString("message"));
-            }
-        } catch (Exception e) {
-            log.error("推送发票失败", e);
-            return AjaxResult.error(e.getMessage());
-        }
+        String result = InvoiceUtil.recbillAdd(json);
 
-        return AjaxResult.error();
+        return result;
 
     }
 
@@ -475,22 +466,28 @@ public class InvoiceManageService implements BaseService<InvoiceManage, InvoiceM
                 return AjaxResult.error(504, "提交失败,开票状态发生变化");
             }
         }
-        String userId = ShiroUtils.getUserId();
-        for (InvoiceManageDto invoiceManage : list) {
-//            invoiceManage.setUpdateUser(userId);
-//            InvoiceManage newRecord = selectByPrimaryKey(invoiceManage.getId());
-//            // 如果流水号为空 则创建一个流水号
-//            String serialNo;
-//            if (StringUtils.isEmpty(newRecord.getSerialNo())) {
-//                serialNo = "wuxi-" + System.currentTimeMillis() + "-001";
-//                newRecord.setSerialNo(serialNo);
-//                updateByPrimaryKeySelective(newRecord);
-//            } else {
-//                serialNo = newRecord.getSerialNo();
-//            }
-//            invoiceManage.setSerialNo(serialNo);
-            invoiceManageService.sendInvoice(invoiceManage);
+        try {
+            for (InvoiceManageDto invoiceManage : list) {
+                String result = invoiceManageService.sendInvoice(invoiceManage);
+                JSONObject jsonObject = JSONObject.parseObject(result);
+                String success = jsonObject.getString("success");
+                if ("true".equals(success)) {
+                    String code = jsonObject.getJSONObject("data").getJSONObject("ar_recbill").getString("code");
+                    invoiceManage.setSendStatus("1");
+                    invoiceManage.setSubmitTime(new Date());
+                    invoiceManage.setSubmitUser(ShiroUtils.getUserId());
+                    invoiceManage.setNcJson(result);
+                    invoiceManage.setNcCode(code);
+                    invoiceManageService.updateByPrimaryKeySelective(invoiceManage);
+                } else if ("false".equals(success)) {
+                    throw new RuntimeException(jsonObject.getString("message"));
+                }
+            }
+        }catch (Exception e){
+            log.error("批量推送发票异常",e);
+            return AjaxResult.error(504, e.getMessage());
         }
+
         return AjaxResult.success();
     }
 

+ 3 - 3
pro-base/src/main/java/com/idea/invoice/task/InvoiceTask.java

@@ -89,7 +89,7 @@ public class InvoiceTask {
     /**
      * 每天凌晨执行 推送载体数据
      */
-    @Scheduled(cron = "0 0 0 1/1 * ?")
+//    @Scheduled(cron = "0 0 0 1/1 * ?")
     public void sendBuild() {
         List<MnpBuilding> mnpBuildings = buildingService.selectNeedSendList();
         for(MnpBuilding building: mnpBuildings){
@@ -121,7 +121,7 @@ public class InvoiceTask {
     /**
      * 每天凌晨执行 推送房间数据
      */
-    @Scheduled(cron = "0 0 0 1/1 * ?")
+//    @Scheduled(cron = "0 0 0 1/1 * ?")
     public void sendHouse(){
         List<ParkRoom> parkRooms = roomService.selectNeedSendList();
         for(ParkRoom record: parkRooms){
@@ -158,7 +158,7 @@ public class InvoiceTask {
     /**
      * 每天凌晨执行 推送客户数据
      */
-    @Scheduled(cron = "0 0 0 1/1 * ?")
+//    @Scheduled(cron = "0 0 0 1/1 * ?")
     public void sendCustomer(){
 
         List<CustomerManagementDto> customerManagementDtos = customerManagementService.selectNeedSendList();