Commit 7988ef72 authored by neo's avatar neo

[DEV] translate listAllProjectList api logic

parent 18a0e9cf
......@@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
......@@ -20,7 +21,9 @@ import pwc.taxtech.atms.service.ProjectService;
@RequestMapping("/api/v1/project")
public class ProjectController {
/** @see PwC.Tax.Tech.Atms.WebApi\Controllers\ProjectController.cs */
/**
* @see PwC.Tax.Tech.Atms.WebApi\Controllers\ProjectController.cs
*/
private static Logger logger = LoggerFactory.getLogger(ProjectController.class);
......@@ -29,23 +32,32 @@ public class ProjectController {
@ApiOperation(value = "listService", notes = "Get service list")
@RequestMapping(value = "listService", method = RequestMethod.GET)
public @ResponseBody List<ServiceTypeDto> getServiceList() {
public @ResponseBody
List<ServiceTypeDto> getServiceList() {
logger.info("/api/v1/project/listService");
return projectService.getServiceList();
}
@ApiOperation(value = "getProjectClientList", notes = "Get project Client list")
@RequestMapping(value = "getProjectClientList", method = RequestMethod.GET)
public @ResponseBody List<ProjectClientDto> getProjectClientList() {
public @ResponseBody
List<ProjectClientDto> getProjectClientList() {
logger.info("/api/v1/project/getProjectClientList");
return projectService.getProjectClientList();
}
@ApiOperation(value = "getProject" ,notes = "Get Project")
@ApiOperation(value = "getProject", notes = "Get Project")
@RequestMapping(value = "getProject", method = RequestMethod.GET)
public @ResponseBody List<ProjectDisplayDto> GetProjectByID(String projectID)
{
public @ResponseBody
List<ProjectDisplayDto> GetProjectByID(String projectID) {
return projectService.getProjectByID(projectID);
}
@ApiOperation(value = "getAllProjectList", notes = "Get All List")
@RequestMapping(value = "getAllProjectList", method = RequestMethod.GET)
public @ResponseBody
List<ProjectDisplayDto> getAllProjectList( String orgID, String serviceID, Integer projectYear) {
logger.info("/api/v1/project/getAllProjectList with orgID {} serviceID {}", orgID, serviceID);
return projectService.getAllProjectList(orgID, serviceID == null ? "" : serviceID, projectYear);
}
}
......@@ -226,7 +226,7 @@ public class UserController {
@SuppressWarnings("rawtypes")
@ApiOperation(value = "查询用户信息", notes = "税务运营管理平台>增值税申报")
@RequestMapping(value = "getUserByName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody OperationResultDto getUserByName(
public @ResponseBody UserDto getUserByName(
@RequestBody UserDto userParam) {
return userRoleService.GetUserByUserName(userParam);
}
......
package pwc.taxtech.atms.dao;
import java.util.Dictionary;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -161,4 +162,63 @@ public interface ProjectMapper extends MyMapper {
"</script>")
List<ProjectDisplayDto> getProjectList(@Param("orgID") String orgID, @Param("serverID") String serviceID,
@Param("projectYear") Integer projectYear);
@Select("SELECT " +
" p.PeriodId, p.Status " +
"FROM " +
" ProjectStatusManage p " +
"WHERE " +
" p.DbName = #{dbName} " +
"ORDER BY PeriodId , Status")
Dictionary<Integer,Integer> getProjectSatusListByDbName(String dbName);
@Select("<script>" +
"SELECT " +
" now() AS CreateTime, " +
" TRUE AS IsActive, " +
" org.ID AS OrganizationID, " +
" org.Name AS Name, " +
" org.Code AS Code, " +
" UUID() AS ID, " +
" org.IndustryID AS IndustryID, " +
" 0 AS Year, " +
" org.RegionID AS RegionID, " +
" 0 AS RuleType, " +
" st.ID AS ServiceTypeID, " +
" reg.ShortName AS RegionName, " +
" now() AS UpdateTime, " +
" st.Name AS ServiceTypeName, " +
" org.Name AS OrganizationName, " +
" ind.Name AS IndustryName, " +
" ostg.TemplateGroupID AS TemplateGroupID, " +
" '' AS TemplateGroupName, " +
" org.ClientCode AS ClientCode, " +
" '' AS DbName, " +
" FALSE AS HaveCreateProject, " +
" ea.EnterpriseAccountSetID AS EnterpriseAccountSetID, " +
" 1 AS StartPeriod, " +
" 12 AS EndPeriod, " +
" ea.EffectiveDate AS EffectiveDate, " +
" ea.ExpiredDate AS ExpiredDate " +
"FROM " +
" Organization org " +
" JOIN " +
" EnterpriseAccountSetOrg ea ON org.ID = ea.OrganizationID " +
" JOIN " +
" OrganizationServiceTemplateGroup ostg ON org.ID = ostg.OrganizationID " +
" JOIN " +
" ServiceType st ON ostg.ServiceTypeID = st.ID " +
" JOIN " +
" Industry ind ON org.IndustryID = ind.ID " +
" JOIN " +
" Region reg ON org.RegionID = reg.ID " +
"WHERE " +
" 1=1" +
" <if test=\"orgID != null and orgID !='' \">AND org.ID=#{orgID}</if>" +
" AND org.IsActive = 1 " +
" AND st.IsActive = 1 " +
" <if test=\"serviceID != null and serviceID !='' \">AND ostg.ServiceTypeID=#{serviceID}</if>" +
"ORDER BY ea.EffectiveDate,org.Code" +
"</script>")
List<ProjectDisplayDto> getProjectFromEnterpriseAccountSetOrg(@Param("orgID") String orgID, @Param("serviceID") String serviceID);
}
\ No newline at end of file
package pwc.taxtech.atms.dto.taxadmin;
public class ProjectYearParam {
public int endMonth;
public int startMonth;
public int year;
}
......@@ -36,6 +36,8 @@ public interface ProjectService {
List<ProjectDisplayDto> getProjectByID(String projectID);
List<ProjectDisplayDto> getAllProjectList(String orgID, String s, Integer projectYear);
// Map<Integer, Integer> getProjectAllStatus(String dbName);
}
package pwc.taxtech.atms.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.beust.jcommander.internal.Lists;
import com.google.common.base.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.dao.ProjectClientMapper;
import pwc.taxtech.atms.dao.ProjectMapper;
import pwc.taxtech.atms.dao.ServiceTypeMapper;
import pwc.taxtech.atms.dao.TemplateGroupMapper;
import pwc.taxtech.atms.dto.ProjectClientDto;
import pwc.taxtech.atms.dto.ServiceTypeDto;
import pwc.taxtech.atms.dto.TemplateGroupDto;
import pwc.taxtech.atms.dto.taxadmin.ProjectDisplayDto;
import pwc.taxtech.atms.dto.taxadmin.ProjectYearParam;
import pwc.taxtech.atms.entitiy.Project;
import pwc.taxtech.atms.entitiy.ProjectClient;
import pwc.taxtech.atms.entitiy.ProjectClientExample;
import pwc.taxtech.atms.entitiy.ProjectClientExample.Criteria;
......@@ -26,9 +26,20 @@ import pwc.taxtech.atms.entitiy.TemplateGroup;
import pwc.taxtech.atms.entitiy.TemplateGroupExample;
import pwc.taxtech.atms.service.ProjectService;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class ProjectServiceImpl implements ProjectService {
/** @see PwC.Tax.Tech.Atms..Admin.Application\Services\Impl\ProjectService.cs */
/**
* @see PwC.Tax.Tech.Atms..Admin.Application\Services\Impl\ProjectService.cs
*/
private static final int FIRST_OR_DEFAULT = 0;
@Autowired
private ServiceTypeMapper serviceTypeMapper;
......@@ -39,6 +50,9 @@ public class ProjectServiceImpl implements ProjectService {
@Autowired
private ProjectClientMapper projectClientMapper;
@Autowired
private ProjectMapper projectMapper;
private static final Logger logger = LoggerFactory.getLogger(ProjectServiceImpl.class);
@Override
......@@ -79,27 +93,194 @@ public class ProjectServiceImpl implements ProjectService {
return projectClientList.stream().map(this::rotateProjectClient).collect(Collectors.toList());
}
/** @TODO: this dmeo only for running,should change to query data from db (neo)*/
/**
* @TODO: this dmeo only for running,should change to query data from db (neo)
*/
@Override
public List<ProjectDisplayDto> getProjectByID(String projectID) {
List<ProjectDisplayDto> displayDtos =new ArrayList<>();
List<ProjectDisplayDto> displayDtos = new ArrayList<>();
displayDtos.add(new ProjectDisplayDto().demo());
return displayDtos;
}
/** @TODO: change the return part after copyProperties function updated */
@Override
public List<ProjectDisplayDto> getAllProjectList(String orgID, String serviceID, Integer projectYear) {
List<ProjectDisplayDto> pList = new ArrayList<>();
List<ProjectDisplayDto> data = projectMapper.getProjectList(orgID, serviceID, projectYear);
//获取每个项目的项目状态
data.forEach(p -> {
p.setProjectStatusList(projectMapper.getProjectSatusListByDbName(p.getDbName()));
});
//添加账套中需要创建的项目
List<ProjectDisplayDto> orgList = getProjectFromEnterpriseAccountSetOrg(data, orgID, serviceID, projectYear);
//修改账套时间变化引起的已建项目的月份更改
List<ProjectDisplayDto> removeList = new ArrayList<>();
orgList.forEach(p -> {
List<ProjectDisplayDto> fixList = data.stream()
.filter((Predicate<ProjectDisplayDto>) x -> x.getOrganizationID() == p.getOrganizationID()
&& x.getEnterpriseAccountSetID() == p.getEnterpriseAccountSetID()
&& x.getServiceTypeID() == p.getServiceTypeID()
&& x.getYear() == p.getYear()
&& (x.getStartPeriod() != p.getStartPeriod() || x.getEndPeriod() != p.getEndPeriod()))
.collect(Collectors.toList());
if (fixList != null && !fixList.isEmpty()) {
ProjectDisplayDto pddFirst=fixList.get(FIRST_OR_DEFAULT);
//修改数据库对应项目起始月
Project project = new Project();
project.setID(pddFirst.getId());
project.setStartPeriod(p.getStartPeriod());
project.setEndPeriod(p.getEndPeriod());
projectMapper.updateByPrimaryKey(project);
//修改已取出数据中项目起始月
pddFirst.setStartPeriod(p.getStartPeriod());
pddFirst.setEndPeriod(p.getEndPeriod());
//删除该条为创建项目记录
removeList.add(p);
}
});
removeList.forEach(r->{orgList.remove(r);});
pList.addAll(data);
pList.addAll(orgList);
return pList;
}
private List<ProjectDisplayDto> getProjectFromEnterpriseAccountSetOrg(List<ProjectDisplayDto> pList, String orgID,
String serviceID, Integer projectYear) {
List<ProjectDisplayDto> list = new ArrayList<>();
List<ProjectDisplayDto> data = projectMapper.getProjectFromEnterpriseAccountSetOrg(orgID, serviceID);
Map<String, ProjectDisplayDto> groupMap = new HashMap<>();
if (data != null && data.size() > 0) {
//去除project表已经存在的项目 g
data.forEach(dto -> {
getOrgProjectYears(dto.getEffectiveDate(), dto.getExpiredDate()).forEach(yDto -> {
ProjectDisplayDto orgDto = new ProjectDisplayDto();
dto.setYear(yDto.year);
dto.setStartPeriod(yDto.startMonth);
dto.setEndPeriod(yDto.endMonth);
dto.setName(dto.getOrganizationName() + "(" + dto.getYear() + ")");
//判断是否已经创建过该项目
//对于VAT,只创建今年及之后年份的项目(2018.1.2经Michelle确定,已放开vat限制)
//if ((projectList != null && projectList.Count > 0) || (int.Parse(orgDto.ServiceTypeID) == 2 && orgDto.Year < DateTime.Now.Year))
if (!pList.stream().anyMatch((Predicate<ProjectDisplayDto>) t -> t.getYear() == dto.getYear()
&& t.getServiceTypeID() == dto.getServiceTypeID()
&& t.getOrganizationID() == dto.getOrganizationID()
&& t.getEnterpriseAccountSetID() == dto.getEnterpriseAccountSetID()
&& t.getStartPeriod() == dto.getStartPeriod()
&& t.getEndPeriod() == dto.getEndPeriod())) {
list.add(dto);
}
});
});
if (!list.isEmpty()) {
list.forEach(m -> {
StringBuilder groupKeyBulder = new StringBuilder(m.getOrganizationID()).append("_")
.append(m.getEnterpriseAccountSetID()).append("_")
.append(m.getYear()).append("_")
.append(m.getServiceTypeID()).append("_")
.append(m.getStartPeriod()).append("_")
.append(m.getEndPeriod());
groupMap.putIfAbsent(groupKeyBulder.toString(), m);
});
}
}
return Lists.newArrayList(groupMap.values());
}
private List<ProjectYearParam> getOrgProjectYears(Date startDate, Date endDate) {
List<ProjectYearParam> pList = new ArrayList<>();
ProjectYearParam pYear = new ProjectYearParam();
Calendar nowCal = Calendar.getInstance();
Date nowDate = new Date();
nowCal.setTime(nowDate);
Calendar startCal = Calendar.getInstance();
startCal.setTime(startDate);
Calendar endCal = Calendar.getInstance();
endCal.setTime(endDate);
if (startDate == null && endDate == null) {
pYear.year = nowCal.get(Calendar.YEAR);
pYear.startMonth = 1;
pYear.endMonth = 12;
pList.add(pYear);
} else if (startDate == null && endDate != null && endCal.after(nowCal)) {
pList.addAll(getProjectYears(nowDate, endDate));
} else if (startDate != null && endDate == null && startCal.before(nowCal)) {
pList.addAll(getProjectYears(startDate, nowDate));
} else if (startDate != null && endDate != null && startCal.get(Calendar.YEAR) <= endCal.get(Calendar.YEAR)) {
pList.addAll(getProjectYears(startDate, endDate));
}
return pList;
}
private List<ProjectYearParam> getProjectYears(Date startDate, Date endDate) {
List<ProjectYearParam> pList = new ArrayList<>();
Calendar start = Calendar.getInstance();
start.setTime(startDate);
int startYear = start.get(Calendar.YEAR);
Calendar end = Calendar.getInstance();
end.setTime(endDate);
int endYear = end.get(Calendar.YEAR);
if (startDate != null && endDate != null && startYear < endYear) {
for (int i = startYear; i <= endYear; i++) {
ProjectYearParam pYear = new ProjectYearParam();
pYear.year = i;
if (startYear == endYear) {
pYear.startMonth = start.get(Calendar.MONTH);
pYear.endMonth = end.get(Calendar.MONTH);
} else if (i == startYear && i < endYear) {
pYear.startMonth = start.get(Calendar.MONTH);
pYear.endMonth = 12;
} else if (i > startYear && i < endYear) {
pYear.startMonth = 1;
pYear.endMonth = 12;
} else if (i > startYear && i == endYear) {
pYear.startMonth = 1;
pYear.endMonth = end.get(Calendar.MONTH);
}
pList.add(pYear);
}
}
return pList;
}
/**
* @TODO: change the return part after copyProperties function updated
*/
private ServiceTypeDto rotateServiceType(ServiceType serviceType) {
ServiceTypeDto serviceTypeDto = new ServiceTypeDto();
return CommonUtils.copyProperties(serviceType, serviceTypeDto);
}
/** @TODO: change the return part after copyProperties function updated */
/**
* @TODO: change the return part after copyProperties function updated
*/
private TemplateGroupDto rotateTemplateGroup(TemplateGroup templateGroup) {
TemplateGroupDto templateGroupDto = new TemplateGroupDto();
return CommonUtils.copyProperties(templateGroup, templateGroupDto);
}
/** @TODO: change the return part after copyProperties function updated */
/**
* @TODO: change the return part after copyProperties function updated
*/
private ProjectClientDto rotateProjectClient(ProjectClient projectClient) {
ProjectClientDto projectClientDto = new ProjectClientDto();
return CommonUtils.copyProperties(projectClient, projectClientDto);
......
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