浏览代码

团队模板保存为个人模板

wujunjie 8 年之前
父节点
当前提交
79e105d133

+ 5 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/template/DoctorGuidanceTempDao.java

@ -25,5 +25,9 @@ public interface DoctorGuidanceTempDao extends PagingAndSortingRepository<Doctor
    @Query("select t from DoctorGuidanceTemp t where t.owner = ?1 or t.owner = 'system' order by t.sendTimes desc")
    Page<DoctorGuidanceTemp> findByOwnerAndSystem(String owner, Pageable pageRequest);
//    Page<List<DoctorGuidanceTemp>> findByOwnerAndSystem(String owner, Pageable pageRequest);
    //    Page<List<DoctorGuidanceTemp>> findByOwnerAndSystem(String owner, Pageable pageRequest);
    //验证医生健康指导模板标题是否重复
    @Query("select t from DoctorGuidanceTemp t where t.owner != 'system' and t.modelName = ?1 ")
    List<DoctorGuidanceTemp> findByTitle(String title);
}

+ 5 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/template/DoctorTeamGuidanceTemplateDao.java

@ -41,4 +41,9 @@ public interface DoctorTeamGuidanceTemplateDao extends PagingAndSortingRepositor
    @Query("update DoctorTeamGuidanceTemplate t set t.useTimes = t.useTimes+1 where t.del = 1 and t.teamId = ?1 and t.teamTemplateCode =?2 ")
    int countSend(int teamId, String guidanceCode);
    //  批量删除(失效)该模板所在的所有团队关系
    @Modifying
    @Query("update DoctorTeamGuidanceTemplate t set t.useTimes =  0 ,t.del = 0 where t.teamId = ?1 and t.teamTemplateCode =?2 ")
    int deleteByTeam(int teamId, String guidanceCode);
}

+ 65 - 61
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorGuidanceTempService.java

