com.hive.surveymanage.controller.IndustryEntityController.java Source code

Java tutorial

Introduction

Here is the source code for com.hive.surveymanage.controller.IndustryEntityController.java

Source

package com.hive.surveymanage.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
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.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.google.zxing.WriterException;
import com.hive.common.AnnexFileUpLoad;
import com.hive.common.SystemCommon_Constant;
import com.hive.common.entity.Annex;
import com.hive.enterprisemanage.entity.EEnterpriseinfo;
import com.hive.enterprisemanage.service.EnterpriseInfoService;
import com.hive.membermanage.entity.MMember;
import com.hive.membermanage.service.MembermanageService;
import com.hive.surveymanage.entity.CObject;
import com.hive.surveymanage.entity.IndustryEntity;
import com.hive.surveymanage.entity.IndustryEntitySurvey;
import com.hive.surveymanage.entity.Survey;
import com.hive.surveymanage.entity.SurveyIndustry;
import com.hive.surveymanage.model.IndustryEntityBean;
import com.hive.surveymanage.service.CObjectService;
import com.hive.surveymanage.service.IndustryEntityService;
import com.hive.surveymanage.service.IndustryEntitySurveyService;
import com.hive.surveymanage.service.SurveyIndustryService;
import com.hive.surveymanage.service.SurveyService;
import com.hive.surveymanage.service.ViewExcelOfEntity;
import com.hive.systemconfig.service.VersionCategoryService;
import com.hive.tagManage.entity.SNBase;
import com.hive.tagManage.entity.SNBatch;
import com.hive.tagManage.entity.SNBatchSurvey;
import com.hive.tagManage.model.SNBaseVo;
import com.hive.tagManage.service.ViewExcelOfSN;
import com.hive.util.DataUtil;
import com.hive.util.DateUtil;
import com.hive.util.EncoderHandler;
import com.hive.util.PropertiesFileUtil;
import com.hive.util.TwoDCodeImage;

import dk.controller.BaseController;
import dk.model.DataGrid;
import dk.model.RequestPage;
import dk.util.MD5;

/**
 * @description ?
 * @author zhaopengfei
 * @createtime 2015-12-15 ?03:55:13
 */
@Controller
@RequestMapping("/industryEntityManage")
public class IndustryEntityController extends BaseController {

    private static final String PREFIX = "surveymanage/industryEntityManage"; // ??

    @Resource
    private IndustryEntityService industryEntityService;
    @Resource
    private VersionCategoryService versionCategoryService;
    @Resource
    private SurveyIndustryService surveryIndustryService;
    @Resource
    private CObjectService cObjectService;
    @Resource
    private MembermanageService membermanageService;
    /** ??Service */
    @Resource
    private EnterpriseInfoService entInfoService;
    @Resource
    private IndustryEntitySurveyService industryEntitySurveyService;
    @Resource
    private SurveyService surveyService;

    /**
     * ????
     * :2015-12-18?9:26:31
     * : pengfei zhao
     * @return
     */
    @RequestMapping("/manage")
    public String manage(Model model, HttpServletRequest request) {
        //???
        PropertiesFileUtil propertiesFileUtil = new PropertiesFileUtil();
        String zxt_url = propertiesFileUtil.findValue("zxt_http_url");
        model.addAttribute("zxt_url", zxt_url);
        return PREFIX + "/manage"; // /manage.jsp
    }

    /**
     * ??
     * :2013-11-3?3:48:48
     * : Ryu Zheng
     * @return
     * @throws UnsupportedEncodingException 
     */
    @RequestMapping("/datagrid.action")
    @ResponseBody
    public DataGrid datagrid(RequestPage page,
            @RequestParam(value = "entityName", required = false, defaultValue = "") String entityName,
            @RequestParam(value = "entityType", required = false) String entityType,
            @RequestParam(value = "entityCategory", required = false) String entityCategory,
            @RequestParam(value = "cauditstatus", required = false) String cauditstatus, HttpServletRequest request)
            throws UnsupportedEncodingException {
        return industryEntityService.datagrid(page, entityName, entityType, entityCategory, cauditstatus);
    }

    /**
     * ???
     * :2013-10-28?3:08:35
     * : pengfei Zhao
     * @param model
     * @return
     */
    @RequestMapping("add")
    public String add(Model model) {
        IndustryEntity industryEntity = new IndustryEntity();
        model.addAttribute("industryEntity", industryEntity);
        return PREFIX + "/add";
    }

    /**
     * ?
     */
    @RequestMapping("queryIndustryEntity")
    public String queryIndustryEntity(Model model) {
        return PREFIX + "/query";
    }

    /**
     * ???? 
     * @param session
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/saveindusEntity")
    @ResponseBody
    public Map<String, Object> saveindusEntity(IndustryEntity induEntity, HttpSession session,
            MultipartHttpServletRequest request, Model model) {
        if (induEntity == null) {
            return error("?");
        }
        String entityName = induEntity.getEntityName();
        boolean isok = industryEntityService.checkEntity(entityName);
        if (isok == true) {
            return error("??");
        }
        //  ??
        String companyTypeCode = StringUtils.EMPTY;
        String[] regTypes = request.getParameterValues("regType");
        for (int i = 0; i < regTypes.length; i++) {
            if (!regTypes[i].equals("")) {
                if (i == 0) {
                    companyTypeCode += regTypes[i];
                } else {
                    companyTypeCode += "_" + regTypes[i];
                }
            }
        }

        //?ID
        Long cObjectId = null;
        CObject cObject = new CObject();
        cObject.setObjectType(surveryIndustryService.getobjectTypebyId(induEntity.getEntityType()));
        cObject.setObjectId(induEntity.getOtherId());
        cObject.setObjectName(entityName);
        cObjectId = cObjectService.saveCobject(cObject);

        induEntity.setCcomtypcode(companyTypeCode);
        // ???
        Long curUserId = (Long) session.getAttribute("userId");
        induEntity.setCreateid(curUserId);
        induEntity.setCreatetime(new Date());
        induEntity.setCauditstatus("0");
        induEntity.setValid("1");
        induEntity.setObjectId(cObjectId.toString());
        industryEntityService.save(induEntity);

        return success("??", induEntity);
    }

    /**
      * ??toEntInfoEdit
      * ????
      * :20151221?4:15:01
      * : pengfei Zhao
      * @param @param entInfoId
      * @param @param model
      * @param @return 
      * @return String
     */
    @RequestMapping("/toEntityInfoEdit")
    public String toEntityInfoEdit(@RequestParam(value = "entInfoId", required = false) Long entInfoId,
            Model model) {
        IndustryEntity induEntity = null;

        // entInfoId??
        if (entInfoId != null) {
            induEntity = industryEntityService.get(entInfoId);
            CObject object = cObjectService.get(Long.valueOf(induEntity.getObjectId()));
            induEntity.setOtherId(object.getObjectId());
        } else {
            induEntity = new IndustryEntity();
            induEntity.setId(entInfoId);
        }

        model.addAttribute("induEntity", induEntity);
        return PREFIX + "/edit";
    }

    /**
      * ??updateEntInfo
      * ???
      * :20151221?4:44:30
      * : pengfei Zhao
      * @param @param session
      * @param @param request
      * @param @param model
      * @param @return 
      * @return Map<String,Object>
     */
    @RequestMapping("/updateEntityInfo")
    @ResponseBody
    public Map<String, Object> updateEntityInfo(@ModelAttribute("induEntity") IndustryEntity induEntity,
            HttpSession session, MultipartHttpServletRequest request, Model model) {

        if (induEntity == null) {
            return error("?");
        }
        //  ??
        String companyTypeCode = StringUtils.EMPTY;
        String[] regTypes = request.getParameterValues("regType");
        for (int i = 0; i < regTypes.length; i++) {
            if (!regTypes[i].equals("")) {
                if (i == 0) {
                    companyTypeCode += regTypes[i];
                } else {
                    companyTypeCode += "_" + regTypes[i];
                }
            }
        }
        induEntity.setCcomtypcode(companyTypeCode);

        // ???
        Long curUserId = (Long) session.getAttribute("userId");
        induEntity.setModifyid(curUserId);
        induEntity.setModifytime(new Date());
        induEntity.setValid("1");
        industryEntityService.saveOrUpdate(induEntity);
        // ?
        return success("??", induEntity);
    }

    /**
      * ??delLogicInfo
      * ???
      * :20151223?5:33:48
      * : pengfei Zhao
      * @param @param model
      * @param @param entInfoId
      * @param @return 
      * @return Map<String,Object>
     */
    @RequestMapping("/delLogicInfo")
    @ResponseBody
    public Map<String, Object> delLogicInfo(Model model, @RequestParam("entInfoId") Long entInfoId) {
        IndustryEntity induEntity = industryEntityService.get(entInfoId);
        if (induEntity == null) {
            return error("");
        }
        industryEntityService.delEntInfo(induEntity);
        return success("?");
    }

    @RequestMapping("/delInfo")
    @ResponseBody
    public Map<String, Object> delInfo(Model model, @RequestParam("entInfoId") Long entInfoId) {
        IndustryEntity induEntity = industryEntityService.get(entInfoId);
        if (induEntity == null) {
            return error("");
        }
        industryEntityService.delete(entInfoId);
        return success("?");
    }

    /**
      * ??checkEntity
      * ????
      * :20151221?5:13:39
      * : pengfei Zhao
      * @param @param request
      * @param @return 
      * @return Object
     */
    @RequestMapping({ "/checkEntity.action" })
    @ResponseBody
    public Object checkEntity(HttpServletRequest request) {
        String ids = request.getParameter("ids");
        String status = request.getParameter("checktype");
        industryEntityService.checkEntity(ids, status);
        return success("??");
    }

    /**
     * ??creatLoginUser
     * ??
     * : pengfei Zhao
    */
    @RequestMapping("/creatUser.action")
    public String creatUser(Model model, @RequestParam(value = "entityId") Long entityId) {
        IndustryEntity induEntity = null;
        induEntity = industryEntityService.get(entityId);
        model.addAttribute("vo", induEntity);
        return PREFIX + "/creatUser";
    }

    /**
      * ??creatLoginUser
      * ??
      * :2016415?4:41:33
      * : pengfei Zhao
      * @return Map<String,Object>
     */
    @RequestMapping("/creatLoginUser")
    @ResponseBody
    public Map<String, Object> creatLoginUser(HttpServletRequest request) {
        String entInfoId = request.getParameter("id");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        IndustryEntity induEntity = industryEntityService.get(Long.valueOf(entInfoId));
        MMember menb = membermanageService.getByuserName(username);
        if (induEntity != null && menb == null) {
            menb = new MMember();
            menb.setCusername(username);
            String encryptedPassword = MD5.getMD5Code(password);
            menb.setCpassword(encryptedPassword);
            menb.setDcreatetime(DateUtil.getTimestamp());
            //menb.setChinesename(induEntity.getLinkMan());
            menb.setChinesename(induEntity.getEntityName());//?? ??  20160712 yf update
            menb.setCnickname(induEntity.getEntityName());
            menb.setCaddress(induEntity.getAddress());
            menb.setCvalid(SystemCommon_Constant.VALID_STATUS_1); //
            menb.setCmemberlevel(SystemCommon_Constant.MEMBER_LEVEL_1);//1
            menb.setCprovincecode(induEntity.getCprovincecode());
            menb.setCcitycode(induEntity.getCcitycode());
            menb.setCdistrictcode(induEntity.getCdistrictcode());
            menb.setCmobilephone(induEntity.getLinkPhone());
            menb.setCmembertype("1");
            menb.setCmemberstatus("0");
            menb.setEnterpriseName(induEntity.getEntityName());
            menb.setIndustryEntityId(induEntity.getId());
            //??
            EEnterpriseinfo enterprise = entInfoService.getEnterpriseInfoByName(induEntity.getEntityName());
            if (enterprise == null) {//?
                enterprise = new EEnterpriseinfo();
                enterprise.setCenterprisename(induEntity.getEntityName());
                enterprise.setDestablishdate(induEntity.getFoundtime());
                enterprise.setCregaddress(induEntity.getAddress());
                enterprise.setCprovincecode(induEntity.getCprovincecode());
                enterprise.setCcitycode(induEntity.getCcitycode());
                enterprise.setCdistrictcode(induEntity.getCdistrictcode());
                enterprise.setCindcatcode(induEntity.getEntityType());
                enterprise.setCcomtypcode(induEntity.getCcomtypcode());
                enterprise.setCbusinesslicenseno(induEntity.getCbusinesslicenseno());
                enterprise.setCbusiness(induEntity.getCbusiness());
                enterprise.setCsummary(induEntity.getCsummary());
                enterprise.setCcontractperson(induEntity.getLinkMan());
                enterprise.setCcontractpersonphone(induEntity.getLinkPhone());
                enterprise.setCcontractaddress(induEntity.getAddress());
                entInfoService.save(enterprise);
            }
            menb.setNenterpriseid(enterprise.getNenterpriseid());
        } else {
            return error("??!");
        }
        membermanageService.save(menb);
        induEntity.setCreatUserstatus("1");
        industryEntityService.update(induEntity);
        return success("?" + induEntity.getEntityName()
                + "?,?????");
    }

    @RequestMapping("parentIndustryList")
    @ResponseBody
    public List<SurveyIndustry> getParentIndustryList() {
        List list = industryEntityService.getParentIndustryList();
        return list;

    }

    /**
     *@Title:allindustryEntityInfo
     *@Description: ??
     *@param@return
     *@returnList<EEnterpriseinfo>
     *@throws
     */
    @RequestMapping("/allindustryEntityInfo.action")
    @ResponseBody
    public List<IndustryEntity> allindustryEntityInfo() {
        return industryEntityService.getIndustryEntityInfo();
    }

    /**
     *@Title:findAllBindedServeyEntity
     *@Description: ??
     * 20160616 yyf add
     *@throws
     */
    @RequestMapping("/findAllBindedSurveyEntity.action")
    @ResponseBody
    public List<IndustryEntity> findAllBindedSurveyEntity() {
        return industryEntityService.findAllBindedSurveyEntity();
    }

    /**
     * ??Id?
     * zpf 20160624 add
     * @return
     */
    @RequestMapping("getAllIndustryEntityListForOther")
    @ResponseBody
    public List<IndustryEntity> getAllIndustryEntityListForOther(HttpServletRequest request,
            @RequestParam(value = "gasIdList", required = true) String gasIdList) {
        List<IndustryEntity> list = null;
        IndustryEntity ins = new IndustryEntity();
        ins.setEntityName("");
        ins.setId(1L);
        if (gasIdList != null && !gasIdList.equals("")) {
            list = industryEntityService.getAllIndustryEntityListForOther(gasIdList);
        }
        list.add(ins);
        return list;

    }

    /**
     * ?
     * @return
     */
    @RequestMapping("getAllIndustryEntityList")
    @ResponseBody
    public List<IndustryEntity> getAllIndustryEntityList(
            @RequestParam(value = "q", required = false) String entityName) {
        List<IndustryEntity> list = industryEntityService.getAllIndustryEntityList(entityName);
        return list;

    }

    /**
     * 
     * @Description: ?
     * @author YangHui 
     * @Created 2014-10-16
     * @param id
     * @return
     * @throws WriterException
     * @throws IOException
     */
    @RequestMapping("createTwoCode")
    @ResponseBody
    public Map<String, Object> createTwoCode(@RequestParam(value = "id") Long id)
            throws WriterException, IOException {

        //???IP?
        PropertiesFileUtil pfu = new PropertiesFileUtil();
        String httpUrl = pfu.findValue("zxt_http_url");

        String text = httpUrl + "zxt-manage/interface/survey/sweepCode.action?id=" + id + "&sign=enterprise";
        String imgName = "";

        IndustryEntity induEntity = industryEntityService.get(id);
        ;
        if (induEntity != null) {
            imgName = induEntity.getEntityName();
        }
        String path = "";
        path = TwoDCodeImage.writeImage(text, imgName);

        return this.success("????", induEntity);
    }

    /**
     * ?
     * @param model
     * @param productId
     * @return
     */
    @RequestMapping("/viewBarcodeInfo.action")
    public String viewBarcodeInfo(Model model, @RequestParam(value = "entityId") Long entityId) {
        IndustryEntity induEntity = null;
        IndustryEntityBean vo = null;
        try {
            induEntity = industryEntityService.get(entityId);
            String queryPath = SystemCommon_Constant.QRCODE_PATH;
            vo = new IndustryEntityBean();
            PropertyUtils.copyProperties(vo, induEntity);
            vo.setQueryPath(queryPath + entityId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        model.addAttribute("vo", vo);
        return PREFIX + "/viewBarcode";
    }

    /**
     * ??
     * @param model
     * @param productId
     * @return
     */
    @RequestMapping("/bindingInfo.action")
    public String bindingInfo(Model model, @RequestParam(value = "entityId") Long entityId) {

        IndustryEntity induEntity = null;
        induEntity = industryEntityService.get(entityId);
        model.addAttribute("vo", induEntity);
        return PREFIX + "/binding";
    }

    /**
     * ??
     * @author ?
     */
    @RequestMapping("/bindingSurveyInfo")
    @ResponseBody
    public Map<String, Object> bindingSurveyInfo(HttpServletRequest request, HttpSession session) {
        try {
            String entityId = request.getParameter("id");
            String surveyId = request.getParameter("surveyId");
            IndustryEntity induEntity = null;
            induEntity = industryEntityService.get(Long.valueOf(entityId));
            if (surveyId != null && !surveyId.equals("")) {
                induEntity.setSurveyId(Long.valueOf(surveyId));
            } else {
                induEntity.setSurveyId(null);
            }
            industryEntityService.saveOrUpdate(induEntity);
            if (surveyId != null && !surveyId.equals("")) {
                List<IndustryEntitySurvey> returnList = industryEntitySurveyService
                        .exitEntityByIndustryandEntityId(entityId, surveyId);
                if (returnList.size() > 0) {
                    IndustryEntitySurvey industryEntitySurvey = returnList.get(0);
                    industryEntitySurvey.setSurveyId(surveyId);
                    industryEntitySurvey.setCreateTime(new Date());
                    industryEntitySurvey.setSurveyTitle(surveyService.get(Long.valueOf(surveyId)).getSubject());
                    industryEntitySurveyService.update(industryEntitySurvey);
                } else {
                    IndustryEntitySurvey industryEntitySurvey = new IndustryEntitySurvey();
                    industryEntitySurvey.setIndustryEntityId(entityId);
                    industryEntitySurvey.setSurveyId(surveyId);
                    industryEntitySurvey.setCreateTime(new Date());
                    industryEntitySurvey.setSurveyTitle(surveyService.get(Long.valueOf(surveyId)).getSubject());
                    industryEntitySurveyService.saveOrUpdate(industryEntitySurvey);
                }
            } else {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return success("??", "");
    }

    /**
      * ??viewQrcode
      * ???
      * :2016125?5:40:08
      * : pengfei Zhao
      * @param @param content
      * @param @param requset
      * @param @param response 
      * @return void
    */
    @RequestMapping("/viewBarcodeImg.action")
    public void viewQrcode(@RequestParam(value = "id") String id,
            @RequestParam(value = "queryPath") String queryPath, HttpServletRequest requset,
            HttpServletResponse response) {
        EncoderHandler encoder = new EncoderHandler();
        encoder.encoderQRCoder(queryPath, response);
    }

    /**
     * 
     * @Description: ?
     * @author yyf
     * @Created 20160615
     */
    @RequestMapping("findSurveyListById")
    @ResponseBody
    public List<Survey> findSurveyListById(@RequestParam(value = "objectId") Long objectId) {

        IndustryEntity ie = industryEntityService.get(objectId);
        List<Survey> list = new ArrayList<Survey>();
        Long surId = ie.getSurveyId();
        if (surId != null && surId > 0) {
            list = surveyService.findSurveyById(surId);
        }
        return list;
    }

    /**
     * 
     * @Description: ?linkId
     * @author yyf
     * @Created 20160615
     */
    @RequestMapping("getLinkIdByParam")
    @ResponseBody
    public IndustryEntitySurvey getLinkIdByParam(@RequestParam(value = "objectId") Long objectId,
            @RequestParam(value = "surveyId") Long surveyId) {
        IndustryEntitySurvey ies = industryEntitySurveyService.getLinkIdByParam(objectId, surveyId);
        if (ies != null) {
            return ies;
        } else {
            throw new RuntimeException("??");
        }
    }

    /**
     * 
     * @Description: ?IndustryEntity
     * @author yyf
     * @Created 20160815
     */
    @RequestMapping("getIndustryEntityById")
    @ResponseBody
    public IndustryEntity getIndustryEntityById(@RequestParam(value = "id") Long id) {
        IndustryEntity ie = industryEntityService.get(id);
        if (ie != null) {
            return ie;
        } else {
            throw new RuntimeException("?");
        }

    }

    /** 
     * Excel 
     * @param model 
     * @param projectId 
     * @param request 
     * @return 
     * @throws UnsupportedEncodingException 
     */
    @RequestMapping(value = "/entitySaveExcel", method = RequestMethod.GET)
    public ModelAndView entitySaveExcel(@RequestParam("ids") String ids) {
        int len = 0;
        String[] id = ids.split(",");
        len = id.length;
        List<IndustryEntityBean> Maplist = new ArrayList<IndustryEntityBean>();
        for (int i = 0; i < id.length; i++) {
            IndustryEntity ie = industryEntityService.get(Long.valueOf(id[i]));
            IndustryEntityBean ieb = industryEntityService.getIndstryEntiyBeanForEntity(ie);
            Maplist.add(ieb);
        }
        Map map = new HashMap();
        map.put("Maplist", Maplist);
        ViewExcelOfEntity viewExcel = new ViewExcelOfEntity();
        return new ModelAndView(viewExcel, map);
    }
}