|
@@ -1,14 +1,32 @@
|
|
|
package com.jeeplus.modules.szCenterservice.controller.szCloud;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.jeeplus.common.config.Global;
|
|
|
import com.jeeplus.common.utils.ObjectUtils;
|
|
|
import com.jeeplus.common.utils.StringUtils;
|
|
|
+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.szCenterservice.service.szCloud.FinanceInvoiceRequest;
|
|
|
+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.workinvoice.service.WorkInvoiceAllService;
|
|
|
+import com.jeeplus.modules.workinvoicedetail.dao.WorkInvoiceDetailDao;
|
|
|
+import com.jeeplus.modules.workinvoicedetail.entity.WorkInvoiceDetail;
|
|
|
import com.jeeplus.modules.workreimbursement.entity.WorkReimbursement;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
@@ -16,10 +34,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping(value = "${adminPath}/cpa_finance")
|
|
@@ -28,6 +43,22 @@ public class CpaFinanceInvoiceController {
|
|
|
@Autowired
|
|
|
private FinanceInvoiceRequest financeInvoiceRequest;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ protected WorkInvoiceDao workInvoiceDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OfficeService officeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkInvoiceAllService workInvoiceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkInvoiceCloudDao workInvoiceCloudDao;
|
|
|
+ @Autowired
|
|
|
+ private WorkInvoiceDetailDao workInvoiceDetailDao;
|
|
|
+ @Autowired
|
|
|
+ private WorkattachmentService workattachmentService;
|
|
|
+
|
|
|
|
|
|
@RequestMapping(value = "saveAudit")
|
|
|
public String saveAudit(WorkInvoice workInvoice, RedirectAttributes redirectAttributes) throws ParseException {
|
|
@@ -72,5 +103,315 @@ public class CpaFinanceInvoiceController {
|
|
|
redirectAttributes.addFlashAttribute("message", sb.toString());
|
|
|
}
|
|
|
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ @RequestMapping(value = "saveInfo", method = RequestMethod.POST)
|
|
|
+ public void saveInfo(@RequestBody String json) throws Exception {
|
|
|
+ WorkInvoice workInvoice = new WorkInvoice();
|
|
|
+ if(json != null) {
|
|
|
+ Map<String, Object> reim = JSONObject.parseObject(json);
|
|
|
+ workInvoice = convertFinance(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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将cpa的发票详情字段转换为当前系统字段
|
|
|
+ * @param resp
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public WorkInvoice convertFinance(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");
|
|
|
+ Long createTimeMillis = (Long) resp.get("createTime");
|
|
|
+ Date createDate = new Date(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());
|
|
|
+ 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());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|