@ -12,6 +12,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@ -30,19 +31,21 @@ public class DoctorGuidanceTempService extends BaseService {
    /**
     * 记录医生健康指导模板使用次数
     *
     * @param modelCode 健康指导模板编码
     */
    public void countSend(String modelCode){
        synchronized (this){
    public void countSend(String modelCode) {
        synchronized (this) {
            String sql = "UPDATE wlyy_doctor_guidance_temp  " +
                    "SET send_times=send_times+1 " +
                    "WHERE CODE=?";
            jdbcTemplate.update(sql,modelCode);
            jdbcTemplate.update(sql, modelCode);
        }
    }
    /**
     * 查询单个指导模板详情
     *
     * @param modelCode
     * @return
     * @throws Exception
@ -51,24 +54,25 @@ public class DoctorGuidanceTempService extends BaseService {
        String sql = "SELECT wdgt.`model_name`,wdgt.`content`,wdgt.`images_url`,wdgt.`create_time`,wdgt.`send_times` " +
                "FROM wlyy_doctor_guidance_temp wdgt " +
                "WHERE wdgt.`code`=?";
        Map temp=(Map)jdbcTemplate.queryForMap(sql,modelCode);
        String modelName= (String)temp.get("model_name");
        String content= (String)temp.get("content");
        String imagesUrl= (String)temp.get("images_url");
        Map temp = (Map) jdbcTemplate.queryForMap(sql, modelCode);
        String modelName = (String) temp.get("model_name");
        String content = (String) temp.get("content");
        String imagesUrl = (String) temp.get("images_url");
//        多图按逗号分割保存成数组
        String [] imagesArray = null;
        if(imagesUrl != null){
        String[] imagesArray = null;
        if (imagesUrl != null) {
            imagesArray = imagesUrl.split(",");
        }
        String createTime = (String)temp.get("create_time").toString();
        String sendTimes = (String)temp.get("send_times").toString();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date createTime = (Date) temp.get("create_time");
        String dateTime = sdf.format(createTime);
        String sendTimes = (String) temp.get("send_times").toString();
        JSONObject json = new JSONObject();
        json.put("modelName",modelName);
        json.put("content",content);
        json.put("imagesUrls",imagesArray);
        json.put("createTime",createTime);
        json.put("sendTimes",sendTimes);
        json.put("modelName", modelName);
        json.put("content", content);
        json.put("imagesUrls", imagesArray);
        json.put("createTime", dateTime);
        json.put("sendTimes", sendTimes);
        return json;
    }
@ -79,7 +83,7 @@ public class DoctorGuidanceTempService extends BaseService {
     * @param content 指导内容
     * @return
     */
    public DoctorGuidanceTemp add(String doctor, String content,String modelName,String imagesUrl) {
    public DoctorGuidanceTemp add(String doctor, String content, String modelName, String imagesUrl) {
        DoctorGuidanceTemp guidanceTemp = new DoctorGuidanceTemp();
        String imageUrls = "";
        String imageRow = "";
@ -92,16 +96,16 @@ public class DoctorGuidanceTempService extends BaseService {
        guidanceTemp.setModelName(modelName);
        if (imagesUrl==null||"".equals(imagesUrl)) {
            imagesUrl=null;
        }else {
        if (imagesUrl == null || "".equals(imagesUrl)) {
            imagesUrl = null;
        } else {
            String[] images = imagesUrl.split(",");
            for (String image : images) {
                if (image.contains("http://")) {
                    imageUrls += image + ",";
                } else {
                    try {
                        imageRow += CommonUtil.copyTempImage(image)+",";
                        imageRow += CommonUtil.copyTempImage(image) + ",";
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
@ -109,7 +113,7 @@ public class DoctorGuidanceTempService extends BaseService {
            }
            imagesUrl = imageUrls + imageRow;
            imagesUrl =  imagesUrl.substring(0,imagesUrl.length()-1);
            imagesUrl = imagesUrl.substring(0, imagesUrl.length() - 1);
        }
        guidanceTemp.setImagesUrl(imagesUrl);
@ -136,16 +140,16 @@ public class DoctorGuidanceTempService extends BaseService {
        guidanceTemp.setModelName(modelName);
        guidanceTemp.setContent(content);
        if (imagesUrl==null||"".equals(imagesUrl)) {
            imagesUrl=null;
        }else {
        if (imagesUrl == null || "".equals(imagesUrl)) {
            imagesUrl = null;
        } else {
            String[] images = imagesUrl.split(",");
            for (String image : images) {
                if (image.contains("http://")) {
                    imageUrls += image + ",";
                } else {
                    try {
                        imageRow += CommonUtil.copyTempImage(image)+",";
                        imageRow += CommonUtil.copyTempImage(image) + ",";
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
@ -153,7 +157,7 @@ public class DoctorGuidanceTempService extends BaseService {
            }
            imagesUrl = imageUrls + imageRow;
            imagesUrl =  imagesUrl.substring(0,imagesUrl.length()-1);
            imagesUrl = imagesUrl.substring(0, imagesUrl.length() - 1);
        }
        guidanceTemp.setImagesUrl(imagesUrl);
@ -173,8 +177,8 @@ public class DoctorGuidanceTempService extends BaseService {
        if (codes != null && codes.length > 0) {
            for (String temp : codes) {
                String sql = "SELECT t.owner FROM wlyy_doctor_guidance_temp t WHERE t.code=?";
                String owner = jdbcTemplate.queryForObject(sql,String.class,temp);
                if(!"system".equals(owner)){
                String owner = jdbcTemplate.queryForObject(sql, String.class, temp);
                if (!"system".equals(owner)) {
                    guidanceTempDao.deleteByCode(temp);
                }
@ -191,49 +195,49 @@ public class DoctorGuidanceTempService extends BaseService {
     * @param type   模板类型
     * @return
     */
    public List<Map<String,Object>> list(String doctor, String type,int pageSize,int pageNo) throws Exception {
    public List<Map<String, Object>> list(String doctor, String type, int pageSize, int pageNo) throws Exception {
        Page<DoctorGuidanceTemp> temps = null;
        PageRequest pageRequest = new PageRequest(pageNo, pageSize);
        List<Map<String,Object>> listMap = new ArrayList<>();
        List<Map<String, Object>> listMap = new ArrayList<>();
        if (type.equals("1")) {
            temps = guidanceTempDao.findByOwner("system",pageRequest);
           List<DoctorGuidanceTemp> list = temps.getContent();
           for (int i=0;i<list.size();i++){
               DoctorGuidanceTemp dgt = list.get(i);
               Map<String,Object> tem = new HashMap<>();
               tem.put("code",dgt.getCode());
               tem.put("owner",dgt.getOwner());
               tem.put("sendTimes",dgt.getSendTimes());
               tem.put("lastTime",dgt.getLastTime());
               tem.put("modelName",dgt.getModelName());
               listMap.add(tem);
           }
            temps = guidanceTempDao.findByOwner("system", pageRequest);
            List<DoctorGuidanceTemp> list = temps.getContent();
            for (int i = 0; i < list.size(); i++) {
                DoctorGuidanceTemp dgt = list.get(i);
                Map<String, Object> tem = new HashMap<>();
                tem.put("code", dgt.getCode());
                tem.put("owner", dgt.getOwner());
                tem.put("sendTimes", dgt.getSendTimes());
                tem.put("lastTime", dgt.getLastTime());
                tem.put("modelName", dgt.getModelName());
                listMap.add(tem);
            }
        } else if (type.equals("2")) {
            temps = guidanceTempDao.findByOwner(doctor,pageRequest);
            temps = guidanceTempDao.findByOwner(doctor, pageRequest);
            List<DoctorGuidanceTemp> list = temps.getContent();
            for (int i=0;i<list.size();i++){
            for (int i = 0; i < list.size(); i++) {
                DoctorGuidanceTemp dgt = list.get(i);
                Map<String,Object> tem = new HashMap<>();
                tem.put("code",dgt.getCode());
                tem.put("owner",dgt.getOwner());
                tem.put("sendTimes",dgt.getSendTimes());
                tem.put("lastTime",dgt.getLastTime());
                tem.put("modelName",dgt.getModelName());
                Map<String, Object> tem = new HashMap<>();
                tem.put("code", dgt.getCode());
                tem.put("owner", dgt.getOwner());
                tem.put("sendTimes", dgt.getSendTimes());
                tem.put("lastTime", dgt.getLastTime());
                tem.put("modelName", dgt.getModelName());
                listMap.add(tem);
            }
        } else {
            temps = guidanceTempDao.findByOwnerAndSystem(doctor,pageRequest);
            temps = guidanceTempDao.findByOwnerAndSystem(doctor, pageRequest);
            List<DoctorGuidanceTemp> list = temps.getContent();
            for (int i=0;i<list.size();i++){
            for (int i = 0; i < list.size(); i++) {
                DoctorGuidanceTemp dgt = list.get(i);
                Map<String,Object> tem = new HashMap<>();
                tem.put("code",dgt.getCode());
                tem.put("owner",dgt.getOwner());
                tem.put("sendTimes",dgt.getSendTimes());
                tem.put("lastTime",dgt.getLastTime());
                tem.put("modelName",dgt.getModelName());
                Map<String, Object> tem = new HashMap<>();
                tem.put("code", dgt.getCode());
                tem.put("owner", dgt.getOwner());
                tem.put("sendTimes", dgt.getSendTimes());
                tem.put("lastTime", dgt.getLastTime());
                tem.put("modelName", dgt.getModelName());
                listMap.add(tem);
            }
        }

+ 48 - 5
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorTeamGuidanceService.java

@ -53,6 +53,8 @@ public class DoctorTeamGuidanceService extends BaseService {
    private PatientHealthGuidanceService patientHealthGuidanceService;
    @Autowired
    private ConsultService consultService;
    @Autowired
    DoctorGuidanceTempDao guidanceTempDao;
    /**
     * 新增团队指导模板
@ -118,7 +120,14 @@ public class DoctorTeamGuidanceService extends BaseService {
     * @param images
     * @throws Exception
     */
    public void modifyTeamGuidance(String doctor, int saveAsGuidance, String guidanceCode, String title, JSONArray teams, String content, String images) throws Exception {
    public void modifyTeamGuidance(String doctor, String isLeader, int saveAsGuidance, String guidanceCode, String title,
                                   JSONArray teams, String content, String images) throws Exception {
//        首先身份验证
        DoctorTeamGuidanceDetail guidanceDetail = doctorTeamGuidanceDetailDao.findGuidanceDetail(guidanceCode);
        String creater = guidanceDetail.getCreater();
        if ((!doctor.equals(creater)) && (!"1".equals(isLeader))) {
            throw new Exception("没有修改权限");
        }
//        图片地址需要处理
        String image = "";
        if (StringUtils.isNotEmpty(images)) {
@ -127,7 +136,12 @@ public class DoctorTeamGuidanceService extends BaseService {
        switch (saveAsGuidance) {
            case 1:
                //      保存为个人模板
                //      保存为个人模板 去除个人模板标题重复
                //        验证模板名称唯一性
                List<DoctorGuidanceTemp> templates = guidanceTempDao.findByTitle(title);
                if (templates != null && templates.size() != 0) {
                    throw new Exception("个人模板标题重复");
                }
                DoctorGuidanceTemp doctorGuidanceTemp = new DoctorGuidanceTemp();
                doctorGuidanceTemp.setCode(getCode());
                doctorGuidanceTemp.setImagesUrl(image);
@ -136,24 +150,53 @@ public class DoctorTeamGuidanceService extends BaseService {
                doctorGuidanceTemp.setModelName(title);
                doctorGuidanceTemp.setOwner(doctor);
                doctorGuidanceTemp.setLastTime(new Date());
                doctorGuidanceTemp.setSendTimes(0);
                doctorGuidanceTemp.setSendTimes(1);
                doctorGuidanceTempDao.save(doctorGuidanceTemp);
            case 0:
                //                        数据库中拥有该模板的所有团队
                List<DoctorTeamGuidanceTemplate> teamIds = doctorTeamGuidanceTemplateDao.getTeamsByGuidance(guidanceCode);
                List teamList = new ArrayList();
                List tempTeams = new ArrayList();
                for (DoctorTeamGuidanceTemplate team : teamIds) {
                    teamList.add(team.getTeamId());
                }
                for (Object team : teams) {
                    JSONObject teamJson = new JSONObject(team.toString());
                    int teamId = teamJson.getInt("teamId");
                    tempTeams.add(teamId);
                    String teamName = teamJson.getString("teamName");
//                    团队内模板标题要去重复(去掉自身)
                    List<DoctorTeamGuidanceTemplate> list = doctorTeamGuidanceTemplateDao.distinctByTeamTitle(title, teamId);
                    if (list.size() <= 1) {
                        doctorTeamGuidanceTemplateDao.modifyTeamGuidance(teamId,guidanceCode, title);
//                        直接失效原有团队模板对应关系  在重新新增以前没有的团队关系 发送次数要归0
                        if (teamList.contains(teamId)) {
//                            数据库有
                            doctorTeamGuidanceTemplateDao.modifyTeamGuidance(teamId, guidanceCode, title);
                        }else if (!teamList.contains(teamId)){
                            //                        现在有,而数据库没有 要新增
                            DoctorTeamGuidanceTemplate doctorTeamGuidanceTemplate = new DoctorTeamGuidanceTemplate();
                            doctorTeamGuidanceTemplate.setCreater(doctor);
                            doctorTeamGuidanceTemplate.setCreateTime(new Date());
                            doctorTeamGuidanceTemplate.setDel(1);
                            doctorTeamGuidanceTemplate.setTeamId(teamId);
                            doctorTeamGuidanceTemplate.setTeamName(teamName);
                            doctorTeamGuidanceTemplate.setTitle(title);
                            doctorTeamGuidanceTemplate.setTeamTemplateCode(guidanceCode);
                            doctorTeamGuidanceTemplate.setUseTimes(0);
                            doctorTeamGuidanceTemplateDao.save(doctorTeamGuidanceTemplate);
                        }
                    } else {
                        throw new Exception(teamName + ":团队标题重复!");
                    }
                    //                直接修改团队模板后修改模板团队对应表
                    doctorTeamGuidanceDetailDao.modifyTeamGuidanceDetail(title, content, image, guidanceCode);
                }
                break;
//                            数据库有,而现在没有
                teamList.removeAll(tempTeams);
                for (Object team:teamList) {
                    doctorTeamGuidanceTemplateDao.deleteTeamGuidance(Integer.parseInt(team.toString()), guidanceCode);
                }
        }
    }

+ 24 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/template/DoctorGuidanceTempController.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.web.doctor.template;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.template.DoctorGuidanceTemp;
import com.yihu.wlyy.repository.template.DoctorGuidanceTempDao;
import com.yihu.wlyy.service.template.DoctorGuidanceTempService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
@ -31,9 +32,12 @@ public class DoctorGuidanceTempController extends BaseController {
    @Autowired
    DoctorGuidanceTempService guidanceTempService;
    @Autowired
    DoctorGuidanceTempDao guidanceTempDao;
    /**
     * 查询单个模板详情
     *
     * @return
     */
    @RequestMapping(value = "/listDetail", method = RequestMethod.GET)
@ -86,11 +90,16 @@ public class DoctorGuidanceTempController extends BaseController {
            if (StringUtils.isEmpty(content)) {
                return error(-1, "内容不能为空");
            }
            if(modelName.length()<1||modelName.length()>10){
                return error(-1,"模板名称不能为空且在10字之内");
            if (modelName.length() < 1 || modelName.length() > 10) {
                return error(-1, "模板名称不能为空且在10字之内");
            }
            //        验证模板名称唯一性
            List<DoctorGuidanceTemp> templates = guidanceTempDao.findByTitle(modelName);
            if (templates != null && templates.size() != 0) {
                return error(-1, "模板名称与现有模板重复,请修改");
            }
            DoctorGuidanceTemp temp = guidanceTempService.add(getUID(), content,modelName,imagesUrl);
            DoctorGuidanceTemp temp = guidanceTempService.add(getUID(), content, modelName, imagesUrl);
            if (temp != null) {
                return write(200, "添加成功");
@ -117,8 +126,8 @@ public class DoctorGuidanceTempController extends BaseController {
    public String modify(@RequestParam @ApiParam(value = "指导编码") String code,
                         @RequestParam @ApiParam(value = "模板标题") String modelName,
                         @RequestParam @ApiParam(value = "指导内容") String content,
                         @RequestParam(required = false) @ApiParam(value = "图片地址")  String imagesUrl
                         ) {
                         @RequestParam(required = false) @ApiParam(value = "图片地址") String imagesUrl
    ) {
        try {
            if (StringUtils.isEmpty(code)) {
                return error(-1, "请指定需修改的模板");
@ -128,11 +137,16 @@ public class DoctorGuidanceTempController extends BaseController {
                return error(-1, "内容不能为空");
            }
            if (StringUtils.isEmpty(modelName)||modelName.length()>10) {
            if (StringUtils.isEmpty(modelName) || modelName.length() > 10) {
                return error(-1, "内容10个汉字之内且不能为空");
            }
//            验证模板名称唯一性 还要去除掉其本身
            List<DoctorGuidanceTemp> templates = guidanceTempDao.findByTitle(modelName);
            if (templates != null && templates.size() > 1) {
                return error(-1, "模板名称与现有模板重复,请修改");
            }
            DoctorGuidanceTemp temp = guidanceTempService.modify(code,modelName,content,imagesUrl);
            DoctorGuidanceTemp temp = guidanceTempService.modify(code, modelName, content, imagesUrl);
            if (temp != null) {
                return write(200, "修改成功");
@ -182,12 +196,12 @@ public class DoctorGuidanceTempController extends BaseController {
    @ApiOperation(value = "查询指导模板")
    public String list(@RequestParam(required = false, defaultValue = "")
                       @ApiParam(value = "模板类型 1:系统 2:自定义 为空:所有") String type,
                       @RequestParam(defaultValue = "10")  String pageSize,
                       @RequestParam(defaultValue = "10") String pageSize,
                       @RequestParam(defaultValue = "1") @ApiParam(value = "当前页码") String pageNo) {
        try {
            int pagesize = Integer.parseInt(pageSize);
            int pageno = Integer.parseInt(pageNo)-1;
            List<Map<String,Object>> temps = guidanceTempService.list(getUID(), type,pagesize,pageno);
            int pageno = Integer.parseInt(pageNo) - 1;
            List<Map<String, Object>> temps = guidanceTempService.list(getUID(), type, pagesize, pageno);
            if (temps == null || temps.size() < 1) {
                return write(200, "查询成功", "data", new JSONArray());

+ 6 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/template/DoctorTeamGuidanceController.java

@ -106,7 +106,7 @@ public class DoctorTeamGuidanceController extends WeixinBaseController {
            @ApiParam(value = "团队模板编码")
            @RequestParam String teamTemplateCode) {
        try {
            JSONObject guidanceDetail = doctorTeamGuidanceService.getTeamGuidanceDetail(teamId,teamTemplateCode);
            JSONObject guidanceDetail = doctorTeamGuidanceService.getTeamGuidanceDetail(teamId, teamTemplateCode);
            return write(200, "获取模板详情成功!", "guidanceDetail", guidanceDetail);
        } catch (Exception e) {
            return invalidUserException(e, -1, e.getMessage());
@ -172,12 +172,15 @@ public class DoctorTeamGuidanceController extends WeixinBaseController {
            @RequestParam String teamInfo,
            @ApiParam(value = "模板内容")
            @RequestParam String content,
            @ApiParam(value = "是否团队长")
            @RequestParam String isLeader,
            @ApiParam(value = "图片路径")
            @RequestParam(required = false) String images) {
        try {
//            新增修改权限,只有创建者和团队长才能修改
            String doctor = getUID();
            JSONArray teams = new JSONArray(teamInfo);
            doctorTeamGuidanceService.modifyTeamGuidance(doctor, saveAsGuidance, guidanceCode, title, teams, content, images);
            doctorTeamGuidanceService.modifyTeamGuidance(doctor,isLeader, saveAsGuidance, guidanceCode, title, teams, content, images);
            return write(200, "修改团队模板成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, e.getMessage());
@ -206,7 +209,7 @@ public class DoctorTeamGuidanceController extends WeixinBaseController {
            @RequestParam String guidanceCode) {
        try {
            String doctor = getUID();
            doctorTeamGuidanceService.deleteTeamGuidance(doctor,deleteAll, teamId, guidanceCode);
            doctorTeamGuidanceService.deleteTeamGuidance(doctor, deleteAll, teamId, guidanceCode);
            return write(200, "删除模板成功!");
        } catch (Exception e) {
            return invalidUserException(e, -1, e.getMessage());