|
@ -120,29 +120,24 @@ public class DoctorTeamGuidanceService extends BaseService {
|
|
|
* @param images
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public void modifyTeamGuidance(String doctor, String isLeader, int saveAsGuidance, String guidanceCode, String title,
|
|
|
JSONArray teams, String content, String images) throws Exception {
|
|
|
public void modifyTeamGuidance(String doctor, String isLeader,int saveAsGuidance,Boolean isRepeat , 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)) {
|
|
|
image = validateImages(images);
|
|
|
}
|
|
|
|
|
|
switch (saveAsGuidance) {
|
|
|
case 1:
|
|
|
// 保存为个人模板 去除个人模板标题重复
|
|
|
// 验证模板名称唯一性
|
|
|
List<DoctorGuidanceTemp> templates = guidanceTempDao.findByTitle(title);
|
|
|
if (templates != null && templates.size() != 0) {
|
|
|
throw new Exception("个人模板标题重复");
|
|
|
}
|
|
|
DoctorGuidanceTemp doctorGuidanceTemp = new DoctorGuidanceTemp();
|
|
|
if (saveAsGuidance == 1) {
|
|
|
// 保存为个人模板 去除个人模板标题重复 个人模板重复和修改是分开的互不影响
|
|
|
// 验证模板名称唯一性
|
|
|
List<DoctorGuidanceTemp> templates = guidanceTempDao.findByTitle(doctor, title);
|
|
|
DoctorGuidanceTemp doctorGuidanceTemp = new DoctorGuidanceTemp();
|
|
|
if (!isRepeat) {
|
|
|
doctorGuidanceTemp.setCode(getCode());
|
|
|
doctorGuidanceTemp.setImagesUrl(image);
|
|
|
doctorGuidanceTemp.setCreateTime(new Date());
|
|
@ -152,51 +147,104 @@ public class DoctorTeamGuidanceService extends BaseService {
|
|
|
doctorGuidanceTemp.setLastTime(new Date());
|
|
|
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");
|
|
|
}
|
|
|
|
|
|
if ((!doctor.equals(creater)) && (!"1".equals(isLeader))) {
|
|
|
throw new Exception("没有修改权限");
|
|
|
}
|
|
|
// 数据库中拥有该模板的所有团队
|
|
|
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) {
|
|
|
List<DoctorTeamGuidanceTemplate> list = doctorTeamGuidanceTemplateDao.distinctByTeamTitle(title, teamId);
|
|
|
if (list.size() <= 1) {
|
|
|
// 直接失效原有团队模板对应关系 在重新新增以前没有的团队关系 发送次数要归0
|
|
|
if (teamList.contains(teamId)) {
|
|
|
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 + ":团队标题重复!");
|
|
|
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);
|
|
|
}
|
|
|
// 直接修改团队模板后修改模板团队对应表
|
|
|
doctorTeamGuidanceDetailDao.modifyTeamGuidanceDetail(title, content, image, guidanceCode);
|
|
|
} else {
|
|
|
throw new Exception(teamName + ":团队标题重复!");
|
|
|
}
|
|
|
// 直接修改团队模板后修改模板团队对应表
|
|
|
doctorTeamGuidanceDetailDao.modifyTeamGuidanceDetail(title, content, image, guidanceCode);
|
|
|
}
|
|
|
// 数据库有,而现在没有
|
|
|
teamList.removeAll(tempTeams);
|
|
|
for (Object team:teamList) {
|
|
|
doctorTeamGuidanceTemplateDao.deleteTeamGuidance(Integer.parseInt(team.toString()), guidanceCode);
|
|
|
}
|
|
|
teamList.removeAll(tempTeams);
|
|
|
for (Object team : teamList) {
|
|
|
doctorTeamGuidanceTemplateDao.deleteTeamGuidance(Integer.parseInt(team.toString()), guidanceCode);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else if (saveAsGuidance == 0) {
|
|
|
if ((!doctor.equals(creater)) && (!"1".equals(isLeader))) {
|
|
|
throw new Exception("没有修改权限");
|
|
|
}
|
|
|
// 数据库中拥有该模板的所有团队
|
|
|
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) {
|
|
|
// 直接失效原有团队模板对应关系 在重新新增以前没有的团队关系 发送次数要归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);
|
|
|
}
|
|
|
// 数据库有,而现在没有
|
|
|
teamList.removeAll(tempTeams);
|
|
|
for (Object team : teamList) {
|
|
|
doctorTeamGuidanceTemplateDao.deleteTeamGuidance(Integer.parseInt(team.toString()), guidanceCode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|