浏览代码

清洗历史模板数据

hurugang 3 年之前
父节点
当前提交
e8893e3f62

+ 26 - 1
src/main/java/cn/hnthyy/thmz/controller/mz/TemplateController.java

@@ -115,7 +115,7 @@ public class TemplateController {
                 resultMap.put("message", "删除医疗范文失败,范文主键参数为空");
                 return resultMap;
             }
-            Template dbTemplate=templateService.queryById(template.getId());
+            Template dbTemplate = templateService.queryById(template.getId());
             dbTemplate.setTemplateStatus(YesNoEnum.YES.code);
             User tokenUser = TokenUtil.getUser(httpServletRequest);
             dbTemplate.setUpdateId(tokenUser.getUserIdCode());
@@ -239,4 +239,29 @@ public class TemplateController {
         }
     }
 
+
+    /**
+     * 将历史的模板数据清洗成可以做行选的模板数据
+     *
+     * @return
+     */
+    @UserLoginToken
+    @RequestMapping(value = "/castToNewTemplate", method = {RequestMethod.GET})
+    public Map<String, Object> castToNewTemplate() {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            int num = templateService.castToNewTemplate();
+            resultMap.put("code", 0);
+            resultMap.put("message", "将历史的模板数据清洗成可以做行选的模板数据成功,总数是" +num+"条");
+            log.info("将历史的模板数据清洗成可以做行选的模板数据成功,总数是" +num+"条");
+            return resultMap;
+        } catch (Exception e) {
+            e.printStackTrace();
+            resultMap.put("code", -1);
+            resultMap.put("message", "将历史的模板数据清洗成可以做行选的模板数据失败,请联系管理员");
+            log.error("系统异常,错误信息{}", e);
+            return resultMap;
+        }
+    }
+
 }

+ 6 - 0
src/main/java/cn/hnthyy/thmz/mapper/thmz/TemplateMapper.java

@@ -9,6 +9,12 @@ import java.util.List;
  * 医疗范文 DAO
  */
 public interface TemplateMapper {
+    /**
+     * 查询所有的处方模板
+     * @return
+     */
+    @Select("select * from t_template")
+    List<Template> selectAll();
 
     /**
      * 保存医疗范文

+ 29 - 0
src/main/java/cn/hnthyy/thmz/service/impl/thmz/TemplateServiceImpl.java

@@ -15,7 +15,12 @@ import cn.hnthyy.thmz.vo.MzPrescriptionVo;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 
@@ -106,5 +111,29 @@ public class TemplateServiceImpl implements TemplateService {
         return templateMapper.updateTemplateByKey(template);
     }
 
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
+    public int castToNewTemplate() {
+        List<Template> templates= templateMapper.selectAll();
+        if(templates==null || templates.size()==0){
+            return 0;
+        }
+        String ids = null;
+        for (Template template:templates){
+            try {
+                saveTemplate(template);
+            } catch (MzException e) {
+                e.printStackTrace();
+                if(ids==null){
+                    ids=template.getId()+",";
+                }else {
+                    ids=template.getId()+template.getId()+",";
+                }
+            }
+        }
+        System.err.println(ids);
+        return templates.size();
+    }
+
 
 }

+ 6 - 0
src/main/java/cn/hnthyy/thmz/service/thmz/TemplateService.java

@@ -45,4 +45,10 @@ public interface TemplateService {
      */
     int modifyTemplateByKey(Template template);
 
+    /**
+     * 将历史的模板数据清洗成可以做行选的模板数据
+     * @return
+     */
+    int castToNewTemplate();
+
 }

+ 1 - 1
src/main/resources/static/js/mz/clinic.js

@@ -2206,7 +2206,7 @@ function medicalModelModal(id) {
                     $("#zdTemplate").html(html);
                 }
                 var prescriptionDetail = jsonData.mzBlRecord.prescriptionDetail;
-                if (prescriptionDetail != null) {
+                if (prescriptionDetail != null && prescriptionDetail!="") {
                     prescriptionDetail = JSON.parse(prescriptionDetail);
                     var xyPrescription = prescriptionDetail.xyPrescription;
                     if (xyPrescription != null) {