Commit 42de9acc authored by eddie.woo's avatar eddie.woo

add

parent 2c87ebc4
......@@ -301,6 +301,11 @@
<scope>system</scope>
<systemPath>${basedir}/lib/java-axp-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
</dependencies>
<profiles>
......
package pwc.taxtech.atms.constant.enums;
import java.util.HashMap;
import java.util.Map;
public class StdAccountEnum {
public enum AcctProp {
Asset("1", "资产"),
Debt("2", "负债"),
Joint("3", "共同"),
Equity("4", "权益"),
Cost("5", "成本"),
Loss("6", "损益");
private String code;
private String name;
public static final Map<String, String> MAPPING = new HashMap<>();
AcctProp(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
static {
for (AcctProp acctProp : AcctProp.values()) {
MAPPING.put(acctProp.getCode(), acctProp.getName());
}
}
}
}
package pwc.taxtech.atms.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BaseController {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
}
......@@ -6,6 +6,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
......@@ -253,4 +254,11 @@ public class EnterpriseAccountManagerController {
public @ResponseBody List<AccountMappingDto> getAccountMappingOrg(@RequestParam String organizationID) {
return enterpriseAccountService.getAccountMappingOrg(organizationID);
}
@ResponseBody
@ApiOperation(value = "按组织机构查找")
@RequestMapping(value = "getEnterpriseAccountSetListByOrgID", method = RequestMethod.GET)
public List<EnterpriseAccountSetDto> getEnterpriseAccountSetListByOrgID(@RequestParam String orgID) {
return enterpriseAccountService.getEnterpriseAccountSetListByOrgID(orgID);
}
}
package pwc.taxtech.atms.controller;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pwc.taxtech.atms.dto.stdaccount.StdAccountFancyTreeDto;
import pwc.taxtech.atms.service.StdAccountService;
import java.util.Collections;
import java.util.List;
@RestController
@RequestMapping("/api/v1/stdAccount")
public class StdAccountController extends BaseController {
@Autowired
private StdAccountService stdAccountService;
@ResponseBody
@ApiOperation(value = "获取科目层级")
@RequestMapping(value = "stdAccountHierarchy", method = RequestMethod.GET)
public List<StdAccountFancyTreeDto> getStdAccountHierarchy(@RequestParam String orgID) {
if (StringUtils.isBlank(orgID)) {
return Collections.emptyList();
}
try {
return stdAccountService.getStdAccountHierarchy(orgID);
} catch (Exception e) {
logger.error("getStdAccountHierarchy error.", e);
}
return Collections.emptyList();
}
}
package pwc.taxtech.atms.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
......@@ -8,6 +7,8 @@ import pwc.taxtech.atms.MyMapper;
import pwc.taxtech.atms.entitiy.EnterpriseAccountSet;
import pwc.taxtech.atms.entitiy.EnterpriseAccountSetExample;
import java.util.List;
@Mapper
public interface EnterpriseAccountSetMapper extends MyMapper {
/**
......@@ -105,4 +106,6 @@ public interface EnterpriseAccountSetMapper extends MyMapper {
* @mbg.generated
*/
int updateByPrimaryKey(EnterpriseAccountSet record);
List<EnterpriseAccountSet> getAccountDtoByOrgId(@Param("orgId") String orgId);
}
\ No newline at end of file
......@@ -34,6 +34,13 @@ public class OperationResultDto<T> extends OperationResultBase {
return new OperationResultDto<>(true);
}
public static OperationResultDto<?> success(Object data) {
OperationResultDto dto = new OperationResultDto();
dto.setData(data);
dto.setResult(true);
return dto;
}
public static OperationResultDto<?> error() {
return OperationResultDto.error(null);
}
......
package pwc.taxtech.atms.dto.stdaccount;
import com.alibaba.fastjson.annotation.JSONField;
import java.util.List;
public class StdAccountFancyTreeDto {
private String title;
private Boolean expanded;
private Boolean hasChildren;
@JSONField(name = "id")
private String ID;
private String acctProp;
private String direction;
private String code;
private String name;
private String fullName;
private List<StdAccountFancyTreeDto> children;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Boolean getExpanded() {
return expanded;
}
public void setExpanded(Boolean expanded) {
this.expanded = expanded;
}
public Boolean getHasChildren() {
return hasChildren;
}
public void setHasChildren(Boolean hasChildren) {
this.hasChildren = hasChildren;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getAcctProp() {
return acctProp;
}
public void setAcctProp(String acctProp) {
this.acctProp = acctProp;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public List<StdAccountFancyTreeDto> getChildren() {
return children;
}
public void setChildren(List<StdAccountFancyTreeDto> children) {
this.children = children;
}
}
......@@ -97,6 +97,8 @@ public interface EnterpriseAccountService {
OperationResultDto clearRepeatEnterpriseAccountList(EnterpriseAccountSetDto enterpriseAccountSetDto);
List<AccountMappingDto> getAccountMappingOrg(String organizationID);
List<EnterpriseAccountSetDto> getEnterpriseAccountSetListByOrgID(String orgId);
}
package pwc.taxtech.atms.service;
import pwc.taxtech.atms.common.ServiceException;
import pwc.taxtech.atms.dto.stdaccount.StdAccountFancyTreeDto;
import java.util.List;
public interface StdAccountService {
List<StdAccountFancyTreeDto> getStdAccountHierarchy(String orgId) throws ServiceException;
}
package pwc.taxtech.atms.service.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import pwc.taxtech.atms.common.AtmsApiSettings;
import pwc.taxtech.atms.common.AuthUserHelper;
import pwc.taxtech.atms.service.OperationLogService;
public class BaseService {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
protected AuthUserHelper authUserHelper;
@Autowired
protected AtmsApiSettings atmsApiSettings;
@Autowired
protected OperationLogService operationLogService;
}
package pwc.taxtech.atms.service.impl;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.common.ServiceException;
import pwc.taxtech.atms.constant.enums.StdAccountEnum;
import pwc.taxtech.atms.dao.OrganizationMapper;
import pwc.taxtech.atms.dao.StandardAccountMapper;
import pwc.taxtech.atms.dto.stdaccount.StdAccountFancyTreeDto;
import pwc.taxtech.atms.entitiy.Organization;
import pwc.taxtech.atms.entitiy.StandardAccount;
import pwc.taxtech.atms.entitiy.StandardAccountExample;
import pwc.taxtech.atms.service.StdAccountService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class StdAccountServiceImpl extends BaseService implements StdAccountService {
@Autowired
private StandardAccountMapper standardAccountMapper;
@Autowired
private OrganizationMapper organizationMapper;
@Override
public List<StdAccountFancyTreeDto> getStdAccountHierarchy(String orgId) throws ServiceException {
List<StdAccountFancyTreeDto> resultList;
try {
if (StringUtils.isBlank(orgId)) {
return Collections.emptyList();
}
Organization organization = organizationMapper.selectByPrimaryKey(orgId);
if (null == organization) {
return Collections.emptyList();
}
String industryId = organization.getIndustryID();
resultList = new ArrayList<>();
if (StringUtils.isNotBlank(industryId)) {
List<StdAccountFancyTreeDto> dtoList = Lists.newArrayList();
StandardAccountExample example = new StandardAccountExample();
StandardAccountExample.Criteria criteria = example.createCriteria();
criteria.andIndustryIDEqualTo(industryId).andRuleTypeEqualTo(2).andIsActiveEqualTo(true);
List<StandardAccount> standardAccountList = standardAccountMapper.selectByExample(example);
List<StandardAccount> topList = standardAccountList.stream().filter(x -> StringUtils.isBlank(x.getParentCode()))
.collect(Collectors.toList());
for (StandardAccount topNode : topList) {
StdAccountFancyTreeDto dto = rotateToDto(topNode);
getSubStdAccount(dto, standardAccountList);
dtoList.add(dto);
}
Map<String, List<StdAccountFancyTreeDto>> map = dtoList.stream().collect(Collectors.groupingBy(x -> x.getAcctProp()));
for (Map.Entry<String, List<StdAccountFancyTreeDto>> entry : map.entrySet()) {
StdAccountFancyTreeDto root = new StdAccountFancyTreeDto();
root.setExpanded(false);
root.setHasChildren(CollectionUtils.isNotEmpty(entry.getValue()));
root.setTitle(StdAccountEnum.AcctProp.MAPPING.get(entry.getKey()));
root.setChildren(entry.getValue());
resultList.add(root);
}
}
} catch (Exception e) {
throw new ServiceException("getStdAccountHierarchy error.", e);
}
return resultList;
}
private void getSubStdAccount(StdAccountFancyTreeDto node, List<StandardAccount> allList) {
List<StdAccountFancyTreeDto> childList = allList.stream().filter(x -> StringUtils.equals(node.getCode(), x.getParentCode()))
.map(this::rotateToDto).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(childList)) {
node.setChildren(childList);
node.setHasChildren(true);
for (StdAccountFancyTreeDto tmp : childList) {
getSubStdAccount(tmp, allList);
}
}
}
private StdAccountFancyTreeDto rotateToDto(StandardAccount account) {
StdAccountFancyTreeDto dto = new StdAccountFancyTreeDto();
dto.setExpanded(false);
dto.setHasChildren(false);
return CommonUtils.copyProperties(account, dto);
}
}
......@@ -318,4 +318,12 @@
order by ${orderByClause}
</if>
</select>
<select id="getAccountDtoByOrgId" resultMap="BaseResultMap">
select ta.ID, ta.Code, ta.Name, ta.IsActive, ta.CreatorID, ta.CreateTime, ta.UpdateTime
from EnterpriseAccountSet ta
left outer join EnterpriseAccountSetOrg tb
on ta.ID = tb.EnterpriseAccountSetID
where tb.OrganizationID=#{orgId}
</select>
</mapper>
\ No newline at end of file
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