Forráskód Böngészése

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

wujunjie 7 éve
szülő
commit
972bc5ec5d

+ 362 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/controller/manager/notification/WeChatController.java

@ -0,0 +1,362 @@
package com.yihu.wlyy.controller.manager.notification;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.controller.BaseController;
import com.yihu.wlyy.entity.User;
import com.yihu.wlyy.entity.WlyyAuditNotice;
import com.yihu.wlyy.entity.WlyyAuditNoticeScope;
import com.yihu.wlyy.entity.WlyyUserRole;
import com.yihu.wlyy.service.manager.notification.WlyyAuditNoticeScopeService;
import com.yihu.wlyy.service.manager.notification.WlyyAuditNoticeService;
import com.yihu.wlyy.service.manager.wlyyrole.WlyyUserRoleService;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
 * Created by yww on 2017/1/22.
 */
@Controller
@RequestMapping("/admin/notification")
public class NotificationController extends BaseController {
    @Autowired
    private WlyyAuditNoticeService wlyyAuditNoticeService;
    @Autowired
    private WlyyAuditNoticeScopeService wlyyAuditNoticeScopeService;
    @Autowired
    private WlyyUserRoleService wlyyUserRoleService;
    @RequestMapping(value = "initial", method = RequestMethod.GET)
    @ApiIgnore
    public String notificationListInitial(Model model) {
        User currentUser = (User) request.getSession().getAttribute("current_user");
        model.addAttribute("isAuditor", wlyyAuditNoticeService.isAuditor(currentUser));
        return "notification/notification_list";
    }
    //跳转消息通知详情页
    @RequestMapping(value = "view", method = RequestMethod.GET)
    @ApiIgnore
    public String notificationView(Model model, @RequestParam(value = "id", required = true) Long id, String mode) {
        User currentUser = (User) request.getSession().getAttribute("current_user");
        WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
        WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeService.findByNoticeId(id);
        model.addAttribute("notice", notice);
        model.addAttribute("noticeId", notice.getId());
        model.addAttribute("title", notice.getTitle());
        model.addAttribute("status", notice.getStatus());
        model.addAttribute("time", notice.getSendTime());
        model.addAttribute("scope", notice.getConditionDescription());
        model.addAttribute("content", notice.getContent());
        model.addAttribute("totalCount", "总共 " + notice.getTotalCount() + " 人");
        model.addAttribute("isAuditor", wlyyAuditNoticeService.isAuditor(currentUser));
        model.addAttribute("isOwned", false);//页面判断用于显示操作按钮
        if (StringUtils.equals(notice.getApplyUserId(), currentUser.getCode())) {
            model.addAttribute("isOwned", true);
        }
        if (noticeScope != null) {
            if (!StringUtils.isEmpty(noticeScope.getServerTypeContent())) {
                model.addAttribute("serverTypeContent", noticeScope.getServerTypeContent());
            }
            if (!StringUtils.isEmpty(noticeScope.getHealthSituationContent())) {
                model.addAttribute("healthSituationContent", noticeScope.getHealthSituationContent());
            }
            if (!StringUtils.isEmpty(noticeScope.getDiseaseTypeContent())) {
                model.addAttribute("diseaseTypeContent", noticeScope.getDiseaseTypeContent());
            }
        }
        model.addAttribute("mode",mode);
        return "notification/notification_view";
    }
    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ResponseBody
    public String searchNotificationList(
            @ApiParam(name = "searchNm", value = "标题/提交人名")
            @RequestParam(value = "searchNm", required = false) String searchNm,
            @ApiParam(name = "status", value = "状态")
            @RequestParam(value = "status", required = false) String status,
            @ApiParam(name = "page")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "rows")
            @RequestParam(value = "rows") int pageSize) {
        try {
            User currentUser = (User) request.getSession().getAttribute("current_user");
            Page<WlyyAuditNotice> notices = wlyyAuditNoticeService.searchList(searchNm, status, currentUser, page, pageSize);
            return write(200, "操作成功", page, pageSize, notices);
        } catch (Exception ex) {
            error(ex);
            return error(-1, "操作失败");
        }
    }
    //页面跳转(详情页面)
    @RequestMapping(value ="infoInit/{id}",method = RequestMethod.GET)
    public String infoInit(@PathVariable("id") Long id, String mode){
        if(id==0){
            request.setAttribute("UUID", UUID.randomUUID().toString().replace("-", ""));
        }
        User currentUser = (User) request.getSession().getAttribute("current_user");
        //范围权限
        String city = "350200";
        String cityAuthority = "0";
        String areaAuthority = "0";
        String communityAuthority = "0";
        List<Map<String, String>> roleMap = (List<Map<String, String>>)request.getSession().getAttribute("roleMap");
        if(roleMap.size()>0){//管理员
            for (Map<String, String> map : roleMap){
                String code = map.get("code");
                if(city.equals(code)){
                    cityAuthority = "1";
                    areaAuthority = "1";
                    communityAuthority = "1";
                }else if(code.length()==6){
                    areaAuthority = "1";
                    communityAuthority = "1";
                }else {
                    communityAuthority = "1";
                }
            }
        }else{
            //社区医生
            communityAuthority = "2";
        }
        request.setAttribute("cityAuthority", cityAuthority);
        request.setAttribute("areaAuthority", areaAuthority);
        request.setAttribute("communityAuthority", communityAuthority);
        request.setAttribute("id", id);
        request.setAttribute("mode",mode);
        request.setAttribute("isAuditor", wlyyAuditNoticeService.isAuditor(currentUser));
        return "notification/notification_edit";
    }
    //根据id获取单个
    @RequestMapping(value = "notice")
    @ResponseBody
    public String getNotice(@RequestParam(value = "id") Long id){
        try {
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeService.findByNoticeId(id);
            JSONObject json = new JSONObject();
            json.put("noticeId",notice.getId());
            json.put("title",notice.getTitle());
            json.put("content",notice.getContent());
            json.put("sendTime",notice.getSendTime());
            json.put("sendType",notice.getSendType());
            json.put("scope",noticeScope.getScope());
            json.put("scopeId",noticeScope.getScopeId());
            json.put("condition",noticeScope.getCondition());
            json.put("diseaseTypeId",noticeScope.getDiseaseTypeId());
            json.put("healthSituationId",noticeScope.getHealthSituationId());
            json.put("serverTypeId",noticeScope.getServerTypeId());
            return write(200,"操作成功!","data",json);
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    /**
     * 是否有有审核权限
     * @return
     */
    @RequestMapping(value = "isNoticeAuditor")
    @ResponseBody
    public String isNoticeAuditor(){
        try {
            User currentUser = (User) request.getSession().getAttribute("current_user");
            boolean flag = wlyyAuditNoticeService.isNoticeAuditor(currentUser.getCode(),String.valueOf(currentUser.getOrganizationId()));
            if(flag){
                return write(200,"有权限!","authority","1");
            }
            return write(200,"没权限!","authority","0");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    //新增
    @RequestMapping(value = "create")
    @ResponseBody
    public String createNotice(String jsonData) {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String,String> map = objectMapper.readValue(jsonData, Map.class);
            User currentUser = (User) request.getSession().getAttribute("current_user");
            wlyyAuditNoticeService.create(map, currentUser);
            return success("新增成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "新增失败!");
        }
    }
    /**
     * 提交
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "submit")
    @ResponseBody
    public String submit(
            @RequestParam(value = "id", required = true) Long id) {
        try {
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            User currentUser = (User) request.getSession().getAttribute("current_user");
            //判断是否为审核者(审核者只能看到非本人的待审核通知,看不到待提交通知)
            if (!StringUtils.equals("1", notice.getStatus())) {
                return error(-1, "提交状态的消息通知才能进行提交操作!");
            }
            boolean res = wlyyAuditNoticeService.isAuditor(currentUser);
            if (res) {
                //审核者自己的消息通知,直接通过+发信息+保存发送对象信息
                wlyyAuditNoticeService.approve(id, notice, currentUser);
                return write(200, "操作成功");
            } else {
                notice.setStatus("2");
                wlyyAuditNoticeService.save(notice);
                return write(200, "操作成功");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    /**
     * 撤回
     * @param id
     * @return
     */
    @RequestMapping(value = "revoke")
    @ResponseBody
    public String revoke(
            @RequestParam(value = "id", required = true) Long id){
        try {
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            if("2".equals(notice.getStatus())){//待审核
                notice.setStatus("6");//撤回
                wlyyAuditNoticeService.save(notice);
            }else{
                return error(-1, "撤回失败,只有待审核才能撤回!");
            }
            return success("撤回成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "撤回失败!");
        }
    }
    //修改
    @RequestMapping(value = "update")
    @ResponseBody
    public String updateNotice(String jsonData){
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            Map<String,String> map = objectMapper.readValue(jsonData, Map.class);
            User currentUser = (User) request.getSession().getAttribute("current_user");
            wlyyAuditNoticeService.updateNotice(map, currentUser);
            return success("修改成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "修改失败!");
        }
    }
    //删除
    @RequestMapping(value = "delete")
    @ResponseBody
    public String deleteNotification(long id) {
        try {
            User currentUser = (User) request.getSession().getAttribute("current_user");
            //是本人的消息通知才能删除
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            if (notice == null) {
                return error(-1, "id有误!");
            }
            if (!StringUtils.equals(notice.getApplyUserId(), currentUser.getCode())) {
                return error(-1, "非本人的消息通知,没有权限删除!");
            }
            wlyyAuditNoticeService.deleteNotice(id);
            return write(200, "操作成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    //审核通过
    @RequestMapping(value = "approve")
    @ResponseBody
    public String approve(long id) {
        try {
            User currentUser = (User) request.getSession().getAttribute("current_user");
            //验证消息通知为待审核
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            if (notice == null) {
                return error(-1, "提供的id有误!");
            }
            if (!StringUtils.equals("2", notice.getStatus())) {
                return error(-1, "消息状态不符,待审核状态才能进行审核操作!");
            }
            String auditorCode = currentUser.getCode();
            String noticeHospital = notice.getApplyUserHospital();
            if (StringUtils.isEmpty(noticeHospital)) {
                return error(-1, "消息通知机构信息有误,为空值!");
            }
            //审核权限验证(审核者的下辖机构有此消息通知编辑者所属机构)
            boolean res = wlyyAuditNoticeService.isNoticeAuditor(auditorCode, noticeHospital);
            wlyyAuditNoticeService.approve(id, notice, currentUser);
            return write(200, "操作成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
    @RequestMapping(value = "refuse")
    @ResponseBody
    public String refuse(
            @RequestParam(value = "id", required = true) Long id) {
        try {
            if (id == null) {
                return error(-1, "id不能为空!");
            }
            User currentUser = (User) request.getSession().getAttribute("current_user");
            //是本人的消息通知才能删除
            WlyyAuditNotice notice = wlyyAuditNoticeService.retrieve(id);
            if (notice == null) {
                return error(-1, "id有误!");
            }
            notice.setStatus("5");
            wlyyAuditNoticeService.save(notice);
            return write(200, "操作成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "操作失败!");
        }
    }
}

+ 147 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/wechat/WechatTemplateConfig.java

@ -0,0 +1,147 @@
package com.yihu.wlyy.entity.wechat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * 微信消息模板按场景区分消息内容
 * @author WuJunjie
 */
@Entity
@Table(name = "weixin_template_config")
public class WechatTemplateConfig extends IdEntity {
	private static final long serialVersionUID = -7399054549159698617L;
	private String templateName;//'自定义模板名称'
    private String scene;//使用场景值
    private String sceneDescription;//'使用场景描述'
    private String first;
    private String url;//模板消息'跳转链接'
    private String remark;
    private String keyword1;
    private String keyword2;
    private String keyword3;
    private String keyword4;
    private String keyword5;
    private String keyword6;
    private String keyword7;
    private Integer status;//状态 1:正常 0:删除
    public static long getSerialVersionUID() {
        return serialVersionUID;
    }
    public String getTemplateName() {
        return templateName;
    }
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
    public String getScene() {
        return scene;
    }
    public void setScene(String scene) {
        this.scene = scene;
    }
    public String getSceneDescription() {
        return sceneDescription;
    }
    public void setSceneDescription(String sceneDescription) {
        this.sceneDescription = sceneDescription;
    }
    public String getFirst() {
        return first;
    }
    public void setFirst(String first) {
        this.first = first;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    public String getKeyword1() {
        return keyword1;
    }
    public void setKeyword1(String keyword1) {
        this.keyword1 = keyword1;
    }
    public String getKeyword2() {
        return keyword2;
    }
    public void setKeyword2(String keyword2) {
        this.keyword2 = keyword2;
    }
    public String getKeyword3() {
        return keyword3;
    }
    public void setKeyword3(String keyword3) {
        this.keyword3 = keyword3;
    }
    public String getKeyword4() {
        return keyword4;
    }
    public void setKeyword4(String keyword4) {
        this.keyword4 = keyword4;
    }
    public String getKeyword5() {
        return keyword5;
    }
    public void setKeyword5(String keyword5) {
        this.keyword5 = keyword5;
    }
    public String getKeyword6() {
        return keyword6;
    }
    public void setKeyword6(String keyword6) {
        this.keyword6 = keyword6;
    }
    public String getKeyword7() {
        return keyword7;
    }
    public void setKeyword7(String keyword7) {
        this.keyword7 = keyword7;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 71 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/wechat/WeixinTemplate.java

@ -0,0 +1,71 @@
package com.yihu.wlyy.entity.wechat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * @Description: 记录各公众号模板详情及自定义类型
 * @Author: WuJunjie
 * @Date: Created in 2018/2/24 17:38
 */
@Entity
@Table(name = "weixin_template")
public class WeixinTemplate  extends IdEntity {
    private String accId;//'微信公众号原始ID'
    private String templateName;//'自定义模板名称'
    private String templateTitle;//'模板标题'
    private Integer type;//'自定义模板类型'
    private String format;//'模板内容格式'
    private Integer status;//'模板状态 1:正常  0:删除'
    public String getAccId() {
        return accId;
    }
    public void setAccId(String accId) {
        this.accId = accId;
    }
    public String getTemplateName() {
        return templateName;
    }
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
    public String getTemplateTitle() {
        return templateTitle;
    }
    public void setTemplateTitle(String templateTitle) {
        this.templateTitle = templateTitle;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    public String getFormat() {
        return format;
    }
    public void setFormat(String format) {
        this.format = format;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 18 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/repository/wechat/WechatTemplateConfigDao.java

@ -0,0 +1,18 @@
package com.yihu.wlyy.repository.wechat;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @Description: 分场景值查询模板文案内容
 * @Author: WuJunjie
 * @Date: Created in 2018/2/23 11:51
 */
public interface WechatTemplateConfigDao extends PagingAndSortingRepository<WechatTemplateConfig, Long>, JpaSpecificationExecutor<WechatTemplateConfig> {
    //根据自定义模板名称、场景值查询有效模板内容
    @Query("select t  from WechatTemplateConfig t where t.templateName=?1 and t.scene=?2 and t.status = 1 ")
    WechatTemplateConfig findByScene(String templateName,String scene);
}

+ 509 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/wechat/WeChatService.java

@ -0,0 +1,509 @@
package com.yihu.wlyy.service.manager.notification;
import com.yihu.wlyy.entity.*;
import com.yihu.wlyy.repository.*;
import com.yihu.wlyy.service.SMSService;
import com.yihu.wlyy.service.manager.wlyyrole.WlyyRoleService;
import com.yihu.wlyy.service.manager.wlyyrole.WlyyUserRoleService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
 * Created by Administrator on 2017/1/22.
 */
@Service
public class WlyyAuditNoticeService extends BaseJpaService<WlyyAuditNotice, WlyyAuditNoticeDao> {
    @Autowired
    private WlyyRoleDao wlyyRoleDao;
    @Autowired
    private WlyyRoleService roleService;
    @Autowired
    private WlyyUserRoleDao wlyyUserRoleDao;
    @Autowired
    private WlyyUserRoleService wlyyUserRoleService;
    @Autowired
    private WlyyAuditNoticeDao wlyyAuditNoticeDao;
    @Autowired
    private WlyyAuditNoticeScopeDao wlyyAuditNoticeScopeDao;
    @Autowired
    private WlyyAuditNoticeObjectDao wlyyAuditNoticeObjectDao;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SMSService smsService;
    /**
     * 新增消息
     * @param map
     * @param user
     */
    @Transactional
    public void create(Map<String,String> map,User user){
        String communityAuthority = map.get("communityAuthority");
        String scope = map.get("scope");// 0- 全市 1 - 指定区 2 - 指定社区
        String scopeId = map.get("scopeId");//范围明细ID,scope=1时为区ID串,2时为社区id串
        String scopeContent = map.get("scopeContent");//
        String city = map.get("city");
        String town = map.get("town");
        String community = map.get("community");
        String conditionDescription = map.get("conditionDescription");
        String conditionType = map.get("condition_type");//筛选条件:0-全部;1-根据条件
        String condition = map.get("condition");//0 - 全部居民   1 - 设置条件?  设置的条件类别:1:卫计委三大分组(服务类型) 2:健康状况 3:疾病类型
        String conditionId = map.get("conditionId");//0 - 全部居民   1 - 设置条件
        String serverTypeContent = map.get("serverTypeContent");
        String serverTypeId = map.get("serverTypeId");
        String healthSituationContent = map.get("healthSituationContent");
        String healthSituationId = map.get("healthSituationId");
        String diseaseTypeContent = map.get("diseaseTypeContent");
        String diseaseTypeId = map.get("diseaseTypeId");
        String sendType = map.get("sendType");
        String content = map.get("content");
        List<Patient> list = getSendPatients(conditionType, scope, city, town, community, serverTypeId, healthSituationId, diseaseTypeId);
        //需要审核的通知公告主表
        WlyyAuditNotice notice = new WlyyAuditNotice();
        notice.setApplyTime(new Date());
        notice.setApplyUserHospital(user.getOrganizationId()+"");
        notice.setApplyUserId(user.getCode());
        notice.setApplyUserName(user.getName());
        notice.setConditionDescription(conditionDescription);
        notice.setContent(content);
        String status = "";// 0 - 创建(瞬间状态) 1- 待提交  2 - 待审核 3 - 待发送 4 - 已发送  5 - 已拒绝 6 - 撤回(处于待审核时可修改为该状态)
        if("2".equals(communityAuthority)){
            //医生 需要审核
            status = "2";
        }else{
            //管理员 直接发送(设置状态,还未执行)
            status = "4";
            notice.setAuditTime(new Date());
            notice.setAuditUserId(user.getCode());
            notice.setAuditUserName(user.getName());
        }
        notice.setStatus(status);
//        notice.setApplyUserHospital(user.getOrganizationName());
        notice.setSendType(sendType);
        if("1".equals(sendType)){
            notice.setSendTime(DateUtil.strToDateLong(map.get("sendTime")+":00"));
        }
        notice.setTitle(map.get("title"));
        notice.setTotalCount(list.size());
        wlyyAuditNoticeDao.save(notice);
        //消息公告对象范围主表
        WlyyAuditNoticeScope noticeScope = new WlyyAuditNoticeScope();
        noticeScope.setNoticeId(notice.getId());
        noticeScope.setScope(scope);
        noticeScope.setScopeContent(scopeContent);
        noticeScope.setScopeId(scopeId);
//        noticeScope.setCondition(condition);
        noticeScope.setCondition(conditionType);
        noticeScope.setServerTypeId(serverTypeId);
        noticeScope.setServerTypeContent(serverTypeContent);
        noticeScope.setHealthSituationId(healthSituationId);
        noticeScope.setHealthSituationContent(healthSituationContent);
        noticeScope.setDiseaseTypeId(diseaseTypeId);
        noticeScope.setDiseaseTypeContent(diseaseTypeContent);
        noticeScope.setConditionDescription(conditionDescription);
        wlyyAuditNoticeScopeDao.save(noticeScope);
        //审核自身消息通知自己发短信操作(新线程)****************新线程发彩信
        if (isAuditor(user)) {
            sendMsgThread(list, notice);
        }
//        if("3".equals(status)){
//            saveNoticeObject(list,notice);
//        }
    }
    /**
     * 保存消息通知对象
     * @param list
     * @param notice
     */
//    private void saveNoticeObject(List<Patient> list,WlyyAuditNotice notice){
//        //需要审核的通知公告对象
//        WlyyAuditNoticeObject noticeObject = null;
//        List<WlyyAuditNoticeObject> objectList = new ArrayList<>();
//        String mobiles = "";
//        int i = 0;
//        for (Patient p:list){
//            noticeObject = new WlyyAuditNoticeObject();
//            noticeObject.setNoticeId(notice.getId());
//            noticeObject.setToUserId(p.getCode());
//            noticeObject.setToUserTel(p.getMobile());
//            noticeObject.setContent(notice.getContent());
//            //TODO 每次条用发送短信接口,根据返回信息对应更新状态,保存数据(若被中断时?)
//            //smsService.sendMsg(mobiles,content);//判断返回值,设置发送状态--立即发送时
//
//            noticeObject.setStatus(notice.getStatus());//?未发送
//            noticeObject.setSendTime(new Date());
//            noticeObject.setInsertTime(new Date());
//            objectList.add(noticeObject);
//
//            i++;
//            mobiles += p.getMobile()+",";
//            if(i%901==0){//900条发一次
//                mobiles = mobiles.substring(0,mobiles.length()-1);
//                //smsService.sendMsg(mobiles,content);
//                System.out.println("i="+i+"---mobile="+mobiles);
//                mobiles = "";
//            }else if(i==list.size()){
//                mobiles = mobiles.substring(0,mobiles.length()-1);
//                //smsService.sendMsg(mobiles,content);
//                System.out.println("i="+i+"---mobile="+mobiles);
//                mobiles = "";
//            }
//        }
//
//        if(objectList.size()>0){
//            wlyyAuditNoticeObjectDao.save(objectList);
//        }
//    }
    /**
     * 按条件查询居民
     * @param conditionType
     * @param scope
     * @param city
     * @param town
     * @param community
     * @param serverTypeId
     * @param healthSituationId
     * @param diseaseTypeId
     * @return
     */
    public List<Patient> getSendPatients(String conditionType,String scope,String city,String town,String community,String serverTypeId,String healthSituationId,String diseaseTypeId){
        List<Patient> list = null;
        String sql = "";
        //根据发送范围,筛选条件过滤出居民
        if("0".equals(conditionType)){//筛选条件分支:全部居民
            if("0".equals(scope)){
                list = patientDao.findByCity(city);//全市全部居民
            }else if("1".equals(scope)){
                String towns[] = town.split(",");
                list = patientDao.findByCityAndTowns(city,towns);//指定区全部居民
            }else if("2".equals(scope)){
                String communitys[] = community.split(",");
                list = patientDao.findByCityAndHospital(city,communitys);//指定社区全部居民
            }
        }else if ("1".equals(conditionType)){//筛选条件分支:按条件(服务类型、健康状况、疾病类型)
            //筛选条件
            String conditionSql = "";
            if(!StringUtils.isEmpty(serverTypeId)){
                conditionSql += " (s.label_type=1 and s.label in ("+serverTypeId+")) ";
                String[] serverTypeIds = serverTypeId.split(",");
            }
            if(!StringUtils.isEmpty(healthSituationId)){
                if(StringUtils.isEmpty(conditionSql)){
                    conditionSql += " (s.label_type=2 and s.label in ("+healthSituationId+"))";
                }else {
                    conditionSql += " or (s.label_type=2 and s.label in ("+healthSituationId+"))";
                }
                String[] healthSituationIds = healthSituationId.split(",");
            }
            if(!StringUtils.isEmpty(diseaseTypeId)){
                if(StringUtils.isEmpty(conditionSql)){
                    conditionSql += " (s.label_type=3 and s.label in ("+diseaseTypeId+")) ";
                }else {
                    conditionSql += " or (s.label_type=3 and s.label in ("+diseaseTypeId+")) ";
                }
                String[] diseaseTypeIds = diseaseTypeId.split(",");
            }
            //-------------发送范围
            if("0".equals(scope)){
                sql += "SELECT DISTINCT p.* from wlyy_patient p " +
                        " WHERE p.city=350200 and p.mobile is not null and p.mobile!='' and p.code in(select DISTINCT s.patient " +
                        " from wlyy_sign_patient_label_info s " +
                        " where "+conditionSql+")";
                SQLQuery sqlQuery = currentSession().createSQLQuery(sql).addEntity(Patient.class);
                list = sqlQuery.list();
            }else if("1".equals(scope)){
                sql += "SELECT DISTINCT p.* from wlyy_patient p " +
                        " WHERE p.city=350200 and p.town in ("+town+") and p.mobile is not null and p.mobile!='' and p.code in(select DISTINCT s.patient " +
                        " from wlyy_sign_patient_label_info s " +
                        " where "+conditionSql+")";
                SQLQuery sqlQuery = currentSession().createSQLQuery(sql).addEntity(Patient.class);
                list = sqlQuery.list();
            }else if("2".equals(scope)){
                community = "'" + community.replace(",","','") + "'";//字符类型数据库需要添加''
                sql += "SELECT DISTINCT p.* from wlyy_patient p LEFT JOIN wlyy_sign_family f on p.code = f.patient " +
                        " WHERE p.city=350200 and f.hospital in ("+community+") and p.mobile is not null and p.mobile!='' and p.code in(select DISTINCT s.patient " +
                        " from wlyy_sign_patient_label_info s " +
                        " where "+conditionSql+")";
                SQLQuery sqlQuery = currentSession().createSQLQuery(sql).addEntity(Patient.class);
                list = sqlQuery.list();
            }
        }
        return list;
    }
    /**
     * 编辑消息
     * @param map
     * @param user
     */
    @Transactional
    public void updateNotice(Map<String,String> map,User user){
        Long noticeId = Long.parseLong(map.get("id"));
        String communityAuthority = map.get("communityAuthority");
        String scope = map.get("scope");// 0- 全市 1 - 指定区 2 - 指定社区
        String scopeId = map.get("scopeId");//范围明细ID,scope=1时为区ID串,2时为社区id串
        String scopeContent = map.get("scopeContent");//
        String city = map.get("city");
        String town = map.get("town");
        String community = map.get("community");
        String conditionDescription = map.get("conditionDescription");
        String conditionType = map.get("condition_type");//筛选条件:0-全部;1-根据条件
        String serverTypeContent = map.get("serverTypeContent");
        String serverTypeId = map.get("serverTypeId");
        String healthSituationContent = map.get("healthSituationContent");
        String healthSituationId = map.get("healthSituationId");
        String diseaseTypeContent = map.get("diseaseTypeContent");
        String diseaseTypeId = map.get("diseaseTypeId");
        String sendType = map.get("sendType");
        String content = map.get("content");
        List<Patient> list = getSendPatients(conditionType, scope, city, town, community, serverTypeId, healthSituationId, diseaseTypeId);
        //需要审核的通知公告主表
        WlyyAuditNotice notice = wlyyAuditNoticeDao.findOne(noticeId);
//        notice.setApplyTime(new Date());
//        notice.setApplyUserHospital(user.getOrganizationId()+"");
//        notice.setApplyUserId(user.getCode());
//        notice.setApplyUserName(user.getName());
        notice.setConditionDescription(conditionDescription);
        notice.setContent(content);
        //审核者自己的通知直接发送短信,状态为“4”
        if (isAuditor(user)) {
            notice.setStatus("4");
        } else {
            notice.setStatus("2");
        }
        notice.setSendType(sendType);
        if("1".equals(sendType)){
            notice.setSendTime(DateUtil.strToDateLong(map.get("sendTime")+":00"));
        }
        notice.setTitle(map.get("title"));
        notice.setTotalCount(list.size());
        wlyyAuditNoticeDao.save(notice);
        //消息公告对象范围主表
        WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeDao.findByNoticeId(noticeId);
        noticeScope.setScope(scope);
        noticeScope.setScopeContent(scopeContent);
        noticeScope.setScopeId(scopeId);
        noticeScope.setCondition(conditionType);
        noticeScope.setServerTypeId(serverTypeId);
        noticeScope.setServerTypeContent(serverTypeContent);
        noticeScope.setHealthSituationId(healthSituationId);
        noticeScope.setHealthSituationContent(healthSituationContent);
        noticeScope.setDiseaseTypeId(diseaseTypeId);
        noticeScope.setDiseaseTypeContent(diseaseTypeContent);
        noticeScope.setConditionDescription(conditionDescription);
        wlyyAuditNoticeScopeDao.save(noticeScope);
        //审核者本人修改操作,为待审核状态>>直接通过,发送短信**********************新线程发彩信
        if (isAuditor(user)) {
            sendMsgThread(list, notice);
        }
    }
    //查询通知列表
    public Page<WlyyAuditNotice> searchList(String searchNm, String status, User currentUser, int page, int pageSize) throws Exception {
        //1、根据当前用户判断其角色(是否有审核权限)1):无-查询本人的消息通知;有-管辖范围的所有消息通知(包括本人的)-添加是否为本人的标记(是本人的才有编辑、删除等操作)否则只是审核、查看
        boolean auditor = false;
        List<WlyyUserRole> userRoles = wlyyUserRoleDao.findByUser(currentUser.getCode());
        if (page <= 0) {
            page = 1;
        }
        if (pageSize <= 0) {
            pageSize = 15;
        }
        PageRequest pageRequest = new PageRequest(page - 1, pageSize);
        String filters = "";
        if (!StringUtils.isEmpty(searchNm)) {
            filters = "title?" + searchNm + " g1;applyUserName?" + searchNm + " g1;";
        }
        if (!StringUtils.isEmpty(status)) {
            filters += "status=" + status + ";";
        }
        if (userRoles.size() > 0) {
            auditor = true;
            String[] roleCodes = new String[userRoles.size()];
            for (int i = 0; i < userRoles.size(); i++) {
                roleCodes[i] = userRoles.get(i).getRole();
            }
            //获取管辖机构codes
            String applyUserHospital = "";
            List<String> orgCodeList = wlyyUserRoleService.getRoleOrgCodes(roleCodes);
            if (orgCodeList.size() > 0) {
                applyUserHospital = StringUtils.join(orgCodeList, ",");
                filters += "applyUserHospital=" + applyUserHospital + ";";
            }
        } else {
            filters += "applyUserId=" + currentUser.getCode() + ";";  //非管理员只能查看自己的信息通知
        }
        List<WlyyAuditNotice> list = search("", filters, "", page, pageSize);
        for (WlyyAuditNotice notice : list) {
            if (!StringUtils.equals(notice.getApplyUserId(), currentUser.getCode())) {
                notice.setOwned(false);
            }
            if (auditor) {
                notice.setAuditor(true);
            }
        }
        Page<WlyyAuditNotice> res = new PageImpl<WlyyAuditNotice>(list, pageRequest, getCount(filters));
        return res;
    }
    //删除消息通知,同时删除对应的消息通知范围
    @Transactional
    public boolean deleteNotice(Long noticeId) {
        wlyyAuditNoticeDao.delete(noticeId);
        WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeDao.findByNoticeId(noticeId);
        if (noticeScope != null) {
            wlyyAuditNoticeScopeDao.delete(noticeScope.getId());
        }
        return true;
    }
    //审核通过发送短信,保存发送对象
    @Transactional
    public void approve(long noticeId, WlyyAuditNotice notice, User currentUser) {
        //1) 查找出通知范围对象
        WlyyAuditNoticeScope noticeScope = wlyyAuditNoticeScopeDao.findByNoticeId(noticeId);
        String conditionType = noticeScope.getCondition();//筛选条件:0-全部;1-根据条件
        String scope = noticeScope.getScope();// 0- 全市 1 - 指定区 2 - 指定社区
        String scopeId = noticeScope.getScopeId();//范围明细ID,scope=1时为区ID串,2时为社区id串
        // scope为0时-空值;为1时-区编码;为2时区+社区编码
        String city = "350200";//厦门市
        String town = "";
        String community = "";
        String serverTypeId = noticeScope.getServerTypeId();
        String healthSituationId = noticeScope.getHealthSituationId();
        String diseaseTypeId = noticeScope.getDiseaseTypeId();
        if ("1".equals(scope)) {
            town = scopeId;
        }
        if ("2".equals(scope) && !StringUtils.isEmpty(scopeId)) {
            String[] values = scopeId.split(";|;");
            for (String value : values) {
                if (!StringUtils.isEmpty(value)) {
                    community += value.split(":|:")[1] + ",";
                }
            }
        }
        if (!StringUtils.isEmpty(community)) {
            community = community.substring(community.length() - 1);
        }
        //2)查找居民
        List<Patient> list = getSendPatients(conditionType, scope, city, town, community, serverTypeId, healthSituationId, diseaseTypeId);
        //3)发送短信,保存发送对象信息6
        if ("2".equals(notice.getStatus())) {
            notice.setStatus("4");//消息通知修改状态
            notice.setAuditUserId(currentUser.getCode());//审核者编码
            notice.setAuditUserName(currentUser.getName());//审核者名称
            wlyyAuditNoticeDao.save(notice);
            //审核通过发送短信*******************新线程
            sendMsgThread(list, notice);
        }
    }
    //判断是否具有对当前消息的审核权限
    public boolean isNoticeAuditor(String auditorCode, String noticeHospital) {
        String[] roleCodes = wlyyRoleDao.findRoleCodesByUser(auditorCode);
        if (roleCodes == null || roleCodes.length <= 0) {
            return false;
        }
        List<String> roleOrgCodes = wlyyUserRoleService.getRoleOrgCodes(roleCodes);
        if (roleOrgCodes != null && roleOrgCodes.size() > 0) {
            return roleOrgCodes.contains(noticeHospital);
        }
        return false;
    }
    //判断当前用户是否是审核者
    public boolean isAuditor(User currentUser) {
        List<WlyyUserRole> userCode = wlyyUserRoleService.findByUserCode(currentUser.getCode());
        if (userCode != null && userCode.size() > 0) {
            return true;
        }
        return false;
    }
    //开启发送短信线程
    private void sendMsgThread(List<Patient> list, WlyyAuditNotice notice) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                sendMsg(list, notice);
            }
        });
        t.start();
    }
    //发送短信
    private void sendMsg(List<Patient> list, WlyyAuditNotice notice) {
        WlyyAuditNoticeObject noticeObject = null;
        List<WlyyAuditNoticeObject> objectList = new ArrayList<>();
        String mobiles = "";
        int i = 0;
        for (Patient p : list) {
            noticeObject = new WlyyAuditNoticeObject();
            noticeObject.setNoticeId(notice.getId());
            noticeObject.setToUserId(p.getCode());
            noticeObject.setToUserTel(p.getMobile());
            noticeObject.setContent(notice.getContent());
            noticeObject.setSendTime(new Date());
            noticeObject.setInsertTime(new Date());
            noticeObject.setStatus("1");//TODO 短信发送状态(1为已发送),待修改
            objectList.add(noticeObject);
            i++;
            mobiles += p.getMobile() + ",";
            if (i % 901 == 0) {//900条发一次
                mobiles = mobiles.substring(0, mobiles.length() - 1);
                //smsService.sendMsg(mobiles,content);
                System.out.println("i=" + i + "---mobile=" + mobiles);
                mobiles = "";
            } else if (i == list.size()) {
                mobiles = mobiles.substring(0, mobiles.length() - 1);
                //smsService.sendMsg(mobiles,content);
                System.out.println("i=" + i + "---mobile=" + mobiles);
                mobiles = "";
            }
        }
        //暂时未审核后才保存发送对象+发送短信,那是否有保存改发送对象信息的必要?(数据量大)
//        if (objectList.size() > 0) {
//            wlyyAuditNoticeObjectDao.save(objectList);
//        }
    }
}

+ 191 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_edit.jsp

@ -0,0 +1,191 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<%@ include file="../head/page_head.jsp"%>
	<title>机构管理</title>
</head>
<style>
	.m-form-group label.label_title {
		width: 100px
	}
	.m-form-group p.tip {
		width: auto;
        margin-left: 100px;
        line-height: 20px;
	}
	.m-form-group ul li{
		line-height: 30px;
		margin-left: 100px;
	}
	.m-form-group .inpRadio{
		 vertical-align: bottom;
		 margin: 8px 0 0;
	 }
	.m-form-group .inpChkb{
		vertical-align: sub;
	}
	.m-form-group .l-text-date{
		width: 140px;
	}
	.m-form-group .sendTime{
		width: 138px;
	}
    .m-form-group  span.community{
        width: 50px;
        display: inline-flex;
    }
	.f-pa{
		position: relative;
	}
	.f-pa .m-form-control{
		margin-left: 200px;
		margin-top: 10px;
	}
	.wordwrap{
		float: left;
		display: block;
		margin: 140px 0 0 10px;
	}
	.wordCount .word{
		color: red;
		padding: 0 4px;
	}
	#messageContent .j-text-wrapper{
		float: left;
	}
	#messageContent .l-text-trigger-cancel{
		display: none!important;
	}
</style>
<body>
<div id="div_roles_info_form" class="m-form-inline f-mt20 f-ml30"
	 data-role-form>
	<input type="hidden" id="uuid" value='${UUID}'/>
	<input type="hidden" id="cityAuthority" value='${cityAuthority}'/>
	<input type="hidden" id="areaAuthority" value='${areaAuthority}'/>
	<input type="hidden" id="communityAuthority" value='${communityAuthority}'/>
	<input type="hidden" id="mode" value='${mode}'/>
	<input type="hidden" id="scopeId"/>
	<input type="hidden" id="diseaseTypeId"/>
	<input type="hidden" id="healthSituationId"/>
	<input type="hidden" id="serverTypeId"/>
	<input type="hidden" id="noticeId" value='${id}' data-attr-scan="id" />
	<div class="m-form-group">
		<label class="label_title" style="">发送范围:</label>
		<div class="u-radio-wrap m-form-control">
			<input type="radio" value="0" name="scope" id="cityScope" class="inpRadio" data-attr-scan=""> 全市
			<input type="radio" value="1" name="scope" id="areaScope" class="inpRadio" data-attr-scan=""> 指定区
			<input type="radio" value="2" name="scope" id="communityScope" class="inpRadio" data-attr-scan=""> 指定社区
		</div>
	</div>
	<div class="m-form-group" id="scope_area" style="display: none">
		<label class="label_title" style="">选择区:</label>
		<div class="u-checkbox-wrap m-form-control scope_areaDiv">
			<%--<input type="checkbox" name="scope_area" class="inpChkb" value="1" data-attr-scan>选项一--%>
			<%--<input type="checkbox" name="scope_area" class="inpChkb" value="2" data-attr-scan>选项二--%>
			<%--<input type="checkbox" name="scope_area" class="inpChkb" value="3" data-attr-scan>选项三--%>
		</div>
	</div>
	<div class="m-form-group" id="scope_community" style="display: none">
		<label class="label_title" style="">选择社区:</label>
		<div class="m-form-control scope_communityDiv" style="margin-top: 5px;">
			<%--<input type="checkbox" name="scope_community" class="inpChkb" value="1" data-attr-scan>选项一--%>
			<%--<input type="checkbox" name="scope_community" class="inpChkb" value="2" data-attr-scan>选项二--%>
			<%--<input type="checkbox" name="scope_community" class="inpChkb" value="3" data-attr-scan>选项三--%>
		</div>
	</div>
	<div class="m-form-group">
		<label class="label_title" style="">筛选条件:</label>
		<div class="u-radio-wrap m-form-control">
			<input type="radio" value="0" name="condition_type" class="inpRadio" data-attr-scan=""> 全部居民
			<input type="radio" value="1" name="condition_type" class="inpRadio" data-attr-scan=""> 设置条件
		</div>
	</div>
	<div class="m-form-group" id="inpCondition" style="display: none;padding-bottom: 0px">
		<label class="label_title" style=""></label>
		<div class="u-checkbox-wrap m-form-control">
			<input type="checkbox" name="condition" class="inpChkb" value="1" data-class=".serverType" data-name="serverType" data-tip="服务类型" data-attr-scan>按服务类型
			<input type="checkbox" name="condition" class="inpChkb" value="2" data-class=".health_situation" data-name="health_situation" data-tip="健康情况" data-attr-scan>按健康情况
			<input type="checkbox" name="condition" class="inpChkb" value="3" data-class=".diease" data-name="diease" data-tip="疾病类型" data-attr-scan>按疾病类型
		</div>
	</div>
	<div class="m-form-group" style=" ">
		<ul style="display: block; vertical-align: middle;">
			<li>
				<div class="m-form-group serverType" style="display: none;padding-bottom: 0px;">
					<label class="label_title" style="text-align: left;width: auto;line-height: 20px;">服务类型:</label>
					<div class="u-checkbox-wrap m-form-control serverTypeDiv" style="line-height: 20px;">
						<%--<input type="checkbox" name="server" class="inpChkb" value="1" data-attr-scan>按服务类型--%>
						<%--<input type="checkbox" name="server" class="inpChkb" value="2" data-attr-scan>按健康情况--%>
						<%--<input type="checkbox" name="server" class="inpChkb" value="3" data-attr-scan>按疾病类型--%>
					</div>
				</div>
			</li>
			<li>
				<div class="m-form-group health_situation" style="display: none;padding-bottom: 0px;">
					<label class="label_title" style="text-align: left;width: auto;line-height: 20px;">健康情况:</label>
					<div class="u-checkbox-wrap m-form-control health_situationDiv" style="line-height: 20px;">
						<%--<input type="checkbox" name="health_situation" class="inpChkb" value="1" data-attr-scan>按服务类型--%>
						<%--<input type="checkbox" name="health_situation" class="inpChkb" value="2" data-attr-scan>按健康情况--%>
						<%--<input type="checkbox" name="health_situation" class="inpChkb" value="3" data-attr-scan>按疾病类型--%>
					</div>
				</div>
			</li>
			<li>
				<div class="m-form-group diease" style="display: none;padding-bottom: 0px;">
					<label class="label_title" style="text-align: left;width: auto;line-height: 20px;">疾病类型:</label>
					<div class="u-checkbox-wrap m-form-control dieaseDiv" style="line-height: 20px;">
						<%--<input type="checkbox" name="diease" class="inpChkb" value="1" data-attr-scan>按服务类型--%>
						<%--<input type="checkbox" name="diease" class="inpChkb" value="2" data-attr-scan>按健康情况--%>
						<%--<input type="checkbox" name="diease" class="inpChkb" value="3" data-attr-scan>按疾病类型--%>
					</div>
				</div>
			</li>
		</ul>
	</div>
	<div class="m-form-group" style="">
		<label class="label_title" style="">通知标题:</label>
		<div class="l-text-wrapper m-form-control essential">
			<input type="text" id="title" class="required useTitle validate-special-char" required-title="请输入通知标题" placeholder="请输入通知标题" data-attr-scan="title" />
		</div>
	</div>
    <div class="m-form-group">
        <label class="label_title" style="">通知内容:</label>
        <div class="l-text-wrapper m-form-control" id="messageContent">
				<textarea type="text" id="content"  maxlength="120"
                          class="required max-length-120 validate-special-char" placeholder="请输入通知具体内容,最多120字,因每条短信限制70字,若大于70字可能将被分割成两条短信" data-attr-scan="content"></textarea>
				<span class="wordwrap" id="wordwrap"><var class="word">0</var>/120</span>
        </div>
    </div>
	<div class="m-form-group">
		<label class="label_title">发送时间:</label>
		<div class="l-text-wrapper m-form-control useTitle ajax validate-special-char">
			<input id="send_type_combo_select" data-type="text" class="" data-name="text" data-attr-scan="sendType">
		</div>
		<div class="m-form-control essential send_time" style="margin-left: 10px;">
			<input type="text" id="send_time" class="sendTime required" placeholder="输入发送时间"  required-title="不能为空" data-attr-scan="sendTime"/>
		</div>
	</div>
	<div class="m-form-group">
		<p class="tip">1、立即发送,则审核通过后立即发送</p>
		<p class="tip">2、定时发送,则审核通过后将在指定时间发送。如在指定时间前未审核通过,则将自动撤回</p>
	</div>
	<div class="m-form-group f-pa" id="btn_save_close" style="right: 10px;bottom: 0;">
		<div class="m-form-control">
			<input type="button" value="提    交" id="btn_save" class="l-button u-btn u-btn-primary u-btn-large f-ib f-vam" />
			<div id="btn_cancel" class="l-button u-btn u-btn-cancel u-btn-large f-ib f-vam" >
				<span>关闭</span>
			</div>
		</div>
	</div>
</div>
</body>
<%@ include file="../head/page_foot.jsp"%>
<%@ include file="notification_edit_js.jsp" %>
</html>

+ 575 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_edit_js.jsp

@ -0,0 +1,575 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<script language="javascript">
    $(function(){
        //先选出 textarea 和 统计字数 dom 节点
        var wordCount = $("#messageContent"),
                textArea = wordCount.find("textarea"),
                word = wordCount.find(".word");
        //调用
        statInputNum(textArea,word);
    });
    /*
     * 剩余字数统计
     * 注意 最大字数只需要在放数字的节点哪里直接写好即可 如:<var class="word">200</var>
     */
    function statInputNum(textArea,numItem) {
        var max = numItem.text(), curLength;
        curLength = textArea.val().length;
        numItem.text(max - curLength);
        textArea.on('input propertychange', function () {
            var _value = $(this).val().replace(/\n/gi,"");
            numItem.text(_value.length);
        });
    }
</script>
<script>
    (function ($, win) {
		$(function () {
			/* ************************** 变量定义 ******************************** */
			var Util = $.Util;
			var notificationInfo = null;
            var serviceLabelType = 1;
            var healthLabelType = 2;
            var dieaseLabelType = 3;
			var province = 350000;
			var city = 350200;
			var isAuditor = ${isAuditor};
			// 表单校验工具类
			var jValidation = $.jValidation;
			/* *************************** 函数定义 ******************************* */
			function pageInit() {
				notificationInfo.init();
			}
			//发送范围事件
            $(":radio[name='scope']").click(function(){
                var scope = $(this).val();
                var scopeId = $("#scopeId").val();//修改时选中值
                if(scope=="0"){
                    $("#scope_area").hide();
                    $("#scope_community").hide();
                }else if(scope=="1"){//展示区
                    $.ajax({
                        url: ctx + "/common/districtAuthority",
                        method: "post",
                        dataType: "json",
                        data: {"type": 3, "code": city},
                        success: function (data) {
                            if(data.status=='200'){
                                var html = "";
                                if(scopeId){
                                    var scopeIds = scopeId.split(",");
                                    for(var i=0;i<data.list.length;i++){
                                        var town = data.list[i];
                                        if(scopeId.indexOf(town.code)<0){
                                            html +="<input type='checkbox' name='scope_area' class='inpChkb' data-name='"+town.name+"' value='"+town.code+"' >"+town.name+"&nbsp;";
                                        }else{
                                            html +="<input type='checkbox' checked='checked' name='scope_area' class='inpChkb' data-name='"+town.name+"' value='"+town.code+"' >"+town.name+"&nbsp;";
                                        }
                                    }
                                }else{
                                    for(var i=0;i<data.list.length;i++){
                                        var town = data.list[i];
                                        html +="<input type='checkbox' name='scope_area' class='inpChkb' data-name='"+town.name+"' value='"+town.code+"' >"+town.name+"&nbsp;";
                                    }
                                }
                                $(".scope_areaDiv").html(html);
                            }else{
                                $.Notice.error(data.msg);
                            }
                        }
                    });
                    $("#scope_area").show();
                    $("#scope_community").hide();
                }else if(scope=="2"){//展示社区
                    $.ajax({
                        url: ctx + "/admin/hos/community",
                        method: "post",
                        dataType: "json",
                        data: {"city": city},
                        success: function (data) {
                            if(data.status=='200'){
                                var communityAuthority = $("#communityAuthority").val();
                                var html = "";
                                var attrTown = "";
                                for(var i=0;i<data.list.length;i++){
                                    var town = data.list[i];
                                    attrTown += town.town+";";
                                    var tn = town.town.split(":");
                                    html +="<div  class='m-form-group u-checkbox-wrap m-form-control' style='height: auto;line-height: 15px;'>";
                                    if("2"==communityAuthority||scopeId.indexOf(tn[0])>=0){
                                        html +="<input type='checkbox' name='"+tn[0]+"' checked='checked' class='inpChkb chkCommunity' data-name='"+town.town+"' data-area='"+tn[1]+"' value='"+tn[0]+"' >"+tn[1]+"&nbsp;";
                                    }else{
                                        html +="<input type='checkbox' name='"+tn[0]+"' class='inpChkb chkCommunity' data-name='"+town.town+"' data-area='"+tn[1]+"' value='"+tn[0]+"' >"+tn[1]+"&nbsp;";
                                    }
                                    for(var j=0;j<town.community.length;j++){
                                        community = town.community[j];
                                        if(j>0&&j%6==0){
                                            html+="<br><span style='display: inline-block;width: 61px;'></span>";
                                        }
                                        var comName = community.name;
                                        comName = comName.substring(3,comName.length);
                                        if("2"==communityAuthority||scopeId.indexOf(community.code)>=0){
                                            html +="<input type='checkbox' name='"+town.town+"' checked='checked' class='inpChkb' data-name='"+comName+"' value='"+community.code+"' ><span class='community'>"+comName+"</span>&nbsp;";
                                        }else{
                                            html +="<input type='checkbox' name='"+town.town+"' class='inpChkb' data-name='"+comName+"' value='"+community.code+"' ><span class='community'>"+comName+"</span>&nbsp;";
                                        }
                                    }
                                    html +="</div>"
                                    html +="<br>";
                                }
                                $(".scope_communityDiv").attr("attr-towns",attrTown);
                                $(".scope_communityDiv").html(html);
                            }else{
                                $.Notice.error(data.msg);
                            }
                        }
                    });
                    $("#scope_area").hide();
                    $("#scope_community").show();
                }
            });
            //选择区 全选/反选 社区
            $(document).on("click",".chkCommunity",function () {
                var name = $(this).attr("data-name");
                $("[name = '"+name+"']:checkbox").prop("checked", $(this).is(':checked'));
            });
            //筛选条件
            $(":radio[name='condition_type']").click(function(){
                var condition_type = $(this).val();
                if(condition_type=="0"){
                    $("#inpCondition").hide();
                    $("[name = 'condition']:checkbox").prop("checked",false);
                    $(".serverType").hide();
                    $(".health_situation").hide();
                    $(".diease").hide();
                }else if(condition_type=="1"){
                    $("#inpCondition").show();
                }
            });
            //标签事件
            $(":checkbox[name='condition']").change(function () {
                var chkValue = $(this).val();
                var selClass = $(this).attr("data-class");
                if($(this).is(':checked')){
                    $.ajax({
                        url: ctx + "/common/label/signPatientLabel",
                        method: "post",
                        dataType: "json",
                        data: {"labelType": chkValue},
                        success: function (data) {
                            if(data.status=='200'){
                                var html = "";
                                var name = selClass.substring(1,selClass.length);
                                for(var i=0;i<data.list.length;i++){
                                    var patiemtLabel = data.list[i];
                                    if(i>0&&i%6==0){
                                        html+="<br>";
                                    }
                                    var selectId = "";
                                    if("1"==chkValue){
                                        selectId = $("#serverTypeId").val();
                                    }
                                    if("2"==chkValue){
                                        selectId = $("#healthSituationId").val();
                                    }
                                    if("3"==chkValue){
                                        selectId = $("#diseaseTypeId").val();
                                    }
                                    if(selectId&&selectId.indexOf(patiemtLabel.code)>=0){
                                        html +="<input type='checkbox' name='"+name+"' checked='checked' class='inpChkb' data-name='"+patiemtLabel.name+"' value='"+patiemtLabel.code+"' >"+patiemtLabel.name+"&nbsp;";
                                    }else{
                                        html +="<input type='checkbox' name='"+name+"' class='inpChkb' data-name='"+patiemtLabel.name+"' value='"+patiemtLabel.code+"' >"+patiemtLabel.name+"&nbsp;";
                                    }
                                }
                                $(selClass+"Div").html(html);
                            }else{
                                $.Notice.error(data.msg);
                            }
                            $(selClass).show();
                        }
                    });
                }else{
                    $(selClass).hide();
                }
            });
			/* *************************** 模块初始化 ***************************** */
			notificationInfo = {
				$form: $("#div_roles_info_form"),
				$scope: $("input[name='scope']"),//发送范围
				$scope_area: $("input[name='scope_area']"),//指定区
				$scope_community: $("input[name='scope_community']"),//指定社区
				$condition_type: $("input[name='condition_type']"),//筛选条件
				$condition: $("input[name='condition']"),//筛选条件
				$server: $("input[name='server']"),//服务类型
				$health_situation: $("input[name='health_situation']"),//健康情况
				$diease: $("input[name='diease']"),//疾病类型
				$title: $("#title"),//消息标题
				$content: $("#content"),//消息内容
				$send_type_combo_select: $("#send_type_combo_select"),//发送方式
				$send_time: $("#send_time"),//发送时间
				$btnsave: $("#btn_save"),//保存按钮
				$btncancle: $("#btn_cancel"),//结束按钮
				init: function () {
					_this = this;
                    //范围权限控制
                    var cityAuthority = $("#cityAuthority").val();
                    var areaAuthority = $("#areaAuthority").val();
                    var communityAuthority = $("#communityAuthority").val();
                    if("0"==cityAuthority){
                        $("#cityScope").attr("disabled", false);
                        $("#cityScope").attr("disabled","disabled")
                    }
                    if("0"==areaAuthority){
                        $("#areaScope").attr("disabled", false);
                        $("#areaScope").attr("disabled", "disabled");
                    }
                    if("0"==communityAuthority){
                        $("#communityScope").attr("disabled", false);
                        $("#communityScope").attr("disabled", "disabled");
                    }
//                    if("2"==communityAuthority){
//                        $("#communityScope").attr("checked", true);
//                    }
					this.$title.ligerTextBox({width: 240, validate: {required: true}});
                    var sendTypeSelect = this.$send_type_combo_select.ligerComboBox({
                        with:180,
                        data: [
                            { text: "立即发送", id: "0" },
//                            { text: "定时发送", id: "1" }//暂时只做立即发送(有审核权限-新增时立即发送,无权限-审核通过后立即发送)
                        ],
                        valueField: 'id',
                        textField: 'text',
                        cancelable: false,
                        initIsTriggerEvent: false,
                        onSelected: function (newvalue){
                            if(newvalue=="0"){
                                $(".send_time").hide();
                            }else{
                                $(".send_time").show();
                            }
                        }
                    });
                    sendTypeSelect.setValue("0");
                    this.$content.ligerTextBox({width: 430, height: 150, validate: {required: true}});
					this.$form.attrScan();
					_this = this;
					var noticeId = $("#noticeId").val();
					var mode = $("#mode").val();//模式  (新增/修改/查看)
					if (isNoEmpty(noticeId) && noticeId != 0) {
						//id不为空时 :为修改页面,进行修改操作
						//异步根据id获取消息信息
                        $.ajax({
                            url: ctx + "/admin/notification/notice",
                            method: "post",
                            dataType: "json",
                            data: {id: noticeId},
                            success: function (result) {
                                if (result.status == '200') {
                                    var notice = result.data;
                                    var scope = notice.scope;
                                    var scopeId = notice.scopeId;
                                    $("#scopeId").val(scopeId);//范围
                                    $(":radio[name='scope'][value='" + scope + "']").click();
                                    var conditionType = notice.condition;//筛选条件
                                    var diseaseTypeId = notice.diseaseTypeId;
                                    var healthSituationId = notice.healthSituationId;
                                    var serverTypeId = notice.serverTypeId;
                                    $("#serverTypeId").val(serverTypeId);
                                    $("#healthSituationId").val(healthSituationId);
                                    $("#diseaseTypeId").val(diseaseTypeId);
                                    $(":radio[name='condition_type'][value='" + conditionType + "']").click();
                                    if(serverTypeId){
                                        $(":checkbox[name='condition'][value='1']").click();
                                    }
                                    if(healthSituationId){
                                        $(":checkbox[name='condition'][value='2']").click();
                                    }
                                    if(diseaseTypeId){
                                        $(":checkbox[name='condition'][value='3']").click();
                                    }
                                    _this.$form.Fields.fillValues({
                                        title: notice.title,
                                        content: notice.content,
                                    });
                                    $(".word").text(notice.content.length);
                                    //发送方式
                                    var sendType = notice.sendType;
                                    if("1"==sendType){
                                        var sendTime = notice.sendTime;
                                        sendTime = sendTime.substring(0,16);
                                        sendTypeSelect.setValue(sendType);
                                        $("#send_time").ligerDateEditor({showTime: true,initValue: sendTime});
                                        $(".send_time").show();
                                    }
                                } else {
                                    $.Notice.error(result.msg);
                                }
                            },
                            error: function (data) {
                                $.Notice.error("系统异常,请联系管理员!");
                            }
                        });
					}else{
                        this.$send_time.ligerDateEditor({showTime: true});
                    }
					this.$form.show();
					this.bindEvents();
				},
				bindEvents: function () {
					var self = this;
					var flag = false;
					$("#btn_save").click(function () {
						var values = self.$form.Fields.getValues();
						if (values.id == '') {
							values.id = 0;
						}
                        values.city = city+"";
                        var s = self.$send_type_combo_select;
                        values.sendType = self.$send_type_combo_select.ligerComboBox().getValue();
                        values.sendTime = self.$send_time.val();
                        values.communityAuthority = $("#communityAuthority").val();
						if (isEmpty(values.scope)) {
							$.Notice.error("请选择发送范围!");
							return false;
						}
						if(values.scope=="0"){
                            values.conditionDescription = "厦门市 全市";
                        }else if(values.scope=="1"){
                            var area = "";
                            var areaName = "";
                            $("input[name='scope_area']:checked").each(function(){
                                area+=$(this).val()+",";
                                areaName+=$(this).attr("data-name")+",";
                            });
                            if(area==""){
                                $.Notice.error("请至少选择一个区!");
                                return false;
                            }
                            areaName = areaName.substring(0,areaName.length-1);
                            area = area.substring(0,area.length-1);
                            values.town = area;
                            values.scopeId = area;
                            values.scopeContent = areaName;
                            values.conditionDescription = "厦门市 "+areaName;
                        }else if(values.scope=="2"){
                            var attrTowns = $(".scope_communityDiv").attr("attr-towns");
                            if(attrTowns.length==0){
                                $.Notice.error("请至少选择一个社区!");
                                return false;
                            }
                            var towns = attrTowns.split(";");
                            var selctCommunity = "";
                            var townCommunity = "";
                            var conditionDescription = "";
                            for(var i=0;i<towns.length;i++){
                                var townName = towns[i];
                                var strCom = "";
                                var strComName = "";
                                $("input[name='"+townName+"']:checked").each(function(){
                                    strCom+=$(this).val()+",";
                                    strComName+=$(this).attr("data-name")+",";
                                });
                                if(strCom.length>0){
                                    //selctCommunity += strCom.substring(0,strCom.length-1);
                                    selctCommunity += strCom;
                                    townCommunity += townName.split(":")[0] +":"+strCom.substring(0,strCom.length-1)+";";
                                    conditionDescription += townName.split(":")[1] +":"+strComName.substring(0,strComName.length-1)+";\n ";
                                }
                            }
                            if(selctCommunity.length==0){
                                $.Notice.error("请至少选择一个社区!");
                                return false;
                            }
                            values.community = selctCommunity.substring(0,selctCommunity.length-1);
                            //values.townCommunity = townCommunity;
                            values.scopeId = townCommunity.substring(0,townCommunity.length-1);
                            values.scopeContent = conditionDescription;
                            values.conditionDescription = "厦门市 "+ conditionDescription;
                        }
                        if (isEmpty(values.condition_type)) {
                            $.Notice.error("请选择筛选条件!");
                            return false;
                        }
						if (values.condition_type=='0') {//全部居民
							var condition = "0";
							var conditionId = "";
							values.condition = condition;
							values.conditionId = conditionId;
						}
                        if(values.condition_type=='1'){
                            var condition = "";
                            var conditionId = "";
                            $("input[name='condition']:checked").each(function(){
                                condition+=$(this).val()+",";
                                var conDetail = "";
                                var nameDetail = "";
                                var dataName = $(this).attr("data-name");
                                $("input[name='"+dataName+"']:checked").each(function(){
                                    conDetail+=$(this).val()+",";
                                    conditionId+=$(this).val()+",";
                                    nameDetail+=$(this).attr("data-name")+",";
                                });
                                if(conDetail.length==0){
                                    $.Notice.error("请至少选择一个"+$(this).attr("data-tip")+"!");
                                    return false;
                                }
                                if(dataName=="serverType"){
                                    values.serverTypeId = conDetail.substring(0,conDetail.length-1);
                                    values.serverTypeContent = nameDetail.substring(0,nameDetail.length-1);
                                }else if(dataName=="health_situation"){
                                    values.healthSituationId = conDetail.substring(0,conDetail.length-1);
                                    values.healthSituationContent = nameDetail.substring(0,nameDetail.length-1);
                                }else if(dataName=="diease"){
                                    values.diseaseTypeId = conDetail.substring(0,conDetail.length-1);
                                    values.diseaseTypeContent= nameDetail.substring(0,nameDetail.length-1);
                                }
                            });
                            if(condition.length==0){
                                $.Notice.error("请至少选择一个设置条件!");
                                return false;
                            }
                            values.condition = condition;
                            values.conditionId = conditionId;
                        }
                        var validator = new jValidation.Validation(self.$form, {
                            immediate: true, onSubmit: false,
                            onElementValidate: function (result,elm) {
                                if (Util.isStrEquals($(elm).attr("id"), 'title')) {
                                    if (isEmpty(values.title)) {
                                        result.setResult(false);
                                        return result;
                                    }
                                }
                                if (Util.isStrEquals($(elm).attr("id"), 'content')) {
                                    if (isEmpty(values.content)) {
                                        result.setResult(false);
                                        return result;
                                    }
                                }
                                if (Util.isStrEquals($(elm).attr("id"), 'send_time')) {
                                    if (values.sendType=="1"&&isEmpty(values.sendTime)) {
                                        result.setResult(false);
                                        return result;
                                    }
                                }
                            }
                        });
                        validator.validate();
						if (isEmpty(values.title)) {
							$.Notice.error("通知标题不能为空!");
							return false;
						}
                        if (isEmpty(values.content)) {
                            $.Notice.error("通知内容不能为空!");
                            return false;
                        }
                        if(values.sendType=="1"&&isEmpty(values.sendTime)){
                            $.Notice.error("发送时间不能为空!");
                            return false;
                        }
						var ddf = $.ligerDialog.open({
                            height: 100,
                            width: 300,
                            title: "提示",
                            isHidden: true,
                            target: "<div style='margin: 0 auto; width: 200px;' >是否确认提交消息通知?提交后无法变更</div>",
							buttons: [
								{
									text: '立即提交', onclick: function (i, d) {
									d.hide();
									update(values);
								}
								},
                                { text: '我在看看', onclick: function (i, d) { d.hide(); }}
                            ]
                        });
//                        $.ajax({
//                            url: ctx + "/admin/notification/isNoticeAuditor",
//                            async: false,
//                            method: "post",
//                            dataType: "json",
//                            data: {},
//                            success: function (data) {
//                                if (data.status == 200) {
//                                    var authority = data.authority;
//
//                                    $.ligerDialog.open({
//                                        height: 250,
//                                        width: 300,
//                                        title: "tishi",
//                                        isHidden: true,
//                                        target: "是否确认提交消息通知?提交后无法变更",
//                                        buttons: [  { text: '立即提交', onclick: function (i, d) { update(values); }},
//                                            { text: '我在看看', onclick: function (i, d) { d.hide(); }}
//                                        ]
//                                    });
//                                } else {
//                                    $.Notice.error(data.msg);
//                                }
//                            }
//                        });
					});
					function update(values) {
						var dataModel = $.DataModel.init();
						var message = "保存中...";
						var url = "update";
						if (values.id == 0) {
							url = "create";
						}
						var wattingDialog = $.Notice.waitting(message);
						dataModel.updateRemote(ctx + "/admin/notification/" + url, {
							data: {jsonData: JSON.stringify(values)},
							success: function (data) {
								wattingDialog.close();
								if (data.status == 200) {
									parent.window.reloadMasterGrid(data.msg);
									parent.window.closeInfoDialog();
								} else {
									$.Notice.error(data.msg);
								}
							},
							error: function (data) {
								wattingDialog.close();
								$.Notice.error("系统异常,请联系管理员!");
							}
						});
					}
					$("#btn_cancel").click(function () {
						parent.window.closeInfoDialog();
					});
				}
			};
			/* *************************** 页面初始化 **************************** */
			pageInit();
		})
	})(jQuery, window);
</script>

+ 44 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_list.jsp

@ -0,0 +1,44 @@
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<%@ include file="../head/page_head.jsp" %>
	<title>用户管理</title>
</head>
<style>
</style>
<body>
<div id="div_wrapper">
	<!-- 检索条件 -->
	<div class="m-retrieve-area f-h50 f-dn f-pr m-form-inline" data-role-form style='display: block;'>
		<div class="m-form-group f-mt10">
			<%--<sec:authorize url="/admin/roles/rolesList">--%>
			<div class="m-form-control f-fs12 f-ml10">
				<input type="text" id="inp_searchNm" placeholder="请输入标题/提交人">
			</div>
			<div class="m-form-control f-fs12 f-ml10">
				<input id="sel_status" placeholder="选择状态"/>
			</div>
			<%--</sec:authorize>--%>
			<%--<sec:authorize url="/admin/roles/create">--%>
			<div class="m-form-control f-mr20" style="float: right">
				<div id="div_new_notice" class="l-button u-btn u-btn-primary u-btn-small f-ib f-vam">
					<span>新增消息通知</span>
				</div>
			</div>
			<%--</sec:authorize>--%>
		</div>
	</div>
	<!-- 列表 -->
	<div id="div_notice_list">
	</div>
</div>
</body>
<%@ include file="../head/page_foot.jsp" %>
<%@ include file="notification_list_js.jsp" %>
</html>

+ 284 - 0
patient-co-manage/wlyy-manage/src/main/webapp/WEB-INF/views/wechat/wechat_list_js.jsp

@ -0,0 +1,284 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<script>
	(function ($, win) {
		$(function () {
			/* ************************** 变量定义 ******************************** */
			// 通用工具类库
			var Util = $.Util;
			var retrieve = null;
			var master = null;
			var isFirstPage = false;
			var status = '';
			var isAuditor = ${isAuditor};
			/* *************************** 函数定义 ******************************* */
			function pageInit() {
				retrieve.init();
				master.init();
			}
			function reloadGrid(params) {
				if (isFirstPage) {
					master.grid.options.newPage = 1;
				}
				master.grid.setOptions({parms: params});
				master.grid.loadData(true);
			}
			/* *************************** 模块初始化 ***************************** */
			retrieve = {
				$element: $('.m-retrieve-area'),
				$addBtn: $('#div_new_notice'),
				$searchNm: $("#inp_searchNm"),
				$status: $('#sel_status'),
				init: function () {
					_this = this;
					this.$searchNm.ligerTextBox({
						width: 240, isSearch: true, search: function () {
							master.reloadGrid();//参数:标签/提交人+消息通知状态
						}
					})
					//状态复选框,选择时也刷新列表
					_this.statusBox = _this.$status.ligerComboBox({
						width: 180,
						data: [
							{text: '全部', statusId: ''},
							{text: '待提交', statusId: '1'},
							{text: '待审核', statusId: '2'},
							{text: '待发送', statusId: '3'},
							{text: '已发送', statusId: '4'},
							{text: '已拒绝', statusId: '5'},
							{text: '已撤回', statusId: '6'},
						],
						initIsTriggerEvent: false,
						valueFieldID: 'statusId',
						valueField: 'statusId',
						onSelected: function (newvalue) {
							status = newvalue;
							if (!master || !master.grid) {
								return
							}
							master.reloadGrid();//参数:标签/提交人+消息通知状态
						},
					});
                    this.bindEvents();
					if (isAuditor) {
						_this.statusBox.setValue('2');//根据是否是审核者设置默认值,审核者:默认选中待审核
					} else {
						_this.statusBox.setValue('');//根据是否是审核者设置默认值,审核者:待审核;非:默认全部
					}
				},bindEvents: function () {
                    var self = this;
                    self.$addBtn.click(function () {
                        master.infoDialog = $.ligerDialog.open({
                            height: 550,
                            width: 750,
                            title: '新增消息',
                            url: ctx + '/admin/notification/infoInit/' + "0" + "?mode=add"
                        })
                    });
                }
			};
			master = {
				infoDialog: null,
				grid: null,
				init: function () {
					this.grid = $("#div_notice_list").ligerGrid($.LigerGridEx.config({
						url: ctx + '/admin/notification/list',
						parms: {status: status},
						ajaxHeader: ajaxHeaderName,
						ajaxHeaderValue: ajaxHeaderValue,
						columns: [
							{display: 'ID', name: 'id', hide: true},
							{display: '标题', name: 'title', width: '14%', align: "left"},
							{display: '状态', name: 'status', hide: true},
							{
								display: '状态', name: 'status', width: '6%', align: "center",
								render: function (row) {
									var html = '';
									if (row.status == '0') {
										return "创建中"
									}
									;
									if (row.status == '1') {
										return "待提交"
									}
									;
									if (row.status == '2') {
										return "待审核"
									}
									;
									if (row.status == '3') {
										return "待发送"
									}
									;
									if (row.status == '4') {
										return "已发送"
									}
									;
									if (row.status == '5') {
										return "已拒绝"
									}
									;
									if (row.status == '6') {
										return "已撤回"
									}
									;
								}
							},
							{display: '通知总人数', name: 'totalCount', width: '15%', align: "center"},
//							{display: '定时发送时间', name: 'sendTime', width: '15%', align: "center"},
							{display: '提交人Id', name: 'applyUserId', hide: true},
							{display: '提交人', name: 'applyUserName', width: '10%', align: "center"},
							{display: '提交时间', name: 'applyTime', width: '15%', align: "center"},
							{display: '审核Id', name: 'auditUserId', hide: true},
							{display: '审核人', name: 'auditUserName', width: '10%', align: "center"},
							{display: '审核时间', name: 'auditTime', width: '15%', align: "center"},
							{
								display: '操作', name: 'operator', width: '15%', align: "center", isSort: false,
								render: function (row) {
									var html = '';
									html += '<a  href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "info:view", row.id) + '">查看</a>';
									if (row.owned == true) {
										if (row.status == 5 || row.status == 6) {
											html += '<a  style="margin-left:10px;"href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "info:edit", row.id) + '">编辑</a>';
											html += '<a  style="margin-left:10px;" title="删除" href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}','{2}'])", "info:del", row.id) + '">删除</a>';
										}
										if (row.status == 2) {
											html += '<a  style="margin-left:10px;"href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "info:revoke", row.id) + '">撤回</a>';
										}
										if (row.status == 1) {
											html += '<a  style="margin-left:10px;" title="删除" href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}','{2}'])", "info:del", row.id) + '">删除</a>';
										}
									}
									<%--<sec:authorize url="/admin/user/update">--%>
									if (row.owned == false && row.auditor == true && row.status == 2) {
										html += '<a  style="margin-left:10px;"href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "info:edit", row.id) + '">审核</a>';
									}
									<%--</sec:authorize>--%>
									return html;
								}
							}
						],
					}));
					// 自适应宽度
					this.grid.adjustToWidth();
					this.bindEvents();
				},
				reloadGrid: function (msg) {
					if (msg) {
						//如果是新增,直接刷新页面
						master.grid.loadData();
					} else {
						debugger
						//如果是查询(获取查询参数)
						var searchNm = retrieve.$searchNm.val() || '';
						var status = retrieve.statusBox.getValue() || '';
						var values = {
							searchNm: searchNm,
							status: status
						}
						reloadGrid.call(this, values);
					}
				},
				delRecord: function (id, code) {
					var self = this;
					$.ajax({
						url: ctx + "/admin/notification/delete",
						data: {"id": id},
						method: "post",
						dataType: "json",
						success: function (result) {
							if (result.status == '200') {
								window.reloadMasterGrid(result.msg);
							} else {
								$.Notice.error(result.msg);
							}
						},
						error: function (data) {
							$.Notice.error("系统异常,请联系管理员!");
						}
					})
				},
				bindEvents: function () {
					var self = this;
					$.subscribe('info:view', function (event, id) {
						var title = '消息通知详情';
						self.infoDialog = $.ligerDialog.open({
							height: 550,
							width: 750,
							urlParms: {"id": id, "mode": "view"},
							title: title,
							url: ctx + '/admin/notification/view'
						})
					});
                    $.subscribe('info:revoke', function (event, id) {
                        var title = '消息通知撤回';
                        self.infoDialog = $.ligerDialog.open({
                            height: 550,
                            width: 750,
                            urlParms: {"id": id, "mode": "revoke"},
                            title: title,
                            url: ctx + '/admin/notification/view'
                        })
                    });
					$.subscribe('info:edit', function (event, id) {
						var title = '编辑用户信息';
						self.infoDialog = $.ligerDialog.open({
							height: 550,
							width: 750,
							title: title,
                            url: ctx + '/admin/notification/infoInit/' + id + "?mode=edit"
						})
					});
					$.subscribe('info:create', function (event, id) {
						var title = '新增消息';
						self.infoDialog = $.ligerDialog.open({
							height: 460,
							width: 490,
							title: title,
							url: ctx + '/notification/infoInit' + "0" + "?mode=add"
						})
					});
					$.subscribe('info:del', function (event, id, code) {
						$.ligerDialog.confirm('确认删除该行信息?<br>如果是请点击确认按钮,否则请点击取消。', function (yes) {
							if (yes) {
								self.delRecord(id, code);
							}
						});
					})
				}
			};
			/* ************************* Dialog页面回调接口 ************************** */
			win.reloadMasterGrid = function (msg) {
				if (isNoEmpty(msg)) {
					$.Notice.success(msg);
				}
				master.reloadGrid(msg);
			};
			win.closeUserInfoDialog = function () {
				master.infoDialog.close();
			};
            win.closeInfoDialog = function () {
                master.infoDialog.close();
            };
			win.openEditInfoDialog = function (id) {
				master.infoDialog.close();
				$.publish("info:edit", id);
			}
			win.deleteNoticeDialog = function (id) {
				master.delRecord(id);
				master.infoDialog.close();
			}
			/* *************************** 页面初始化 **************************** */
			pageInit();
		});
	})(jQuery, window);
</script>