Commit 50f6a44d authored by eddie.woo's avatar eddie.woo

add autoMap

parent 159d0642
......@@ -163,6 +163,10 @@
<property name="useActualColumnNames" value="true" />
<property name="ignoreQualifiersAtRuntime" value="true"/>
</table>
<table tableName="AccountMappingManual" domainObjectName="AccountMappingManual">
<property name="useActualColumnNames" value="true" />
<property name="ignoreQualifiersAtRuntime" value="true"/>
</table>
<table tableName="EnterpriseAccountSetOrg" domainObjectName="EnterpriseAccountSetOrg">
<property name="useActualColumnNames" value="true" />
<property name="ignoreQualifiersAtRuntime" value="true"/>
......
package pwc.taxtech.atms.common.message;
public class EnterpriseAccountSetOrgMsg {
public static final String EnterpriseAccountSetOrgExists = "EnterpriseAccountSetOrgExists";
public static final String NoOrgSetOrOrgExist = "NoOrgSetOrOrgExist";
public static final String EnterpriseAccountSetOrgDateTimeOverlap = "EnterpriseAccountSetOrgDateTimeOverlap";
public static final String RelevantOranization = "RelevantOranization";
public static final String EffectiveDateAreaProblem = "EffectiveDateAreaProblem";
public static final String EnterpriseAccountSetOrgOnlyOncePerYear = "EnterpriseAccountSetOrgOnlyOncePerYear";
}
package pwc.taxtech.atms.constant;
public class AccountMappingConstant {
public enum Status {
UNMAPPED(1, "未对应"),
MAPPED(2, "已对应"),
DIRECTION_DIFFERENT(3, "借贷方向不一致"),
ACCOUNT_TYPE_DIFFERENT(4, "科目类型不一致");
private Integer code;
private String name;
Status(Integer code, String name) {
this.code = code;
this.name = name;
}
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
}
}
package pwc.taxtech.atms.constant.enums;
public enum AccountRuleEnum {
Rule2001("企业会计制度(2001年实施)", 1),
Rule2007("企业会计准则(2007年实施)", 2);
private String name;
private Integer value;
AccountRuleEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
......@@ -270,4 +270,16 @@ public class EnterpriseAccountManagerController {
@RequestParam String filterType) {
return enterpriseAccountService.getList(espID, orgID, filterType);
}
@ResponseBody
@ApiOperation(value = "科目自动对应")
@RequestMapping(value = "autoMap", method = RequestMethod.GET)
public OperationResultDto autoMap(@RequestParam String orgID, @RequestParam String accountSetID) {
try {
return enterpriseAccountService.autoMap(orgID, accountSetID);
} catch (Exception e) {
logger.error("autoMap error.", e);
}
return OperationResultDto.error("自动对应失败");
}
}
......@@ -20,6 +20,7 @@ import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.OrganizationValidateDto;
import pwc.taxtech.atms.dto.dimension.DimensionOrgDtoDashboard;
import pwc.taxtech.atms.dto.dimension.OrgDashboardParams;
import pwc.taxtech.atms.dto.navtree.DevTreeDto;
import pwc.taxtech.atms.dto.navtree.NavTreeDto;
import pwc.taxtech.atms.dto.organization.DimensionRoleDto;
import pwc.taxtech.atms.dto.organization.OrgBasicDto;
......@@ -46,46 +47,53 @@ public class OrganizationController {
@ApiOperation(value = "根据使用的方式获取机构的列表")
@RequestMapping(value = "getjson", method = RequestMethod.GET)
public @ResponseBody List<NavTreeDto> getOrgListToJson(@RequestParam("useType") Integer useType) {
public @ResponseBody
List<NavTreeDto> getOrgListToJson(@RequestParam("useType") Integer useType) {
return organizationService.getOrgListToJson(useType);
}
@ApiOperation(value = "获取根据机构筛选的属性和机构名称")
@RequestMapping(value = "getOrganizationFilterList", method = RequestMethod.GET)
public @ResponseBody List<OrganizationDto> getOrganizationFilterList() {
public @ResponseBody
List<OrganizationDto> getOrganizationFilterList() {
return organizationService.getOrganizationFilterList();
}
@ApiOperation(value = "根据使用的方式获取机构的展示列表")
@RequestMapping(value = "display", method = RequestMethod.GET)
public @ResponseBody List<OrganizationDto> getOrgList(@RequestParam("useType") Integer useType) {
public @ResponseBody
List<OrganizationDto> getOrgList(@RequestParam("useType") Integer useType) {
return organizationService.getOrgList(useType);
}
@ApiOperation(value = "获取行业列表")
@RequestMapping(value = "getProjectIndustrys", method = RequestMethod.GET)
public @ResponseBody List<IndustryDto> getProjectIndustry() {
public @ResponseBody
List<IndustryDto> getProjectIndustry() {
logger.info("GET /api/v1/org/getProjectIndustrys");
return organizationService.getProjectIndustryList();
}
@ApiOperation(value = "层级显示机构列表_列表显示")
@RequestMapping(value = "getOrgListLevel", method = RequestMethod.GET)
public @ResponseBody List<OrgBasicDto> getOrgListLevel() {
public @ResponseBody
List<OrgBasicDto> getOrgListLevel() {
logger.info("GET /api/v1/org/getOrgListLevel");
return organizationService.getOrgListLevel();
}
@ApiOperation(value = "纳税人识别号唯一性验证")
@RequestMapping(value = "taxPayerNumberUniqueValidate", method = RequestMethod.POST)
public @ResponseBody Boolean taxPayerNumberUniqueValidate(@RequestBody OrganizationValidateDto validateDto) {
public @ResponseBody
Boolean taxPayerNumberUniqueValidate(@RequestBody OrganizationValidateDto validateDto) {
logger.info("POST /api/v1/org/taxPayerNumberUniqueValidate");
return organizationService.taxPayerNumberUniqueValidate(validateDto);
}
@ApiOperation(value = "获取机构展示面板(Dashboard)")
@RequestMapping(value = "getOrgDashboard", method = RequestMethod.POST)
public @ResponseBody List<DimensionOrgDtoDashboard> getOrgDashboardPost(
public @ResponseBody
List<DimensionOrgDtoDashboard> getOrgDashboardPost(
@RequestBody(required = false) List<String> expandedOrgList,
@RequestParam("dimensionID") String dimensionID, @RequestParam("parentOrgID") String parentOrgID) {
logger.info("POST /api/v1/org/getOrgDashboard");
......@@ -96,8 +104,9 @@ public class OrganizationController {
@ApiOperation(value = "获取单个机构展示面板(Dashboard)")
@RequestMapping(value = "getOrgDashboardOnly", method = RequestMethod.GET)
public @ResponseBody List<DimensionOrgDtoDashboard> getOrgDashboard(@RequestParam("dimensionID") String dimensionID,
@RequestParam("parentOrgID") String parentOrgID, @RequestParam("filterFlag") String filterFlag) {
public @ResponseBody
List<DimensionOrgDtoDashboard> getOrgDashboard(@RequestParam("dimensionID") String dimensionID,
@RequestParam("parentOrgID") String parentOrgID, @RequestParam("filterFlag") String filterFlag) {
logger.info("POST /api/v1/org/getOrgDashboardOnly");
OrgDashboardParams param = new OrgDashboardParams();
param.setFilterFlag(filterFlag);
......@@ -113,7 +122,8 @@ public class OrganizationController {
@ApiOperation(value = "获取机构上层维度")
@RequestMapping(value = "getOrgBuAreaIndustryUser", method = RequestMethod.GET)
public @ResponseBody List<DimensionRoleDto> getOrgBuAreaIndustryUser(@RequestParam("userID") String userID) {
public @ResponseBody
List<DimensionRoleDto> getOrgBuAreaIndustryUser(@RequestParam("userID") String userID) {
logger.info("POST /api/v1/org/getOrgBuAreaIndustryUser");
return userRoleService.getOrgBuAreaIndustryUser(userID);
}
......@@ -140,7 +150,8 @@ public class OrganizationController {
@SuppressWarnings("rawtypes")
@ApiOperation(value = "禁用选中机构信息")
@RequestMapping(value = "disableOrgs", method = RequestMethod.POST)
public @ResponseBody OperationResultDto disableOrgs(@RequestBody List<String> orgIDs) {
public @ResponseBody
OperationResultDto disableOrgs(@RequestBody List<String> orgIDs) {
logger.info("POST /api/v1/org/disableOrgs");
return organizationService.disableOrgs(orgIDs);
}
......@@ -148,21 +159,24 @@ public class OrganizationController {
@SuppressWarnings("rawtypes")
@ApiOperation(value = "启用选中机构信息")
@RequestMapping(value = "enableOrgs", method = RequestMethod.GET)
public @ResponseBody OperationResultDto enableOrgs(@RequestParam("orgID") String orgID) {
public @ResponseBody
OperationResultDto enableOrgs(@RequestParam("orgID") String orgID) {
logger.info("POST /api/v1/org/enableOrgs");
return organizationService.enableOrgs(orgID);
}
@ApiOperation(value = "通过orgId获取一个组织的信息")
@RequestMapping(value = "displaySingle", method = RequestMethod.GET)
public @ResponseBody OrganizationDto getSingleOrgByOrgID(@RequestParam("orgId") String orgId) {
public @ResponseBody
OrganizationDto getSingleOrgByOrgID(@RequestParam("orgId") String orgId) {
logger.info("POST /api/v1/org/displaySingle");
return organizationService.getSingleOrgByOrgID(orgId);
}
@ApiOperation(value = "机构代码唯一性验证")
@RequestMapping(value = "codeUniqueValidate", method = RequestMethod.POST)
public @ResponseBody Boolean codeUniqueValidate(@RequestBody OrganizationValidateDto validateDto) {
public @ResponseBody
Boolean codeUniqueValidate(@RequestBody OrganizationValidateDto validateDto) {
logger.info("POST /api/v1/org/codeUniqueValidate");
return validateDto != null && organizationService.codeUniqueValidate(validateDto);
}
......@@ -170,14 +184,16 @@ public class OrganizationController {
@SuppressWarnings("rawtypes")
@ApiOperation(value = "为当前的维度添加现有的机构,可以批量的添加", notes = "机构管理>卡片视角>点击机构+>关联现有机构>确定")
@RequestMapping(value = "updateOrgToDimension", method = RequestMethod.POST)
public @ResponseBody OperationResultDto updateOrgToDimension(@RequestBody UpdateOrgDimensionDto dto) {
public @ResponseBody
OperationResultDto updateOrgToDimension(@RequestBody UpdateOrgDimensionDto dto) {
return organizationService.updateOrgToDimension(dto.getDimensionValueID(), dto.getDimensionID(),
dto.getOrgDtoList());
}
@ApiOperation(value = "增加机构信息")
@RequestMapping(value = "add", method = RequestMethod.POST)
public @ResponseBody OperationResultDto<Object> addOrg(@RequestBody OrganizationDto orgDto) {
public @ResponseBody
OperationResultDto<Object> addOrg(@RequestBody OrganizationDto orgDto) {
logger.info("POST /api/v1/org/add");
if (StringUtils.isBlank(orgDto.getClientCode()) && StringUtils.isNotBlank(orgDto.getCode())) {
orgDto.setClientCode(orgDto.getCode());
......@@ -187,7 +203,8 @@ public class OrganizationController {
@ApiOperation(value = "更新机构信息")
@RequestMapping(value = "update", method = RequestMethod.PUT)
public @ResponseBody OperationResultDto<Object> updateOrg(@RequestBody OrganizationDto orgDto) {
public @ResponseBody
OperationResultDto<Object> updateOrg(@RequestBody OrganizationDto orgDto) {
logger.info("PUT /api/v1/org/update");
if (StringUtils.isBlank(orgDto.getClientCode()) && StringUtils.isNotBlank(orgDto.getCode())) {
orgDto.setClientCode(orgDto.getCode());
......@@ -197,17 +214,27 @@ public class OrganizationController {
@ApiOperation(value = "删除用户维度权限设置")
@RequestMapping(value = "deleteUserDimensionValue", method = RequestMethod.POST)
public @ResponseBody Boolean deleteUserDimensionValue(@RequestBody DimensionRoleDto dto,
@RequestParam("userID") String userID) {
public @ResponseBody
Boolean deleteUserDimensionValue(@RequestBody DimensionRoleDto dto,
@RequestParam("userID") String userID) {
userService.deleteUserDimensionValue(dto, userID);
return true;
}
@ApiOperation(value = "获取机构通用信息", notes = "机构管理>卡片视角>机构视图>点击机构灰色区域文字")
@RequestMapping(value = "getGeneralInfo", method = RequestMethod.GET)
public @ResponseBody OrgGeneralInfoDto getGeneralInfo(@RequestParam("orgID") String orgID) {
public @ResponseBody
OrgGeneralInfoDto getGeneralInfo(@RequestParam("orgID") String orgID) {
logger.info("POST /api/v1/org/getGeneralInfo");
return organizationService.getGeneralInfo(orgID);
}
@ResponseBody
@ApiOperation(value = "获取机构树信息", notes = "科目对应>复制对应关系>弹出层")
@RequestMapping(value = "getOrgIvhTreeList", method = RequestMethod.GET)
public List<DevTreeDto> getOrgIvhTreeList(@RequestParam("useType") Integer useType,
@RequestParam("orgSetID") String orgSetID) {
return organizationService.getOrgIvhTreeList(useType, orgSetID);
}
}
package pwc.taxtech.atms.dao.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.AccountMappingManualMapper;
import pwc.taxtech.atms.entitiy.AccountMappingManual;
import pwc.taxtech.atms.entitiy.AccountMappingManualExample;
import java.util.List;
import java.util.Optional;
@Service
public class AccountMappingManualDao {
@Autowired
AccountMappingManualMapper mapper;
public Optional<List<AccountMappingManual>> getAll() {
AccountMappingManualExample example = new AccountMappingManualExample();
return Optional.ofNullable(mapper.selectByExample(example));
}
}
package pwc.taxtech.atms.dao.dao;
import com.google.common.collect.Lists;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.constant.AccountMappingConstant;
import pwc.taxtech.atms.constant.EnterpriseAccountConstant;
import pwc.taxtech.atms.dao.EnterpriseAccountMapper;
import pwc.taxtech.atms.dto.epaccount.EnterpriseAccountDto;
import pwc.taxtech.atms.entitiy.EnterpriseAccount;
import pwc.taxtech.atms.entitiy.EnterpriseAccountExample;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Service
public class EnterpriseAccountDao {
@Autowired
private EnterpriseAccountMapper enterpriseAccountMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
public Optional<List<EnterpriseAccount>> getByEpAccountSetId(String epAccountSetId) {
EnterpriseAccountExample example = new EnterpriseAccountExample();
EnterpriseAccountExample.Criteria criteria = example.createCriteria();
criteria.andEnterpriseAccountSetIDEqualTo(epAccountSetId);
return Optional.ofNullable(enterpriseAccountMapper.selectByExample(example));
}
public Optional<EnterpriseAccount> getEpAccount(String epAccountCode, String epAccountSetId) {
EnterpriseAccountExample example = new EnterpriseAccountExample();
EnterpriseAccountExample.Criteria criteria = example.createCriteria();
criteria.andCodeEqualTo(epAccountCode);
criteria.andEnterpriseAccountSetIDEqualTo(epAccountSetId);
return enterpriseAccountMapper.selectByExample(example).stream().findFirst();
}
public String getEpAccountID(String epAccountCode, String epAccountSetId) {
Optional<EnterpriseAccount> optional = getEpAccount(epAccountCode, epAccountSetId);
return optional.isPresent() ? optional.get().getID() : StringUtils.EMPTY;
}
public List<EnterpriseAccountDto> getAccountMappingResult(String accountSetId, int ruleId, String industryId) {
//amk.IndustryId倒序排列可以保证在结果集中,同一个COA,本行业的匹配结果在通用关键字匹配结果之前出现
String sql = "SELECT a.Code, a.IsLeaf, sa.Code StdCode,a.FullName as AccountFullName, amk.FullName as MappingFullName,amk.IndustryId"
+ " FROM (select * from AccountMappingKeyword where IndustryId=?) amk "
+ " INNER JOIN (select * from StandardAccount where IndustryId=?) sa ON amk.StandardCode = sa.Code"
+ " INNER JOIN EnterpriseAccount a on a.FullName like amk.FullName"
+ " WHERE amk.RuleType = ? AND sa.IsLeaf = 1 AND a.EnterpriseAccountSetID=?"
+ " ORDER BY a.Code,amk.IndustryId DESC";
List<Map<String, Object>> queryList = jdbcTemplate.queryForList(sql, industryId, industryId, ruleId, accountSetId);
List<EnterpriseAccountDto> list = Lists.newArrayList();
for (Map<String, Object> obj : queryList) {
EnterpriseAccountDto account = new EnterpriseAccountDto();
account.setCode(MapUtils.getString(obj, "Code"));
account.setIsLeaf(StringUtils.equals(MapUtils.getString(obj, "isLeaf"), "1"));
account.setStdCode(MapUtils.getString(obj, "StdCode"));
account.setFullName(MapUtils.getString(obj, "AccountFullName"));
account.setMappingFullName(MapUtils.getString(obj, "MappingFullName"));
list.add(account);
}
return list;
}
public List<Map<String, Object>> selectAccounts(String industryId, String accountSetId, String organizationID, int iAcctProp,
int iIsMapped, int iLevel, Boolean bIsActive) {
//In admin module, enterprise account has IsInVoucher to identify vouchers
//However web admin is not requried voucher, so the field is not available in web admin,
//so set acctVoucherHasNull=true at this moment
//But in the web admin, balance is not required at this stage, so set balanceIsNull=true
//string sql = "select count(1) from EnterpriseAccount where IsInVoucher is null";
//bool balanceIsNull = true;
//bool acctVoucherHasNull = true;
List<String> whereList = Lists.newArrayList();
String sql = "SELECT * FROM ( " +
"SELECT CASE IsLeaf WHEN 0 THEN '+' ELSE '' END IsEx,Code, Name, FullName, " +
"CASE Direction WHEN 1 THEN N'借方' WHEN -1 THEN N'贷方' END Direction, " +
"CASE StdAccountCode WHEN '0000' THEN '-' ELSE StdAccountCode END StdCode," +
"CASE StdAccountCode WHEN '0000' THEN '-' ELSE StdName END StdName, " +
"CASE StdAccountCode WHEN '0000' THEN '-' ELSE StdAccountCode + '/' + StdFullName END StdCodeName, " +
"CASE StdAccountCode WHEN '0000' THEN '-' ELSE CASE StdDirection WHEN 1 THEN N'借方' WHEN -1 THEN N'贷方' END END StdDirection, " +
"CASE WHEN AcctProp<>StdAcctProp THEN 1 ELSE 0 END IsAcctPropDiff," +
"CASE WHEN StdAccountCode IS NULL THEN 0 ELSE 1 END MappingStatus, " +
"CASE WHEN StdAccountCode IS NULL THEN AcctProp ELSE StdAcctProp END AcctProp, ParentCode, AcctLevel, StdAccountCode AcctStdCode, IsLeaf " +
" FROM (SELECT ID,Code,Name,FullName,Direction,AcctProp,ParentCode,AcctLevel,IsLeaf FROM EnterpriseAccount WHERE EnterpriseAccountSetID=?) ea " +
"LEFT JOIN (SELECT EnterpriseAccountCode ,StandardAccountCode FROM AccountMapping WHERE OrganizationID=? AND IndustryID=?) am ON ea.Code=am.EnterpriseAccountCode " +
"LEFT JOIN (SELECT ID StdID, Code StdAccountCode, Name StdName, FullName StdFullName,Direction StdDirection,AcctProp StdAcctProp FROM StandardAccount WHERE IndustryID=?) sa ON am.StandardAccountCode=sa.StdAccountCode ) T";
List<Object> params = Lists.newArrayList(accountSetId, organizationID, industryId, industryId);
if (iAcctProp != EnterpriseAccountConstant.InvalidId) {
sql += "AcctProp = ?";
params.add(iAcctProp);
}
if (iIsMapped == AccountMappingConstant.Status.UNMAPPED.getCode()) {
sql += "StdCode IS NULL";
} else if (iIsMapped == AccountMappingConstant.Status.MAPPED.getCode()) {
sql += "StdCode IS NOT NULL";
} else if (iIsMapped == AccountMappingConstant.Status.DIRECTION_DIFFERENT.getCode()) {
sql += "StdCode IS NOT NULL AND Direction<>StdDirection";
} else if (iIsMapped == AccountMappingConstant.Status.ACCOUNT_TYPE_DIFFERENT.getCode()) {
sql += "StdCode IS NOT NULL AND IsAcctPropDiff=1";
}
if (iLevel != EnterpriseAccountConstant.InvalidId) {
sql += "AcctLevel = ?";
params.add(iLevel);
}
sql += " ORDER BY Code";
return jdbcTemplate.queryForList(sql, params.toArray());
}
}
package pwc.taxtech.atms.dao.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.EnterpriseAccountSetOrgMapper;
import pwc.taxtech.atms.entitiy.EnterpriseAccountSetOrg;
import pwc.taxtech.atms.entitiy.EnterpriseAccountSetOrgExample;
import java.util.List;
@Service
public class EnterpriseAccountSetOrgDao {
@Autowired
private EnterpriseAccountSetOrgMapper mapper;
public List<EnterpriseAccountSetOrg> getByOrgIdAndAccountSetId(String orgId, String accountSetId) {
EnterpriseAccountSetOrgExample example = new EnterpriseAccountSetOrgExample();
EnterpriseAccountSetOrgExample.Criteria criteria = example.createCriteria();
criteria.andOrganizationIDEqualTo(orgId);
criteria.andEnterpriseAccountSetIDEqualTo(accountSetId);
return mapper.selectByExample(example);
}
}
package pwc.taxtech.atms.dao.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.StandardAccountMapper;
import pwc.taxtech.atms.entitiy.StandardAccount;
import pwc.taxtech.atms.entitiy.StandardAccountExample;
import java.util.List;
import java.util.Optional;
@Service
public class StandardAccountDao {
@Autowired
private StandardAccountMapper standardAccountMapper;
public Optional<List<StandardAccount>> getByIndustryId(String industryId) {
StandardAccountExample example = new StandardAccountExample();
StandardAccountExample.Criteria criteria = example.createCriteria();
criteria.andIndustryIDEqualTo(industryId);
return Optional.ofNullable(standardAccountMapper.selectByExample(example));
}
}
package pwc.taxtech.atms.dto.accountmapping;
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.CommonConstants;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.dao.AccountMappingMapper;
import pwc.taxtech.atms.dao.dao.EnterpriseAccountDao;
import pwc.taxtech.atms.entitiy.AccountMapping;
import pwc.taxtech.atms.entitiy.AccountMappingExample;
import java.util.List;
@Service
public class AccountMappingDao {
@Autowired
AccountMappingMapper mapper;
@Autowired
EnterpriseAccountDao epAccountDao;
public void delByEpAccountCodeList(List<String> codeList) {
if (CollectionUtils.isNotEmpty(codeList)) {
AccountMappingExample example = new AccountMappingExample();
AccountMappingExample.Criteria criteria = example.createCriteria();
criteria.andEnterpriseAccountCodeIn(codeList);
mapper.deleteByExample(example);
}
}
public boolean isStdExists(String accountSetID, String enterpirseAccountCode, String industryID, String orgID) {
AccountMappingExample example = new AccountMappingExample();
AccountMappingExample.Criteria criteria = example.createCriteria();
criteria.andEnterpriseAccountCodeEqualTo(enterpirseAccountCode);
criteria.andEnterpriseAccountSetIDEqualTo(accountSetID);
criteria.andOrganizationIDEqualTo(orgID);
criteria.andIndustryIDEqualTo(industryID);
criteria.andStandardAccountCodeNotEqualTo(CommonConstants.EmptyStdCode);
return mapper.countByExample(example) > 0;
}
private void updateToTable(String accountCode, String accountSetId, String stdAccountCode,
String industryID, String enterpriseAccountID, String orgID) {
AccountMappingExample example = new AccountMappingExample();
AccountMappingExample.Criteria criteria = example.createCriteria();
criteria.andEnterpriseAccountCodeEqualTo(accountCode);
criteria.andEnterpriseAccountSetIDEqualTo(accountSetId);
criteria.andOrganizationIDEqualTo(orgID);
criteria.andIndustryIDEqualTo(industryID);
mapper.deleteByExample(example);
AccountMapping mapping = new AccountMapping();
mapping.setID(CommonUtils.getUUID());
mapping.setEnterpriseAccountCode(accountCode);
mapping.setEnterpriseAccountSetID(accountSetId);
mapping.setOrganizationID(orgID);
mapping.setStandardAccountCode(stdAccountCode);
mapping.setIndustryID(industryID);
mapper.insertSelective(mapping);
}
public void mapStdAccountByCode(String accountSetId, String stdAccountCode, String accountCode,
String industryID, String orgId, boolean bOverwrite, int acctLevel) {
String enterpriseAccountID = epAccountDao.getEpAccountID(accountCode, accountSetId);
if (StringUtils.isBlank(stdAccountCode))
stdAccountCode = CommonConstants.NullStdCode;
//region 新逻辑
if (!bOverwrite) {
if (!isStdExists(accountSetId, accountCode, industryID, orgId)) {
updateToTable(accountCode, accountSetId, stdAccountCode, industryID, enterpriseAccountID, orgId);
}
} else {
updateToTable(accountCode, accountSetId, stdAccountCode, industryID, enterpriseAccountID, orgId);
}
//endregion
}
}
package pwc.taxtech.atms.dto.accountmapping;
import com.alibaba.fastjson.annotation.JSONField;
import java.util.Date;
public class AccountMappingManualDto {
@JSONField(name = "id")
public String ID;
public String standardCode;
public String fullName;
public String enterpriseAccountSetID;
public String organizationID;
public String industryID;
public int priority;
public Date updateTime;
public String updateBy;
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getStandardCode() {
return standardCode;
}
public void setStandardCode(String standardCode) {
this.standardCode = standardCode;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getEnterpriseAccountSetID() {
return enterpriseAccountSetID;
}
public void setEnterpriseAccountSetID(String enterpriseAccountSetID) {
this.enterpriseAccountSetID = enterpriseAccountSetID;
}
public String getOrganizationID() {
return organizationID;
}
public void setOrganizationID(String organizationID) {
this.organizationID = organizationID;
}
public String getIndustryID() {
return industryID;
}
public void setIndustryID(String industryID) {
this.industryID = industryID;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
}
package pwc.taxtech.atms.dto.stdaccount;
import com.alibaba.fastjson.annotation.JSONField;
import java.util.List;
public class StandardAccountDto {
@JSONField(name = "id")
public String ID;
public String code;
public String name;
public String parentCode;
public String fullName;
public int number;
public Boolean expanded;
public Integer acctProp;
public Integer subProp;
public Integer acctLevel;
public int direction;
public Boolean isLeaf;
public int ruleType;
public Boolean isActive;
public String englishName;
public String industryID;
public String title;
public String etsName;
public String etsCode;
public List<StandardAccountDto> children;
public String treeLevel;
/// <summary>
/// 父级科目名称
/// </summary>
/// <value>
/// The name of the parent.
/// </value>
public String parentName;
/// <summary>
/// 父级科目全名
/// </summary>
/// <value>
/// The full name of the parent.
/// </value>
public String parentFullName;
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
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 getParentCode() {
return parentCode;
}
public void setParentCode(String parentCode) {
this.parentCode = parentCode;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public Boolean getExpanded() {
return expanded;
}
public void setExpanded(Boolean expanded) {
this.expanded = expanded;
}
public Integer getAcctProp() {
return acctProp;
}
public void setAcctProp(Integer acctProp) {
this.acctProp = acctProp;
}
public Integer getSubProp() {
return subProp;
}
public void setSubProp(Integer subProp) {
this.subProp = subProp;
}
public Integer getAcctLevel() {
return acctLevel;
}
public void setAcctLevel(Integer acctLevel) {
this.acctLevel = acctLevel;
}
public int getDirection() {
return direction;
}
public void setDirection(int direction) {
this.direction = direction;
}
public Boolean getLeaf() {
return isLeaf;
}
public void setLeaf(Boolean leaf) {
isLeaf = leaf;
}
public int getRuleType() {
return ruleType;
}
public void setRuleType(int ruleType) {
this.ruleType = ruleType;
}
public Boolean getActive() {
return isActive;
}
public void setActive(Boolean active) {
isActive = active;
}
public String getEnglishName() {
return englishName;
}
public void setEnglishName(String englishName) {
this.englishName = englishName;
}
public String getIndustryID() {
return industryID;
}
public void setIndustryID(String industryID) {
this.industryID = industryID;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getEtsName() {
return etsName;
}
public void setEtsName(String etsName) {
this.etsName = etsName;
}
public String getEtsCode() {
return etsCode;
}
public void setEtsCode(String etsCode) {
this.etsCode = etsCode;
}
public List<StandardAccountDto> getChildren() {
return children;
}
public void setChildren(List<StandardAccountDto> children) {
this.children = children;
}
public String getTreeLevel() {
return treeLevel;
}
public void setTreeLevel(String treeLevel) {
this.treeLevel = treeLevel;
}
public String getParentName() {
return parentName;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
public String getParentFullName() {
return parentFullName;
}
public void setParentFullName(String parentFullName) {
this.parentFullName = parentFullName;
}
}
......@@ -101,6 +101,8 @@ public interface EnterpriseAccountService {
List<EnterpriseAccountSetDto> getEnterpriseAccountSetListByOrgID(String orgId);
List<EnterpriseAccountDto> getList(String epAccountSetID, String orgId, String filterType);
OperationResultDto autoMap(String orgId, String accountSetId);
}
......@@ -9,6 +9,7 @@ import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.OrganizationValidateDto;
import pwc.taxtech.atms.dto.dimension.DimensionOrgDtoDashboard;
import pwc.taxtech.atms.dto.dimension.OrgDashboardParams;
import pwc.taxtech.atms.dto.navtree.DevTreeDto;
import pwc.taxtech.atms.dto.navtree.NavTreeDto;
import pwc.taxtech.atms.dto.organization.OrgBasicDto;
import pwc.taxtech.atms.dto.organization.OrgCustomDto;
......@@ -83,4 +84,6 @@ public interface OrganizationService {
OrgGeneralInfoDto getGeneralInfo(String orgID);
List<DevTreeDto> getOrgIvhTreeList(Integer useType,String orgSetId);
}
......@@ -4,6 +4,7 @@ package pwc.taxtech.atms.service.impl;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.nutz.lang.Files;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -11,16 +12,26 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pwc.taxtech.atms.common.*;
import pwc.taxtech.atms.common.message.EnterpriseAccountMessage;
import pwc.taxtech.atms.common.message.EnterpriseAccountSetOrgMsg;
import pwc.taxtech.atms.common.message.LogMessage;
import pwc.taxtech.atms.constant.EnterpriseAccountConstant;
import pwc.taxtech.atms.constant.IndustryConstant;
import pwc.taxtech.atms.constant.enums.AccountRuleEnum;
import pwc.taxtech.atms.dao.dao.AccountMappingManualDao;
import pwc.taxtech.atms.dao.dao.EnterpriseAccountDao;
import pwc.taxtech.atms.dao.dao.EnterpriseAccountSetOrgDao;
import pwc.taxtech.atms.dao.dao.StandardAccountDao;
import pwc.taxtech.atms.dto.OperationLogDto;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.UpdateLogParams;
import pwc.taxtech.atms.dto.ValidateInfoDto;
import pwc.taxtech.atms.dto.accountmapping.AccountMappingDao;
import pwc.taxtech.atms.dto.accountmapping.AccountMappingManualDto;
import pwc.taxtech.atms.dto.epaccount.AccountMappingDto;
import pwc.taxtech.atms.dto.epaccount.EnterpriseAccountAndValidateInfo;
import pwc.taxtech.atms.dto.epaccount.EnterpriseAccountDto;
import pwc.taxtech.atms.dto.epaccount.EnterpriseAccountSetDto;
import pwc.taxtech.atms.dto.stdaccount.StandardAccountDto;
import pwc.taxtech.atms.entitiy.*;
import pwc.taxtech.atms.service.AccountService;
import pwc.taxtech.atms.service.EnterpriseAccountService;
......@@ -33,9 +44,22 @@ import java.util.stream.Collectors;
@Service
public class EnterpriseAccountServiceImpl extends AbstractService implements EnterpriseAccountService {
@Autowired private AccountService accountService;
@Autowired private EnterpriseAccountSetService enterpriseAccountSetService;
@Autowired private FileService fileService;
@Autowired
private AccountService accountService;
@Autowired
private EnterpriseAccountSetService enterpriseAccountSetService;
@Autowired
private FileService fileService;
@Autowired
private EnterpriseAccountDao enterpriseAccountDao;
@Autowired
private StandardAccountDao standardAccountDao;
@Autowired
private AccountMappingManualDao mappingManualDao;
@Autowired
private EnterpriseAccountSetOrgDao epAccountSetOrgDao;
@Autowired
private AccountMappingDao accountMappingDao;
private Map<String, List<String>> mapParentAccountResult;
......@@ -673,6 +697,404 @@ public class EnterpriseAccountServiceImpl extends AbstractService implements Ent
return total.stream().sorted(Comparator.comparing(EnterpriseAccountDto::getCode)).collect(Collectors.toList());
}
@Transactional
@Override
public OperationResultDto autoMap(String orgId, String accountSetId) {
//region 基础数据获取
Optional<EnterpriseAccountSetOrg> optional = epAccountSetOrgDao.getByOrgIdAndAccountSetId(orgId, accountSetId)
.stream().findFirst();
Organization org = organizationMapper.selectByPrimaryKey(orgId);
if (optional.isPresent() && null != org) {
EnterpriseAccountSetOrg setOrg = optional.get();
String industryId = org.getIndustryID();
//标准科目准则
int ruleId = AccountRuleEnum.Rule2007.getValue();
//获取账套信息便于存储日志
EnterpriseAccountSet accountSet = new EnterpriseAccountSet();
//endregion
//region 获取基础信息
//获取指定企业账套下的企业科目集合并转化为DTO
List<EnterpriseAccount> epAccountList = enterpriseAccountDao.getByEpAccountSetId(setOrg.getEnterpriseAccountSetID()).get();
List<EnterpriseAccountDto> accountDtoList = epAccountList.stream().map(x -> {
return CommonUtils.copyProperties(x, new EnterpriseAccountDto());
}).collect(Collectors.toList());
//获取与该机构行业相同的标准科目集合并转化为DTO
List<StandardAccount> stdAccountList = standardAccountDao.getByIndustryId(industryId).get();
List<StandardAccountDto> stdAccountDtoList = epAccountList.stream().map(x -> {
return CommonUtils.copyProperties(x, new StandardAccountDto());
}).collect(Collectors.toList());
//获取叶子节点标准科目集合
List<StandardAccountDto> stdAccountLeafList = stdAccountDtoList.stream().filter(x -> x.isLeaf).collect(Collectors.toList());
List<AccountMappingManual> allAccountMappingManualList = mappingManualDao.getAll().get();
accountSet = enterpriseAccountSetMapper.selectByPrimaryKey(accountSetId);
//endregion
//region Step 0: 从手动对应库优先获取对应关系
applyPriorityKeywords(accountDtoList, allAccountMappingManualList, accountSetId, orgId, industryId);
//endregion
//region Step 1: 匹配企业科目全称FullName与标准科目FullName完全一致
//Step 1: Map accounts which name is identical to standard code fullname
for (StandardAccountDto stdAccount : stdAccountLeafList) {
Optional<EnterpriseAccountDto> account = accountDtoList.stream().filter(x -> StringUtils.equals(x.getFullName(),
stdAccount.getFullName())).findFirst();
if (account.isPresent() && StringUtils.isNotBlank(account.get().getCode())) {
if (account.get().getIsLeaf()) {
accountMappingDao.mapStdAccountByCode(setOrg.getEnterpriseAccountSetID(), stdAccount.getCode(),
account.get().getCode(), industryId, orgId, false, 0);
} else {
List<EnterpriseAccountDto> relatedAccounts = accountDtoList.stream().filter(x -> StringUtils.startsWith(x.getCode()
, account.get().getCode())).collect(Collectors.toList());
// in case user has already mapped some of the leaf accounts and we do not want to overwrite them, otherwise just loop all and map all.
// now use recursion to map one by one...
mapAllChildrenRecursively(orgId, industryId, setOrg.getEnterpriseAccountSetID(),
account.get().getCode(), stdAccount.getCode(), relatedAccounts, false);
}
}
}
//endregion
//region Step 2: 匹配关键字库AccountMappingKeyword
List<EnterpriseAccountDto> accountList = enterpriseAccountDao.getAccountMappingResult(setOrg.getEnterpriseAccountSetID(), ruleId, industryId);
accountDtoList = getAllActiveAccounts(orgId, industryId, setOrg.getEnterpriseAccountSetID(), false); //rdbDisplayPart.Checked 只显示有期初余额或有凭证的科目
for (EnterpriseAccountDto account : accountList) {
EnterpriseAccountDto crtAccount = account;
if (accountDtoList.stream().anyMatch(x -> StringUtils.equals(x.getCode(), account.getCode()))) {
List<EnterpriseAccountDto> mappingAccounts = accountDtoList.stream()
.filter(x -> StringUtils.equals(x.getCode(), account.getCode())).collect(Collectors.toList());
//查找C_AccountMappingKeyword中是否有关键字与当前科目的FullName完全匹配
for (EnterpriseAccountDto a : mappingAccounts) {
Optional<EnterpriseAccountDto> identicalMappedAccount = accountList.stream().filter(x -> StringUtils.equals(x.getCode(), a.getCode()) &&
StringUtils.equals(x.getMappingFullName(), a.getFullName())).findFirst();
if (identicalMappedAccount.isPresent()) {
crtAccount = identicalMappedAccount.get();
break;
}
}
if (crtAccount.getIsLeaf()) {
accountMappingDao.mapStdAccountByCode(setOrg.getEnterpriseAccountSetID(), crtAccount.getStdCode(),
crtAccount.getCode(), industryId, orgId, false, 0);
} else {
EnterpriseAccountDto finalCrtAccount = crtAccount;
List<EnterpriseAccountDto> relatedAccounts = accountDtoList.stream().filter(x -> StringUtils.startsWith(x.getCode(),
finalCrtAccount.getCode())).collect(Collectors.toList());
// in case user has already mapped some of the leaf accounts and we do not want to overwrite them, otherwise just loop all and map all.
// now use recursion to map one by one...
mapAllChildrenRecursively(orgId, industryId, setOrg.getEnterpriseAccountSetID(), crtAccount.getCode(),
crtAccount.getStdCode(), relatedAccounts, false);
}
}
}
//endregion
//region Step 3: Map 2nd or lower level of accounts which can be mapped to "其他"
//Step 3: Map 2nd or lower level of accounts which can be mapped to "其他"
accountDtoList = getAllActiveAccounts(orgId, industryId, setOrg.getEnterpriseAccountSetID(), false); //rdbDisplayPart.Checked 只显示有期初余额或有凭证的科目
List<EnterpriseAccountDto> accountsUnmappedList = accountDtoList.stream().filter(x -> StringUtils.isBlank(x.getStdCode())
&& x.getAcctLevel() > 1).collect(Collectors.toList());
for (EnterpriseAccountDto accountsUnmapped : accountsUnmappedList) {
String accountsUnmappedParent = accountsUnmapped.getParentCode();
List<EnterpriseAccountDto> accountsUnmappedBrothers = accountDtoList.stream().filter(x -> StringUtils.equals(x.getParentCode(),
accountsUnmappedParent) && StringUtils.isNotBlank(x.getStdCode()) && !StringUtils.equals(x.getStdCode(),
CommonConstants.EmptyStdCode) && !StringUtils.equals(x.getStdCode(), CommonConstants.DashSignSeparator))
.sorted(Comparator.comparingInt(a -> a.getStdCode().length())).collect(Collectors.toList());
EnterpriseAccountDto accountsUnmappedBrother;
if (CollectionUtils.isNotEmpty(accountsUnmappedBrothers)) {
accountsUnmappedBrother = accountsUnmappedBrothers.get(0);
List<StandardAccountDto> stdAccountss = stdAccountDtoList.stream().filter(x -> StringUtils.equals(x.getCode(),
accountsUnmappedBrother.getStdCode())).collect(Collectors.toList());
StandardAccountDto stdAccount;
if (CollectionUtils.isNotEmpty(stdAccountss)) {
stdAccount = stdAccountss.get(0);
List<StandardAccountDto> stdAccountOthers = stdAccountLeafList.stream().filter(x -> StringUtils.equals(x.getParentCode(),
stdAccount.getParentCode()) && StringUtils.equals(x.getName(), EnterpriseAccountConstant.StrOthers)).collect(Collectors.toList());//其他
if (CollectionUtils.isNotEmpty(stdAccountOthers)) {
StandardAccountDto stdAccountOther = stdAccountOthers.get(0);
if (accountsUnmapped.getIsLeaf()) {
accountMappingDao.mapStdAccountByCode(setOrg.getEnterpriseAccountSetID(), stdAccountOther.getCode(),
accountsUnmapped.getCode(), industryId, orgId, false, 0);
} else {
List<EnterpriseAccountDto> relatedAccounts = accountDtoList.stream().filter(x -> StringUtils.startsWith(x.getCode(),
accountsUnmapped.getCode())).collect(Collectors.toList());
mapAllChildrenRecursively(orgId, industryId, setOrg.getEnterpriseAccountSetID(),
accountsUnmapped.getCode(), stdAccountOther.getCode(), relatedAccounts, true);
}
}
}
}
}
//endregion
//region Step 4: Update the mapping of all parents
//Step 4: Update the mapping of all parents
accountDtoList = getAllActiveAccounts(orgId, industryId, setOrg.getEnterpriseAccountSetID(), false); //rdbDisplayPart.Checked 只显示有期初余额或有凭证的科目
List<EnterpriseAccountDto> accountParents = accountDtoList.stream().filter(x -> StringUtils.isBlank(x.getStdCode()) &&
!x.getIsLeaf()).sorted(Comparator.comparingInt(EnterpriseAccountDto::getAcctLevel).reversed()).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(accountParents)) {
List<EnterpriseAccountDto> accountParentList = accountParents;
for (EnterpriseAccountDto accountParent : accountParentList) {
List<EnterpriseAccountDto> accountParentChildList = accountDtoList.stream().filter(x -> StringUtils
.equals(x.getParentCode(), accountParent.getCode())).collect(Collectors.toList());
List<EnterpriseAccountDto> accountParentChildMappedList = accountParentChildList.stream().filter(x -> StringUtils
.isNotBlank(x.getStdCode())).collect(Collectors.toList());
boolean isAllMappedSame = true;
//All children accounts are mapped
if (accountParentChildList.size() == accountParentChildMappedList.size() && CollectionUtils.isNotEmpty(accountParentChildList)) {
String mappedStdCode = accountParentChildList.get(0).getStdCode();
for (EnterpriseAccountDto accountParentChild : accountParentChildList) {
if (!StringUtils.equalsIgnoreCase(mappedStdCode, accountParentChild.getStdCode())) {
isAllMappedSame = false;
break;
}
}
if (isAllMappedSame) {
accountMappingDao.mapStdAccountByCode(setOrg.getEnterpriseAccountSetID(), mappedStdCode, accountParent.getCode(),
industryId, orgId, false, 0);
EnterpriseAccountDto account = accountDtoList.stream().filter(x -> StringUtils.equals(x.getCode(), accountParent.getCode())).findFirst().get();
account.setStdCode(mappedStdCode);
} else {
//if all child accounts map to the same parent stdcode, save the parent stdcode.
//otherwise, same "0000" and display "-"
List<StandardAccountDto> mappedStdAccounts = stdAccountDtoList.stream().filter(x -> StringUtils.equals(x.getCode(),
mappedStdCode)).collect(Collectors.toList());
StandardAccountDto mappedStdAccount = new StandardAccountDto();
boolean isAllMappedSameParent = true;
if (CollectionUtils.isNotEmpty(mappedStdAccounts)) {
mappedStdAccount = mappedStdAccounts.get(0);
for (EnterpriseAccountDto accountParentChild : accountParentChildList) {
StandardAccountDto accountParentChildStdAccount = new StandardAccountDto();
List<StandardAccountDto> accountParentChildStdAccounts = stdAccountDtoList.stream().filter(x ->
StringUtils.equals(x.getCode(), accountParentChild.getStdCode())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(accountParentChildStdAccounts)) {
accountParentChildStdAccount = accountParentChildStdAccounts.get(0);
if (!StringUtils.equalsIgnoreCase(mappedStdAccount.getParentCode(), accountParentChildStdAccount.getParentCode())) {
isAllMappedSameParent = false;
break;
}
} else {
isAllMappedSameParent = false;
}
}
} else {
isAllMappedSameParent = false;
}
EnterpriseAccountDto account = accountDtoList.stream().filter(x -> StringUtils.equals(x.getCode(),
accountParent.getCode())).findFirst().get();
if (isAllMappedSameParent) {
accountMappingDao.mapStdAccountByCode(setOrg.getEnterpriseAccountSetID(), mappedStdAccount.getParentCode(),
accountParent.getCode(), industryId, orgId, true, 0);
} else {
//todo 全局变量
// this.MapParentAccountResult = new Dictionary<string, List<string>>();
List<String> codeList = Lists.newArrayList();
if (CollectionUtils.isNotEmpty(accountParentChildList)) {
//只需要把子科目加入其中一个就可以了
//否则将会循环多次
codeList.add(accountParentChildList.get(0).getCode());
mapAccountUpdateParent(codeList, accountSetId, industryId, orgId, true);
}
accountMappingDao.mapStdAccountByCode(setOrg.getEnterpriseAccountSetID(), CommonConstants.EmptyStdCode,
accountParent.getCode(), industryId, orgId, false, 0);
}
}
}
}
}
//endregion
OperationLogDto operationLogDto = new OperationLogDto();
operationLogDto.setOperationContent(StringUtils.EMPTY);
operationLogDto.setAction(OperationAction.New.value());
operationLogDto.setOperationObject(org.getName() + "-" + accountSet.getName());
operationLogDto.setOriginalState(StringUtils.EMPTY);
operationLogDto.setUpdateState(StringUtils.EMPTY);
operationLogDto.setModule(OperationModule.SubjectCorresponding.value());
operationLogDto.setComment(StringUtils.EMPTY);
operationLogDto.setLogType(OperateLogType.OperationLogSubject.value());
operationLogService.addOperationLog(operationLogDto);
return OperationResultDto.success();
} else {
return OperationResultDto.error(EnterpriseAccountSetOrgMsg.NoOrgSetOrOrgExist);
}
}
public List<EnterpriseAccountDto> getAllActiveAccounts(String orgID, String industryId, String accountSetId, Boolean isActive) {
List<Map<String, Object>> list = enterpriseAccountDao.selectAccounts(industryId, accountSetId, orgID, EnterpriseAccountConstant.InvalidId,
EnterpriseAccountConstant.InvalidId, EnterpriseAccountConstant.InvalidId, isActive);
return list.stream().map(x -> {
EnterpriseAccountDto dto = new EnterpriseAccountDto();
dto.setCode(MapUtils.getString(x, "Code"));
dto.setName(MapUtils.getString(x, "Name"));
dto.setFullName(MapUtils.getString(x, "FullName"));
dto.setParentCode(MapUtils.getString(x, "ParentCode"));
dto.setAcctLevel(MapUtils.getInteger(x, "AcctLevel"));
dto.setStdCode(MapUtils.getString(x, "StdCode"));
dto.setIsLeaf(MapUtils.getShort(x, "IsLeaf") == EnterpriseAccountConstant.I_Yes);
return dto;
}).collect(Collectors.toList());
}
private Boolean mapAllChildrenRecursively(String orgID, String industryID, String accountSetId, String accountCode,
String stdAccountCode, List<EnterpriseAccountDto> accounts, Boolean exceptionFlag) {
List<String> enterpriseCodeList = Lists.newArrayList();
boolean allChildrenMapped = true;
List<EnterpriseAccountDto> children = accounts.stream().filter(x -> StringUtils.equals(x.getParentCode(), accountCode))
.collect(Collectors.toList());
for (EnterpriseAccountDto child : children) {
if (child.getIsLeaf()) {
if (StringUtils.isBlank(child.getStdCode())) {
accountMappingDao.mapStdAccountByCode(accountSetId, stdAccountCode, child.getCode(), industryID, orgID, false, 0);
} else {
if (!StringUtils.equals(child.getStdCode(), stdAccountCode)) {
allChildrenMapped = false;
if (exceptionFlag) {
//只需要添加一次即可
enterpriseCodeList.add(child.getCode());
}
}
}
} else {
allChildrenMapped = mapAllChildrenRecursively(orgID, industryID, accountSetId, child.getCode(),
stdAccountCode, accounts, false);
}
}
//子科目全部对应时,父科目显示对应:1.子科目对应一致-子科目对应的标准科目;2.子科目对应不一致-0000
if (allChildrenMapped) {
accountMappingDao.mapStdAccountByCode(accountSetId, stdAccountCode, accountCode, industryID, orgID, false, 0);
} else {
accountMappingDao.mapStdAccountByCode(accountSetId, CommonConstants.EmptyStdCode, accountCode, industryID, orgID, false, 0);
}
if (exceptionFlag) {
//todo
// this.mapParentAccountResult = new Dictionary<string, List<string>>();
mapAccountUpdateParent(enterpriseCodeList, accountSetId, industryID, orgID, false);
}
//Update the mapping of parent account
//var row = grdTarget.Rows.OfType<DataGridViewRow>()
// .Where(r => r.Cells["AccountCode"].Value.ToString().Trim() == accountCode).FirstOrDefault();
//if (row != null)
//{
// UpdateParentAccounts(row.Index, accountCode, false);
//}
return allChildrenMapped;
}
private void applyPriorityKeywords(List<EnterpriseAccountDto> allEpAccountDtoList, List<AccountMappingManual> allManualList,
String accountSetID, String orgID, String industryID){
List<AccountMappingManualDto> resultList;
//1 账套机构行业都一样 (本身优先级别最高)
List<AccountMappingManual> tmpManualList = allManualList.stream().filter(x -> StringUtils.equals(x.getEnterpriseAccountSetID(), accountSetID)
&& StringUtils.equals(x.getOrganizationID(), orgID) && StringUtils.equals(x.getIndustryID(), industryID)).collect(Collectors.toList());
resultList = wrapPriority(tmpManualList, 1);
//2 账套行业一样,机构不一样
tmpManualList = allManualList.stream().filter(x -> StringUtils.equals(x.getEnterpriseAccountSetID(), accountSetID)
&& !StringUtils.equals(x.getOrganizationID(), orgID) && StringUtils.equals(x.getIndustryID(), industryID)).collect(Collectors.toList());
resultList = getManualMappingResult(resultList, wrapPriority(tmpManualList, 2));
//3 账套不一样,机构和行业都一样
tmpManualList = allManualList.stream().filter(x -> !StringUtils.equals(x.getEnterpriseAccountSetID(), accountSetID)
&& StringUtils.equals(x.getOrganizationID(), orgID) && StringUtils.equals(x.getIndustryID(), industryID)).collect(Collectors.toList());
resultList = getManualMappingResult(resultList, wrapPriority(tmpManualList, 3));
//4 账套机构一样,行业不一样
tmpManualList = allManualList.stream().filter(x -> StringUtils.equals(x.getEnterpriseAccountSetID(), accountSetID)
&& StringUtils.equals(x.getOrganizationID(), orgID) && !StringUtils.equals(x.getIndustryID(), industryID)).collect(Collectors.toList());
resultList = getManualMappingResult(resultList, wrapPriority(tmpManualList, 4));
//5 机构一样,账套行业不一样
tmpManualList = allManualList.stream().filter(x -> !StringUtils.equals(x.getEnterpriseAccountSetID(), accountSetID)
&& StringUtils.equals(x.getOrganizationID(), orgID) && !StringUtils.equals(x.getIndustryID(), industryID)).collect(Collectors.toList());
resultList = getManualMappingResult(resultList, wrapPriority(tmpManualList, 5));
//6 账套机构不一样,行业一样
tmpManualList = allManualList.stream().filter(x -> !StringUtils.equals(x.getEnterpriseAccountSetID(), accountSetID)
&& !StringUtils.equals(x.getOrganizationID(), orgID) && StringUtils.equals(x.getIndustryID(), industryID)).collect(Collectors.toList());
resultList = getManualMappingResult(resultList, wrapPriority(tmpManualList, 6));
//7 账套一样,机构行业都不一样
tmpManualList = allManualList.stream().filter(x -> StringUtils.equals(x.getEnterpriseAccountSetID(), accountSetID)
&& !StringUtils.equals(x.getOrganizationID(), orgID) && !StringUtils.equals(x.getIndustryID(), industryID)).collect(Collectors.toList());
resultList = getManualMappingResult(resultList, wrapPriority(tmpManualList, 7));
//8 账套机构行业都不一样
tmpManualList = allManualList.stream().filter(x -> !StringUtils.equals(x.getEnterpriseAccountSetID(), accountSetID)
&& !StringUtils.equals(x.getOrganizationID(), orgID) && !StringUtils.equals(x.getIndustryID(), industryID)).collect(Collectors.toList());
resultList = getManualMappingResult(resultList, wrapPriority(tmpManualList, 8));
List<AccountMapping> mappingList = Lists.newArrayList();
resultList.stream().forEach(x->{
allEpAccountDtoList.stream().filter(EnterpriseAccountDto::getIsLeaf).forEach(y->{
if (StringUtils.equals(x.getFullName(),y.getFullName())){
AccountMapping tmp = new AccountMapping();
tmp.setID(CommonUtils.getUUID());
tmp.setEnterpriseAccountCode(y.getCode());
tmp.setStandardAccountCode(x.getStandardCode());
tmp.setOrganizationID(orgID);
tmp.setIndustryID(industryID);
mappingList.add(tmp);
}
});
});
//先删除
List<AccountMapping> filterMappingResult = mappingList.stream().filter(x -> StringUtils.isNotBlank(x.getEnterpriseAccountCode()))
.collect(Collectors.toList());
List<String> filterEACodeList = filterMappingResult.stream().map(AccountMapping::getEnterpriseAccountCode).collect(Collectors.toList());
accountMappingDao.delByEpAccountCodeList(filterEACodeList);
filterMappingResult.stream().forEach(x -> accountMappingMapper.insertSelective(x));
}
private List<AccountMappingManualDto> getManualMappingResult(List<AccountMappingManualDto> priorityList,
List<AccountMappingManualDto> lowerPriorityList) {
List<AccountMappingManualDto> originalMapList = new ArrayList<>(priorityList);
List<String> list1 = priorityList.stream().map(AccountMappingManualDto::getFullName).collect(Collectors.toList());
List<String> list2 = lowerPriorityList.stream().map(AccountMappingManualDto::getFullName).collect(Collectors.toList());
List<String> intersectedList = list1.stream().filter(list2::contains).collect(Collectors.toList());
List<AccountMappingManualDto> addedList = lowerPriorityList.stream().filter(x -> list2.stream()
.filter(y -> !intersectedList.contains(y)).collect(Collectors.toList()).contains(x.getFullName()))
.collect(Collectors.toList());
originalMapList.addAll(addedList);
return originalMapList;
}
private List<AccountMappingManualDto> wrapPriority(List<AccountMappingManual> manualList, int priority) {
return manualList.stream().collect(Collectors.groupingBy(AccountMappingManual::getFullName))
.entrySet().stream().map(x -> {
AccountMappingManualDto dto = new AccountMappingManualDto();
AccountMappingManual manual = x.getValue().stream().sorted((m1, m2) -> m2.getUpdateTime()
.compareTo(m1.getUpdateTime())).findFirst().get();
CommonUtils.copyProperties(manual, dto);
dto.setPriority(priority);
return dto;
}).collect(Collectors.toList());
}
private void formatEpAccountDtoTree(List<EnterpriseAccountDto> rootList, List<EnterpriseAccountDto> allList,
List<EnterpriseAccountDto> result) {
if (CollectionUtils.isEmpty(rootList)) {
......
......@@ -25,6 +25,8 @@ import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.format.DateTimeFormat;
......@@ -95,6 +97,8 @@ import pwc.taxtech.atms.dto.dimension.DimensionValueDisplayDto;
import pwc.taxtech.atms.dto.dimension.DimensionValueJoinDimensionDto;
import pwc.taxtech.atms.dto.dimension.OrgDashboardParams;
import pwc.taxtech.atms.dto.epaccount.EnterpriseAccountSetOrgDto;
import pwc.taxtech.atms.dto.navtree.DevTreeDto;
import pwc.taxtech.atms.dto.navtree.IvhTreeDto;
import pwc.taxtech.atms.dto.navtree.NavTreeDto;
import pwc.taxtech.atms.dto.organization.OrgBasicDto;
import pwc.taxtech.atms.dto.organization.OrgCountDto;
......@@ -2848,6 +2852,103 @@ public class OrganizationServiceImpl implements OrganizationService {
return getOrgGeneralInfo(orgID);
}
@Override
public List<DevTreeDto> getOrgIvhTreeList(Integer useType, String orgSetId) {
//todo
List<DevTreeDto> result = Lists.newArrayList();
List<IvhTreeDto> orgDtoList = Lists.newArrayList();
List<Organization> orgList;
OrganizationExample orgExample = new OrganizationExample();
if (useType < 2)
{
orgList = organizationMapper.selectByExample(orgExample);
}
else
{
EnterpriseAccountSetOrgExample tmpExample = new EnterpriseAccountSetOrgExample();
EnterpriseAccountSetOrgExample.Criteria criteria = tmpExample.createCriteria();
criteria.andEnterpriseAccountSetIDEqualTo(orgSetId);
List<EnterpriseAccountSetOrg> enAccountSetOrgList = enterpriseAccountSetOrgMapper.selectByExample(tmpExample);
if (CollectionUtils.isNotEmpty(enAccountSetOrgList)){
List<String> orgIdList = enAccountSetOrgList.stream().map(EnterpriseAccountSetOrg::getOrganizationID)
.collect(toList());
OrganizationExample.Criteria orgCriteria = orgExample.createCriteria();
orgCriteria.andIDIn(orgIdList);
orgList = organizationMapper.selectByExample(orgExample);
}else {
orgList = Lists.newArrayList();
}
}
if (CollectionUtils.isNotEmpty(orgList)) {
//find rootOrg
List<Organization> rootOrgList;
if (useType == 1) {
rootOrgList = orgList.stream().filter(x -> StringUtils.isBlank(x.getParentID())).collect(toList());
} else {
rootOrgList = orgList.stream().filter(x -> StringUtils.isBlank(x.getParentID()) && x.getIsActive())
.collect(toList());
}
List<ServiceType> serviceList = Lists.newArrayList();
for (Organization org: rootOrgList){
IvhTreeDto root = new IvhTreeDto();
root.setChildren(Lists.newArrayList());
root.setLabel(org.getName());
root.setValue(org);
orgDtoList.add(generateIvhTreeDto(org,orgList,serviceList,useType));
}
}
return orgDtoList.stream().map(this::devTreeDtoMapper).collect(toList());
}
private DevTreeDto devTreeDtoMapper(IvhTreeDto ivhTreeDto) {
DevTreeDto dto = new DevTreeDto();
dto.setText(ivhTreeDto.getLabel());
List<IvhTreeDto> childList = ivhTreeDto.getChildren();
if (CollectionUtils.isNotEmpty(childList)) {
dto.setItems(Lists.newArrayList());
for (IvhTreeDto ivh : childList) {
dto.getItems().add(devTreeDtoMapper(ivh));
}
}
dto.setId(ivhTreeDto.getId());
dto.setData(ivhTreeDto);
return dto;
}
private IvhTreeDto generateIvhTreeDto(Organization parentOrg, List<Organization> orgList,
List<ServiceType> serviceList, int useType) {
IvhTreeDto result = new IvhTreeDto();
OrganizationDto parentOrgDto = new OrganizationDto();
CommonUtils.copyProperties(parentOrg, parentOrgDto);
if (null != parentOrg && StringUtils.isNotBlank(parentOrg.getID())) {
parentOrgDto.setParentName(orgList.stream().filter(x -> StringUtils.equals(x.getID(), parentOrg.getParentID()))
.findFirst().map(x -> x.getName()).orElse(StringUtils.EMPTY));
}
List<Organization> subOrgList;
if (useType == 1) {
subOrgList = orgList.stream().filter(x -> StringUtils.equals(x.getParentID(), parentOrg.getID())).collect(toList());
} else {
subOrgList = orgList.stream().filter(x -> StringUtils.equals(x.getParentID(), parentOrg.getID()) && x.getIsActive())
.collect(toList());
}
parentOrgDto.setSubOrgs(Lists.newArrayList());
List<IvhTreeDto> children = Lists.newArrayList();
//create and add subtrees to the current node
for (Organization subOrg : subOrgList) {
children.add(generateIvhTreeDto(subOrg, orgList, serviceList, useType));
}
result.setLabel(parentOrgDto.getName());
result.setValue(parentOrgDto);
result.setChildren(children);
return result;
}
private OrgGeneralInfoDto getOrgGeneralInfo(String orgID) {
List<OrgGeneralInfoMiddleDto> query = organizationMapper.selectJoinToOrgGeneralInfo();
List<OrgGeneralInfoMiddleDto> filter = query.stream().filter(x -> Strings.equals(x.getID(), orgID))
......
......@@ -89,6 +89,8 @@ public class StdAccountServiceImpl extends BaseService implements StdAccountServ
StdAccountFancyTreeDto dto = new StdAccountFancyTreeDto();
dto.setExpanded(false);
dto.setHasChildren(false);
return CommonUtils.copyProperties(account, dto);
CommonUtils.copyProperties(account, dto);
dto.setTitle(dto.getCode() + "-" + (StringUtils.equals(dto.getDirection(), "1") ? "借" : "贷") + "-" + dto.getName());
return dto;
}
}
......@@ -758,7 +758,7 @@ public class UserServiceImpl extends AbstractService implements UserService {
userRole.setServiceTypeID(r != null ? r.getServiceTypeID() : "");
userRoleList.add(userRole);
logger.debug("Start to insert user role [ {} ] with roleID [ {} ]", userRole.getID(), role);
userRoleMapper.insert(userRole);
userRoleMapper.insertSelective(userRole);
}
// 添加所属机构的访问权限
UserOrganization userOrganization = findUserOrganizationByUserIDAndOrganizationID(user.getID(),
......
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- DruidDataSource数据源配置) -->
<!-- See: https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_DruidDataSource%E5%8F%82%E8%80%83%E9%85%8D%E7%BD%AE -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
......@@ -42,4 +44,23 @@
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="stat" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
</bean>
<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
<property name="patterns">
<list>
<value>pwc.taxtech.atms.dao.*</value>
</list>
</property>
</bean>
<aop:config>
<aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut"/>
</aop:config>
</beans>
\ 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