|
@@ -2,12 +2,17 @@ package com.gqy.document.service.impl;
|
|
|
|
|
|
import com.gqy.common.core.domain.AjaxResult;
|
|
|
import com.gqy.common.core.domain.AjaxResultCQY;
|
|
|
+import com.gqy.common.utils.SecurityUtils;
|
|
|
+import com.gqy.common.utils.StringUtils;
|
|
|
import com.gqy.document.domain.DcTemplate;
|
|
|
import com.gqy.document.domain.TemplateCategory;
|
|
|
import com.gqy.document.mapper.DcTemplateMapper;
|
|
|
import com.gqy.document.service.IDcTemplateService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -17,8 +22,11 @@ import java.util.Map;
|
|
|
* 模板服务实现
|
|
|
*/
|
|
|
@Service
|
|
|
+
|
|
|
public class DcTemplateServiceImpl implements IDcTemplateService {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(DcTemplateServiceImpl.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private DcTemplateMapper dcTemplateMapper;
|
|
|
|
|
@@ -90,4 +98,86 @@ public class DcTemplateServiceImpl implements IDcTemplateService {
|
|
|
public List<DcTemplate> pageTemplate(DcTemplate dcTemplate){
|
|
|
return dcTemplateMapper.pageTemplate(dcTemplate);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建模板
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public AjaxResultCQY create(DcTemplate template) {
|
|
|
+ try {
|
|
|
+ // 参数校验
|
|
|
+ if (StringUtils.isEmpty(template.getName())) {
|
|
|
+ return AjaxResultCQY.error("模板名称不能为空");
|
|
|
+ }
|
|
|
+ template.setUser_id(SecurityUtils.getUserId());
|
|
|
+
|
|
|
+ // 设置当前用户ID
|
|
|
+ // template.getParams().put("userId", SecurityUtils.getUserId());
|
|
|
+
|
|
|
+ // 检查名称是否已存在
|
|
|
+ if (dcTemplateMapper.checkNameUnique(template) != null) {
|
|
|
+ return AjaxResultCQY.error("已存在同名模板");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置默认值
|
|
|
+ if (template.getAttrs() == null) {
|
|
|
+ template.setAttrs("[]");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 插入记录
|
|
|
+ dcTemplateMapper.insertTemplate(template);
|
|
|
+
|
|
|
+ // 使用返回的ID更新code
|
|
|
+ template.setCode(String.valueOf(template.getId()));
|
|
|
+
|
|
|
+ // 更新编码为ID
|
|
|
+ dcTemplateMapper.updateTemplateCode(template);
|
|
|
+
|
|
|
+ return AjaxResultCQY.success("创建成功");
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return AjaxResultCQY.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新模板
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public AjaxResultCQY update(DcTemplate template) {
|
|
|
+ try {
|
|
|
+ // 参数校验
|
|
|
+ if (template.getId() == null) {
|
|
|
+ return AjaxResultCQY.error("模板ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置当前用户ID
|
|
|
+ template.getParams().put("userId", SecurityUtils.getUserId());
|
|
|
+
|
|
|
+ template.setUser_id(SecurityUtils.getUserId());
|
|
|
+
|
|
|
+ // 检查模板是否存在
|
|
|
+ DcTemplate existTemplate = dcTemplateMapper.selectTemplateById(template.getId());
|
|
|
+ if (existTemplate == null) {
|
|
|
+ return AjaxResultCQY.error("模板不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否有权限修改
|
|
|
+// if (!existTemplate.getAdmin_id().equals(SecurityUtils.getUserId())) {
|
|
|
+// return AjaxResult.error("无权修改此模板");
|
|
|
+// }
|
|
|
+
|
|
|
+ // 更新模板
|
|
|
+ if (dcTemplateMapper.updateTemplateCode(template) > 0) {
|
|
|
+ return AjaxResultCQY.success("更新成功");
|
|
|
+ }
|
|
|
+ return AjaxResultCQY.error("更新失败");
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return AjaxResultCQY.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|