Commit b9fcb4da authored by Ken you's avatar Ken you

add ebs JournalEntry api ---Ken

parent 68f705b9
......@@ -415,14 +415,6 @@
<artifactId>jxls-core</artifactId>
<version>1.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
......
package pwc.taxtech.atms.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import pwc.taxtech.atms.dto.ApiResultDto;
import pwc.taxtech.atms.dto.ebsdto.JEqueryDto;
import java.util.Collections;
import java.util.List;
@RestController
@RequestMapping("/ebs/api/v1/dd")
public class EbsApiController {
private static final Logger logger= LoggerFactory.getLogger(EbsApiController.class);
@RequestMapping(value = "/queryRemoteServerThenUpdateJE", method = RequestMethod.POST)
public ApiResultDto queryRemoteServerThenUpdateJE(@RequestBody List<JEqueryDto> items) {
if (items!=null&&!items.isEmpty()) {
return ApiResultDto.success(Collections.emptyList());
}
try {
return ApiResultDto.success(queryRemoteServerThenUpdateJE(items));
} catch (Exception e) {
logger.error("queryRemoteServerThenUpdateJE error.", e);
}
return ApiResultDto.fail();
}
}
package pwc.taxtech.atms.dto.vatdto.excelheader;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class CashFlowHeader {
private String companyNameCn;
private String companyNameEn;
......@@ -13,4 +8,60 @@ public class CashFlowHeader {
private String ledgerName;
private String ledgerCurrencyCode;
private String status;
public String getCompanyNameCn() {
return companyNameCn;
}
public void setCompanyNameCn(String companyNameCn) {
this.companyNameCn = companyNameCn;
}
public String getCompanyNameEn() {
return companyNameEn;
}
public void setCompanyNameEn(String companyNameEn) {
this.companyNameEn = companyNameEn;
}
public Integer getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Integer periodStart) {
this.periodStart = periodStart;
}
public Integer getPeriodEnd() {
return periodEnd;
}
public void setPeriodEnd(Integer periodEnd) {
this.periodEnd = periodEnd;
}
public String getLedgerName() {
return ledgerName;
}
public void setLedgerName(String ledgerName) {
this.ledgerName = ledgerName;
}
public String getLedgerCurrencyCode() {
return ledgerCurrencyCode;
}
public void setLedgerCurrencyCode(String ledgerCurrencyCode) {
this.ledgerCurrencyCode = ledgerCurrencyCode;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
package pwc.taxtech.atms.service;
import pwc.taxtech.atms.dto.ebsdto.JEqueryDto;
import java.util.List;
public interface EbsApiService {
/**
* EBS 日记账同步更新
* @param items
*/
void queryRemoteServerThenUpdateJE(List<JEqueryDto> items);
}
package pwc.taxtech.atms.service.impl;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.util.BeanUtil;
import pwc.taxtech.atms.dto.ebsdto.JEqueryDto;
import pwc.taxtech.atms.service.EbsApiService;
import pwc.taxtech.atms.vat.dao.JournalEntryMapper;
import pwc.taxtech.atms.vat.entity.JournalEntry;
import pwc.taxtech.atms.vat.entity.JournalEntryExample;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.Optional;
@Service
public class EbsApiServiceImpl implements EbsApiService {
@Resource
private JournalEntryMapper journalEntryMapper;
@Resource
private DistributedIdService distributedIdService;
@Resource
private BeanUtil beanUtil;
private static final Logger logger= LoggerFactory.getLogger(EbsApiServiceImpl.class);
@Override
public void queryRemoteServerThenUpdateJE(List<JEqueryDto> items) {
long start=System.currentTimeMillis();
logger.debug("start queryRemoteServerThenUpdateJE");
//判断数据是否存在
if(items.size()==0){
logger.error("empty EBS JE response, skip processing");
return;
}
logger.debug("requestJEItems:"+ JSON.toJSONString(items));
for(JEqueryDto a:items){
try {
processJE(a);
}catch (Exception e){
logger.error("break loop as catch:" + e, e);
}
}
logger.debug("end queryRemoteServerThenUpdateJE,took [{}] ms",System.currentTimeMillis()-start);
}
private void processJE(JEqueryDto item){
JournalEntryExample journalEntryExample=new JournalEntryExample();
journalEntryExample.createCriteria().andHeaderIdEqualTo(item.getHeaderId()).andLineNumEqualTo(item.getLineNum());
List<JournalEntry> journalEntryList=journalEntryMapper.selectByExample(journalEntryExample);
//唯一则更新否则插入
JournalEntry journalEntry=new JournalEntry();
if(journalEntryList.size()==1){
logger.info("exit and update journalEntry headerId:{},lineNum:{}", item.getHeaderId(),item.getLineNum());
journalEntry=journalEntryList.get(0);
populateFieldsJE(item,journalEntry);
journalEntryMapper.updateByPrimaryKey(journalEntry);
}else{
logger.info("miss and insert journalEntry headerId:{},lineNum:{}", item.getHeaderId(),item.getLineNum());
populateFieldsJE(item,journalEntry);
journalEntry.setId(distributedIdService.nextId());
journalEntry.setCreatedBy("");
journalEntry.setCreatedDate(new Date());
journalEntry.setCreateTime(new Date());
journalEntryMapper.insertSelective(journalEntry);
}
}
private void populateFieldsJE(JEqueryDto item,JournalEntry result){
result.setOrganizationId(trimLimit(item.getOrganizationId(),128));
result.setProjectId(trimLimit(item.getProjectId(),128));
result.setDate(item.getDate());
result.setSource(trimLimit(item.getSource(),20));
result.setLedgerId(trimLimit(item.getLedgerId(),128));
result.setLedgerName(trimLimit(item.getLedgerName(),300));
result.setCurrencyCode(trimLimit(item.getCurrencyCode(),20));
result.setStatus(trimLimit(item.getStatus(),10));
result.setHeaderId(trimLimit(item.getHeaderId(),128));
result.setLineNum(trimLimit(item.getLineNum(),300));
result.setApprovalStatus(trimLimit(item.getApprovalStatus(),20));
result.setPostedStatus(trimLimit(item.getPostedStatus(),20));
result.setPeriod(StringUtils.isBlank(item.getPeriod().toString())?0:item.getPeriod());
result.setAccountingDate(item.getAccountingDate());
result.setJournalSource(trimLimit(item.getJournalSource(),20));
result.setCategory(trimLimit(item.getCategory(),50));
result.setName(trimLimit(item.getName(),300));
result.setVoucherNum(trimLimit(item.getVoucherNum(),128));
result.setDescription(trimLimit(item.getDescription(),500));
result.setSegment1(trimLimit(item.getSegment1(),300));
result.setSegment2(trimLimit(item.getSegment2(),300));
result.setSegment3(trimLimit(item.getSegment3(),300));
result.setSegment4(trimLimit(item.getSegment4(),300));
result.setSegment5(trimLimit(item.getSegment5(),300));
result.setSegment6(trimLimit(item.getSegment6(),300));
result.setSegment7(trimLimit(item.getSegment7(),300));
result.setSegment8(trimLimit(item.getSegment8(),300));
result.setSegment9(trimLimit(item.getSegment9(),300));
result.setSegment10(trimLimit(item.getSegment10(),300));
result.setSegment1Name(trimLimit(item.getSegment1Name(),300));
result.setSegment2Name(trimLimit(item.getSegment2Name(),300));
result.setSegment3Name(trimLimit(item.getSegment3Name(),300));
result.setSegment4Name(trimLimit(item.getSegment4Name(),300));
result.setSegment5Name(trimLimit(item.getSegment5Name(),300));
result.setSegment6Name(trimLimit(item.getSegment6Name(),300));
result.setSegment7Name(trimLimit(item.getSegment7Name(),300));
result.setSegment8Name(trimLimit(item.getSegment8Name(),300));
result.setSegment9Name(trimLimit(item.getSegment9Name(),300));
result.setSegment10Name(trimLimit(item.getSegment10Name(),300));
result.setJournalCurrencyCode(trimLimit(item.getJournalCurrencyCode(),20));
result.setSobCurrencyCode(trimLimit(item.getSobCurrencyCode(),20));
result.setAccountedDr(Optional.ofNullable(item.getAccountedDr()).map(x->x.setScale(4, RoundingMode.HALF_UP)).orElse(BigDecimal.ZERO));
result.setAccountedCr(Optional.ofNullable(item.getAccountedCr()).map(x->x.setScale(4, RoundingMode.HALF_UP)).orElse(BigDecimal.ZERO));
result.setEnteredDr(Optional.ofNullable(item.getEnteredDr()).map(x->x.setScale(4, RoundingMode.HALF_UP)).orElse(BigDecimal.ZERO));
result.setEnteredCr(Optional.ofNullable(item.getEnteredCr()).map(x->x.setScale(4, RoundingMode.HALF_UP)).orElse(BigDecimal.ZERO));
result.setCfItem(trimLimit(item.getCfItem(),50));
result.setAttribute1(trimLimit(item.getAttribute1(),300));
result.setAttribute2(item.getAttribute2());
result.setAttribute3(trimLimit(item.getAttribute3(),300));
result.setAttribute4(trimLimit(item.getAttribute4(),300));
result.setAttribute5(trimLimit(item.getAttribute5(),300));
result.setAttribute6(trimLimit(item.getAttribute6(),300));
result.setAttribute7(trimLimit(item.getAttribute7(),300));
result.setAttribute8(trimLimit(item.getAttribute8(),300));
result.setAttribute9(trimLimit(item.getAttribute9(),300));
result.setAttribute10(trimLimit(item.getAttribute10(),300));
result.setAttribute11(trimLimit(item.getAttribute11(),300));
result.setAttribute12(trimLimit(item.getAttribute12(),300));
result.setAttribute13(trimLimit(item.getAttribute13(),300));
result.setAttribute14(trimLimit(item.getAttribute14(),300));
result.setAttribute15(trimLimit(item.getAttribute15(),300));
result.setAttribute16(trimLimit(item.getAttribute16(),300));
result.setLateUpdatedBy("");
result.setLateUpdatedDate(new Date());
result.setUpdateTime(new Date());
}
/** Trim字符串,并限定字符串的长度. 如果是输入值是空指针,会返回空字符串 */
public String trimLimit(String str, int limit) {
if (Strings.isBlank(str)) {
return "";
}
String tmp = str.trim();
String result = cutString(tmp, limit);
if (result == null)
result = "";
return result;
}
/** 限定字符串的长度. */
public String cutString(String s, int length) {
if (Lang.isEmpty(length) || Lang.isEmpty(s))
return "";
else if (s.length() <= length)
return s;
else
return s.substring(0, length);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment