zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package com.shlanbao.tzsc.pms.sys.datadict.service.impl;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
import com.shlanbao.tzsc.utils.tools.FillUserInfoUtil;
import com.shlanbao.tzsc.utils.tools.LogAnno;
import org.apache.commons.lang.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.shlanbao.tzsc.base.dao.DocFileManageDaoI;
import com.shlanbao.tzsc.base.dao.SysEqpCategoryDaoI;
import com.shlanbao.tzsc.base.mapping.DocFilemanage;
import com.shlanbao.tzsc.base.mapping.SysEqpCategory;
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.base.model.PageParams;
import com.shlanbao.tzsc.base.model.SessionInfo;
import com.shlanbao.tzsc.base.service.BaseService;
import com.shlanbao.tzsc.plugin.service.LoadComboboxServiceI;
import com.shlanbao.tzsc.pms.sys.datadict.beans.SysEqpCategoryBean;
import com.shlanbao.tzsc.pms.sys.datadict.service.SysEqpCategoryServiceI;
import com.shlanbao.tzsc.utils.params.ComboboxType;
import com.shlanbao.tzsc.utils.tools.BeanConvertor;
import com.shlanbao.tzsc.utils.tools.StringUtil;
 
@Service
public class SysEqpCategoryServiceImpl extends BaseService implements SysEqpCategoryServiceI {
    @Autowired
    protected SysEqpCategoryDaoI sysEqpCategoryDao;
    @Autowired
    protected DocFileManageDaoI docFileManageDao;
    @Autowired
    private LoadComboboxServiceI  comboboxServiceI;
    @Autowired
    private HttpServletRequest request;
    @LogAnno(operateType = "数据字典新增")
    @Override
    public void addMdCategory(SysEqpCategory mdEqpCategory) throws Exception {
            SysEqpCategory categroy = null;        
            //categroy = sysEqpCategoryDao.findById(SysEqpCategory.class, mdEqpCategory.getId());    
            categroy = mdEqpCategory;
            categroy.setDel("0");
            categroy.setId(UUID.randomUUID().toString());
        FillUserInfoUtil.fillCreateUserInfo(categroy,request);
        sysEqpCategoryDao.save(categroy);
        //comboboxServiceI.initCombobox(ComboboxType.EQPCATEGORY);
    }
 
    @Override
    public SysEqpCategory getMdCategoryById(String id) throws Exception {
        return sysEqpCategoryDao.findById(SysEqpCategory.class, id);
    }
 
    @Override
    public DataGrid queryMdCategory(SysEqpCategory mdEqpCategory,PageParams pageParams) throws Exception {
        
        StringBuffer whereSql = new StringBuffer();//设置查询参数
        if(StringUtil.notNull(mdEqpCategory.getCode())){
            whereSql.append(" and o.code like '%" + mdEqpCategory.getCode() +"%'");
        }
        if(StringUtil.notNull(mdEqpCategory.getName())){
            whereSql.append(" and o.name like '%" + mdEqpCategory.getName() +"%'");
        }
        if(StringUtil.notNull(mdEqpCategory.getEqpType())){
            whereSql.append(" and o.name like '%"+mdEqpCategory.getEqpType()+"%'");
        }
        if(StringUtil.notNull(mdEqpCategory.getCycleType())){
            whereSql.append(" and o.cycle_type='"+mdEqpCategory.getCycleType()+"' ");
        }
        //总记录数============================================================================================
        long total= 0;
        List<SysEqpCategoryBean> lastRows = new ArrayList<SysEqpCategoryBean>();
        String countSql =" select  count(o.id) from SYS_EQP_CATEGORY o where o.DEL=0  and o.maintainace_type='"+mdEqpCategory.getMaintainaceType()+"'";
        List<?> list = sysEqpCategoryDao.queryBySql(countSql+whereSql.toString(), null);//只会有一条记录
        if(null!=list&&list.size()>0){
            Object arr=(Object) list.get(0);//返回一个对象,而不是 一组数组
            total =Long.parseLong(ObjectUtils.toString(arr));
        }
        //===================================================================================================
        if(total>0){
            StringBuffer lastSql = new StringBuffer();    
            lastSql.append("SELECT * FROM ( ");
            lastSql.append("SELECT ROWNUM as rownumber,o. ID,o.code,o. NAME,o.DES,o.ENABLE,o.DEl,o.maintainace_type,o.CYCLE_NUM,o.CYCLE_TYPE,o.CREATE_USER_NAME,o.CREATE_USER_TIME,o.UPDATE_USER_NAME,o.UPDATE_USER_TIME FROM SYS_EQP_CATEGORY o WHERE o.DEL = 0 ");
            lastSql.append(" and o.maintainace_type='"+mdEqpCategory.getMaintainaceType()+"'");
            lastSql.append(whereSql);
            lastSql.append(")temp1 where  temp1.rownumber>").append(((pageParams.getPage()-1)*pageParams.getRows()))
            .append(" and temp1.rownumber<=").append((pageParams.getPage()*pageParams.getRows())).append(" ");
            
            list = sysEqpCategoryDao.queryBySql(lastSql.toString(), null);
            if(null!=list&&list.size()>0){
                SysEqpCategoryBean bean = null;
                for(int i=0;i<list.size();i++){
                    bean = new SysEqpCategoryBean();
                    Object[] arr=(Object[]) list.get(i);
                    bean.setId(ObjectUtils.toString(arr[1]));
                    bean.setCode(ObjectUtils.toString(arr[2]));
                    bean.setName(ObjectUtils.toString(arr[3]));
                    bean.setDes(ObjectUtils.toString(arr[4]));
                    String enable = ObjectUtils.toString(arr[5]);
                    if(null!=enable&&!"".equals(enable)){
                        bean.setEnable(Long.parseLong(enable));
                    }
                    bean.setDel(ObjectUtils.toString(arr[6]));
                    bean.setCycleNum(ObjectUtils.toString(arr[7]));
                    bean.setCycleType(ObjectUtils.toString(arr[8]));
                    bean.setCreateUserName(arr[10]==null?null:StringUtil.convertObjToString(arr[10]));
                    bean.setCreateUserTime(arr[11]==null?null:(Date) arr[11]);
                    bean.setUpdateUserName(arr[12]==null?null:StringUtil.convertObjToString(arr[12]));
                    bean.setUpdateUserTime(arr[13]==null?null:(Date) arr[13]);
                    lastRows.add(bean);
                }
            }
        }
        return new DataGrid(lastRows, total);
    }
 
