package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
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.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.PushMinistryOfTransportUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* 分公司管理控制器
|
*
|
* @author fengshuonan
|
* @Date 2020-06-06 09:15:48
|
*/
|
@Controller
|
@RequestMapping("/tCompany")
|
public class TCompanyController extends BaseController {
|
|
private String PREFIX = "/system/tCompany/";
|
|
@Autowired
|
private ITCompanyService tCompanyService;
|
|
@Autowired
|
private ITRegionService tRegionService;
|
|
@Autowired
|
private IUserService userService;
|
|
@Autowired
|
private ITTaxiCardService cardService;
|
|
@Autowired
|
private ITCompanyCityService tCompanyCityService;
|
|
@Autowired
|
private PushMinistryOfTransportUtil pushMinistryOfTransportUtil;
|
|
@Autowired
|
private ISpellOrderRuleService spellOrderRuleService;
|
|
@Autowired
|
private ITDriverService tDriverService;
|
|
@Autowired
|
private ITDriverServiceService tDriverServiceService;
|
|
@Autowired
|
private ITCarService tCarService;
|
|
@Autowired
|
private ITCarServiceService tCarServiceService;
|
|
@Autowired
|
private IMenuEntryConfigService menuEntryConfigService;
|
|
@Autowired
|
private IMenuService menuService;
|
|
@Value("${pushMinistryOfTransport}")
|
private boolean pushMinistryOfTransport;
|
|
|
/**
|
* 跳转到修改平台信息
|
*/
|
@RequestMapping("/admin_update")
|
public String tCompanyUpdate(Model model) {
|
ShiroUser user1 = ShiroKit.getUser();
|
TCompany tCompany = tCompanyService.selectById(user1.getObjectId());
|
model.addAttribute("item",tCompany);
|
LogObjectHolder.me().set(tCompany);
|
|
//省
|
List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("provinceList",provinceList);
|
|
//系统用户对象
|
User user = userService.selectById(user1.getId());
|
model.addAttribute("user",user);
|
|
//经营区域
|
List<Map<String, Object>> scopeList = tCompanyService.getCompanyScopeById(tCompany.getId());
|
model.addAttribute("scopeList",scopeList);
|
|
//传递当前用户角色类型,用于控制非平台账号禁用经营业务和经营区域编辑
|
model.addAttribute("roleType", user1.getRoleType());
|
|
return PREFIX + "platformEdit.html";
|
}
|
|
/**
|
* 跳转到入口设置页面
|
*/
|
@RequestMapping("/menu_entry_config")
|
public String menuEntryConfig(Model model) {
|
addMenuEntryConfigModel(model);
|
return PREFIX + "menuEntryConfig.html";
|
}
|
|
/**
|
* 加载入口配置页面数据
|
*/
|
private void addMenuEntryConfigModel(Model model) {
|
Integer companyId = ShiroKit.getUser().getObjectId();
|
List<MenuEntryConfig> entryConfigList = menuEntryConfigService.selectList(
|
new EntityWrapper<MenuEntryConfig>().eq("openCityId", companyId).orderBy("id", true));
|
List<Menu> entryMenuList = menuService.selectList(
|
new EntityWrapper<Menu>()
|
.eq("status", 1)
|
.eq("ismenu", 1)
|
.isNotNull("url")
|
.ne("url", "")
|
.orderBy("levels", true)
|
.orderBy("num", true));
|
model.addAttribute("entryConfigList", entryConfigList);
|
model.addAttribute("entryMenuList", entryMenuList);
|
}
|
|
/**
|
* 跳转到分公司管理首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "tCompany.html";
|
}
|
|
/**
|
* 跳转到加盟商管理首页
|
*/
|
@RequestMapping("/franchisee")
|
public String franchisee() {
|
return PREFIX + "franchisee.html";
|
}
|
|
/**
|
* 跳转到添加分公司管理
|
*/
|
@RequestMapping("/tCompany_add")
|
public String tCompanyAdd(Model model) {
|
List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("provinceList",provinceList);
|
return PREFIX + "tCompany_add.html";
|
}
|
|
/**
|
* 跳转到添加加盟商司管理
|
*/
|
@RequestMapping("/tCompany_addFranchisee")
|
public String tCompany_addFranchisee(Model model) {
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
if (1 == roleType){
|
//查询分公司
|
List<TCompany> companyList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 2));
|
model.addAttribute("companyList",companyList);
|
}else if (2 == roleType){
|
TCompany tCompany = tCompanyService.selectById(ShiroKit.getUser().getObjectId());
|
model.addAttribute("company",tCompany);
|
}
|
model.addAttribute("roleType",roleType);
|
return PREFIX + "tCompany_addFranchisee.html";
|
}
|
|
/**
|
* 跳转到查看分公司详情
|
*/
|
@RequestMapping("/tCompany_detail/{tCompanyId}")
|
public String tCompany_detail(@PathVariable Integer tCompanyId, Model model) {
|
TCompany tCompany = tCompanyService.selectById(tCompanyId);
|
model.addAttribute("item",tCompany);
|
LogObjectHolder.me().set(tCompany);
|
|
//省
|
List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("provinceList",provinceList);
|
|
//系统用户对象
|
User user = userService.selectOne(new EntityWrapper<User>().eq("roleType", 2).eq("objectId", tCompanyId));
|
model.addAttribute("user",user);
|
|
//经营区域
|
List<Map<String, Object>> scopeList = tCompanyService.getCompanyScopeById(tCompanyId);
|
model.addAttribute("scopeList",scopeList);
|
|
return PREFIX + "tCompany_detail.html";
|
}
|
|
/**
|
* 跳转到修改分公司管理
|
*/
|
@RequestMapping("/tCompany_update/{tCompanyId}")
|
public String tCompanyUpdate(@PathVariable Integer tCompanyId, Model model) {
|
TCompany tCompany = tCompanyService.selectById(tCompanyId);
|
model.addAttribute("item",tCompany);
|
LogObjectHolder.me().set(tCompany);
|
|
//省
|
List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("provinceList",provinceList);
|
|
//系统用户对象
|
User user = userService.selectOne(new EntityWrapper<User>().eq("roleType", 2).eq("objectId", tCompanyId));
|
model.addAttribute("user",user);
|
|
//经营区域
|
List<Map<String, Object>> scopeList = tCompanyService.getCompanyScopeById(tCompanyId);
|
model.addAttribute("scopeList",scopeList);
|
|
// 传递当前用户角色类型,用于控制非平台账号禁用经营业务和经营区域编辑
|
model.addAttribute("roleType", ShiroKit.getUser().getRoleType());
|
return PREFIX + "tCompany_edit.html";
|
}
|
|
/**
|
* 跳转到查看加盟商
|
*/
|
@RequestMapping("/tCompany_detailFranchisee/{tCompanyId}")
|
public String tCompany_detailFranchisee(@PathVariable Integer tCompanyId, Model model) {
|
TCompany tCompany = tCompanyService.selectById(tCompanyId);
|
model.addAttribute("item", tCompany);
|
LogObjectHolder.me().set(tCompany);
|
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
model.addAttribute("roleType", roleType);
|
|
TCompany obj = tCompanyService.selectById(tCompany.getSuperiorId());
|
if (SinataUtil.isNotEmpty(obj)) {
|
model.addAttribute("companyName", obj.getName());
|
} else {
|
model.addAttribute("companyName", "平台");
|
}
|
|
|
//系统用户对象
|
User user = userService.selectOne(new EntityWrapper<User>().eq("roleType", 3).eq("objectId", tCompanyId));
|
model.addAttribute("user", user);
|
return PREFIX + "tCompany_detailFranchisee.html";
|
}
|
|
/**
|
* 跳转到修改分公司管理
|
*/
|
@RequestMapping("/tCompany_updateFranchisee/{tCompanyId}")
|
public String tCompany_updateFranchisee(@PathVariable Integer tCompanyId, Model model) {
|
TCompany tCompany = tCompanyService.selectById(tCompanyId);
|
model.addAttribute("item", tCompany);
|
LogObjectHolder.me().set(tCompany);
|
|
Integer roleType = ShiroKit.getUser().getRoleType();
|
if (1 == roleType) {
|
//查询分公司
|
List<TCompany> companyList = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("type", 2));
|
model.addAttribute("companyList", companyList);
|
} else if (2 == roleType) {
|
TCompany obj = tCompanyService.selectById(ShiroKit.getUser().getObjectId());
|
model.addAttribute("company", obj);
|
}
|
model.addAttribute("roleType", roleType);
|
|
//系统用户对象
|
User user = userService.selectOne(new EntityWrapper<User>().eq("roleType", 3).eq("objectId", tCompanyId));
|
model.addAttribute("user", user);
|
return PREFIX + "tCompany_updateFranchisee.html";
|
}
|
|
@RequestMapping(value = "/change")
|
@ResponseBody
|
public Object change(@RequestParam Integer code) {
|
List<TRegion> list = new ArrayList<>();
|
if (SinataUtil.isNotEmpty(code)){
|
TRegion region = tRegionService.selectOne(new EntityWrapper<TRegion>().eq("code", code));
|
list = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", region.getId()));
|
}
|
return list;
|
}
|
|
|
|
//// 移除经营区域时校验
|
@RequestMapping(value = "/searchArea")
|
@ResponseBody
|
public Object searchArea(Integer companyId, Integer id) {
|
List<TTaxiCard> list = cardService.selectList(new EntityWrapper<TTaxiCard>().eq("companyId",companyId));
|
for (TTaxiCard tTaxiCard : list) {
|
if (ToolUtil.isNotEmpty(tTaxiCard.getCompanyCityId())){
|
String[] arr = tTaxiCard.getCompanyCityId().split(";");
|
for (String s : arr) {
|
if (s.equals(id.toString())){
|
return "该区域正被打车卡使用,不允许移除";
|
}
|
}
|
}
|
}
|
return SUCCESS_TIP;
|
}
|
|
|
|
|
/**
|
* 获取分公司管理列表
|
*/
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object list(String insertTime,
|
String name,
|
String principalName,
|
String principalPhone,
|
String adminName,
|
String adminPhone,
|
String serviceStr,
|
Integer state) {
|
String beginTime = null;
|
String endTime = null;
|
if (SinataUtil.isNotEmpty(insertTime)){
|
String[] timeArray = insertTime.split(" - ");
|
beginTime = timeArray[0];
|
endTime = timeArray[1];
|
}
|
Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
|
page.setRecords(tCompanyService.getCompanyList(page,beginTime,endTime,name,principalName,principalPhone,adminName,adminPhone,serviceStr,state));
|
return super.packForBT(page);
|
}
|
|
/**
|
* 获取分公司管理列表
|
*/
|
@RequestMapping(value = "/listFranchisee")
|
@ResponseBody
|
public Object listFranchisee(String insertTime,
|
String name,
|
String account,
|
String principalName,
|
String principalPhone,
|
String serviceStr,
|
Integer state) {
|
String beginTime = null;
|
String endTime = null;
|
if (SinataUtil.isNotEmpty(insertTime)) {
|
String[] timeArray = insertTime.split(" - ");
|
beginTime = timeArray[0];
|
endTime = timeArray[1];
|
}
|
Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
|
if (ShiroKit.getUser().getRoleType() == 3) {
|
page.setRecords(null);
|
} else {
|
page.setRecords(tCompanyService.getFranchiseeList(page, beginTime, endTime, name, account, principalName, principalPhone, serviceStr, state, ShiroKit.getUser().getRoleType(), ShiroKit.getUser().getObjectId()));
|
}
|
return super.packForBT(page);
|
}
|
|
|
/**
|
* 新增分公司管理
|
*/
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
public Object add(TCompany tCompany,@RequestParam String subArr,String account,String password) {
|
String name = tCompany.getName();
|
name = name.replaceAll("& lt;", "<");
|
name = name.replaceAll("& gt;", ">");
|
name = name.replaceAll("& #40;", "(");
|
name = name.replaceAll("& #41;", ")");
|
tCompany.setName(name);
|
//判断账号是否已存在
|
int count = userService.selectCount(new EntityWrapper<User>().eq("account", account));
|
if (count > 0) {
|
return "error";
|
}
|
if(ToolUtil.isEmpty(tCompany.getIdentifier())){
|
return "统一社会信用代码不能为空";
|
}
|
String commissionError = validateBusinessCommission(tCompany);
|
if (commissionError != null) {
|
return commissionError;
|
}
|
tCompany.setIsNeedFerry(2);
|
tCompany.setType(2); //2:分公司
|
tCompany.setState(0); //0:正常
|
tCompany.setFlag("1");
|
tCompany.setInsertTime(new Date());
|
tCompany.setUpdateTime(new Date());
|
tCompanyService.insert(tCompany);
|
// 添加拼单设置
|
SpellOrderRule spellOrderRule = new SpellOrderRule();
|
spellOrderRule.setCompanyId(tCompany.getId());
|
spellOrderRuleService.insert(spellOrderRule);
|
|
//添加User对象
|
User user = new User();
|
user.setAccount(account);
|
user.setPhone(account);
|
user.setSalt(ShiroKit.getRandomSalt(5));
|
user.setPassword(ShiroKit.md5(password, user.getSalt()));
|
user.setRoleid("2");
|
user.setDeptid(25);
|
user.setStatus(1);
|
user.setCreatetime(new Date());
|
user.setRoleType(2);
|
user.setObjectId(tCompany.getId());
|
user.setName(tCompany.getName());
|
user.setSex(1);
|
userService.insert(user);
|
|
//添加经营区域
|
addSocpe(subArr, tCompany.getId());
|
return SUCCESS_TIP;
|
}
|
|
//添加经营区域
|
public void addSocpe(String subArr,Integer id){
|
JSONArray jsonArray = JSON.parseArray(subArr);
|
|
|
List<Integer> integers = new ArrayList<>();
|
for (int i = 0; i < jsonArray.size(); i++) {
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
integers.add(jsonObject.getInteger("recordId"));
|
}
|
|
tCompanyCityService.delete(new EntityWrapper<TCompanyCity>().eq("companyId", id).notIn("id",integers));
|
|
|
int size = jsonArray.size();
|
for (int i = 0; i < size; i++){
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
TCompanyCity tCompanyCity = tCompanyCityService.selectOne(new EntityWrapper<TCompanyCity>().eq("id", jsonObject.getInteger("recordId")).eq("companyId", id));
|
if (SinataUtil.isEmpty(tCompanyCity)){
|
tCompanyCity = new TCompanyCity();
|
tCompanyCity.setProvinceCode(jsonObject.getInteger("provinceCode"));
|
tCompanyCity.setCityCode(jsonObject.getInteger("cityCode"));
|
tCompanyCity.setAreaCode(jsonObject.getInteger("areaCode"));
|
tCompanyCity.setCompanyId(id);
|
tCompanyCity.setState(1);
|
tCompanyCityService.insert(tCompanyCity);
|
}else{
|
tCompanyCity.setProvinceCode(jsonObject.getInteger("provinceCode"));
|
tCompanyCity.setCityCode(jsonObject.getInteger("cityCode"));
|
tCompanyCity.setAreaCode(jsonObject.getInteger("areaCode"));
|
tCompanyCityService.updateById(tCompanyCity);
|
}
|
}
|
}
|
|
/**
|
* 删除分公司管理
|
*/
|
@RequestMapping(value = "/delete")
|
@ResponseBody
|
public Object delete(@RequestParam Integer tCompanyId) {
|
TCompany tCompany = tCompanyService.selectById(tCompanyId);
|
tCompany.setFlag("3");
|
tCompanyService.updateById(tCompany);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 保存平台入口配置,入口名称和URL以后端查询到的菜单信息为准。
|
*/
|
private String saveMenuEntryConfig(String entryConfigArr) {
|
if (ToolUtil.isEmpty(entryConfigArr)) {
|
return null;
|
}
|
// 开通城市id直接取当前登录用户绑定的对象id,不由页面传入。
|
Integer companyId = ShiroKit.getUser().getObjectId();
|
JSONArray jsonArray;
|
try {
|
jsonArray = JSON.parseArray(entryConfigArr);
|
} catch (Exception e) {
|
return "入口配置格式错误";
|
}
|
|
List<MenuEntryConfig> entryConfigList = new ArrayList<>();
|
Date now = new Date();
|
for (int i = 0; i < jsonArray.size(); i++) {
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
Long menuId = jsonObject.getLong("menuId");
|
if (menuId == null) {
|
return "请选择入口";
|
}
|
Menu menu = menuService.selectById(menuId);
|
if (menu == null || !Integer.valueOf(1).equals(menu.getStatus())
|
|| !Integer.valueOf(1).equals(menu.getIsmenu())
|
|| ToolUtil.isEmpty(menu.getUrl())) {
|
return "入口菜单不存在或已禁用";
|
}
|
|
Integer id = jsonObject.getInteger("id");
|
MenuEntryConfig entryConfig = null;
|
if (id != null) {
|
// 只能更新当前开通城市下的入口配置,避免跨城市改数据。
|
entryConfig = menuEntryConfigService.selectOne(
|
new EntityWrapper<MenuEntryConfig>().eq("id", id).eq("openCityId", companyId));
|
if (entryConfig == null) {
|
return "入口配置不存在";
|
}
|
}
|
if (entryConfig == null) {
|
entryConfig = new MenuEntryConfig();
|
entryConfig.setCreateTime(now);
|
entryConfig.setOpenCityId(companyId);
|
}
|
// menuName和entryUrl以后端菜单表为准,不信任前端展示值。
|
entryConfig.setTitle(jsonObject.getString("title"));
|
entryConfig.setMenuId(menu.getId());
|
entryConfig.setMenuName(menu.getName());
|
entryConfig.setEntryUrl(menu.getUrl());
|
entryConfig.setUpdateTime(now);
|
entryConfigList.add(entryConfig);
|
}
|
|
List<Integer> keepIds = new ArrayList<>();
|
for (MenuEntryConfig entryConfig : entryConfigList) {
|
if (entryConfig.getId() == null) {
|
menuEntryConfigService.insert(entryConfig);
|
} else {
|
menuEntryConfigService.updateById(entryConfig);
|
}
|
keepIds.add(entryConfig.getId());
|
}
|
|
Wrapper<MenuEntryConfig> deleteWrapper = new EntityWrapper<MenuEntryConfig>().eq("openCityId", companyId);
|
if (!keepIds.isEmpty()) {
|
deleteWrapper.notIn("id", keepIds);
|
}
|
menuEntryConfigService.delete(deleteWrapper);
|
return null;
|
}
|
|
/**
|
* 修改分公司管理
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
@Transactional(rollbackFor = Exception.class)
|
public Object update(TCompany tCompany,@RequestParam String subArr,String account,String password,Integer userId) {
|
String name = tCompany.getName();
|
name = name.replaceAll("& lt;", "<");
|
name = name.replaceAll("& gt;", ">");
|
name = name.replaceAll("& #40;", "(");
|
name = name.replaceAll("& #41;", ")");
|
tCompany.setName(name);
|
String commissionError = validateBusinessCommission(tCompany);
|
if (commissionError != null) {
|
return commissionError;
|
}
|
TCompany oldCompany = tCompanyService.selectById(tCompany.getId());
|
tCompany.setIsNeedFerry(2);
|
User user = userService.selectById(userId);
|
if(null != user && ToolUtil.isNotEmpty(password)){
|
user.setPassword(ShiroKit.md5(password, user.getSalt()));
|
userService.updateById(user);
|
}
|
|
// ========== 级联更新逻辑 ==========
|
if (oldCompany != null && oldCompany.getType() == 2) {
|
String driverServiceError = validateCancelledServiceDriverUsage(oldCompany, tCompany, true);
|
if (driverServiceError != null) {
|
return driverServiceError;
|
}
|
// 1. 检测并级联更新经营业务
|
cascadeUpdateBusinessScope(oldCompany, tCompany);
|
|
// 2. 更新分公司本身
|
tCompany.setUpdateTime(new Date());
|
tCompanyService.updateById(tCompany);
|
addSocpe(subArr, tCompany.getId());
|
} else {
|
tCompany.setUpdateTime(new Date());
|
tCompanyService.updateById(tCompany);
|
addSocpe(subArr, tCompany.getId());
|
}
|
// ========== 级联更新逻辑结束 ==========
|
|
TCompany tCompany1 = tCompanyService.selectById(tCompany.getId());
|
if (tCompany1.getType() == 1) {
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
if (pushMinistryOfTransport) {//上传平台数据
|
pushMinistryOfTransportUtil.baseInfoCompanyPay();//上传网约车平台公司支付信息
|
pushMinistryOfTransportUtil.baseInfoCompany(tCompany.getId());
|
pushMinistryOfTransportUtil.baseInfoCompanyService();
|
pushMinistryOfTransportUtil.baseInfoCompanyPermit(tCompany.getId());
|
}
|
}
|
}).start();
|
}
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 保存入口设置
|
*/
|
@RequestMapping(value = "/update_entry_config")
|
@ResponseBody
|
@Transactional(rollbackFor = Exception.class)
|
public Object updateEntryConfig(String entryConfigArr) {
|
String entryConfigError = saveMenuEntryConfig(entryConfigArr);
|
if (entryConfigError != null) {
|
return entryConfigError;
|
}
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改加盟商管理
|
*/
|
@RequestMapping(value = "/updateFranchisee")
|
@ResponseBody
|
public Object updateFranchisee(TCompany tCompany,String account,String password,Integer userId) {
|
String name = tCompany.getName();
|
name = name.replaceAll("& lt;", "<");
|
name = name.replaceAll("& gt;", ">");
|
name = name.replaceAll("& #40;", "(");
|
name = name.replaceAll("& #41;", ")");
|
tCompany.setName(name);
|
String commissionError = validateBusinessCommission(tCompany);
|
if (commissionError != null) {
|
return commissionError;
|
}
|
tCompany.setIsNeedFerry(2);
|
TCompany oldCompany = tCompanyService.selectById(tCompany.getId());
|
String driverServiceError = validateCancelledServiceDriverUsage(oldCompany, tCompany, false);
|
if (driverServiceError != null) {
|
return driverServiceError;
|
}
|
tCompany.setUpdateTime(new Date());
|
// tCompany.setVersion(tCompany.getVersion() + 1);
|
tCompanyService.updateById(tCompany);
|
|
//修改账号密码
|
User user = userService.selectById(userId);
|
user.setPassword(ShiroKit.md5(password, user.getSalt()));
|
userService.updateById(user);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 新增加盟商管理
|
*/
|
@RequestMapping(value = "/addFranchisee")
|
@ResponseBody
|
public Object addFranchisee(TCompany tCompany,String account,String password) {
|
String name = tCompany.getName();
|
name = name.replaceAll("& lt;", "<");
|
name = name.replaceAll("& gt;", ">");
|
name = name.replaceAll("& #40;", "(");
|
name = name.replaceAll("& #41;", ")");
|
tCompany.setName(name);
|
//判断账号是否已存在
|
int count = userService.selectCount(new EntityWrapper<User>().eq("account", account));
|
if (count > 0) {
|
return "error";
|
}
|
if(ToolUtil.isEmpty(tCompany.getIdentifier())){
|
return "统一社会信用代码不能为空";
|
}
|
String commissionError = validateBusinessCommission(tCompany);
|
if (commissionError != null) {
|
return commissionError;
|
}
|
tCompany.setIsNeedFerry(2);
|
tCompany.setType(3); //2:分公司
|
if (ShiroKit.getUser().getRoleType() == 2) {
|
tCompany.setSuperiorId(ShiroKit.getUser().getObjectId());
|
}
|
tCompany.setState(0); //0:正常
|
tCompany.setFlag("1");
|
tCompany.setInsertTime(new Date());
|
tCompanyService.insert(tCompany);
|
|
//添加User对象
|
User user = new User();
|
user.setAccount(account);
|
user.setPhone(account);
|
user.setSalt(ShiroKit.getRandomSalt(5));
|
user.setPassword(ShiroKit.md5(password, user.getSalt()));
|
user.setRoleid("3");
|
user.setDeptid(26);
|
user.setStatus(1);
|
user.setCreatetime(new Date());
|
user.setRoleType(3);
|
user.setObjectId(tCompany.getId());
|
user.setName(tCompany.getName());
|
user.setSex(1);
|
userService.insert(user);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 级联更新经营业务
|
* 当分公司取消某项经营业务时,同步更新下属加盟商和司机
|
* @param oldCompany 更新前的分公司数据
|
* @param newCompany 更新后的分公司数据
|
*/
|
private void cascadeUpdateBusinessScope(TCompany oldCompany, TCompany newCompany) {
|
Integer companyId = oldCompany.getId();
|
|
// 1. 找出被取消的经营业务(从1变为2)
|
List<Integer> cancelledServiceTypes = new ArrayList<>();
|
// 快车: isSpe -> type=1
|
if (isServiceCancelled(oldCompany.getIsSpe(), newCompany.getIsSpe())) {
|
cancelledServiceTypes.add(1);
|
}
|
// 出租车: isTaxi -> type=2
|
if (isServiceCancelled(oldCompany.getIsTaxi(), newCompany.getIsTaxi())) {
|
cancelledServiceTypes.add(2);
|
}
|
// 跨城: isCross -> type=3
|
if (isServiceCancelled(oldCompany.getIsCross(), newCompany.getIsCross())) {
|
cancelledServiceTypes.add(3);
|
}
|
// 同城物流: isSameLogistics -> type=4
|
if (isServiceCancelled(oldCompany.getIsSameLogistics(), newCompany.getIsSameLogistics())) {
|
cancelledServiceTypes.add(4);
|
}
|
// 跨城物流: isCrossLogistics -> type=5
|
if (isServiceCancelled(oldCompany.getIsCrossLogistics(), newCompany.getIsCrossLogistics())) {
|
cancelledServiceTypes.add(5);
|
}
|
// 包车: isCharter -> type=6
|
if (isServiceCancelled(oldCompany.getIsCharter(), newCompany.getIsCharter())) {
|
cancelledServiceTypes.add(6);
|
}
|
|
if (cancelledServiceTypes.isEmpty()) {
|
return; // 没有取消任何业务,无需级联更新
|
}
|
|
// 2. 查询该分公司下的所有加盟商
|
List<TCompany> franchiseeList = tCompanyService.selectList(
|
new EntityWrapper<TCompany>()
|
.eq("type", 3)
|
.eq("superiorId", companyId)
|
.ne("flag", "3")
|
);
|
|
// 3. 更新加盟商的经营业务字段
|
for (TCompany franchisee : franchiseeList) {
|
updateFranchiseeBusinessScope(franchisee, cancelledServiceTypes);
|
}
|
|
// 4. 删除分公司直属司机的对应经营业务记录
|
deleteDriverServices(companyId, null, cancelledServiceTypes);
|
|
// 5. 删除分公司直属车辆的对应经营业务记录
|
deleteCarServices(companyId, null, cancelledServiceTypes);
|
|
// 6. 删除加盟商司机和车辆的对应经营业务记录
|
List<Integer> franchiseeIds = franchiseeList.stream()
|
.map(TCompany::getId)
|
.collect(Collectors.toList());
|
|
if (!franchiseeIds.isEmpty()) {
|
for (Integer franchiseeId : franchiseeIds) {
|
deleteDriverServices(null, franchiseeId, cancelledServiceTypes);
|
deleteCarServices(null, franchiseeId, cancelledServiceTypes);
|
}
|
}
|
}
|
|
/**
|
* 判断经营业务是否被取消(从1变为2)
|
* @param oldValue 旧值
|
* @param newValue 新值
|
* @return true表示被取消
|
*/
|
private boolean isServiceCancelled(Integer oldValue, Integer newValue) {
|
return Integer.valueOf(1).equals(oldValue) && Integer.valueOf(2).equals(newValue);
|
}
|
|
/**
|
* 更新加盟商的经营业务字段
|
* @param franchisee 加盟商
|
* @param cancelledTypes 被取消的业务类型列表
|
*/
|
private void updateFranchiseeBusinessScope(TCompany franchisee, List<Integer> cancelledTypes) {
|
boolean needUpdate = false;
|
|
// 快车
|
if (cancelledTypes.contains(1) && Integer.valueOf(1).equals(franchisee.getIsSpe())) {
|
franchisee.setIsSpe(2);
|
needUpdate = true;
|
}
|
// 出租车
|
if (cancelledTypes.contains(2) && Integer.valueOf(1).equals(franchisee.getIsTaxi())) {
|
franchisee.setIsTaxi(2);
|
needUpdate = true;
|
}
|
// 跨城
|
if (cancelledTypes.contains(3) && Integer.valueOf(1).equals(franchisee.getIsCross())) {
|
franchisee.setIsCross(2);
|
needUpdate = true;
|
}
|
// 同城物流
|
if (cancelledTypes.contains(4) && Integer.valueOf(1).equals(franchisee.getIsSameLogistics())) {
|
franchisee.setIsSameLogistics(2);
|
needUpdate = true;
|
}
|
// 跨城物流
|
if (cancelledTypes.contains(5) && Integer.valueOf(1).equals(franchisee.getIsCrossLogistics())) {
|
franchisee.setIsCrossLogistics(2);
|
needUpdate = true;
|
}
|
// 包车
|
if (cancelledTypes.contains(6) && Integer.valueOf(1).equals(franchisee.getIsCharter())) {
|
franchisee.setIsCharter(2);
|
needUpdate = true;
|
}
|
|
if (needUpdate) {
|
franchisee.setUpdateTime(new Date());
|
tCompanyService.updateById(franchisee);
|
}
|
}
|
|
private String validateBusinessCommission(TCompany company) {
|
if (Integer.valueOf(1).equals(company.getIsSpe()) && !hasCommissionSetting(company.getSpe())) {
|
return "请先设置快车司机抽成";
|
}
|
if (Integer.valueOf(1).equals(company.getIsTaxi()) && !hasCommissionSetting(company.getTaxi())) {
|
return "请先设置出租车司机抽成";
|
}
|
if (Integer.valueOf(1).equals(company.getIsCross()) && !hasCommissionSetting(company.getCross())) {
|
return "请先设置跨城出行司机抽成";
|
}
|
return null;
|
}
|
|
private boolean hasCommissionSetting(String configText) {
|
if (SinataUtil.isEmpty(configText)) {
|
return false;
|
}
|
try {
|
JSONObject config = JSON.parseObject(configText);
|
JSONArray rules = config.getJSONArray("rules");
|
if (hasCommissionRule(rules)) {
|
return true;
|
}
|
JSONArray timeRules = config.getJSONArray("time_rules");
|
if (timeRules != null) {
|
for (int i = 0; i < timeRules.size(); i++) {
|
if (hasCommissionRule(timeRules.getJSONArray(i))) {
|
return true;
|
}
|
}
|
}
|
} catch (Exception e) {
|
return false;
|
}
|
return false;
|
}
|
|
private boolean hasCommissionRule(JSONArray rules) {
|
if (rules == null || rules.size() <= 0) {
|
return false;
|
}
|
for (int i = 0; i < rules.size(); i++) {
|
JSONObject rule = rules.getJSONObject(i);
|
if (rule != null && rule.containsKey("percent") && SinataUtil.isNotEmpty(rule.getString("percent"))) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
private String validateCancelledServiceDriverUsage(TCompany oldCompany, TCompany newCompany, boolean includeSubCompanies) {
|
if (oldCompany == null || newCompany == null) {
|
return null;
|
}
|
List<Integer> cancelledTypes = getCancelledCoreServiceTypes(oldCompany, newCompany);
|
if (cancelledTypes.isEmpty()) {
|
return null;
|
}
|
List<Integer> driverIds = getCompanyDriverIds(oldCompany.getId(), includeSubCompanies);
|
if (driverIds.isEmpty()) {
|
return null;
|
}
|
for (Integer cancelledType : cancelledTypes) {
|
if (hasDriverEnabledService(driverIds, cancelledType)) {
|
return "当前公司内存在司机正在使用" + getServiceName(cancelledType) + "业务,无法变动";
|
}
|
}
|
return null;
|
}
|
|
private List<Integer> getCancelledCoreServiceTypes(TCompany oldCompany, TCompany newCompany) {
|
List<Integer> cancelledTypes = new ArrayList<>();
|
if (isServiceCancelled(oldCompany.getIsSpe(), newCompany.getIsSpe())) {
|
cancelledTypes.add(1);
|
}
|
if (isServiceCancelled(oldCompany.getIsTaxi(), newCompany.getIsTaxi())) {
|
cancelledTypes.add(2);
|
}
|
if (isServiceCancelled(oldCompany.getIsCross(), newCompany.getIsCross())) {
|
cancelledTypes.add(3);
|
}
|
return cancelledTypes;
|
}
|
|
private List<Integer> getCompanyDriverIds(Integer companyId, boolean includeSubCompanies) {
|
List<Integer> driverIds = new ArrayList<>();
|
List<Integer> companyIds = new ArrayList<>();
|
addCompanyAndSubCompanyIds(companyIds, companyId, includeSubCompanies);
|
for (Integer id : companyIds) {
|
addDriverIds(driverIds, tDriverService.selectList(new EntityWrapper<TDriver>().ne("flag", "3").eq("companyId", id)));
|
addDriverIds(driverIds, tDriverService.selectList(new EntityWrapper<TDriver>().ne("flag", "3").eq("franchiseeId", id)));
|
}
|
return driverIds;
|
}
|
|
private void addCompanyAndSubCompanyIds(List<Integer> companyIds, Integer companyId, boolean includeSubCompanies) {
|
if (companyId == null || companyIds.contains(companyId)) {
|
return;
|
}
|
companyIds.add(companyId);
|
if (!includeSubCompanies) {
|
return;
|
}
|
List<TCompany> childCompanies = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("superiorId", companyId).ne("flag", "3"));
|
for (TCompany childCompany : childCompanies) {
|
if (childCompany != null) {
|
addCompanyAndSubCompanyIds(companyIds, childCompany.getId(), true);
|
}
|
}
|
}
|
|
private void addDriverIds(List<Integer> driverIds, List<TDriver> drivers) {
|
if (drivers == null) {
|
return;
|
}
|
for (TDriver driver : drivers) {
|
if (driver != null && driver.getId() != null && !driverIds.contains(driver.getId())) {
|
driverIds.add(driver.getId());
|
}
|
}
|
}
|
|
private boolean hasDriverEnabledService(List<Integer> driverIds, Integer serviceType) {
|
if (driverIds == null || driverIds.isEmpty() || serviceType == null) {
|
return false;
|
}
|
return tDriverServiceService.selectCount(new EntityWrapper<TDriverService>()
|
.in("driverId", driverIds)
|
.eq("type", serviceType)) > 0;
|
}
|
|
private String getServiceName(Integer serviceType) {
|
if (Integer.valueOf(1).equals(serviceType)) {
|
return "快车";
|
}
|
if (Integer.valueOf(2).equals(serviceType)) {
|
return "出租车";
|
}
|
if (Integer.valueOf(3).equals(serviceType)) {
|
return "跨城出行";
|
}
|
return "";
|
}
|
|
/**
|
* 删除司机的经营业务记录
|
* @param companyId 分公司ID(查询直属司机时使用)
|
* @param franchiseeId 加盟商ID(查询加盟商司机时使用)
|
* @param serviceTypes 要删除的业务类型列表
|
*/
|
private void deleteDriverServices(Integer companyId, Integer franchiseeId, List<Integer> serviceTypes) {
|
Wrapper<TDriver> wrapper = new EntityWrapper<TDriver>().ne("flag", "3");
|
|
if (companyId != null) {
|
// 查询分公司直属司机(companyId匹配且franchiseeId为空或0)
|
wrapper.eq("companyId", companyId)
|
.andNew()
|
.isNull("franchiseeId")
|
.or()
|
.eq("franchiseeId", 0);
|
} else if (franchiseeId != null) {
|
// 查询加盟商司机
|
wrapper.eq("franchiseeId", franchiseeId);
|
} else {
|
return;
|
}
|
|
List<TDriver> drivers = tDriverService.selectList(wrapper);
|
|
for (TDriver driver : drivers) {
|
tDriverServiceService.delete(
|
new EntityWrapper<TDriverService>()
|
.eq("driverId", driver.getId())
|
.in("type", serviceTypes)
|
);
|
}
|
}
|
|
/**
|
* 删除车辆的经营业务记录
|
* @param companyId 分公司ID(查询直属车辆时使用)
|
* @param franchiseeId 加盟商ID(查询加盟商车辆时使用)
|
* @param serviceTypes 要删除的业务类型列表
|
*/
|
private void deleteCarServices(Integer companyId, Integer franchiseeId, List<Integer> serviceTypes) {
|
Wrapper<TCar> wrapper = new EntityWrapper<TCar>().ne("state", 2);
|
|
if (companyId != null) {
|
// 查询分公司直属车辆(companyId匹配且franchiseeId为空或0)
|
wrapper.eq("companyId", companyId)
|
.andNew()
|
.isNull("franchiseeId")
|
.or()
|
.eq("franchiseeId", 0);
|
} else if (franchiseeId != null) {
|
// 查询加盟商车辆
|
wrapper.eq("franchiseeId", franchiseeId);
|
} else {
|
return;
|
}
|
|
List<TCar> cars = tCarService.selectList(wrapper);
|
|
for (TCar car : cars) {
|
tCarServiceService.delete(
|
new EntityWrapper<TCarService>()
|
.eq("carId", car.getId())
|
.in("type", serviceTypes)
|
);
|
}
|
}
|
|
}
|