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.plugins.Page;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.core.util.DateUtil;
|
import com.stylefeng.guns.core.util.SinataUtil;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import org.springframework.beans.factory.annotation.Value;
|
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.RequestParam;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 分公司管理控制器
|
*
|
* @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 ITCompanyCityService tCompanyCityService;
|
|
@Autowired
|
private ICityService cityService;
|
|
/**
|
* 跳转到修改平台信息
|
*/
|
@RequestMapping("/admin_update")
|
public String tCompanyUpdate(Model model) {
|
TCompany tCompany = tCompanyService.selectOne(new EntityWrapper<TCompany>().eq("type",1).notIn("flag",3));
|
model.addAttribute("item",tCompany);
|
LogObjectHolder.me().set(tCompany);
|
|
//省
|
List<City> cities = cityService.selectList(null);
|
// List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
|
model.addAttribute("city",cities);
|
|
//系统用户对象
|
User user = userService.selectOne(new EntityWrapper<User>().eq("roleType", 1).eq("objectId", tCompany.getId()));
|
model.addAttribute("user",user);
|
|
//经营区域
|
List<Map<String, Object>> scopeList = tCompanyService.getCompanyScopeById(tCompany.getId());
|
model.addAttribute("scopeList",scopeList);
|
return PREFIX + "platformEdit.html";
|
}
|
|
/**
|
* 跳转到分公司管理首页
|
*/
|
@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<City> cities = cityService.selectList(null);
|
model.addAttribute("city",cities);
|
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<City> cities = cityService.selectList(null);
|
model.addAttribute("city",cities);
|
|
//系统用户对象
|
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<City> cities = cityService.selectList(null);
|
model.addAttribute("city",cities);
|
|
//系统用户对象
|
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_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 = "/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) {
|
//判断账号是否已存在
|
int count = userService.selectCount(new EntityWrapper<User>().eq("account", account));
|
if (count > 0){
|
return "error";
|
}
|
tCompany.setType(2); //2:分公司
|
tCompany.setState(0); //0:正常
|
tCompany.setInsertTime(new Date());
|
tCompanyService.insert(tCompany);
|
|
//添加User对象
|
User user = new User();
|
user.setAccount(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){
|
tCompanyCityService.delete(new EntityWrapper<TCompanyCity>().eq("companyId", id));
|
JSONArray jsonArray = JSON.parseArray(subArr);
|
int size = jsonArray.size();
|
List<TCompanyCity> list = new ArrayList<>();
|
for (int i = 0; i < size; i++) {
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
TCompanyCity tCompanyCity = new TCompanyCity();
|
tCompanyCity.setCityId(jsonObject.getInteger("cityId"));
|
tCompanyCity.setCompanyId(id);
|
tCompanyCity.setState(1);
|
list.add(tCompanyCity);
|
}
|
if(list.size() > 0){
|
tCompanyCityService.insertBatch(list);
|
}
|
}
|
|
/**
|
* 新增加盟商管理
|
*/
|
@RequestMapping(value = "/addFranchisee")
|
@ResponseBody
|
public Object addFranchisee(TCompany tCompany,String account,String password) {
|
//判断账号是否已存在
|
int count = userService.selectCount(new EntityWrapper<User>().eq("account", account));
|
if (count > 0){
|
return "error";
|
}
|
tCompany.setType(3); //2:分公司
|
if (ShiroKit.getUser().getRoleType() == 2){
|
tCompany.setSuperiorId(ShiroKit.getUser().getObjectId());
|
}
|
tCompany.setState(0); //0:正常
|
tCompany.setInsertTime(new Date());
|
tCompanyService.insert(tCompany);
|
|
//添加User对象
|
User user = new User();
|
user.setAccount(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;
|
}
|
|
/**
|
* 删除分公司管理
|
*/
|
@RequestMapping(value = "/delete")
|
@ResponseBody
|
public Object delete(@RequestParam Integer tCompanyId) {
|
TCompany tCompany = tCompanyService.selectById(tCompanyId);
|
tCompany.setFlag("3");
|
tCompanyService.updateById(tCompany);
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改分公司管理
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TCompany tCompany,@RequestParam String subArr,String account,String password,Integer userId) {
|
//判断账号
|
User user = userService.selectById(userId);
|
if (SinataUtil.isNotEmpty(account) && SinataUtil.isNotEmpty(password)){
|
if (!user.getAccount().equals(account)){
|
//判断账号是否已存在
|
int count = userService.selectCount(new EntityWrapper<User>().eq("account", account));
|
if (count > 0){
|
return "error";
|
}
|
}
|
//修改账号密码
|
user.setAccount(account);
|
user.setSalt(ShiroKit.getRandomSalt(5));
|
user.setPassword(ShiroKit.md5(password, user.getSalt()));
|
}
|
tCompanyService.updateById(tCompany);
|
user.setName(tCompany.getName());
|
userService.updateById(user);
|
|
//添加经营区域
|
addSocpe(subArr,tCompany.getId());
|
|
TCompany tCompany1 = tCompanyService.selectById(tCompany.getId());
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改加盟商管理
|
*/
|
@RequestMapping(value = "/updateFranchisee")
|
@ResponseBody
|
public Object updateFranchisee(TCompany tCompany,String account,String password,Integer userId) {
|
//判断账号
|
User user = userService.selectById(userId);
|
if (!user.getAccount().equals(account)){
|
//判断账号是否已存在
|
int count = userService.selectCount(new EntityWrapper<User>().eq("account", account));
|
if (count > 0){
|
return "error";
|
}
|
}
|
tCompanyService.updateById(tCompany);
|
|
//修改账号密码
|
user.setAccount(account);
|
user.setSalt(ShiroKit.getRandomSalt(5));
|
user.setPassword(ShiroKit.md5(password, user.getSalt()));
|
user.setName(tCompany.getName());
|
userService.updateById(user);
|
|
return SUCCESS_TIP;
|
}
|
|
}
|