    @LogAnno(operateType = "删除设备类型")
    @Override
    public void deleteMdCategory(String id) throws Exception {
        String sql = "delete from SYS_EQP_CATEGORY where ID='"+id+"'";
        sysEqpCategoryDao.updateBySql(sql, null);
        String typesql = "delete from SYS_EQP_TYPE where CID='"+id+"'";
        sysEqpCategoryDao.updateBySql(typesql, null);
        comboboxServiceI.initCombobox(ComboboxType.EQPCATEGORY);
    }
 
    @Override
    public List<SysEqpCategoryBean> queryMdCategory() throws Exception {
        String hql = "from SysEqpCategory o where 1=1 and o.enable=1 and o.del=0";
        List<SysEqpCategoryBean> mdeqpcategropbean=beanConvertor.copyList(sysEqpCategoryDao.query(hql, new Object[]{}), SysEqpCategoryBean.class);
        return mdeqpcategropbean;
    }
 
    @LogAnno(operateType = "修改设备类型")
    @Override
    public void updateCategory(SysEqpCategoryBean mdEqpCategoryBean) throws Exception {
        mdEqpCategoryBean.setDel("0");
        SysEqpCategory o = BeanConvertor.copyProperties(mdEqpCategoryBean, SysEqpCategory.class);
        SysEqpCategory sysEqpCategory = sysEqpCategoryDao.findById(SysEqpCategory.class, mdEqpCategoryBean.getId());
        BeanConvertor.copyProperties(o,sysEqpCategory);
        FillUserInfoUtil.fillUpdateUserInfo(sysEqpCategory,request);
        sysEqpCategoryDao.saveOrUpdate(sysEqpCategory);
        //comboboxServiceI.initCombobox(ComboboxType.EQPCATEGORY);
    }
    
 
    @Override
    public DocFilemanage fileUpdate(String otherTableId,HttpSession session, HttpServletRequest request,
            SysEqpCategoryBean fmBean) throws Exception {
        request.setCharacterEncoding("utf-8");
        SessionInfo sessionInfo = (SessionInfo) session.getAttribute("sessionInfo");
        //获取文件名
        String[] fileUrls = (String[])request.getParameterValues("fileUrl")[0].split(",");
        String[] fileNames = (String[])request.getParameterValues("fileName")[0].split(",");
        //删除原有图片 保证图片唯一
        String updateSql ="update DOC_FILEMANAGE set IS_DELETED=1  where TABLE_ZJ_ID=? ";
        List<Object> objs = new ArrayList<Object>();
        objs.add(otherTableId);
        docFileManageDao.updateBySql(updateSql, objs);
        
        Long l = Long.valueOf(request.getParameter("securityLevel"));
        DocFilemanage file = null;
        for (int i = 0; i < fileUrls.length; i++) {//这里应该只有一张图片上传
            String uuIdKey = UUID.randomUUID().toString() ;
            file = new DocFilemanage();
            file.setAttr1(fmBean.getImagesVersion());//版本号
            file.setCreatePersonId(sessionInfo.getUser().getId());//新增用户
            file.setCreateName(sessionInfo.getUser().getName());
            file.setCreateTime(new Date());
            file.setIsDeleted("0");
            file.setSecurityLevel(l);
            file.setFileId(fileUrls[i]);
            file.setFileName(fileNames[i].substring(0,fileNames[i].lastIndexOf(".")));
            file.setFileType(fileUrls[i].substring(fileUrls[i].lastIndexOf(".")+1));
            file.setId(uuIdKey);
            file.setTableZjId(otherTableId);
            String key = docFileManageDao.saveBackKey(file);
            file.setId(key);
            file.setTableZjId(otherTableId);
        }
        //更新它下面的 所有子项为 null
        updateSql ="update SYS_EQP_TYPE set SET_IMAGE_POINT=null  where CID=? and DEL=0 ";
        objs = new ArrayList<Object>();
        objs.add(otherTableId);
        docFileManageDao.updateBySql(updateSql, objs);
        return file;
    }
    @Override
    public int updateCategory(DocFilemanage file){
        //回写主表 主键 和 上传的地址
        String updateSql ="update SYS_EQP_CATEGORY set UPLOAD_ID=? where ID=? ";
        List<Object> prams = new ArrayList<Object>();
        prams.add(file.getId());prams.add(file.getTableZjId());
        return docFileManageDao.updateBySql(updateSql, prams);
    }
 
    @Override
    public void batchDeleteMdCategory(String ids) {
        try {
            String[] split=ids.split(",");
            for (int i = 0; i < split.length; i++) {
                String id = split[i];
                String sql = "delete from SYS_EQP_CATEGORY where ID='"+id+"'";
                sysEqpCategoryDao.updateBySql(sql, null);
                String typesql = "delete from SYS_EQP_TYPE where CID='"+id+"'";
                sysEqpCategoryDao.updateBySql(typesql, null);
            }
            comboboxServiceI.initCombobox(ComboboxType.EQPCATEGORY);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
}