qa-prevention-gwj/src/main/java/com/zcloud/controller/xgf/TrainingBatchController.java

401 lines
15 KiB
Java
Raw Normal View History

2023-12-18 20:24:02 +08:00
package com.zcloud.controller.xgf;
import com.alibaba.fastjson.JSONObject;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.service.system.UsersService;
import com.zcloud.service.xgf.TrainingBatchService;
import com.zcloud.util.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.*;
/**
*
* luoxiaobao
* 2023-05-08
* www.zcloudchina.com
*/
@Controller
@RequestMapping("/trainingbatch")
public class TrainingBatchController extends BaseController {
@Autowired
private TrainingBatchService trainingbatchService;
@Autowired
private UsersService usersService;
@Value("${prevention.api.url}")
private String preventionUrl;
/**
*
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/add")
@RequiresPermissions("trainingbatch:add")
@ResponseBody
public Object add() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
trainingbatchService.save(pd);
map.put("result", errInfo);
return map;
}
/**
*
*
* @param out
* @throws Exception
*/
@RequestMapping(value = "/delete")
@RequiresPermissions("trainingbatch:del")
@ResponseBody
public Object delete() throws Exception {
Map<String, String> map = new HashMap<String, String>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
trainingbatchService.delete(pd);
map.put("result", errInfo); //返回结果
return map;
}
/**
*
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/edit")
@RequiresPermissions("trainingbatch:edit")
@ResponseBody
public Object edit() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
trainingbatchService.edit(pd);
map.put("result", errInfo);
return map;
}
/**
*
*
* @param page
* @throws Exception
*/
@RequestMapping(value = "/list")
@RequiresPermissions("trainingbatch:list")
@ResponseBody
public Object list(Page page) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
page.setPd(pd);
List<PageData> varList = trainingbatchService.list(page); //列出TrainingBatch列表
for (PageData x : varList) {
PageData condition = new PageData();
condition.put("USER_ID", x.getString("SUPERVISION_USER_ID"));
Map result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition);
if (result != null) {
x.put("SUPERVISION_USER_NAME", result.get("NAME"));
}
condition.clear();
condition.put("DEPARTMENT_ID", x.getString("SUPERVISION"));
result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition);
if (result != null) {
x.put("SUPERVISION_DEPT_NAME", result.get("NAME"));
}
condition.clear();
condition.put("USER_ID", x.getString("MANAGER_USER_ID"));
result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition);
if (result != null) {
x.put("MANAGER_USER_NAME", result.get("NAME"));
}
condition.clear();
condition.put("DEPARTMENT_ID", x.getString("MANAGER"));
result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition);
if (result != null) {
x.put("MANAGER_DEPT_NAME", result.get("NAME"));
}
condition.clear();
condition.put("USER_ID", x.getString("TERRITORIALITY_USER_ID"));
result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition);
if (result != null) {
x.put("ERRITORIALITY_USER_NAME", result.get("NAME"));
}
condition.clear();
condition.put("DEPARTMENT_ID", x.getString("TERRITORIALITY"));
result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition);
if (result != null) {
x.put("ERRITORIALITY_DEPT_NAME", result.get("NAME"));
}
}
map.put("varList", varList);
map.put("page", page);
map.put("result", errInfo);
return map;
}
/**
*
*
* @param page
* @throws Exception
*/
@RequestMapping(value = "/userList")
@RequiresPermissions("trainingbatch:list")
@ResponseBody
public Object userList(Page page) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
page.setPd(pd);
List<PageData> varList = usersService.flowlistPage(page); //列出TrainingBatch列表
map.put("varList", varList);
map.put("page", page);
map.put("result", errInfo);
return map;
}
/**
*
*
* @param page
* @throws Exception
*/
@RequestMapping(value = "/batchUserList")
@RequiresPermissions("trainingbatch:list")
@ResponseBody
public Object batchUserList(Page page) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
page.setPd(pd);
List<PageData> varList = trainingbatchService.batchUserlistPage(page); //列出TrainingBatch列表
for (PageData x : varList) {
PageData condition = new PageData();
condition.put("USER_ID", x.getString("SUPERVISION_USER_ID"));
Map result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition);
if (result != null) {
x.put("SUPERVISION_USER_NAME", result.get("NAME"));
}
condition.clear();
condition.put("DEPARTMENT_ID", x.getString("SUPERVISION"));
result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition);
if (result != null) {
x.put("SUPERVISION_DEPT_NAME", result.get("NAME"));
}
condition.clear();
condition.put("USER_ID", x.getString("MANAGER_USER_ID"));
result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition);
if (result != null) {
x.put("MANAGER_USER_NAME", result.get("NAME"));
}
condition.clear();
condition.put("DEPARTMENT_ID", x.getString("MANAGER"));
result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition);
if (result != null) {
x.put("MANAGER_DEPT_NAME", result.get("NAME"));
}
condition.clear();
condition.put("USER_ID", x.getString("TERRITORIALITY_USER_ID"));
result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition);
if (result != null) {
x.put("ERRITORIALITY_USER_NAME", result.get("NAME"));
}
condition.clear();
condition.put("DEPARTMENT_ID", x.getString("TERRITORIALITY"));
result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition);
if (result != null) {
x.put("ERRITORIALITY_DEPT_NAME", result.get("NAME"));
}
}
map.put("varList", varList);
map.put("page", page);
map.put("result", errInfo);
return map;
}
/**
*
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/goEdit")
@RequiresPermissions("trainingbatch:edit")
@ResponseBody
public Object goEdit() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
pd = trainingbatchService.findById(pd); //根据ID读取
map.put("pd", pd);
map.put("result", errInfo);
return map;
}
/**
*
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/deleteAll")
@RequiresPermissions("trainingbatch:del")
@ResponseBody
public Object deleteAll() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
String DATA_IDS = pd.getString("DATA_IDS");
if (Tools.notEmpty(DATA_IDS)) {
String ArrayDATA_IDS[] = DATA_IDS.split(",");
trainingbatchService.deleteAll(ArrayDATA_IDS);
errInfo = "success";
} else {
errInfo = "error";
}
map.put("result", errInfo); //返回结果
return map;
}
/**
* excel
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/excel")
@RequiresPermissions("toExcel")
public ModelAndView exportExcel() throws Exception {
ModelAndView mv = new ModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
Map<String, Object> dataMap = new HashMap<String, Object>();
List<String> titles = new ArrayList<String>();
titles.add("创建人"); //1
titles.add("创建时间"); //2
titles.add("修改人"); //3
titles.add("修改时间"); //4
titles.add("是否删除"); //5
titles.add("批次名称"); //6
titles.add("所属企业"); //7
titles.add("培训人数"); //8
titles.add("培训企业"); //9
dataMap.put("titles", titles);
List<PageData> varOList = trainingbatchService.listAll(pd);
List<PageData> varList = new ArrayList<PageData>();
for (int i = 0; i < varOList.size(); i++) {
PageData vpd = new PageData();
vpd.put("var1", varOList.get(i).getString("CREATOR")); //1
vpd.put("var2", varOList.get(i).getString("CREATTIME")); //2
vpd.put("var3", varOList.get(i).getString("OPERATOR")); //3
vpd.put("var4", varOList.get(i).getString("OPERATTIME")); //4
vpd.put("var5", varOList.get(i).get("ISDELETE").toString()); //5
vpd.put("var6", varOList.get(i).getString("BATCH_NAME")); //6
vpd.put("var7", varOList.get(i).getString("CORPINFO_ID")); //7
vpd.put("var8", varOList.get(i).get("USER_COUNT").toString()); //8
vpd.put("var9", varOList.get(i).getString("TRAIN_CORP_DEPT")); //9
varList.add(vpd);
}
dataMap.put("varList", varList);
ObjectExcelView erv = new ObjectExcelView();
mv = new ModelAndView(erv, dataMap);
return mv;
}
@RequestMapping(value = "/sendMessage")
@ResponseBody
@Transactional
public Object sendMessage() throws Exception {
PageData request = this.getPageData();
List<PageData> list = Warden.getList(request.getString("list"));
List<PageData> userList = new ArrayList<>();
for (PageData x : list) {
PageData entity = usersService.getById(x);
Map<Object, Object> map = new HashMap<>(entity);
for (Object key : map.keySet()) {
map.putIfAbsent(key, "");
}
entity.put("CORPINFO_ID", request.get("corp_id"));
userList.add(entity);
// 更新用户信息
PageData info = usersService.findById(entity);
info.put("EMPLOYER", request.get("corp_id"));
info.put("EMPLOYER_NAME", request.get("corp_name"));
info.put("EMPLOY_FLAG", "1");
usersService.editUser(info);
}
PageData info = new PageData();
info.put("infoList", JSONObject.toJSON(userList));
HttpClientUtil.doPost(preventionUrl + "/xfgUser/synchronizationUserInfo", info);
Map<String, Object> response = new HashMap<>();
response.put("result", "success");
return response;
}
@RequestMapping(value = "/submitApplication")
@ResponseBody
@Transactional
public Object submitApplication() throws Exception{
PageData request = this.getPageData();
PageData info = new PageData();
info.put("xgf_user_ids",request.get("xgf_user_ids"));
HttpClientUtil.doPost(preventionUrl + "/xfgUser/approvalApplication", info);
List<String> list = Arrays.asList(request.getString("xgf_user_ids").split(","));
PageData condition = new PageData();
for (String x : list) {
condition.put("USER_ID", x);
PageData entity = usersService.findById(condition);
entity.put("EMPLOY_FLAG", "2");
usersService.editUser(entity);
}
Map<String, Object> response = new HashMap<>();
response.put("result", "success");
return response;
}
}