Browse Source

苏州分公司发票数据同步到本系统

sangwenwei 7 months ago
parent
commit
74837e4c4b

+ 19 - 0
src/main/java/com/jeeplus/common/szCcpm/controller/SzCloudList.java

@@ -0,0 +1,19 @@
+package com.jeeplus.common.szCcpm.controller;
+
+import com.jeeplus.modules.szCenterservice.service.szCloud.FinanceInvoiceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SzCloudList {
+
+    @Autowired
+    private FinanceInvoiceService financeInvoiceService;
+
+    /**
+     * 保存发票信息
+     */
+    public void saveFinanceInfo() throws Exception {
+        financeInvoiceService.getFinanceInvoiceList();
+    }
+}

+ 12 - 6
src/main/java/com/jeeplus/modules/centerservice/config/ConnectionService.java

@@ -1,6 +1,8 @@
 package com.jeeplus.modules.centerservice.config;
 
 import com.jeeplus.common.config.Global;
+import com.jeeplus.common.szCcpm.controller.CcpmList;
+import com.jeeplus.common.szCcpm.controller.SzCloudList;
 import com.jeeplus.common.utils.JedisUtils;
 import com.jeeplus.modules.sys.entity.User;
 import com.jeeplus.modules.sys.utils.UserUtils;
@@ -27,6 +29,9 @@ public class ConnectionService {
     @Autowired
     private RestTemplate restTemplate;
 
+    @Autowired
+    private SzCloudList szCloudList;
+
 
     @Autowired
     private ApplicationContext applicationContext;
@@ -54,14 +59,15 @@ public class ConnectionService {
             Map<String, String> responseBody1 = responseEntity1.getBody();
             String message1 = responseBody1.get("message");
             if ("success".equals(message) && "success".equals(message1)) {
-                if (!isConnected) {
-                    JedisUtils.set("ccpmConnect", "true", 24);
-                    System.out.println("Connected successfully.");
-                }
-                isConnected = true; // 更新连接状态
+                szCloudList.saveFinanceInfo();
+//                if (!isConnected) {
+//                    JedisUtils.set("ccpmConnect", "true", 24);
+//                    System.out.println("Connected successfully.");
+//                }
+//                isConnected = true; // 更新连接状态
             }
         } catch (Exception e) {
-            isConnected = false; // 连接失败,更新状态
+//            isConnected = false; // 连接失败,更新状态
             JedisUtils.set("ccpmConnect", "false", 24);
             System.out.println("Connection failed: " + e.getMessage());
         }

+ 14 - 1
src/main/java/com/jeeplus/modules/szCenterservice/service/szCloud/FinanceInvoiceRequest.java

@@ -79,5 +79,18 @@ public class FinanceInvoiceRequest {
         return "";
     }
 
-
+    public Object getFinanceInvoiceList() {
+        Object res = null;
+        try {
+            Map<String, Object> paramMap = new HashMap<>();
+            String path = Global.getConfig("SZ_PATH");
+            String url = szRestTemplateService.getUrl(path, "/transpond/FinanceList", paramMap);
+            ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, null, String.class);
+            res = exchange.getBody();
+        } catch (Exception e) {
+            System.out.println("远程调用失败");
+            e.printStackTrace();
+        }
+        return res;
+    }
 }

+ 342 - 0
src/main/java/com/jeeplus/modules/szCenterservice/service/szCloud/FinanceInvoiceService.java

@@ -6,12 +6,20 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.jeeplus.modules.projectrecord.entity.ProjectRecords;
 import com.jeeplus.modules.sys.entity.Area;
+import com.jeeplus.modules.sys.entity.Office;
 import com.jeeplus.modules.sys.entity.User;
 import com.jeeplus.modules.sys.entity.Workattachment;
+import com.jeeplus.modules.sys.service.OfficeService;
+import com.jeeplus.modules.sys.service.WorkattachmentService;
+import com.jeeplus.modules.sys.utils.UserUtils;
 import com.jeeplus.modules.workclientinfo.entity.WorkClientAttachment;
 import com.jeeplus.modules.workclientinfo.entity.WorkClientInfo;
+import com.jeeplus.modules.workinvoice.dao.WorkInvoiceCloudDao;
+import com.jeeplus.modules.workinvoice.dao.WorkInvoiceDao;
 import com.jeeplus.modules.workinvoice.entity.WorkInvoice;
+import com.jeeplus.modules.workinvoice.entity.WorkInvoiceCloud;
 import com.jeeplus.modules.workinvoice.entity.WorkInvoiceProjectRelation;
+import com.jeeplus.modules.workinvoicedetail.dao.WorkInvoiceDetailDao;
 import com.jeeplus.modules.workinvoicedetail.entity.WorkInvoiceDetail;
 import com.jeeplus.modules.workreimbursement.entity.ReimbursementVATTax;
 import com.jeeplus.modules.workreimbursement.entity.WorkAccount;
@@ -32,6 +40,19 @@ public class FinanceInvoiceService {
     @Autowired
     private FinanceInvoiceRequest financeInvoiceRequest;
 
+    @Autowired
+    protected WorkInvoiceDao workInvoiceDao;
+
+    @Autowired
+    private WorkInvoiceCloudDao workInvoiceCloudDao;
+    @Autowired
+    private WorkInvoiceDetailDao workInvoiceDetailDao;
+    @Autowired
+    private WorkattachmentService workattachmentService;
+
+    @Autowired
+    private OfficeService officeService;
+
     /**
      * 查询发票详情
      * @param id
@@ -311,6 +332,281 @@ public class FinanceInvoiceService {
         return workAccounts;
     }
 
+
+    /**
+     * 将cpa的发票详情字段转换为当前系统字段(用于保存数据库)
+     * @param resp
+     * @return
+     */
+    public WorkInvoice convertFinanceInsert(Map<String,Object> resp) throws Exception{
+        WorkInvoice result = new WorkInvoice();
+        if (Objects.nonNull(resp)) {
+            result.setIsSzCloud("sz");
+            // id
+            if (Objects.nonNull(resp.get("id"))) {
+                result.setId(resp.get("id").toString());
+            }
+            if (Objects.nonNull(resp.get("createByName"))){
+                String createByName = (String) resp.get("createByName");
+                User user = UserUtils.getByUserName(createByName);
+                result.setCreateBy(user);
+                result.setUpdateBy(user);
+                Office office = officeService.get(user.getOffice().getId());
+                result.setOffice(office);
+                result.setCompanyId(user.getCompany().getId());
+            }
+            if (Objects.nonNull(resp.get("status"))){
+                result.setInvoiceState(resp.get("status").toString());
+            }
+            if (Objects.nonNull(resp.get("createTime"))){
+                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+                String createTimeMillis = (String) resp.get("createTime");
+                Date createDate = dateFormat.parse(createTimeMillis);
+                result.setCreateDate(createDate);
+                result.setUpdateDate(createDate);
+            }
+            // processInstanceId
+            if (Objects.nonNull(resp.get("procInsId"))) {
+                result.setProcessInstanceId(resp.get("procInsId").toString());
+            }
+            // 基本信息
+            if (Objects.nonNull(resp.get("financeInvoiceBaseDTOList"))){
+                String data = JSON.toJSONString(resp.get("financeInvoiceBaseDTOList"));
+                List<Object> baseList = JSON.parseArray(data,Object.class);
+                ArrayList<WorkInvoiceCloud> projectRelations = new ArrayList<>();
+                if (Objects.nonNull(baseList)){
+                    for (Object base : baseList) {
+                        WorkInvoiceCloud projectRelation = new WorkInvoiceCloud();
+                        Map<String, Object> baseMap = JSONObject.parseObject(JSON.toJSONString(base));
+                        if (Objects.nonNull(baseMap.get("programName"))){
+                            projectRelation.setProjectName(baseMap.get("programName").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("contractName"))){
+                            projectRelation.setWorkContractName(baseMap.get("contractName").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("programNo"))){
+                            projectRelation.setProjectNum(baseMap.get("programNo").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("clientName"))){
+                            projectRelation.setClientName(baseMap.get("clientName").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("reportNo"))){
+                            projectRelation.setReportNo(baseMap.get("reportNo").toString());
+                        }
+                        projectRelation.setId(baseMap.get("id").toString());
+                        projectRelation.setInvoiceId(result.getId());
+                        projectRelation.setDelFlag("0");
+                        projectRelation.setCreateBy(result.getCreateBy());
+                        projectRelation.setUpdateBy(result.getUpdateBy());
+                        projectRelation.setCreateDate(result.getCreateDate());
+                        projectRelation.setUpdateDate(result.getUpdateDate());
+                        if (null != result.getOffice()){
+                            projectRelation.setOfficeId(result.getOffice().getId());
+                        }
+                        projectRelation.setCompanyId(result.getCompanyId());
+                        projectRelations.add(projectRelation);
+                    }
+
+                }
+                result.setWorkInvoiceCloudList(projectRelations);
+            }
+
+            // 发票类型
+            if (Objects.nonNull(resp.get("type"))) {
+                result.setInvoiceType(resp.get("type").toString());
+            }
+            //发票编号
+            if (Objects.nonNull(resp.get("no"))) {
+                result.setNumber(resp.get("no").toString());
+            }
+            //开票类型
+            if (Objects.nonNull(resp.get("billingType"))) {
+                result.setNewDrawer(resp.get("billingType").toString());
+            }
+            //实际开票单位
+            if (Objects.nonNull(resp.get("billingWorkplaceReal"))) {
+                WorkClientInfo workClientInfo = new WorkClientInfo();
+                workClientInfo.setId(resp.get("billingWorkplaceReal").toString());
+                result.setClient(workClientInfo);
+            }
+            //纳税人识别号
+            if (Objects.nonNull(resp.get("taxpayerIdentificationNo"))) {
+                result.setOrUnicode(resp.get("taxpayerIdentificationNo").toString());
+            }
+            //地址
+            if (Objects.nonNull(resp.get("address"))) {
+                result.setAddress(resp.get("address").toString());
+            }
+            //电话
+            if (Objects.nonNull(resp.get("telPhone"))) {
+                result.setTelephone(resp.get("telPhone").toString());
+            }
+            //开户银行
+            if (Objects.nonNull(resp.get("openBank"))) {
+                result.setBank(resp.get("openBank").toString());
+            }
+            //银行账号
+            if (Objects.nonNull(resp.get("bankAccount"))) {
+                result.setBankNumber(resp.get("bankAccount").toString());
+            }
+            //收款类型
+            if (Objects.nonNull(resp.get("receivablesTypeLabel"))) {
+                result.setChargeType(resp.get("receivablesTypeLabel").toString());
+            }
+            //开票内容
+            if (Objects.nonNull(resp.get("billingContentLabel"))) {
+                result.setBillingContent(resp.get("billingContentLabel").toString());
+            }
+            //开票金额
+            if (Objects.nonNull(resp.get("account"))) {
+                result.setMoney(Double.parseDouble(resp.get("account").toString()));
+            }
+            //开票内容要求
+            if (Objects.nonNull(resp.get("billingContentTerms"))) {
+                result.setContent(resp.get("billingContentTerms").toString());
+            }
+            //开票人
+            if (Objects.nonNull(resp.get("billingPeople"))) {
+                User userName = UserUtils.getByUserName(resp.get("billingPeople").toString());
+                result.setDrawer(userName);
+                result.setDrawerName(userName.getName());
+
+            }
+            //实际开票人
+            if (Objects.nonNull(resp.get("billingPeopleRealName"))) {
+                User userName = UserUtils.getByUserName(resp.get("billingPeopleRealName").toString());
+                result.setActualDrawerName(resp.get("billingPeopleRealName").toString());
+                result.setActualDrawerId(userName.getId());
+            }
+            //接收邮箱
+            if (Objects.nonNull(resp.get("actualDrawerEmailAddress"))) {
+                result.setActualDrawerEmailAddress(resp.get("actualDrawerEmailAddress").toString());
+            }
+            //对账人
+            if (Objects.nonNull(resp.get("reconciliationPeopleName"))) {
+                User userName = UserUtils.getByUserName(resp.get("reconciliationPeopleName").toString());
+                result.setAccountCheckingUserName(resp.get("reconciliationPeopleName").toString());
+                result.setAccountCheckingUserId(userName.getId());
+            }
+            //对账地区
+            if (Objects.nonNull(resp.get("reconciliationAreaName"))) {
+                Area area = new Area();
+                area.setId(resp.get("reconciliationAreaName").toString());
+                result.setArea(area);
+            }
+            //备注
+            if (Objects.nonNull(resp.get("remarks"))) {
+                result.setRemarks(resp.get("remarks").toString());
+            }
+            //开票时间
+            if (Objects.nonNull(resp.get("billingDate"))) {
+                String billingDate = resp.get("billingDate").toString();
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                Date date = sdf.parse(billingDate);
+                result.setInvoiceDate(date);
+            }
+            //领票时间
+            if (Objects.nonNull(resp.get("collectDate"))) {
+                String billingDate = resp.get("collectDate").toString();
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                Date date = sdf.parse(billingDate);
+                result.setTakeDate(date);
+            }
+            //发票明细
+            if (Objects.nonNull(resp.get("financeInvoiceDetailDTOList"))){
+                String data = JSON.toJSONString(resp.get("financeInvoiceDetailDTOList"));
+                List<Object> baseList = JSON.parseArray(data,Object.class);
+                ArrayList<WorkInvoiceDetail> workInvoiceDetails = new ArrayList<>();
+                if (Objects.nonNull(baseList)){
+                    for (Object base : baseList) {
+                        WorkInvoiceDetail workInvoiceDetail = new WorkInvoiceDetail();
+                        Map<String, Object> baseMap = JSONObject.parseObject(JSON.toJSONString(base));
+                        if (Objects.nonNull(baseMap.get("code"))){
+                            workInvoiceDetail.setCode(baseMap.get("code").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("number"))){
+                            workInvoiceDetail.setNumber(baseMap.get("number").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("account"))){
+                            workInvoiceDetail.setTotalMoney(baseMap.get("account").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("amount"))){
+                            workInvoiceDetail.setTaxMoney(baseMap.get("amount").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("rate"))){
+                            workInvoiceDetail.setTax(baseMap.get("rate").toString());
+                        }
+                        if (Objects.nonNull(baseMap.get("tax"))){
+                            workInvoiceDetail.setTaxRate(baseMap.get("tax").toString());
+                        }
+                        workInvoiceDetail.setId(baseMap.get("id").toString());
+                        workInvoiceDetail.setInvoiceId(result.getId());
+                        workInvoiceDetail.setDelFlag("0");
+                        workInvoiceDetail.setCreateBy(result.getCreateBy());
+                        workInvoiceDetail.setUpdateBy(result.getUpdateBy());
+                        workInvoiceDetail.setCreateDate(result.getCreateDate());
+                        workInvoiceDetail.setUpdateDate(result.getUpdateDate());
+                        if (null != result.getOffice()){
+                            workInvoiceDetail.setOfficeId(result.getOffice().getId());
+                        }
+                        workInvoiceDetail.setComId(result.getCompanyId());
+                        workInvoiceDetail.setBackSign("正常");
+                        workInvoiceDetail.setState("正常");
+                        workInvoiceDetails.add(workInvoiceDetail);
+                    }
+
+                }
+                result.setWorkAccountList(workInvoiceDetails);
+            }
+
+            // 附件
+            if (Objects.nonNull(resp.get("workAttachmentDtoList"))) {
+                String jsonString = JSON.toJSONString(resp.get("workAttachmentDtoList"));
+                List<Object> attachmentList = JSON.parseArray(jsonString, Object.class);
+                List<Workattachment> attachments = new ArrayList<>();
+                if (Objects.nonNull(attachmentList)) {
+                    for (Object attachment : attachmentList) {
+                        Workattachment attachmentDto = new Workattachment();
+                        Map<String, Object> fileMap = JSONObject.parseObject(JSON.toJSONString(attachment));
+                        User u = new User();
+                        if (Objects.nonNull(fileMap.get("name"))) { // 附件名称
+                            attachmentDto.setAttachmentName(fileMap.get("name").toString());
+                        }
+                        if (Objects.nonNull(fileMap.get("createBy"))) { // 创建人
+                            Map<String, Object> createBy = JSONObject.parseObject(JSON.toJSONString(fileMap.get("createBy")));
+                            if (Objects.nonNull(createBy.get("name"))) {
+                                u.setName(createBy.get("name").toString());
+                            }
+                        }
+                        if (Objects.nonNull(fileMap.get("createTime"))) { // 创建时间
+                            Object createTime = fileMap.get("createTime");
+                            if (createTime instanceof Long) {
+                                long timestamp = (Long) createTime;
+                                attachmentDto.setCreateDate(new Date(timestamp));
+                            }
+                        }
+                        if (Objects.nonNull(fileMap.get("url"))) { // 文件地址
+                            attachmentDto.setUrl(fileMap.get("url").toString());
+                        }
+                        attachmentDto.setCreateBy(u); // 创建人
+                        attachmentDto.setAttachmentId(result.getId());
+                        attachmentDto.setAttachmentFlag("115");
+                        User byUserName = UserUtils.getByUserName(u.getName());
+                        attachmentDto.setAttachmentUser(byUserName.getId());
+                        attachmentDto.setDelFlag("0");
+                        attachmentDto.setCreateBy(result.getCreateBy());
+                        attachmentDto.setUpdateBy(result.getUpdateBy());
+                        attachmentDto.setCreateDate(result.getCreateDate());
+                        attachmentDto.setUpdateDate(result.getUpdateDate());
+                        attachments.add(attachmentDto);
+                    }
+                }
+                result.setWorkAttachments(attachments);
+            }
+        }
+        return result;
+    }
+
     /**
      * 报销审核
      * @return
@@ -324,4 +620,50 @@ public class FinanceInvoiceService {
         return res;
     }
 
+
+    /**
+     * 将szCloud中的发票数据保存到数据库中
+     */
+    public void getFinanceInvoiceList() throws Exception {
+        Object financeInvoiceList = financeInvoiceRequest.getFinanceInvoiceList();
+        if (Objects.nonNull(financeInvoiceList)){
+            List<Map<String, Object>> financeInvoiceListMap = JSONObject.parseObject((String) financeInvoiceList, List.class);
+            if (financeInvoiceListMap != null && !financeInvoiceListMap.isEmpty()) {
+                for (Map<String, Object> reim : financeInvoiceListMap) {
+                    WorkInvoice workInvoice = new WorkInvoice();
+                    workInvoice = convertFinanceInsert(reim); // 格式转换
+                    //保存信息
+                    WorkInvoice invoice = workInvoiceDao.getById(workInvoice.getId());
+                    if (invoice != null){
+                        workInvoiceDao.update(workInvoice);
+                    }else {
+                        workInvoiceDao.insert(workInvoice);
+                    }
+                    //附件处理
+                    Workattachment workattachment = new Workattachment();
+                    workattachment.setAttachmentId(workInvoice.getId());
+                    workattachment.setAttachmentFlag("115");
+                    workattachment.setAttachmentUser(workInvoice.getCreateBy().getId());
+                    workattachmentService.delete(workattachment);
+                    for (Workattachment workAttachment : workInvoice.getWorkAttachments()) {
+                        workattachmentService.insertOnWorkAttachment(workAttachment);
+                    }
+                    //开票明细处理
+                    WorkInvoiceDetail workInvoiceDetail = new WorkInvoiceDetail();
+                    workInvoiceDetail.setInvoiceId(workInvoice.getId());
+                    workInvoiceDetailDao.delete(workInvoiceDetail);
+                    for (WorkInvoiceDetail invoiceDetail : workInvoice.getWorkAccountList()) {
+                        workInvoiceDetailDao.insert(invoiceDetail);
+
+                    }
+                    //开票与项目关系处理
+                    workInvoiceCloudDao.deleteByInvoiceId(workInvoice.getId());
+                    for (WorkInvoiceCloud workInvoiceCloud : workInvoice.getWorkInvoiceCloudList()) {
+                        workInvoiceCloudDao.insert(workInvoiceCloud);
+                    }
+                }
+            }
+
+        }
+    }
 }