企业管理功能模块开发
This commit is contained in:
@@ -7,6 +7,7 @@ import org.hibernate.validator.HibernateValidator;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.groups.Default;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -27,6 +28,13 @@ public class ValidUtil {
|
||||
.buildValidatorFactory().getValidator();
|
||||
}
|
||||
|
||||
private static Validator validatorAll;
|
||||
|
||||
static {
|
||||
validatorAll = Validation.buildDefaultValidatorFactory()
|
||||
.getValidator();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动校验@Vaild并抛出异常信息
|
||||
*
|
||||
@@ -39,4 +47,23 @@ public class ValidUtil {
|
||||
throw new JeroBootException(constraintViolation.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @Description 校验excel 每行数据格式
|
||||
* @Author lqt
|
||||
* @Date 2021/8/26
|
||||
* @Param count excel 行数
|
||||
* @Return
|
||||
* @Exception
|
||||
*/
|
||||
public static StringBuilder validateExcel(Object object, int count,Class<?>... groups){
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Set<ConstraintViolation<Object>> set = validatorAll.validate(object, Default.class);
|
||||
if(set != null && set.size() >0 ){
|
||||
for(ConstraintViolation<Object> constraintViolation : set){
|
||||
// 这里循环获取错误信息,可以自定义格式
|
||||
msg.append("第").append(count).append("行:").append(constraintViolation.getMessage()).append("</br>");
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.jero.modules.company.common;
|
||||
|
||||
public class PayCompanyManagementCommon {
|
||||
/**
|
||||
* (1:管理端,2:报名)
|
||||
*/
|
||||
public final static Integer DATA_SOURCE1 = 1;
|
||||
/**
|
||||
* (1:管理端,2:报名)
|
||||
*/
|
||||
public final static Integer DATA_SOURCE2 = 2;
|
||||
/**
|
||||
* 报名新增(1:是,0:否)
|
||||
*/
|
||||
public final static Integer SIGNING_UP1 = 1;
|
||||
/**
|
||||
* 报名新增(1:是,0:否)
|
||||
*/
|
||||
public final static Integer SIGNING_UP0 = 0;
|
||||
}
|
||||
+90
-6
@@ -1,7 +1,7 @@
|
||||
package com.jero.modules.company.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -10,18 +10,22 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.ValidUtil;
|
||||
import com.jero.modules.company.common.PayCompanyManagementCommon;
|
||||
import com.jero.modules.company.entity.PayCompanyManagement;
|
||||
import com.jero.modules.company.service.IPayCompanyManagementService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.jeecgframework.poi.excel.ExcelImportCheckUtil;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -78,7 +82,16 @@ public class PayCompanyManagementController extends JeroController<PayCompanyMan
|
||||
LambdaQueryWrapper<PayCompanyManagement> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(PayCompanyManagement::getCompanyName,payCompanyManagement.getCompanyName());
|
||||
PayCompanyManagement payCompanyManagementNew = payCompanyManagementService.getOne(queryWrapper);
|
||||
// 存在数据
|
||||
if(!Objects.isNull(payCompanyManagementNew)){
|
||||
// 如果是管理新增 && 已存在数据来源是报名,更新数据,变更来源为管理端
|
||||
if(!Objects.equals(payCompanyManagement.getDataSource(),PayCompanyManagementCommon.DATA_SOURCE1)
|
||||
&& !Objects.equals(payCompanyManagementNew.getDataSource(),PayCompanyManagementCommon.DATA_SOURCE2)){
|
||||
payCompanyManagement.setId(payCompanyManagementNew.getId());
|
||||
payCompanyManagement.setDataSource(PayCompanyManagementCommon.DATA_SOURCE1);
|
||||
payCompanyManagementService.updateById(payCompanyManagement);
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
return Result.error("该企业名称已存在!");
|
||||
}
|
||||
payCompanyManagementService.save(payCompanyManagement);
|
||||
@@ -219,6 +232,77 @@ public class PayCompanyManagementController extends JeroController<PayCompanyMan
|
||||
@ApiOperation(value="企业管理-excel导入数据", notes="企业管理-excel导入数据")
|
||||
@PostMapping(value = "/importExcel")
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, PayCompanyManagement.class);
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(1);
|
||||
params.setHeadRows(1);
|
||||
try {
|
||||
//导入Excel格式校验,看匹配的字段文本概率
|
||||
Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), PayCompanyManagement.class, params);
|
||||
if(!t){
|
||||
throw new RuntimeException("导入Excel校验失败 !");
|
||||
}
|
||||
List<PayCompanyManagement> list = ExcelImportUtil.importExcel(file.getInputStream(), PayCompanyManagement.class, params);
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
List<PayCompanyManagement> listSigning = new ArrayList<>();
|
||||
List<PayCompanyManagement> listRemove = new ArrayList<>();
|
||||
List<PayCompanyManagement> listAll = payCompanyManagementService.list();
|
||||
List<String> listCompany = new ArrayList<>();
|
||||
StringBuilder msg = new StringBuilder();
|
||||
list.forEach(p->{
|
||||
int count = list.indexOf(p);
|
||||
// 校验 表中是否存在企业名称
|
||||
if(!CollectionUtils.isEmpty(listAll)){
|
||||
List<PayCompanyManagement> listCompanyEquals = listAll.stream().filter(p1->Objects.equals(p1.getCompanyName(),p.getCompanyName())).collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(listCompanyEquals)){
|
||||
// 已存在数据来源是报名,变更来源为管理端,替换掉数据
|
||||
if(!Objects.equals(listCompanyEquals.get(0).getDataSource(),PayCompanyManagementCommon.DATA_SOURCE2)){
|
||||
PayCompanyManagement payCompanyManagement = p;
|
||||
payCompanyManagement.setId(listCompanyEquals.get(0).getId());
|
||||
payCompanyManagement.setDataSource(PayCompanyManagementCommon.DATA_SOURCE1);
|
||||
listSigning.add(payCompanyManagement);
|
||||
listRemove.add(p);
|
||||
}
|
||||
msg.append("第").append(count + 3).append("行:企业名称已经存在,请修改。</br>");
|
||||
}
|
||||
}
|
||||
// 校验excel表中是否存在重复企业名称
|
||||
if(listCompany.contains(p.getCompanyName())){
|
||||
msg.append("第 ").append(count + 3).append(" 行:企业名称在excel中重复,请修改。</br>");
|
||||
}
|
||||
listCompany.add(p.getCompanyName());
|
||||
p.setDataSource(PayCompanyManagementCommon.DATA_SOURCE1);
|
||||
p.setSigningUp(PayCompanyManagementCommon.SIGNING_UP0);
|
||||
// 校验字段值
|
||||
StringBuilder s = ValidUtil.validateExcel(p,(count+3));
|
||||
if(!StringUtils.isBlank(s)){
|
||||
msg.append(s);
|
||||
}
|
||||
});
|
||||
if(!StringUtils.isBlank(msg)){
|
||||
return Result.error(msg.toString());
|
||||
}
|
||||
// 去掉变更来源的数据
|
||||
if(CollectionUtils.isEmpty(list) && !CollectionUtils.isEmpty(listRemove)){
|
||||
list.removeAll(listRemove);
|
||||
}
|
||||
// 更新数据
|
||||
payCompanyManagementService.updateDate(listSigning,list);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Result.error("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.OK("文件导入成功!");
|
||||
}
|
||||
}
|
||||
|
||||
+11
-7
@@ -5,6 +5,7 @@ import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.jero.modules.system.volid.group.Group;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
@@ -14,9 +15,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* @Description: pay_company_management
|
||||
@@ -31,7 +30,6 @@ import javax.validation.constraints.Size;
|
||||
@ApiModel(value="pay_company_management对象", description="pay_company_management")
|
||||
public class PayCompanyManagement implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
// todo 缺少正则
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
@@ -41,7 +39,6 @@ public class PayCompanyManagement implements Serializable {
|
||||
@Excel(name = "企业名称", width = 15)
|
||||
@ApiModelProperty(value = "企业名称")
|
||||
@NotEmpty(message = "企业名称不能为空!")
|
||||
@Size(max = 50,message = "企业名称长度应小于50个字符")
|
||||
private String companyName;
|
||||
/**公司地址*/
|
||||
@Excel(name = "公司地址", width = 15)
|
||||
@@ -52,11 +49,13 @@ public class PayCompanyManagement implements Serializable {
|
||||
@Excel(name = "公司电话", width = 15)
|
||||
@ApiModelProperty(value = "公司电话")
|
||||
@Size(max = 15, message = "公司电话长度应小于15个字符")
|
||||
@Pattern(regexp = "^((0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$|(0\\d{10})$",message = "公司电话格式错误")
|
||||
private String companyPhone;
|
||||
/**邮编*/
|
||||
@Excel(name = "邮编", width = 15)
|
||||
@ApiModelProperty(value = "邮编")
|
||||
@Size(min=6,max = 6,message = "邮编长度必须为6个字符")
|
||||
@Pattern(regexp = "^[0-9]{6}$",message = "邮编格式错误")
|
||||
private String postalCode;
|
||||
/**银行户名*/
|
||||
@Excel(name = "银行户名", width = 15)
|
||||
@@ -72,6 +71,7 @@ public class PayCompanyManagement implements Serializable {
|
||||
@Excel(name = "银行账号", width = 15)
|
||||
@ApiModelProperty(value = "银行账号")
|
||||
@Size(max = 50, message = "银行账号长度应小于50个字符")
|
||||
@Pattern(regexp = "^[0-9]*$",message = "银行账号格式错误")
|
||||
private String bankAccount;
|
||||
/**税号*/
|
||||
@Excel(name = "税号", width = 15)
|
||||
@@ -80,9 +80,13 @@ public class PayCompanyManagement implements Serializable {
|
||||
private String dutyCode;
|
||||
/**数据来源(1:管理端,2:报名)*/
|
||||
@ApiModelProperty(value = "数据来源(1:管理端,2:报名)")
|
||||
@Max(2)
|
||||
@Min(1)
|
||||
private Integer dataSource;
|
||||
/**报名新增(1:是,2为否)*/
|
||||
@ApiModelProperty(value = "报名新增(1:是,2为否)")
|
||||
/**报名新增(1:是,0:否)*/
|
||||
@ApiModelProperty(value = "报名新增(1:是,0:否)")
|
||||
@Max(1)
|
||||
@Min(0)
|
||||
private Integer signingUp;
|
||||
/**备注*/
|
||||
@Excel(name = "备注", width = 15)
|
||||
|
||||
+8
-1
@@ -14,6 +14,10 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @Description: pay_contacts_management
|
||||
* @Author: jeecg-boot
|
||||
@@ -46,7 +50,8 @@ public class PayContactsManagement implements Serializable {
|
||||
private String name;
|
||||
/**性别(1为男,2为女)*/
|
||||
@Excel(name = "性别(1为男,2为女)", width = 15)
|
||||
@ApiModelProperty(value = "性别(1为男,2为女)")
|
||||
@ApiModelProperty(value = "性别")
|
||||
@NotNull(message = "年龄不能为空")
|
||||
private Integer gender;
|
||||
/**职务*/
|
||||
@Excel(name = "职务", width = 15)
|
||||
@@ -55,10 +60,12 @@ public class PayContactsManagement implements Serializable {
|
||||
/**手机号*/
|
||||
@Excel(name = "手机号", width = 15)
|
||||
@ApiModelProperty(value = "手机号")
|
||||
@Pattern(regexp = "^1(3|4|5|7|8)\\d{9}$",message = "手机号码格式错误")
|
||||
private String phone;
|
||||
/**邮箱*/
|
||||
@Excel(name = "邮箱", width = 15)
|
||||
@ApiModelProperty(value = "邮箱")
|
||||
@Email(message = "邮箱格式有误")
|
||||
private String email;
|
||||
/**通讯地址*/
|
||||
@Excel(name = "通讯地址", width = 15)
|
||||
|
||||
+11
@@ -4,6 +4,8 @@ package com.jero.modules.company.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.modules.company.entity.PayCompanyManagement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: pay_company_management
|
||||
* @Author: jeecg-boot
|
||||
@@ -11,4 +13,13 @@ import com.jero.modules.company.entity.PayCompanyManagement;
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface IPayCompanyManagementService extends IService<PayCompanyManagement> {
|
||||
/**
|
||||
* @Description 更新数据
|
||||
* @Author lqt
|
||||
* @Date 2021/8/26
|
||||
* @Param
|
||||
* @Return
|
||||
* @Exception
|
||||
*/
|
||||
void updateDate(List<PayCompanyManagement> listSigning,List<PayCompanyManagement> list);
|
||||
}
|
||||
|
||||
+20
@@ -4,7 +4,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.modules.company.entity.PayCompanyManagement;
|
||||
import com.jero.modules.company.mapper.PayCompanyManagementMapper;
|
||||
import com.jero.modules.company.service.IPayCompanyManagementService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: pay_company_management
|
||||
@@ -15,4 +20,19 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class PayCompanyManagementServiceImpl extends ServiceImpl<PayCompanyManagementMapper, PayCompanyManagement> implements IPayCompanyManagementService {
|
||||
|
||||
@Autowired
|
||||
IPayCompanyManagementService iPayCompanyManagementService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateDate(List<PayCompanyManagement> listSigning, List<PayCompanyManagement> list) {
|
||||
// 已存在企业名称,变更数据来源
|
||||
if(!CollectionUtils.isEmpty(listSigning)){
|
||||
iPayCompanyManagementService.updateBatchById(listSigning);
|
||||
}
|
||||
// 更新excel数据
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
iPayCompanyManagementService.saveBatch(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user