Commit 6062aa0a authored by frank.xa.zhang's avatar frank.xa.zhang

add apis for report configuration function

parent ec72a43d
......@@ -7,6 +7,7 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
......@@ -44,8 +45,9 @@ public class FTPClientPool {
/**
* 上传
* @param filePath 相对路径
* @param fileName 文件名
*
* @param filePath 相对路径
* @param fileName 文件名
* @param inputStream InputStream
* @throws Exception Exception
*/
......@@ -65,6 +67,7 @@ public class FTPClientPool {
/**
* 下载
*
* @param filePath 相对路径 + 文件名
* @return InputStream
* @throws Exception Exception
......@@ -83,7 +86,7 @@ public class FTPClientPool {
if (StringUtils.isNotBlank(p) && !StringUtils.equals(p, ".")) {
if (!ftpClient.changeWorkingDirectory(p)) {
ftpClient.makeDirectory(p);
if (!ftpClient.changeWorkingDirectory(p)){
if (!ftpClient.changeWorkingDirectory(p)) {
throw new IOException("changeWorkingDirectory error.");
}
}
......@@ -104,4 +107,22 @@ public class FTPClientPool {
public String getFtpRootPath() {
return ftpRootPath;
}
/**
* 删除ftp文件
*
* @param filePath
*/
public void delete(String filePath) throws Exception {
if (StringUtils.isBlank(filePath)) {
return;
}
FTPClient client = getClient();
if (!isExist(filePath, client)) {
return;
} else {
client.deleteFile(filePath);
}
}
}
......@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import pwc.taxtech.atms.common.ftp.FTPClientPool;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.TemplateGroupDto;
import pwc.taxtech.atms.service.TemplateGroupService;
......@@ -20,6 +21,9 @@ public class TemplateGroupController {
@Autowired
TemplateGroupService templateGroupService;
@Autowired
FTPClientPool ftpClientPool;
@ApiOperation(value = "获取所有的模板分组")
@RequestMapping(value = "getall", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
......@@ -41,5 +45,23 @@ public class TemplateGroupController {
return templateGroupService.updateTemplateGroupName(templateGroupDto);
}
@RequestMapping(value = "deleteTemplateGroup", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody
OperationResultDto<Object> DeleteTemplateGroup(TemplateGroupDto templateGroupDto) {
OperationResultDto<Object> result = templateGroupService.deleteTemplateGroup(templateGroupDto);
if (result.getResult()) {
List<String> pathList = (List<String>) result.getData();
if (pathList != null && pathList.size() > 0) {
for(String path:pathList){
String pathAndName = path;
try {
ftpClientPool.delete(pathAndName);
}
catch(Exception e){
}
}
}
}
return result;
}
}
......@@ -107,4 +107,6 @@ public interface CellTemplateConfigMapper extends MyMapper {
int updateByPrimaryKey(CellTemplateConfig record);
List<CellTemplateConfig> getCellTemplateConfigByTemplateID(@Param("templateID") String templateID);
int deleteCellTemplateConfigByCellTemplate(@Param("templateDbID") String templateDbID);
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import org.springframework.security.access.method.P;
import pwc.taxtech.atms.MyMapper;
import pwc.taxtech.atms.entitiy.KeyValueReference;
import pwc.taxtech.atms.entitiy.KeyValueReferenceExample;
......@@ -105,4 +106,6 @@ public interface KeyValueReferenceMapper extends MyMapper {
* @mbg.generated
*/
int updateByPrimaryKey(KeyValueReference record);
int deleteKeyValueReferenceByCellTemplate(@Param("templateDbID") String templateDbID);
}
\ No newline at end of file
......@@ -108,4 +108,6 @@ public interface OrganizationServiceTemplateGroupMapper extends MyMapper {
int updateByPrimaryKey(OrganizationServiceTemplateGroup record);
List<OrganizationServiceTemplateGroupDto> getSingleOrgByOrgIDToOSTGDto(@Param("orgId") String orgId);
List<String> getOrgnizationServiceTemplateGroupOrgNames(@Param("templateGroupDtoID") String templateGroupDtoID);
}
\ No newline at end of file
......@@ -11,4 +11,6 @@ public interface TemplateGroupService {
List<TemplateGroupDto> get(int serviceTypeID, Integer taxPayType, String industryID);
OperationResultDto<Object> updateTemplateGroupName(TemplateGroupDto templateGroupDto);
OperationResultDto<Object> deleteTemplateGroup(TemplateGroupDto templateGroupDto);
}
package pwc.taxtech.atms.service.impl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.constant.enums.TemplateGroupType;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.TemplateGroupDto;
import pwc.taxtech.atms.entitiy.TemplateGroup;
import pwc.taxtech.atms.entitiy.TemplateGroupExample;
import pwc.taxtech.atms.entitiy.*;
import pwc.taxtech.atms.service.TemplateGroupService;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class TemplateGroupServiceImpl extends AbstractService implements TemplateGroupService {
......@@ -58,7 +59,7 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
if (!templateGroups.isEmpty()) {
OperationResultDto<Object> result = new OperationResultDto<>();
result.setResult(false);
result.setResultMsg(TemplateGroupMessage.TemplateGroupNameExist);
result.setResultMsg(TemplateGroupMessage.TEMPLATE_GROUP_NAME_EXIST);
}
entity.setName(templateGroupDto.getName());
templateGroupMapper.updateByPrimaryKey(entity);
......@@ -67,12 +68,58 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
return result;
}
@Override
@Transactional
public OperationResultDto<Object> deleteTemplateGroup(TemplateGroupDto templateGroupDto) {
OperationResultDto<Object> result = new OperationResultDto<>();
TemplateGroup templateGroupDb = templateGroupMapper.selectByPrimaryKey(templateGroupDto.getID());
if (templateGroupDb.getIsSystemType()) {
result.setResult(false);
result.setResultMsg(TemplateGroupMessage.SYSTEM_TYPE_CANNOT_DELETE);
return result;
}
List<String> userOranizationNameList = organizationServiceTemplateGroupMapper.getOrgnizationServiceTemplateGroupOrgNames(templateGroupDto.getID());
if (userOranizationNameList != null && !userOranizationNameList.isEmpty()) {
result.setResult(false);
result.setResultMsg(TemplateGroupMessage.ORGANIZATION_USED_TEMPLATE_GROUP);
return result;
}
List<Template> allTemplateDbList = templateMapper.selectByExample(new TemplateExample());
List<Template> templateDbList = allTemplateDbList.stream().filter(a -> a.getTemplateGroupID().equals(templateGroupDb.getID())).collect(Collectors.toList());
List<String> pathList = new ArrayList<>();
for (Template templateDb : templateDbList) {
boolean anySameCodeExists = allTemplateDbList.stream().anyMatch(a -> a.getCode().equals(templateDb.getCode()) && a.getID().equals(templateDb.getCode()));
if (!anySameCodeExists) {
pathList.add((templateDb.getPath()));
}
deleteTemplate(templateDb);
}
templateGroupMapper.deleteByPrimaryKey(templateGroupDb.getID());
result.setResult(true);
result.setData(pathList);
return result;
}
private void deleteTemplate(Template templateDb) {
cellTemplateConfigMapper.deleteCellTemplateConfigByCellTemplate(templateDb.getID());
keyValueReferenceMapper.deleteKeyValueReferenceByCellTemplate(templateDb.getID());
CellTemplateExample example = new CellTemplateExample();
example.createCriteria().andReportTemplateIDEqualTo(templateDb.getID());
cellTemplateMapper.deleteByExample(example);
}
public class TemplateGroupMessage {
public static final String TemplateGroupNameExist = "TemplateGroupNameExist";
public static final String TEMPLATE_GROUP_NAME_EXIST = "TemplateGroupNameExist";
public static final String SystemTypeCannotDelete = "SystemTypeCannotDelete";
public static final String SYSTEM_TYPE_CANNOT_DELETE = "SystemTypeCannotDelete";
public static final String OrganizationUsedTemplateGroup = "OrganizationUsedTemplateGroup";
public static final String ORGANIZATION_USED_TEMPLATE_GROUP = "OrganizationUsedTemplateGroup";
}
}
......@@ -528,4 +528,8 @@
<select id="getCellTemplateConfigByTemplateID" parameterType="java.lang.String" resultMap="BaseResultMap">
select b.* from CellTemplate a join CellTemplateConfig b on a.ID = b.CellTemplateID where a.ReportTemplateID=#{templateID,jdbcType=VARCHAR}
</select>
<delete id="deleteCellTemplateConfigByCellTemplate" parameterType="java.lang.String">
DELETE FROM CellTemplateConfig a WHERE a.ID in(SELECT b.ID FROM CellTemplateConfig b INNER JOIN CellTemplate c on b.CellTemplateID=c.ID WHERE c.ReportTemplateID=#{templateDbID,jdbcType=VARCHAR})
</delete>
</mapper>
\ No newline at end of file
......@@ -318,4 +318,7 @@
order by ${orderByClause}
</if>
</select>
<delete id="deleteKeyValueReferenceByCellTemplate" parameterType="java.lang.String">
DELETE FROM KeyValueReference a WHERE a.ID in(SELECT b.ID FROM KeyValueReference b INNER JOIN CellTemplate c on b.CellTemplateID=c.ID WHERE c.ReportTemplateID=#{templateDbID,jdbcType=VARCHAR})
</delete>
</mapper>
\ No newline at end of file
......@@ -290,4 +290,7 @@
where m.OrganizationID = #{orgId}
order by m.ServiceTypeID
</select>
<select id="getOrgnizationServiceTemplateGroupOrgNames" parameterType="java.lang.String" resultMap="java.lang.String">
SELECT q.Name FROM OrganizationServiceTemplateGroup p LEFT JOIN Organization q on p.OrganizationID=q.ID WHERE p.TemplateGroupID=#{templateGroupDtoID,jdbcType:VARCHAR} AND q.IsActive=1
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment