fs-danaus
2022-05-11 d24ea3d93ce60607b52d2245d2b6a5812fc5a4d6
提交 | 用户 | age
a6a76f 1 package com.yc.api.controller;
F 2
493df4 3 import com.alibaba.fastjson.JSON;
a6a76f 4 import com.google.gson.JsonObject;
F 5 import com.yc.action.BaseAction;
6 import com.yc.action.grid.GridUtils;
7 import com.yc.action.grid.TreeGridDTO;
8 import com.yc.action.new38action.Type38action;
9 import com.yc.action.panval.DocNavigation;
10 import com.yc.action.upload.AttachmentAction;
11 import com.yc.action.upload.PostBeanInfo;
d77745 12 import com.yc.api.bean.*;
a6a76f 13 import com.yc.api.service.ApiServiceIfc;
F 14 import com.yc.api.utils.FileUtil;
15 import com.yc.entity.AttachmentConfig;
d24ea3 16 import com.yc.entity.UserAccountEntity;
a6a76f 17 import com.yc.exception.ApplicationException;
F 18 import com.yc.exception.CallBackMessage;
19 import com.yc.factory.FactoryBean;
20 import com.yc.ionic.action.LinksBean;
21 import com.yc.ionic.schedule.ZipUtil;
22 import com.yc.multiData.SpObserver;
23 import com.yc.sdk.password.action.ChangePassword;
24 import com.yc.sdk.shopping.action.VerificationCodes;
25 import com.yc.sdk.shopping.action.api.InvitationCode;
26 import com.yc.service.BaseService;
27 import com.yc.service.build.top.BuildTopIfc;
28 import com.yc.service.grid.GridServiceIfc;
29 import com.yc.service.sqlformat.entity.SqlFormatEntity;
30 import com.yc.service.sqlformat.utils.SqlFormatUtils;
d24ea3 31 import com.yc.service.user.UserAccountServiceIfc;
a6a76f 32 import com.yc.utils.EncodeUtil;
F 33 import com.yc.utils.SessionKey;
34 import org.apache.commons.io.FileUtils;
35 import org.apache.commons.lang3.StringUtils;
36 import org.springframework.beans.factory.annotation.Autowired;
a34567 37 import org.springframework.dao.EmptyResultDataAccessException;
a6a76f 38 import org.springframework.data.redis.core.RedisTemplate;
F 39 import org.springframework.jdbc.support.rowset.SqlRowSet;
40 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
41 import org.springframework.stereotype.Controller;
42 import org.springframework.web.bind.annotation.*;
43 import org.springframework.web.context.request.async.WebAsyncTask;
44
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
47 import java.io.File;
48 import java.io.IOException;
d24ea3 49 import java.net.URLDecoder;
a6a76f 50 import java.sql.SQLException;
F 51 import java.util.ArrayList;
52 import java.util.HashMap;
53 import java.util.List;
54 import java.util.Map;
55 import java.util.concurrent.Callable;
56 import java.util.concurrent.TimeUnit;
57
58 import static java.util.stream.Collectors.toList;
59
60 @Controller
61 public class ApiController extends BaseAction {
62
63     @Autowired
64     GridServiceIfc gridService;
65     @Autowired
66     RedisTemplate redisTemplate;
67     @Autowired
68     ThreadPoolTaskExecutor threadPoolExecutor;
d77745 69     @Autowired
F 70     ApiServiceIfc apiServiceIfc;
a6a76f 71     private static String sysfunclink = "b.[origformid]            " +
F 72             ",b.[origformtype]         " +
73             ",b.[sortid]               " +
74             ",b.[linklabel]            " +
75             ",b.[linkformid]           " +
76             ",b.[linkformtype]         " +
77             ",b.[linkdescribe]         " +
78             ",b.[linkmode]             " +
79             ",b.[hotkey]               " +
80             ",b.[spfield]              " +
81             ",b.[close_origform]       " +
82             ",b.[origfields]           " +
83             ",b.[linkfields]           " +
84             ",b.[orighdfields]         " +
85             ",b.[linkhdfields]         " +
86             ",b.[efilter]              " +
87             ",b.[warnmessage]          " +
88             ",b.[self_datafields]      " +
89             ",b.[link_datafields]      " +
90             ",b.[firstrecord_editmode] " +
91             ",b.[return_one_record]    " +
92             ",b.[numfieldid]           " +
93             ",b.[locksqlwhere]         " +
94             ",b.[showbutton]           " +
95             ",b.[returndataset]        " +
96             ",b.[refresh_origform]     " +
97             ",b.[numfieldid_origform]  " +
98             ",b.[noshowspmessage]      " +
99             ",b.[linkformdisplayfields]" +
100             ",b.[ftlockconditionflag]  " +
101             ",b.[groupname]            " +
102             ",b.[navigateyn]           " +
103             ",b.[editstatus]           " +
104             ",b.[isshowpwdedit]        " +
105             ",b.[selectchecker]        " +
106             ",b.[returncurchecker]     " +
107             ",b.[returncurcheckername] " +
108             ",b.[smallimagefilename]   " +
109             ",b.[smallimagefilepath]   " +
110             ",b.[ft]                   " +
111             ",b.[ftformtype]           " +
112             ",b.[fk]                   " +
113             ",b.[seekgroupid]          " +
114             ",b.[spremissfield]        " +
115             ",b.[dpremissfield]        " +
116             ",b.[fkefilter]            " +
117             ",b.[isautosaved]          " +
118             ",b.[showitemexpression]   " +
119             ",b.[linkscope]            ";
120
121     private static String gformFilter = "[formid]            " +
122             ",[statisid]         " +
123             ",[fieldid]          " +
124             ",[fieldname]        " +
125             ",[ft]               " +
126             ",[ftformtype]       " +
127             ",[emptyrefdata]     " +
128             ",[fk]               " +
129             ",[seekgroupid]      " +
130             ",[spremissfield]    " +
131             ",[dpremissfield]    " +
132             ",[efilter]          " +
133             ",[return_one_record]" +
134             ",[numfieldid]        " +
135             ",[visible]           " +
136             ",[hidelabel]         " +
137             ",[controltype]       " +
138             ",[rowno]             " +
139             ",[colno]             " +
140             ",[lengthnum]         " +
141             ",[heightnum]         " +
142             ",[initvalue]         " +
143             ",[compsingle]        " +
144             ",[sqlscript]         " +
145             ",[memo]              ";
146     private static String sysmasterdetail = "[formid]   " +
147             ",[detailformid]    " +
148             ",[masterfield]     " +
149             ",[masterkeys]      " +
150             ",[detailkeys]      " +
151             ",[mastersumfields] " +
152             ",[detailsumfields] " +
153             ",[detailreadonly]  " +
154             ",[detailmemo]      " +
155             ",[sequenceid]      " +
156             ",[gridheight]      ";
157
158     private static String systreeset = "[formid]              " +
159             ",[formtype]           " +
160             ",[treeformid]         " +
161             ",[treeName]           " +
162             ",[SortID]             " +
163             ",[keyfield]           " +
164             ",[parentfield]        " +
165             ",[nodeid]             " +
166             ",[listfield]          " +
167             ",[displayfield]       " +
168             ",[separatedst]        " +
169             ",[treefield]          " +
170             ",[autocodefield]      " +
171             ",[treefilterstr]      " +
172             ",[authcheck]          " +
173             ",[allowdrag]          " +
174             ",[defNodeTypeFilter]  " +
175             ",[startnodetypefilter]" +
176             ",[treewidth]";
177
178     private static String TabPageFormid = "[mainformid]      " +
179             ",[mainformname]   " +
180             ",[FormGroupID]    " +
181             ",[FormGroupName] " +
182             ",[SortBy]        " +
183             ",[formid]        " +
184             ",[formname]      " +
185             ",[formtype]      " +
186             ",[LabelName]     " +
187             ",[FT]            " +
188             ",[FTName]        " +
189             ",[FK]            " +
190             ",[SeekGroupID]   " +
191             ",[GridHeight]    " +
192             ",[GroupID]       " +
193             ",[GroupName]     " +
194             ",[TabID]         " +
195             ",[TabName]         " +
196             ",[TabHeight]     " +
197             ",[isStartupCollapsed]";
198     private static String table3 =
199             "a.[buttonID]              ," +
200                     "a.[ButtonName]            ," +
201                     "a.[formid]                ," +
202                     "a.[headflag]              ," +
203                     "a.[fieldid]               ," +
204                     "a.[docitem]               ," +
205                     "a.[ProcName]              ," +
206                     "a.[Memo]                  ," +
207                     "a.[isShowPwdEdit]         ," +
208                     "a.[editStatus]            ," +
209                     "a.[SelectChecker]         ," +
210                     "a.[ReturnCurChecker]      ," +
211                     "a.[ReturnCurCheckerName]  ," +
212                     "a.[FT]                    ," +
213                     "a.[FTFormType]            ," +
214                     "a.[FK]                    ," +
215                     "a.[SeekGroupID]           ," +
216                     "a.[sPremissField]         ," +
217                     "a.[dPremissField]         ," +
218                     "a.[FKeFilter]             ," +
219                     "a.[isAutoSaved]           ," +
220                     "a.[showItemExpression]    ," +
221                     "a.[isInspection]          ," +
222                     "a.[isExchangeDataWithHost]," +
223                     "a.[UrlShowLocation]       ," +
224                     "a.[ExternalURL],           " +
225                     "b.[IconPath],b.[isReturnToLastPage]          \n ";
226
227     private String getDataType = "set nocount on select\n" +
228             "col.COLUMN_NAME as ColumnName,\n" +
229             "col.DATA_TYPE as DataType,\n" +
230             "col.CHARACTER_OCTET_LENGTH as DataLength\n" +
231             "--col.IS_NULLABLE as IsNullable,\n" +
232             "--ccu.CONSTRAINT_NAME as IsPrimaryKey,\n" +
233             "--de.value as Description\n" +
234             "from INFORMATION_SCHEMA.COLUMNS col\n" +
235             "left join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu\n" +
236             "on ccu.TABLE_NAME=col.TABLE_NAME\n" +
237             "and ccu.COLUMN_NAME=col.COLUMN_NAME\n" +
238             "and ccu.CONSTRAINT_NAME like 'PK_%'\n" +
239             "left join ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', ?,'column', default) as de\n" +
240             "on col.COLUMN_NAME = de.objname COLLATE Chinese_PRC_CI_AS\n" +
241             "where col.TABLE_NAME=?";
242
243     /**
08505f 244      * 出库扫序列号,检验是否与当前单据匹配
d77745 245      * 1,如果不存在则返回错误,提示所扫的物料不在当前出库单
F 246      * 2,如果有一个或多个结果,则返回给前端选择
247      */
08505f 248     @RequestMapping(value = "/qr/ScanSerialNumberOut.do")
d77745 249     @ResponseBody
08505f 250     public Object scanSerialNumberOut(@RequestBody SerialNumberEntity entity, HttpServletRequest request) {
d77745 251         CallBackMessage callBackMessage = new CallBackMessage();
F 252         try {
253             SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
254             if (StringUtils.isBlank(entity.getDocCode())) {
255                 throw new ApplicationException("单号不能为空");
256             }
257             if (StringUtils.isBlank(entity.getSerialNumber())) {
258                 throw new ApplicationException("序列号不能为空");
259             }
260             if (entity.getFormid() == null || entity.getFormid().intValue() == 0) {
261                 throw new ApplicationException("功能号不能为空");
262             }
263             if (entity.getFormType() == null || entity.getFormType().intValue() == 0) {
264                 throw new ApplicationException("功能类型不能为空");
265             }
08505f 266             final Map map = apiServiceIfc.getMatCodeBySerialNumberOut(entity);
F 267
d77745 268             if (GridUtils.prossRowSetDataType_Int(map, "state") == 0) {
493df4 269                 if (GridUtils.prossRowSetDataType_Int(map, "Status") == 2) {
F 270                     throw new ApplicationException(String.format("该序列号【%s】已经出库,不允许重复出库", entity.getSerialNumber()));
08505f 271                 }
d77745 272                 //表示序列号对应的物料存在于当前单据
F 273                 map.remove("state");
274                 callBackMessage.sendSuccessMessageByDefault();
275                 callBackMessage.setInfo(map);
276             } else {
277                 //表示序列号对应的物料不存在于当前单据,拿错物料
278                 callBackMessage.sendErrorMessage("所扫物料不属于当前单据");
279                 map.remove("state");
280                 callBackMessage.setInfo(map);
281             }
282             return callBackMessage.toJSONObject();
493df4 283         } catch (EmptyResultDataAccessException ex) {
F 284             callBackMessage.sendErrorMessage(String.format("序列号【%s】不存在于当前库存,请检查", entity.getSerialNumber()));
a34567 285             return callBackMessage.toJSONObject();
493df4 286         } catch (Exception e) {
d77745 287             callBackMessage.sendErrorMessage(e.getMessage());
F 288             return callBackMessage.toJSONObject();
289         } finally {
290             SpObserver.setDBtoInstance();
291         }
292
293     }
493df4 294
08505f 295     /**
F 296      * 入库扫序列号,检验是否与当前单据匹配
297      * 1,如果不存在则返回错误,提示所扫的物料不在当前出库单
298      * 2,如果有一个或多个结果,则返回给前端选择
299      */
300     @RequestMapping(value = "/qr/ScanSerialNumberIn.do")
301     @ResponseBody
302     public Object scanSerialNumberIn(@RequestBody SerialNumberEntity entity, HttpServletRequest request) {
303         CallBackMessage callBackMessage = new CallBackMessage();
304         try {
305             SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
306             if (StringUtils.isBlank(entity.getDocCode())) {
307                 throw new ApplicationException("单号不能为空");
308             }
309             if (StringUtils.isBlank(entity.getSerialNumber())) {
310                 throw new ApplicationException("序列号不能为空");
311             }
312             if (entity.getFormid() == null || entity.getFormid().intValue() == 0) {
313                 throw new ApplicationException("功能号不能为空");
314             }
315             if (entity.getFormType() == null || entity.getFormType().intValue() == 0) {
316                 throw new ApplicationException("功能类型不能为空");
317             }
318             if (StringUtils.isBlank(entity.getMatCode())) {
319                 throw new ApplicationException("物料编号不能为空");
320             }
493df4 321             Map map = apiServiceIfc.getMatCodeBySerialNumberIn(entity);
08505f 322             if (GridUtils.prossRowSetDataType_Int(map, "state") == 0) {
F 323                 //表示序列号对应的物料存在于当前单据
324                 map.remove("state");
325                 callBackMessage.sendSuccessMessageByDefault();
326                 callBackMessage.setInfo(map);
327             } else {
328                 //表示序列号已入库,弹出提示,不能录入
493df4 329                 throw new ApplicationException(String.format("该序列号【%s】已经存在,不允许重复入库", entity.getSerialNumber()));
F 330             }
08505f 331             return callBackMessage.toJSONObject();
493df4 332         } catch (Exception e) {
08505f 333             callBackMessage.sendErrorMessage(e.getMessage());
F 334             return callBackMessage.toJSONObject();
335         } finally {
336             SpObserver.setDBtoInstance();
337         }
d77745 338
08505f 339     }
493df4 340
d77745 341     /**
F 342      * 显示当前单据已扫的序列号列表
343      */
344     @RequestMapping(value = "/qr/showSerialNumberInfo.do")
345     @ResponseBody
346     public Object showSerialNumberInfo(@RequestBody SerialNumberEntity entity, HttpServletRequest request) {
347         CallBackMessage callBackMessage = new CallBackMessage();
348         try {
349             SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
350             if (StringUtils.isBlank(entity.getDocCode())) {
351                 throw new ApplicationException("单号不能为空");
352             }
353             if (entity.getFormid() == null || entity.getFormid().intValue() == 0) {
354                 throw new ApplicationException("功能号不能为空");
355             }
356             if (entity.getFormType() == null || entity.getFormType().intValue() == 0) {
357                 throw new ApplicationException("功能类型不能为空");
358             }
359             final List<T110503Entity> t110503Entities = apiServiceIfc.showSerialNumberList(entity);
360             callBackMessage.setInfo(t110503Entities);
361             callBackMessage.sendSuccessMessageByDefault();
362             return callBackMessage.toJSONObject();
363         } catch (Exception e) {
364             callBackMessage.sendErrorMessage(e.getMessage());
365             return callBackMessage.toJSONObject();
366         } finally {
367             SpObserver.setDBtoInstance();
368         }
369
370     }
371
372     /**
a6a76f 373      * 取功能号在9801,9802的设置
F 374      */
375     @RequestMapping(value = "/formSetting.do", method = RequestMethod.GET)
376     public void get9802Info(String formid, HttpServletRequest request, HttpServletResponse response) {
377         String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
378         try {
379             SpObserver.setDBtoInstance("_" + dbid);
380             if (formid == null || "".equals(formid)) {
381                 CallBackMessage callBackMessage = new CallBackMessage();
382                 callBackMessage.sendErrorMessage("formid不能为空");
383                 this.printJson(response, callBackMessage.toString());
384                 return;
385             }
386
387             int int_formid = 0;
388             int formType = 0;
389             String[] content = formid.split(";");
390             try {
391                 int_formid = Integer.parseInt(content[0]);
392                 if (content.length == 2) {
393                     formType = Integer.parseInt(content[1]);
394                 }
395             } catch (Exception e) {
396                 CallBackMessage callBackMessage = new CallBackMessage();
397                 callBackMessage.sendErrorMessage(e.getMessage());
398                 this.printJson(response, callBackMessage.toString());
399                 return;
400             }
401             Map<String, Object> map = new HashMap<String, Object>();
402             if (formType == 0) {
403                 try {
404                     formType = gridService.getWindowTypeByGform(int_formid);
405                 } catch (Exception e) {
406                     CallBackMessage callBackMessage = new CallBackMessage();
407                     callBackMessage.sendErrorMessage(int_formid + "在9810查找不到窗体类型信息" + e.getMessage());
408                     this.printJson(response, callBackMessage.toString());
409                     return;
410                 }
411             }
412             map.put("formType", formType);
413             //主从表表名
414             String hdTable = "";//主表
415             String dtTable = "";//从表
416             Map<String, Object> gform = gridService.getSimpleJdbcTemplate().queryForMap(gridService.getGET_GFORM().toLowerCase(), int_formid);
417             map.put("9801", gform);
418             hdTable = GridUtils.prossRowSetDataType_String(gform, "hdtable");
419             dtTable = GridUtils.prossRowSetDataType_String(gform, "dttable");
420
421             map.put("9802", gridService.getSimpleJdbcTemplate().queryForList("set nocount on ; select " + gridService.getGET_GFIELD().toLowerCase() + " from gfield where formid=?  order by statisid asc", int_formid));
422
423             //自定义时间查询
424             map.put("9816", gridService.getSimpleJdbcTemplate().queryForList("set nocount on select  datefield,begindatestr,enddatestr,docstate,ShowAllNopost,dateLimitYn,MonthRangeYN,selfdocYn,hidescrapYn from _sysdatefilter  where formid=? ", int_formid));
425             //功能链接 by19-74 去掉,修改为通过另外接口直接把处理好的数据返回
426             //map.put("9842", gridService.getSimpleJdbcTemplate().queryForList("select " + sysfunclink + "  from _sysfunclink  where origformid=? order by  sortid asc ", formid));
427             map.put("9842", "[]");
428
429             if (formType == 497 || formType == 499 || formType == 15 || formType == 17 || formType == 9 || formType == 496 || formType == 498 || formType == 8 || formType == 16 || formType == 5) {
430                 //单据状态值
431
432                 map.put("9815", gridService.getSimpleJdbcTemplate().queryForList("set nocount on select dictvalue,interValue from _sysdict where dictid=(select DocStatusName from gform where formid=?)", int_formid));
433
434                 //单据表头过滤设置
435
436                 map.put("9743", gridService.getSimpleJdbcTemplate().queryForList("set nocount on select " + gformFilter + " from gformFilter where formid=? order by StatisID asc ", int_formid));
437
438                 //OA按钮设置
439
440                 map.put("9881", gridService.getSimpleJdbcTemplate().queryForList("set nocount on select " + table3 + " from gfieldApprovedButton a left join t111634 b on a.ButtonName=b.ButtonName where a.formid=? order by a.[docitem] asc", int_formid));
441
442             }
443
444
445             //3表设置
446             if (formType == 15 || formType == 77) {
447
448                 map.put("9825", gridService.getSimpleJdbcTemplate().queryForList("set nocount on select " + sysmasterdetail + " from _sysmasterdetail where formid=?", int_formid));
449             }
450             //树设置
451             if (formType == 2 || formType == 3 || formType == 4 || formType == 20 ||
452                     formType == 301 || formType == 302 || formType == 304 || formType == 238 ||
453                     formType == 30) {
454                 final List<Map<String, Object>> list = gridService.getSimpleJdbcTemplate().queryForList("set nocount on select " + systreeset + " from _systreeset where formid=?", int_formid);
455                 map.put("9824", list);
456                 if (list != null && list.size() > 0) {
457                     //增加树过滤条件
458                     final SqlFormatEntity sqlFormatByEntity = SqlFormatUtils.createSQLFormatByEntity(list.get(0), 9824);
459                     map.put("treefilterstr", sqlFormatByEntity);
460                 }
461             }
462             //496多表设置
d77745 463             if (formType == 497 || formType == 499 || formType == 496 || formType == 498) {
a6a76f 464
F 465                 map.put("9771", gridService.getSimpleJdbcTemplate().queryForList("set nocount on select " + TabPageFormid + " from _sys_TabPageFormid where mainformid=? and Actived=1 order by TabID asc ,SortBy asc ", int_formid));
466
467             }
468             //表字段的数据类型信息(int ,varchar....)
469             if (formType != 18 && formType != 19 && formType != 38) {//18,19,38查询类型,不需要取数据类型
470                 if (!"".equals(hdTable))
471                     map.put(hdTable, gridService.getSimpleJdbcTemplate().queryForList(getDataType, hdTable, hdTable));
472                 if (!"".equals(dtTable))
473                     map.put(dtTable, gridService.getSimpleJdbcTemplate().queryForList(getDataType, dtTable, dtTable));
474             }
475             if (formType == 38) {
476                 final Type38action type38action = (Type38action) FactoryBean.getBean("type38action");
477                 map.put("queryList", type38action.get38TypeInfo(request, response, int_formid));
478             }
479             this.printJson(response, GridUtils.toJson(map));
480         } catch (Exception e) {
481             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(e) + "\"}");
482         } finally {
483             SpObserver.setDBtoInstance();
484         }
485     }
486
487     /**
488      * 获取流程跟踪信息
489      */
490     @RequestMapping(value = "/processTrack.do", method = RequestMethod.GET)
491     public void getprocess(int formid, String doccode, HttpServletRequest request, HttpServletResponse response) {// 修改待办事宜为已读状
492         List<?> list = null;
493         String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
494         try {
495             SpObserver.setDBtoInstance("_" + dbid);
496
497             list = gridService.getSimpleJdbcTemplate().queryForList("set nocount on select doccode,id,username,inserttime,nextcheckercode,nextcheckername,curstatus,msg from spickorderlog with (nolock) where doccode=? and formid=? order by  doccode,inserttime asc", doccode.replace("'", ""), formid);
498
499             this.printJson(response, GridUtils.toJson(list));
500         } catch (Exception e) {
501             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(e) + "\"}");
502         } finally {
503             SpObserver.setDBtoInstance();
504         }
505     }
506     /**
507      *
508      * APP 用户注册
509      */
510 //    @RequestMapping(value="/reg.do", method = RequestMethod.POST)
511 //    public @ResponseBody Map register(@RequestBody RegisterUser user, HttpServletRequest request, HttpServletResponse response) {//
512 //    //1验证手机
513 //
514 //    }
515
516     /***
517      *用在多表中取得子功能号的列表数据,用在点击功能链接时替换参数
518      * @param info
519      * @param request
520      * @param response
521      * @return
522      */
523     @RequestMapping(value = "/getFormList.do", method = RequestMethod.POST)
524     public @ResponseBody
525     List<Map<String, Object>> getFormList(@RequestBody FristForm info, HttpServletRequest request, HttpServletResponse response) {
526         String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
527         try {
528             SpObserver.setDBtoInstance("_" + dbid);
529             //通过功能号和类型取得对应的表名
530             TreeGridDTO dto = new TreeGridDTO();
531             dto.dbid = dbid;
532             this.getTableName(Integer.parseInt(info.getFormid()), info.getFormtype(), dto);
533
534             String sql = "set nocount on select " + info.getFields() + " from " + dto.table + " where " + info.getWhere();
535
536             return gridService.getJdbcTemplate().queryForList(sql);
537         } catch (Exception ex) {
538             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}");
539         } finally {
540             SpObserver.setDBtoInstance();
541         }
542         return null;
543     }
544
545     @RequestMapping(value = "/api/upPortraitV2.do", method = RequestMethod.POST)
546     @CrossOrigin
547     public @ResponseBody
548     Object uploadPortraitV2(HttpServletRequest request, HttpServletResponse response) {
549         CallBackMessage callBackMessage = new CallBackMessage();
550         try {
551             AttachmentAction attachmentAction = (AttachmentAction) FactoryBean.getBean("attachmentAction");
552             PostBeanInfo postBeanInfo = attachmentAction.prossParameter(request);
553             SpObserver.setDBtoInstance("_" + postBeanInfo.getDbid());
554             postBeanInfo.setFormid(0);
555             postBeanInfo.setFieldid("");
556             Object result = attachmentAction.doPostAttachmentV2(postBeanInfo, request, response);
557             if (result instanceof Map) {
558                 //TODO 更新用户表相关字段
559                 ApiServiceIfc apiServiceIfc = (ApiServiceIfc) FactoryBean.getBean("apiService");
560                 int count = apiServiceIfc.uploadPortrait(postBeanInfo.getUsercode(), ((Map) result).get("uuid") + "");
561                 if (count > 0) {
562                     return result;
563                 } else {
564                     throw new ApplicationException("更新用户头像失败");
565                 }
566             } else if (result instanceof JsonObject) {
567                 return result;
568             }
569         } catch (Exception ex) {
570             callBackMessage.sendErrorMessage(this.getErrorMsg(ex));
571             return callBackMessage;
572         } finally {
573             SpObserver.setDBtoInstance();
574         }
575         return null;
576     }
577
578     /***
579      *上传用户头像
580      * @param request
581      * @param response
582      * @return
583      */
584     @RequestMapping(value = "/api/upPortrait.do", method = RequestMethod.POST)
585     public @ResponseBody
586     List<Map<String, Object>> uploadPortrait(HttpServletRequest request, HttpServletResponse response) {
587         String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
588         try {
589             SpObserver.setDBtoInstance("_" + dbid);
590             AttachmentAction attachmentAction = (AttachmentAction) FactoryBean.getBean("attachmentAction");
591             request.setAttribute("formid", 0);
592             request.setAttribute("type", 0);
593             Object result = attachmentAction.doPostAttachment(request, response);
594             if (result instanceof Map) {
595                 //TODO 更新用户表相关字段
596                 String userCode = (String) request.getSession().getAttribute(SessionKey.HRCODE);
597                 ApiServiceIfc apiServiceIfc = (ApiServiceIfc) FactoryBean.getBean("apiService");
598                 int count = apiServiceIfc.uploadPortrait(userCode, ((Map) result).get("uuid") + "");
599                 if (count > 0) {
600                     printJson(response, GridUtils.toJson(result));
601                 } else {
602                     throw new ApplicationException("更新用户头像失败");
603                 }
604             } else if (result instanceof JsonObject) {
605                 printJson(response, result.toString());
606             }
607         } catch (Exception ex) {
608             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}");
609         } finally {
610             SpObserver.setDBtoInstance();
611         }
612         return null;
613     }
614
615     /***
616      * Ionic APP更新调用接口,下载更新包,新版本用这个接口
617      * @param json
618      * @param request
619      * @param response
620      */
621     @Deprecated
622     @RequestMapping(value = "/app/getZip.do", method = RequestMethod.POST)
623     public void chcpUpdateZip(@RequestBody ChcpInfo json, HttpServletRequest request, HttpServletResponse response) {
624         //creatFileToZip(json, response);
625     }
626
627     /***
628      * Ionic APP更新调用接口,下载更新包
629      * @param json
630      * @param request
631      * @param response
632      */
633     @Deprecated
634     @RequestMapping(value = "/v", method = RequestMethod.POST)
635     public void chcpUpdate(@RequestBody ChcpInfo json, HttpServletRequest request, HttpServletResponse response) {
636         //creatFileToZip(json, response);
637
638     }
639
640     public void creatFileToZip(@RequestBody ChcpInfo json, HttpServletResponse response) {
641         //String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
642         //pc生成app页面所在的路径
643         String webUrl = AttachmentConfig.get("Ionic.webUrl");
644         //app下载更新包所在的路径
645         String appUrl = AttachmentConfig.get("Ionic.PageUrl");
646
647         try {
648             //文件的根目录
649             String webRoot = webUrl + json.dbname + File.separator + "ionic_chcp" + File.separator + "www" + File.separator;
650             long timestamp = System.currentTimeMillis();
651             String tempRoot = appUrl + json.dbname + File.separator + json.dbname + "_" + timestamp;
652             List<String> others = json.other;
653
654             //    第一次下载时直接下载已存在的;
655             if (json.frist == 1) {
656                 //基础包
657                 String zip = appUrl + json.dbname + File.separator + json.dbname + ".zip";
658                 File file = new File(zip);
659                 //存在则直接下载
660                 if (file.exists()) {
661                     FileUtil.downloadFile(file, response, false);
662                 } else {//生成基础包再下载
663                     extracted(others, webRoot, tempRoot, json, timestamp, appUrl + json.dbname + File.separator, response);
664                 }
665             } else {
666                 extracted(others, webRoot, tempRoot, json, timestamp, appUrl + json.dbname + File.separator, response);
667             }
668
669         } finally {
670             //    SpObserver.setDBtoInstance();
671         }
672     }
673
674     private void extracted(List<String> others, String webRoot, String appRoot, ChcpInfo json, long timestamp, String appBaseUrl, HttpServletResponse response) {
675         try {
676             if (json.frist == 0) {
677                 //1,处理other里面的文件
678                 for (String str : others) {
679                     //copy单文件到对应目录的文件
680                     FileUtils.copyFile(new File(webRoot + str), new File(appRoot + File.separator + str));
681                 }
682                 //----增加把chcp.json,chcp.manifest 二个文件也copy过去,保持当前的状态,而不是每次下载基础包都是
683                 //用最新的版本做比对,之前存在着取了最新的版本,丢失了中间更新的部分页面,导致需要更新的功能号页面,得不到更新,是旧的或是找不到页面的情况
684                 FileUtils.copyFile(new File(webRoot + "chcp.json"), new File(appRoot + File.separator + "chcp.json"));
685                 FileUtils.copyFile(new File(webRoot + "chcp.manifest"), new File(appRoot + File.separator + "chcp.manifest"));
686                 //----
687                 //2,处理formids,这里需要根据formid,dbid组装路径来copy目录下面的文件
688                 if (!"".equals(json.formids) && json.frist == 0) {
689                     String[] formids = json.formids.split(";");
690                     int total = formids.length;
691                     String from = null;
692                     String to = null;
693                     System.out.println(json.dbname + "->" + timestamp + "--需要处理formids-:【" + json.formids.toString() + "】");
694                     //-----把相关信息写到数据库,用作跟踪调试
695 //                BaseService baseService=(BaseService) FactoryBean.getBean("BaseService");
696 //                try {
697 //                    SpObserver.setDBtoDemo();
698 //                    baseService.getSimpleJdbcTemplate().queryForObject("set nocount on \n insert into appinfo(dbName,info,[timestamps],usercode) values (?,?,?,?);", Integer.class, json.dbname, GridUtils.toJson(json), timestamp,json.usercode);
699 //                }catch (Exception e){
700 //                    e.printStackTrace();
701 //                }finally {
702 //                    SpObserver.setDBtoInstance();
703 //                }
704                     //------
705                     for (int i = 0; i < total; i++) {
706                         from = webRoot + "app" + File.separator + json.dbid + File.separator + formids[i];
707                         to = appRoot + File.separator + "app" + File.separator + json.dbid + File.separator;
708                         FileUtils.copyDirectoryToDirectory(new File(from), new File(to));
709                     }
710                 }
711                 String zipName = json.dbname + "_" + timestamp + ".zip";
712                 String appPath = appBaseUrl + json.dbname + "_" + timestamp;
713                 zipAndDownload(appPath, appBaseUrl, zipName, response, true);
714             } else {//新增全新下载,把整个目录copy过来生成zip包
715                 File[] files = new File(webRoot).listFiles();
716                 String appPath = appBaseUrl + json.dbname;
717                 if (files != null) {
718                     for (File file : files) {
719                         if (file.isDirectory()) {
720                             FileUtils.copyDirectoryToDirectory(file, new File(appBaseUrl + File.separator + json.dbname));
721                         } else {
722                             FileUtils.copyFileToDirectory(file, new File(appPath));
723                         }
724                     }
725                 }
726                 String zipName = json.dbname + ".zip";
727                 zipAndDownload(appPath, appBaseUrl, zipName, response, false);
728             }
729
730         } catch (IOException e) {
731             e.printStackTrace();
732         }
733     }
734
735     public static void zipAndDownload(String appPath, String appRoot, String zip, HttpServletResponse response, boolean isDelete) {
736         try {
737
738             ZipUtil.zip(appPath, null, null);
739             File file = new File(appRoot);
740             if (file.exists()) {//存在则直接下载
741                 FileUtil.downloadFile(file, response, isDelete);
742             }
743         } catch (Exception e) {
744             e.printStackTrace();
745         }
746     }
747
748     /**
493df4 749      * 清除个人格线cookie数据
F 750      */
751     @RequestMapping(value = "/grid/clearCookie.do")
752     public @ResponseBody
753     Object clearCookie(Integer formid, String cookieType, HttpServletRequest request, HttpServletResponse response) {
754         CallBackMessage callBackMessage = new CallBackMessage();
755         String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
756         String userCode = request.getSession().getAttribute(SessionKey.USERCODE) + "";
757         try {
758             SpObserver.setDBtoInstance("_" + dbid);
759             if (formid == null || formid == 0) {
760                 throw new ApplicationException("功能号不能为空");
761             }
762             apiServiceIfc.clearCookie(userCode, formid, cookieType);
763             callBackMessage.sendSuccessMessageByDefault();
764             return callBackMessage.toJSONObject();
765         } catch (Exception ex) {
766             callBackMessage.sendErrorMessage(this.getErrorMsg(ex));
767             return callBackMessage.toJSONObject();
768         } finally {
769             SpObserver.setDBtoInstance();
770         }
771     }
772
773     /**
a6a76f 774      * 保存格线cookie
F 775      */
493df4 776     @RequestMapping(value = "/grid/cookie.do", method = RequestMethod.POST)
a6a76f 777     public @ResponseBody
493df4 778     WebAsyncTask GridCookie(CookieEntity cookieEntity, HttpServletRequest request, HttpServletResponse response) {
a6a76f 779         String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
F 780         String userCode = request.getSession().getAttribute(SessionKey.USERCODE) + "";
781         CallBackMessage callBackMessage = new CallBackMessage();
493df4 782         if (StringUtils.isNotBlank(request.getParameter("_pop_json"))) {
F 783             cookieEntity = JSON.parseObject(request.getParameter("_pop_json"), CookieEntity.class);
784         }
785         Callable<Object> callable = new GridCookiesCallable(cookieEntity, userCode, dbid, gridService);
a6a76f 786         //定义超时15秒
F 787         WebAsyncTask asyncTask = new WebAsyncTask(TimeUnit.SECONDS.toMillis(15), threadPoolExecutor, callable);
788         asyncTask.onCompletion(
789                 () -> log.info("执行成功")
790         );
791         asyncTask.onError(
792                 (Callable<Object>) () -> {
793                     log.info("执行出错");
794                     callBackMessage.sendErrorMessage("执行出错,请重新操作");
795                     return callBackMessage.toJSONObject();
796                 }
797         );
798         asyncTask.onTimeout(
799                 (Callable<Object>) () -> {
800                     log.info("执行超时");
801                     callBackMessage.sendErrorMessage("执行超时,请重新操作");
802                     return callBackMessage.toJSONObject();
803                 }
804         );
805         return asyncTask;
806     }
807
808     /**
809      * 取功能号对应的自动编号信息
810      */
811     @RequestMapping(value = "/autocodeInfo.do", method = RequestMethod.GET)
812     public @ResponseBody
813     Map<String, Object> getAutoCodeInfo(String formid, HttpServletRequest request, HttpServletResponse response) {
814         String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
815         try {
816             SpObserver.setDBtoInstance("_" + dbid);
817
818             String sql = "set nocount on select g.formid,g.codelength,g.preFixcode,g.precodetype,c.Formtype,c.Curcode,c.Fieldid from gform g,_sysautocode c where g.formid=c.formid and g.formid=?";
819
820             return gridService.getJdbcTemplate().queryForMap(sql, new Object[]{formid});
821         } catch (Exception ex) {
822             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}");
823         } finally {
824             SpObserver.setDBtoInstance();
825         }
826         return null;
827     }
828
829     /**
830      * 取回符合条件的功能链接
831      *
832      * @param bean
833      * @param request
834      * @param response
835      * @return
836      */
837     @RequestMapping(value = "/getFunLinksV2.do", method = RequestMethod.POST)
838     public @ResponseBody
839     Object getFunLinksV2(@RequestBody LinksBean bean, HttpServletRequest request,
840                          HttpServletResponse response) {
841         Map map = new HashMap();
842         try {
843             Object object = this.getFunLinks(bean, request, response);
844             //增加单号导航
845             List docNavList = new ArrayList();
846             //有单号才执行
847             if (StringUtils.isNotBlank(bean.getDoccode()) && (bean.getFormtype() == 5 || bean.getFormtype() == 8 || (bean.getFormtype() == 16 && bean.getIsMutType() == 0) || bean.getFormtype() == 496 || bean.getFormtype() == 498)) {
848                 DocNavigation docNavigation = (DocNavigation) FactoryBean.getBean("docNavigation");
849                 docNavList = docNavigation.getDocNavigation(bean.getFormid(), bean.getDoccode(), request, response);
850             }
851             map.put("links", object);
852             map.put("docNav", docNavList);
853         } catch (Exception ex) {
854             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}");
855         }
856         return map;
857     }
858
859     /**
860      * 取回符合条件的功能链接
861      *
862      * @param bean
863      * @param request
864      * @param response
865      * @return
866      */
867     @RequestMapping(value = "/getFunLinks.do", method = RequestMethod.POST)
868     public @ResponseBody
869     Object getFunLinks(@RequestBody LinksBean bean, HttpServletRequest request,
870                        HttpServletResponse response) {
871
872         try {
873             SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
874             List<Map<String, Object>> list = null;//所有功能链接集合
875             BaseService baseService = (BaseService) FactoryBean.getBean("BaseService");
876             String sql = "set nocount on select  " + sysfunclink +
877                     ",a.largImagePath from _sysfunclink b left join _sysMenu a on b.linkformid=cast(a.formid as varchar(20)) where b.origformid=? and b.origformtype=? order by b.sortid asc \n";
878             //496多表
879             if (bean.getFormtype() == 496 || bean.getFormtype() == 498) {
880                 sql = "set nocount on \n select  " + sysfunclink +
881                         " ,c.largImagePath from _sysFuncLink b left join _sysMenu c on b.linkformid=cast(c.formid as varchar(20)) \n" +
882                         "where exists(select 1 from _sys_TabPageFormid a where a.mainformid = ? \n" +
883                         "   and a.formid = b.origformid \n" +
884                         "   and ((a.mainformid = a.formid and b.origformtype = 496) \n" +
885                         "   or (a.mainformid <> a.formid and  a.formtype = b.origformtype ))\n" +
886                         "   )\n" +
887                         " order by b.origformid asc ,b.sortid asc \n";
888                 list = baseService.getSimpleJdbcTemplate().queryForList(sql, bean.getFormid());
889             } else {
890                 list = baseService.getSimpleJdbcTemplate().queryForList(sql, bean.getFormid(), bean.getFormtype());
891
892             }
893             List<Map<String, Object>> result = new ArrayList<>();
894             BuildTopIfc buildTopIfc = (BuildTopIfc) FactoryBean.getBean("BuildTopImpl");
895             String tempFormid = null;
896             if (list != null && list.size() > 0) {
897                 for (int k = 0; k < list.size(); k++) {
898                     Map<String, Object> tempMap = list.get(k);
899                     String formid = tempMap.get("origformid") + "";
900                     if (tempFormid != null) {
901                         if (tempFormid.equalsIgnoreCase(formid))
902                             continue;
903                     }
904                     tempFormid = formid;
905                     final List<Map<String, Object>> tempList = list.stream().filter(x -> (x.get("origformid") != null && formid.equals(x.get("origformid") + ""))).collect(toList());//处理同一个功能号里所有表达式的数据
906                     final List<Map<String, Object>> collectNotitemexpression = list.stream().filter(x ->
907                             (x.get("origformid") != null && formid.equals(x.get("origformid") + ""))
908                                     && (x.get("showitemexpression") == null || "".equals(x.get("showitemexpression")))
909                                     && (//处理editstatus有值的情况
910                                     StringUtils.isBlank(bean.getDoccode())//新单
911                                             && (x.get("editstatus") != null && StringUtils.isNotBlank(x.get("editstatus") + "") ? ((";" + x.get("editstatus") + ";").contains(";0;")) : true)
912                             )
913                     ).collect(toList());//没有表达式的数据
914
915                     Map<String, Object> map = buildTopIfc.buildFuncLinkExpression_APPV2(Integer.parseInt(formid), Integer.parseInt(tempMap.get("origformtype") + ""), bean.getDoccode(), request, request.getSession(), tempList);
916                     if (map != null) {//有结果
917                         for (Map.Entry<String, Object> entry : map.entrySet()) {
918                             if ("1".equals(entry.getValue() + "")) {//取值为1,表示有权限,(没有表达式的也在里面设置为1)
919                                 String[] key = entry.getKey().split("_");
920                                 result.addAll(
921                                         tempList.stream().filter(obj -> (obj.get("sortid") + "").equals(key[1] + "") && (obj.get("linkformid") + "").equals(key[0] + "")).collect(toList()
922                                         ));
923                             }
924                         }
925
926                     } else {//条件不成立,返回null,则取没有表达式的链接
927                         result.addAll(collectNotitemexpression);
928                     }
929                 }
930             }
931             return result;
932         } catch (Exception ex) {
933             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}");
934         } finally {
935             SpObserver.setDBtoInstance();
936         }
937         return null;
938     }
939
940     /**
941      * 9802设置不感应,但可能数据库存在有字段
942      * 获取表的字段和数据类型,因为存在,表示要在页面显示出来,但在新增,修改时需要过滤
943      *
944      * @param tablename
945      * @param request
946      * @param response
947      * @return
948      */
949     @RequestMapping(value = "/api/getColumnsInfo.do", method = RequestMethod.GET)
950     public @ResponseBody
951     Object getColumnsInfo(String tablename, HttpServletRequest request,
952                           HttpServletResponse response) {
953
954         List<Map<String, Object>> list = null;
955         try {
956             SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
957             list = gridService.getSimpleJdbcTemplate().queryForList("set nocount on ; select column_name ,data_type from INFORMATION_SCHEMA.columns  where table_name=?", tablename);
958             return list;
959         } catch (Exception ex) {
960             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}");
961         } finally {
962             SpObserver.setDBtoInstance();
963         }
964         return null;
965     }
966
967     /**
968      * 取22类型存储过程参数列表
969      */
970     @RequestMapping(value = "/get22ParamInfo.do", method = RequestMethod.POST)
971     public @ResponseBody
972     String getPrimKey(@RequestParam String formid,
973                       HttpServletRequest request, HttpServletResponse response) {// 修改待办事宜为已读状态
974         try {
975             String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
976             SpObserver.setDBtoInstance("_" + dbid);
d77745 977             String cols = this.gridService.getSimpleJdbcTemplate().queryForObject(" select stuff((SELECT ',''' + CONVERT(VARCHAR,  isnull(b.fieldid,''))+'''' from gField b where   b.isload=1 and b.headflag=0 and  \n" +
F 978                     "formid=? and isnull(DataLink,0)=1 order by StatisID asc  FOR XML PATH ('')),1,1,'')", String.class, formid);
979             if (cols == null || "".equalsIgnoreCase(cols)) {
980                 throw new ApplicationException(formid + "在9802字段列表为空,请在9802添加参数字段定义或查看字段的【感应】参数是否选上");
a6a76f 981             }
d77745 982             return "[" + (cols == null ? "" : cols) + "]";
a6a76f 983         } catch (Exception ex) {
F 984             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}");
985         } finally {
986             SpObserver.setDBtoInstance();
987         }
988         return null;
989     }
990
991     /**
992      * 修改密码,通过手机验证码和新密码修改密码
993      */
994     @SuppressWarnings("unchecked")
995     @RequestMapping(value = "/api/forgotPwd.do", method = RequestMethod.POST)
996     public void changePwd(@RequestBody PwdBean json, HttpServletRequest request, HttpServletResponse response) {
997         JsonObject rightJson = new JsonObject();
998         JsonObject errJson = new JsonObject();
999         if (json.getTel() == null || "null".equalsIgnoreCase(json.getTel()) || "".equalsIgnoreCase(json.getTel())) {
1000             errJson.addProperty("error", "手机号不能为空");
1001         }
1002         if (json.getNewPwd() == null || "null".equalsIgnoreCase(json.getNewPwd()) || "".equalsIgnoreCase(json.getNewPwd())) {
1003             errJson.addProperty("error", "新密码不能为空");
1004         }
1005         if (json.getCode() == null || "null".equalsIgnoreCase(json.getCode()) || "".equalsIgnoreCase(json.getCode())) {
1006             errJson.addProperty("error", "验证码不能为空");
1007         }
1008         if (errJson != null && errJson.has("error")) {
1009             this.printJson(response, errJson.toString());
1010             return;
1011         }
1012         String tel = EncodeUtil.replaceUrlChar(json.getTel());
1013         if (tel.length() > 20) {//表示已加密,需要解密
1014             try {
1015                 tel = ChangePassword.getDecryptPassword(tel);
1016             } catch (Exception e) {
1017                 e.printStackTrace();
1018             }
1019         }
1020         //1,验证手机验证码
1021         InvitationCode invitationCode = (InvitationCode) FactoryBean.getBean("invitationCode");
1022         boolean flg = invitationCode.verificationCode(response, tel, json.getCode(), rightJson, errJson);
1023         if (!flg) {
1024             //2,执行修改密码功能
1025
1026             try {
1027                 SpObserver.setDBtoDemo();
1028                 String pwd_str = EncodeUtil.replaceUrlChar(json.getNewPwd());
1029
1030                 if (pwd_str.length() < 30) {//明文,需要加密密码保存
1031                     pwd_str = ChangePassword.getEncryptPassword(pwd_str);
1032                 }
d24ea3 1033                 String result = apiServiceIfc.doUpdateUserPwd(pwd_str, tel);
F 1034                 if (result !=null) {
a6a76f 1035                     redisTemplate.delete(VerificationCodes.getCodeKey(json.getTel()));
F 1036                     rightJson.addProperty("status", "密码修改成功!");
d24ea3 1037                     UserPwdEntity entity=new UserPwdEntity();
F 1038                     entity.setTel(tel);
1039                     entity.setNewPwd(pwd_str);
1040                     entity.setDbIdList(result);
1041                     entity.setType("app");//表示由app端调用
1042                     threadPoolExecutor.execute(new UpdateUserPassWordThread(entity));
a6a76f 1043                 } else {
F 1044                     errJson.addProperty("error", "密码修改出错!");
1045                 }
1046             } catch (Exception e) {
1047                 e.printStackTrace();
1048                 errJson.addProperty("info", this.getErrorMsg(e));
1049                 rightJson.add("error", errJson);
1050             } finally {
1051                 SpObserver.setDBtoInstance();
1052             }
1053             this.printJson(response, rightJson.toString());
1054         }
1055     }
d24ea3 1056     /**
F 1057      * 接收推送过来的修改密码请求
1058      */
1059     @SuppressWarnings("unchecked")
1060     @RequestMapping(value = "/open/mutual/updateUserPwd.do", method = RequestMethod.POST)
1061     public void updateUserPwd(HttpServletRequest request, HttpServletResponse response) {
1062         try{
1063             String data = URLDecoder.decode(request.getParameter("data"), "utf-8");
1064             UserPwdEntity entity = JSON.parseObject(data, UserPwdEntity.class);
1065             SpObserver.setDBtoInstance("_" + entity.getDbId());
1066             UserAccountServiceIfc userAccountServiceIfc = (UserAccountServiceIfc) FactoryBean.getBean("UserAccountServiceImpl");
1067             final UserAccountEntity userInfoByTelephone = userAccountServiceIfc.getUserInfoByTelephone(entity.getTel());
1068             if (userInfoByTelephone != null && StringUtils.isNotBlank(userInfoByTelephone.getUserCode())) {
1069                 userAccountServiceIfc.savePassword(userInfoByTelephone.getUserCode(), entity.getNewPwd(), userInfoByTelephone.getUserCode());
1070                 System.out.println("dbid:"+entity.getDbId()+"完成");
1071             }
1072         }catch(Exception ex){
1073             ex.printStackTrace();
1074         }finally {
1075             SpObserver.setDBtoInstance();
1076         }
a6a76f 1077
d24ea3 1078     }
a6a76f 1079     /**
F 1080      * 发手机验证码
1081      */
1082     @RequestMapping(value = "/api/sendSms.do", method = RequestMethod.GET)
1083     public void sendSms(String tel, HttpServletRequest request, HttpServletResponse response) {
1084         //发送验证码到对应手机号
1085         //TODO 暂定用标准版的短信账号来发送,以后再转第三方做验证调用时就可以用第三方的短信账号
1086         request.setAttribute(SessionKey.SHOPPING_DBID, "82");
1087         VerificationCodes verificationCodes = (VerificationCodes) FactoryBean.getBean("verificationCodes");
1088         verificationCodes.GenRandomVcode(tel, request, response);
1089     }
1090
1091     /**
1092      * 取功能号对应的主键,多个是以;号分隔
1093      */
1094     @RequestMapping(value = "/forminfo.do", method = RequestMethod.POST)
1095     public @ResponseBody
1096     Map<String, String> getPrimKey(@RequestBody FormInfo json, HttpServletRequest request, HttpServletResponse response) {
1097         String dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
1098         try {
1099             //Gson gson = new Gson();
1100             Map<String, String> map = new HashMap<String, String>();
1101             // FormInfo  json=gson.fromJson(request.getParameter("_pop_json"), new com.google.gson.reflect.TypeToken<FormInfo>() {}.getType());
1102             //SpObserver.setDBtoInstance("_" + dbid);
1103             // 取到对应功能号的表名
1104             //wintype 格式:9@p@1
1105             TreeGridDTO dto = new TreeGridDTO();
1106             dto.dbid = dbid;
1107             this.getTableName(json.getFormid(), json.getWintype(), dto);
1108             dto.b497 = json.isB497();
1109             dto.b499 = json.isB499();
1110             this.setOrderName(dto);
1111             dto.orderFiled = json.getFiled();
1112             this.getFirstField(dto);//取主键
1113             this.setOrderFiled(dto);
1114             this.setOrderBy(dto);
1115
1116             map.put("primeKey", dto.primeKey);
1117             map.put("sortCols", dto.sortCols);
1118             map.put("sortTypes", dto.sortTypes);
1119             map.put("tableName", dto.table);
1120             int isView = 0;
1121             //多表才执行
1122             if (dto.b497 || dto.b499) {
1123                 try {
1124                     SpObserver.setDBtoInstance("_" + dto.dbid);
1125                     String tableType = this.gridService.getSimpleJdbcTemplate().queryForObject("select TABLE_TYPE from information_schema.TABLES where table_name=?", String.class, dto.table);
1126                     if ("VIEW".equals(tableType)) {
1127                         //针对496多表子功能号是视图,新增提交时需要把action修改为add
1128                         isView = 1;
1129                     }
1130                 } finally {
1131                     SpObserver.setDBtoInstance();
1132                 }
1133             }
1134             map.put("isView", isView + "");
1135             return map;
1136         } catch (Exception ex) {
1137             this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}");
1138         }
1139         return null;
1140     }
1141
1142     private void setOrderFiled(TreeGridDTO dto) {
1143
1144     }
1145
1146     private void getFirstField(TreeGridDTO dto) {
1147         //1先读表关键功能,如果没有相关的再读表结构
1148
1149         String keyfields = null;
1150         try {
1151             SpObserver.setDBtoInstance("_" + dto.dbid);
e23226 1152             String taleName=dto.table;
F 1153             if(dto.winType==18||dto.winType==19){
1154                 taleName=dto.table.split("\\|")[0];
1155             }
1156             keyfields = gridService.getTableKeyFields(taleName);
a6a76f 1157         } finally {
F 1158             SpObserver.setDBtoInstance();
1159         }
1160         if (keyfields == null || "".equalsIgnoreCase(keyfields)) {
e23226 1161             //2只取主表,主从表情况
a6a76f 1162             List<String> keys = null;
F 1163             try {
1164                 SpObserver.setDBtoInstance("_" + dto.dbid);
1165                 try {
1166                     keys = gridService.getPrimaryKey(dto.table);
1167                 } catch (SQLException e) {
1168                     // TODO Auto-generated catch block
1169                     e.printStackTrace();
1170                 }
1171             } finally {
1172                 SpObserver.setDBtoInstance();
1173             }
1174             if (keys != null) {
1175                 for (String str : keys) {
1176                     if (dto.field == "")
1177                         dto.field += str;
1178                     else
1179                         dto.field += ";" + str;
1180                 }
1181                 keys = null;
1182             }
1183         } else {
1184             String[] arry = keyfields.split(";");
1185             for (int i = 0; i < arry.length; i++) {
1186                 if ("".equals(dto.field))
1187                     dto.field += arry[i].toLowerCase();
1188                 else
1189                     dto.field += ";" + arry[i].toLowerCase();
1190
1191             }
1192             arry = null;
1193         }
1194         dto.primeKey = dto.field;
1195     }
1196
1197     public void getTableName(int formid, String winType, TreeGridDTO dto) {
1198         SqlRowSet gform = null;
1199         try {
1200             SpObserver.setDBtoInstance("_" + dto.dbid);
1201             gform = gridService.getGformByFormID(formid);
1202         } finally {
1203             SpObserver.setDBtoInstance();
1204         }
1205         String[] temp = winType.split("@p@");
1206         dto.winType = Integer.parseInt(temp[0]);
1207         dto.conNum = temp.length > 1 ? Integer.parseInt(temp[1]) : 0;
1208         if (!gform.wasNull()) {
1209             gform.first();
1210             dto.HDTable = gform.getString("hdtable");
1211             //dto.dataformid=(gform.getString("dataformid")==null||gform.getString("dataformid").length()==0||gform.getString("dataformid").equalsIgnoreCase("0"))?"":(gform.getString("dataformid")+(!this.isDanJun(dto)?"":"|"+gform.getInt("predocstatus")));
1212             //dto.tranformid=(gform.getString("dataformid")==null||gform.getString("dataformid").length()==0||gform.getString("dataformid").equalsIgnoreCase("0"))?"":(gform.getString("dataformid"));
1213             dto.DTtable = gform.getString("dttable");
1214 //        dto.frozencols=gform.getInt("frozencols");
1215 //        dto.formname=gform.getString("formname");
1216 //        dto.gantt=gform.getBoolean("isGantt");//是否为甘特图类型的功能号
1217 //        dto.predocstatus=gform.getInt("predocstatus");//确认前状态,为了给格线在确认后不能再修改(新增,修改,删除) by 2013-02-01
1218 //        dto.rowcopyfields=gform.getString("rowcopyfields");//行复制时排除字段
1219 //        dto.pageSize=gform.getInt("pageSize");//页记录数
1220 //        dto.autopaging=gform.getInt("autopaging");//是否分页
1221 //        dto.optype=gform.getInt("optype");//功能号权限
1222 //        dto.lockGridSort=gform.getInt("LockGridSort");//冻结列排序
1223 //         dto.colset=gform.getInt("isShowCell");//是否显示列过滤
1224 //         dto.mainCol=gform.getString("byGroup");//树分组显示字段
1225 //         dto.isFilter=gform.getInt("isFilter");//是否打开过滤功能
1226 //         boolean blactions=gform.getBoolean("addNewRow");//直接增行
1227 //         try {
1228 //         dto.postStatusAddNew=gform.getInt("PostStatusGridAddNew");//根据状态值是否可以显示增行按钮,用在OA审核中
1229 //         }catch(Exception e) {
1230 //             dto.postStatusAddNew=0;
1231 //         }
1232             // if(blactions) dto.actions="<Actions OnClickButtonAdd=\"AddRowEnd\" />";
1233             // dto.defaultRowCount=gform.getInt("DefaultRowCount");//格线默认加载时显示行数
1234 //        if(!"".equalsIgnoreCase(dto.tolkey)&&(dto.b497||dto.b499)&&dto.PriFormID>0){//是多表的情况 且是第一个子功能号
1235 //            
1236 //            SqlRowSet f=null;
1237 //            try{
1238 //                SpObserver.setDBtoInstance("_"+dto.dbid);
1239 //                    f=gridService.getGformByFormID(dto.PriFormID);
1240 //            }finally{
1241 //            SpObserver.setDBtoInstance();
1242 //            }
1243 //            if(!f.wasNull()){
1244 //                f.first();
1245 //                dto.rowcopyformids=f.getString("rowcopyformids");//复单时排除功能号        
1246 //            }
1247 //            
1248 //        }else{
1249 //            dto.rowcopyformids=gform.getString("rowcopyformids");//复单时排除功能号
1250 //        }
1251 //        if(dto.gridHeight==0) dto.gridHeight=gform.getInt("GridHeight");//表格高度
1252 //        dto.glcodefield=gform.getString("glcodefield");//会计科目需要的字段
1253 //        if(!this.isNullOrEmptry(dto.glcodefield)){//格式:主表汇总,明细表汇总|平衡字段|平衡值公式字段
1254 //            List<Map<String ,Object>> map=null;
1255 //             try{
1256 //                    SpObserver.setDBtoInstance("_"+dto.dbid);
1257 //                    map=gridService.getSimpleJdbcTemplate().queryForList("select MasterSumFields,DetailSumFields from _sysmasterdetail where FormID=?", dto.formID);
1258 //             }finally{
1259 //                SpObserver.setDBtoInstance();
1260 //                }
1261 //            if(map.size()>0){
1262 //                Map<String ,Object> m=map.get(0);
1263 //                dto.gltotal=m.get("MasterSumFields")+","+m.get("DetailSumFields")+"|"+gform.getString("checkblncfields")+"|"+gform.getString("chkFormula"); 
1264 //            m=null;
1265 //            }
1266 //            map=null;
1267 //            }
1268             dto.index1 = gform.getString("index1");//列表的排序字段-9类型
1269             dto.index2 = gform.getString("index2");//明细表的排序字段-5类型
1270 //        dto.formdatafilters=gform.getString("formdatafilters")==null?"":this.replaceBlank(gform.getString("formdatafilters"));
1271 //        dto.ProcGroupafterSavedoc=gform.getString("ProcGroupafterSavedoc")==null?"":this.replaceBlank(gform.getString("ProcGroupafterSavedoc"));
1272 //        dto.trangroup=gform.getString("transgroupcode")==null?"":gform.getString("transgroupcode");
1273 //        dto.DealAfterDocSave=gform.getString("DealAfterDocSave")==null?"":this.replaceBlank(gform.getString("DealAfterDocSave"));
1274 //        
1275 //        dto.cancelProc=gform.getString("CancelBtnProcName")==null?"":this.replaceBlank(gform.getString("CancelBtnProcName"));
1276 //        
1277 //        dto.revokeProc=gform.getString("RevokeBtnProcName")==null?"":this.replaceBlank(gform.getString("RevokeBtnProcName"));
1278 //        
1279 //        dto.cancelisSave=gform.getBoolean("CancelIsSave")?1:0;
1280
1281             if (dto.winType == 0 || (dto.winType == 7 && dto.conNum == 0) || dto.winType == 1 || dto.winType == 5 || (dto.winType == 9 && dto.conNum == 0) || dto.winType == 3 || dto.winType == 4 ||
1282                     dto.winType == 17 || (dto.winType == 302 && dto.conNum == 0) || dto.winType == 19 ||
1283                     (dto.winType == 499 && dto.conNum == 0) || (dto.winType == 10 && dto.conNum == 0) ||//dto.winType == 10 &&dto.conNum == 1 修改为dto.conNum == 0  by danaus 2020/1/11 13:53
1284                     (dto.winType == 497 && dto.conNum == 0) || (dto.winType == 2 && dto.conNum == 0) ||
1285                     (dto.winType == 20 && dto.conNum == 0) || (dto.winType == 301 && dto.conNum == 0) ||
1286                     (dto.winType == 30 && dto.conNum == 0) ||
1287                     (dto.winType == 303 && dto.conNum == 0) || (dto.winType == 304 && dto.conNum == 0) ||
1288                     (dto.winType == 238 && dto.conNum == 0) || (dto.winType == 302) ||
1289                     (dto.winType == 15 && (dto.conNum == 0 || dto.conNum == 2))) {
1290                 dto.table = dto.HDTable;
1291                 dto.isList = true;
1292             } else {
1293                 dto.table = dto.DTtable;
1294             }
1295
1296             gform = null;
1297
1298         }
1299
1300     }
1301
1302     /**
1303      * 根据不同类型决定不同的排序规则
1304      * //1,读取9801设置,
1305      * //2,根据不同类型再进行不同的设置(单据清单desc,明细 以docitem asc,)
1306      * //3,对于不是上面的二种情况不用排序
1307      */
1308     private void setOrderBy(TreeGridDTO dto) {
1309         String temp = "";
1310         if (dto.order == 1 && dto.index1 != null && !dto.index1.isEmpty()) { //9801 主表
1311             temp = setSqlOrderBy(dto.index1, " asc");
1312         } else if (dto.order == 2 && dto.index2 != null && !dto.index2.isEmpty()) {//明细表
1313             temp = setSqlOrderBy(dto.index2, " asc");
1314         } else {
1315             if (dto.field.isEmpty())
1316                 temp = dto.orderFiled;
1317             else
1318                 temp = setSqlOrderBy(dto.field, (dto.order == 1 && dto.winType != 2 && dto.winType != 20) ? " desc" : " asc");
1319         }
1320         dto.field = "";
1321         if (!"".equalsIgnoreCase(temp)) {
1322             String[] s = temp.replaceAll(",", " ").split("\\s+");//
1323             StringBuilder cols = new StringBuilder();
1324             StringBuilder types = new StringBuilder();
1325
1326             for (int j = 0; j < s.length; j += 2) {
1327                 if (s.length < 2) throw new ApplicationException("【" + temp + "】内容格式不正确【filed1,1,filed2,0....】");
1328                 if (j > 0) {
1329                     cols.append(",");
1330                     types.append(",");
1331                 }
1332                 cols.append(s[j].equalsIgnoreCase("_ycid_") ? "id" : s[j]);
1333                 types.append("asc".equalsIgnoreCase(s[j + 1]) ? "0" : "1");
1334             }
1335             dto.sortCols = cols.toString();
1336             dto.sortTypes = types.toString();
1337
1338         }
1339
1340     }
1341
1342     private String setSqlOrderBy(String index22, String x) {//x为desc,asc
1343         StringBuilder temp = new StringBuilder();
1344         index22 = index22.replaceAll(";", ",");
1345         String[] sorts = index22.split(",");
1346         int index = 0;
1347         for (String s : sorts) {
1348             String[] str = s.split("\\s");
1349             if (str.length == 2) {
1350                 if (index > 0)
1351                     temp.append(",").append(str[0]).append(" " + str[1]);
1352                 else
1353                     temp.append(str[0]).append(" " + str[1]);
1354             } else {
1355                 if (index > 0)
1356                     temp.append(",").append(str[0]).append(" " + x);
1357                 else
1358                     temp.append(str[0]).append(" " + x);
1359             }
1360             index++;
1361         }
1362         return temp.toString();
1363     }
1364
1365     /**
1366      * 根据类型选用不同的字段作为排序
1367      *
1368      * @return 1表示清单,2表示明细
1369      **/
1370     private void setOrderName(TreeGridDTO dto) {
1371
1372         switch (dto.winType) {
1373             case 9:
1374             case 15:
1375             case 17:
1376             case 499:
1377             case 497:
1378                 //case 10:
1379                 if (dto.conNum == 0) {
1380                     //isList=t
1381                     dto.order = 1;
1382                 } else
1383                     dto.order = 2;
1384                 dto.isBill = true;
1385                 break;
1386             case 1:
1387                 if (dto.b497 || dto.b499) {
1388                     dto.order = 2;
1389                     dto.isBill = true;
1390                 } else
1391                     dto.order = 1;
1392                 break;
1393             default:
1394                 dto.order = 1;
1395         }
1396     }
1397 }