⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auctionmsgaction.java~11~

📁 源码/软件简介: 云网论坛1.1RC国际版是采用JSP开发的集论坛、CMS(网站内容管理系统)、博客、聊天室、商城、交友、语音灌水等于一体的门户式社区。拥有CWBBS ( Cloud Web BBS
💻 JAVA~11~
📖 第 1 页 / 共 2 页
字号:
package com.redmoon.forum.plugin.auction;

import javax.servlet.http.HttpServletRequest;
import cn.js.fan.util.ErrMsgException;
import javax.servlet.ServletContext;
import com.redmoon.forum.plugin.base.IPluginMsgAction;
import org.apache.log4j.Logger;
import com.redmoon.forum.MsgDb;
import cn.js.fan.util.StrUtil;
import java.util.Calendar;
import cn.js.fan.util.ResKeyException;
import com.redmoon.kit.util.FileUpload;
import cn.js.fan.util.DateUtil;
import java.util.Iterator;
import cn.js.fan.util.ImageUtil;
import java.io.File;
import cn.js.fan.util.file.FileUtil;
import java.io.IOException;
import java.util.Vector;

public class AuctionMsgAction implements IPluginMsgAction {
    Logger logger = Logger.getLogger(this.getClass().getName());

    public static final String ACTION_APPLY = "apply";
    public static final String ACTION_ACCEPT_APPLY = "acceptApply";
    public static final String ACTION_DECLINE_APPLY = "declineApply";

    public static final String ACTION_APPLY_MARRY = "applymarry";
    public static final String ACTION_ACCEPT_MARRY = "acceptApplyMarry";
    public static final String ACTION_DECLINE_MARRY = "acceptDeclineMarry";

    public AuctionMsgAction() {
    }

    /**
     *
     * @param application ServletContext
     * @param request HttpServletRequest
     * @param md MsgDb 所存储的是ReceiveData后得来的信息
     * @return boolean
     * @throws ErrMsgException
     */
    public synchronized boolean editTopic(ServletContext application,
                                          HttpServletRequest request,
                                          MsgDb md, FileUpload fu) throws
            ErrMsgException {
        md = md.getMsgDb(md.getId()); // 注意参数md并非是对应于id的md
        // 是交易贴
        if (md.getReplyid() == -1) {
            AuctionDb ad = new AuctionDb();
            ad = ad.getAuctionDb(md.getId());
            ad.setUserName(md.getName());
            String strcount = fu.getFieldValue("count");
            int count = 1;
            try {
                count = Integer.parseInt(strcount);
            }
            catch (Exception e) {
                throw new ErrMsgException(AuctionSkin.LoadString(request,
                        "err_count_must_string"));
            }
            String name = StrUtil.getNullStr(fu.getFieldValue("name"));
            if (name.equals(""))
                throw new ErrMsgException(AuctionSkin.LoadString(request,
                        "err_want_name"));
            /*
                         // 销售类型不能更改
                         int sellType = AuctionDb.SELL_TYPE_AUCTION;
                         String strsellType = fu.getFieldValue("sellType");
                         if (StrUtil.isNumeric(strsellType)) {
                sellType = Integer.parseInt(strsellType);
                         }
                         ad.setSellType(sellType);
             */
            String moneyCode = StrUtil.getNullStr(fu.getFieldValue("moneyCode"));
            String shopDir = StrUtil.getNullStr(fu.getFieldValue("shopDir"));
            if (shopDir.equals(""))
                shopDir = AuctionShopDirDb.DEFAULT;

            ad.setCount(count);
            // logger.info("name=" + name);
            ad.setName(name);

            // 如果该用户是商家,则判别其是否更改了目录
            AuctionShopDb as = new AuctionShopDb();
            as = as.getAuctionShopDb(md.getName());
            if (as.isLoaded()) { // 用户是商家
                String oldShopDir = ad.getShopDir();
                if (!oldShopDir.equals(shopDir)) {
                    // 如果不是改至系统目录,则重置商品的catalogCode
                    if (!shopDir.equals(AuctionShopDirDb.DEFAULT)) {
                        // 取得新商铺目录对应的catalogCode
                        AuctionShopDirDb asd2 = new AuctionShopDirDb();
                        asd2 = asd2.getAuctionShopDirDb(md.getName(), shopDir);
                        ad.setCatalogCode(asd2.getCatalogCode());
                    }
                    ad.setShopDir(shopDir);
                }
            }
            else { // 用户为散户
                String catalogCode = StrUtil.getNullString(fu.getFieldValue("catalogCode"));
                if (catalogCode.equals(Leaf.TYPE_NONE_OPTION_VALUE))
                    throw new ErrMsgException(AuctionSkin.LoadString(request, "err_want_catalog"));
                ad.setCatalogCode(catalogCode);
            }

            // 如果是拍卖
            if (ad.getSellType() == ad.SELL_TYPE_AUCTION) {
                String strbeginDate = fu.getFieldValue("beginDate");
                String strendDate = fu.getFieldValue("endDate");
                java.util.Date beginDate = null;
                try {
                    beginDate = DateUtil.parse(strbeginDate,
                                   "yyyy-MM-dd");
                }
                catch (Exception e) {
                    logger.error("editTopic:" + e.getMessage());
                }
                java.util.Date endDate = null;
                try {
                    endDate = DateUtil.parse(strendDate,
                        "yyyy-MM-dd");
                }
                catch (Exception e) {
                    logger.error("editTopic:" + e.getMessage());
                }
                if (beginDate == null || endDate == null) {
                    throw new ErrMsgException(AuctionSkin.LoadString(request,
                            "err_date_format"));
                }

                /*
                if (DateUtil.datediff(beginDate,
                                      new java.util.Date(Calendar.getInstance().
                        getTimeInMillis())) < 0) {
                    logger.info("beginDate=" + DateUtil.format(beginDate, "yyyy-MM-dd") + " endDate=" + DateUtil.format(endDate, "yyyy-MM-dd"));
                    throw new ErrMsgException(AuctionSkin.LoadString(request,
                            "err_beginDate_early_than_curDate"));
                }
                */

                if (DateUtil.compare(beginDate, endDate) == 1) {
                    throw new ErrMsgException(AuctionSkin.LoadString(request,
                            "err_beginDate_late_than_endDate"));
                }
                AuctionConfig ac = new AuctionConfig();
                int max = ac.getIntProperty(ac.ExpireDayMax);
                if (DateUtil.datediff(endDate, beginDate) > max)
                    throw new ErrMsgException(AuctionSkin.LoadString(request,
                            "err_expire_day_max"));

                ad.setBeginDate(beginDate);
                ad.setEndDate(endDate);
            }

            // 如果是一口价
            boolean isShow = false;
            if (ad.getSellType()==ad.SELL_TYPE_SELL) {
                String sIsShow = fu.getFieldValue("isShow");
                // 仅供展示
                if (sIsShow!=null && sIsShow.equals("true")) {
                    ad.setShow(true);
                    isShow = true;
                }
                else
                    ad.setShow(false);
            }

            // 检查图片是否已被修改
            boolean isImageChanged = false;
            String image = StrUtil.getNullString(ad.getImage());
            if (!image.equals("")) {
                // 原来有缩略图片,则从原来的缩略图片名称推断出文件名
                String origFile = image.substring(0, image.length()-4) + "." + md.getFileName();
                if (!origFile.equals(md.getFileName())) {
                    isImageChanged = true;
                    // 删除原来的文件
                    String realPath = application.getRealPath("/");
                    File imgFile = new File(realPath + "forum/" + ad.getImage());
                    imgFile.delete();
                }
            }
            if (isImageChanged) {
                String ext = StrUtil.getNullStr(md.getExtName());
                if (ext.equals("gif") || ext.equals("jpg") || ext.equals("jpeg") ||
                    ext.equals("png")) {
                    String fileName = md.getFileName();
                    ImageUtil iu = new ImageUtil();
                    String realPath = application.getRealPath("/");
                    File srcFile = new File(realPath + "forum/" + fileName);
                    // 根据文件名
                    image = FileUtil.getFileNameWithoutExt(fileName) +
                                   "_s.jpg";
                    logger.info("fileName=" + fileName);
                    logger.info(realPath + "forum/" + image);
                    File desFile = new File(realPath + "forum/" + image);
                    try {
                        iu.Image2Thumb(srcFile, desFile, 80);
                    } catch (IOException e) {
                        logger.error("EditTopic:" + e.getMessage());
                    }
                    ad.setImage(image);
                }
            }

            // 保存修改
            boolean re = ad.save();

            if (re) {
                AuctionWorthDb aw = new AuctionWorthDb();
                Vector awv = aw.list(md.getId());

                aw = (AuctionWorthDb)awv.get(0);
                // 如果是拍卖
                if (ad.getSellType() == AuctionDb.SELL_TYPE_AUCTION) {
                    String strPrice = fu.getFieldValue("price");
                    String strDlt = fu.getFieldValue("dlt");
                    String strReferPrice = fu.getFieldValue("referPrice");
                    double price = StrUtil.toDouble(strPrice);
                    double dlt = StrUtil.toDouble(strDlt);
                    double referPrice = StrUtil.toDouble(strReferPrice);

                    aw.setPrice(price);
                    aw.setDlt(dlt);
                    aw.setReferPrice(referPrice);
                    aw.setMoneyCode(moneyCode);
                    re = aw.save();
                }

                // 如果是一口价
                if (ad.getSellType() == AuctionDb.SELL_TYPE_SELL) {
                    Iterator awir = awv.iterator();

                    // 删除原来的AuctionWorthDb
                    while (awir.hasNext()) {
                        AuctionWorthDb awd = (AuctionWorthDb) awir.next();
                        awd.del();
                    }

                    String[] moneyTypes = fu.getFieldValues("moneyType");
                    if (moneyTypes != null) {
                        int len = moneyTypes.length;
                        for (int i = 0; i < len; i++) {
                            String strprice = fu.getFieldValue("price_" +
                                    moneyTypes[i]);
                            double price = 0.0;
                            logger.info("moneyTypes[" + i + "]=" + moneyTypes[i] + " price=" + strprice);
                            try {
                                price = Double.parseDouble(strprice);
                            } catch (Exception e) {
                                logger.error("EditTopic: Double.parseDouble " +
                                             e.getMessage());
                                throw new ErrMsgException(AuctionSkin.
                                        LoadString(request, "err_price_format"));
                            }
                            aw.setMsgRootId(md.getId());
                            aw.setMoneyCode(moneyTypes[i]);
                            aw.setPrice(price);
                            try {
                                aw.create();
                            }
                            catch (ResKeyException e) {
                                throw new ErrMsgException(e.getMessage(request));
                            }
                        }
                    } else {
                        // 如果不是仅供展示,则报缺少币种错
                        if (!isShow) {
                            throw new ErrMsgException(AuctionSkin.LoadString(
                                    request, "err_want_money"));
                        }
                    }
                }
            }
        }
        // refreshWorthOfAuction
        return true;
    }

    public boolean AddNew(ServletContext application,
                          HttpServletRequest request, MsgDb md, FileUpload fu) throws
            ErrMsgException {
        // logger.info("AddNew:msgRootId=" + md.getId());
        md = md.getMsgDb(md.getId());

        AuctionDb ad = new AuctionDb();
        ad.setmsgRootId(md.getId());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -