|
|
@ -1,15 +1,36 @@ |
|
|
|
package com.yxt.anrui.buscenter.biz.busdiscountpackagehandover; |
|
|
|
|
|
|
|
import com.yxt.anrui.buscenter.api.busdiscountpackagehandover.BusDiscountpackageHandover; |
|
|
|
import com.yxt.anrui.buscenter.api.busdiscountpackagehandover.BusDiscountpackageHandoverDto; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.yxt.anrui.buscenter.api.busdiscountpackagehandover.*; |
|
|
|
import com.yxt.anrui.buscenter.api.busdiscountpackagehandoverlist.BusDiscountpackageHandoverList; |
|
|
|
import com.yxt.anrui.buscenter.api.busdiscountpackagehandoverlist.BusDiscountpackageHandoverListDto; |
|
|
|
import com.yxt.anrui.buscenter.api.busdiscountpackagehandoverlist.BusDiscountpackageHandoverListVo; |
|
|
|
import com.yxt.anrui.buscenter.api.busfile.BusFile; |
|
|
|
import com.yxt.anrui.buscenter.api.busfile.BusFileDto; |
|
|
|
import com.yxt.anrui.buscenter.biz.busdiscountpackagehandoverlist.BusDiscountpackageHandoverListService; |
|
|
|
import com.yxt.anrui.buscenter.biz.busfile.BusFileService; |
|
|
|
import com.yxt.anrui.fin.api.finuncollectedreceivablesdetailed.FinUncollectedReceivablesDetailedPdfVo; |
|
|
|
import com.yxt.anrui.portal.api.sysrole.SysRoleFeign; |
|
|
|
import com.yxt.anrui.portal.api.sysrole.SysRoleVo; |
|
|
|
import com.yxt.common.base.config.component.DocPdfComponent; |
|
|
|
import com.yxt.common.base.config.component.FileUploadComponent; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
|
import com.yxt.common.base.utils.PagerUtil; |
|
|
|
import com.yxt.common.base.utils.WordConvertUtils; |
|
|
|
import com.yxt.common.core.query.PagerQuery; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.io.File; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author Administrator |
|
|
@ -21,13 +42,87 @@ public class BusDiscountpackageHandoverService extends MybatisBaseService<BusDis |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private BusDiscountpackageHandoverListService busDiscountpackageHandoverListService; |
|
|
|
@Autowired |
|
|
|
private SysRoleFeign sysRoleFeign; |
|
|
|
@Autowired |
|
|
|
private FileUploadComponent fileUploadComponent; |
|
|
|
@Autowired |
|
|
|
private BusFileService busFileService; |
|
|
|
@Autowired |
|
|
|
private DocPdfComponent docPdfComponent; |
|
|
|
|
|
|
|
/** |
|
|
|
* 筛选条件 |
|
|
|
* |
|
|
|
* @param query |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private QueryWrapper<BusDiscountpackageHandover> createQueryWrapper(BusDiscountpackageHandoverQuery query) { |
|
|
|
QueryWrapper<BusDiscountpackageHandover> qw = new QueryWrapper<>(); |
|
|
|
qw.eq("useOrgSid", query.getUseOrgSid()); |
|
|
|
qw.eq("isDelete", 0); |
|
|
|
if (StringUtils.isNotBlank(query.getCustomerName())) { |
|
|
|
qw.like("customerName", query.getCustomerName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getContractNo())) { |
|
|
|
qw.like("contractNo", query.getContractNo()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getRecName())) { |
|
|
|
qw.like("recName", query.getRecName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getRecUserSid())) { |
|
|
|
qw.eq("recUserSid", query.getRecUserSid()); |
|
|
|
} |
|
|
|
if (null != query.getState()) { |
|
|
|
if (query.getState() == 3) { |
|
|
|
qw.eq("state", query.getState()); |
|
|
|
} else { |
|
|
|
qw.ne("state", 3); |
|
|
|
} |
|
|
|
} |
|
|
|
String createStartTime = query.getCreateStartTime(); |
|
|
|
String createEndTime = query.getCreateEndTime(); |
|
|
|
qw.apply(StringUtils.isNotEmpty(createStartTime), "date_format (createTime,'%Y-%m-%d') >= date_format('" + createStartTime + "','%Y-%m-%d')"). |
|
|
|
apply(StringUtils.isNotEmpty(createEndTime), "date_format (createTime,'%Y-%m-%d') <= date_format('" + createEndTime + "','%Y-%m-%d')" |
|
|
|
); |
|
|
|
return qw; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询优惠包交接管理分页列表 |
|
|
|
* |
|
|
|
* @param pq |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public PagerVo<BusDiscountpackageHandoverVo> listPage(PagerQuery<BusDiscountpackageHandoverQuery> pq) { |
|
|
|
//从传入参数中取查询条件
|
|
|
|
BusDiscountpackageHandoverQuery query = pq.getParams(); |
|
|
|
//取到当前登录用户的sid
|
|
|
|
String userSid = query.getUserSid(); |
|
|
|
//根据当前用户sid查询用户角色
|
|
|
|
List<SysRoleVo> roleVoList = sysRoleFeign.fetchByUserSid(userSid).getData(); |
|
|
|
//判断当前登录用户角色是否为销售专员
|
|
|
|
if (null != roleVoList) { |
|
|
|
for (SysRoleVo sysRoleVo : roleVoList) { |
|
|
|
//如果当前登录用户角色包含分公司销售专员,将当前用户sid保存到查询条件中
|
|
|
|
if ("分公司销售专员".equals(sysRoleVo.getName())) { |
|
|
|
query.setRecUserSid(userSid); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
QueryWrapper<BusDiscountpackageHandover> qw = createQueryWrapper(query); |
|
|
|
IPage<BusDiscountpackageHandover> page = PagerUtil.queryToPage(pq); |
|
|
|
IPage<BusDiscountpackageHandoverVo> pagging = baseMapper.selectPageVo(page, qw); |
|
|
|
PagerVo<BusDiscountpackageHandoverVo> p = PagerUtil.pageToVo(pagging, null); |
|
|
|
return p; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新增 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
*/ |
|
|
|
public void saveOrUpdateDto(BusDiscountpackageHandoverDto dto) { |
|
|
|
public boolean saveOrUpdateDto(BusDiscountpackageHandoverDto dto) { |
|
|
|
BusDiscountpackageHandover entity = new BusDiscountpackageHandover(); |
|
|
|
String sid = entity.getSid(); |
|
|
|
dto.setSid(sid); |
|
|
@ -44,6 +139,275 @@ public class BusDiscountpackageHandoverService extends MybatisBaseService<BusDis |
|
|
|
busDiscountpackageHandoverListService.save(handoverList); |
|
|
|
} |
|
|
|
} |
|
|
|
this.save(entity); |
|
|
|
return this.save(entity); |
|
|
|
} |
|
|
|
|
|
|
|
public BusDiscountpackageHandoverToDoVo handover(String sid) { |
|
|
|
BusDiscountpackageHandoverToDoVo toDoVo = new BusDiscountpackageHandoverToDoVo(); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
toDoVo.setSid(sid); |
|
|
|
//根据待交接sid查询
|
|
|
|
BusDiscountpackageHandover ph = this.fetchBySid(sid); |
|
|
|
if (null != ph) { |
|
|
|
if (StringUtils.isNotBlank(ph.getContractNo())) { |
|
|
|
toDoVo.setContractNo(ph.getContractNo()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getCustomerName())) { |
|
|
|
toDoVo.setCustomerName(ph.getCustomerName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getVehModel())) { |
|
|
|
toDoVo.setVehModel(ph.getVehModel()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getVehCount())) { |
|
|
|
toDoVo.setVehCount(ph.getVehCount()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getVins())) { |
|
|
|
String vins = ph.getVins(); |
|
|
|
String[] split = vins.split(","); |
|
|
|
for (String s : split) { |
|
|
|
String vinNo = ""; |
|
|
|
if (s.length() > 8) { |
|
|
|
vinNo = s.substring(s.length() - 8); |
|
|
|
} else { |
|
|
|
vinNo = s; |
|
|
|
} |
|
|
|
sb.append(vinNo).append(","); |
|
|
|
} |
|
|
|
sb.delete(sb.length() - 1, sb.length()); |
|
|
|
toDoVo.setVinNo(sb.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
List<BusDiscountpackageHandoverListVo> listVos = this.returnHandoverListVo(sid); |
|
|
|
toDoVo.setBusDiscountpackageHandoverLists(listVos); |
|
|
|
return toDoVo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 交接操作 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @return |
|
|
|
* @throws ParseException |
|
|
|
*/ |
|
|
|
public int toDohandover(BusDiscountpackageHandoverDto dto) throws ParseException { |
|
|
|
String sid = dto.getSid(); |
|
|
|
String userSid = dto.getUserSid(); |
|
|
|
//根据当前用户sid查询用户角色
|
|
|
|
List<SysRoleVo> roleVoList = sysRoleFeign.fetchByUserSid(userSid).getData(); |
|
|
|
//判断当前登录用户角色是否为销售专员
|
|
|
|
if (null != roleVoList) { |
|
|
|
for (SysRoleVo sysRoleVo : roleVoList) { |
|
|
|
//如果当前登录用户角色包含分公司销售专员,将当前用户sid保存到查询条件中
|
|
|
|
if ("分公司销售专员".equals(sysRoleVo.getName())) { |
|
|
|
dto.setState("3"); |
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss"); |
|
|
|
String currentTime = simpleDateFormat.format(System.currentTimeMillis()); |
|
|
|
Date currentDate = simpleDateFormat.parse(currentTime); |
|
|
|
dto.setRecTime(currentDate); |
|
|
|
List<BusFileDto> busFiles = dto.getBusFiles(); |
|
|
|
if (null != busFiles) { |
|
|
|
uploadPicture(busFiles, sid); |
|
|
|
} |
|
|
|
} else { |
|
|
|
dto.setState("2"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
int i = this.updateBySid(dto.toMap(), sid); |
|
|
|
List<BusDiscountpackageHandoverListDto> listDtos = dto.getBusDiscountpackageHandoverLists(); |
|
|
|
for (BusDiscountpackageHandoverListDto listDto : listDtos) { |
|
|
|
String listDtoSid = listDto.getSid(); |
|
|
|
//判断当前登录用户角色是否为销售专员
|
|
|
|
if (null != roleVoList) { |
|
|
|
for (SysRoleVo sysRoleVo : roleVoList) { |
|
|
|
//如果当前登录用户角色包含分公司销售专员,将当前用户sid保存到查询条件中
|
|
|
|
if ("分公司销售专员".equals(sysRoleVo.getName())) { |
|
|
|
listDto.setState("3"); |
|
|
|
} else { |
|
|
|
listDto.setState("2"); |
|
|
|
} |
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss"); |
|
|
|
String currentTime = simpleDateFormat.format(System.currentTimeMillis()); |
|
|
|
Date currentDate = simpleDateFormat.parse(currentTime); |
|
|
|
listDto.setModifyTime(currentDate); |
|
|
|
busDiscountpackageHandoverListService.updateStateBySid(listDto.getState(), listDto.getModifyTime(), listDtoSid); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return i; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public BusDiscountpackageHandoverDetailsVo handoverDetails(String sid) { |
|
|
|
|
|
|
|
BusDiscountpackageHandoverDetailsVo detailsVo = new BusDiscountpackageHandoverDetailsVo(); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
//根据待交接sid查询
|
|
|
|
BusDiscountpackageHandover ph = this.fetchBySid(sid); |
|
|
|
if (null != ph) { |
|
|
|
if (StringUtils.isNotBlank(ph.getContractNo())) { |
|
|
|
detailsVo.setContractNo(ph.getContractNo()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getVins())) { |
|
|
|
String vins = ph.getVins(); |
|
|
|
String[] split = vins.split(","); |
|
|
|
for (String s : split) { |
|
|
|
String vinNo = ""; |
|
|
|
if (s.length() > 8) { |
|
|
|
vinNo = s.substring(s.length() - 8); |
|
|
|
} else { |
|
|
|
vinNo = s; |
|
|
|
} |
|
|
|
sb.append(vinNo).append(","); |
|
|
|
} |
|
|
|
sb.delete(sb.length() - 1, sb.length()); |
|
|
|
detailsVo.setVinNo(sb.toString()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getCustomerName())) { |
|
|
|
detailsVo.setCustomerName(ph.getCustomerName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getVehModel())) { |
|
|
|
detailsVo.setVehModel(ph.getVehModel()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getVehCount())) { |
|
|
|
detailsVo.setVehCount(ph.getVehCount()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getRecName())) { |
|
|
|
detailsVo.setRecName(ph.getRecName()); |
|
|
|
} |
|
|
|
if (null != ph.getRecTime()) { |
|
|
|
detailsVo.setRecTime(ph.getRecTime()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getRecPhone())) { |
|
|
|
detailsVo.setRecPhone(ph.getRecPhone()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(ph.getRemarks())) { |
|
|
|
detailsVo.setRemarks(ph.getRemarks()); |
|
|
|
} |
|
|
|
} |
|
|
|
List<BusDiscountpackageHandoverListVo> listVos = this.returnHandoverListVo(sid); |
|
|
|
detailsVo.setBusDiscountpackageHandoverLists(listVos); |
|
|
|
return detailsVo; |
|
|
|
} |
|
|
|
|
|
|
|
//根据sid查询优惠包列表
|
|
|
|
private List<BusDiscountpackageHandoverListVo> returnHandoverListVo(String sid) { |
|
|
|
//定义序号
|
|
|
|
int i = 1; |
|
|
|
List<BusDiscountpackageHandoverListVo> listVos = new ArrayList<>(); |
|
|
|
List<BusDiscountpackageHandoverList> listByMainSid = busDiscountpackageHandoverListService.findListByMainSid(sid); |
|
|
|
if (null != listByMainSid) { |
|
|
|
for (BusDiscountpackageHandoverList handoverList : listByMainSid) { |
|
|
|
BusDiscountpackageHandoverListVo listVo = new BusDiscountpackageHandoverListVo(); |
|
|
|
if (StringUtils.isNotBlank(handoverList.getSid())) { |
|
|
|
listVo.setSid(handoverList.getSid()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(handoverList.getDiscountName())) { |
|
|
|
listVo.setDiscountName(handoverList.getDiscountName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(String.valueOf(handoverList.getPrice()))) { |
|
|
|
listVo.setPrice(handoverList.getPrice()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(handoverList.getNumber())) { |
|
|
|
listVo.setNumber(handoverList.getNumber()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(String.valueOf(handoverList.getTotalPrice()))) { |
|
|
|
listVo.setTotalPrice(handoverList.getTotalPrice()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(handoverList.getExplain())) { |
|
|
|
listVo.setExplain(handoverList.getExplain()); |
|
|
|
} |
|
|
|
listVo.setSNo(i++); |
|
|
|
listVos.add(listVo); |
|
|
|
} |
|
|
|
} |
|
|
|
return listVos; |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<String> createPdf(List<String> sids) throws Exception { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String path = ""; |
|
|
|
String filePath = "/template/"; |
|
|
|
List<File> fileList = new ArrayList<>(); |
|
|
|
//根据获得的sid查询交接确认数据
|
|
|
|
for (String sid : sids) { |
|
|
|
BusDiscountpackageHandoverDetailsVo detailsVo = this.handoverDetails(sid); |
|
|
|
String s = commonCreatePdf(detailsVo); |
|
|
|
File file = new File(s); |
|
|
|
fileList.add(file); |
|
|
|
} |
|
|
|
String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
|
|
|
long seconds = System.currentTimeMillis(); |
|
|
|
String targetPath = docPdfComponent.getUploadTemplateUrl(); |
|
|
|
File file = WordConvertUtils.mulFile2One(fileList, targetPath + "优惠包交接确认单" + dateStr + seconds + ".pdf"); |
|
|
|
if (fileList.size() <= 0) { |
|
|
|
path = null; |
|
|
|
} else { |
|
|
|
for (File fileDelete : fileList) { |
|
|
|
fileDelete.delete(); |
|
|
|
} |
|
|
|
path = filePath + "优惠包交接确认单" + dateStr + seconds + ".pdf"; |
|
|
|
} |
|
|
|
return rb.success().setData(path); |
|
|
|
} |
|
|
|
|
|
|
|
public String commonCreatePdf(BusDiscountpackageHandoverDetailsVo pdfVo) { |
|
|
|
|
|
|
|
Map<String, Object> dataMap = new HashMap<String, Object>(); |
|
|
|
List<BusDiscountpackageHandoverListVo> handoverLists = pdfVo.getBusDiscountpackageHandoverLists(); |
|
|
|
List<Map<String, Object>> newList = new ArrayList<>(); |
|
|
|
dataMap.put("customerName", pdfVo.getCustomerName()); |
|
|
|
dataMap.put("vehCount", pdfVo.getVehCount()); |
|
|
|
dataMap.put("contractNo", pdfVo.getContractNo()); |
|
|
|
dataMap.put("recPhone", pdfVo.getRecPhone()); |
|
|
|
dataMap.put("vehModel", pdfVo.getVehModel()); |
|
|
|
dataMap.put("vinNo", pdfVo.getVinNo()); |
|
|
|
dataMap.put("remarks", pdfVo.getRemarks()); |
|
|
|
if (null != handoverLists) { |
|
|
|
for (BusDiscountpackageHandoverListVo handoverList : handoverLists) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("sNo", handoverList.getSNo()); |
|
|
|
map.put("discountName", handoverList.getDiscountName()); |
|
|
|
map.put("explain", handoverList.getExplain()); |
|
|
|
map.put("number", handoverList.getNumber()); |
|
|
|
newList.add(map); |
|
|
|
} |
|
|
|
} |
|
|
|
dataMap.put("newList", newList); |
|
|
|
//获取模板
|
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ftl/discountPackage.ftl"); |
|
|
|
//生成word文件名
|
|
|
|
String targetPath = docPdfComponent.getUploadTemplateUrl(); |
|
|
|
String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); |
|
|
|
long seconds = System.currentTimeMillis(); |
|
|
|
String typeName = dateStr + seconds + ".doc"; |
|
|
|
File file = new File(targetPath + "discountPackage" + seconds + ".ftl"); |
|
|
|
File dir = new File(targetPath); |
|
|
|
WordConvertUtils.inputStreamToFile(inputStream, file); |
|
|
|
WordConvertUtils.creatWord1(dataMap, file, targetPath, typeName, dir); |
|
|
|
//新生成的word路径
|
|
|
|
String wordPath = targetPath + typeName; |
|
|
|
String pdfName = "优惠包交接确认单" + dateStr + seconds + ".pdf"; |
|
|
|
WordConvertUtils.doc2pdf(wordPath, targetPath, pdfName); |
|
|
|
String path = targetPath + pdfName; |
|
|
|
return path; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean uploadPicture(List<BusFileDto> fileDtos, String sid) { |
|
|
|
boolean isSuccess = false; |
|
|
|
BusDiscountpackageHandover bh = this.fetchById(sid); |
|
|
|
if (null != fileDtos) { |
|
|
|
for (BusFileDto busFile : fileDtos) { |
|
|
|
BusFile bf = new BusFile(); |
|
|
|
busFile.setLinkSid(sid); |
|
|
|
String urlPrefix = fileUploadComponent.getUrlPrefix(); |
|
|
|
String[] split = busFile.getFilePath().split(urlPrefix); |
|
|
|
busFile.setFilePath(split[1]); |
|
|
|
busFile.setName(bh.getRecName()); |
|
|
|
busFile.fillEntity(bf); |
|
|
|
isSuccess = busFileService.save(bf); |
|
|
|
} |
|
|
|
} |
|
|
|
return isSuccess; |
|
|
|
} |
|
|
|
} |
|
|
|