📄 auctionmsgaction.java~12~
字号:
ad.setState(ad.STATE_SELLING);
ad.setUserName(md.getName());
String strUserType = fu.getFieldValue("userType");
String strcount = fu.getFieldValue("count");
int userType = 0;
if (StrUtil.isNumeric(strUserType))
userType = Integer.parseInt(strUserType);
int count = 1;
if (StrUtil.isNumeric(strcount))
count = Integer.parseInt(strcount);
else
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);
}
String moneyCode = StrUtil.getNullStr(fu.getFieldValue("moneyCode"));
String shopDir = StrUtil.getNullStr(fu.getFieldValue("shopDir"));
if (shopDir.equals("")) {
shopDir = AuctionShopDirDb.DEFAULT;
String catalogCode = StrUtil.getNullStr(fu.getFieldValue("catalogCode"));
// 验证是商品目录是否合法
if (catalogCode.equals("") || catalogCode.equals(Leaf.TYPE_NONE_OPTION_VALUE)) {
throw new ErrMsgException(AuctionSkin.LoadString(request, "err_want_catalog"));
}
else
ad.setCatalogCode(catalogCode);
}
else {
// 根据shopDir得到catalogCode
AuctionShopDirDb asd = new AuctionShopDirDb();
asd = asd.getAuctionShopDirDb(md.getName(), shopDir);
ad.setCatalogCode(asd.getCatalogCode());
}
ad.setSellType(sellType);
ad.setCount(count);
// logger.info("name=" + name);
ad.setName(name);
ad.setUserType(userType);
ad.setShopDir(shopDir);
// 如果销售类型为拍卖
if (sellType == 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("AddNew:" + e.getMessage());
}
java.util.Date endDate = null;
try {
endDate = DateUtil.parse(strendDate, "yyyy-MM-dd");
} catch (Exception e) {
logger.error("AddNew:" + 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)
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 (sellType == AuctionDb.SELL_TYPE_SELL) {
// 检查是否仅供展示
String sisShow = fu.getFieldValue("isShow");
// logger.info("isShow=" + sisShow);
if (sisShow!=null && sisShow.equals("true")) {
isShow = true;
ad.setShow(true);
}
}
boolean re = false;
try {
AuctionWorthDb aw = new AuctionWorthDb();
aw.setMsgRootId(md.getId());
// 如果是拍卖
if (sellType == AuctionDb.SELL_TYPE_AUCTION) {
String strPrice = fu.getFieldValue("price");
String strDlt = fu.getFieldValue("dlt");
String strReferPrice = fu.getFieldValue("referPrice");
try {
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.create();
}
catch (ErrMsgException e) {
throw new ErrMsgException(AuctionSkin.LoadString(
request, "err_price_format"));
}
}
// 如果是一口价
if (sellType == AuctionDb.SELL_TYPE_SELL) {
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) {
re = false;
logger.error("AddNew: Double.parseDouble " +
e.getMessage());
throw new ErrMsgException(AuctionSkin.
LoadString(request, "err_price_format"));
}
aw.setMoneyCode(moneyTypes[i]);
aw.setPrice(price);
re = aw.create();
}
} else {
// 如果不是为了展示,则价格必须要填
if (!isShow) {
re = false;
throw new ErrMsgException(AuctionSkin.LoadString(
request, "err_want_money"));
}
else
re = true;
}
}
} catch (ResKeyException e) {
re = false;
throw new ErrMsgException(e.getMessage(request));
}
if (re) {
try {
re = ad.create();
if (re) {
// 生成缩略图
ad = ad.getAuctionDb(md.getId());
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);
// 根据文件名
String image = FileUtil.getFileNameWithoutExt(fileName) + "_s.jpg";
// logger.info(realPath + "forum/" + image);
File desFile = new File(realPath + "forum/" + image);
try {
iu.Image2Thumb(srcFile, desFile, 80);
}
catch (IOException e) {
logger.error("AddNew:" + e.getMessage());
}
ad.setImage(image);
ad.save();
}
}
} catch (ResKeyException e) {
throw new ErrMsgException(e.getMessage(request));
}
}
return re;
}
public boolean AddQuickReply(ServletContext application,
HttpServletRequest request, long replyMsgId) throws
ErrMsgException {
return true;
}
/**
* 本方法置于MsgMgr中delTopic真正删除贴子之前,使在删除插件相应内容后,再删除贴子本身
* @param application ServletContext
* @param request HttpServletRequest
* @param md MsgDb
* @return boolean
* @throws ErrMsgException
*/
public boolean delTopic(ServletContext application,
HttpServletRequest request, MsgDb md) throws
ErrMsgException {
// 如果是删除根贴
if (md.getReplyid() == -1) {
// 删除plugin_auction中对应的内容,所有plugin_auction_sq_message中对应于msgRootId的内容
// 及所有plugin_auction_user中对应的msgRootId中的内容
AuctionDb ad = new AuctionDb();
ad = ad.getAuctionDb(md.getId());
String image = StrUtil.getNullString(ad.getImage());
ad.del();
if (!image.equals("")) {
image = application.getRealPath("/") + "forum/" + image;
File f = new File(image);
f.delete();
}
}
return true;
}
/**
* 此函数置于MsgDb delSingleMsg中真正删除贴子之前,以便于递归删除贴子
* @param delId int
* @return boolean
* @throws ErrMsgException
*/
public boolean delSingleMsg(long delId) throws
ErrMsgException {
//AuctionMsgDb sm = new AuctionMsgDb();
//sm = sm.getAuctionMsgDb(delId);
//return sm.del();
return true;
}
public boolean AddReply(ServletContext application,
HttpServletRequest request, MsgDb md, FileUpload fu) throws
ErrMsgException {
String auctionAction;
auctionAction = StrUtil.getNullString(fu.getFieldValue("auctionAction"));
// logger.info("auctionAction=" + auctionAction);
if (auctionAction.equals(ACTION_APPLY)) {
// 登记该贴为申请贴
} else if (auctionAction.equals(this.ACTION_ACCEPT_APPLY)) { // 同意申请成为追求者
// 发送短消息至被回复者,它已被置为追求者
}
//else if (auctionAction.equals(this.ACTION_DECLINE_APPLY)) {
//}
else if (auctionAction.equals(ACTION_APPLY_MARRY)) { // 登记申请结婚
// 登记该贴为申请结婚贴
} else if (auctionAction.equals(this.ACTION_ACCEPT_MARRY)) { // 接受求婚
// 发送短消息至被回复者,它已被置为追求者
}
//else if (auctionAction.equals(this.ACTION_DECLINE_MARRY)) {
//}
else {
// 登记密级
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -