Commit 2c0845dd authored by frank.xa.zhang's avatar frank.xa.zhang

fixed org -- frank

parent 995a3328
package pwc.taxtech.atms.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pwc.taxtech.atms.dto.ApiResultDto;
import pwc.taxtech.atms.dto.IdModel;
import pwc.taxtech.atms.dto.OrganizationStructureDto;
import pwc.taxtech.atms.dto.OrganizationStructureInputDto;
import pwc.taxtech.atms.service.impl.OrganizationStructureServiceImpl;
import java.util.List;
@RestController
@RequestMapping("/api/v1/organizationstructure")
public class OrganizationStructureController {
private static Logger logger = LoggerFactory.getLogger(OrganizationStructureController.class);
@Autowired
private OrganizationStructureServiceImpl organizationStructureService;
// @ApiOperation(value = "主数据机构层级查询")
@RequestMapping(value = "/getlist", method = RequestMethod.GET)
public @ResponseBody
List<OrganizationStructureDto> getOrganizationStructures() {
logger.debug("OrganizationStructureController /getlist");
return organizationStructureService.getOrganizationStructures();
}
// @ApiOperation(value = "主数据机构层级增加")
// @ApiImplicitParam(name = "organizationStructureDtoList", value = "organizationStructureDto List", required = true, dataType = "List<OrganizationStructureDto>")
@RequestMapping(value = "/add", method = RequestMethod.POST)
public ApiResultDto addOrganizationStructures(@RequestBody List<OrganizationStructureInputDto> organizationStructureDtoList) {
logger.debug("OrganizationStructureController /add");
return organizationStructureService.addOrganizationStructures(organizationStructureDtoList);
}
// @ApiOperation(value = "主数据机构层级删除")
// @ApiImplicitParam(name = "idModel", value = "idModel", required = true, dataType = "IdModel")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public @ResponseBody
Integer deleteOrganizationStructure(@RequestBody IdModel idModel) {
logger.debug("OrganizationStructureController /delete");
return organizationStructureService.deleteOrganizationStructure(idModel);
}
// @ApiOperation(value = "主数据机构层级修改")
// @ApiImplicitParam(name = "organizationStructureDtoList", value = "organizationStructureDto List", required = true, dataType = "List<OrganizationStructureDto>")
@RequestMapping(method = RequestMethod.PUT)
public @ResponseBody
ApiResultDto updateOrganizationStructure(@RequestBody List<OrganizationStructureInputDto> organizationStructureDtoList) {
logger.debug("OrganizationStructureController update");
return organizationStructureService.updateOrganizationStructures(organizationStructureDtoList);
}
}
......@@ -2021,7 +2021,7 @@ public class OrganizationServiceImpl extends BaseService{
}
// 添加账套
// if(!orgDto.getOversea()){
if(!orgDto.getOversea()){
// for (EnterpriseAccountSetOrgDto p : orgDto.getEnterpriseAccountSetOrgList()) {
// EnterpriseAccountSetOrg enterpriseAccountSetOrg = new EnterpriseAccountSetOrg();
// enterpriseAccountSetOrg.setId(CommonUtils.getUUID());
......@@ -2067,19 +2067,19 @@ public class OrganizationServiceImpl extends BaseService{
// newRule.setUpdateTime(now);
// taxPayerReportRuleMapper.insert(newRule);
// }
// for (OrganizationServiceTemplateGroupDto p : orgDto.getOrganizationServiceTemplateGroupList()) {
// OrganizationServiceTemplateGroup orgServiceTempGroup = new OrganizationServiceTemplateGroup();
// orgServiceTempGroup.setId(distributedIdService.nextId());
// orgServiceTempGroup.setOrganizationId(orgDto.getId());
// orgServiceTempGroup.setServiceTypeId(p.getServiceTypeId());
// orgServiceTempGroup.setTemplateGroupId(p.getTemplateGroupId());
// organizationServiceTemplateGroupMapper.insert(orgServiceTempGroup);
// }
//
// // CopyModelTree(orgDto);//__restoreroy__
//
// addOrgSelfDimensionList(orgDto);
// }
for (OrganizationServiceTemplateGroupDto p : orgDto.getOrganizationServiceTemplateGroupList()) {
OrganizationServiceTemplateGroup orgServiceTempGroup = new OrganizationServiceTemplateGroup();
orgServiceTempGroup.setId(distributedIdService.nextId());
orgServiceTempGroup.setOrganizationId(orgDto.getId());
orgServiceTempGroup.setServiceTypeId(p.getServiceTypeId());
orgServiceTempGroup.setTemplateGroupId(p.getTemplateGroupId());
organizationServiceTemplateGroupMapper.insert(orgServiceTempGroup);
}
// CopyModelTree(orgDto);//__restoreroy__
addOrgSelfDimensionList(orgDto);
}
// C#中的内部类CommonLogParams 在JAVA中已经被合并到OperationLogDto中
UpdateLogParams tempCommonLogParms = new UpdateLogParams();
tempCommonLogParms.setOperationModule(Organization.value());
......@@ -2434,13 +2434,13 @@ public class OrganizationServiceImpl extends BaseService{
//
// EnterpriseAccountSetOrgExample e2 = new EnterpriseAccountSetOrgExample();
for (EnterpriseAccountSetOrgDto p : orgDto.getEnterpriseAccountSetOrgList()) {
p.setEffectiveDate(Strings.isBlank(p.getEffectiveDateStr()) ? p.getEffectiveDate()
: DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(p.getEffectiveDateStr() + "-01")
.toDate());
p.setExpiredDate(Strings.isBlank(p.getExpiredDateStr()) ? p.getExpiredDate()
: DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(p.getExpiredDateStr() + "-01")
.plusMonths(1).minusDays(1).toDate());
// for (EnterpriseAccountSetOrgDto p : orgDto.getEnterpriseAccountSetOrgList()) {
// p.setEffectiveDate(Strings.isBlank(p.getEffectiveDateStr()) ? p.getEffectiveDate()
// : DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(p.getEffectiveDateStr() + "-01")
// .toDate());
// p.setExpiredDate(Strings.isBlank(p.getExpiredDateStr()) ? p.getExpiredDate()
// : DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(p.getExpiredDateStr() + "-01")
// .plusMonths(1).minusDays(1).toDate());
// if (enterpriseAccountSetOrgList != null
// && enterpriseAccountSetOrgList.stream().anyMatch(t -> Strings.equals(t.getId(), p.getId()))) {
// EnterpriseAccountSetOrg tempDto = enterpriseAccountSetOrgList.stream()
......@@ -2478,18 +2478,18 @@ public class OrganizationServiceImpl extends BaseService{
// .forEach(delSet -> enterpriseAccountSetOrgMapper.deleteByPrimaryKey(delSet.getId()));
// }
OrganizationServiceTemplateGroupExample oSTGExample = new OrganizationServiceTemplateGroupExample();
pwc.taxtech.atms.entity.OrganizationServiceTemplateGroupExample.Criteria oSTGCriteria = oSTGExample
.createCriteria();
if (orgDto.getId() != null) {
oSTGCriteria.andOrganizationIdEqualTo(orgDto.getId());
} else {
oSTGCriteria.andOrganizationIdIsNull();
}
List<OrganizationServiceTemplateGroup> currentOrganizationServiceTemplateGroupList = organizationServiceTemplateGroupMapper
.selectByExample(oSTGExample);
List<OrganizationServiceTemplateGroup> updateOrganizationServiceTemplateGroupList = new ArrayList<>();
// OrganizationServiceTemplateGroupExample oSTGExample = new OrganizationServiceTemplateGroupExample();
// pwc.taxtech.atms.entity.OrganizationServiceTemplateGroupExample.Criteria oSTGCriteria = oSTGExample
// .createCriteria();
// if (orgDto.getId() != null) {
// oSTGCriteria.andOrganizationIdEqualTo(orgDto.getId());
// } else {
// oSTGCriteria.andOrganizationIdIsNull();
// }
// List<OrganizationServiceTemplateGroup> currentOrganizationServiceTemplateGroupList = organizationServiceTemplateGroupMapper
// .selectByExample(oSTGExample);
//
// List<OrganizationServiceTemplateGroup> updateOrganizationServiceTemplateGroupList = new ArrayList<>();
// TaxPayerReportRuleExample taxExample = new TaxPayerReportRuleExample();
// taxExample.or().andIsDefaultEqualTo(true);
// Assert.notNull(orgDto.getId(), "orgDto id null exception on updateOrg");
......@@ -2499,16 +2499,16 @@ public class OrganizationServiceImpl extends BaseService{
// TaxPayerReportRule activeRule = reportRules.stream()
// .filter(t -> t.getOrganizationId() == null ? false : t.getOrganizationId().contains(orgDto.getId()))
// .findFirst().orElse(null);
// C#中在此处定义的defaultRule在下文中未被引用,JAVA中将其删除
// 更新机构服务
currentOrganizationServiceTemplateGroupList.stream()
.forEach(tg -> organizationServiceTemplateGroupMapper.deleteByPrimaryKey(tg.getId()));
// For VAT, update Rule Engine tables instead of
OrganizationServiceTemplateGroupDto vatSetting = orgDto.getOrganizationServiceTemplateGroupList().stream()
.filter(t -> Strings.equals(t.getServiceTypeId(), ServiceTypeEnum.VAT.value().toString()))
.findFirst().orElse(null);
// // C#中在此处定义的defaultRule在下文中未被引用,JAVA中将其删除
//
// // 更新机构服务
// currentOrganizationServiceTemplateGroupList.stream()
// .forEach(tg -> organizationServiceTemplateGroupMapper.deleteByPrimaryKey(tg.getId()));
//
// // For VAT, update Rule Engine tables instead of
// OrganizationServiceTemplateGroupDto vatSetting = orgDto.getOrganizationServiceTemplateGroupList().stream()
// .filter(t -> Strings.equals(t.getServiceTypeId(), ServiceTypeEnum.VAT.value().toString()))
// .findFirst().orElse(null);
// if (vatSetting != null) {
// TemplateGroup templateGrp = vatSetting.getTemplateGroupId() != null
// ? templateGroupMapper.selectByPrimaryKey(vatSetting.getTemplateGroupId())
......@@ -2567,16 +2567,16 @@ public class OrganizationServiceImpl extends BaseService{
// }
// } else if (activeRule != null) { // If no setting, remove non-default rule
// taxPayerReportRuleMapper.deleteByPrimaryKey(activeRule.getId());
}
// for (OrganizationServiceTemplateGroupDto p : orgDto.getOrganizationServiceTemplateGroupList()) {
// OrganizationServiceTemplateGroup temp = new OrganizationServiceTemplateGroup();
// temp.setId(distributedIdService.nextId());
// temp.setOrganizationId(orgDto.getId());
// temp.setServiceTypeId(p.getServiceTypeId());
// temp.setTemplateGroupId(p.getTemplateGroupId());
//// updateOrganizationServiceTemplateGroupList.add(temp);
// organizationServiceTemplateGroupMapper.insertSelective(temp);
// }
for (OrganizationServiceTemplateGroupDto p : orgDto.getOrganizationServiceTemplateGroupList()) {
OrganizationServiceTemplateGroup temp = new OrganizationServiceTemplateGroup();
temp.setId(distributedIdService.nextId());
temp.setOrganizationId(orgDto.getId());
temp.setServiceTypeId(p.getServiceTypeId());
temp.setTemplateGroupId(p.getTemplateGroupId());
// updateOrganizationServiceTemplateGroupList.add(temp);
organizationServiceTemplateGroupMapper.insertSelective(temp);
}
// 更新自定义属性
// C#中的内部类CommonLogParams 在JAVA中替换成UpdateLogParams中
......@@ -2670,8 +2670,8 @@ public class OrganizationServiceImpl extends BaseService{
List<UpdateLogParams> addLogList = new ArrayList<>();
// List<TemplateGroup> queryTemplate = templateGroupMapper.selectByExample(null);
// List<ServiceType> queryService = serviceTypeMapper.selectByExample(null);
//
List<ServiceType> queryService = serviceTypeMapper.selectByExample(null);
// for (OrganizationServiceTemplateGroup item : addList) {
// ServiceType st1 = queryService.stream().filter(sa -> Strings.equals(sa.getId(), item.getServiceTypeId()))
// .findFirst().orElse(null);
......
package pwc.taxtech.atms.service.impl;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import pwc.taxtech.atms.common.*;
import pwc.taxtech.atms.common.message.ErrorMessageCN;
import pwc.taxtech.atms.dao.OrganizationStructureMapper;
import pwc.taxtech.atms.dto.*;
import pwc.taxtech.atms.entity.OrganizationStructure;
import pwc.taxtech.atms.entity.OrganizationStructureExample;
import pwc.taxtech.atms.exception.ApplicationException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class OrganizationStructureServiceImpl {
private static final Logger logger = LoggerFactory.getLogger(OrganizationStructureServiceImpl.class);
@Autowired
private OrganizationStructureMapper organizationStructureMapper;
@Autowired
private OperationLogServiceImpl operationLogService;
@Autowired
private OrganizationServiceImpl organizationService;
@Autowired
private AuthUserHelper authUserHelper;
public List<OrganizationStructureDto> getOrganizationStructures() {
logger.debug("OrganizationStructureService getOrganizationStructures");
OrganizationStructureExample organizationStructureExample = new OrganizationStructureExample();
organizationStructureExample.setOrderByClause("name ASC");
List<OrganizationStructure> organizationStructureList = organizationStructureMapper
.selectByExample(organizationStructureExample);
return rotateOrganizationStructureList(organizationStructureList);
}
public ApiResultDto addOrganizationStructures(List<OrganizationStructureInputDto> organizationStructureDtoList) {
logger.debug("OrganizationStructureService addOrganizationStructure");
logger.debug("organization structure to add: {}", JSON.toJSONString(organizationStructureDtoList, true));
ApiResultDto res = ApiResultDto.success();
if (organizationStructureDtoList.isEmpty()) {
return ApiResultDto.fail(CommonConstants.JSONNULLOBJECT);
}
for (OrganizationStructureInputDto organizationStructureDto : organizationStructureDtoList) {
res = addOrganizationStructure(organizationStructureDto);
if(ApiResultDto.FAILED == res.getCode()) break;
}
return res;
}
public ApiResultDto addOrganizationStructure(OrganizationStructureInputDto organizationStructureDto) {
OrganizationStructureExample example = new OrganizationStructureExample();
example.createCriteria().andNameEqualTo(organizationStructureDto.getName());
if(organizationStructureMapper.countByExample(example)>0){
return ApiResultDto.fail(ErrorMessageCN.StrctureRepeat);
}
OrganizationStructure organizationStructure = rotateOrganizationStructureDto(organizationStructureDto);
organizationStructure.setId(CommonUtils.getUUID());
organizationStructure.setCreateTime(new Date());
organizationStructure.setUpdateTime(new Date());
organizationStructureMapper.insert(organizationStructure);
// operation log
OperationLogDto operationLogDto = new OperationLogDto();
makeUpOperationLogDto(operationLogDto);
operationLogDto.setOperationObject(organizationStructureDto.getName());
operationLogDto.setAction(OperationAction.New.value());
operationLogService.addOperationLog(operationLogDto);
return ApiResultDto.success();
}
private void makeUpOperationLogDto(OperationLogDto operationLogDto) {
operationLogDto.setModule(OperationModule.BasicDataOrganizationStructure.value());
operationLogDto.setLogType(OperateLogType.OperationLogBasicData.value());
}
public Integer deleteOrganizationStructure(IdModel idModel) {
logger.debug("OrganizationStructureService deleteOrganizationStructure");
logger.debug("organization structure to delete, id: {}", JSON.toJSONString(idModel, true));
if (idModel == null || idModel.getId() == null) {
throw new ApplicationException(CommonConstants.JSONNULLOBJECT);
}
OrganizationStructure organizationStructure = organizationStructureMapper.selectByPrimaryKey(idModel.getId());
if (organizationStructure == null) {
throw new ApplicationException("can't find OrganizationStructure to delete, id: " + idModel.getId());
}
int result = organizationStructureMapper.deleteByPrimaryKey(idModel.getId());
// operation log
OperationLogDto operationLogDto = new OperationLogDto();
makeUpOperationLogDto(operationLogDto);
operationLogDto.setAction(OperationAction.Delete.value());
operationLogService.addOperationLog(operationLogDto);
return result;
}
public ApiResultDto updateOrganizationStructures(List<OrganizationStructureInputDto> organizationStructureDtoList) {
logger.debug("OrganizationStructureService updateOrganizationStructures");
logger.debug("organization structure to update: {}", JSON.toJSONString(organizationStructureDtoList, true));
if (organizationStructureDtoList.isEmpty()) {
return ApiResultDto.fail(CommonConstants.JSONNULLOBJECT);
}
for (OrganizationStructureInputDto organizationStructureDto : organizationStructureDtoList) {
//isActive changed or not
boolean isStatusChangeOperation = false;
if (organizationStructureDto == null || !StringUtils.hasText(organizationStructureDto.getId())) {
return ApiResultDto.fail("primary key can't be null");
}
// current OrganizationStructure
OrganizationStructure organizationStructure = organizationStructureMapper
.selectByPrimaryKey(organizationStructureDto.getId());
if (organizationStructure == null) {
return ApiResultDto.fail("can't find organizationStructure, id: " + organizationStructureDto.getId());
}
boolean notChange = organizationStructureDto.getIsActive().equals(organizationStructure.getIsActive())&&
organizationStructure.getName().equals(organizationStructureDto.getName());
OrganizationStructureExample example = new OrganizationStructureExample();
example.createCriteria().andIdNotEqualTo(organizationStructureDto.getId()).andNameEqualTo(organizationStructureDto.getName());
boolean nameExist = organizationStructureMapper.countByExample(example) > 0;
if (notChange) {
return ApiResultDto.fail(ErrorMessageCN.OrgStructureFailed);
}
if (nameExist) {
return ApiResultDto.fail(ErrorMessageCN.OrgStructureNameExist);
}
//copy current OrganizationStructure as tmp
OrganizationStructure originOrganizationStructure = new OrganizationStructure();
CommonUtils.copyProperties(organizationStructure, originOrganizationStructure);
if (!organizationStructureDto.getIsActive().equals(organizationStructure.getIsActive()) ||
!org.apache.commons.lang3.StringUtils.equals( organizationStructureDto.getName(),organizationStructure.getName())) {
isStatusChangeOperation = true;
organizationStructure.setIsActive(organizationStructureDto.getIsActive());
organizationStructure.setName(organizationStructureDto.getName());
// 参照atms取消层级若有机构不能停用的限制
/*if (!organizationStructureDto.getIsActive()&&
organizationService.isOrganizationStructureExists(organizationStructureDto.getId())) {
// continue;
// return false;
throw new ApplicationException("the organization must not contain sub-organization!");
}*/
}
organizationStructure.setUpdateTime(new Date());
organizationStructureMapper.updateByPrimaryKey(organizationStructure);
//add operation log
if (isStatusChangeOperation) {
UpdateLogParams updateLogParams = new UpdateLogParams();
updateLogParams.setOperationObject(originOrganizationStructure.getName());
updateLogParams.setOriginalState(originOrganizationStructure);
updateLogParams.setUpdateState(organizationStructure);
updateLogParams.setOperationUser(authUserHelper.getCurrentAuditor().get());
updateLogParams.setOperationModule(OperationModule.BasicDataOrganizationStructure.value());
updateLogParams.setOperationAction(OperationAction.Update.value());
updateLogParams.setOperateLogType(OperateLogType.OperationLogBasicData.value());
//check how many properties being updated and the log number should be same
operationLogService.updateDataAddLog(updateLogParams);
}
}
return ApiResultDto.success();
}
private OrganizationStructure rotateOrganizationStructureDto(OrganizationStructureInputDto organizationStructureDto) {
OrganizationStructure organizationStructure = new OrganizationStructure();
organizationStructure.setId(organizationStructureDto.getId());
organizationStructure.setName(organizationStructureDto.getName());
organizationStructure.setIsActive(organizationStructureDto.getIsActive());
return organizationStructure;
}
private List<OrganizationStructureDto> rotateOrganizationStructureList(
List<OrganizationStructure> organizationStructureList) {
List<OrganizationStructureDto> organizationStructureDtoList = new ArrayList<>();
if (organizationStructureList != null && !organizationStructureList.isEmpty()) {
for (OrganizationStructure organizationStructure : organizationStructureList) {
organizationStructureDtoList.add(rotateOrganizationStructure(organizationStructure));
}
}
return organizationStructureDtoList;
}
private OrganizationStructureDto rotateOrganizationStructure(OrganizationStructure organizationStructure) {
OrganizationStructureDto organizationStructureDto = new OrganizationStructureDto();
organizationStructureDto.setId(organizationStructure.getId());
organizationStructureDto.setIsActive(organizationStructure.getIsActive());
organizationStructureDto.setName(organizationStructure.getName());
return organizationStructureDto;
}
}
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