对比新文件 |
| | |
| | | package com.gk.firework.Controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.gk.firework.Controller.Base.BaseController; |
| | | import com.gk.firework.Domain.*; |
| | | import com.gk.firework.Domain.Enum.EnterpriseSafetySupervision; |
| | | import com.gk.firework.Domain.Enum.ErrorCode; |
| | | import com.gk.firework.Domain.Utils.*; |
| | | import com.gk.firework.Domain.Utils.Properties; |
| | | import com.gk.firework.Domain.Vo.RegisterVo; |
| | | import com.gk.firework.Service.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.validation.FieldError; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.gk.firework.Domain.Enum.ErrorCode.ERROR_10001; |
| | | |
| | | /** |
| | | * @author : jingjy |
| | | * @date : 2021/6/24 16:52 |
| | | */ |
| | | @Api(tags = "注册信息") |
| | | @RequestMapping("/register") |
| | | @RestController |
| | | public class RegisterController extends BaseController { |
| | | |
| | | /** 未审核 **/ |
| | | private final Byte REVIEW_INCOMPLETE = 0; |
| | | /** 审核通过 **/ |
| | | private final Byte REVIEW_APPROVE = 1; |
| | | /** 审核拒绝 **/ |
| | | private final Byte REVIEW_REJECTION = 2; |
| | | |
| | | @Autowired |
| | | private RegisterService registerService; |
| | | @Autowired |
| | | private EnterpriseResourceService enterpriseResourceService; |
| | | @Autowired |
| | | private EnterpriseService enterpriseService; |
| | | @Autowired |
| | | private UserService userService; |
| | | @Autowired |
| | | private BlackListService blackListService; |
| | | |
| | | @PostMapping("/add") |
| | | public Msg addRegisterInfo(@Validated RegisterVo registerVo, BindingResult bindingResult){ |
| | | if (registerVo == null){ |
| | | return new Msg(ErrorCode.ERROR_10001); |
| | | } |
| | | |
| | | if (bindingResult.hasErrors()) { |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (String s : bindingResult.getFieldErrors().stream() |
| | | .map(FieldError::getDefaultMessage).collect(Collectors.toList())) { |
| | | stringBuilder.append(s); |
| | | stringBuilder.append(","); |
| | | } |
| | | return new Msg(ErrorCode.ERROR_10002,stringBuilder.toString()); |
| | | } |
| | | |
| | | boolean isSupervision = false; |
| | | for (EnterpriseSafetySupervision e : EnterpriseSafetySupervision.values()){ |
| | | if (registerVo.getType().equals(e.getMsg())){ |
| | | isSupervision = true; |
| | | } |
| | | } |
| | | |
| | | if (!isSupervision){ |
| | | return new Msg(ErrorCode.ERROR_10004,"企业类型无效"); |
| | | } |
| | | |
| | | if ((boolean)isEnterpriseNameExist(registerVo.getEnterprisename()).getResult()){ |
| | | return new Msg(ErrorCode.ERROR_10004,"企业名称已存在"); |
| | | } |
| | | |
| | | if ((boolean)isEnterpriseNumberExist(registerVo.getEnterprisenumber()).getResult()){ |
| | | return new Msg(ErrorCode.ERROR_10004,"企业编码已存在"); |
| | | } |
| | | |
| | | RegisterInfo registerInfo = BeanUtils.copy(registerVo,RegisterInfo.class); |
| | | registerInfo.setCreatedat(new Date()); |
| | | |
| | | registerService.save(registerInfo); |
| | | |
| | | Map<String,MultipartFile[]> map = new HashMap<>(8); |
| | | map.put(RegisterVo.BUSINESS,registerVo.getBusinessLicense()); |
| | | map.put(RegisterVo.ID_CARD,registerVo.getIdCard()); |
| | | map.put(RegisterVo.LEGAL_PERSON,registerVo.getLegalPersonFile()); |
| | | map.put(RegisterVo.OPERATION,registerVo.getOperationQualification()); |
| | | map.put(RegisterVo.ESCORT_COMPANY,registerVo.getEscortCompany()); |
| | | map.put(RegisterVo.INSURANCE,registerVo.getInsurance()); |
| | | map.put(RegisterVo.PRODUCTION,registerVo.getSafetyProduction()); |
| | | Msg msg = uploadFiles(map,registerInfo); |
| | | if (!msg.getCode().equals(ErrorCode.SUCCESS.getMsg())){ |
| | | return msg; |
| | | } |
| | | |
| | | return success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "注册信息审核", httpMethod = "POST") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "注册信息id",required = true), |
| | | @ApiImplicitParam(name = "reviewResult",value = "审核结果(1.审核通过;2.审核驳回)",required = true), |
| | | @ApiImplicitParam(name = "reviewContent",value = "审核意见"), |
| | | }) |
| | | @PostMapping("/review") |
| | | public Msg reviewRegister(@RequestBody JSONObject object){ |
| | | Long id = object.getLong("id"); |
| | | Byte reviewResult = object.getByte("reviewResult"); |
| | | String reviewContent = object.getString("reviewContent").trim(); |
| | | if (id == null || reviewResult == null){ |
| | | return new Msg(ErrorCode.ERROR_10001); |
| | | } |
| | | if (reviewResult.equals(REVIEW_INCOMPLETE)){ |
| | | return new Msg(ErrorCode.ERROR_10004); |
| | | }else if (!(reviewResult.equals(REVIEW_REJECTION)||reviewResult.equals(REVIEW_APPROVE))){ |
| | | return new Msg(ErrorCode.ERROR_10004); |
| | | } |
| | | |
| | | UserInfo userInfo = userService.getById(getUser().getId()); |
| | | //普通用户 |
| | | int normalUser = 3; |
| | | if (userInfo.getType() == normalUser){ |
| | | return new Msg(ErrorCode.ERROR_70001); |
| | | } |
| | | RegisterInfo registerInfo = registerService.getById(id); |
| | | if (registerInfo == null){ |
| | | return new Msg(ErrorCode.ERROR_50001); |
| | | } |
| | | if ((boolean)isEnterpriseNameExist(registerInfo.getEnterprisename()).getResult()){ |
| | | return new Msg(ErrorCode.ERROR_10004,"企业名称已存在"); |
| | | } |
| | | |
| | | if ((boolean)isEnterpriseNumberExist(registerInfo.getEnterprisenumber()).getResult()){ |
| | | return new Msg(ErrorCode.ERROR_10004,"企业编码已存在"); |
| | | } |
| | | |
| | | registerInfo.setReviewresult(reviewResult); |
| | | registerInfo.setReviewat(new Date()); |
| | | registerInfo.setReviewer(getUser().getId().toString()); |
| | | registerInfo.setReviewcontent(reviewContent); |
| | | registerService.updateById(registerInfo); |
| | | if (reviewResult.equals(REVIEW_APPROVE)){ |
| | | //创建企业账户 |
| | | enterpriseService.addEnterpriseByRegister(registerInfo,userInfo); |
| | | } |
| | | return success(); |
| | | } |
| | | |
| | | /** |
| | | * @Description: 根据企业名称判断企业是否存在 |
| | | */ |
| | | @GetMapping("/isNameExist") |
| | | @ApiOperation(value = "企业名称是否存在", httpMethod = "GET") |
| | | @ApiImplicitParam(name = "enterpriseName", value = "企业名称", required = true) |
| | | public Msg isEnterpriseNameExist(@RequestParam("enterpriseName")String enterpriseName){ |
| | | if (StringUtils.isBlank(enterpriseName.trim())){ |
| | | return new Msg(ERROR_10001); |
| | | } |
| | | boolean flag = true; |
| | | Enterprise enterprise = enterpriseService.selectEnterpriseByName(enterpriseName); |
| | | if (enterprise == null){ |
| | | flag = false; |
| | | return success(flag); |
| | | } |
| | | BlackList blackList = blackListService.getByEnterprisenumber(enterprise.getEnterprisenumber()); |
| | | if (blackList != null) flag = false; |
| | | return success(flag); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @Description: 根据企业编码判断企业是否存在 |
| | | */ |
| | | @GetMapping("/isNumberExist") |
| | | @ApiOperation(value = "企业编码是否存在", httpMethod = "GET") |
| | | @ApiImplicitParam(name = "enterpriseNumber", value = "企业编码", required = true) |
| | | public Msg isEnterpriseNumberExist(@RequestParam("enterpriseNumber")String enterpriseNumber){ |
| | | if (StringUtils.isBlank(enterpriseNumber.trim())){ |
| | | return new Msg(ERROR_10001); |
| | | } |
| | | boolean flag = true; |
| | | Enterprise enterprise = enterpriseService.selectEnterpriseByNumber(enterpriseNumber); |
| | | if (enterprise == null){ |
| | | flag = false; |
| | | } |
| | | return success(flag); |
| | | } |
| | | |
| | | @GetMapping("/review") |
| | | public Msg getWaitReviewData(@RequestParam(value = "name", required = false) String name, |
| | | @RequestParam(value = "type", required = false) String type, |
| | | @RequestParam(value = "reviewResult", required = false) Integer reviewResult, |
| | | @RequestParam(defaultValue = "0") Integer pageIndex, |
| | | @RequestParam(defaultValue = "10") Integer pageSize, |
| | | String sort, String order){ |
| | | Msg msg = new Msg(true); |
| | | |
| | | PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order); |
| | | Map<String, Object> condition = new HashMap<>(4); |
| | | if (StringUtils.isNotBlank(name)) { |
| | | condition.put("name", name); |
| | | } |
| | | if (StringUtils.isNotBlank(type)) { |
| | | condition.put("type", type); |
| | | } |
| | | if (reviewResult != null ){ |
| | | condition.put("reviewResult", reviewResult); |
| | | } |
| | | UserInfo userInfo = userService.getById(getUser().getId()); |
| | | |
| | | pageInfo.setCondition(condition); |
| | | registerService.selectDataGrid(pageInfo); |
| | | msg.setResult(pageInfo); |
| | | return msg; |
| | | } |
| | | |
| | | private Msg uploadFiles(Map<String, MultipartFile[]> map, RegisterInfo registerInfo) { |
| | | List<EnterpriseResource> adds = new ArrayList<>(); |
| | | try { |
| | | for (Map.Entry<String, MultipartFile[]>entry : map.entrySet()){ |
| | | MultipartFile[] files = entry.getValue(); |
| | | if (files != null && files.length > 0) { |
| | | for (MultipartFile file : files) { |
| | | String name = UploadUtil.uploadFile(file, Properties.enterprisePath); |
| | | EnterpriseResource er = new EnterpriseResource(); |
| | | er.setTabletype(entry.getKey()); |
| | | er.setFilename(file.getOriginalFilename()); |
| | | er.setUrl(Properties.enterprise + name); |
| | | er.setCreatetime(new Date()); |
| | | er.setCreatebyname(registerInfo.getEnterprisename()); |
| | | er.setBelongid(registerInfo.getId()); |
| | | er.setValidflag(true); |
| | | adds.add(er); |
| | | } |
| | | } |
| | | } |
| | | //执行 |
| | | enterpriseResourceService.saveBatch(adds); |
| | | return success(); |
| | | |
| | | } catch (Exception e) { |
| | | return new Msg(ErrorCode.ERROR_40001,"文件上传失败"); |
| | | } |
| | | |
| | | } |
| | | } |