|
|
@ -26,7 +26,9 @@ |
|
|
|
package com.yxt.sms.biz.smssalesreturn; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.yxt.sms.biz.smssalesbill.*; |
|
|
@ -36,15 +38,31 @@ import com.yxt.sms.biz.smssalesbillinvoice.SmsSalesBillInvoice; |
|
|
|
import com.yxt.sms.biz.smssalesbillinvoice.SmsSalesBillInvoiceService; |
|
|
|
import com.yxt.sms.biz.smssalesbillsettle.SmsSalesBillSettle; |
|
|
|
import com.yxt.sms.biz.smssalesbillsettle.SmsSalesBillSettleService; |
|
|
|
import com.yxt.sms.biz.smssalesreturn.flowable.*; |
|
|
|
import com.yxt.sms.biz.smssalesreturndetail.SmsSalesReturnDetail; |
|
|
|
import com.yxt.sms.biz.smssalesreturndetail.SmsSalesReturnDetailService; |
|
|
|
import com.yxt.sms.biz.smssalesreturnsettle.SmsSalesReturnSettle; |
|
|
|
import com.yxt.sms.biz.smssalesreturnsettle.SmsSalesReturnSettleService; |
|
|
|
import com.yxt.sms.feign.as.asbusrepairbill.*; |
|
|
|
import com.yxt.sms.feign.flowable.flow.*; |
|
|
|
import com.yxt.sms.feign.flowable.flow2.FlowDelegateQuery; |
|
|
|
import com.yxt.sms.feign.flowable.flow2.FlowFeign; |
|
|
|
import com.yxt.sms.feign.flowable.flowtask.FlowTaskFeign; |
|
|
|
import com.yxt.sms.feign.flowable.flowtask.FlowTaskVo; |
|
|
|
import com.yxt.sms.feign.flowable.flowtask.LatestTaskVo; |
|
|
|
import com.yxt.sms.feign.fms.fmspaysettle.FmsPaysettleDto; |
|
|
|
import com.yxt.sms.feign.fms.fmspaysettle.FmsPaysettleFeign; |
|
|
|
import com.yxt.sms.feign.message.MessageFeign; |
|
|
|
import com.yxt.sms.feign.message.MessageFlowVo; |
|
|
|
import com.yxt.sms.feign.message.MessageFlowableQuery; |
|
|
|
import com.yxt.sms.feign.portal.sysorganization.SysOrganizationFeign; |
|
|
|
import com.yxt.sms.feign.portal.sysorganization.SysOrganizationVo; |
|
|
|
import com.yxt.sms.feign.privilege.PrivilegeQuery; |
|
|
|
import com.yxt.sms.feign.sysuser.SysUserFeign; |
|
|
|
import com.yxt.sms.feign.wms.wmsinventory.WmsInventoryFeign; |
|
|
|
import com.yxt.sms.feign.wms.wmsinventory.WmsUpdateCountQuery; |
|
|
|
import com.yxt.sms.utils.SmsBillNo; |
|
|
|
import com.yxt.sms.utils.SmsRule; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
|
import com.yxt.common.base.utils.PagerUtil; |
|
|
@ -59,8 +77,8 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* Project: sms(sms) <br/> |
|
|
@ -96,24 +114,36 @@ public class SmsSalesReturnService extends MybatisBaseService<SmsSalesReturnMapp |
|
|
|
private FmsPaysettleFeign fmsPaysettleFeign; |
|
|
|
@Autowired |
|
|
|
private AsBusrepairBillFeign asBusrepairBillFeign; |
|
|
|
@Autowired |
|
|
|
private SysOrganizationFeign sysOrganizationFeign; |
|
|
|
@Autowired |
|
|
|
private SysUserFeign sysUserFeign; |
|
|
|
@Autowired |
|
|
|
private FlowableFeign flowableFeign; |
|
|
|
@Autowired |
|
|
|
private FlowTaskFeign flowTaskFeign; |
|
|
|
@Autowired |
|
|
|
private FlowFeign flowFeign; |
|
|
|
@Autowired |
|
|
|
private MessageFeign messageFeign; |
|
|
|
|
|
|
|
private QueryWrapper<SmsSalesReturn> createQueryWrapper(SmsSalesReturnQuery query) { |
|
|
|
// todo: 这里根据具体业务调整查询条件
|
|
|
|
// 多字段Like示例:qw.and(wrapper -> wrapper.like("name", query.getName()).or().like("remark", query.getName()));
|
|
|
|
QueryWrapper<SmsSalesReturn> qw = new QueryWrapper<>(); |
|
|
|
if (StringUtils.isNotBlank(query.getQueryName())) { |
|
|
|
qw.and(wrapper -> wrapper.like("r.createByName", query.getQueryName()) |
|
|
|
.or().like("r.billNo", query.getQueryName()) |
|
|
|
.or().like("b.salesName", query.getQueryName()) |
|
|
|
.or().like("b.customerName", query.getQueryName()) |
|
|
|
.or().like("b.mobile", query.getQueryName()) |
|
|
|
.or().like("b.vehMark", query.getQueryName()) |
|
|
|
.or().like("r.sourceBillNo", query.getQueryName()) |
|
|
|
); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getUseOrgSid())) { |
|
|
|
qw.eq("r.useOrgSid", query.getUseOrgSid()); |
|
|
|
} |
|
|
|
// if (StringUtils.isNotBlank(query.getQueryName())) {
|
|
|
|
// qw.and(wrapper -> wrapper.like("r.createByName", query.getQueryName())
|
|
|
|
// .or().like("r.billNo", query.getQueryName())
|
|
|
|
// .or().like("b.salesName", query.getQueryName())
|
|
|
|
// .or().like("b.customerName", query.getQueryName())
|
|
|
|
// .or().like("b.mobile", query.getQueryName())
|
|
|
|
// .or().like("b.vehMark", query.getQueryName())
|
|
|
|
// .or().like("r.sourceBillNo", query.getQueryName())
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// if (StringUtils.isNotBlank(query.getUseOrgSid())) {
|
|
|
|
// qw.eq("r.useOrgSid", query.getUseOrgSid());
|
|
|
|
// }
|
|
|
|
String startDate = query.getStartDate(); |
|
|
|
String endDate = query.getEndDate(); |
|
|
|
qw.apply(StringUtils.isNotEmpty(startDate), "date_format (r.createTime,'%Y-%m-%d') >= date_format('" + startDate + "','%Y-%m-%d')"). |
|
|
@ -126,9 +156,69 @@ public class SmsSalesReturnService extends MybatisBaseService<SmsSalesReturnMapp |
|
|
|
|
|
|
|
public PagerVo<SmsSalesReturnVo> listPageVo(PagerQuery<SmsSalesReturnQuery> pq) { |
|
|
|
SmsSalesReturnQuery query = pq.getParams(); |
|
|
|
QueryWrapper<SmsSalesReturn> qw = createQueryWrapper(query); |
|
|
|
QueryWrapper<SmsSalesReturn> qw = new QueryWrapper<>(); |
|
|
|
if (StringUtils.isNotBlank(query.getMenuUrl())) { |
|
|
|
PrivilegeQuery privilegeQuery = new PrivilegeQuery(); |
|
|
|
privilegeQuery.setOrgPath(query.getOrgPath()); |
|
|
|
privilegeQuery.setMenuUrl(query.getMenuUrl()); |
|
|
|
privilegeQuery.setUserSid(query.getUserSid()); |
|
|
|
ResultBean<String> defaultIdReltBean = sysUserFeign.selectPrivilegeLevel(privilegeQuery); |
|
|
|
if (StringUtils.isNotBlank(defaultIdReltBean.getData())) { |
|
|
|
//数据权限ID(1集团、2事业部、3分公司、4部门、5个人)
|
|
|
|
String orgSidPath = query.getOrgPath(); |
|
|
|
orgSidPath = orgSidPath + "/"; |
|
|
|
int i1 = orgSidPath.indexOf("/"); |
|
|
|
int i2 = orgSidPath.indexOf("/", i1 + 1); |
|
|
|
int i3 = orgSidPath.indexOf("/", i2 + 1); |
|
|
|
int i4 = orgSidPath.indexOf("/", i3 + 1); |
|
|
|
String orgLevelKey = defaultIdReltBean.getData(); |
|
|
|
if ("1".equals(orgLevelKey)) { |
|
|
|
orgSidPath = orgSidPath.substring(0, i1); |
|
|
|
qw.like("so.orgSidPath", orgSidPath); |
|
|
|
} else if ("2".equals(orgLevelKey)) { |
|
|
|
orgSidPath = orgSidPath.substring(0, i2); |
|
|
|
qw.like("so.orgSidPath", orgSidPath); |
|
|
|
} else if ("3".equals(orgLevelKey)) { |
|
|
|
orgSidPath = orgSidPath.substring(0, i3); |
|
|
|
qw.like("so.orgSidPath", orgSidPath); |
|
|
|
} else if ("4".equals(orgLevelKey)) { |
|
|
|
orgSidPath = orgSidPath.substring(0, i4); |
|
|
|
qw.like("so.orgSidPath", orgSidPath); |
|
|
|
} else if ("5".equals(orgLevelKey)) { |
|
|
|
qw.eq("s.createBySid", query.getUserSid()); |
|
|
|
} else { |
|
|
|
PagerVo<SmsSalesReturnVo> p = new PagerVo<>(); |
|
|
|
return p; |
|
|
|
} |
|
|
|
} else { |
|
|
|
PagerVo<SmsSalesReturnVo> p = new PagerVo<>(); |
|
|
|
return p; |
|
|
|
} |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getUseOrgName())) { |
|
|
|
qw.like("s.useOrgName", query.getUseOrgName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getDeptName())) { |
|
|
|
qw.like("s.deptName", query.getDeptName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getCreateByName())) { |
|
|
|
qw.like("s.createByName", query.getCreateByName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(query.getBillNo())) { |
|
|
|
qw.like("s.billNo", query.getBillNo()); |
|
|
|
} |
|
|
|
String startDate = query.getStartDate(); |
|
|
|
String endDate = query.getStartDate(); |
|
|
|
qw.apply(StringUtils.isNotEmpty(startDate), "date_format (s.createTime,'%Y-%m-%d') >= date_format('" + startDate + "','%Y-%m-%d')"). |
|
|
|
apply(StringUtils.isNotEmpty(endDate), "date_format (s.createTime,'%Y-%m-%d') <= date_format('" + endDate + "','%Y-%m-%d')" |
|
|
|
); |
|
|
|
String closeDateStart = query.getColesStartDate(); |
|
|
|
String closeDateEnd = query.getColesEndDate(); |
|
|
|
qw.apply(StringUtils.isNotEmpty(closeDateStart), "date_format (s.closeDate,'%Y-%m-%d') >= date_format('" + closeDateStart + "','%Y-%m-%d')"). |
|
|
|
apply(StringUtils.isNotEmpty(closeDateEnd), "date_format (s.closeDate,'%Y-%m-%') <= date_format('" + closeDateEnd + "','%Y-%m-%d')" |
|
|
|
); |
|
|
|
IPage<SmsSalesReturn> page = PagerUtil.queryToPage(pq); |
|
|
|
IPage<SmsSalesReturnVo> pagging = baseMapper.selectPageVo(page, qw); |
|
|
|
IPage<SmsSalesReturnVo> pagging = baseMapper.listPage(page, qw); |
|
|
|
PagerVo<SmsSalesReturnVo> p = PagerUtil.pageToVo(pagging, null); |
|
|
|
return p; |
|
|
|
} |
|
|
@ -407,7 +497,7 @@ public class SmsSalesReturnService extends MybatisBaseService<SmsSalesReturnMapp |
|
|
|
if (!sitemVos.isEmpty()) { |
|
|
|
for (SitemVo smsSitemVo : sitemVos) { |
|
|
|
SmsSitemVo sitemVo = new SmsSitemVo(); |
|
|
|
BeanUtil.copyProperties(smsSitemVo,sitemVo); |
|
|
|
BeanUtil.copyProperties(smsSitemVo, sitemVo); |
|
|
|
smsSitemVos.add(sitemVo); |
|
|
|
} |
|
|
|
vo.setSitemVos(smsSitemVos); |
|
|
@ -417,7 +507,11 @@ public class SmsSalesReturnService extends MybatisBaseService<SmsSalesReturnMapp |
|
|
|
if (!goodsDetailsVos.isEmpty()) { |
|
|
|
for (GoodsDetailsVo goodsDetailsVo : goodsDetailsVos) { |
|
|
|
SmsGoodsDetailsVo smsGoodsDetailsVo = new SmsGoodsDetailsVo(); |
|
|
|
BeanUtil.copyProperties(goodsDetailsVo,smsGoodsDetailsVo); |
|
|
|
BeanUtil.copyProperties(goodsDetailsVo, smsGoodsDetailsVo); |
|
|
|
//查询已退数量
|
|
|
|
String goodsID = goodsDetailsVo.getGoodsID(); |
|
|
|
String sumBackCount = baseMapper.selBackCountByGoodsID(goodsID, sid); |
|
|
|
smsGoodsDetailsVo.setReturnedCount(sumBackCount); |
|
|
|
smsGoodsDetailsVos.add(smsGoodsDetailsVo); |
|
|
|
} |
|
|
|
vo.setGoodsDetailsVos(smsGoodsDetailsVos); |
|
|
@ -460,7 +554,12 @@ public class SmsSalesReturnService extends MybatisBaseService<SmsSalesReturnMapp |
|
|
|
if (!goodsDetailsVos.isEmpty()) { |
|
|
|
for (SalesGoodsVo goodsDetailsVo : goodsDetailsVos) { |
|
|
|
SmsGoodsDetailsVo smsGoodsDetailsVo = new SmsGoodsDetailsVo(); |
|
|
|
BeanUtil.copyProperties(goodsDetailsVo,smsGoodsDetailsVo); |
|
|
|
BeanUtil.copyProperties(goodsDetailsVo, smsGoodsDetailsVo); |
|
|
|
//查询已退数量
|
|
|
|
String goodsID = goodsDetailsVo.getGoodsID(); |
|
|
|
String sumBackCount = baseMapper.selBackCountByGoodsID(goodsID, sid); |
|
|
|
smsGoodsDetailsVo.setReturnedCount(sumBackCount); |
|
|
|
smsGoodsDetailsVos.add(smsGoodsDetailsVo); |
|
|
|
smsGoodsDetailsVos.add(smsGoodsDetailsVo); |
|
|
|
} |
|
|
|
vo.setGoodsDetailsVos(smsGoodsDetailsVos); |
|
|
@ -470,4 +569,517 @@ public class SmsSalesReturnService extends MybatisBaseService<SmsSalesReturnMapp |
|
|
|
} |
|
|
|
return vo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成单据编号 |
|
|
|
* |
|
|
|
* @param orgSid |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String getApplyCode(String orgSid) { |
|
|
|
//获取分公司sid
|
|
|
|
ResultBean<SysOrganizationVo> resultBean1 = sysOrganizationFeign.fetchBySid(orgSid); |
|
|
|
String orgCode = resultBean1.getData().getOrgCode(); |
|
|
|
SmsBillNo b = new SmsBillNo(); |
|
|
|
b.setOrgCode(orgCode); |
|
|
|
b.setBillType("THD"); |
|
|
|
String bill = SmsRule.getBill(b); |
|
|
|
int i = baseMapper.selectNum(bill); |
|
|
|
String billNo = SmsRule.getBillNo(bill, i); |
|
|
|
return billNo; |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<String> saveBill(SmsSalesReturnNewDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String sid = ""; |
|
|
|
List<SalesGoodsReturnVo> goodsVos = dto.getReturnGoods(); |
|
|
|
if (!goodsVos.isEmpty()) { |
|
|
|
for (SalesGoodsReturnVo goodsVo : goodsVos) { |
|
|
|
BigDecimal reCount = new BigDecimal(goodsVo.getReturnedCount()); //已退数量
|
|
|
|
BigDecimal backCount = new BigDecimal(goodsVo.getBackCount()); //退货数量
|
|
|
|
BigDecimal add = reCount.add(backCount); |
|
|
|
BigDecimal currentCount = new BigDecimal(goodsVo.getCurrentCount()); //总数量
|
|
|
|
if (add.compareTo(currentCount) > 0) { |
|
|
|
return rb.setMsg("退货数量不能大于总数量"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(dto.getSid())) { |
|
|
|
sid = dto.getSid(); |
|
|
|
SmsSalesReturn smsSalesReturn = fetchBySid(sid); |
|
|
|
BeanUtil.copyProperties(dto, smsSalesReturn, "id", "sid"); |
|
|
|
baseMapper.updateById(smsSalesReturn); |
|
|
|
smsSalesReturnDetailService.deleteByMainSid(sid); |
|
|
|
} else { |
|
|
|
SmsSalesReturn entity = new SmsSalesReturn(); |
|
|
|
sid = entity.getSid(); |
|
|
|
BeanUtil.copyProperties(dto, entity, "id", "sid"); |
|
|
|
String applyCode = getApplyCode(dto.getCreateOrgSid()); |
|
|
|
entity.setBillNo(applyCode); |
|
|
|
entity.setNodeState("待提交"); |
|
|
|
baseMapper.insert(entity); |
|
|
|
} |
|
|
|
List<SalesGoodsReturnVo> returnGoods = dto.getReturnGoods(); |
|
|
|
if (!returnGoods.isEmpty()) { |
|
|
|
for (SalesGoodsReturnVo returnGood : returnGoods) { |
|
|
|
SmsSalesReturnDetail detail = new SmsSalesReturnDetail(); |
|
|
|
BeanUtil.copyProperties(returnGood, detail, "id", "sid"); |
|
|
|
detail.setBillSid(sid); |
|
|
|
smsSalesReturnDetailService.insert(detail); |
|
|
|
} |
|
|
|
} |
|
|
|
return rb.success().setData(sid); |
|
|
|
} |
|
|
|
|
|
|
|
public SmsSalesReturnNewDetailsVo fetchNewDetailsVoBySid(String sid) { |
|
|
|
SmsSalesReturnNewDetailsVo vo = new SmsSalesReturnNewDetailsVo(); |
|
|
|
SmsSalesReturn smsSalesReturn = fetchBySid(sid); |
|
|
|
if (null != smsSalesReturn) { |
|
|
|
BeanUtil.copyProperties(smsSalesReturn, vo); |
|
|
|
Integer type = smsSalesReturn.getType(); |
|
|
|
vo.setCreateTime(DateUtil.formatDate(smsSalesReturn.getCreateTime())); |
|
|
|
if (StringUtils.isNotBlank(smsSalesReturn.getProcInstId())) { |
|
|
|
vo.setInstanceId(smsSalesReturn.getProcInstId()); |
|
|
|
} |
|
|
|
if (type == 0) { |
|
|
|
//维修工单
|
|
|
|
AsBusrepairBillDetailsVo data = asBusrepairBillFeign.fetchDetailsBySid(smsSalesReturn.getSourceBillSid()).getData(); |
|
|
|
if (null != data) { |
|
|
|
vo.setSourceBillNo(data.getBillNo()); |
|
|
|
vo.setBillType(data.getBillType()); |
|
|
|
vo.setBillDate(data.getCreateDate()); |
|
|
|
if (StringUtils.isNotBlank(data.getSubject())) { |
|
|
|
vo.setSubject(data.getSubject()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getWaitorName())) { |
|
|
|
vo.setWaitorName(data.getWaitorName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getCustomerName())) { |
|
|
|
vo.setCustomerName(data.getCustomerName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getMobile())) { |
|
|
|
vo.setMobile(data.getMobile()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getCustomerOrg())) { |
|
|
|
vo.setCustomerOrg(data.getCustomerOrg()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getVehMark())) { |
|
|
|
vo.setVehMark(data.getVehMark()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getVinNo())) { |
|
|
|
vo.setVinNo(data.getVinNo()); |
|
|
|
} |
|
|
|
SettleVo settleVo = data.getSettleVo(); |
|
|
|
if (null != settleVo) { |
|
|
|
vo.setSettleDate(settleVo.getSettleTime()); |
|
|
|
} |
|
|
|
List<SitemVo> sitemVos = data.getSitemVos(); |
|
|
|
List<SmsSitemVo> smsSitemVos = new ArrayList<>(); |
|
|
|
if (!sitemVos.isEmpty()) { |
|
|
|
for (SitemVo smsSitemVo : sitemVos) { |
|
|
|
SmsSitemVo sitemVo = new SmsSitemVo(); |
|
|
|
BeanUtil.copyProperties(smsSitemVo, sitemVo); |
|
|
|
smsSitemVos.add(sitemVo); |
|
|
|
} |
|
|
|
vo.setSitemVos(smsSitemVos); |
|
|
|
} |
|
|
|
List<GoodsDetailsVo> goodsDetailsVos = data.getGoodsDetailsVos(); |
|
|
|
List<SmsGoodsDetailsVo> smsGoodsDetailsVos = new ArrayList<>(); |
|
|
|
if (!goodsDetailsVos.isEmpty()) { |
|
|
|
for (GoodsDetailsVo goodsDetailsVo : goodsDetailsVos) { |
|
|
|
SmsGoodsDetailsVo smsGoodsDetailsVo = new SmsGoodsDetailsVo(); |
|
|
|
BeanUtil.copyProperties(goodsDetailsVo, smsGoodsDetailsVo); |
|
|
|
//查询已退数量
|
|
|
|
String goodsID = goodsDetailsVo.getGoodsID(); |
|
|
|
String sumBackCount = baseMapper.selBackCountByGoodsID(goodsID, sid); |
|
|
|
smsGoodsDetailsVo.setReturnedCount(sumBackCount); |
|
|
|
smsGoodsDetailsVos.add(smsGoodsDetailsVo); |
|
|
|
} |
|
|
|
vo.setGoodsDetailsVos(smsGoodsDetailsVos); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (type == 1) { |
|
|
|
//销售单
|
|
|
|
SmsSalesBillDetailsVo data = smsSalesBillService.fetchDetailsVoBySid(smsSalesReturn.getSourceBillSid()); |
|
|
|
if (null != data) { |
|
|
|
vo.setSourceBillNo(data.getBillNo()); |
|
|
|
vo.setBillType("销售单"); |
|
|
|
vo.setBillDate(data.getCreateTime()); |
|
|
|
if (StringUtils.isNotBlank(data.getSubject())) { |
|
|
|
vo.setSubject(data.getSubject()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getSalesName())) { |
|
|
|
vo.setWaitorName(data.getSalesName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getCustomerName())) { |
|
|
|
vo.setCustomerName(data.getCustomerName()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getMobile())) { |
|
|
|
vo.setMobile(data.getMobile()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getCustomerOrg())) { |
|
|
|
vo.setCustomerOrg(data.getCustomerOrg()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getVehMark())) { |
|
|
|
vo.setVehMark(data.getVehMark()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(data.getVinNo())) { |
|
|
|
vo.setVinNo(data.getVinNo()); |
|
|
|
} |
|
|
|
SettlementVo settleVo = data.getSettlementVo(); |
|
|
|
if (null != settleVo) { |
|
|
|
vo.setSettleDate(settleVo.getSettleTime()); |
|
|
|
} |
|
|
|
List<SalesGoodsVo> goodsDetailsVos = data.getGoodsVos(); |
|
|
|
List<SmsGoodsDetailsVo> smsGoodsDetailsVos = new ArrayList<>(); |
|
|
|
if (!goodsDetailsVos.isEmpty()) { |
|
|
|
for (SalesGoodsVo goodsDetailsVo : goodsDetailsVos) { |
|
|
|
SmsGoodsDetailsVo smsGoodsDetailsVo = new SmsGoodsDetailsVo(); |
|
|
|
BeanUtil.copyProperties(goodsDetailsVo, smsGoodsDetailsVo); |
|
|
|
//查询已退数量
|
|
|
|
String goodsID = goodsDetailsVo.getGoodsID(); |
|
|
|
String sumBackCount = baseMapper.selBackCountByGoodsID(goodsID, sid); |
|
|
|
smsGoodsDetailsVo.setReturnedCount(sumBackCount); |
|
|
|
smsGoodsDetailsVos.add(smsGoodsDetailsVo); |
|
|
|
smsGoodsDetailsVos.add(smsGoodsDetailsVo); |
|
|
|
} |
|
|
|
vo.setGoodsDetailsVos(smsGoodsDetailsVos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
List<SmsSalesReturnDetail> details = smsSalesReturnDetailService.fetchByBillSid(sid); |
|
|
|
if (!details.isEmpty()) { |
|
|
|
List<SalesGoodsReturnVo> returnGoods = new ArrayList<>(); //退货商品列表
|
|
|
|
for (SmsSalesReturnDetail detail : details) { |
|
|
|
SalesGoodsReturnVo returnVo = new SalesGoodsReturnVo(); |
|
|
|
BeanUtil.copyProperties(detail, returnVo, "id", "sid"); |
|
|
|
returnGoods.add(returnVo); |
|
|
|
} |
|
|
|
vo.setReturnGoods(returnGoods); |
|
|
|
} |
|
|
|
} |
|
|
|
return vo; |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean deleteBySids(String[] sids) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
//查询该sid中是否有结算的
|
|
|
|
int count = baseMapper.selectBySid(StringUtils.join(sids, ",")); |
|
|
|
if (count > 0) { |
|
|
|
return rb.setMsg("删除的数据中包含已经提交审批的数据,删除失败"); |
|
|
|
} |
|
|
|
delBySids(sids); |
|
|
|
for (String sid : sids) { |
|
|
|
smsSalesReturnDetailService.deleteByMainSid(sid); |
|
|
|
} |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------flow----------------------------------
|
|
|
|
public ResultBean submit(SubmitSmsGoodsReturnDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
SmsSalesReturn smsSalesReturn = fetchBySid(dto.getSid()); |
|
|
|
int r = submitBusinessData(dto, smsSalesReturn); |
|
|
|
if (r == 3) { |
|
|
|
return rb.setMsg("该申请不存在"); |
|
|
|
} |
|
|
|
if (r == 0) { |
|
|
|
return rb.setMsg("操作失败!提交的数据不一致"); |
|
|
|
} |
|
|
|
//新增修改保存
|
|
|
|
ResultBean<String> resultBean = saveBill(dto); |
|
|
|
String businessSid = ""; |
|
|
|
if (resultBean.getSuccess()) { |
|
|
|
businessSid = resultBean.getData(); |
|
|
|
} else { |
|
|
|
return rb.setMsg(resultBean.getMsg()); |
|
|
|
} |
|
|
|
smsSalesReturn = fetchBySid(businessSid); |
|
|
|
//创建BusinessVariables实体对象
|
|
|
|
BusinessVariables bv = new BusinessVariables(); |
|
|
|
//流程中的参数赋值、若有网关,则赋值网关中判断的字段。
|
|
|
|
Map<String, Object> variables = new HashMap<>(); |
|
|
|
//用户的部门全路径sid
|
|
|
|
SysOrganizationVo deptVo = sysOrganizationFeign.fetchBySid(smsSalesReturn.getDeptSid()).getData(); |
|
|
|
bv.setOrgSidPath(deptVo.getOrgSidPath()); |
|
|
|
//业务sid
|
|
|
|
bv.setBusinessSid(businessSid); |
|
|
|
//用户sid
|
|
|
|
bv.setUserSid(smsSalesReturn.getCreateBySid()); |
|
|
|
//若app移动端有此功能,则传递appMap参数
|
|
|
|
Map<String, Object> appMap = new HashMap<>(); |
|
|
|
appMap.put("sid", businessSid); |
|
|
|
//需和移动端沟通业务sid保存的属性具体值:appMap中sid不是固定的。移动端提供具体字段。
|
|
|
|
variables.put("app", appMap); |
|
|
|
//流程定义id
|
|
|
|
bv.setModelId(ProcDefEnum.SMSSALESRETURN.getProDefId()); |
|
|
|
bv.setFormVariables(variables); |
|
|
|
if (r == 1) { |
|
|
|
ResultBean<UpdateFlowFieldVo> voResultBean = flowFeign.startProcess(bv); |
|
|
|
UpdateFlowFieldVo ufVo = voResultBean.getData(); |
|
|
|
updateFlowFiled(BeanUtil.beanToMap(ufVo)); |
|
|
|
//极光推送
|
|
|
|
smsSalesReturn = fetchBySid(businessSid); |
|
|
|
MessageFlowableQuery messageFlowableQuery = new MessageFlowableQuery(); |
|
|
|
MessageFlowVo messageFlowVo = new MessageFlowVo(); |
|
|
|
BeanUtil.copyProperties(ufVo, messageFlowVo); |
|
|
|
messageFlowableQuery.setUfVo(messageFlowVo); |
|
|
|
messageFlowableQuery.setAppMap(appMap); |
|
|
|
messageFlowableQuery.setBusinessSid(businessSid); |
|
|
|
messageFlowableQuery.setModuleName("商品退货申请"); |
|
|
|
messageFlowableQuery.setMsgContent(smsSalesReturn.getCreateByName() + "提交的" + messageFlowableQuery.getModuleName() + ",请审批"); |
|
|
|
messageFlowableQuery.setMsgTitle("商品退货申请"); |
|
|
|
messageFeign.pushMessage(messageFlowableQuery); |
|
|
|
return voResultBean; |
|
|
|
} |
|
|
|
if (r == 2) { |
|
|
|
// ToDo:驳回到发起人后再次提交
|
|
|
|
if (StringUtils.isBlank(dto.getInstanceId())) { |
|
|
|
return rb.setMsg("参数错误:instanceId"); |
|
|
|
} |
|
|
|
bv.setTaskId(smsSalesReturn.getTaskId()); |
|
|
|
bv.setTaskDefKey(smsSalesReturn.getNodeSid()); |
|
|
|
bv.setComment(StringUtils.isNotBlank(dto.getComment()) ? dto.getComment() : "重新提交"); |
|
|
|
bv.setInstanceId(dto.getInstanceId()); |
|
|
|
return complete(bv); |
|
|
|
} |
|
|
|
return rb; |
|
|
|
} |
|
|
|
|
|
|
|
private synchronized int submitBusinessData(SubmitSmsGoodsReturnDto dto, SmsSalesReturn smsSalesReturn) { |
|
|
|
int r = 0; |
|
|
|
if (StringUtils.isBlank(dto.getSid())) { |
|
|
|
r = 1; |
|
|
|
} else { |
|
|
|
if (smsSalesReturn != null) { |
|
|
|
String businessTaskId = smsSalesReturn.getTaskId(); |
|
|
|
if (StringUtils.isBlank(businessTaskId) && StringUtils.isBlank(dto.getTaskId())) { |
|
|
|
//新提交
|
|
|
|
r = 1; |
|
|
|
} else if (StringUtils.isNotBlank(businessTaskId) && businessTaskId.equals(dto.getTaskId())) { |
|
|
|
//二次提交//只有数据一致的时候才能进行下一步
|
|
|
|
r = 2; |
|
|
|
} |
|
|
|
} else { |
|
|
|
r = 3; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
private int updateFlowFiled(Map<String, Object> map) { |
|
|
|
return baseMapper.updateFlowFiled(map); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean complete(BusinessVariables bv) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String businessSid = bv.getBusinessSid(); |
|
|
|
SmsSalesReturn smsSalesReturn = fetchBySid(businessSid); |
|
|
|
Map<String, Object> variables = new HashMap<>(); |
|
|
|
Map<String, Object> appMap = new HashMap<>(); |
|
|
|
appMap.put("sid", businessSid); |
|
|
|
variables.put("app", appMap); |
|
|
|
FlowProcessMapQuery flowProcessMapQuery = new FlowProcessMapQuery(); |
|
|
|
if (StringUtils.isBlank(smsSalesReturn.getProcDefId())) { |
|
|
|
flowProcessMapQuery.setProDefKey(bv.getModelId()); |
|
|
|
} else { |
|
|
|
flowProcessMapQuery.setProDefKey(smsSalesReturn.getProcDefId()); |
|
|
|
} |
|
|
|
flowProcessMapQuery.setVariables(variables); |
|
|
|
variables = flowableFeign.getMap(flowProcessMapQuery).getData(); |
|
|
|
//=======================================
|
|
|
|
bv.setFormVariables(variables); |
|
|
|
SysOrganizationVo deptVo = sysOrganizationFeign.fetchBySid(smsSalesReturn.getDeptSid()).getData(); |
|
|
|
bv.setOrgSidPath(deptVo.getOrgSidPath()); |
|
|
|
if (bv.getTaskId().equals(smsSalesReturn.getTaskId())) { |
|
|
|
ResultBean<UpdateFlowFieldVo> resultBean = flowFeign.handleProsess(bv); |
|
|
|
if (!resultBean.getSuccess()) { |
|
|
|
return rb.setMsg(resultBean.getMsg()); |
|
|
|
} |
|
|
|
UpdateFlowFieldVo ufVo = resultBean.getData(); |
|
|
|
updateFlowFiled(BeanUtil.beanToMap(resultBean.getData())); |
|
|
|
if ("Event_end".equals(resultBean.getData().getTaskDefKey())) { |
|
|
|
smsSalesReturn = fetchBySid(businessSid); |
|
|
|
smsSalesReturn.setCloseDate(new Date()); |
|
|
|
baseMapper.updateById(smsSalesReturn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
//极光推送
|
|
|
|
smsSalesReturn = fetchBySid(businessSid); |
|
|
|
MessageFlowableQuery messageFlowableQuery = new MessageFlowableQuery(); |
|
|
|
MessageFlowVo messageFlowVo = new MessageFlowVo(); |
|
|
|
BeanUtil.copyProperties(ufVo, messageFlowVo); |
|
|
|
ufVo.setProcDefId(smsSalesReturn.getProcDefId()); |
|
|
|
ufVo.setProcInsId(smsSalesReturn.getProcInstId()); |
|
|
|
messageFlowableQuery.setUfVo(messageFlowVo); |
|
|
|
messageFlowableQuery.setAppMap(appMap); |
|
|
|
messageFlowableQuery.setBusinessSid(businessSid); |
|
|
|
messageFlowableQuery.setModuleName("商品退货申请"); |
|
|
|
messageFlowableQuery.setMsgContent(smsSalesReturn.getCreateByName() + "提交的" + messageFlowableQuery.getModuleName() + ",请审批"); |
|
|
|
messageFlowableQuery.setMsgTitle("商品退货申请"); |
|
|
|
messageFeign.pushMessage(messageFlowableQuery); |
|
|
|
} |
|
|
|
return rb.success().setData(resultBean.getData()); |
|
|
|
} else { |
|
|
|
return rb.setMsg("操作失败!提交的数据不一致"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<List<SmsGoodsReturnNodeVo>> getPreviousNodesForReject(SmsGoodsReturnNodeQuery query) { |
|
|
|
ResultBean<List<SmsGoodsReturnNodeVo>> rb = ResultBean.fireFail(); |
|
|
|
BusinessVariables bv = new BusinessVariables(); |
|
|
|
BeanUtil.copyProperties(query, bv); |
|
|
|
bv.setModelId(ProcDefEnum.SMSSALESRETURN.getProDefId()); |
|
|
|
ResultBean<List<Map<String, Object>>> resultBean = flowTaskFeign.getPreviousNodesForReject(bv); |
|
|
|
//判断数组是否为空,若为空则赋值,若不为空,则遍历循环将map中的数据赋值给getNodeVo
|
|
|
|
List<SmsGoodsReturnNodeVo> voList = Optional.ofNullable(resultBean.getData()).orElse(new ArrayList<>()).stream().map(m -> JSON.parseObject(JSON.toJSONString(m), SmsGoodsReturnNodeVo.class)).collect(Collectors.toList()); |
|
|
|
return rb.success().setData(voList); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<List<SmsGoodsReturnNodeVo>> getNextNodesForSubmit(SmsGoodsReturnNodeQuery query) { |
|
|
|
ResultBean<List<SmsGoodsReturnNodeVo>> rb = ResultBean.fireFail(); |
|
|
|
BusinessVariables bv = new BusinessVariables(); |
|
|
|
BeanUtil.copyProperties(query, bv); |
|
|
|
bv.setModelId(ProcDefEnum.SMSSALESRETURN.getProDefId()); |
|
|
|
ResultBean<List<Map<String, Object>>> resultBean = flowTaskFeign.getNextNodesForSubmit(bv); |
|
|
|
//判断数组是否为空,若为空则赋值,若不为空,则遍历循环将map中的数据赋值给getNodeVo
|
|
|
|
List<SmsGoodsReturnNodeVo> voList = Optional.ofNullable(resultBean.getData()).orElse(new ArrayList<>()).stream().map(m -> JSON.parseObject(JSON.toJSONString(m), SmsGoodsReturnNodeVo.class)).collect(Collectors.toList()); |
|
|
|
return rb.success().setData(voList); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean reject(SmsGoodsReturnTaskQuery query) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String businessSid = query.getBusinessSid(); |
|
|
|
SmsSalesReturn reverseSettle = fetchBySid(businessSid); |
|
|
|
if (reverseSettle == null) { |
|
|
|
return rb.setMsg("该申请不存在"); |
|
|
|
} |
|
|
|
String businessTaskId = reverseSettle.getTaskId(); |
|
|
|
if (StringUtils.isNotBlank(businessTaskId)) { |
|
|
|
if (businessTaskId.equals(query.getTaskId())) { |
|
|
|
if (StringUtils.isBlank(query.getComment())) { |
|
|
|
return rb.setMsg("请填写意见"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(query.getUserSid())) { |
|
|
|
return rb.setMsg("参数错误:userSid"); |
|
|
|
} |
|
|
|
FlowTaskVo flowTaskVo = new FlowTaskVo(); |
|
|
|
BeanUtil.copyProperties(query, flowTaskVo); |
|
|
|
Map<String, Object> variables = new HashMap<>(); |
|
|
|
Map<String, Object> appMap = new HashMap<>(); |
|
|
|
appMap.put("sid", businessSid); |
|
|
|
variables.put("app", appMap); |
|
|
|
flowTaskVo.setValues(variables); |
|
|
|
ResultBean<UpdateFlowFieldVo> resultBean = flowableFeign.taskReject(flowTaskVo); |
|
|
|
if (!resultBean.getSuccess()) { |
|
|
|
return rb.setMsg(resultBean.getMsg()); |
|
|
|
} |
|
|
|
UpdateFlowFieldVo ufVo = resultBean.getData(); |
|
|
|
Map<String, Object> map = BeanUtil.beanToMap(ufVo); |
|
|
|
//更新业务中的流程相关的参数
|
|
|
|
updateFlowFiled(map); |
|
|
|
//极光推送
|
|
|
|
reverseSettle = fetchBySid(businessSid); |
|
|
|
MessageFlowableQuery messageFlowableQuery = new MessageFlowableQuery(); |
|
|
|
MessageFlowVo messageFlowVo = new MessageFlowVo(); |
|
|
|
BeanUtil.copyProperties(ufVo, messageFlowVo); |
|
|
|
String procId = reverseSettle.getProcInstId(); |
|
|
|
ufVo.setProcInsId(procId); |
|
|
|
ufVo.setProcDefId(reverseSettle.getProcDefId()); |
|
|
|
messageFlowableQuery.setUfVo(messageFlowVo); |
|
|
|
messageFlowableQuery.setAppMap(appMap); |
|
|
|
messageFlowableQuery.setBusinessSid(businessSid); |
|
|
|
messageFlowableQuery.setModuleName("商品退货申请"); |
|
|
|
ResultBean<List<LatestTaskVo>> listResultBean = flowTaskFeign.getLatestTasks(procId); |
|
|
|
String nextNodeUserSids = listResultBean.getData().get(0).getASSIGNEE_(); |
|
|
|
List<String> receiveSidList = Arrays.asList(nextNodeUserSids.split(",")); |
|
|
|
if (receiveSidList.size() == 1 && receiveSidList.get(0).equals(reverseSettle.getCreateBySid())) { |
|
|
|
messageFlowableQuery.setMsgContent("您提交的" + messageFlowableQuery.getModuleName() + "已被驳回,请重新提交"); |
|
|
|
} else { |
|
|
|
messageFlowableQuery.setMsgContent(reverseSettle.getCreateByName() + "提交的" + messageFlowableQuery.getModuleName() + ",请审批"); |
|
|
|
} |
|
|
|
messageFlowableQuery.setMsgTitle("商品退货申请"); |
|
|
|
messageFeign.pushMessage(messageFlowableQuery); |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
} |
|
|
|
return rb.setMsg("操作失败!提交的数据不一致!"); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean revokeProcess(SmsGoodsReturnTaskQuery query) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
if (StringUtils.isBlank(query.getUserSid())) { |
|
|
|
return rb.setMsg("参数错误:userSid"); |
|
|
|
} |
|
|
|
SmsSalesReturn smsSalesReturn = fetchBySid(query.getBusinessSid()); |
|
|
|
String businessTaskId = smsSalesReturn.getTaskId(); |
|
|
|
if (StringUtils.isNotBlank(businessTaskId)) { |
|
|
|
if (businessTaskId.equals(query.getTaskId())) { |
|
|
|
FlowTaskVo flowTaskVo = new FlowTaskVo(); |
|
|
|
BeanUtil.copyProperties(query, flowTaskVo); |
|
|
|
ResultBean<UpdateFlowFieldVo> resultBean = flowableFeign.revokeProcess(flowTaskVo); |
|
|
|
if (!resultBean.getSuccess()) { |
|
|
|
return rb.setMsg(resultBean.getMsg()); |
|
|
|
} |
|
|
|
updateFlowFiled(BeanUtil.beanToMap(resultBean.getData())); |
|
|
|
return rb.success().setData(resultBean.getData()); |
|
|
|
} |
|
|
|
} |
|
|
|
return rb.setMsg("操作失败,提交的数据不一致!"); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean breakProcess(SmsGoodsReturnTaskQuery query) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
if (StringUtils.isBlank(query.getInstanceId())) { |
|
|
|
return rb.setMsg("参数错误:instanceId"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(query.getUserSid())) { |
|
|
|
return rb.setMsg("参数错误:userSid"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(query.getComment())) { |
|
|
|
return rb.setMsg("请填写意见"); |
|
|
|
} |
|
|
|
SmsSalesReturn smsSalesReturn = fetchBySid(query.getBusinessSid()); |
|
|
|
String businessTaskId = smsSalesReturn.getTaskId(); |
|
|
|
if (StringUtils.isNotBlank(businessTaskId)) { |
|
|
|
if (query.getUserSid().equals(smsSalesReturn.getCreateBySid())) { |
|
|
|
FlowTaskVo flowTaskVo = new FlowTaskVo(); |
|
|
|
BeanUtil.copyProperties(query, flowTaskVo); |
|
|
|
ResultBean<UpdateFlowFieldVo> resultBean = flowableFeign.breakProcess(flowTaskVo); |
|
|
|
if (!resultBean.getSuccess()) { |
|
|
|
return rb.setMsg(resultBean.getMsg()); |
|
|
|
} |
|
|
|
Map<String, Object> map = BeanUtil.beanToMap(resultBean.getData()); |
|
|
|
updateFlowFiled(map); |
|
|
|
return rb.success().setData(resultBean.getData()); |
|
|
|
} else { |
|
|
|
if (businessTaskId.equals(query.getTaskId())) { |
|
|
|
FlowTaskVo flowTaskVo = new FlowTaskVo(); |
|
|
|
BeanUtil.copyProperties(query, flowTaskVo); |
|
|
|
ResultBean<UpdateFlowFieldVo> resultBean = flowableFeign.breakProcess(flowTaskVo); |
|
|
|
if (!resultBean.getSuccess()) { |
|
|
|
return rb.setMsg(resultBean.getMsg()); |
|
|
|
} |
|
|
|
Map<String, Object> map = BeanUtil.beanToMap(resultBean.getData()); |
|
|
|
updateFlowFiled(map); |
|
|
|
return rb.success().setData(resultBean.getData()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return rb.setMsg("操作失败!提交的数据不一致!"); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean delegate(SmsGoodsReturnDelegateQuery query) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
FlowDelegateQuery delegateQuery = new FlowDelegateQuery(); |
|
|
|
BeanUtil.copyProperties(query, delegateQuery); |
|
|
|
flowFeign.delegate(delegateQuery); |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|