public ServiceResult getTotalCount(Scrapped model, String beginDate, String endDate) { ServiceResult result = new ServiceResult(false); Long data = scrappedDao.getTotalCount(model, beginDate, endDate); result.addData("total", data); result.setIsSuccess(true); return result; }
@Override public ServiceResult mulDelete(String ids) { ServiceResult result = new ServiceResult(false); if (StringUtils.isEmpty(ids)) { result.setMessage("请选择要删除的记录"); return result; } String[] idArray = StringUtil.split(ids, GobelConstants.SPLIT_SEPARATOR); if (idArray.length == 0) { result.setMessage("请选择要删除的记录"); return result; } boolean haveDelete = false; for (String id : idArray) { Goods oldModel = goodsDAO.load(Integer.parseInt(id)); if (oldModel == null) { continue; } else { goodsDAO.delete(Integer.parseInt(id)); haveDelete = true; } } if (!haveDelete) { result.setMessage("没有可删除的教材"); return result; } result.setIsSuccess(true); return result; }
@Override public ServiceResult send(String toMailAddr, String subject, String content, Integer mailType) { ServiceResult result = new ServiceResult(false); MimeMessage mailMessage = mailSender.createMimeMessage(); // 设置utf-8或GBK编码,否则邮件会有乱码 MimeMessageHelper messageHelper = null; // 设置邮件参数 SystemConfig systemConfig = systemConfigDAO.load(1); try { messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8"); messageHelper.setFrom( systemConfig.getEmailCode(), systemConfig.getCompanyName()); // 发送者,这里还可以另起Email别名,不用和xml里的username一致 messageHelper.setTo(toMailAddr); // 接受者 messageHelper.setSubject(subject); // 主题 messageHelper.setText(content, true); // 邮件内容 mailSender.send(mailMessage); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } MailsHistory mailsHistory = new MailsHistory(); mailsHistory.setTitle(subject); mailsHistory.setContent(content); mailsHistory.setReceiveIDs(toMailAddr); mailsHistory.setMailType(mailType); mailsHistoryDAO.save(mailsHistory); result.setIsSuccess(true); return result; }
/** * @Description: 批量删除资讯 @Create: 2013-5-30 上午10:21:46 * * @author jcf * @update logs */ public void mulDelete() { ServiceResult result = new ServiceResult(false); try { result = informationService.mulDelete(ids); } catch (Throwable e) { result.setMessage("批量删除资讯失败"); logger.error("批量删除资讯失败", e); } ajaxJson(result.toJSON()); }
/** @Description: 删除获奖学生 @Created Time: 2013-6-23 下午12:33:54 @Author lys */ public void mulDelete() { ServiceResult result = new ServiceResult(false); try { result = competitionPrizeStudentService.mulDelete(ids); } catch (Exception e) { result.setMessage("删除获奖学生失败"); logger.error("删除获奖学生失败", e); } String jsonString = result.toJSON(); ajaxJson(jsonString); }
/** @Description: 打开初始化资讯 @Created Time: 2013-6-3 下午10:46:40 @Author lys */ public void init() { ServiceResult result = new ServiceResult(false); try { result = informationService.init(model); } catch (Exception e) { result.setMessage(" 打开初始化资讯失败"); logger.error(" 打开初始化资讯失败", e); } String jsonString = result.toJSON(); ajaxJson(jsonString); }
/** * @Description: 保存省份 @Create: 2013-5-31 下午2:29:22 * * @author wxy * @update logs * @return */ public void save() { ServiceResult result = new ServiceResult(false); try { result = provinceService.save(model); } catch (Exception e) { result.setMessage("保存省份失败"); logger.error("保存省份失败", e); } String jsonString = result.toJSON(); ajaxJson(jsonString); }
public ServiceResult query( Scrapped model, String beginDate, String endDate, Integer page, Integer rows) { ServiceResult result = new ServiceResult(false); List<Scrapped> list = scrappedDao.query(model, beginDate, endDate, page, rows); String[] properties = { "scrappedId", "scrappedDate", "user.userName", "user.userId", "qtyTotal", "scrappedType" }; String data = JSONUtil.toJson(list, properties); result.addData("datagridData", data); result.setIsSuccess(true); return result; }
/** * @Description: 批量修改状态 @Create: 2013-5-30 上午10:21:57 * * @author jcf * @update logs */ public void mulUpdateStatus() { ServiceResult result = new ServiceResult(false); try { result = informationService.mulUpdateStatus(ids, model); } catch (Exception e) { result.setMessage("批量修改资讯状态失败"); logger.error("批量修改资讯状态失败", e); result.setIsSuccess(false); } String jsonString = result.toJSON(); ajaxJson(jsonString); }
/** @Description: 保存资讯 @Created Time: 2013-6-3 下午3:44:52 @Author lys */ public void save() { ServiceResult result = new ServiceResult(false); try { Integer teacherId = getIntegerSession(Teacher.LOGIN_TEACHERID); result = informationService.save(model, teacherId); } catch (Exception e) { result.setMessage("保存资讯失败"); logger.error("保存资讯失败", e); } String jsonString = result.toJSON(); ajaxJson(jsonString); }
/** * @Description: 更新省份顺序 @Create: 2013-5-31 下午15:25:55 * * @author wxy * @update logs */ public void updateArray() { Integer updateProvinceId = Integer.parseInt(getParameter("updateProvinceId")); ServiceResult result = new ServiceResult(false); try { result = provinceService.updateArray(model.getProvinceId(), updateProvinceId); } catch (Exception e) { result.setMessage("更新排序失败"); logger.error("更新排序失败", e); } String jsonString = result.toJSON(); ajaxJson(jsonString); }
/** @Description: 更新资讯排序 @Created Time: 2013-6-3 下午11:27:06 @Author lys */ public void updateArray() { String informationId = getParameter("informationId"); String updateInformationId = getParameter("updateInformationId"); ServiceResult result = new ServiceResult(false); try { result = informationService.updateArray(informationId, updateInformationId); } catch (Exception e) { result.setMessage("更新排序失败"); logger.error("更新排序失败", e); } String jsonString = result.toJSON(); ajaxJson(jsonString); }
/** @Description: 学生登陆 @Created Time: 2013-5-9 下午4:08:03 @Author lys */ public void studentLogin() { try { ServiceResult result = new ServiceResult(false); String captchaID = request.getSession().getId(); String challengeResponse = StringUtils.upperCase(request.getParameter(JCaptchaEngine.CAPTCHA_INPUT_NAME)); if (StringUtils.isEmpty(challengeResponse) || captchaService.validateResponseForID(captchaID, challengeResponse) == false) { result.setMessage("验证码错误"); ajaxJson(result.toJSON()); return; } // 根据用户名和密码判断是否允许登录 Student loginStudent = studentService.login(userCode, MD5Util.getMD5(userPwd)); if (null == loginStudent) { result.setMessage("用户名或密码错误或未注册激活!!"); } else { setSession(Student.LOGIN_ID, loginStudent.getStudentId()); setSession(Student.LOGIN_NAME, loginStudent.getStudentName()); setSession(LoginType.LOGINTYPE, LoginType.STUDENT); result.addData("studentId", loginStudent.getStudentId()); result.addData("studentName", loginStudent.getStudentName()); result.setIsSuccess(true); } String ajaxString = result.toJSON(); ajaxJson(ajaxString); } catch (Exception e) { e.printStackTrace(); } }
public ServiceResult queryDetail(Scrapped model) { ServiceResult result = new ServiceResult(false); List<ScrappedDetail> list = scrappedDetailDao.query("scrapped", model); String[] properties = { "scrappedDetailId", "commodity.commodityId", "commodity.commodityName", "qty", "warehouse.warehouseId", "commodityTypeName", "unitName" }; String data = JSONUtil.toJson(list, properties); result.addData("datagridData", data); result.setIsSuccess(true); return result; }
/** @Description: 用户端登录 @Created Time: 2013-3-29 上午11:29:36 @Author lys */ public void teacherLogin() { try { ServiceResult result = new ServiceResult(false); String captchaID = request.getSession().getId(); String challengeResponse = StringUtils.upperCase(request.getParameter(JCaptchaEngine.CAPTCHA_INPUT_NAME)); if (StringUtils.isEmpty(challengeResponse) || captchaService.validateResponseForID(captchaID, challengeResponse) == false) { result.setMessage("验证码错误"); ajaxJson(result.toJSON()); return; } // 根据用户名和密码判断是否允许登录 Teacher loginTeacher = teacherService.login(userCode, MD5Util.getMD5(userPwd)); if (null == loginTeacher) { result.setMessage("用户名或密码错误!!"); } else { setSession(Teacher.LOGIN_TEACHERID, loginTeacher.getTeacherId()); setSession(Teacher.LOGIN_TEACHERName, loginTeacher.getTeacherName()); setSession(LoginType.LOGINTYPE, LoginType.TEACHER); result.setIsSuccess(true); } String ajaxString = result.toJSON(); ajaxJson(ajaxString); } catch (Exception e) { e.printStackTrace(); } }
public ServiceResult delete(String scrappedIds) { ServiceResult result = new ServiceResult(false); if (StringUtils.isEmpty(scrappedIds)) { result.setMessage("请选择要删除的单子"); return result; } String[] scrappedArr = StringUtil.split(scrappedIds); for (String scrappedId : scrappedArr) { Scrapped oldModel = scrappedDao.load(Integer.parseInt(scrappedId)); if (oldModel == null) { result.setMessage("该单子已不存在"); return result; } else { List<ScrappedDetail> detailList = scrappedDetailDao.query("scrapped", oldModel); for (ScrappedDetail scrappedDetail : detailList) { Store store = storeDao.query(scrappedDetail.getCommodity(), scrappedDetail.getWarehouse()); Commodity commodity = commodityDao.load(scrappedDetail.getCommodity().getCommodityId()); if (oldModel.getScrappedType().equals(1)) { if (store.getQtyStore() - scrappedDetail.getQty() < 0) { throw new RuntimeException( "商品" + scrappedDetail.getCommodity().getCommodityName() + "数量不足,无法进行操作"); } store.setQtyStore(store.getQtyStore() - scrappedDetail.getQty()); commodity.setQtyStore(commodity.getQtyStore() - scrappedDetail.getQty()); } else { store.setQtyStore(store.getQtyStore() + scrappedDetail.getQty()); commodity.setQtyStore(commodity.getQtyStore() + scrappedDetail.getQty()); } scrappedDetailDao.delete(scrappedDetail); } scrappedDao.delete(oldModel); } } result.setIsSuccess(true); return result; }
public ServiceResult save(Goods model) { ServiceResult result = new ServiceResult(false); if (model == null) { result.setMessage("请填写教材信息"); return result; } if (StringUtils.isEmpty(model.getGoodsName())) { result.setMessage("请填写教材名称"); return result; } if (model.getPurchasePrice() == null) { model.setPurchasePrice(0d); } if (model.getSellingPrice() == null) { model.setSellingPrice(0d); } if (model.getGoodsId() == null) { // 新增 if (goodsDAO.load("goodsName", model.getGoodsName()) != null) { result.setMessage("请教材名称已存在"); return result; } model.setAmount(0d); model.setPrice(0d); model.setStore(0); goodsDAO.save(model); } else { Goods oldModel1 = goodsDAO.load("goodsName", model.getGoodsName()); if (oldModel1 != null && oldModel1.getGoodsId().intValue() != model.getGoodsId().intValue()) { result.setMessage("请教材名称已存在"); return result; } Goods oldModel2 = goodsDAO.load(model.getGoodsId()); if (oldModel2 == null) { result.setMessage("该教材已不存在"); return result; } oldModel2.setGoodsName(model.getGoodsName()); oldModel2.setPressName(model.getPressName()); oldModel2.setPurchasePrice(model.getPurchasePrice()); oldModel2.setSellingPrice(model.getSellingPrice()); } result.setIsSuccess(true); result.addData("goodsId", model.getGoodsId()); return result; }
public ServiceResult save( Scrapped model, String scrappedDetailIds, String commodityIds, String warehouseDetailIds, String qtys, String delScrappedIds) { ServiceResult result = new ServiceResult(false); if (model == null) { result.setMessage("请填写损溢单信息"); return result; } if (model.getScrappedId() == null && model.getScrappedType() == null) { result.setMessage("请选择损溢类型"); return result; } if (model.getScrappedDate() == null) { result.setMessage("请填写日期"); return result; } if (model.getUser() == null) { result.setMessage("请选择经办人"); return result; } User user = userDao.get(model.getUser().getUserId()); if (user == null) { result.setMessage("请选择已有的经办人"); return result; } String[] commodityIdArr = StringUtil.split(commodityIds); String[] warehouseDetailIdArr = StringUtil.split(warehouseDetailIds); String[] qtysArr = StringUtil.split(qtys); String[] scrappedDetailIdArr = StringUtil.split(scrappedDetailIds); String[] delScrappedIdArr = StringUtil.split(delScrappedIds); for (int i = 0; i < commodityIdArr.length; i++) { if (StringUtils.isEmpty(qtysArr[i])) { result.setMessage("第" + (i + 1) + "行数据没有填写数量"); return result; } if (StringUtils.isEmpty(warehouseDetailIdArr[i])) { result.setMessage("第" + (i + 1) + "行数据没有选择仓库"); return result; } Warehouse warehouse = warehouseDao.get(Integer.parseInt(warehouseDetailIdArr[i])); if (warehouse == null) { result.setMessage("第" + (i + 1) + "行数据没有选择已有仓库"); return result; } } Scrapped oldModel = null; boolean isAdd = true; if (model.getScrappedId() == null) { scrappedDao.save(model); } else { // 修改 oldModel = scrappedDao.load(model.getScrappedId()); if (oldModel == null) { result.setMessage("该损溢单已不存在"); return result; } oldModel.setScrappedDate(model.getScrappedDate()); oldModel.setUser(model.getUser()); oldModel.setQtyTotal(model.getQtyTotal()); oldModel.setNote(model.getNote()); if (delScrappedIdArr.length != 0) { for (String detailId : delScrappedIdArr) { if (StringUtils.isNotEmpty(detailId)) { ScrappedDetail scrappedDetail = scrappedDetailDao.load(Integer.parseInt(detailId)); Commodity commodity = scrappedDetail.getCommodity(); Warehouse warehouse = scrappedDetail.getWarehouse(); Store store = storeDao.query(commodity, warehouse); if (oldModel.getScrappedType().equals(0)) { store.setQtyStore(store.getQtyStore() + scrappedDetail.getQty()); commodity.setQtyStore(commodity.getQtyStore() + scrappedDetail.getQty()); } else { if (store.getQtyStore() - scrappedDetail.getQty() < 0) { throw new RuntimeException( "商品" + commodity.getCommodityName() + "在仓库" + warehouse.getWarehouseName() + "数量不足,无法进行修改"); } store.setQtyStore(store.getQtyStore() - scrappedDetail.getQty()); commodity.setQtyStore(commodity.getQtyStore() - scrappedDetail.getQty()); } scrappedDetailDao.delete(scrappedDetail.getScrappedDetailId()); } } } isAdd = false; } for (int i = 0; i < commodityIdArr.length; i++) { String commodityId = commodityIdArr[i]; Commodity commodity = commodityDao.load(Integer.parseInt(commodityId)); Warehouse warehouse = warehouseDao.get(Integer.parseInt(warehouseDetailIdArr[i])); Store store = storeDao.query(commodity, warehouse); if (isAdd) { // 增加 ScrappedDetail scrappedDetail = new ScrappedDetail(); scrappedDetail.setCommodity(commodity); scrappedDetail.setWarehouse(warehouse); scrappedDetail.setQty(Integer.parseInt(qtysArr[i])); scrappedDetail.setScrapped(model); scrappedDetailDao.save(scrappedDetail); if (store == null) { // 添加库存 if (model.getScrappedType().equals(0)) { throw new RuntimeException( "商品" + commodity.getCommodityName() + "在仓库" + warehouse.getWarehouseName() + "数量不足,无法进行报废"); } else { store = new Store(); store.setCommodity(commodity); store.setWarehouse(warehouse); store.setQtyStore(Integer.parseInt(qtysArr[i])); storeDao.save(store); } } else { if (model.getScrappedType().equals(0)) { if ((store.getQtyStore() - Integer.parseInt(qtysArr[i])) < 0) { throw new RuntimeException( "商品" + commodity.getCommodityName() + "在仓库" + warehouse.getWarehouseName() + "数量不足,无法进行报废"); } store.setQtyStore(store.getQtyStore() - Integer.parseInt(qtysArr[i])); } else { store.setQtyStore(store.getQtyStore() + Integer.parseInt(qtysArr[i])); } } if (model.getScrappedType().equals(0)) { commodity.setQtyStore(commodity.getQtyStore() - Integer.parseInt(qtysArr[i])); } else { commodity.setQtyStore(commodity.getQtyStore() + Integer.parseInt(qtysArr[i])); } } else { // 修改 if (store == null) { // 添加库存 store = new Store(); store.setCommodity(commodity); store.setWarehouse(warehouse); store.setQtyStore(Integer.parseInt(qtysArr[i])); storeDao.save(store); } else { ScrappedDetail oldDetail = new ScrappedDetail(); Integer subtractQty = 0; if (StringUtils.isNotEmpty(scrappedDetailIdArr[i])) { oldDetail = scrappedDetailDao.load(Integer.parseInt(scrappedDetailIdArr[i])); // 修改库存 subtractQty = (Integer.parseInt(qtysArr[i])) - oldDetail.getQty().intValue(); if (!(warehouse.getWarehouseId().equals(oldDetail.getWarehouse().getWarehouseId()))) { // 修改仓库时,若是报废单,则先把旧仓库数量加上,在减去新仓库数量,若是已出单,则先把旧仓库数量减去,再加上新仓库数量 Store oldStore = storeDao.query(oldDetail.getCommodity(), oldDetail.getWarehouse()); if (oldModel.getScrappedType().equals(0)) { oldStore.setQtyStore(oldStore.getQtyStore() + oldDetail.getQty()); commodity.setQtyStore(commodity.getQtyStore() + oldDetail.getQty()); } else { oldStore.setQtyStore(oldStore.getQtyStore() - oldDetail.getQty()); commodity.setQtyStore(commodity.getQtyStore() - oldDetail.getQty()); } subtractQty = Integer.parseInt(qtysArr[i]); } else { if (oldModel.getScrappedType().equals(0)) { if ((store.getQtyStore() - subtractQty) < 0) { throw new RuntimeException( "商品" + commodity.getCommodityName() + "在仓库" + warehouse.getWarehouseName() + "数量不足,无法进行操作"); } } else { if ((store.getQtyStore() + subtractQty) < 0) { throw new RuntimeException( "商品" + commodity.getCommodityName() + "在仓库" + warehouse.getWarehouseName() + "数量不足,无法进行操作"); } } } } else { oldDetail.setCommodity(commodity); oldDetail.setScrapped(model); subtractQty = Integer.parseInt(qtysArr[i]); } // 修改详细单 oldDetail.setQty(Integer.parseInt(qtysArr[i])); oldDetail.setWarehouse(warehouse); if (oldModel.getScrappedType().equals(0)) { if (store.getQtyStore() - subtractQty < 0) { throw new RuntimeException( "商品" + commodity.getCommodityName() + "在仓库" + warehouse.getWarehouseName() + "数量不足,无法进行操作"); } store.setQtyStore(store.getQtyStore() - subtractQty); commodity.setQtyStore(commodity.getQtyStore() - subtractQty); } else { if (store.getQtyStore() + subtractQty < 0) { throw new RuntimeException( "商品" + commodity.getCommodityName() + "在仓库" + warehouse.getWarehouseName() + "数量不足,无法进行操作"); } store.setQtyStore(store.getQtyStore() + subtractQty); commodity.setQtyStore(commodity.getQtyStore() + subtractQty); } if (oldDetail.getScrappedDetailId() == null) { scrappedDetailDao.save(oldDetail); } } } } result.setIsSuccess(true); result.addData("scrappedId", model.getScrappedId()); return result; }