From b219589d73f46bd98995bceb4caf16dadb56b869 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 12 九月 2025 20:30:13 +0800
Subject: [PATCH] 修改bug

---
 ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TDispatchController.java |  271 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 164 insertions(+), 107 deletions(-)

diff --git a/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TDispatchController.java b/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TDispatchController.java
index 9d79d0d..0fb36a9 100644
--- a/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TDispatchController.java
+++ b/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TDispatchController.java
@@ -4,23 +4,34 @@
 import com.baomidou.mybatisplus.plugins.Page;
 import com.stylefeng.guns.core.base.controller.BaseController;
 import com.stylefeng.guns.core.base.tips.ErrorTip;
+import com.stylefeng.guns.core.beetl.ShiroExtUtil;
 import com.stylefeng.guns.core.common.constant.factory.PageFactory;
+import com.stylefeng.guns.core.log.LogObjectHolder;
 import com.stylefeng.guns.core.shiro.ShiroKit;
+import com.stylefeng.guns.core.shiro.ShiroUser;
 import com.stylefeng.guns.core.util.SinataUtil;
 import com.stylefeng.guns.modular.system.model.TCompany;
+import com.stylefeng.guns.modular.system.model.TDispatch;
+import com.stylefeng.guns.modular.system.model.User;
 import com.stylefeng.guns.modular.system.service.ITCompanyService;
+import com.stylefeng.guns.modular.system.service.ITDispatchService;
 import com.stylefeng.guns.modular.system.service.IUserService;
+import com.stylefeng.guns.modular.system.util.ResultUtil;
+import com.stylefeng.guns.modular.system.util.qianyuntong.EmployeeUtil;
+import com.stylefeng.guns.modular.system.util.qianyuntong.UserUtil;
+import com.stylefeng.guns.modular.system.util.qianyuntong.model.DeleteStafNodeRequest;
+import com.stylefeng.guns.modular.system.util.qianyuntong.model.QYTUserInfo;
+import com.stylefeng.guns.modular.system.util.qianyuntong.model.SaveStaffNode;
+import com.stylefeng.guns.modular.system.util.qianyuntong.model.SaveStaffNodeRequest;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.beans.factory.annotation.Autowired;
-import com.stylefeng.guns.core.log.LogObjectHolder;
+import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
-import com.stylefeng.guns.modular.system.model.TDispatch;
-import com.stylefeng.guns.modular.system.service.ITDispatchService;
+import org.springframework.web.bind.annotation.ResponseBody;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -35,46 +46,47 @@
 @Controller
 @RequestMapping("/tDispatch")
 public class TDispatchController extends BaseController {
-
-    private String PREFIX = "/system/tDispatch/";
-
-    @Autowired
-    private ITDispatchService tDispatchService;
-
-    @Autowired
-    private ITCompanyService tCompanyService;
-
-    @Autowired
-    private IUserService userService;
-
-    /**
-     * 跳转到调度管理首页
-     */
-    @RequestMapping("")
-    public String index() {
-        return PREFIX + "tDispatch.html";
-    }
-
-    /**
+	
+	private String PREFIX = "/system/tDispatch/";
+	
+	@Autowired
+	private ITDispatchService tDispatchService;
+	
+	@Autowired
+	private ITCompanyService tCompanyService;
+	
+	@Autowired
+	private IUserService userService;
+	@Resource
+	private ShiroExtUtil shiroExtUtil;
+	
+	/**
+	 * 跳转到调度管理首页
+	 */
+	@RequestMapping("")
+	public String index() {
+		return PREFIX + "tDispatch.html";
+	}
+	
+	/**
      * 跳转到添加调度管理
      */
     @RequestMapping("/tDispatch_add")
     public String tDispatchAdd(Model model) {
-        model.addAttribute("roleType",ShiroKit.getUser().getRoleType());
-
-        List<TCompany> companyList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 2)
-                .eq("isCross", 1)
-                .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
-        model.addAttribute("companyList",companyList);
-
-        if (2 == ShiroKit.getUser().getRoleType()){
-            List<TCompany> franchiseeList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 3)
-                    .eq("superiorId",ShiroKit.getUser().getObjectId()));
-            model.addAttribute("franchiseeList",franchiseeList);
-        }else{
-            model.addAttribute("franchiseeList",null);
-        }
-        return PREFIX + "tDispatch_add.html";
+	    model.addAttribute("roleType", shiroExtUtil.getUser().getRoleType());
+	
+	    List<TCompany> companyList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 2)
+			    .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
+	    model.addAttribute("companyList", companyList);
+	
+	    if (2 == shiroExtUtil.getUser().getRoleType()) {
+		    List<TCompany> franchiseeList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 3)
+				    .eq("superiorId", shiroExtUtil.getUser().getObjectId()));
+		    model.addAttribute("franchiseeList", franchiseeList);
+	    } else {
+		    model.addAttribute("franchiseeList", null);
+	    }
+	    return PREFIX + "tDispatch_add.html";
     }
 
     /**
@@ -101,27 +113,24 @@
      */
     @RequestMapping("/tDispatch_update/{tDispatchId}")
     public String tDispatchUpdate(@PathVariable Integer tDispatchId, Model model) {
-        TDispatch tDispatch = tDispatchService.selectById(tDispatchId);
-        model.addAttribute("item",tDispatch);
-        LogObjectHolder.me().set(tDispatch);
-
-        Integer roleType = ShiroKit.getUser().getRoleType();
-        model.addAttribute("roleType",roleType);
-        if (1 == roleType){
-            List<TCompany> companyList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 2)
-                    .eq("isCross", 1)
-                    .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
-            model.addAttribute("companyList",companyList);
-
-            List<TCompany> franchiseeList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 3)
-                    .eq("superiorId",tDispatch.getCompanyId())
-                    .eq("isCross", 1)
+	    TDispatch tDispatch = tDispatchService.selectById(tDispatchId);
+	    model.addAttribute("item", tDispatch);
+	    LogObjectHolder.me().set(tDispatch);
+	
+	    Integer roleType = shiroExtUtil.getUser().getRoleType();
+	    model.addAttribute("roleType", roleType);
+	    if (1 == roleType) {
+		    List<TCompany> companyList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 2)
+				    .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
+		    model.addAttribute("companyList", companyList);
+		
+		    List<TCompany> franchiseeList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 3)
+				    .eq("superiorId", tDispatch.getCompanyId())
                     .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
             model.addAttribute("franchiseeList",franchiseeList);
         }else if (2 == roleType){
             List<TCompany> franchiseeList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 3)
-                    .eq("superiorId",ShiroKit.getUser().getObjectId())
-                    .eq("isCross", 1)
+		            .eq("superiorId", shiroExtUtil.getUser().getObjectId())
                     .last(" and state != 1 and FIND_IN_SET(flag,'1,2')"));
             model.addAttribute("franchiseeList",franchiseeList);
         }
@@ -142,7 +151,7 @@
             endTime = timeArray[1];
         }
         Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
-        page.setRecords(tDispatchService.getDispatchList(page,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),beginTime,endTime,name,companyName,franchiseeName,account,state));
+	    page.setRecords(tDispatchService.getDispatchList(page, shiroExtUtil.getUser().getRoleType(), shiroExtUtil.getUser().getObjectId(), beginTime, endTime, name, companyName, franchiseeName, account, state));
         return super.packForBT(page);
     }
 
@@ -152,31 +161,63 @@
     @RequestMapping(value = "/add")
     @ResponseBody
     public Object add(TDispatch tDispatch) {
-        //判断账号是否存在
-        int count = tDispatchService.selectCount(new EntityWrapper<TDispatch>().eq("account",tDispatch.getAccount()).last(" and FIND_IN_SET(state,'1,2')"));
-        if (count > 0){
-            return new ErrorTip(500,"账号已存在,请重新输入");
-        }
-        Integer roleType = ShiroKit.getUser().getRoleType();
-        Integer objectId = ShiroKit.getUser().getObjectId();
-        if (2 == roleType){
-            tDispatch.setCompanyId(objectId);
-        }else if (3 == roleType){
-            TCompany company = tCompanyService.selectById(objectId);
-            tDispatch.setCompanyId(company.getSuperiorId());
-            tDispatch.setFranchiseeId(objectId);
-        }
-        tDispatch.setInsertTime(new Date());
-        tDispatch.setInsertUserId(ShiroKit.getUser().getId());
-        tDispatch.setInsertUserRole(roleType);
-        tDispatch.setState(1);
-        if(tDispatch.getCompanyId() == null){
-            Integer objectId1 = userService.selectById(ShiroKit.getUser().getId()).getObjectId();
-            tDispatch.setCompanyId(objectId1);
-        }
-        tDispatch.setPassword(ShiroKit.md5(tDispatch.getPassword(), "WL:x9#"));
-        tDispatchService.insert(tDispatch);
-        return SUCCESS_TIP;
+	    //判断账号是否存在
+	    int count = tDispatchService.selectCount(new EntityWrapper<TDispatch>().eq("account", tDispatch.getAccount()).last(" and FIND_IN_SET(state,'1,2')"));
+	    if (count > 0) {
+		    return new ErrorTip(500, "账号已存在,请重新输入");
+	    }
+	    Integer roleType = shiroExtUtil.getUser().getRoleType();
+	    Integer objectId = shiroExtUtil.getUser().getObjectId();
+	    if (2 == roleType) {
+		    tDispatch.setCompanyId(objectId);
+	    } else if (3 == roleType) {
+		    TCompany company = tCompanyService.selectById(objectId);
+		    tDispatch.setCompanyId(company.getSuperiorId());
+		    tDispatch.setFranchiseeId(objectId);
+	    }
+	    tDispatch.setInsertTime(new Date());
+	    tDispatch.setInsertUserId(shiroExtUtil.getUser().getId());
+	    tDispatch.setInsertUserRole(roleType);
+	    tDispatch.setState(1);
+	    if (tDispatch.getCompanyId() == null) {
+		    Integer objectId1 = userService.selectById(shiroExtUtil.getUser().getId()).getObjectId();
+		    tDispatch.setCompanyId(objectId1);
+	    }
+	    tDispatch.setPassword(ShiroKit.md5(tDispatch.getPassword(), "WL:x9#"));
+
+		User user = userService.selectById(shiroExtUtil.getUser().getId());
+		TCompany tCompany = tCompanyService.selectById(user.getObjectId());
+		List<QYTUserInfo> userInfoByPhone = UserUtil.getUserInfoByPhone(tDispatch.getAccount(), tCompany.getEnterCode());
+		Long empId = null;
+		Integer empnew = null;
+		if(null == userInfoByPhone || userInfoByPhone.size() == 0){
+			SaveStaffNodeRequest request = new SaveStaffNodeRequest();
+			request.setMobile(user.getPhone());
+			request.setEntercode(tCompany.getEnterCode());
+			request.setEmpName(tDispatch.getName());
+			request.setEmpNickname(tDispatch.getName());
+			request.setLoginNo(tDispatch.getPhone());
+			request.setEmpSex("男");
+			request.setMphone(tDispatch.getPhone());
+			request.setEmail(tDispatch.getPhone() + "@qyt.com");
+			request.setDeptId(0);
+			request.setPositionId(1);
+			request.setSuperLevel(0);
+			request.setHideMobile(0);
+			ResultUtil<SaveStaffNode> resultUtil = EmployeeUtil.saveStaffNode(request);
+			if(200 != resultUtil.getStatus()){
+				return new ErrorTip(resultUtil.getStatus(), resultUtil.getMsg());
+			}
+			SaveStaffNode saveStaffNode = resultUtil.getData();
+			empId = saveStaffNode.getEmpId();
+			empnew = 1;
+		}
+		tDispatch.setEmpId(empId);
+		tDispatch.setEntercode(tCompany.getEnterCode());
+		tDispatch.setEnterId(Long.valueOf(tCompany.getEnterCode()));
+		tDispatch.setEmpnew(empnew);
+		tDispatchService.insert(tDispatch);
+	    return SUCCESS_TIP;
     }
 
     /**
@@ -197,6 +238,22 @@
             dispatch.setState(1);
         }
         tDispatchService.updateById(dispatch);
+		ShiroUser user = shiroExtUtil.getUser();
+		TCompany tCompany = tCompanyService.selectById(user.getObjectId());
+		if (null != dispatch.getEmpId() && 1 == dispatch.getEmpnew()) {
+			//中台先删除司机
+			List<QYTUserInfo> userInfoByPhone = UserUtil.getUserInfoByPhone(dispatch.getPhone(), tCompany.getEnterCode());
+			if (null != userInfoByPhone && 0 < userInfoByPhone.size() && 1 == dispatch.getEmpnew()) {
+				DeleteStafNodeRequest deleteStafNodeRequest = new DeleteStafNodeRequest();
+				deleteStafNodeRequest.setEmpId(dispatch.getEmpId());
+				deleteStafNodeRequest.setEntercode(tCompany.getEnterCode());
+				deleteStafNodeRequest.setMobile(tCompany.getPrincipalPhone());
+				ResultUtil resultUtil = EmployeeUtil.ecrmDeleteStafNode(deleteStafNodeRequest);
+				if(200 != resultUtil.getStatus()){
+					return new ErrorTip(resultUtil.getStatus(), resultUtil.getMsg());
+				}
+			}
+		}
         return SUCCESS_TIP;
     }
 
@@ -206,28 +263,28 @@
     @RequestMapping(value = "/update")
     @ResponseBody
     public Object update(TDispatch tDispatch) {
-        TDispatch obj = tDispatchService.selectById(tDispatch.getId());
-        if (!obj.getAccount().equals(tDispatch.getAccount())){
-            //判断账号是否存在
-            int count = tDispatchService.selectCount(new EntityWrapper<TDispatch>().eq("account",tDispatch.getAccount()).last(" and FIND_IN_SET(state,'1,2')"));
-            if (count > 0){
-                return new ErrorTip(500,"账号已存在,请重新输入");
-            }
-        }
-        Integer roleType = ShiroKit.getUser().getRoleType();
-        Integer objectId = ShiroKit.getUser().getObjectId();
-        if (2 == roleType){
-            tDispatch.setCompanyId(objectId);
-        }else if (3 == roleType){
-            TCompany company = tCompanyService.selectById(objectId);
-            tDispatch.setCompanyId(company.getSuperiorId());
-            tDispatch.setFranchiseeId(objectId);
-        }
-        if (SinataUtil.isNotEmpty(tDispatch.getPassword())){
-            tDispatch.setPassword(ShiroKit.md5(tDispatch.getPassword(), "WL:x9#"));
-        }
-        tDispatchService.updateById(tDispatch);
-        return SUCCESS_TIP;
+	    TDispatch obj = tDispatchService.selectById(tDispatch.getId());
+	    if (!obj.getAccount().equals(tDispatch.getAccount())) {
+		    //判断账号是否存在
+		    int count = tDispatchService.selectCount(new EntityWrapper<TDispatch>().eq("account", tDispatch.getAccount()).last(" and FIND_IN_SET(state,'1,2')"));
+		    if (count > 0) {
+			    return new ErrorTip(500, "账号已存在,请重新输入");
+		    }
+	    }
+//	    Integer roleType = shiroExtUtil.getUser().getRoleType();
+//	    Integer objectId = shiroExtUtil.getUser().getObjectId();
+//	    if (2 == roleType) {
+//		    tDispatch.setCompanyId(objectId);
+//	    } else if (3 == roleType) {
+//		    TCompany company = tCompanyService.selectById(objectId);
+//		    tDispatch.setCompanyId(company.getSuperiorId());
+//		    tDispatch.setFranchiseeId(objectId);
+//	    }
+	    if (SinataUtil.isNotEmpty(tDispatch.getPassword())) {
+		    tDispatch.setPassword(ShiroKit.md5(tDispatch.getPassword(), "WL:x9#"));
+	    }
+	    tDispatchService.updateById(tDispatch);
+	    return SUCCESS_TIP;
     }
 
 }

--
Gitblit v1.7.1