From 60a1a3b8815758fbf6e6bd54643c5b3e2e6af8fb Mon Sep 17 00:00:00 2001 From: gongbiao Date: Mon, 10 Sep 2018 20:04:44 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=9A=E5=91=98][=E4=BF=AE=E6=94=B9][?= =?UTF-8?q?=E5=AF=BC=E5=85=A5]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simple/domain/po/WxCUserBasicInfo.java | 6 ++++ .../impl/WxCUserBasicInfoServiceImpl.java | 33 +++++++++++-------- .../mapper/WxCUserBasicInfoMapper.xml | 12 +++---- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/mallinkService/src/main/java/com/simple/domain/po/WxCUserBasicInfo.java b/mallinkService/src/main/java/com/simple/domain/po/WxCUserBasicInfo.java index 180948877..0debb147e 100644 --- a/mallinkService/src/main/java/com/simple/domain/po/WxCUserBasicInfo.java +++ b/mallinkService/src/main/java/com/simple/domain/po/WxCUserBasicInfo.java @@ -5,6 +5,7 @@ import cn.afterturn.easypoi.excel.annotation.Excel; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; +import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; import java.util.List; @@ -46,17 +47,21 @@ public class WxCUserBasicInfo implements Serializable { /*微信用户绑定的手机号**/ @Excel(name="手机",width = 20,orderNum = "2") @io.swagger.annotations.ApiModelProperty(value="微信用户绑定的手机号",name="phone") + @NotNull private String phone; /*出生日期**/ @Excel(name="生日",width = 20,format="yyyy-MM-dd",orderNum = "3") + @NotNull @io.swagger.annotations.ApiModelProperty(value="出生日期",name="birthdate") private Date birthdate; /*学历**/ @Excel(name="学历",width = 20,orderNum = "4") + @NotNull @io.swagger.annotations.ApiModelProperty(value="学历",name="education") private String education; /*性别:0:保密 1.男 2女**/ @Excel(name="性别",width = 20,replace = { "保密_0", "男_1","女_2"},orderNum = "2") + @NotNull @io.swagger.annotations.ApiModelProperty(value="性别:0:保密 1.男 2女",name="sex") private Integer sex; /*邮箱**/ @@ -83,6 +88,7 @@ public class WxCUserBasicInfo implements Serializable { /*用户姓名**/ @Excel(name="姓名",width = 20) + @NotNull @io.swagger.annotations.ApiModelProperty(value="用户姓名",name="name") private String name; diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java index 228614175..16efaf807 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java @@ -302,29 +302,36 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { try { ImportParams params = new ImportParams(); - params.setTitleRows(1); - params.setHeadRows(1); + + List datalist = ExcelImportUtil.importExcel(file.getInputStream(),WxCUserBasicInfo.class, params); WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); wxCUserBasicInfo.setTenantId(tenantId); List list = wxCUserBasicInfoMapper.findList(wxCUserBasicInfo); final IdWorker idWorker = IdWorker.get(); for(WxCUserBasicInfo user:datalist){ - WxCUserBasicInfo tempuser = list.stream().filter(u -> u.getPhone().equals(user.getPhone())).findFirst().get(); - if(tempuser!=null){ - tempuser.setSex(user.getSex()); - tempuser.setEducation(user.getEducation()); - tempuser.setBirthdate(user.getBirthdate()); - tempuser.setName(user.getName()); - wxCUserBasicInfoMapper.updateByPrimaryKeySelective(tempuser); - } else { - user.setId(idWorker.nextId()); - wxCUserBasicInfoMapper.insertSelective(user); + if(user.getPhone()!=null){ + WxCUserBasicInfo tempuser=null; + if(list.size()>0){ + tempuser = list.stream().filter(u -> u.getPhone().equals(user.getPhone())).findFirst().get(); + } + if(tempuser!=null){ + tempuser.setTenantId(tenantId); + tempuser.setSex(user.getSex()); + tempuser.setEducation(user.getEducation()); + tempuser.setBirthdate(user.getBirthdate()); + tempuser.setName(user.getName()); + wxCUserBasicInfoMapper.updateByPrimaryKeySelective(tempuser); + } else { + user.setId(idWorker.nextId()); + user.setTenantId(tenantId); + wxCUserBasicInfoMapper.insertSelective(user); + } } } } catch (Exception e) { - throw new MallinkException(500,"模板导入失败"); + throw new MallinkException(500,"模板导入失败"+e); } return new ResultData(Result.SUCCESS,"导入成功"); diff --git a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml index d4cefec11..bed2cacd1 100644 --- a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml @@ -32,7 +32,7 @@ - and c.`tenant_id` like concat('%', #{tenantId},'%') + and `tenant_id` = #{tenantId} @@ -67,20 +67,16 @@ and `tag_id` = #{tagId} - - and `c_user_id` = #{cUserId} - - - and c.`create_date` = #{createDate} + and `create_date` = #{createDate} - and c.`update_date` = #{updateDate} + and `update_date` = #{updateDate} - and c.`name` like concat('%', #{name},'%') + and `name` like concat('%', #{name},'%') and id in