|  | @ -1,16 +1,21 @@
 | 
	
		
			
				|  |  | package com.yihu.wlyy.service.manager.feedback;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.Doctor;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.Message;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.SMS;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.feedback.Appeal;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.DoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.MessageDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.PatientDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.SMSDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.feedback.AppealDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.SMSService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.HttpClientUtil;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.apache.http.NameValuePair;
 | 
	
		
			
				|  |  | import org.apache.http.message.BasicNameValuePair;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
	
		
			
				|  | @ -25,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | import org.springside.modules.persistence.DynamicSpecifications;
 | 
	
		
			
				|  |  | import org.springside.modules.persistence.SearchFilter;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
	
		
			
				|  | @ -46,8 +52,10 @@ public class AppealService extends BaseService {
 | 
	
		
			
				|  |  |     private SMSService smsService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SMSDao smsDao;
 | 
	
		
			
				|  |  |     @Value("${image.imgUrlDomain}")
 | 
	
		
			
				|  |  |     private String imgUrlDomain;
 | 
	
		
			
				|  |  |     @Value("${wlyyService.api}")
 | 
	
		
			
				|  |  |     private String wlyyService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private MessageDao messageDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 分页查找问题
 | 
	
	
		
			
				|  | @ -69,13 +77,13 @@ public class AppealService extends BaseService {
 | 
	
		
			
				|  |  |         PageRequest pageRequest = new PageRequest(page - 1, rows, sort);
 | 
	
		
			
				|  |  |         // 设置查询条件
 | 
	
		
			
				|  |  |         Map<String, SearchFilter> filters = new HashMap<>();
 | 
	
		
			
				|  |  |         if (type!=-1){
 | 
	
		
			
				|  |  |         if (type != -1) {
 | 
	
		
			
				|  |  |             filters.put("type", new SearchFilter("type", SearchFilter.Operator.EQ, type));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (identity!=-1){
 | 
	
		
			
				|  |  |         if (identity != -1) {
 | 
	
		
			
				|  |  |             filters.put("identity", new SearchFilter("identity", SearchFilter.Operator.EQ, identity));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (status!=-1){
 | 
	
		
			
				|  |  |         if (status != -1) {
 | 
	
		
			
				|  |  |             filters.put("status", new SearchFilter("status", SearchFilter.Operator.EQ, status));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 未删除
 | 
	
	
		
			
				|  | @ -85,7 +93,6 @@ public class AppealService extends BaseService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据类型、身份、状态查询申诉列表
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -136,10 +143,10 @@ public class AppealService extends BaseService {
 | 
	
		
			
				|  |  |         int status = appeal.getStatus();
 | 
	
		
			
				|  |  | //        identity 1、患者 2、医生
 | 
	
		
			
				|  |  |         String name = null;
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(creater)){
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(creater)) {
 | 
	
		
			
				|  |  |             if (identity == 1) {
 | 
	
		
			
				|  |  |                 name = patientDao.findNameByCode(creater);
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 Doctor doctor = doctorDao.findByCode(creater);
 | 
	
		
			
				|  |  |                 name = doctor.getName();
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -154,23 +161,22 @@ public class AppealService extends BaseService {
 | 
	
		
			
				|  |  |         map.put("idcard", appeal.getIdcard());
 | 
	
		
			
				|  |  |         map.put("images", images);
 | 
	
		
			
				|  |  |         map.put("result", result);
 | 
	
		
			
				|  |  |         map.put("imgUrlDomain", imgUrlDomain);
 | 
	
		
			
				|  |  |         if (status == 0){
 | 
	
		
			
				|  |  |             appealDao.modifyAppealStatus(id,1);
 | 
	
		
			
				|  |  |         if (status == 0) {
 | 
	
		
			
				|  |  |             appealDao.modifyAppealStatus(id, 1);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return map;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //根据申诉ID保存处理结果,并更改状态
 | 
	
		
			
				|  |  |     public void saveAppealResult(long id, String result) throws Exception {
 | 
	
		
			
				|  |  |         appealDao.modifyAppealResult(id,result);
 | 
	
		
			
				|  |  |         appealDao.modifyAppealStatus(id,2);
 | 
	
		
			
				|  |  |         appealDao.modifyAppealResult(id, result);
 | 
	
		
			
				|  |  |         appealDao.modifyAppealStatus(id, 2);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void delappeal(String ids) {
 | 
	
		
			
				|  |  |         if(ids!=null){
 | 
	
		
			
				|  |  |         if (ids != null) {
 | 
	
		
			
				|  |  |             String[] _ids = ids.split(",");
 | 
	
		
			
				|  |  |             for(String id:_ids){
 | 
	
		
			
				|  |  |             for (String id : _ids) {
 | 
	
		
			
				|  |  |                 Long _id = Long.valueOf(id);
 | 
	
		
			
				|  |  |                 appealDao.delAppeal(_id);
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -184,47 +190,80 @@ public class AppealService extends BaseService {
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public void dealAppeal(Long id,String result) throws Exception {
 | 
	
		
			
				|  |  |     public void dealAppeal(Long id, String result) throws Exception {
 | 
	
		
			
				|  |  |         Appeal appeal = appealDao.findFeedbackById(id);
 | 
	
		
			
				|  |  |         appeal.setResult(result);
 | 
	
		
			
				|  |  |         appeal.setStatus(2);
 | 
	
		
			
				|  |  |         appealDao.save(appeal);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //发送处理完成短信
 | 
	
		
			
				|  |  |         //您某年某月某日在i健康平台提交的账号申诉已处理,请使用i健康应用(微信公众号)查看处理结果,查看路径:账号登录—忘记密码—账号申诉—申诉记录
 | 
	
		
			
				|  |  |         //医生和居民用不同的内容,医生是i健康应用,居民是i健康微信公众号
 | 
	
		
			
				|  |  |         StringBuffer msgContent = new StringBuffer("您");
 | 
	
		
			
				|  |  |         msgContent.append(DateUtil.getYMD(appeal.getCreateTime()));
 | 
	
		
			
				|  |  |         msgContent.append("在i健康平台提交的账号申诉已处理,请使用");
 | 
	
		
			
				|  |  |         if(appeal.getIdentity()==1){
 | 
	
		
			
				|  |  |             msgContent.append("微信公众号");
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             msgContent.append("i健康应用");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         msgContent.append("查看处理结果,查看路径:账号登录—忘记密码—账号申诉—申诉记录");
 | 
	
		
			
				|  |  |         JSONObject json = smsService.sendMsg(appeal.getPhone(),msgContent.toString());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         SMS sms = new SMS();
 | 
	
		
			
				|  |  |         Date date = new Date();
 | 
	
		
			
				|  |  |         // 延后5分钟
 | 
	
		
			
				|  |  |         sms.setContent(msgContent.toString());
 | 
	
		
			
				|  |  |         sms.setDeadline(date);
 | 
	
		
			
				|  |  |         sms.setCzrq(date);
 | 
	
		
			
				|  |  |         sms.setMobile(appeal.getPhone());
 | 
	
		
			
				|  |  |         sms.setIp("127.0.0.1");
 | 
	
		
			
				|  |  |         sms.setType(11);
 | 
	
		
			
				|  |  |         sms.setStatus(1);
 | 
	
		
			
				|  |  |         sms.setCaptcha("");
 | 
	
		
			
				|  |  |         smsDao.save(sms);
 | 
	
		
			
				|  |  |         if (json == null) {
 | 
	
		
			
				|  |  |             // 发送失败
 | 
	
		
			
				|  |  |             logger.error("申诉处理完成:短信发送失败");
 | 
	
		
			
				|  |  |         } else if (json.getInt("result") != 0) {
 | 
	
		
			
				|  |  |             logger.error("申诉处理完成:短信发送失败"+json.getString("description"));
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             //发送成功,保存到数据库
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             //发送处理完成短信
 | 
	
		
			
				|  |  |             //您某年某月某日在i健康平台提交的账号申诉已处理,请使用i健康应用(微信公众号)查看处理结果,查看路径:账号登录—忘记密码—账号申诉—申诉记录
 | 
	
		
			
				|  |  |             //医生和居民用不同的内容,医生是i健康应用,居民是i健康微信公众号
 | 
	
		
			
				|  |  |             StringBuffer msgContent = new StringBuffer("您");
 | 
	
		
			
				|  |  |             msgContent.append(DateUtil.getYMD(appeal.getCreateTime()));
 | 
	
		
			
				|  |  |             msgContent.append("在i健康平台提交的账号申诉已处理,请使用");
 | 
	
		
			
				|  |  |             if (appeal.getIdentity() == 1) {
 | 
	
		
			
				|  |  |                 msgContent.append("微信公众号");
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 msgContent.append("i健康应用");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             msgContent.append("查看处理结果,查看路径:账号登录—忘记密码—账号申诉—申诉记录");
 | 
	
		
			
				|  |  |             JSONObject json = smsService.sendMsg(appeal.getPhone(), msgContent.toString());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             SMS sms = new SMS();
 | 
	
		
			
				|  |  |             Date date = new Date();
 | 
	
		
			
				|  |  |             // 延后5分钟
 | 
	
		
			
				|  |  |             sms.setContent(msgContent.toString());
 | 
	
		
			
				|  |  |             sms.setDeadline(date);
 | 
	
		
			
				|  |  |             sms.setCzrq(date);
 | 
	
		
			
				|  |  |             sms.setMobile(appeal.getPhone());
 | 
	
		
			
				|  |  |             sms.setIp("127.0.0.1");
 | 
	
		
			
				|  |  |             sms.setType(11);
 | 
	
		
			
				|  |  |             sms.setStatus(1);
 | 
	
		
			
				|  |  |             smsDao.save(sms);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |             if (json == null) {
 | 
	
		
			
				|  |  |                 // 发送失败
 | 
	
		
			
				|  |  |                 logger.error("申诉处理完成:短信发送失败");
 | 
	
		
			
				|  |  |             } else if (json.getInt("result") != 0) {
 | 
	
		
			
				|  |  |                 logger.error("申诉处理完成:短信发送失败" + json.getString("description"));
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 //发送成功,保存到数据库
 | 
	
		
			
				|  |  |                 smsDao.save(sms);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (appeal.getIdentity() == 2) {
 | 
	
		
			
				|  |  |                 String creater = appeal.getCreater();
 | 
	
		
			
				|  |  |                 SimpleDateFormat formatDate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
 | 
	
		
			
				|  |  |                 String newDate = formatDate.format(new Date());
 | 
	
		
			
				|  |  |                 String title = "新增系统消息";
 | 
	
		
			
				|  |  |                 String content = "您在" + newDate + "提交的意见反馈已处理,您可点此查看处理结果";
 | 
	
		
			
				|  |  |                 Message message = new Message();
 | 
	
		
			
				|  |  |                 message.setType(10);
 | 
	
		
			
				|  |  |                 message.setCode(UUID.randomUUID().toString());
 | 
	
		
			
				|  |  |                 message.setCzrq(new Date());
 | 
	
		
			
				|  |  |                 message.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                 message.setContent(content);
 | 
	
		
			
				|  |  |                 message.setRead(1);//设置未读
 | 
	
		
			
				|  |  |                 message.setReceiver(creater);//设置接受医生的code
 | 
	
		
			
				|  |  |                 message.setSender("system");//设置发送的用户
 | 
	
		
			
				|  |  |                 message.setTitle(title);
 | 
	
		
			
				|  |  |                 message.setReadonly(1);//是否只读消息
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //wlyy给医生发送系统消息
 | 
	
		
			
				|  |  |                 Doctor doctor = doctorDao.findByCode(creater);
 | 
	
		
			
				|  |  |                 String doctorOpenID = doctor.getOpenid();
 | 
	
		
			
				|  |  |                 String url = wlyyService + "/patient/feedback/sendMessage";
 | 
	
		
			
				|  |  |                 List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("receiver", creater));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("title", title));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("content", content));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 HttpClientUtil.post(url, params, "UTF-8");
 | 
	
		
			
				|  |  |                 messageDao.save(message);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |