package com.nationalelectric.greenH5; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.locks.ReentrantLock; import javax.annotation.Resource; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.jysoft.unipush.AliasManage; import com.jysoft.weChat.service.WechatService; import com.jysoft.weChat.vo.ContentVo; import com.nationalelectirc.Constant.Constant; import com.nationalelectirc.utils.RestResult; import com.nationalelectric.greenH5.DTO.GreenFoodOrderDetailDTO; import com.nationalelectric.greenH5.DTO.GreenFoodOrderListDTO; import com.nationalelectric.greenH5.bizc.BaseServiceImpl; import com.nationalelectric.greenH5.bizc.IGreenDrugsApplyBizc; import com.nationalelectric.greenH5.bizc.IGreenDrugsDetailBizc; import com.nationalelectric.greenH5.bizc.IGreenFoodOrderDetailBizc; import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc; import com.nationalelectric.greenH5.enums.OrderStatus; import com.nationalelectric.greenH5.enums.PayStatus; import com.nationalelectric.greenH5.enums.TakeStatus; import com.nationalelectric.greenH5.po.GreenDiningRoom; import com.nationalelectric.greenH5.po.GreenDrugsApply; import com.nationalelectric.greenH5.po.GreenDrugsDetail; import com.nationalelectric.greenH5.po.GreenFoodOrderDetail; import com.nationalelectric.greenH5.po.GreenFoodOrderList; import com.nationalelectric.greenH5.po.GreenUserInfo; import com.nationalelectric.greenH5.po.GreenWashCarInfo; import com.nationalelectric.greenH5.utils.DateTime; import com.nationalelectric.greenH5.utils.DateTimeHelper; import com.nationalelectric.greenH5.utils.DateUtil; import com.sgcc.uap.persistence.IHibernateDao; import com.sgcc.uap.service.validator.ServiceValidatorBaseException; import net.sf.json.JSONObject; import net.sf.json.JSONArray; /** * 概述
*

* 功能
* * @author chenweikang */ @Controller @RequestMapping("/greenDrugsApply") public class GreenDrugsApplyController extends GreenBaseController { @Resource private AliasManageController aliasManageController; @Resource private IHibernateDao hibernateDao; @Autowired private BaseServiceImpl baseService; @Resource private WechatService wService; /** * greenfoodorderdetail GreenFoodOrderDetail逻辑构件 */ @Resource private IGreenDrugsApplyBizc greenDrugsApplyBizc; @Resource private IGreenDrugsDetailBizc greenDrugsDetailBizc; @Resource private IGreenOperateLogBizc greenOperateLogBizc; private ReentrantLock lock = new ReentrantLock(); /**提交订单*/ @SuppressWarnings("deprecation") @RequestMapping(value="/submitDrugsApply", method = RequestMethod.POST) @Transactional(rollbackFor=Exception.class) @ResponseBody public RestResult submitDrugsApply(@RequestBody GreenDrugsApply greenDrugsApply){ try { lock.lock(); String userId = greenDrugsApply.getUserId(); GreenUserInfo info = getUserInfo(userId); if(info==null){ return new RestResult(Constant.FAILED, "非法用户"); } greenDrugsApply.setCreateTime(DateTimeHelper.getNowDate()); greenDrugsApply.setCreateBy(userId); hibernateDao.saveObject(greenDrugsApply); for(GreenDrugsDetail gd:greenDrugsApply.getDetailList()){ gd.setCreateBy(userId); gd.setCreateTime(DateTimeHelper.getNowDate()); gd.setApplyId(greenDrugsApply.getId()); List imgs = gd.getImgs(); String picture=""; String pictureData=""; for(int i=0;i> userList2 = hibernateDao.queryForListWithSql(getUserSql, new Object[]{role}); title = "药品审核"; text = "您好,您有新的药品预订需要审核,请注意查看。"; url = "/pages/medical/drugsApproval"; aliasManageController.pushToSingleBatch(userList2, title, text, url); return new RestResult(Constant.SUCCESS,"成功"); }catch (ServiceValidatorBaseException e) { throw e; }catch (Exception e) { e.printStackTrace(); //设置手动回滚 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return new RestResult(Constant.FAILED,"返回异常"); }finally { if (lock.isLocked()) { lock.unlock(); } } } /**用户订单列表*/ @RequestMapping(value="/getMyDrugsApplyList", method = RequestMethod.POST) @ResponseBody public RestResult getMyDrugsApplyList(@RequestBody GreenDrugsApply greenDrugsApply){ String userId = greenDrugsApply.getUserId(); GreenUserInfo info = getUserInfo(userId); if(info==null){ return new RestResult(Constant.FAILED, "非法用户"); } try { StringBuffer sb = new StringBuffer(); //分页信息 int pageSize = greenDrugsApply.getPageSize(); int page = greenDrugsApply.getPage(); int limit = ((page > 0 ? page : 1) -1) * pageSize; //查询订单 sb.append(" SELECT * FROM(SELECT RN.*,ROWNUM rw FROM( " + "Select a.id as \"id\",a.user_id as \"user_id\",a.user_name as \"user_name\",a.tel_number as \"tel_number\"," + "a.dept_id as \"dept_id\",a.dept_name as \"dept_name\",a.create_by as \"create_by\"," + "to_char(a.modify_time,'YYYY-MM-DD HH24:MI:SS') as \"modify_time\",a.modify_by as \"modify_by\",a.status as \"status\",a.is_deleted as \"is_deleted\"," + "a.reason as \"reason\",a.endremind as \"endremind\", " + "to_char(a.create_time,'YYYY-MM-DD HH24:MI:SS') as \"createTime\",u.real_name as \"real_name\",u.mobile as \"mobile\" " + "from green_drugs_apply a left join green_user_info u on a.modify_by = u.id " + " where a.is_deleted='N' and a.user_id = ? order by a.create_time desc " + " )rn ) WHERE rw > ? AND rw <= ? "); List> applyList = hibernateDao.queryForListWithSql(sb.toString() ,new Object[]{ userId, limit, pageSize}); StringBuilder stringBuilder = new StringBuilder(); String stringId = null; if (!applyList.isEmpty()) { stringBuilder.append("("); for (int i = 0;i> detailList =hibernateDao.queryForListWithSql( sql); for (Map map : detailList) { String picString=(String)map.get("drugs_pic1"); if(picString!=null&&!picString.isEmpty()){ map.put("drugs_pic1", baseService.getImageBase64(picString)); } String picString2=(String)map.get("drugs_pic2"); if(picString2!=null&&!picString2.isEmpty()){ map.put("drugs_pic2", baseService.getImageBase64(picString2)); } } //初始化图片缓存 baseService.initImage(); String stringId2 = null; String stringId3 = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < applyList.size(); i++) { ArrayList arrayList = new ArrayList(); applyList.get(i).put("detailList",null); stringId2 = String.valueOf(applyList.get(i).get("id")); //Date date = (Date) applyList.get(i).get("createTime"); Date date = sdf.parse(String.valueOf(applyList.get(i).get("createTime"))); DateTime dt = new DateTime(date); String pickDate = ""; if(dt.getDay()>=7){ dt = dt.addMonths(1); } pickDate = dt.toString("yyyy年MM")+"月下旬"; applyList.get(i).put("pickDate", pickDate); for (int j = 0; j < detailList.size(); j++) { stringId3 = String.valueOf(detailList.get(j).get("apply_id")); if (stringId2.equals(stringId3)) { arrayList.add(detailList.get(j)); applyList.get(i).put("detailList",arrayList); } } } } return new RestResult(Constant.SUCCESS,"成功",applyList); }catch (ServiceValidatorBaseException e) { throw e; }catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED,"返回异常"); } } /**用户订单列表*/ @RequestMapping(value="/getDrugsApplyList", method = RequestMethod.POST) @ResponseBody public RestResult getDrugsApplyList(@RequestBody GreenDrugsApply greenDrugsApply){ String userId = greenDrugsApply.getUserId(); GreenUserInfo info = getUserInfo(userId); if(info==null){ return new RestResult(Constant.FAILED, "非法用户"); } try { StringBuffer sb = new StringBuffer(); //分页信息 int pageSize = greenDrugsApply.getPageSize(); int page = greenDrugsApply.getPage(); int limit = ((page > 0 ? page : 1) -1) * pageSize; //查询订单 sb.append(" SELECT * FROM(SELECT RN.*,ROWNUM rw FROM( " + "Select a.id as \"id\",a.user_id as \"user_id\",a.user_name as \"user_name\",a.tel_number as \"tel_number\"," + "a.dept_id as \"dept_id\",a.dept_name as \"dept_name\",a.create_by as \"create_by\"," + "to_char(a.modify_time,'yyyy-mm-dd hh24:mi:ss') as \"modify_time\",a.modify_by as \"modify_by\",a.status as \"status\",a.is_deleted as \"is_deleted\"," + "a.reason as \"reason\",a.endremind as \"endremind\", " + "to_char(a.create_time,'YYYY-MM-DD HH24:MI:SS') as \"createTime\" " + " from green_drugs_apply a" + " where is_deleted='N' "); Integer status = greenDrugsApply.getStatus(); if(status==3){ sb.append(" and status <> 0 "); }else{ sb.append(" and status = "+status+" "); } sb.append(" order by create_time desc " + " )rn ) WHERE rw > ? AND rw <= ? "); List> applyList = hibernateDao.queryForListWithSql(sb.toString() ,new Object[]{ limit, pageSize}); StringBuilder stringBuilder = new StringBuilder(); String stringId = null; if (!applyList.isEmpty()) { stringBuilder.append("("); for (int i = 0;i> detailList =hibernateDao.queryForListWithSql( sql); for (Map map : detailList) { String picString=(String)map.get("drugs_pic1"); if(picString!=null&&!picString.isEmpty()){ map.put("drugs_pic1", baseService.getImageBase64(picString)); } String picString2=(String)map.get("drugs_pic2"); if(picString2!=null&&!picString2.isEmpty()){ map.put("drugs_pic2", baseService.getImageBase64(picString2)); } } //初始化图片缓存 baseService.initImage(); String stringId2 = null; String stringId3 = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < applyList.size(); i++) { ArrayList arrayList = new ArrayList(); applyList.get(i).put("detailList",null); stringId2 = String.valueOf(applyList.get(i).get("id")); //Date date = (Date) applyList.get(i).get("create_time"); Date date = sdf.parse(String.valueOf(applyList.get(i).get("createTime"))); DateTime dt = new DateTime(date); String pickDate = ""; if(dt.getDay()>=7){ dt = dt.addMonths(1); } pickDate = dt.toString("yyyy年MM")+"月下旬"; applyList.get(i).put("pickDate", pickDate); for (int j = 0; j < detailList.size(); j++) { stringId3 = String.valueOf(detailList.get(j).get("apply_id")); if (stringId2.equals(stringId3)) { arrayList.add(detailList.get(j)); applyList.get(i).put("detailList",arrayList); } } } return new RestResult(Constant.SUCCESS,"成功",applyList); } return new RestResult(Constant.SUCCESS,"成功",null); }catch (ServiceValidatorBaseException e) { throw e; }catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED,"返回异常"); } } @RequestMapping(value="/getDrugsApplyDetail", method = RequestMethod.POST) @ResponseBody public RestResult getDrugsApplyDetail(@RequestBody GreenDrugsApply greenDrugsApply){ // String userId = greenDrugsApply.getUserId(); // GreenUserInfo info = getUserInfo(userId); // if(info==null){ // return new RestResult(Constant.FAILED, "非法用户"); // } Long id = greenDrugsApply.getId(); try { StringBuffer sb = new StringBuffer(); //分页信息 int pageSize = greenDrugsApply.getPageSize(); int page = greenDrugsApply.getPage(); page = (page-1) * pageSize; //查询订单 sb.append(" Select a.id as \"id\",a.user_id as \"user_id\",a.user_name as \"user_name\",a.tel_number as \"tel_number\"," + "a.dept_id as \"dept_id\",a.dept_name as \"dept_name\",a.create_by as \"create_by\"," + "to_char(a.modify_time,'yyyy-mm-dd hh24:mi:ss') as \"modify_time\",a.modify_by as \"modify_by\",a.status as \"status\",a.is_deleted as \"is_deleted\"," + "a.reason as \"reason\",a.endremind as \"endremind\"," + "to_char(a.create_time,'YYYY-MM-DD HH24:MI:SS') as \"createTime\",u.real_name as \"real_name\",u.mobile as \"mobile\" " + "from green_drugs_apply a left join green_user_info u on a.modify_by = u.id" + " where a.id=? "); List> applyList = hibernateDao.queryForListWithSql(sb.toString(),new Object[]{ id}); StringBuilder stringBuilder = new StringBuilder(); String stringId = null; if (!applyList.isEmpty()) { stringBuilder.append("("); for (int i = 0;i> detailList =hibernateDao.queryForListWithSql( sql); for (Map map : detailList) { String picString=(String)map.get("drugs_pic1"); if(picString!=null&&!picString.isEmpty()){ map.put("drugs_pic1", baseService.getImageBase64(picString)); } String picString2=(String)map.get("drugs_pic2"); if(picString2!=null&&!picString2.isEmpty()){ map.put("drugs_pic2", baseService.getImageBase64(picString2)); } } //初始化图片缓存 baseService.initImage(); String stringId2 = null; String stringId3 = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < applyList.size(); i++) { ArrayList arrayList = new ArrayList(); applyList.get(i).put("detailList",null); stringId2 = String.valueOf(applyList.get(i).get("id")); //Date date = (Date) applyList.get(i).get("create_time"); Date date = sdf.parse(String.valueOf(applyList.get(i).get("createTime"))); DateTime dt = new DateTime(date); String pickDate = ""; if(dt.getDay()>=7){ dt = dt.addMonths(1); } pickDate = dt.toString("yyyy年MM")+"月下旬"; applyList.get(i).put("pickDate", pickDate); for (int j = 0; j < detailList.size(); j++) { stringId3 = String.valueOf(detailList.get(j).get("apply_id")); if (stringId2.equals(stringId3)) { arrayList.add(detailList.get(j)); applyList.get(i).put("detailList",arrayList); } } } return new RestResult(Constant.SUCCESS,"成功",applyList); } return new RestResult(Constant.SUCCESS,"成功",null); }catch (ServiceValidatorBaseException e) { throw e; }catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED,"返回异常"); } } /**用户订单列表*/ @RequestMapping(value="/updateDrugs", method = RequestMethod.POST) @ResponseBody public RestResult updateDrugs(JSONObject data){ String userId = data.getString("userId"); GreenUserInfo info = getUserInfo(userId); if(info==null){ return new RestResult(Constant.FAILED, "非法用户"); } try { JSONArray ja = data.getJSONArray("detailList"); for(int i=0;i map = (Map) JSONObject.toBean(ja.getJSONObject(i), Map.class); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd"); GreenDrugsDetail gd = greenDrugsDetailBizc.get(Long.parseLong((Integer)map.get("id")+"")); //gd.setId((Long)obj.get("id")); //gd.setApplyId((Long)obj.get("apply_id")); gd.setDrugsName((String)map.get("drugsName")); gd.setDrugsFactory((String)map.get("drugsFactory")); gd.setDrugsType((String)map.get("drugsType")); gd.setDrugsNum(Integer.parseInt(map.get("drugsNum").toString())); gd.setIsDeleted(((String)map.get("isDeleted")).equals("Y")?'Y':'N'); // String picString1=(String)obj.get("drugs_pic1"); // String picture=""; // String pictureData=""; // String date = sdf1.format(new Date()) + "/"; // String uuid = date + UUID.randomUUID().toString().replaceAll("-",""); // baseService.saveImgToIO(uuid+Constant.IMG_SUFFIX, picString1); // picture = uuid+Constant.IMG_SUFFIX; // pictureData = uuid; // gd.setDrugsPic1(picture); // gd.setDrugsPic1Data(pictureData); // // String picString2=(String)obj.get("drugs_pic2"); // date = sdf1.format(new Date()) + "/"; // uuid = date + UUID.randomUUID().toString().replaceAll("-",""); // baseService.saveImgToIO(uuid+Constant.IMG_SUFFIX, picString2); // picture = uuid+Constant.IMG_SUFFIX; // pictureData = uuid; // gd.setDrugsPic2(picture); // gd.setDrugsPic2Data(pictureData); // gd.setIsDeleted((Character)obj.get("is_deleted")); //greenDrugsDetailBizc.update(gd, gd.getId()); hibernateDao.updateObject(gd,gd.getId()); } String title = "药品预定"; String text = "您好,您的药品预定已被修改,请注意查看。"; String url = "/pages/medical/drugreserve?currentTabIndex=1"; aliasManageController.pushToSingle(userId, title, text, url); return new RestResult(Constant.SUCCESS,"修改成功"); }catch (ServiceValidatorBaseException e) { throw e; }catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED,"修改失败"); } } /**用户订单列表*/ @RequestMapping(value="/drugsApplyApproval", method = RequestMethod.POST) @ResponseBody public RestResult drugsApplyApproval(@RequestBody GreenDrugsApply greenDrugsApply){ try { Long id = greenDrugsApply.getId(); Integer status = greenDrugsApply.getStatus(); String reason = greenDrugsApply.getReason()==null?"":greenDrugsApply.getReason(); String modifyBy = greenDrugsApply.getModifyBy()==null?"":greenDrugsApply.getModifyBy(); String sql = "update green_drugs_apply set status=? ,reason=?,modify_by =?,modify_time=? where id=?" ; hibernateDao.updateWithSql(sql, new Object[]{status,reason,modifyBy,new Date(),id}); greenDrugsApply = greenDrugsApplyBizc.get(id); if(status == 1){ String title = "药品预定"; String text = "您好,您的药品预定已通过审核,请注意查看。"; String url = "/pages/medical/drugreserve?currentTabIndex=1"; aliasManageController.pushToSingle(greenDrugsApply.getUserId(), title, text, url); //查询所有有这个权限的人员 String role = "14005";//药品受理权限 String getUserSql = "SELECT u.id,u.ISC_ID FROM green_user_info u " + " LEFT JOIN green_user_role_rel r ON u.id = r.user_id " + " LEFT JOIN green_role_permission p ON p.role_id = r.role_id " + " WHERE p.permission_id = ? "; List> userList2 = hibernateDao.queryForListWithSql(getUserSql, new Object[]{role}); title = "药品受理"; text = "您好,您有新的药品预定需要受理,请注意查看。"; url = "/pages/medical/drug-reserve-sl"; aliasManageController.pushToSingleBatch(userList2, title, text, url); }else{ String title = "药品预定"; String text = "您好,您的药品预定被拒绝,请注意查看。"; String url = "/pages/medical/drugreserve?currentTabIndex=1"; aliasManageController.pushToSingle(greenDrugsApply.getUserId(), title, text, url); } return new RestResult(Constant.SUCCESS,"审核成功"); }catch (ServiceValidatorBaseException e) { throw e; }catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED,"审核失败"); } } /** * 提醒 * * @param greenHaircutRemainDTO * @return */ @RequestMapping(value = "/remindPickUpDrugs", method = RequestMethod.POST) public @ResponseBody RestResult remindPickUpDrugs(@RequestBody GreenDrugsApply greenDrugsApply) { try { String sql = "select endremind as \"endremind\" from green_drugs_apply where id ="+greenDrugsApply.getId()+""; List> list = hibernateDao.queryForListWithSql(sql); String title = "药品预定"; String text = "您好,您预定的药品已到货,请及时取货。"; String url = "/pages/medical/drugreserve?currentTabIndex=1"; aliasManageController.pushToSingle(greenDrugsApply.getUserId(), title, text, url); // String sqlDetail = "select * from green_drugs_detail where apply_id ="+greenDrugsApply.getId()+""; // List> listDetail = hibernateDao.queryForListWithSql(sqlDetail); // String detail =""; // for(int i=0;i m = listDetail.get(i); // if(i!=0){ // detail+="、"+m.get("drugs_name")+"x"+m.get("drugs_num"); // }else{ // detail+=m.get("drugs_name")+"x"+m.get("drugs_num"); // } // // } // String userId = greenDrugsApply.getUserId(); // GreenUserInfo userInfo = getUserInfo(userId); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // String openIdString = userInfo.getWxOpenId(); // Map dataMap = new HashMap(); // dataMap.put("first", new ContentVo("您好!您订购的药品已到,请及时取走!", "#173177")); // dataMap.put("keyword1", new ContentVo(detail, "#black")); // dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black")); // dataMap.put("keyword3", new ContentVo("药房", "#black")); // dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177")); // wService.publishMsg(dataMap, openIdString, 7); Integer endRemind = list.get(0).get("endremind")==null?0:Integer.parseInt(String.valueOf(list.get(0).get("endremind"))); String upSql = "update green_drugs_apply set endremind="+(endRemind+1)+" where id="+greenDrugsApply.getId(); hibernateDao.executeSqlUpdate(upSql); // 返回结果 return new RestResult(Constant.SUCCESS, ""); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } }