package com.zbooksoft.gdmis.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.ruili.wcp.common.EncryptUtil;
|
import com.ruili.wcp.common.IdGenerater;
|
import com.ruili.wcp.common.LogUtils;
|
import com.ruili.wcp.common.OperateType;
|
import com.ruili.wcp.data.entity.management.*;
|
import com.ruili.wcp.engine.form.IFormData;
|
import com.ruili.wcp.service.management.*;
|
import com.ruili.wcp.web.common.LicenseException;
|
import com.ruili.wcp.web.model.AjaxResponse;
|
import com.ruili.wcp.web.model.ErrorInfo;
|
import com.zbooksoft.gdmis.data.entity.UserCheck;
|
|
import com.zbooksoft.gdmis.data.entity.UtilizationUnit;
|
import com.zbooksoft.gdmis.data.entity.UtilizationUser;
|
import com.zbooksoft.gdmis.service.UserCheckService;
|
|
import com.zbooksoft.gdmis.service.UtilizationUnitService;
|
import com.zbooksoft.gdmis.service.UtilizationUserService;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* @Description:利用用户管理
|
* @Author: zhai
|
* @Date: 2024/8/22
|
**/
|
@Controller
|
@RequestMapping("/utilizationUser")
|
public class UtilizationUserController {
|
@Autowired
|
DeptService deptService;
|
@Autowired
|
JdbcTemplate jdbcTemplate;
|
@Autowired
|
UserService userService;
|
@Autowired
|
RoleService roleService;
|
// @Autowired
|
// UserQuestionService userQuestionService;
|
@Autowired
|
UtilizationUserService utilizationUserService;
|
@Autowired
|
UtilizationUnitService utilizationUnitService;
|
@Autowired
|
KeywordParamService keywordParamService;
|
@Autowired
|
KeywordService keywordService;
|
@Autowired
|
UserCheckService userCheckService;
|
|
@Autowired
|
IFormData iform;
|
|
private static final Logger logger = LoggerFactory.getLogger(UtilizationUserController.class);
|
|
@RequestMapping(value = "/register")
|
public Object register() {
|
return new ModelAndView("gh/utilizationUser/register3");
|
}
|
|
//获取部门信息
|
|
@RequestMapping({"/getDept"})
|
@ResponseBody
|
public Object getDept() {
|
try {
|
List<UtilizationUnit> utilizationUnitList = utilizationUnitService.list();
|
return new AjaxResponse(utilizationUnitList);
|
} catch (Exception e) {
|
logger.error(e.getMessage(), e);
|
return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
|
}
|
|
}
|
|
@RequestMapping({"/getValue"})
|
@ResponseBody
|
public Object getValue(String name) {
|
try {
|
QueryWrapper<Keyword> keywordQueryWrapper = new QueryWrapper<>();
|
keywordQueryWrapper.eq("keyword_name", name);
|
Keyword keyword = keywordService.getOne(keywordQueryWrapper);
|
|
QueryWrapper<KeywordParam> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("keyword_id", keyword.getKeywordId());
|
List<KeywordParam> KeywordParamList = keywordParamService.list(queryWrapper);
|
return new AjaxResponse(KeywordParamList);
|
} catch (Exception e) {
|
logger.error(e.getMessage(), e);
|
return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
|
}
|
|
}
|
|
|
/**
|
* 注册
|
*
|
* @param formData
|
* @param request
|
* @return
|
*/
|
@RequestMapping(value = {"/saveRegister"}, produces = {"application/json; charset=utf-8"}, method = {RequestMethod.POST})
|
@ResponseBody
|
public Object saveRegister(@RequestBody Map<String, Object> formData, HttpServletRequest request) {
|
try {
|
String cardId = formData.get("ID_CARD").toString();
|
String mobile = formData.get("MOBILE").toString();
|
//先判断一些条件(身份证唯一等)
|
String sql = "select ID from UTL_UTILIZATION_USER where ID_CARD = '" + cardId + "'";
|
List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
|
if (maps.size() > 0) {
|
return new AjaxResponse(new ErrorInfo("该身份证已被注册!"), false);
|
}
|
|
String sql2 = "select ID from UTL_UTILIZATION_USER where MOBILE = '" + mobile + "'";
|
List<Map<String, Object>> maps2 = jdbcTemplate.queryForList(sql2);
|
if (maps2.size() > 0) {
|
return new AjaxResponse(new ErrorInfo("该手机号已被注册!"), false);
|
}
|
User user = new User();
|
String userName = formData.get("USER_NAME").toString();
|
String sex = formData.get("SEX").toString();
|
String province = formData.get("PROVINCE").toString();
|
String city = formData.get("CITY").toString();
|
String deptNames = formData.get("DEPT").toString();
|
String deptNature = formData.get("DEPT_NATURE").toString();
|
String deptAddress = formData.get("DEPT_ADDRESS").toString();
|
String postCode = formData.get("POST_CODE").toString();
|
String certificateNumber = formData.get("CERTIFICATE_NUMBER").toString();
|
String job = formData.get("JOB").toString();
|
String telNumber = formData.get("TEL_NUMBER").toString();
|
String email = formData.get("EMAIL").toString();
|
String qqNum = formData.get("QQ_NUM").toString();
|
String projectType = formData.get("PROJECT_TYPE").toString();
|
String projectName = formData.get("PROJECT_NAME").toString();
|
String trade = formData.get("TRADE").toString();
|
String materialScope = formData.get("MATERIAL_SCOPE").toString();
|
String materialPurpose = formData.get("MATERIAL_PURPOSE").toString();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
String applyDate = sdf.format(new Date());
|
|
|
//登录名为身份证号,唯一性
|
user.setUserName(cardId);
|
String pwd = cardId.substring(cardId.length() - 6, cardId.length());
|
String md5Pwd = EncryptUtil.getInstance().MD5(pwd);
|
//默认取身份证后六位作为密码
|
user.setPassword(md5Pwd);
|
user.setTrueName(userName);
|
|
Byte enableLogin = 1;
|
user.setEnableLogin(enableLogin);
|
user.setUserType(1);
|
user.setMobilePhone(mobile);
|
user.setCreateTime(new Date());
|
//用户设置为外部用户
|
LambdaQueryWrapper<Dept> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(Dept::getDeptName, "外部用户");
|
Dept dept = deptService.getOne(wrapper);
|
user.setDeptId(dept.getDeptId());
|
user.setDeptName("外部用户");
|
|
//插入系统用户表
|
userService.saveUser(user);
|
Long userId = user.getUserId();
|
|
//初始化用户默认角色
|
List<Role> roles = roleService.addUserToDefaultRole(user.getUserId());
|
if (roles != null && roles.size() > 0) {
|
for (Role role : roles) {
|
LogUtils.insertLog("角色管理", OperateType.安全操作_新增.toString(), "增加角色内用户", "增加角色【" + role.getRoleName() + "】内用户:" + user.getTrueAndUserName(), "", request);
|
}
|
}
|
//插入利用用户表
|
long id = IdGenerater.getId();
|
HashMap<String, Object> mapData = new HashMap<>();
|
mapData.put("ID", id);
|
mapData.put("ENABLE_LOGIN", enableLogin);
|
mapData.put("PASSWORD", pwd);
|
mapData.put("USER_NAME", userName);
|
mapData.put("SEX", sex);
|
mapData.put("ID_CARD", cardId);
|
mapData.put("PROVINCE", province);
|
mapData.put("CITY", city);
|
mapData.put("DEPT", deptNames);
|
mapData.put("POST_CODE", postCode);
|
mapData.put("DEPT_ADDRESS", deptAddress);
|
mapData.put("MOBILE", mobile);
|
mapData.put("TEL_NUMBER", telNumber);
|
mapData.put("EMAIL", email);
|
mapData.put("QQ_NUM", qqNum);
|
mapData.put("PROJECT_TYPE", projectType);
|
mapData.put("MATERIAL_SCOPE", materialScope);
|
mapData.put("MATERIAL_PURPOSE", materialPurpose);
|
mapData.put("JOB", job);
|
mapData.put("PROJECT_NAME", projectName);
|
mapData.put("DEPT_NATURE", deptNature);
|
mapData.put("TRADE", trade);
|
mapData.put("CERTIFICATE_NUMBER", certificateNumber);
|
mapData.put("USER_ID", userId);
|
mapData.put("APPLY_DATE", applyDate);
|
mapData.put("LOGIN_NAME", cardId);
|
iform.insert(1826177548856377345L, mapData);
|
|
return new AjaxResponse(true);
|
} catch (Exception e) {
|
logger.error("添加注册用户出错", e);
|
return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
|
}
|
}
|
|
/**
|
* 验收是否已经进行了登记
|
*
|
* @param userId
|
* @return
|
*/
|
@RequestMapping({"/getCheckUserInfo"})
|
@ResponseBody
|
public Object getCheckUserInfo(String userId) {
|
try {
|
QueryWrapper<UserCheck> userCheckQueryWrapper = new QueryWrapper<>();
|
userCheckQueryWrapper.eq("UTILIZATION_USER_ID", userId);
|
userCheckQueryWrapper.ge("VALID_END", new Date());
|
int count = userCheckService.count(userCheckQueryWrapper);
|
if (count > 0) {
|
return new AjaxResponse("该用户已经进行了登记");
|
}
|
UtilizationUser utilizationUser = utilizationUserService.getById(userId);
|
return new AjaxResponse(utilizationUser);
|
} catch (Exception e) {
|
logger.error(e.getMessage(), e);
|
return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
|
}
|
}
|
|
// /**
|
// * 到馆登记
|
// *
|
// * @param formData
|
// * @param utilizationUserId
|
// * @return
|
// */
|
// @RequestMapping({"/saveCheckUserInfo"})
|
// @ResponseBody
|
// public Object saveCheckUserInfo(@RequestBody Map<String, Object> formData, String utilizationUserId) {
|
// try {
|
// UserCheck userCheck = new UserCheck();
|
// String userName = formData.get("USER_NAME").toString();
|
// String cardId = formData.get("CARD_ID").toString();
|
// String deptName = formData.get("DEPT_NAME").toString();
|
// String deptNature = formData.get("DEPT_NATURE").toString();
|
// String projectName = formData.get("PROJECT_NAME").toString();
|
// String projectType = formData.get("PROJECT_TYPE").toString();
|
// String borrowUser = formData.get("BORROW_USER").toString();
|
// String materialScope = formData.get("MATERIAL_SCOPE").toString();
|
// String purpose = formData.get("PURPOSE").toString();
|
// String certificateNum = formData.get("CERTIFICATE_NUM").toString();
|
// String validStart = formData.get("VALID_START").toString();
|
// String validEnd = formData.get("VALID_END").toString();
|
// String operatorName = formData.get("OPERATOR_NAME").toString();
|
// String userId = formData.get("USER_ID").toString();
|
// String loginName = formData.get("LOGIN_NAME").toString();
|
//
|
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
// userCheck.setUserName(userName);
|
// userCheck.setUtilizationUserId(Long.parseLong(utilizationUserId));
|
// userCheck.setUserId(Long.parseLong(userId));
|
// userCheck.setCardId(cardId);
|
// userCheck.setDeptName(deptName);
|
// userCheck.setDeptNature(deptNature);
|
// userCheck.setProjectName(projectName);
|
// userCheck.setProjectType(projectType);
|
// userCheck.setBorrowUser(borrowUser);
|
// userCheck.setMaterialScope(materialScope);
|
// userCheck.setPurpose(purpose);
|
// userCheck.setCertificateNum(certificateNum);
|
// userCheck.setValidStart(sdf.parse(validStart));
|
// userCheck.setValidEnd(sdf.parse(validEnd));
|
// userCheck.setOperatorName(operatorName);
|
// userCheck.setRegisterDate(new Date());
|
// userCheck.setLoginName(loginName);
|
// userCheckService.saveOrUpdate(userCheck);
|
// return new AjaxResponse(userCheck);
|
// } catch (Exception e) {
|
// logger.error(e.getMessage(), e);
|
// return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
|
// }
|
// }
|
|
// /**
|
// * 验证是否在有效期内
|
// *
|
// * @param userName
|
// * @return
|
// */
|
// @RequestMapping({"/userVerify"})
|
// @ResponseBody
|
// public Object userVerify(@RequestBody String userName) {
|
// try {
|
// User userByName = userService.getUserByName(userName);
|
// String deptName = userByName.getDeptName();
|
// if (deptName != null && "外部用户".equals(deptName)) {
|
// Date tomorrow = new Date();
|
// Calendar calendar = Calendar.getInstance();
|
// calendar.setTime(tomorrow);
|
// calendar.add(Calendar.DAY_OF_YEAR, -1); // 加一天
|
// tomorrow = calendar.getTime();
|
// QueryWrapper<UserCheck> userCheckQueryWrapper = new QueryWrapper<>();
|
// userCheckQueryWrapper.eq("USER_ID", userByName.getUserId());
|
// userCheckQueryWrapper.ge("VALID_END", tomorrow);
|
// int count = userCheckService.count(userCheckQueryWrapper);
|
// if (count == 0) {
|
// return new AjaxResponse(new ErrorInfo("该用户尚未登记登记"), false);
|
// }
|
//
|
// }
|
// return new AjaxResponse(true);
|
// } catch (Exception e) {
|
// logger.error(e.getMessage(), e);
|
// return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
|
// }
|
//
|
// }
|
|
/**
|
* 满意度调查页面
|
*
|
* @return
|
* @throws LicenseException
|
*/
|
@RequestMapping(value = "/userQuestion")
|
public Object userQuestion() {
|
ModelAndView mav = new ModelAndView("hn/utilizationUser/userQuestion");
|
return mav;
|
}
|
|
|
}
|