Package com.lgx8.management.action

Source Code of com.lgx8.management.action.MerchantContoller

package com.lgx8.management.action;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.lgx8.common.PageArgument;
import com.lgx8.common.PageList;
import com.lgx8.common.servlet.BaseController;
import com.lgx8.common.util.StrUtil;
import com.lgx8.management.dao.IDictionaryDao;
import com.lgx8.management.dao.IMerchantDao;
import com.lgx8.management.dao.IOrganizationDao;
import com.lgx8.management.entities.Dictionary;
import com.lgx8.management.entities.Merchant;
import com.lgx8.management.entities.Organization;
import com.lgx8.management.service.IUserOrganizationMerchantService;
import com.lgx8.right.dao.IUserDao;
import com.lgx8.right.entities.RunTimeUser;
import com.lgx8.right.entities.User;

@Controller
public class MerchantContoller extends BaseController {
 
  @Resource(name="merchantDao")
  IMerchantDao merchantDao;
 
  @Resource(name="organizationDao")
  IOrganizationDao organizationDao;
 
  @Resource(name="userDao")
  IUserDao userDao;
 
  @Autowired
  IUserOrganizationMerchantService userOrganizationMerchantService;
 
  @Resource(name="dictionaryDao")
  IDictionaryDao dictionaryDao;
 
  /**
   * 商家名称、商家编号、商家登陆账号、联系人姓名、推广中心名称、运营中心名为查询条件查询联盟商家列表
   * @param request
   * @param response
   * @return
   */
  @RequestMapping("/merchant/pageQuery.do")
  public ModelAndView pageQuery(HttpServletRequest request,HttpServletResponse response){
    RunTimeUser rtUser = RunTimeUser.getRunTimeUser(request);
    String sjmc = request.getParameter("SJMC");
    String sjbh = request.getParameter("SJGSZCBH");
    String sjdlzh = request.getParameter("SJFRDBUN");
    String fzr = request.getParameter("SJFRDBTN");
    String tgzx = request.getParameter("ORG");
    long _orid = 0;
    long _type = 0;
    if(rtUser!=null){
      _type = rtUser.getUsertype();
      if( _type == 4 || _type == 5){
        Organization _or = (Organization)userOrganizationMerchantService.getOrganizationOrMerchantByUser(rtUser);
        if(_or!=null){
          _orid = _or.getID();
        }
      }
    }
    MerchantQueryForm  queryForm = new MerchantQueryForm();
    queryForm.setSJMC(sjmc);
    queryForm.setSJGSZCBH(sjbh);
    queryForm.setSJDLZH(sjdlzh);
    queryForm.setSJFRDB(fzr);
    queryForm.setTGZXMC(tgzx);
    queryForm.setUsertype(_type);
    queryForm.setOrgid(_orid);
    PageArgument pageArgment = getPageInfo(request);
    PageList pageList = merchantDao.listMerchantByConditions(queryForm.toHql(), queryForm.getPara(), pageArgment);
    printJSON(response, pageList.toJSON());
    return null;
  }
 
  @RequestMapping("/merchant/delMerchant.do")
  public ModelAndView delMerchant(HttpServletRequest request,HttpServletResponse response) {
    //准备删除的联盟商
        String[] delMerchantIds = this.getKeyStoreArray(request);
    if (delMerchantIds.length > 0) {
        for (int i = 0 ; i < delMerchantIds.length ; i++) {
          Merchant m = merchantDao.getMerchantById(Long.parseLong(delMerchantIds[i]));
          if(m != null)
        {
            m.setDELETEFLAG("1");
              merchantDao.updateMerchant(m);
        }
        }
      }
    this.clearKeyStore(request);
    return new ModelAndView(new RedirectView("../page/management/merchant/list_merchant.jsp"));
  }
 
  @RequestMapping("/merchant/addMerchantIni.do")
  public ModelAndView addMerchantIni(HttpServletRequest request,HttpServletResponse response) {
    /**
     * 初始化推荐组织机构
     */
    List<Organization> organizations = organizationDao.listAllOrganizations();
    return new ModelAndView("/management/merchant/modify_merchant").addObject("orgs", organizations);
  }
 
  @RequestMapping("/merchant/modifyMerchantIni.do")
  public ModelAndView modifyMerchantIni(HttpServletRequest request,HttpServletResponse response) {
    String SJID = request.getParameter("id");//商家id
    Merchant mr = merchantDao.getMerchantById(Integer.parseInt(SJID));
    /**
     * 初始化推荐组织机构
     */
    List<Organization> organizations = organizationDao.listAllOrganizations();
    request.setAttribute("orgs", organizations);
    return new ModelAndView("/management/merchant/modify_merchant").addObject("Merchant", mr);
  }
 
  @RequestMapping("/merchant/setMerchantCard.do")
  public ModelAndView setMerchantCard(HttpServletRequest request,HttpServletResponse response) {
    String SJID = request.getParameter("id");//商家id
    Merchant mr = merchantDao.getMerchantById(Integer.parseInt(SJID));
    /**
     * 初始化推荐组织机构
     */
    List<Organization> organizations = organizationDao.listAllOrganizations();
    request.setAttribute("orgs", organizations);
    return new ModelAndView("/management/merchant/setcard_merchant").addObject("Merchant", mr);
  }
 
