方法比较长,仅仅贴了入口到出问题的那一句
@At
@Ok("json")
@RequiresPermissions("busi.manager.productDetail.edit")
@SLog(tag = "Edit", msg = "Edit:productDetail")
public Object editDo(@Param("::detail.") ProductDetail productDetail, HttpServletRequest req) {
try {
if (!isEmpty(productDetail)) {
Subject subject = SecurityUtils.getSubject();
Sys_user curUser = (Sys_user) subject.getPrincipal();
Supplier sup = supService.fetch(Cnd.where("txt_user_id", "=", curUser.getId()));
productDetail.setOpById(curUser.getId());
productDetail.setOpByName(curUser.getNickname());
productDetail.setDtUpdateTime(new Date());
Product pro = productDetail.getProduct();
//更新大类小类, 用#分开
String[] subCate = pro.getTxt_product_sub_category().split("#");
int subId = Integer.valueOf(subCate[1]);
pro.setTxt_product_sub_category(subCate[0]);
pro.setTxt_product_sub_category_id(subCate[1]);
ProductCategory cate = categoryService.fetch(subId);
ProductCategory fCate = categoryService.fetch(cate.getInt_parent_id());
pro.setTxt_product_category(fCate.getTxt_category_name());
pro.setTxt_product_category_id(String.valueOf(fCate.getId()));
pro.setOpById(curUser.getId());
pro.setOpByName(curUser.getNickname());
pro.setDtUpdateTime(new Date());
pro.setTxt_product_description(pro.getTxt_product_description().replace("\"", "'"));
//如果非定制那么清空这两个字段
if(!pro.isForCompany())
{
pro.setTxt_company_id("");
pro.setTxt_company_name("");
}
//库存
ProductStock stock = productDetail.getProductStock();
//价格
ProductPrice price = productDetail.getProductPrice();
//查询旧的价格
ProductPrice oldPrice = priceService.fetch(Cnd.where("txt_product_detail_code", "=", productDetail.getTxt_product_detail_code()));
ProductPriceLog priceLog = null;
if (!isEmpty(oldPrice)) {
if (!oldPrice.equals(price)) {//如果价格有变动
priceLog = new ProductPriceLog(price);
priceLog.setDetail_code(productDetail.getTxt_product_detail_code());
priceLog.setTxt_status(CommonConst.PRODUCT_TO_CHECK);//价格待审核
priceLog.setCreate_dt(new Date());
priceLog.setCreate_by(curUser.getId());
productDetail.setTxt_product_status(CommonConst.PRODUCT_MODIFY_ON);//价格修改待上架
}
}
//图片
//应用根目录
String strDirPath = req.getSession().getServletContext().getRealPath("/");
strDirPath = strDirPath.substring(0, strDirPath.length() - 1);
String srcPath = "";
String tarfolder = "";
//如果当前的detail的图片发生了改变
//更新
String id = productDetail.getId();
ProductDetail oldDetail = productDetailService.fetch(id);
if(!productDetail.getTxt_detail_img().equals(oldDetail.getTxt_detail_img()))
{
srcPath = strDirPath + productDetail.getTxt_detail_img();
String absPath = productDetail.getTxt_detail_img();
String fileName = FileUtil.getFileName(absPath);
tarfolder = strDirPath + "/assets/img/productImage/" + sup.getTxt_supplier_name() + "/" + fCate.getTxt_category_name() + "/" + subCate[0] + "/";
productDetail.setTxt_detail_img(FileUtil.reNameFile(strDirPath, srcPath, tarfolder, fileName));
}