com.ssic.education.provider.controller.ProUserRegController.java Source code

Java tutorial

Introduction

Here is the source code for com.ssic.education.provider.controller.ProUserRegController.java

Source

package com.ssic.education.provider.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.base.Objects;
import com.ssic.educateion.common.dto.EduSupplierReviewDto;
import com.ssic.educateion.common.dto.ProLicenseDto;
import com.ssic.educateion.common.dto.ProSupplierDto;
import com.ssic.educateion.common.dto.SupplierDto;
import com.ssic.education.handle.service.IEduSupplierReviewService;
import com.ssic.education.handle.service.IProLicenseService;
import com.ssic.education.handle.service.ISupplierService;
import com.ssic.education.provider.dto.ProUsersDto;
import com.ssic.education.provider.pageModel.Json;
import com.ssic.education.provider.service.IProUsersService;
import com.ssic.education.utils.constants.DataStatus;
import com.ssic.education.utils.util.BeanUtils;
import com.ssic.education.utils.util.UUIDGenerator;

/**
 * 
* ???
* @author: cwftalus@163.com
* @version: 2016520 ?1:37:22
 */
@Controller
@RequestMapping(value = "/proUserRegController")
public class ProUserRegController extends BaseController {

    @Autowired
    private ISupplierService iSupplierService;

    @Autowired
    private IProUsersService iProUsersService;

    @Autowired
    private IEduSupplierReviewService iEduSupplierReviewService;

    @Autowired
    private IProLicenseService iProLicenseService;

    @RequestMapping(value = "/pureg")
    @ResponseBody
    @Transactional
    public Json prreg(SupplierDto supplierDto, ProUsersDto proUsersDto) {
        Json json = new Json();
        //??  -->  ??(?) //??        String supplierId = UUIDGenerator.getUUID();
        String supplierId = UUIDGenerator.getUUID();
        //      iSupplierService.saveOrUpdateSupplier(supplierDto);
        //?
        saveSupplierReview(supplierId);
        //???
        String[] licenses = getRequest().getParameterValues("licenseList");

        String creatorId = UUIDGenerator.getUUID();

        saveLicenses(supplierId, licenses, creatorId, supplierDto);
        //licenses ????

        //?
        proUsersDto.setId(creatorId);
        proUsersDto.setCreator(creatorId);
        proUsersDto.setSourceId(supplierId);
        proUsersDto.setName(supplierDto.getSupplierName());
        proUsersDto.setIsadmin(DataStatus.ENABLED);
        String proUserId = iProUsersService.saveProUsers(proUsersDto);

        return json;

    }

    private void saveLicenses(String supplierId, String[] licenses, String creatorId, SupplierDto supplierDto) {
        if (licenses != null) {
            for (String licesse : licenses) {
                if (!StringUtils.isEmpty(licesse)) {
                    String licenseName = licesse.split("#")[0];
                    String licPic = licesse.split("#")[1];
                    String licNo = licesse.split("#")[2];
                    String licType = licesse.split("#")[3];
                    ProLicenseDto proLicenseDto = new ProLicenseDto();
                    proLicenseDto.setLicType(DataStatus.DISABLED);
                    proLicenseDto.setLicName(licenseName);
                    proLicenseDto.setLicPic(licPic);
                    proLicenseDto.setLicType(Integer.valueOf(licType));
                    ;
                    proLicenseDto.setLicNo(licNo);
                    proLicenseDto.setRelationId(supplierId);
                    proLicenseDto.setCerSource(Short.valueOf("0"));
                    proLicenseDto.setCreator(creatorId);
                    iProLicenseService.saveProLicense(proLicenseDto);

                    if (Objects.equal(licType, "4")) {
                        supplierDto.setBusinessLicense(licNo);
                    } else if (Objects.equal(licType, "0")) {
                        supplierDto.setFoodServiceCode(licNo);
                    } else if (Objects.equal(licType, "2")) {
                        supplierDto.setFoodCirculationCode(licNo);
                    } else if (Objects.equal(licType, "3")) {
                        supplierDto.setFoodProduceCode(licNo);
                    }
                }
            }
            supplierDto.setId(supplierId);
            supplierDto.setReviewed(Byte.valueOf("0"));
            supplierDto.setSupplierType(Integer.valueOf(1));//?  0?1???2  
            iSupplierService.insertSupplier(supplierDto);//saveOrUpdateSupplier(supplierDto);
        }

        //      business_license            ?  4                                                              
        //      organization_code           ?                                                            
        //      food_service_code           ????   0                                                         
        //      food_service_code_date      ????                                                
        //      food_business_code          ??????                                                      
        //      food_business_code_date     ??????                                          
        //      food_circulation_code       ????            2                                                
        //      food_circulation_code_date  ????                                                
        //      food_produce_code           ???          3                                                  
        //      food_produce_code_date      ???   

    }

    private void saveSupplierReview(String supplierId) {
        String[] committees = getRequest().getParameterValues("committees");
        List<String> commitIdList = Arrays.asList(committees);
        List<EduSupplierReviewDto> insertList = new ArrayList<EduSupplierReviewDto>();
        Date date = new Date();
        for (String committeeId : commitIdList) {
            EduSupplierReviewDto tDto = new EduSupplierReviewDto(committeeId, supplierId,
                    Short.valueOf(String.valueOf(DataStatus.DISABLED)), date, date);
            insertList.add(tDto);
        }
        iEduSupplierReviewService.saveSupplierReview(insertList);
    }

}