  /**
   * @param request
   * @param response
   * @return
   */
  @RequestMapping("/merchant/saveMerchant.do")
  public ModelAndView saveMerchant(HttpServletRequest request,HttpServletResponse response) {
    RunTimeUser rtUser = RunTimeUser.getRunTimeUser(request);
    String SJID = request.getParameter("SJID");//商家id
    String posturl = request.getParameter("posturl");//商家自助修改资料
    String SJMC = request.getParameter("SJMC");//商家名称
    String SJLX = request.getParameter("SJLX");//商家类型
    String SJDZ = request.getParameter("SJDZ");//商家地址
    String SJDHHM = request.getParameter("SJDHHM");//商家电话
    String SJFWXJ = request.getParameter("SJFWXJ");//商家评定星级
    String YYKSSJ = request.getParameter("YYKSSJ");//开始时间
    String YYJSSJ = request.getParameter("YYJSSJ");//结束时间
    String SFSHSM = request.getParameter("SFSHSM");//是否送货上门
    String SJFRDB = request.getParameter("Jgfzr");//商家法人代表User
    String SJGSZCBH = request.getParameter("SJGSZCBH");//商家工商注册编号
    String organization = request.getParameter("organization");
    String RESERVATION01 = request.getParameter("RESERVATION01");
    String RESERVATION02 = request.getParameter("RESERVATION02");
    String RESERVATION03 = request.getParameter("RESERVATION03");
    String RESERVATION04 = request.getParameter("RESERVATION04");
    String RESERVATION05 = request.getParameter("RESERVATION05");
    String RESERVATION06 = request.getParameter("RESERVATION06");
   

    String province = request.getParameter("province");
    String city = request.getParameter("city");
    String county = request.getParameter("county");
   
   
    Dictionary d0 = dictionaryDao.findByKindAndCode("province", province);
    Dictionary d1 = dictionaryDao.findByKindAndCode("city", city);
    Dictionary d2 = dictionaryDao.findByKindAndCode("county", county);
   
    Organization o = null;
    if (!StrUtil.isNullStr(organization)) {
      o = organizationDao.getOrganizationById(Long.parseLong(organization));
    }
    User u = null;
    if (!StrUtil.isNullStr(SJFRDB)) {
//      u = userDao.findUser("username", new Object[]{SJFRDB});
     
      u = userDao.findUserByUserName(SJFRDB);
      u.setUsertype(User.USER_TYPE_MERCHANT);
    }
    if (!StrUtil.isNullStr(SJID) && !"0".equals(SJID)){
      Merchant mr = merchantDao.getMerchantById(Integer.parseInt(SJID));
      mr.setSJMC(SJMC);
      mr.setSJLX(SJLX);
      mr.setSFSHSM(SFSHSM);
      mr.setYYKSSJ(YYKSSJ);
      mr.setYYJSSJ(YYJSSJ);
      mr.setSJFWXJ(SJFWXJ);
      mr.setSJDZ(SJDZ);
      mr.setSJDHHM(SJDHHM);
      mr.setSJGSZCBH(SJGSZCBH);
      if(o != null)mr.setOrganization(o);
      if(o != null)mr.setAreaNode(o.getJGSZQY());
      mr.setSJFRDB(u);
      mr.setUser(rtUser);
      mr.setRESERVATION01(RESERVATION01);
      mr.setRESERVATION02(RESERVATION02);
      mr.setRESERVATION03(RESERVATION03);
      mr.setRESERVATION04(RESERVATION04);
      mr.setRESERVATION05(RESERVATION05);
      mr.setRESERVATION06(RESERVATION06);
      mr.setDELETEFLAG("0");
     
      mr.setProvince(d0 != null ? d0.getDETAIL():province);
      mr.setCity(d1 != null ? d1.getDETAIL():city);
      mr.setCounty(d2 != null ? d2.getDETAIL():county);
     
      merchantDao.updateMerchant(mr);
     
      u.setOrganizationid(mr.getID());
     
      userDao.updateUser(u);
    } else {
      Merchant mr = new Merchant();
      mr.setSJMC(SJMC);
      mr.setSJLX(SJLX);
      mr.setSFSHSM(SFSHSM);
      mr.setYYKSSJ(YYKSSJ);
      mr.setYYJSSJ(YYJSSJ);
      mr.setSJFWXJ(SJFWXJ);
      mr.setSJDZ(SJDZ);
      mr.setSJDHHM(SJDHHM);
      mr.setSJGSZCBH(SJGSZCBH);
      if(o != null)mr.setOrganization(o);
      if(o != null)mr.setAreaNode(o.getJGSZQY());
      mr.setSJFRDB(u);
      mr.setUser(rtUser);
      mr.setSJTJSJ(new Date());
      mr.setRESERVATION01(RESERVATION01);
      mr.setRESERVATION02(RESERVATION02);
      mr.setRESERVATION03(RESERVATION03);
      mr.setRESERVATION04(RESERVATION04);
      mr.setRESERVATION05(RESERVATION05);
      mr.setRESERVATION06(RESERVATION06);
      mr.setDELETEFLAG("0");
     
      mr.setProvince(d0 != null ? d0.getDETAIL():province);
      mr.setCity(d1 != null ? d1.getDETAIL():city);
      mr.setCounty(d2 != null ? d2.getDETAIL():county);
     
      merchantDao.createMerchant(mr);
     
      u.setOrganizationid(mr.getID());
     
      userDao.updateUser(u);
    }
   
    if (!"".equals(posturl) && posturl != null) {
      return new ModelAndView(posturl).addObject("ErrMsg", "修改成功");
    }
    return new ModelAndView(new RedirectView("../page/management/merchant/list_merchant.jsp"));
  }
}
TOP

Related Classes of com.lgx8.management.action.MerchantContoller

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.