package cn.autoform.web.service.templatecategoryedit;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.github.pagehelper.Page;
|
|
import cn.autoform.bean.TemplateCategoryOutput;
|
import cn.autoform.bean.TemplateManagerOutput;
|
import cn.autoform.bean.page.PageResult;
|
import cn.autoform.db.entity.TemplateCategoryEntity;
|
import cn.autoform.db.entity.TemplateManagerEntity;
|
import cn.autoform.web.mapper.templatecategoryedit.TemplateCategoryEditMapper;
|
|
/**
|
* 模板分类编辑Service
|
* @author lt-zwy
|
*
|
*/
|
@Service
|
public class TemplateCategoryEditService {
|
|
@Autowired
|
private TemplateCategoryEditMapper templateCategoryEditMapper = null;
|
|
public int updateTempFormName(TemplateManagerEntity templateManagerEntity){
|
return templateCategoryEditMapper.updateTempFormName(templateManagerEntity);
|
}
|
|
/**
|
* 根据参数查询模板分类信息
|
* @param tenantID
|
* @param businessCategoryID
|
* @param templateCategoryID
|
* @param pageNum
|
* @return
|
*/
|
public List<PageResult<TemplateCategoryOutput>> queryTemplateList(String tenantID, String businessCategoryID, String selectFor,int pageNum,int pageSize,String selectName) {
|
//分页查询开始的条数
|
int pageStrat = 0;
|
if(pageNum!=0){
|
pageStrat=(pageNum-1)*pageSize;
|
}
|
// 根据租户id和业务分类id查询模板分类
|
List<TemplateCategoryOutput> temCateList = templateCategoryEditMapper.queryTempCategory(tenantID, businessCategoryID,pageStrat,pageSize,selectName);
|
int count = templateCategoryEditMapper.getTempLatePageCount(tenantID, businessCategoryID,selectName);
|
System.out.println("+++++++++"+temCateList.size());
|
if(!temCateList.isEmpty()){
|
//当模板分类只有一条时,不可删除
|
if(temCateList.size()==1){
|
temCateList.get(0).setCanDeleteFlag(true);
|
}
|
// 设置第一个模板分类【isOpened打开】
|
temCateList.get(0).setOpenedFlag(true);
|
// 再根据租户id,以及返回的业务分类id和模板分类id查询模板信息
|
for(int i=0; i<temCateList.size(); i++) {
|
List<TemplateManagerOutput> temManaList = templateCategoryEditMapper.queryTempManager(tenantID,
|
temCateList.get(i).getBusinessCategoryID(),
|
temCateList.get(i).getTemplateCategoryID(),
|
selectFor);
|
if(!temManaList.isEmpty()){
|
// 设置查询使用数量,templateCategoryName
|
for(int j=0; j<temManaList.size(); j++) {
|
int templateUseSum = templateCategoryEditMapper.queryTemplateUsedSum(tenantID, temManaList.get(j).getTemplateID());
|
temManaList.get(j).setTemplateUseSum(templateUseSum);
|
temManaList.get(j).setTemplateCategoryName(temCateList.get(i).getTemplateCategoryName());
|
//CheckBox显示模板是否启用
|
if("1".equals(temManaList.get(j).getEnablesetting())){
|
temManaList.get(j).setUsableFlag(true);
|
}else{
|
temManaList.get(j).setUsableFlag(false);
|
}
|
}
|
temCateList.get(i).setTemplateManagerOutput(temManaList);
|
}
|
}
|
if(temCateList.get(0).getTemplateManagerOutput() != null){
|
// 第一个分类下的第一个模板信息【selected显示】
|
temCateList.get(0).getTemplateManagerOutput().get(0).setSelected(true);
|
}
|
}
|
PageResult<TemplateCategoryOutput> pageResult=new PageResult<TemplateCategoryOutput>();
|
pageResult.setList(temCateList);
|
pageResult.setCount(Long.valueOf(count));
|
List<PageResult<TemplateCategoryOutput>> list =new ArrayList<PageResult<TemplateCategoryOutput>>();
|
list.add(pageResult);
|
return list;
|
}
|
/**
|
* 新增模板分类
|
* @param templateCategoryEntity
|
* @return
|
*/
|
public int createTemplateCategoryInfo(TemplateCategoryEntity templateCategoryEntity) {
|
int sameCount = templateCategoryEditMapper.categoryNameCheck(templateCategoryEntity);
|
if(sameCount == 0){
|
return templateCategoryEditMapper.createTemplateCategory(templateCategoryEntity);
|
}else if(sameCount != 0){
|
return 2;
|
}else{
|
return 0;
|
}
|
}
|
|
/**
|
* 编辑模板分类
|
* @param templateCategoryEntity
|
* @return
|
*/
|
public int updateTemlateCategoryInfo(TemplateCategoryEntity templateCategoryEntity) {
|
int sameCount = templateCategoryEditMapper.categoryNameCheck(templateCategoryEntity);
|
if(sameCount == 0){
|
return templateCategoryEditMapper.saveTemplateCategory(templateCategoryEntity);
|
}else if(sameCount != 0){
|
return 2;
|
}else{
|
return 0;
|
}
|
}
|
|
/**
|
* 新增模板
|
* @param templateManagerEntity
|
* @return
|
*/
|
public int createTemplateInfo(TemplateManagerOutput templateManagerOutput) {
|
int sameCount = templateCategoryEditMapper.templateNameCheck(templateManagerOutput);
|
if(sameCount == 0){
|
//新增模板管理表
|
int templateReturn = templateCategoryEditMapper.createTemplate(templateManagerOutput);
|
if(templateReturn == 1){
|
return 1;
|
}else{
|
return 0;
|
}
|
}else{
|
return 2;//名称重复
|
}
|
}
|
|
/**
|
* 编辑模板
|
* @param templateManagerEntity
|
* @return
|
*/
|
public int updateTemplateInfo(TemplateManagerOutput templateManagerOutput) {
|
int sameCount = templateCategoryEditMapper.templateNameCheck(templateManagerOutput);
|
if(sameCount == 0){
|
//设置模板是否启用
|
if(templateManagerOutput.isUsableFlag()){
|
templateManagerOutput.setEnablesetting("1");
|
}else{
|
templateManagerOutput.setEnablesetting("0");
|
}
|
return templateCategoryEditMapper.saveTemplate(templateManagerOutput);
|
}else{
|
return 2;
|
}
|
}
|
|
/**
|
* 删除模板分类及下属模板
|
* @param templateCategoryOutput
|
* @return
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
public int deleteTemplateCategory(TemplateCategoryOutput templateCategoryOutput) {
|
|
//删除模板分类标签
|
int categoryDelete = templateCategoryEditMapper.deleteCategory(templateCategoryOutput);
|
int templateDelete = 0;
|
if(templateCategoryOutput.getTemplateManagerOutput() != null){
|
//删除分类下的模板
|
List<TemplateManagerOutput> tempList = templateCategoryOutput.getTemplateManagerOutput();
|
for(int i=0; i<tempList.size(); i++){
|
templateDelete = templateCategoryEditMapper.deleteTemplate(tempList.get(i));
|
}
|
if(categoryDelete == 1 && templateDelete == 1){
|
return 1;
|
}else{
|
return 0;
|
}
|
}else{
|
if(categoryDelete == 1){
|
return 1;
|
}else{
|
return 0;
|
}
|
}
|
}
|
|
/**
|
* 删除分类模板标签下的模板
|
* @param templateManagerOutput
|
* return
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
public int deleteTemplate(TemplateManagerOutput templateManagerOutput){
|
int templateDeleteReturnNum = templateCategoryEditMapper.deleteTemplate(templateManagerOutput);
|
if(templateDeleteReturnNum == 1){
|
return 1;
|
}else{
|
return 0;
|
}
|
}
|
|
/**
|
* 验证当前模板是否已启用,已经停用的模板不可以创建表单
|
* @param tenantID
|
* @param templateID
|
* @return
|
*/
|
public int checkTemplateEnable(String tenantID, String templateID) {
|
String enableSeting = templateCategoryEditMapper.checkTemplateEnable(tenantID, templateID);
|
if("1".equals(enableSeting)){
|
return 1;
|
}else{
|
return 0;
|
}
|
}
|
}
|