多单位版国产化地质资料管理系统
zs
2026-02-04 fe02f176b512a9d6a4e12437d929e04e99bb7567
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.zbooksoft.gdmis.common.operate;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruili.wcp.common.EncryptUtil;
import com.ruili.wcp.common.SpringContextUtil;
import com.ruili.wcp.data.entity.management.Dept;
import com.ruili.wcp.data.entity.management.Role;
import com.ruili.wcp.data.entity.management.User;
import com.ruili.wcp.engine.form.IFormData;
import com.ruili.wcp.service.management.DeptService;
import com.ruili.wcp.service.management.RoleService;
import com.ruili.wcp.service.management.UserService;
import com.ruili.wcp.web.model.AjaxResponse;
import com.ruili.wcp.web.model.ErrorInfo;
import com.zbooksoft.gdmis.data.entity.UtilizationUser;
import com.zbooksoft.gdmis.service.UtilizationUserService;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
 
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * @Description:利用审批用户操作
 * @Author: zhai
 * @Date: 2024/8/26
 **/
public class UtilizationUserOperate {
    private static final Logger logger = LoggerFactory.getLogger(UtilizationUserOperate.class);
    JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringContextUtil.getBean("jdbcTemplate");
    UtilizationUserService utilizationUserService = (UtilizationUserService) SpringContextUtil.getBean("utilizationUserServiceImpl");
    UserService userService = (UserService) SpringContextUtil.getBean("userServiceImpl");
    DeptService deptService = (DeptService) SpringContextUtil.getBean("deptServiceImpl");
    RoleService roleService = (RoleService) SpringContextUtil.getBean("roleServiceImpl");
    IFormData iform = (IFormData) SpringContextUtil.getBean("iFormData");
 
    /**
     * 审批通过
     *
     * @param viewId
     * @param idList
     * @return
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    public AjaxResponse registrationApproval(Long viewId, ArrayList<Long> idList) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute("user");
        try {
            String approval = user.getTrueName();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String approvalDate = sdf.format(new Date());
            Long approvalId = user.getUserId();
//            String updateSql = "UPDATE UTL_UTILIZATION_USER SET APPROVAL_DATE ='" + approvalDate + "',APPROVAL_ID =" + approvalId + " , APPROVAL = '" + approval + "' WHERE  ID IN (" + StringUtils.join(idList, ",") + ")";
//            String strSql = "update " + view.getMainTableName() + " set fbzt = 1 , FBRQ = TO_DATE('" + formattedDate + "', 'YYYY-MM-DD')";
            String updateSql = "UPDATE UTL_UTILIZATION_USER SET APPROVAL_DATE = TO_DATE('" + approvalDate + "', 'YYYY-MM-DD'),APPROVAL_ID =" + approvalId + " , APPROVAL = '" + approval + "' WHERE  ID IN (" + StringUtils.join(idList, ",") + ")";
            jdbcTemplate.update(updateSql);
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    /**
     * 删除后事件
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse afterDelete(Long viewId, ArrayList<Long> idList) {
        for (int i = 0; i < idList.size(); i++) {
            try {
                UtilizationUser utilizationUser = utilizationUserService.getById(idList.get(i));
                Long userId = utilizationUser.getUserId();
                userService.removeById(userId);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
            }
        }
        return new AjaxResponse(true);
    }
 
    /**
     * 人工添加利用用户保存后事件
     *
     * @param formId
     * @param keyId
     * @param formData
     * @return
     */
    public AjaxResponse afterSave(Long formId, Long keyId, Map<String, Object> formData) {
 
        String utilizationUserId = formData.get("USER_ID") == null ? "" : formData.get("USER_ID").toString();
        String cardId = formData.get("ID_CARD").toString();
        String mobile = formData.get("MOBILE").toString();
        String userName = formData.get("USER_NAME").toString();
 
        String pwd = cardId.substring(cardId.length() - 6, cardId.length());
        String md5Pwd = EncryptUtil.getInstance().MD5(pwd);
 
        User user = new User();
        if (StringUtils.isNotEmpty(utilizationUserId)) {
            user = userService.getUserById(Long.parseLong(utilizationUserId));
            //登录名为身份证号,唯一性
            user.setUserName(cardId);
            //默认取身份证后六位作为密码
            user.setPassword(md5Pwd);
            user.setTrueName(userName);
            user.setMobilePhone(mobile);
            userService.saveOrUpdate(user);
        } else {
            //登录名为身份证号,唯一性
            user.setUserName(cardId);
            //默认取身份证后六位作为密码
            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();
 
            HashMap<String, Object> insertMap = new HashMap<>();
            insertMap.put("ENABLE_LOGIN", 1);
            insertMap.put("PASSWORD", pwd);
            insertMap.put("LOGIN_NAME", cardId);
            insertMap.put("USER_ID", userId);
            iform.update(1826177548856377345L, insertMap, keyId);
            //初始化用户默认角色
            List<Role> roles = roleService.addUserToDefaultRole(user.getUserId());
 
        }
 
 
        return new AjaxResponse(true);
    }
}