package com.yihu.wlyy.service.app.label; import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabel; import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelLog; import com.yihu.wlyy.repository.doctor.SignPatientLabelDao; import com.yihu.wlyy.repository.doctor.SignPatientLabelLogDao; import com.yihu.wlyy.service.BaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 标签服务类 *

* Created by lyr on 2016/10/9. */ @Service @Transactional public class SignPatientLabelService extends BaseService { @Autowired SignPatientLabelDao labelDao; @Autowired SignPatientLabelLogDao labelLogDao; /** * 新增自定义标签 * * @param lableName 标签名称 * @param creator 创建人 * @param teamCode 所属团队 * @return */ public SignPatientLabel addLabel(String lableName, String creator, long teamCode) { SignPatientLabel label = new SignPatientLabel(); label.setLabelCode(getCode()); label.setLabelName(lableName); label.setLabelType("4"); label.setIsSystem(1); label.setCreator(creator); label.setTeamCode(teamCode); label.setStatus(1); label.setCzrq(new Date()); return labelDao.save(label); } /** * 修改某个自定义标签 * * @param labelCode 标签code * @param newName 新名称 * @return */ public int modifyLabel(String labelCode, String newName, String modifyBy) { SignPatientLabel label = labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode, "4", 1); if (label == null) { // 标签不存在 return -1; } if (label.getIsSystem() == 1) { // 系统标签不能修改 return -2; } SignPatientLabelLog log = new SignPatientLabelLog(); log.setLabelCode(labelCode); log.setOldName(label.getLabelName()); log.setNewName(newName); log.setModifyType(1); log.setModifyBy(modifyBy); log.setCzrq(new Date()); label.setLabelName(newName); label.setCzrq(new Date()); labelLogDao.save(log); return 1; } /** * 删除某个自定义标签 * * @param labelCode 标签code * @return */ public int deleteLabel(String labelCode, String modifyBy) { SignPatientLabel label = labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode, "4", 1); if (label == null) { // 标签不存在 return -1; } if (label.getIsSystem() == 1) { // 系统标签不能删除 return -2; } SignPatientLabelLog log = new SignPatientLabelLog(); log.setLabelCode(labelCode); log.setModifyType(2); log.setModifyBy(modifyBy); log.setCzrq(new Date()); label.setStatus(0); label.setCzrq(new Date()); labelLogDao.save(log); return 1; } /** * 查询某个团队的标签 * * @param teamCode 团队code * @return */ public List getTeamAllLabels(long teamCode) { List labels = new ArrayList<>(); // 非自定义系统标签 List systemLabels = labelDao.findSystemLabels(); if (systemLabels.size() > 0) { labels.addAll(systemLabels); } // 自定义标签 List customLabels = labelDao.findCustomLabels(teamCode); if (customLabels.size() > 0) { labels.addAll(customLabels); } return labels; } /** * 查询某个团队的自定义标签 * * @param teamCode 团队code * @return */ public List getLabelsByTypeAndTeam(String labelType, long teamCode) { List labels = new ArrayList<>(); if (labelType.equals("4")) { // 自定义标签 labels = labelDao.findCustomLabels(teamCode); } else { labels = labelDao.findByLabelTypeAndStatus(labelType, 1); } return labels; } /** * 查询某个标签 * * @param labelCode 标签code * @param labelType 标签类型 * @return */ public SignPatientLabel getLabelByCodeAndType(String labelCode, String labelType) { return labelDao.findByLabelCodeAndLabelTypeAndStatus(labelCode,labelType,1); } }