com.jkkp.modules.supplier.controller.SupplierController.java Source code

Java tutorial

Introduction

Here is the source code for com.jkkp.modules.supplier.controller.SupplierController.java

Source

package com.jkkp.modules.supplier.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import com.jkkp.appapi.common.utils.HttpFileTools;
import com.jkkp.common.BaseController;
import com.jkkp.common.interceptor.AccessMenu;
import com.jkkp.common.interceptor.AccessPagination;
import com.jkkp.common.response.ResponseObject;
import com.jkkp.common.response.ResponsePagination;
import com.jkkp.modules.basedata.constants.AttachmentConstant;
import com.jkkp.modules.basedata.constants.UserLoginType;
import com.jkkp.modules.basedata.model.Attachment;
import com.jkkp.modules.basedata.service.IAreaDomainService;
import com.jkkp.modules.basedata.service.IAttachmentService;
import com.jkkp.modules.basedata.service.impl.AttachmentServiceImpl;
import com.jkkp.modules.basedata.view.VAttachment;
import com.jkkp.modules.supplier.mapper.SupplierMapper;
import com.jkkp.modules.supplier.model.CertifcateType;
import com.jkkp.modules.supplier.model.Supplier;
import com.jkkp.modules.supplier.model.SupplierCompany;
import com.jkkp.modules.supplier.model.SupplierCompanyStaff;
import com.jkkp.modules.supplier.model.SupplierLevel;
import com.jkkp.modules.supplier.model.SupplierUser;
import com.jkkp.modules.supplier.service.ICertifcateTypeService;
import com.jkkp.modules.supplier.service.ISupplierCertifcateRelationService;
import com.jkkp.modules.supplier.service.ISupplierLevelService;
import com.jkkp.modules.supplier.service.ISupplierService;
import com.jkkp.modules.supplier.service.impl.SupplierCompanyServiceImpl;
import com.jkkp.modules.supplier.service.impl.SupplierCompanyStaffServiceImpl;
import com.jkkp.modules.supplier.service.impl.SupplierUserServiceImpl;
import com.jkkp.modules.supplier.view.SupplierCompanyStaffInfo;
import com.jkkp.modules.supplier.view.VSupplier;
import com.jkkp.modules.supplier.view.VSupplierUser;
import com.jkkp.modules.system.model.Admin;
import com.jkkp.pc.main.service.IRegionService;
import com.jkkp.utils.AllDao;
import com.jkkp.utils.CheckedUtil;
import com.jkkp.utils.CommonUtil;
import com.jkkp.utils.Pager;
import com.jkkp.utils.Pagination;
import com.jkkp.utils.RequestParamUtils;

@Controller
@RequestMapping("/supplier")
public class SupplierController extends BaseController {

    @Autowired
    private IAreaDomainService areaDomainService;
    @Autowired
    private ISupplierService supplierService;
    @Autowired
    private ISupplierLevelService supplierLevelService;
    @Autowired
    private SupplierUserServiceImpl supplierUserServiceImpl;
    @Autowired
    private SupplierCompanyServiceImpl service;
    @Autowired
    private SupplierCompanyStaffServiceImpl serviceImpl;
    @Autowired
    private IAttachmentService attachmentService;
    @Autowired
    private SupplierMapper dao;
    @Autowired
    private SupplierMapper supplierMapper;
    @Autowired
    private ICertifcateTypeService certifcateTypeService;
    @Autowired
    private ISupplierCertifcateRelationService supplierCertifcateRelationService;
    @Autowired
    private ISupplierConditionService supplierConditionService;
    @Autowired
    private IRegionService regionService;
    @Autowired
    private AttachmentServiceImpl attachmentServiceImpl;

    /**
     * ???
     */
    @AccessMenu
    @AccessPagination(custom = true, async = AccessPagination.ASYNC.ASYNC_NO)
    @RequestMapping("/supplierByType")
    public String findSupplierByType(HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("typeId", 1);
        Pagination.setSearchParams(params);
        Pagination.setPageParams(request, supplierMapper, "findSupplierByType", "findSupplierByTypeCount");
        request.setAttribute("pagination", supplierService.paginationCustom(params));
        request.setAttribute("mid", request.getParameter("mid"));
        request.setAttribute("pid", request.getParameter("pid"));
        return "/supplier/supplier_staff_Manager";
    }

    @ResponseBody
    @RequestMapping("/supplierByTypePagination.do")
    public Object supplierByTypePagination(HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("typeId", 1);
        Pagination.setSearchParams(params);
        Pagination.setPageParams(request, supplierMapper, "findSupplierByType", "findSupplierByTypeCount");
        return new ResponsePagination(supplierService.paginationCustom(params));
    }

    /**
     * 
     * 
     * @return
     */
    @AccessMenu
    @RequestMapping("/examineView")
    public String examineView(HttpServletRequest request, @RequestParam Integer id) {

        Supplier supplier = supplierService.findById(id);

        // ?
        SupplierCompany supplierCompany = service.fin(id);
        // ?
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        List<SupplierCompanyStaffInfo> staffList = serviceImpl.findSaffListBySpId(params);
        Attachment att = new Attachment();
        att.setMainid(id);
        // ??
        VSupplierUser su = new VSupplierUser();
        su.setSpId(id);
        this.getCertifcateList(request, su.getSpId());
        // ?logo
        List<VAttachment> logoList = attachmentService.findAttachment(id, AttachmentConstant.SUPPLIER_COMPANY_TYPE);
        request.setAttribute("logo", logoList.size() > 0 ? logoList.get(0).getDownloadPath() : "");

        //?
        List<VAttachment> fanList = attachmentService.findAttachment(id, AttachmentConstant.SUPPLIER_IDCARD_FRONT);
        List<VAttachment> zhengList = attachmentService.findAttachment(id,
                AttachmentConstant.SUPPLIER_IDCARD_NEGATIVE);
        //?
        List<VAttachment> yingyeList = attachmentService.findAttachment(id,
                AttachmentConstant.SUPPLIER_BUSINESS_LICENCE);
        request.setAttribute("fanList", fanList);
        request.setAttribute("zhengList", zhengList);
        request.setAttribute("yingyeList", yingyeList);

        request.setAttribute("supplierCompany", supplierCompany);
        request.setAttribute("sp", supplier);
        request.setAttribute("mid", request.getParameter("mid"));
        request.setAttribute("pid", request.getParameter("pid"));
        request.setAttribute("staffList", staffList);

        return "/supplier/examineView";
    }

    /**
     * 
     * 
     * @param cause
     *            
     * @return
     */
    @ResponseBody
    @RequestMapping("/examine.do")
    public Object examine(HttpServletRequest request, @RequestParam(value = "id", required = false) Integer id,
            @RequestParam(value = "flag", required = false) boolean flag,
            @RequestParam(value = "cause", required = false) String cause) {

        Supplier supplier = supplierService.findById(id);
        try {
            if (flag) {
                supplier.setProxyStatus(1);
                supplier.setCause(null);
                supplierService.update(supplier);
                return new ResponseObject(true, supplier.getSpName() + " !");
            } else {
                supplier.setProxyStatus(-1);
                if (StringUtils.isNotEmpty(cause)) {
                    supplier.setCause(cause);
                } else {
                    return new ResponseObject(false, " !");
                }
                supplierService.update(supplier);
                return new ResponseObject(true, supplier.getSpName() + " !");
            }

        } catch (Exception e) {
            return new ResponseObject(false, ",?? !");
        }
    }

    //
    @AccessMenu
    @AccessPagination(custom = true, async = AccessPagination.ASYNC.ASYNC_NO)
    @RequestMapping(value = "/index")
    public String index(HttpServletRequest request) {
        request.setAttribute("pagination", supplierService.pagination());
        //request.setAttribute("areaDomain", areaDomainService.finAll());
        request.setAttribute("regionList", regionService.getParentRegions());
        return "/supplier/supplier-list";
    }

    //?
    @ResponseBody
    @AccessPagination(custom = true, async = AccessPagination.ASYNC.ASYNC_YES)
    @RequestMapping("/pagination.do")
    public void pagination(HttpServletRequest request) {
        Pagination.setContext(supplierService);
    }

    //----------- 
    @AccessMenu
    @AccessPagination(custom = true, async = AccessPagination.ASYNC.ASYNC_NO)
    @RequestMapping(value = "/examineList")
    public String examineList(HttpServletRequest request) {
        //      Map<String, Object> params = new HashMap<String, Object>();
        //      params.put("state", 0);
        //      Pagination.setSearchParams(params);
        //      Pagination.setPageParams(request, supplierMapper, "findPage","countPage");
        //      request.setAttribute("pagination",supplierService.paginationCustom(params));
        //      request.setAttribute("areaDomain", areaDomainService.finAll());

        request.setAttribute("pagination", supplierService.pagination());
        request.setAttribute("regionList", regionService.getParentRegions());
        return "/supplier/examine_list";
    }

    @ResponseBody
    @RequestMapping("/proxyOneSupplier.do")
    public Object proxyOneSupplier(HttpServletRequest req) {
        try {
            Integer level = CommonUtil.stringToInteger(req.getParameter("level"));
            Integer proxyStatus = CommonUtil.stringToInteger(req.getParameter("proxyStatus"));
            Integer spId = CommonUtil.stringToInteger(req.getParameter("spId"));
            Float gainRate = CommonUtil.stringToFloat(req.getParameter("gainRate"));
            supplierService.proxyOneSupplier(level, proxyStatus, spId, gainRate);
            return new ResponseObject(true, "?");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseObject(false, "");
        }

    }

    //----------- ----------
    @AccessMenu
    @RequestMapping("/detail")
    public String detail(HttpServletRequest request, @RequestParam(required = false) Integer id) {
        if (id != null) {
            // ?
            SupplierCompany supplierCompany = service.fin(id);
            request.setAttribute("supplierCompany", supplierCompany);
            Supplier supplier = supplierService.findById(id);
            request.setAttribute("sp", supplier);

            getCertifcateList(request, id);
            // ?logo
            List<VAttachment> logoList = attachmentService.findAttachment(id,
                    AttachmentConstant.SUPPLIER_COMPANY_TYPE);
            request.setAttribute("logo", logoList.size() > 0 ? logoList.get(0).getDownloadPath() : "");
            if (supplier.getType() == UserLoginType.RenovationCompany_TYPE) {
                // ?
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("id", id);
                List<SupplierCompanyStaffInfo> staff = serviceImpl.findSaffListBySpId(params);

                // ??
                List<VAttachment> staffList = attachmentService.findAttachment(null,
                        AttachmentConstant.SUPPLIER_STAFF_TYPE);

                // ??
                for (VAttachment attachment : staffList) {
                    for (SupplierCompanyStaffInfo supplierCompanyStaffInfo : staff) {
                        if (attachment.getMainid().equals(supplierCompanyStaffInfo.getId()))
                            supplierCompanyStaffInfo.setAvatar(attachment.getDownloadPath());
                    }
                }
                request.setAttribute("st", staff);
                return "/supplier/supplier_detail";
            }
            return "/supplier/supervisor_detail";
        }
        return "/supplier/supplier_detail";
    }

    // ?
    @AccessMenu
    @RequestMapping("/edit")
    public String edit(HttpServletRequest request) {
        //?
        request.setAttribute("regionList", regionService.getParentRegions());

        int id = CommonUtil.stringToInteger(request.getParameter("id"));
        Supplier supplier = supplierService.supplierDetail(id);
        if (supplier != null) {
            //?
            supplier.setGainRate(supplier.getGainRate() * 100);
            Integer regionId = supplier.getRegionId();
            request.setAttribute("regionName", regionService.selectRegionName(regionId));
        }
        request.setAttribute("supplier", supplier);
        //????
        if (supplier != null && supplier.getLevelId() != null && supplier.getLevelId() > 6) {
            request.setAttribute("supplierLevel", supplierLevelService.findById(supplier.getLevelId()));
        }

        return "/supplier/supplier_edit";
    }

    // ?
    @AccessMenu
    @RequestMapping("/add")
    public String addOne(HttpServletRequest request) {
        request.setAttribute("regionList", regionService.getParentRegions());
        return "/supplier/supplier_add";
    }

    //?
    @RequestMapping(value = "/save.do")
    public String save(HttpServletRequest req, Integer regionId, String spName, String contactUser,
            String contactMobile, String legalPerson, Float gainRate, String address, Integer type, Integer levelId,
            Integer levelMoney, String bindMobile) {
        try {
            req.setCharacterEncoding("utf-8");
            String abbreviation = req.getParameter("abbreviation");
            System.out.println("save legalPerson=" + legalPerson);

            //?
            Supplier supplier = new Supplier();
            supplier.setAbbreviation(abbreviation);
            //supplier.setCityDomain(cityDomain);
            supplier.setSpName(spName);
            supplier.setContactUser(contactUser);
            supplier.setLegalPerson(legalPerson);
            supplier.setContactMobile(contactMobile);
            supplier.setGainRate(gainRate / 100);
            //         supplier.setStartDate(startDate);
            //         supplier.setEndDate(endDate);
            supplier.setAddress(address);
            supplier.setType(type);
            supplier.setBindMobile(bindMobile);
            supplier.setLevelId(levelId);
            supplier.setRegionId(regionId);
            if (levelId != null && levelId == 0) {
                List<SupplierLevel> levelMoneyList = supplierLevelService.selectByProperty("levelMoney",
                        levelMoney);
                if (levelMoneyList.size() > 0) {
                    supplier.setLevelId(levelMoneyList.get(0).getId());
                } else {
                    SupplierLevel supplierLevel = supplierLevelService.saveOne(levelMoney);
                    supplier.setLevelId(supplierLevel.getId());
                }
            }
            supplierService.saveOrUpdate(supplier);
            String params = RequestParamUtils.joinRedirectParams(req, new String[] { "mid", "pid" });
            return "redirect:index.xhtml" + params;
        } catch (Exception e) {
            logger.error("", e);
            return "404";
        }

    }

    //?
    @RequestMapping(value = "/updateOne.do", method = RequestMethod.POST)
    public String updateOneSupplier(HttpServletRequest req, Integer regionId, String spName, String contactUser,
            String contactMobile, String legalPerson, Float gainRate, String address, Integer type, Integer levelId,
            Integer spId, String bindMobile, Integer levelMoney) {
        try {
            req.setCharacterEncoding("utf-8");
            String abbreviation = req.getParameter("abbreviation");
            System.out.println("updateOne abbreviation=" + abbreviation);
            Supplier supplier = new Supplier();
            supplier.setAbbreviation(abbreviation);
            supplier.setId(spId);
            //supplier.setCityDomain(cityDomain);
            supplier.setSpName(spName);
            supplier.setContactUser(contactUser);
            supplier.setLegalPerson(legalPerson);
            supplier.setContactMobile(contactMobile);
            supplier.setGainRate(gainRate / 100);
            //         supplier.setStartDate(startDate);
            //         supplier.setEndDate(endDate);
            supplier.setAddress(address);
            supplier.setType(type);
            supplier.setBindMobile(bindMobile);
            supplier.setLevelId(levelId);
            supplier.setRegionId(regionId);
            if (levelId != null && levelId == 0) {
                List<SupplierLevel> levelMoneyList = supplierLevelService.selectByProperty("levelMoney",
                        levelMoney);
                if (levelMoneyList.size() > 0) {
                    supplier.setLevelId(levelMoneyList.get(0).getId());
                } else {
                    SupplierLevel supplierLevel = supplierLevelService.saveOne(levelMoney);
                    supplier.setLevelId(supplierLevel.getId());
                }
            }
            supplierService.saveOrUpdate(supplier);
            String params = RequestParamUtils.joinRedirectParams(req, new String[] { "mid", "pid" });
            return "redirect:index.xhtml" + params;
        } catch (Exception e) {
            logger.error("?", e);
            return "404";
        }
    }

    //
    @ResponseBody
    @RequestMapping(value = "deleteSuInfo.do")
    public Object deleteSuInfo(Integer spId) {
        try {
            supplierService.deleteSupplierInfosBySpid(spId);
            return new ResponseObject(true, "?");
        } catch (Exception e) {
            logger.error("?");
            return new ResponseObject(false, "");
        }
    }

    @ResponseBody
    @RequestMapping(value = "/findByArea.do")
    public Object findByArea(HttpServletRequest request, HttpServletResponse response) {
        Supplier supplier = new Supplier();
        supplier.setCityDomain(request.getParameter("city_domain"));
        List<Supplier> list = supplierService.select(supplier);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list", list);
        return map;
    }

    /**
     * ?
     */
    @ResponseBody
    @RequestMapping(value = "/checkUser")
    public Object checkUser(HttpServletRequest request, @RequestParam String name, @RequestParam String password,
            @RequestParam Integer type) {
        String pwd = CommonUtil.md5(password);
        SupplierUser supplier = supplierUserServiceImpl.login(name, pwd, type);
        if (supplier == null) {
            return new ResponseObject(false, "???!");
        } else {
            return new ResponseObject(true, "??!");
        }
    }

    /**
     * ?
     */
    @RequestMapping(value = "/login.do")
    public String login(HttpServletRequest request, @RequestParam String name, @RequestParam String pass,
            @RequestParam Integer type) {
        String pwd = null;
        try {
            pwd = CommonUtil.md5(pass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        SupplierUser supplier = supplierUserServiceImpl.login(name, pwd, UserLoginType.RenovationCompany_TYPE);
        if (supplier == null) {
            request.setAttribute("loginError", "????");
            return "/supplier/supplierlogin";
        } else {
            // JkkpSecureUtil.setAuthPass(request);
            request.getSession().setAttribute("su", supplier);
            return "/supplier/supplierlogin_list";
        }
    }

    /**
     * ??
     */
    @RequestMapping("/supervisorLogin.do")
    public String supervisorLogin(HttpServletRequest request, @RequestParam String name,
            @RequestParam String pass) {
        String pwd = CommonUtil.md5(pass);
        SupplierUser supplier = supplierUserServiceImpl.login(name, pwd, UserLoginType.Supervisor_TYPE);
        if (supplier == null) {
            request.setAttribute("loginError", "???!");
            return "redirect:/supplier/jl_login.xhtml";
        } else {
            request.getSession().setAttribute("su", supplier);
            return "/supplier/jl_index";
        }
    }

    /**
     * ??
     */
    @RequestMapping(value = "login")
    public String login(HttpServletRequest request, @RequestParam String name, @RequestParam String pass) {
        String pwd = CommonUtil.md5(pass);
        SupplierUser supplier = supplierUserServiceImpl.login(name, pwd, UserLoginType.RenovationCompany_TYPE);
        if (supplier == null) {
            request.setAttribute("loginError", "???!");
            return "redirect:/supplier/supplierlogin.xhtml";
        } else {
            request.getSession().setAttribute("su", supplier);
            return "/supplier/supplierlogin_list";
        }
    }

    /**
     * ?
     */
    @RequestMapping(value = "/supplierlogin")
    public String supplierLogin() {
        return "/supplier/supplierlogin";
    }

    /**
     * 
     */
    @RequestMapping(value = "/supplier_index")
    public String supplierlogin_list() {
        return "/supplier/supplierlogin_list";
    }

    /**
     * 
     */
    @RequestMapping(value = "/foreman_index")
    public String foreman_login() {
        return "/supplier/foreman_index";
    }

    /**
     * ??
     */
    @RequestMapping(value = "/jl_login")
    public String jlLogin() {
        return "/supplier/supervisorlogin";
    }

    /**
     * ?
     */
    @RequestMapping(value = "/jl_index")
    public String supervisor_list() {
        return "/supplier/jl_index";
    }

    /**
     * ?
     */
    @RequestMapping(value = "/logout")
    public String zx_logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return "redirect:supplier_index.xhtml";
    }

    /**
     * ??
     */
    @RequestMapping(value = "/jl_logout")
    public String jl_logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return "redirect:jl_index.xhtml";
    }

    /**
     * ?
     */
    @RequestMapping(value = "/foreman_logout")
    public String foreman_logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return "redirect:foreman_index.xhtml";
    }

    /**
     * ??
     * 
     * @param request
     * @param su
     */
    public void getCertifcateList(HttpServletRequest request, Integer id) {
        // ??
        List<CertifcateType> certList = certifcateTypeService.select(null);
        // ?
        //List<VAttachment> qualList = attachmentService.findAttachment(id,AttachmentConstant.SUPPLIER_QUAL_CERTIFICATE_TYPE);
        // ?
        //List<VAttachment> pracList = attachmentService.findAttachment(id,AttachmentConstant.SUPPLIER_PRAC_CERTIFICATE_TYPE);
        // ?
        List<VAttachment> decoration = attachmentService.findAttachment(id,
                AttachmentConstant.DECORATION_BUSINESS_CERTIFICATE);
        // ??
        List<VAttachment> bank = attachmentService.findAttachment(id, AttachmentConstant.BANK_OPEN_LICENCE);
        // ???
        List<VAttachment> trademark = attachmentService.findAttachment(id,
                AttachmentConstant.TRADEMARK_REGINTER_COPIES);
        // ?
        List<VAttachment> author = attachmentService.findAttachment(id,
                AttachmentConstant.AUTHORIZATION_CERTIFICATE);
        // ?
        List<VAttachment> taxation = attachmentService.findAttachment(id,
                AttachmentConstant.TAXATION_REGINTER_CERTIFICATE);
        // ?
        List<VAttachment> business = attachmentService.findAttachment(id,
                AttachmentConstant.BUSINESS_LICENSE_COPIES);
        // ??
        List<VAttachment> organization = attachmentService.findAttachment(id,
                AttachmentConstant.ORGANIZATION_CODE_CERTIFICATE);
        // ?
        List<VAttachment> liveList = attachmentService.findAttachment(id,
                AttachmentConstant.SUPPLIER_LIVE_CERTIFICATE_TYPE);

        request.setAttribute("certList", certList);
        request.setAttribute("decoration", decoration);
        request.setAttribute("bank", bank);
        request.setAttribute("trademark", trademark);
        request.setAttribute("author", author);
        request.setAttribute("taxation", taxation);
        request.setAttribute("business", business);
        request.setAttribute("organization", organization);
        request.setAttribute("liveList", liveList);
    }

    /**
     * ?
     */
    @RequestMapping(value = "/supervisorDetail")
    public String supervisorDetail(HttpServletRequest request) {

        VSupplierUser su = (VSupplierUser) request.getSession().getAttribute("su");
        Supplier supplier = supplierService.findById(su.getSpId());
        request.setAttribute("sp", supplier);

        // ??
        getCertifcateList(request, su.getSpId());

        // ?logo
        List<VAttachment> logoList = attachmentService.findAttachment(su.getSpId(),
                AttachmentConstant.SUPPLIER_COMPANY_TYPE);
        request.setAttribute("logo", logoList.size() > 0 ? logoList.get(0).getDownloadPath() : "");

        //
        Integer levelId = supplier.getLevelId();
        if (CheckedUtil.isNotEmpty(levelId)) {
            SupplierLevel level = supplierLevelService.findById(levelId);
            request.setAttribute("level", level);
        }

        return "supplier/supervisorDetail";
    }

    /**
     * ?
     */
    @RequestMapping(value = "/xiangqing")
    public String xiangqing(HttpServletRequest request) {

        VSupplierUser su = (VSupplierUser) request.getSession().getAttribute("su");

        // ?
        SupplierCompany supplierCompany = service.fin(su.getSpId());
        request.setAttribute("supplierCompany", supplierCompany);
        Supplier supplier = supplierService.findById(su.getSpId());
        request.setAttribute("sp", supplier);

        getCertifcateList(request, su.getSpId());

        // ?
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", su.getSpId());
        List<SupplierCompanyStaffInfo> staff = serviceImpl.findSaffListBySpId(params);
        // ?logo
        List<VAttachment> logoList = attachmentService.findAttachment(su.getSpId(),
                AttachmentConstant.SUPPLIER_COMPANY_TYPE);
        request.setAttribute("logo", logoList.size() > 0 ? logoList.get(0).getDownloadPath() : "");

        // ??
        List<VAttachment> staffList = attachmentService.findAttachment(null,
                AttachmentConstant.SUPPLIER_STAFF_TYPE);

        // ??
        for (VAttachment attachment : staffList) {
            for (SupplierCompanyStaffInfo supplierCompanyStaffInfo : staff) {
                if (attachment.getMainid().equals(supplierCompanyStaffInfo.getId()))
                    supplierCompanyStaffInfo.setAvatar(attachment.getDownloadPath());
            }
        }
        request.setAttribute("st", staff);

        //
        Integer levelId = supplier.getLevelId();
        if (CheckedUtil.isNotEmpty(levelId)) {
            SupplierLevel level = supplierLevelService.findById(levelId);
            request.setAttribute("level", level);
        }
        return "/supplier/supplier";
    }

    /**
     * ??
     */
    @RequestMapping(value = "/update")
    public String update(HttpServletRequest request, SupplierCompany supplierCompany) {
        VSupplierUser su = (VSupplierUser) request.getSession().getAttribute("su");
        supplierCompany.setSpId(su.getSpId());
        service.saveUpdate(supplierCompany);
        return "/supplier/supplierlogin_list";
    }

    /**
     * ??
     */
    @RequestMapping(value = "/updateSupervisor")
    public String updateSupervisor(HttpServletRequest request, Supplier supplier) {
        supplierService.updateSupervisor(supplier);
        return "/supplier/jl_index";
    }

    /**
     * ?
     */
    @RequestMapping("/deleteCertificate")
    public String deleteCertificate(Integer id, String returnUrl, HttpServletRequest request) {
        if (id != null && id > 0) {
            Attachment att = attachmentService.findById(id);
            attachmentService.delete(att);
            request.setAttribute("msg", "??");
        } else {
            request.setAttribute("msg", "?");
        }
        return "redirect:/supplier/" + returnUrl + ".xhtml";
    }

    /**
     * ?
     */
    @RequestMapping(value = "/uploadCertificate", method = RequestMethod.POST)
    public String uploadCertificate(HttpServletRequest request, Integer cid, String returnUrl, String remark)
            throws IOException {
        VSupplierUser su = (VSupplierUser) request.getSession().getAttribute("su");
        Supplier supplier = supplierService.findById(su.getSpId());
        supplier.setProxyStatus(0);
        supplierService.update(supplier, cid, remark, request);
        return "redirect:/supplier/" + returnUrl + ".xhtml";
    }

    /**
     * Logo
     */
    @ResponseBody
    @RequestMapping(value = "/uploadLogo", method = RequestMethod.POST)
    public Object uploadLogo(Integer id, HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        VSupplierUser su = (VSupplierUser) request.getSession().getAttribute("su");
        Attachment att = new Attachment();
        att.setMainid(su.getSpId());
        att.setFiletype(AttachmentConstant.SUPPLIER_COMPANY_TYPE);
        List<Attachment> logoList = attachmentService.select(att);
        if (logoList != null && logoList.size() > 0) {
            for (Attachment attachment : logoList) {
                attachmentService.delete(attachment);
            }
        }
        Attachment attachment = attachmentService.uploadOne((MultipartRequest) request);
        if (attachment != null) {
            int mainid = su.getSpId();
            Admin admin = new Admin();
            attachmentService.saveAttachment(attachment, admin, mainid, AttachmentConstant.SUPPLIER_COMPANY_TYPE);
            return new ResponseObject(true, "Logo? ?");
        }
        Supplier supplier = supplierService.findById(su.getSpId());
        supplier.setProxyStatus(0);
        supplierService.update(supplier);
        return new ResponseObject(true, "Logo ?");
    }

    /**
     * 
     */
    @RequestMapping(value = "/saveSupplierCompanyStaff", method = RequestMethod.POST)
    public String saveSupplierCompanyStaff(SupplierCompanyStaff entity, HttpServletRequest request,
            MultipartFile userImg) {
        VSupplierUser su = (VSupplierUser) request.getSession().getAttribute("su");
        Attachment attachment = attachmentService.uploadOne((MultipartRequest) request);
        entity.setSpId(su.getSpId());
        entity.setCreateTime(new java.sql.Date(System.currentTimeMillis()));
        serviceImpl.save(entity);
        if (attachment != null) {
            int mainid = entity.getId();
            Admin admin = new Admin();
            attachmentService.saveAttachment(attachment, admin, mainid, AttachmentConstant.SUPPLIER_STAFF_TYPE);
        }
        return "redirect:/supplier/xiangqing.xhtml";
    }

    /**
     * 
     */
    @RequestMapping(value = "/updateSupplierCompanyStaff", method = RequestMethod.POST)
    public String updateSupplierCompanyStaff(SupplierCompanyStaff entity, HttpServletRequest request,
            MultipartFile userImg, String avatar) {
        SupplierCompanyStaff oldEntity = serviceImpl.findById(entity.getId());
        Attachment att = new Attachment();
        att.setMainid(entity.getId());
        att.setFiletype(AttachmentConstant.SUPPLIER_STAFF_TYPE);
        List<Attachment> staffImageList = attachmentService.select(att);
        if (userImg.getSize() > 0) {
            if (!staffImageList.isEmpty()) {
                for (Attachment attachment : staffImageList) {
                    attachmentService.deleteById(attachment.getId());
                }
            }
            Attachment attachment = attachmentService.uploadOne((MultipartRequest) request);
            if (attachment != null) {
                int mainid = entity.getId();
                Admin admin = new Admin();
                attachmentService.saveAttachment(attachment, admin, mainid, AttachmentConstant.SUPPLIER_STAFF_TYPE);
            }
        }
        if (entity.getSid() == 2) {
            entity.setSjsSuggest(null);
        }
        entity.setAvatar(null);
        entity.setCreateTime(oldEntity.getCreateTime());
        entity.setSpId(oldEntity.getSpId());
        serviceImpl.update(entity);
        return "redirect:/supplier/xiangqing.xhtml";
    }

    /**
     * 
     */
    @ResponseBody
    @RequestMapping(value = "/removeSupplierCompanyStaff")
    public Object removeSupplierCompanyStaff(Integer id) {
        if (id > 0) {
            serviceImpl.deleteById(id);
            Attachment att = new Attachment();
            att.setMainid(id);
            att.setFiletype(AttachmentConstant.SUPPLIER_STAFF_TYPE);
            List<Attachment> staffImageList = attachmentService.select(att);
            for (Attachment attachment : staffImageList) {
                HttpFileTools.deleteFile(attachment.getFilepath());
            }
        }
        return new ResponseObject(true, "??");
    }

    /*
     * @RequestMapping(value = "/update") public String
     * update(HttpServletRequest request,SupplierCompany
     * supplierCompany,@RequestParam String[] picture,@RequestParam String[]
     * tra,@RequestParam String[] name,@RequestParam String[] job,@RequestParam
     * String sid,@RequestParam String hh,@RequestParam String wid) { Integer
     * id=CommonUtil.stringToInteger(sid); Integer
     * yid=CommonUtil.stringToInteger(wid);
     * service.saveUpdate(supplierCompany,yid); serviceImpl.del(id);
     * serviceImpl.saveUpdate(id, tra, name, job); sImpl.del(id);
     * sImpl.saveOrUpdate(picture, hh, id); return "/supplier/supplier"; }
     */
    // @ResponseBody @RequestMapping("/list_json.do")
    // public JSONObject list_json(HttpServletRequest
    // request,HttpServletResponse response,
    // @RequestParam(defaultValue="20")Integer pageSize,
    // @RequestParam(defaultValue="1")Integer pageNo) {
    // response.setContentType("text/html;charset=UTF-8");
    // JSONObject map = new JSONObject();
    // String and=supplierService.getAndByRequest(request);
    // long count=dao.getCount(and);
    // Pager pager=new Pager(and, pageSize, pageNo,count);
    // List<VSupplier> list=dao.getPageList(pager);
    // map.put("count",count);
    // map.put("pageCount",pager.pageCount);
    // map.put("pageNo", pager.pageNo);
    // map.put("pageSize",pager.pageSize);
    // map.put("list", JSONArray.fromObject(list,AllDao.jcfg));
    // return map;
    // }//?IEJSON??

    @RequestMapping("/list4json.do")
    // 
    public void list4json(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(defaultValue = "20") Integer pageSize, @RequestParam(defaultValue = "1") Integer pageNo)
            throws Exception {
        String and = supplierService.getAndByRequest(request);
        long count = dao.getCount(and);
        Pager pager = new Pager(and, pageSize, pageNo, count);
        List<VSupplier> list = dao.getPageList(pager);
        response.setContentType("text/html;charset=UTF-8");
        JSONObject json = JSONObject.fromObject(pager);
        json.put("data", JSONArray.fromObject(list, AllDao.jcfg));
        PrintWriter out = response.getWriter();
        out.println(json);
        out.flush();
        out.close();
    }

    @RequestMapping(value = "/edit4json.do")
    // ????
    public void edit4json(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(required = false, defaultValue = "0") Integer id) throws Exception {
        String result = "";
        JSONObject json = new JSONObject();
        VSupplier bean = dao.getBeanById(id);
        if (bean == null || bean.getId() == null || bean.getId() == 0) {
            bean = new VSupplier();
            result = "";
        }
        json.put("supplier", bean);
        request.setAttribute("supplier", bean);
        json.put("result", result);
        request.setAttribute("result", result);
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println(json);
        out.flush();
        out.close();
    }

    @RequestMapping(value = "/save4json.do")
    // ??
    public void save4json(Supplier bean, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String result = "";
        JSONObject json = new JSONObject();
        if (bean == null || bean.getId() == null || bean.getId() == 0) {
            int flag = dao.insert(bean);
            result = flag > 0 ? "?" : "";
        } else {
            int flag = dao.updateByPrimaryKey(bean);
            result = flag > 0 ? "?" : "";
        }
        json.put("supplier", bean);
        request.setAttribute("supplier", bean);
        json.put("result", result);
        request.setAttribute("result", result);
        response.setContentType("text/plain;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println(json);
        out.flush();
        out.close();
    }

    @RequestMapping(value = "/delete4json.do")
    // 
    public void save4json(Integer[] chkId, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String result = "";
        int cnt = 0;
        if (chkId == null)
            result = "";
        else
            for (int i = 0; i < chkId.length; i++) {
                VSupplier bean = dao.getBeanById(chkId[i]);
                if (bean == null)
                    continue;
                System.out.println("id?" + chkId[i] + "" + bean);
                cnt += dao.deleteByPrimaryKey(bean);
            }
        result = cnt > 0 ? "?" : "";
        response.setContentType("text/plain;charset=UTF-8");
        JSONObject json = new JSONObject();
        json.put("result", result);
        json.put("del_cnt", cnt);
        PrintWriter out = response.getWriter();
        out.println(json);
        out.flush();
        out.close();
    }

    // @ModelAttribute //??????????
    // public void getModel(@RequestParam(value="id",required=false) Integer
    // id,Map<String,Object> map){
    // if(id!=null){
    // map.put("supplier",dao.getBeanById(id));
    // }else{
    // map.put("supplier",new Supplier());
    // }
    // }

}