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> 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 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 temManaList = templateCategoryEditMapper.queryTempManager(tenantID, temCateList.get(i).getBusinessCategoryID(), temCateList.get(i).getTemplateCategoryID(), selectFor); if(!temManaList.isEmpty()){ // 设置查询使用数量,templateCategoryName for(int j=0; j pageResult=new PageResult(); pageResult.setList(temCateList); pageResult.setCount(Long.valueOf(count)); List> list =new ArrayList>(); 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 tempList = templateCategoryOutput.getTemplateManagerOutput(); for(int i=0; i