From 6500da411f234b8ad0ee493909d515bf9eeecdd5 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期四, 16 十月 2025 19:28:27 +0800
Subject: [PATCH] 最新版本541200007
---
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java | 265 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 255 insertions(+), 10 deletions(-)
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
index c7ef282..437120d 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkSketchServiceImpl.java
@@ -33,6 +33,7 @@
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
+import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.*;
import java.util.Date;
@@ -85,6 +86,22 @@
public void delete(JkSketch jkSketch) {
UpdateWrapper<JkSketch> deleteWrapper = new UpdateWrapper<>(jkSketch);
jkSketchMapper.delete(deleteWrapper);
+ }
+
+
+ @Override
+ @PostConstruct
+ public void initAyncsJob() {
+ //閲嶇疆浜ら�氳鍒掑拰绾胯矾瑙勫垝鐨勫紓姝ヤ换鍔$姸鎬�
+ jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
+ .set(JkSketch::getStatus,Constants.THREE)
+ .eq(JkSketch::getIsdeleted,Constants.ZERO)
+ .eq(JkSketch::getStatus,Constants.ONE));
+ categoryMapper.update(null,new UpdateWrapper<Category>().lambda()
+ .set(Category::getStatus,Constants.ZERO)
+ .eq(Category::getType,Constants.FOUR)
+ .eq(Category::getIsdeleted,Constants.ZERO)
+ .eq(Category::getStatus,Constants.TWO));
}
@Override
@@ -142,6 +159,77 @@
jkSketchMapper.updateById(model);
return model;
}
+
+ @Override
+ public JkSketch updateSketchLine(JkSketch jkSketch) {
+ JkSketch model = jkSketchMapper.selectById(jkSketch.getId());
+ if(model == null ||Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
+ if( jkSketch.getSketchLineList() ==null || jkSketch.getSketchLineList().size()==0 ){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璇锋寜瑕佹眰璋冩暣浼樺寲鏂规锛�");
+ }
+ if(Constants.equalsInteger(model.getStatus(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠绾胯矾姝e瓨鍦ㄤ紭鍖栦换鍔★紝璇疯�愬績绛夊緟浼樺寲瀹屾垚鍐嶈繘琛岃璋冩暣鎿嶄綔锛�");
+ }
+
+ //褰撳墠鎵�鏈夌嚎璺�(绗﹀悎鏉′欢鐨勭嚎璺級
+ List<JkSketchLine> lineList = jkSketchLineMapper.selectJoinList(JkSketchLine.class,new MPJLambdaWrapper<JkSketchLine>()
+ .selectAll(JkSketchLine.class )
+ .selectAs(JkLine::getName,JkSketchLine::getLineName)
+ .selectAs(JkLine::getMaxOrder,JkSketchLine::getMaxOrder)
+ .selectAs(JkLine::getMaxCustomer,JkSketchLine::getMaxCustomer)
+ .leftJoin(JkLine.class,JkLine::getId,JkOrders::getLineId )
+ .eq(JkSketchLine::getSketchId,jkSketch.getId())
+ .eq(JkSketchLine::getIsdeleted,Constants.ZERO));
+ if(lineList ==null ||lineList.size() ==0){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠绾胯矾涓嶆弧瓒充紭鍖栨柟妗堣皟鏁存潯浠讹紒");
+ }
+ for(JkSketchLine line :lineList){
+ JkSketchLine lineParam =getLineParamById(line.getId(),jkSketch.getSketchLineList());
+ if(lineParam == null){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇峰熀浜庣幇鏈夌嚎璺繘琛屾柟妗堣皟鏁达紝绾胯矾銆�"+line.getLineName()+"銆戠嚎璺厤缃笉姝g‘锛�");
+ }
+ if(lineParam.getCustomerList() == null || lineParam.getCustomerList().size() == 0 ){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇峰熀浜庣幇鏈夌嚎璺繘琛屾柟妗堣皟鏁达紝绾胯矾銆�"+line.getLineName()+"銆戝鎴蜂俊鎭笉鑳戒负绌猴紒");
+ }
+ Integer totalCus = 0;
+ BigDecimal totalNum =new BigDecimal(0);
+ for(JkSketchCustomer customer :lineParam.getCustomerList()){
+ totalCus += 1;//鎬诲鎴烽噺
+ totalNum = totalNum.add(Constants.formatBigdecimal(customer.getTotalNum()));//鎬婚�佽揣閲�
+ customer.setSketchLineId(line.getId());
+ }
+ if( totalCus > Constants.formatIntegerNum(line.getMaxCustomer()) ){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戠嚎璺鍗曞鎴锋暟閲忚秴杩囦簡绾胯矾鎬诲鎴烽噺闄愬埗锛屾棤娉曡繘琛岃皟鏁达紒");
+ }
+ if( totalNum.doubleValue() > Constants.formatIntegerNum(line.getMaxOrder())){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣鍗曢�佽揣閲忚秴杩囦簡绾胯矾鎬婚�佽揣閲忛檺鍒讹紝鏃犳硶杩涜璋冩暣锛�");
+ }
+ lineParam.setTotalNum(totalNum);
+ lineParam.setOrderNum(totalCus);
+ }
+ model.setSketchLineList(jkSketch.getSketchLineList());//绾胯矾淇℃伅
+ model.setStatus(Constants.ONE);
+ model.setEditDate(new Date());
+ model.setEditor(jkSketch.getLoginUserInfo().getId());
+ model.setPlanLineDate(model.getEditDate());
+ model.setPlanLineUserId(jkSketch.getLoginUserInfo().getId());
+ model.setJobId(UUID.randomUUID().toString());
+ redisTemplate.opsForValue().set(Constants.RedisKeys.JKLINE_JOB+model.getJobId(),true );//鍋氬紓姝ュ鐞�
+ jkSketchMapper.updateById(model);
+ return model;
+ }
+
+ private JkSketchLine getLineParamById(Integer id, List<JkSketchLine> sketchLineList) {
+ for(JkSketchLine line: sketchLineList){
+ if(Constants.equalsInteger(line.getId(),id)){
+ return line;
+ }
+ }
+ return null;
+ }
+
@Override
public JkSketch initOriginDistance(JkSketch jkSketch ) {
JkSketch model = jkSketchMapper.selectById(jkSketch.getId());
@@ -344,7 +432,7 @@
}
String errorMsg ="";
for(JkCustomer c1 : customerList){
- if(c1.getLatitude()==null || c1.getLongitude() ==null){
+ if(c1.getLatitude()==null || c1.getLongitude() ==null || Constants.equalsInteger(c1.getDistanceStatus(),Constants.TWO)){
errorMsg += c.getName()+"-"+c.getName()+" | ";
}
}
@@ -367,13 +455,17 @@
long[] vehicleCapacities1=new long[lineList.size()];//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
long[] demands1 = new long[customerList.size()+1]; //鍚勪釜鐐圭殑璁㈠崟閲�
long[][] distanceMatrix1 = new long[customerList.size()+1][customerList.size()+1];
+ distanceMatrix1[0][0] = 0;
demands1[0] =0;//鍘熺偣
for (int i = 0; i < customerList.size(); i++) {
List<DistanceMapParam> disList = customerList.get(i).getDistanceMapParamList();
- distanceMatrix1[0][i] = disList.get(0).getDistance();
- distanceMatrix1[i][0] = disList.get(disList.size() -1).getDistance();
+ distanceMatrix1[0][i+1] = disList.get(0).getDistance();
+ distanceMatrix1[i+1][0] = disList.get(disList.size() -1).getDistance();
demands1[i+1] = Constants.formatBigdecimal( customerList.get(i).getTotalNum()).longValue(); //鍚勪釜鐐圭殑璁㈠崟閲�
- for (int j = 0; j< disList.size()-2; j++) {
+ for (int j = 0; j < customerList.size(); j++) {
+ distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ;
+ }
+ /* for (int j = 0; j< disList.size()-2; j++) {
if(j+1 >=10){
break;
}
@@ -382,7 +474,7 @@
}else{
distanceMatrix1[i+1][j+1] = 1l;
}
- }
+ }*/
}
for (int i = 0; i < lineList.size(); i++) {
vehicleCapacities1[i] = lineList.get(i).getMaxOrder();//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
@@ -402,6 +494,149 @@
}
}
+ @Override
+ @Async
+ public void startEditSketchLineAsync(JkSketch model) {
+ boolean success = true;
+ int totalDistance = 0;
+ List<JkSketchLine> lineList = model.getSketchLineList();
+ try {
+ MPJLambdaWrapper<JkSketchCustomer> queryWrapper = new MPJLambdaWrapper<>();
+ queryWrapper.selectAll(JkSketchCustomer.class )
+ .selectAs(JkCustomer::getName,JkSketchCustomer::getName)
+ .selectAs(JkCustomer::getCode,JkSketchCustomer::getCode)
+ .selectAs(JkCustomer::getDistance,JkSketchCustomer::getDistanceJson)
+ .selectAs(JkCustomer::getLongitude,JkSketchCustomer::getLongitude)
+ .selectAs(JkCustomer::getLatitude,JkSketchCustomer::getLatitude)
+ .selectAs(JkCustomer::getStartDistance,JkSketchCustomer::getStartDistance)
+ .selectAs(JkCustomer::getEndDistance,JkSketchCustomer::getEndDistance)
+ .leftJoin(JkCustomer.class,JkCustomer::getId,JkSketchCustomer::getCustomerId )
+ .eq(JkSketchCustomer::getSketchId, model.getId())
+ .eq(JkSketchCustomer::getIsdeleted,Constants.ZERO)
+ .orderByAsc(JkSketchCustomer::getSortnum);
+ List<JkSketchCustomer> customerList = jkSketchCustomerMapper.selectJoinList(JkSketchCustomer.class,queryWrapper);
+ if(customerList == null ||customerList.size() ==0){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇ョ嚎璺鎴蜂俊鎭负绌猴紝涓嶆弧瓒充紭鍖栨潯浠讹紒");
+ }
+
+ int totalNum = 0;
+ for(JkSketchLine line : lineList){
+ //瀹屽杽绾胯矾瀹㈡埛浼樺寲鍙傛暟
+ List<JkSketchCustomer> customerListParam = line.getCustomerList() ;
+ if(customerListParam ==null || customerListParam.size()==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST);
+ }
+ initSketchCustomerListParam(line.getCustomerList(),customerList) ;
+ totalNum += customerListParam.size();
+ }
+ if(totalNum != Constants.formatIntegerNum(model.getOrderNum())){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST);
+ }
+ for(JkSketchLine line : lineList){
+ //閫愪釜璺嚎浼樺寲
+ List<JkSketchCustomer> customerListParam = line.getCustomerList() ;
+ TspSolver.DataModel dataModel = new TspSolver.DataModel();
+ int vehicleNumber1 = 1;//绾胯矾鏁伴噺
+ long[] vehicleCapacities1=new long[]{line.getMaxOrder()};//姣忚締杞︾殑鏈�澶ц鍗曢噺闄愬埗
+ long[] demands1 = new long[customerListParam.size()+1]; //鍚勪釜鐐圭殑璁㈠崟閲�
+ long[][] distanceMatrix1 = new long[customerListParam.size()+1][customerListParam.size()+1];
+ distanceMatrix1[0][0] = 0;
+ demands1[0] =0;//鍘熺偣
+ for (int i = 0; i < customerListParam.size(); i++) {
+ List<DistanceMapParam> disList = customerListParam.get(i).getDistanceMapParamList();
+ distanceMatrix1[0][i+1] = disList.get(0).getDistance();
+ distanceMatrix1[i+1][0] = disList.get(disList.size() -1).getDistance();
+ demands1[i+1] = Constants.formatBigdecimal( customerListParam.get(i).getTotalNum()).longValue(); //鍚勪釜鐐圭殑璁㈠崟閲�
+ for (int j = 0; j < customerListParam.size(); j++) {
+ distanceMatrix1[i+1][j+1] =disList.get(j+1).getDistance() ;
+ }
+
+ }
+ //鏋勯�犱紭鍖栨暟鎹ā鍨�
+ dataModel.initDataInfo(vehicleNumber1,demands1,vehicleCapacities1,distanceMatrix1);
+ TspSolver.startSearch(dataModel);
+ if(dataModel.getSolutions()==null || dataModel.getSolutions().size()==0){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣皟鏁村け璐� 锛屾湭鑾峰緱鏈�浼樹氦閫氳鍒掓柟妗堬紒");
+ }
+ TspSolverSolutions so = dataModel.getSolutions().get(0);
+ List<Integer> routes = so.getRouteIndex();
+ totalDistance += so.getDistance();
+ if(routes.size() <=2) {
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绾胯矾銆�"+line.getLineName()+"銆戣皟鏁村け璐� 锛屾湭鑾峰緱鏈�浼樹氦閫氳鍒掓柟妗堬紒");
+ }
+ //鏈夋晥璺緞
+ for (Integer cIndex : routes){
+ if(cIndex ==0){
+ continue; //璧峰鐐逛笉澶勭悊
+ }
+ JkSketchCustomer customer = customerListParam.get(cIndex-1);
+ customer.setSortnum(cIndex-1);
+ }
+ line.setDistance(so.getDistance());
+ }
+
+ }catch (Exception e){
+ e.printStackTrace();
+ success =false;
+ }finally {
+ if(success){
+ List<JkSketchCustomer> allList = new ArrayList<>();
+ for(JkSketchLine line : lineList){
+ allList.addAll(line.getCustomerList());
+ }
+ jkSketchLineMapper.updateById(lineList);
+ jkSketchCustomerMapper.updateById(allList);
+ }
+ jkSketchMapper.update(null,new UpdateWrapper<JkSketch>().lambda()
+ .eq(JkSketch::getId,model.getId() )
+ .eq(JkSketch::getJobId,model.getJobId() )
+ .set(success,JkSketch::getDistance,totalDistance)
+ .set(JkSketch::getPlanLineInfo,success?"鏈�杩戜竴娆$嚎璺皟鏁存垚鍔�":"鏈�杩戜竴娆$嚎璺皟鏁村け璐ワ紒")
+ .set(JkSketch::getStatus,success?Constants.TWO:Constants.THREE)
+ .set(JkSketch::getPlanLineEndDate,new Date()));
+ }
+
+ }
+
+ private List<JkSketchCustomer> initSketchCustomerListParam(List<JkSketchCustomer> customerList, List<JkSketchCustomer> customerList1) {
+ for(JkSketchCustomer param : customerList){
+ for(JkSketchCustomer model : customerList1){
+ if(Constants.equalsInteger(model.getId(),param.getId())){
+ param.setLatitude(model.getLatitude());
+ param.setLongitude(model.getLongitude());
+ param.setStartDistance(model.getStartDistance());
+ param.setEndDistance(model.getEndDistance());
+ param.setDistanceJson(model.getDistanceJson());
+ }
+ }
+ }
+ for(JkSketchCustomer c : customerList){
+ List<DistanceMapParam> tmpList = new ArrayList<>();
+ List<DistanceMapParam> distanceMapParamList = getListFromJsonStr(c.getDistanceJson());
+ DistanceMapParam t0 = new DistanceMapParam();
+ t0.setId(-2);//琛ㄧず杩斿洖鍥尯
+ t0.setDistance(Constants.formatLongNum(c.getStartDistance()) );
+ tmpList.add(t0);
+ for(JkSketchCustomer cm : customerList){
+ //瀹㈡埛鍜屽鎴蜂箣闂寸殑璺濈淇℃伅
+ DistanceMapParam t = new DistanceMapParam();
+ t.setId(cm.getCustomerId());
+ t.setDistance(0);
+ DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),distanceMapParamList);
+ if(param!=null){//濡傛灉涔嬪墠宸茬粡鑾峰彇杩�
+ t = param;
+ }
+ tmpList.add(t);
+ }
+ DistanceMapParam tt = new DistanceMapParam();
+ tt.setId(-2);//琛ㄧず杩斿洖鍥尯
+ tt.setDistance(Constants.formatLongNum(c.getEndDistance()));
+ tmpList.add(tt);
+ c.setDistanceMapParamList(tmpList);
+ }
+ return customerList;
+ }
+
private void initCustomerDistance( List<JkSketchLine> lineList,JkSketch model,boolean updateLineDistance) {
List<JkSketchCustomer> customerList = model.getCustomerList();
@@ -443,13 +678,22 @@
for (JkSketchLine line :lineList){
long lineDistance = 0;
List<JkSketchCustomer> customers = getCustomerListByLineId(line.getId(),customerList);
+ int index =0;
for(JkSketchCustomer c : customers){
- lineDistance+= Constants.formatLongNum(c.getStartDistance());
- lineDistance+= Constants.formatLongNum(c.getEndDistance());
- for(JkSketchCustomer cm : customers){
+ if(index ==0){
+ lineDistance+= Constants.formatLongNum(c.getStartDistance());
+ }
+ if(index == customers.size()-1){
+ lineDistance+= Constants.formatLongNum(c.getEndDistance());
+ break;
+ }
+ DistanceMapParam param = getParamByCustomerIds( customers.get(index+1).getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
+ lineDistance += param.getDistance();
+ index++;
+ /* for(JkSketchCustomer cm : customers){
DistanceMapParam param = getParamByCustomerIds( cm.getCustomerId(),getListFromJsonStr(c.getDistanceJson()));
lineDistance += param.getDistance();
- }
+ }*/
}
if(updateLineDistance && Constants.equalsInteger(model.getStatus(),Constants.ZERO) ){
line.setDistance(lineDistance);
@@ -503,10 +747,11 @@
if(solutions!=null && solutions.size()>0){
for(TspSolverSolutions so : solutions){
List<Integer> routes = so.getRouteIndex();
+ totalDistance+= so.getDistance();
if(routes.size() <=2) {
continue;//鏃犲鎴风殑闈炴湁鏁堣矾绾�
}
- totalDistance+= so.getDistance();
+// totalDistance+= so.getDistance();
JkLine line =model.getLineList().get(so.getLineIndex());
JkSketchLine tModel = new JkSketchLine();
tModel.setSketchId(model.getId());
--
Gitblit v1.9.3