|
|
@ -30,15 +30,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.yxt.anrui.base.api.basedatalist.BaseDataListFeign; |
|
|
|
import com.yxt.anrui.base.api.basedatalist.BaseDataListVo; |
|
|
|
import com.yxt.anrui.base.api.commonappendix.CommonAppendix; |
|
|
|
import com.yxt.anrui.base.api.commonappendix.CommonAppendixFeign; |
|
|
|
import com.yxt.anrui.base.api.commonappendix.CommonAttachTypeEnum; |
|
|
|
import com.yxt.anrui.crm.api.crmcustomerfile.*; |
|
|
|
import com.yxt.anrui.crm.api.crmcustomerfile.AppCrmCustomerTempArchivesDto; |
|
|
|
import com.yxt.anrui.crm.api.crmcustomerfile.AppCustomerArchivesDataDto; |
|
|
|
import com.yxt.anrui.crm.api.crmfile.CrmFile; |
|
|
|
import com.yxt.anrui.crm.api.crmfile.CrmFileDetailsVo; |
|
|
|
import com.yxt.anrui.crm.api.crmfile.CrmFileDto; |
|
|
|
import com.yxt.anrui.crm.biz.crmfile.CrmFileService; |
|
|
|
import com.yxt.anrui.portal.api.sysuser.SysUserFeign; |
|
|
|
import com.yxt.anrui.portal.api.sysuser.app.AppUserOrgInfoVo; |
|
|
|
import com.yxt.common.base.config.component.FileUploadComponent; |
|
|
|
import com.yxt.common.base.utils.DateUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
|
import com.yxt.common.base.utils.PagerUtil; |
|
|
@ -49,6 +52,9 @@ import com.yxt.common.core.vo.PagerVo; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
@ -68,121 +74,213 @@ import java.util.List; |
|
|
|
@Service |
|
|
|
public class CrmCustomerFileService extends MybatisBaseService<CrmCustomerFileMapper, CrmCustomerFile> { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
BaseDataListFeign baseDataListFeign; |
|
|
|
@Autowired |
|
|
|
private CrmFileService crmFileService; |
|
|
|
@Autowired |
|
|
|
private FileUploadComponent fileUploadComponent; |
|
|
|
|
|
|
|
public PagerVo<CrmCustomerFile> listPage(PagerQuery<CrmCustomerFileQuery> pq) { |
|
|
|
CrmCustomerFileQuery query = pq.getParams(); |
|
|
|
QueryWrapper<CrmCustomerFile> qw = createQueryWrapper(query); |
|
|
|
IPage<CrmCustomerFile> page = PagerUtil.queryToPage(pq); |
|
|
|
IPage<CrmCustomerFile> pagging = baseMapper.selectPage(page, qw); |
|
|
|
PagerVo<CrmCustomerFile> p = PagerUtil.pageToVo(pagging, null); |
|
|
|
return p; |
|
|
|
} |
|
|
|
public List<CrmCustomerFile> listAll(CrmCustomerFileQuery query) { |
|
|
|
QueryWrapper<CrmCustomerFile> qw = createQueryWrapper(query); |
|
|
|
return baseMapper.selectList(qw); |
|
|
|
} |
|
|
|
private QueryWrapper<CrmCustomerFile> createQueryWrapper(CrmCustomerFileQuery query) { |
|
|
|
// todo: 这里根据具体业务调整查询条件
|
|
|
|
// 多字段Like示例:qw.and(wrapper -> wrapper.like("name", query.getName()).or().like("remark", query.getName()));
|
|
|
|
QueryWrapper<CrmCustomerFile> qw = new QueryWrapper<>(); |
|
|
|
|
|
|
|
qw.eq("linkSid", query.getCustomerSid()); |
|
|
|
if (StringUtils.isNotBlank(query.getFileName())) { |
|
|
|
qw.like("fileName", query.getFileName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getAttachType())) { |
|
|
|
qw.like("attachType", query.getAttachType()); |
|
|
|
} |
|
|
|
return qw; |
|
|
|
} |
|
|
|
|
|
|
|
public PagerVo<CrmCustomerFileVo> listPageVo(PagerQuery<CrmCustomerFileQuery> pq) { |
|
|
|
QueryWrapper<CrmCustomerFile> qw = createQueryWrapper(pq.getParams()); |
|
|
|
IPage<CrmCustomerFile> page = PagerUtil.queryToPage(pq); |
|
|
|
IPage<CrmCustomerFileVo> pagging = baseMapper.selectPageVo(page, qw); |
|
|
|
PagerVo<CrmCustomerFileVo> p = PagerUtil.pageToVo(pagging, null); |
|
|
|
List<CrmCustomerFileVo> records = p.getRecords(); |
|
|
|
if (records.size() == 0){ |
|
|
|
fetchByDataTypeKey(pq.getParams().getCustomerSid()); |
|
|
|
IPage<CrmCustomerFileVo> paging = baseMapper.selectPageVo(page, qw); |
|
|
|
PagerVo<CrmCustomerFileVo> g = PagerUtil.pageToVo(paging, null); |
|
|
|
return g; |
|
|
|
} |
|
|
|
return p; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据资料类别key查询资料清单列表并保存到客户资料初始化表中 |
|
|
|
*/ |
|
|
|
private void fetchByDataTypeKey(String customerSid) { |
|
|
|
ResultBean<List<BaseDataListVo>> bean = baseDataListFeign.selectDataList("客户"); |
|
|
|
List<BaseDataListVo> data = bean.getData(); |
|
|
|
for (BaseDataListVo datum : data) { |
|
|
|
CrmCustomerFile crmCustomerFile = new CrmCustomerFile(); |
|
|
|
datum.fromEntity(crmCustomerFile); |
|
|
|
crmCustomerFile.setLinkSid(customerSid); |
|
|
|
this.save(crmCustomerFile); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public List<CrmCustomerFileVo> listAllVo(CrmCustomerFileQuery query) { |
|
|
|
QueryWrapper<CrmCustomerFile> qw = createQueryWrapper(query); |
|
|
|
return baseMapper.selectListAllVo(qw); |
|
|
|
} |
|
|
|
|
|
|
|
public List<CrmCustomerFileVo> listVo() { |
|
|
|
return baseMapper.selectListVo(); |
|
|
|
} |
|
|
|
|
|
|
|
public CrmCustomerFileVo fetchByIdVo(String id){ |
|
|
|
CrmCustomerFile entity = this.fetchById(id); |
|
|
|
CrmCustomerFileVo vo = new CrmCustomerFileVo(); |
|
|
|
BeanUtil.copyProperties(entity, vo); |
|
|
|
return vo; |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<CrmCustomerFileListVo> fetchFileListBySid(String sid) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
CrmCustomerFileListVo crmCustomerFileListVo = new CrmCustomerFileListVo(); |
|
|
|
CrmCustomerFile crmCustomerFile = this.fetchBySid(sid); |
|
|
|
crmCustomerFileListVo.setAttachType(crmCustomerFile.getAttachType()); |
|
|
|
crmCustomerFileListVo.setFileName(crmCustomerFile.getFileName()); |
|
|
|
List<CrmFileDetailsVo> crmFileVos = crmFileService.fetchByLinkSid(sid); |
|
|
|
if (crmFileVos.size() == 0){ |
|
|
|
return rb.success().setData(crmCustomerFileListVo); |
|
|
|
} |
|
|
|
for (CrmFileDetailsVo crmFileVo : crmFileVos) { |
|
|
|
String fileName = crmFileVo.getFileName(); |
|
|
|
fileName=fileName.substring(0,fileName.lastIndexOf('_')); |
|
|
|
crmFileVo.setFileName(fileName); |
|
|
|
} |
|
|
|
crmCustomerFileListVo.setCrmFileDetailsVoList(crmFileVos); |
|
|
|
return rb.success().setData(crmCustomerFileListVo); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean saveCustomerFile(String staffName,String staffSid,String sid, List<CrmFileDto> crmFileDtos) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
for (CrmFileDto crmFileDto : crmFileDtos) { |
|
|
|
String filePath = crmFileDto.getFilePath(); |
|
|
|
if (filePath.indexOf(fileUploadComponent.getUrlPrefix()) > -1) { |
|
|
|
filePath = filePath.replace(fileUploadComponent.getUrlPrefix(), ""); |
|
|
|
} |
|
|
|
CrmFile crmFile = new CrmFile(); |
|
|
|
crmFileDto.fillEntity(crmFile); |
|
|
|
crmFile.setFilePath(filePath); |
|
|
|
crmFile.setLinkSid(sid); |
|
|
|
crmFile.setCreateBySid(staffSid); |
|
|
|
crmFile.setCreateTime(new Date()); |
|
|
|
crmFile.setAttachType(CommonAttachTypeEnum.CUSTOMER_FILE.getAttachType()); |
|
|
|
crmFile.setName(staffName); |
|
|
|
crmFileService.save(crmFile); |
|
|
|
} |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
@Autowired |
|
|
|
BaseDataListFeign baseDataListFeign; |
|
|
|
@Autowired |
|
|
|
private CrmFileService crmFileService; |
|
|
|
@Autowired |
|
|
|
private FileUploadComponent fileUploadComponent; |
|
|
|
@Autowired |
|
|
|
SysUserFeign sysUserFeign; |
|
|
|
|
|
|
|
public PagerVo<CrmCustomerFile> listPage(PagerQuery<CrmCustomerFileQuery> pq) { |
|
|
|
CrmCustomerFileQuery query = pq.getParams(); |
|
|
|
QueryWrapper<CrmCustomerFile> qw = createQueryWrapper(query); |
|
|
|
IPage<CrmCustomerFile> page = PagerUtil.queryToPage(pq); |
|
|
|
IPage<CrmCustomerFile> pagging = baseMapper.selectPage(page, qw); |
|
|
|
PagerVo<CrmCustomerFile> p = PagerUtil.pageToVo(pagging, null); |
|
|
|
return p; |
|
|
|
} |
|
|
|
|
|
|
|
public List<CrmCustomerFile> listAll(CrmCustomerFileQuery query) { |
|
|
|
QueryWrapper<CrmCustomerFile> qw = createQueryWrapper(query); |
|
|
|
return baseMapper.selectList(qw); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<CrmCustomerFile> createQueryWrapper(CrmCustomerFileQuery query) { |
|
|
|
// todo: 这里根据具体业务调整查询条件
|
|
|
|
// 多字段Like示例:qw.and(wrapper -> wrapper.like("name", query.getName()).or().like("remark", query.getName()));
|
|
|
|
QueryWrapper<CrmCustomerFile> qw = new QueryWrapper<>(); |
|
|
|
|
|
|
|
qw.eq("linkSid", query.getCustomerSid()); |
|
|
|
if (StringUtils.isNotBlank(query.getFileName())) { |
|
|
|
qw.like("fileName", query.getFileName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getAttachType())) { |
|
|
|
qw.like("attachType", query.getAttachType()); |
|
|
|
} |
|
|
|
return qw; |
|
|
|
} |
|
|
|
|
|
|
|
public PagerVo<CrmCustomerFileVo> listPageVo(PagerQuery<CrmCustomerFileQuery> pq) { |
|
|
|
QueryWrapper<CrmCustomerFile> qw = createQueryWrapper(pq.getParams()); |
|
|
|
IPage<CrmCustomerFile> page = PagerUtil.queryToPage(pq); |
|
|
|
IPage<CrmCustomerFileVo> pagging = baseMapper.selectPageVo(page, qw); |
|
|
|
PagerVo<CrmCustomerFileVo> p = PagerUtil.pageToVo(pagging, null); |
|
|
|
List<CrmCustomerFileVo> records = p.getRecords(); |
|
|
|
if (records.size() == 0) { |
|
|
|
fetchByDataTypeKey(pq.getParams().getCustomerSid()); |
|
|
|
IPage<CrmCustomerFileVo> paging = baseMapper.selectPageVo(page, qw); |
|
|
|
PagerVo<CrmCustomerFileVo> g = PagerUtil.pageToVo(paging, null); |
|
|
|
return g; |
|
|
|
} |
|
|
|
return p; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据资料类别key查询资料清单列表并保存到客户资料初始化表中 |
|
|
|
*/ |
|
|
|
private void fetchByDataTypeKey(String customerSid) { |
|
|
|
ResultBean<List<BaseDataListVo>> bean = baseDataListFeign.selectDataList("客户"); |
|
|
|
List<BaseDataListVo> data = bean.getData(); |
|
|
|
for (BaseDataListVo datum : data) { |
|
|
|
CrmCustomerFile crmCustomerFile = new CrmCustomerFile(); |
|
|
|
datum.fromEntity(crmCustomerFile); |
|
|
|
crmCustomerFile.setLinkSid(customerSid); |
|
|
|
this.save(crmCustomerFile); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public List<CrmCustomerFileVo> listAllVo(CrmCustomerFileQuery query) { |
|
|
|
QueryWrapper<CrmCustomerFile> qw = createQueryWrapper(query); |
|
|
|
return baseMapper.selectListAllVo(qw); |
|
|
|
} |
|
|
|
|
|
|
|
public List<CrmCustomerFileVo> listVo() { |
|
|
|
return baseMapper.selectListVo(); |
|
|
|
} |
|
|
|
|
|
|
|
public CrmCustomerFileVo fetchByIdVo(String id) { |
|
|
|
CrmCustomerFile entity = this.fetchById(id); |
|
|
|
CrmCustomerFileVo vo = new CrmCustomerFileVo(); |
|
|
|
BeanUtil.copyProperties(entity, vo); |
|
|
|
return vo; |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<CrmCustomerFileListVo> fetchFileListBySid(String sid) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
CrmCustomerFileListVo crmCustomerFileListVo = new CrmCustomerFileListVo(); |
|
|
|
CrmCustomerFile crmCustomerFile = this.fetchBySid(sid); |
|
|
|
crmCustomerFileListVo.setAttachType(crmCustomerFile.getAttachType()); |
|
|
|
crmCustomerFileListVo.setFileName(crmCustomerFile.getFileName()); |
|
|
|
List<CrmFileDetailsVo> crmFileVos = crmFileService.fetchByLinkSid(sid); |
|
|
|
if (crmFileVos.size() == 0) { |
|
|
|
return rb.success().setData(crmCustomerFileListVo); |
|
|
|
} |
|
|
|
for (CrmFileDetailsVo crmFileVo : crmFileVos) { |
|
|
|
String fileName = crmFileVo.getFileName(); |
|
|
|
fileName = fileName.substring(0, fileName.lastIndexOf('_')); |
|
|
|
crmFileVo.setFileName(fileName); |
|
|
|
} |
|
|
|
crmCustomerFileListVo.setCrmFileDetailsVoList(crmFileVos); |
|
|
|
return rb.success().setData(crmCustomerFileListVo); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean saveCustomerFile(String staffName, String staffSid, String sid, List<CrmFileDto> crmFileDtos) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
for (CrmFileDto crmFileDto : crmFileDtos) { |
|
|
|
String filePath = crmFileDto.getFilePath(); |
|
|
|
if (filePath.indexOf(fileUploadComponent.getUrlPrefix()) > -1) { |
|
|
|
filePath = filePath.replace(fileUploadComponent.getUrlPrefix(), ""); |
|
|
|
} |
|
|
|
CrmFile crmFile = new CrmFile(); |
|
|
|
crmFileDto.fillEntity(crmFile); |
|
|
|
crmFile.setFilePath(filePath); |
|
|
|
crmFile.setLinkSid(sid); |
|
|
|
crmFile.setCreateBySid(staffSid); |
|
|
|
crmFile.setCreateTime(new Date()); |
|
|
|
crmFile.setAttachType(CommonAttachTypeEnum.CUSTOMER_FILE.getAttachType()); |
|
|
|
crmFile.setName(staffName); |
|
|
|
crmFileService.save(crmFile); |
|
|
|
} |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<AppCrmCustomerTempArchivesVo> initCustomerArchives(String customerSid, String userSid) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
fetchByDataTypeKey(customerSid); |
|
|
|
AppCrmCustomerTempArchivesVo vo = new AppCrmCustomerTempArchivesVo(); |
|
|
|
List<AppCustomerArchivesDataVo> dataVos = baseMapper.selectByCustomerSid(customerSid); |
|
|
|
for (AppCustomerArchivesDataVo appCustomerArchivesDataVo : dataVos) { |
|
|
|
String createTime = appCustomerArchivesDataVo.getCreateTime(); |
|
|
|
Date date = DateUtils.dateStrConvertDate(createTime, "yyyy-MM-dd HH:mm:ss"); |
|
|
|
long time = date.getTime(); |
|
|
|
String s = String.valueOf(time); |
|
|
|
appCustomerArchivesDataVo.setLastUploadTime(s); |
|
|
|
String sid = appCustomerArchivesDataVo.getSid(); |
|
|
|
List<CrmFile> listVo = baseMapper.selArchivesFileImageBySid(sid); |
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
for (CrmFile crmFile : listVo) { |
|
|
|
String url = fileUploadComponent.getUrlPrefix() + crmFile.getFilePath(); |
|
|
|
list.add(url); |
|
|
|
} |
|
|
|
appCustomerArchivesDataVo.setFiles(list); |
|
|
|
} |
|
|
|
return rb.success().setData(vo); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean saveCustomerArchives(AppCrmCustomerTempArchivesDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
AppUserOrgInfoVo data = sysUserFeign.getUserOrgInfoByUserSid(dto.getUserSid()).getData(); |
|
|
|
List<AppCustomerArchivesDataDto> archivesDataDtos = dto.getData(); |
|
|
|
for (AppCustomerArchivesDataDto datum : archivesDataDtos) { |
|
|
|
if (datum.isChange() == true) { |
|
|
|
// 先查询库里key集合是否为空 ?
|
|
|
|
List<AppCustomerArchivesDataVo> dataVos = baseMapper.selectByCustomerSid(dto.getCustomerSid()); |
|
|
|
for (AppCustomerArchivesDataVo appCustomerArchivesDataVo : dataVos) { |
|
|
|
String sid = appCustomerArchivesDataVo.getSid(); |
|
|
|
Integer count = baseMapper.selectBySid(sid); |
|
|
|
if (count <= 0) { |
|
|
|
//不存在 直接新增保存 并更新时间为当前提交的时间
|
|
|
|
List<String> files = datum.getFiles(); |
|
|
|
for (String file : files) { |
|
|
|
if (file.indexOf(fileUploadComponent.getUrlPrefix()) > -1) { |
|
|
|
file = file.replace(fileUploadComponent.getUrlPrefix(), ""); |
|
|
|
} |
|
|
|
CrmFile crmFile = new CrmFile(); |
|
|
|
crmFile.setFilePath(file); |
|
|
|
crmFile.setLinkSid(sid); |
|
|
|
crmFile.setCreateBySid(data.getStaffSid()); |
|
|
|
crmFile.setCreateTime(new Date()); |
|
|
|
crmFile.setAttachType(CommonAttachTypeEnum.CUSTOMER_FILE.getAttachType()); |
|
|
|
crmFile.setName(data.getStaffName()); |
|
|
|
crmFileService.save(crmFile); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
// 存在 需要判断是否是当天的 如果不是当天的 false
|
|
|
|
String createTime = appCustomerArchivesDataVo.getCreateTime(); |
|
|
|
Date date = DateUtils.dateStrConvertDate(createTime, "yyyy-MM-dd"); |
|
|
|
boolean b = DateUtils.compTime(date, new Date()); |
|
|
|
if (b) { |
|
|
|
//如果是当天的 并新增 提交时间为当前提交时间
|
|
|
|
List<String> files = datum.getFiles(); |
|
|
|
for (String file : files) { |
|
|
|
//删除之前的附件并且删除服务器上的
|
|
|
|
crmFileService.deleteFilesOss(file); |
|
|
|
//新增
|
|
|
|
if (file.indexOf(fileUploadComponent.getUrlPrefix()) > -1) { |
|
|
|
file = file.replace(fileUploadComponent.getUrlPrefix(), ""); |
|
|
|
} |
|
|
|
CrmFile crmFile = new CrmFile(); |
|
|
|
crmFile.setFilePath(file); |
|
|
|
crmFile.setLinkSid(sid); |
|
|
|
crmFile.setCreateBySid(data.getStaffSid()); |
|
|
|
crmFile.setCreateTime(new Date()); |
|
|
|
crmFile.setAttachType(CommonAttachTypeEnum.CUSTOMER_FILE.getAttachType()); |
|
|
|
crmFile.setName(data.getStaffName()); |
|
|
|
crmFileService.save(crmFile); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return rb.fail().setMsg("提示:身份证是在 " + appCustomerArchivesDataVo.getCreateTime() + "日上传的,仅支持当天进行修改删除"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |