fs-danaus
2024-09-19 ae692b78c8750473c63a0b4eeaa12c69fd744442
提交 | 用户 | age
703a8b 1 package com.yc.crm.clues.service;
F 2
3 import com.yc.action.grid.GridUtils;
035491 4 import com.yc.crm.base.entity.AuditEntity;
F 5 import com.yc.crm.base.entity.FileStructEntity;
7204e3 6 import com.yc.crm.base.entity.Response;
035491 7 import com.yc.crm.base.util.Utils;
703a8b 8 import com.yc.crm.clues.entity.*;
035491 9 import com.yc.exception.ApplicationException;
703a8b 10 import com.yc.service.BaseService;
F 11 import org.apache.commons.lang3.StringUtils;
12 import org.springframework.jdbc.core.BeanPropertyRowMapper;
13 import org.springframework.stereotype.Service;
14 import org.springframework.transaction.annotation.Transactional;
15
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.Map;
7204e3 19 import java.util.Set;
035491 20 import java.util.stream.Collectors;
703a8b 21
F 22 @Service
05aec6 23 public class CluesServiceImpl extends BaseService implements CluesServiceIfc {
703a8b 24     @Transactional(rollbackFor = Exception.class)
F 25     @Override
26     public void save(T481101Entity t481101Entity) {
05aec6 27         if (StringUtils.isBlank(t481101Entity.getCluesName())) {
F 28             throw new ApplicationException("线索名称不能为空");
035491 29         }
05aec6 30         String sql = " declare " +
703a8b 31                 "    @DocCode                  nvarchar(16),\n" +
F 32                 "    @FormID                   int,\n" +
33                 "    @DocDate                  datetime,\n" +
34                 "    @periodid                 varchar(50),\n" +
35                 "    @DocStatus                int,\n" +
36                 "    @DocStatusName            varchar(50),\n" +
37                 "    @companyid                nvarchar(20),\n" +
38                 "    @companyname              varchar(50),\n" +
d32c21 39                 "    @ccCode                varchar(20),\n" +
F 40                 "    @ccName                varchar(50),\n" +
703a8b 41                 "    @EnterCode                varchar(20),\n" +
F 42                 "    @EnterName                varchar(50),\n" +
43                 "    @EnterDate                datetime,\n" +
44                 "    @ModifyName               varchar(40),\n" +
45                 "    @ModifyDate               datetime,\n" +
46                 "    @modifylog                varchar(200),\n" +
47                 "    @PostName                 varchar(40),\n" +
48                 "    @PostDate                 datetime,\n" +
49                 "    @CreateUsercode           varchar(50),\n" +
50                 "    @CreateUserName           varchar(50),\n" +
51                 "    @isRead                   int,\n" +
52                 "    @Email                    varchar(50),\n" +
53                 "    @Website                  varchar(100),\n" +
54                 "    @Phone                    varchar(50),\n" +
55                 "    @DoNotCall                int,\n" +
56                 "    @MobilePhone              varchar(50),\n" +
57                 "    @CltStatus                varchar(20),\n" +
58                 "    @Country                  varchar(50),\n" +
59                 "    @Province                 varchar(50),\n" +
60                 "    @City                     varchar(50),\n" +
61                 "    @District                 varchar(50),\n" +
62                 "    @Street                   varchar(50),\n" +
63                 "    @Address                  varchar(200),\n" +
64                 "    @PostCode                 varchar(50),\n" +
65                 "    @HDMemo                   varchar(500),\n" +
66                 "    @clues_name               nvarchar(50),\n" +
67                 "    @last_edit_user           varchar(20),\n" +
68                 "    @edit_time                datetime,\n" +
69                 "    @public_time              datetime,\n" +
70                 "    @tagList                  varchar(200),\n" +
71                 "    @homepage                 varchar(50),\n" +
72                 "    @origin_list              nvarchar(250),\n" +
73                 "    @short_name               nvarchar(250),\n" +
74                 "    @corporate_name           nvarchar(250),\n" +
75                 "    @biz_type                 nvarchar(20),\n" +
76                 "    @tel_area_code            varchar(10),\n" +
77                 "    @tel                      varchar(20),\n" +
78                 "    @intention_level          varchar(50),\n" +
79                 "    @annual_procurement       money,\n" +
80                 "    @timezone                 varchar(10),\n" +
05aec6 81                 "    @ad_keyword               nvarchar(300),\n" +
703a8b 82                 "    @image_list               varchar(100),\n" +
F 83                 "    @scale_id                 varchar(100),\n" +
84                 "    @seller                   varchar(50),\n" +
85                 "    @inquiry_origin           nvarchar(100),\n" +
86                 "    @category_ids             nvarchar(100),\n" +
87                 "    @inquiry_country          nvarchar(50),\n" +
88                 "    @pin_flag                 bit \n" +
89                 " \ndeclare " +
90                 "    @main_customer_flag bit,\n" +
91                 "    @id                 bigint, \n" +
92                 "    @refCode            varchar(50),\n" +
93                 "    @name               nvarchar(50),\n" +
94                 "    @contact_email              nvarchar(150),\n" +
95                 "    @gender             nvarchar(10),\n" +
96                 "    @post               nvarchar(50),\n" +
97                 "    @remark             nvarchar(50),\n" +
98                 "    @contact_image_list         nvarchar(150),\n" +
99                 "    @birth              nvarchar(50),\n" +
100                 "    @post_grade         nvarchar(50),\n" +
101                 "    @growth_level       int,\n" +
102                 "    @create_time        datetime,\n" +
05aec6 103                 "    @update_time        datetime,\n" +
F 104                 "    @last_inserted_id bigint\n" +//自增主键值
703a8b 105                 " \ndeclare " +
F 106                 "    @media_type varchar(50),\n" +
107                 "    @media_refid                 bigint, \n" +
035491 108                 "    @media_id                 bigint, \n" +
05aec6 109                 "    @media_value            varchar(150)\n" +
703a8b 110                 " \ndeclare " +
F 111                 "    @areaCode varchar(50),\n" +
112                 "    @telList_refid                 bigint, \n" +
035491 113                 "    @telList_id                 bigint, \n" +
05aec6 114                 "    @telList_tel            varchar(150)\n" +
F 115                 //---赋值
703a8b 116                 " select " +
F 117                 "@FormID=481101 ,           \n" +
118                 "@DocDate=convert(datetime,convert(varchar(10),GETDATE(),120) )  ,          \n" +
05aec6 119                 "@DocCode=" + GridUtils.prossSqlParm(t481101Entity.getDocCode()) + ",         \n" +
F 120                 "@companyid=" + GridUtils.prossSqlParm(t481101Entity.getCompanyid()) + ",         \n" +
121                 "@companyname= " + GridUtils.prossSqlParm(t481101Entity.getCompanyname()) + ",         \n" +
d32c21 122                 "@ccCode=" + GridUtils.prossSqlParm(t481101Entity.getCcCode()) + ",         \n" +
F 123                 "@ccName= " + GridUtils.prossSqlParm(t481101Entity.getCcName()) + ",         \n" +
703a8b 124                 "@periodid= dbo.GetPeriodID(@FormID,@CompanyID,getdate()),          \n" +
05aec6 125                 "@EnterCode=" + GridUtils.prossSqlParm(t481101Entity.getCreateUsercode()) + ",         \n" +
F 126                 "@EnterName=" + GridUtils.prossSqlParm(t481101Entity.getCreateUserName()) + " ,        \n" +
703a8b 127                 "@EnterDate=getdate() ,        \n" +
05aec6 128                 "@ModifyName =" + GridUtils.prossSqlParm(t481101Entity.getCreateUserName()) + ",         \n" +
703a8b 129                 "@ModifyDate =getdate() ,       \n" +
05aec6 130                 "@PostName =" + GridUtils.prossSqlParm(t481101Entity.getCreateUserName()) + ",         \n" +
703a8b 131                 "@PostDate=getdate() ,           \n" +
05aec6 132                 "@CreateUsercode=" + GridUtils.prossSqlParm(t481101Entity.getCreateUsercode()) + ",         \n" +
F 133                 "@CreateUserName=" + GridUtils.prossSqlParm(t481101Entity.getCreateUserName()) + " ,        \n" +
134                 "@isRead =" + t481101Entity.getIsRead() + ",           \n" +//TODO 自己新建,isRead=1,其他人
703a8b 135                 "@Email=null,             \n" +
05aec6 136                 "@Country =" + GridUtils.prossSqlParm(t481101Entity.getCountry()) + ",         \n" +
F 137                 "@province =" + GridUtils.prossSqlParm(t481101Entity.getProvince()) + ",         \n" +
138                 "@city =" + GridUtils.prossSqlParm(t481101Entity.getCity()) + ",         \n" +
139                 "@Address =" + GridUtils.prossSqlParm(t481101Entity.getAddress()) + ",         \n" +
140                 "@PostCode =" + GridUtils.prossSqlParm(t481101Entity.getCreateUsercode()) + ",         \n" +
141                 "@HDMemo =" + GridUtils.prossSqlParm(t481101Entity.getHdMemo()) + ",         \n" +
142                 "@clues_name= " + GridUtils.prossSqlParm(t481101Entity.getCluesName()) + ",         \n" +
143                 "@last_edit_user=" + GridUtils.prossSqlParm(t481101Entity.getCreateUsercode()) + ",         \n" +
703a8b 144                 "@edit_time=getdate(),         \n" +
F 145                 "@public_time   =getdate(),      \n" +
05aec6 146                 "@tagList= " + GridUtils.prossSqlParm(t481101Entity.getTagList()) + ",         \n" +
F 147                 "@homepage=" + GridUtils.prossSqlParm(t481101Entity.getHomepage()) + ",         \n" +
148                 "@origin_list= " + GridUtils.prossSqlParm(t481101Entity.getOriginList()) + ",         \n" +
149                 "@short_name=" + GridUtils.prossSqlParm(t481101Entity.getShortName()) + ",         \n" +
150                 "@corporate_name=" + GridUtils.prossSqlParm(t481101Entity.getCorporateName()) + ",         \n" +
151                 "@biz_type=" + GridUtils.prossSqlParm(t481101Entity.getBizType()) + ",         \n" +
152                 "@tel_area_code=" + GridUtils.prossSqlParm(t481101Entity.getTelAreaCode()) + ",         \n" +
153                 "@tel=" + GridUtils.prossSqlParm(t481101Entity.getTel()) + ",         \n" +
154                 "@intention_level=" + GridUtils.prossSqlParm(t481101Entity.getIntentionLevel()) + ",         \n" +
155                 "@annual_procurement=" + t481101Entity.getAnnualProcurement() + ",         \n" +
156                 "@timezone=" + GridUtils.prossSqlParm(t481101Entity.getTimezone()) + ",         \n" +
157                 "@ad_keyword =" + GridUtils.prossSqlParm(t481101Entity.getAdKeyword()) + ",         \n" +
158                 "@image_list =" + GridUtils.prossSqlParm(t481101Entity.getImageList()) + ",         \n" +
159                 "@scale_id=" + GridUtils.prossSqlParm(t481101Entity.getScaleId()) + ",         \n" +
160                 "@seller =" + GridUtils.prossSqlParm(t481101Entity.getSeller()) + ",         \n" +
161                 "@inquiry_origin=" + GridUtils.prossSqlParm(t481101Entity.getInquiryOrigin()) + ",         \n" +
162                 "@category_ids =" + GridUtils.prossSqlParm(t481101Entity.getCategoryIds()) + ",         \n" +
163                 "@inquiry_country=" + GridUtils.prossSqlParm(t481101Entity.getInquiryCountry()) + ",         \n" +
164                 "@pin_flag=" + t481101Entity.getPinFlag() + "          \n" +
703a8b 165                 " if isnull(@doccode,'')=''\n" +//新增
05aec6 166                 "begin\n" +
F 167                 //新增则生成单号
168                 "  exec sp_newdoccode @formid,@EnterCode,@doccode output \n" +
703a8b 169                 "insert into t481101H(" +
F 170                 "FormID" +
171                 ",DocDate" +
172                 ",DocCode" +
173                 ",companyid" +
174                 ",companyname" +
d32c21 175                 ",ccCode" +
F 176                 ",ccName" +
703a8b 177                 ",periodid" +
F 178                 ",EnterCode" +
179                 ",EnterName" +
180                 ",EnterDate" +
181                 ",ModifyName" +
182                 ",ModifyDate" +
183                 ",PostName" +
184                 ",PostDate" +
185                 ",CreateUsercode" +
186                 ",CreateUserName" +
187                 ",isRead" +
188                 ",Email" +
189                 ",Country " +
035491 190                 ",province " +
F 191                 ",city " +
703a8b 192                 ",Address" +
F 193                 ",PostCode" +
194                 ",HDMemo" +
195                 ",clues_name" +
196                 ",last_edit_user" +
197                 ",edit_time" +
198                 ",public_time" +
199                 ",tagList" +
200                 ",homepage" +
201                 ",origin_list" +
202                 ",short_name" +
203                 ",corporate_name" +
204                 ",biz_type" +
205                 ",tel_area_code" +
206                 ",tel" +
207                 ",intention_level" +
208                 ",annual_procurement" +
209                 ",timezone" +
210                 ",ad_keyword " +
211                 ",image_list " +
212                 ",scale_id" +
213                 ",seller" +
214                 ",inquiry_origin" +
215                 ",category_ids" +
216                 ",inquiry_country" +
217                 ",pin_flag ,DocStatusName" +
218                 ")values(" +
219                 "@FormID" +
220                 ",@DocDate" +
221                 ",@DocCode" +
222                 ",@companyid" +
223                 ",@companyname" +
d32c21 224                 ",@ccCode" +
F 225                 ",@ccName" +
703a8b 226                 ",@periodid" +
F 227                 ",@EnterCode" +
228                 ",@EnterName" +
229                 ",@EnterDate" +
230                 ",@ModifyName" +
231                 ",@ModifyDate" +
232                 ",@PostName" +
233                 ",@PostDate" +
234                 ",@CreateUsercode" +
235                 ",@CreateUserName" +
236                 ",@isRead" +
237                 ",@Email" +
238                 ",@Country " +
035491 239                 ",@province " +
F 240                 ",@city " +
703a8b 241                 ",@Address" +
F 242                 ",@PostCode" +
243                 ",@HDMemo" +
244                 ",@clues_name" +
245                 ",@last_edit_user" +
246                 ",@edit_time" +
247                 ",@public_time" +
248                 ",@tagList" +
249                 ",@homepage" +
250                 ",@origin_list" +
251                 ",@short_name" +
252                 ",@corporate_name" +
253                 ",@biz_type" +
254                 ",@tel_area_code" +
255                 ",@tel" +
256                 ",@intention_level" +
257                 ",@annual_procurement" +
258                 ",@timezone" +
259                 ",@ad_keyword " +
260                 ",@image_list " +
261                 ",@scale_id" +
262                 ",@seller" +
263                 ",@inquiry_origin" +
264                 ",@category_ids" +
265                 ",@inquiry_country" +
266                 ",@pin_flag,'起草' " +
267                 ")\n" +
268                 //----处理联系人信息
ae692b 269                 contactAddSql(t481101Entity.getContactsList(),"线索") +
703a8b 270                 "end\n" +
F 271                 "else \n" +//-------修改
272                 "begin\n" +
273                 " update t481101H set " +
274                 "ModifyName=@ModifyName" +
275                 ",ModifyDate=@ModifyDate" +
276                 ",Country=@Country " +
035491 277                 ",province=@province " +
F 278                 ",city=@city " +
703a8b 279                 ",Address=@Address" +
F 280                 ",HDMemo=@HDMemo" +
281                 ",clues_name=@clues_name" +
282                 ",last_edit_user=@last_edit_user" +
283                 ",edit_time=@edit_time" +
284                 ",tagList=@tagList" +
285                 ",homepage=@homepage" +
286                 ",origin_list=@origin_list" +
287                 ",short_name=@short_name" +
288                 ",corporate_name=@corporate_name" +
289                 ",biz_type=@biz_type" +
290                 ",tel_area_code=@tel_area_code" +
291                 ",tel=@tel" +
292                 ",intention_level=@intention_level" +
293                 ",annual_procurement=@annual_procurement" +
294                 ",timezone=@timezone" +
295                 ",ad_keyword=@ad_keyword " +
296                 ",image_list=@image_list " +
297                 ",scale_id=@scale_id" +
298                 ",seller=@seller" +
299                 ",inquiry_origin=@inquiry_origin" +
300                 ",category_ids=@category_ids" +
301                 ",inquiry_country=@inquiry_country,pin_flag=@pin_flag from t481101H where doccode=@doccode\n" +
302                 //----处理联系人信息
ae692b 303                 contactUpdateSql(t481101Entity.getContactsList(),"线索") +
703a8b 304                 "end\n" +
035491 305                 //--处理审计功能
F 306                 auditAddSql(t481101Entity);
7204e3 307         //System.out.println("clues:"+sql);
703a8b 308         this.doBaseExecute(sql);
F 309     }
310
035491 311     private String auditAddSql(T481101Entity t481101Entity) {
05aec6 312         List<AuditEntity> list = t481101Entity.getAuditRecords();
F 313         if (list == null || list.size() == 0) {
314             return "";
315         }
316         String sql = " declare @now datetime=getdate()\n";//方便同一时间提交到时输出成一条
317         for (AuditEntity audit : list) {
318             sql += " insert into _sysAudit([formid],[newvalue],[headflag],[auditType],[fieldname],[mainFormid],[usercode],[oldvalue],[fieldid],[username],[doccode],[auditIndex],[auditDateTime],[auditDate])values(" + t481101Entity.getFormId() + "," + GridUtils.prossSqlParm(audit.getNewValue()) + ",0," + GridUtils.prossSqlParm(audit.getAuditType()) + "," + GridUtils.prossSqlParm(audit.getFieldName()) + "," + t481101Entity.getFormId() + "," + GridUtils.prossSqlParm(t481101Entity.getCreateUsercode()) + "," + GridUtils.prossSqlParm(audit.getOldValue()) + "," + GridUtils.prossSqlParm(audit.getFieldId()) + "," + GridUtils.prossSqlParm(t481101Entity.getCreateUserName()) + ",@docCode,null,@now,convert(varchar(10),@now,120))\n";
035491 319         }
F 320         return sql;
321     }
7204e3 322
d32c21 323     @Override
F 324     public Response contactList(CluesRequestEntity request) {
325         String fileds = " " +
326                 "c.refCode,c.id,a.docCode,a.clues_name           \n" +
327                 ",c.name              \n" +
328                 ",c.email             \n" +
329                 ",@TotalRowCount as totalRowCount ,@pageCount as pageCount              \n";
330         String where = " contactType='线索' ";
331         if (request.getSearchTxt() != null && request.getSearchTxt().size() > 0) {
332             //拼接查询条件
333             where += getSearchInfo(request);
334         }
335         String sql = "set nocount on ; \n" +
336 //                "                 declare @key varchar(300)  \n" +
337 //                "                 select @key ="+1+" \n" +
338                 "                 declare @Limit int , @Page int ,@StartRowNo int ,@EndRowNo int ; \n" +
339                 "                 select @Limit  = " + request.getPageSize() + " , @Page  = " + request.getPageNo() + "  ; \n" +
340                 "                 declare @TotalRowCount int ,@pageCount int; \n" +
341                 " select @StartRowNo = (isnull(@Page,0) - 1) * isnull(@Limit,0) + 1 ; \n" +
342                 " select @EndRowNo = isnull(@Page,0) * isnull(@Limit,0) ; \n" +
343                 " select @TotalRowCount =count(1),@pageCount=CEILING((COUNT(1)+0.0)/" + request.getPageSize() + ")  from t482103 c \n" +
344                 " left join t481101h a on a.docCode=c.refCode\n" +
345                 " left join t481104h b on a.docCode=b.refCode" +
346                 " where " + where + " \n" +
347                 " SELECT * FROM ( \n" +
348                 " select top 100 percent ROW_NUMBER() OVER (ORDER BY  a.docCode) AS NO,\n" +
349                 fileds + "  from t482103 c \n" +
350                 " left join t481101h a on a.docCode=c.refCode\n" +
351                 " left join t481104h b on a.docCode=b.refCode" +
352                 " where " + where +
353                 " order by  a.docCode asc \n" +
354                 " ) t WHERE t.NO  BETWEEN @StartRowNo AND @EndRowNo";
355         List<ContactEntity> list = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ContactEntity.class));
356         //增加联系人输出
357         Response response = new Response();
358         response.setTotalCount((list != null && list.size() > 0) ? list.get(0).getTotalRowCount() : 0);
359         response.setPageCount((list != null && list.size() > 0) ? list.get(0).getPageCount() : 0);
360         response.setData(list);
361         return response;
362     }
7204e3 363
703a8b 364     @Override
7204e3 365     public Response getAllClues(CluesRequestEntity request) {
05aec6 366         String fileds = "" +
7204e3 367                 "a.DocCode                 \n" +
F 368                 ",a.FormID                 \n" +
369                 ",a.DocStatus              \n" +
370                 ",a.DocStatusName          \n" +
371                 ",a.companyid              \n" +
372                 ",a.companyname            \n" +
373                 ",a.EnterCode              \n" +
374                 ",a.EnterName              \n" +
375                 ",a.EnterDate              \n" +
376                 ",a.ModifyName             \n" +
377                 ",a.ModifyDate             \n" +
378                 ",a.PostName               \n" +
379                 ",a.PostDate               \n" +
380                 ",a.CreateUsercode         \n" +
381                 ",a.CreateUserName         \n" +
382                 ",a.Country                \n" +
383                 ",a.HDMemo                 \n" +
384                 ",a.clues_name             \n" +
385                 ",a.archive_time           \n" +
386                 ",a.order_time             \n" +
387                 ",a.lost_day_count         \n" +
388                 ",a.transfer_count         \n" +
389                 ",a.release_count          \n" +
390                 ",a.is_archive             \n" +
391                 ",a.archive_type           \n" +
392                 ",a.status_id              \n" +
393                 ",a.status                 \n" +
394                 ",a.follow_up_time         \n" +
395                 ",a.fail_type              \n" +
396                 ",a.fail_status            \n" +
397                 ",a.fail_status_name       \n" +
398                 ",a.fail_reason            \n" +
399                 ",a.read_flag              \n" +
400                 ",a.last_edit_user         \n" +
401                 ",a.edit_time              \n" +
402                 ",a.private_time           \n" +
403                 ",a.public_time            \n" +
404                 ",a.is_public              \n" +
405                 ",a.store_id               \n" +
406                 ",a.star                  \n" +
407                 ",a.transform_task_status  \n" +
408                 ",a.next_follow_up_time    \n" +
409                 ",a.duplicate_flag         \n" +
410                 ",a.tagList                \n" +
411                 ",a.homepage               \n" +
035491 412                 ",a.address               \n" +
7204e3 413                 ",a.origin_list            \n" +
F 414                 ",a.short_name             \n" +
415                 ",a.corporate_name         \n" +
416                 ",a.biz_type               \n" +
417                 ",a.tel_area_code          \n" +
418                 ",a.tel                    \n" +
419                 ",a.intention_level        \n" +
420                 ",a.annual_procurement     \n" +
421                 ",a.timezone               \n" +
422                 ",a.ad_keyword             \n" +
423                 ",a.image_list             \n" +
424                 ",a.scale_id               \n" +
425                 ",a.seller                 \n" +
426                 ",a.inquiry_origin         \n" +
427                 ",a.category_ids           \n" +
428                 ",a.inquiry_country        \n" +
429                 ",b.id               \n" +
430                 ",b.refCode           \n" +
431                 ",b.ownerCode         \n" +
432                 ",b.ownerName         \n" +
433                 ",b.enterTime         \n" +
434                 ",b.exitTime          \n" +
435                 ",b.isRead as hasRead          \n" +
436                 ",b.reasonForRollback \n" +
437                 ",b.costs             \n" +
438                 ",b.pinFlag  as hasPinFlag        \n" +
439                 ",b.firstFllowUpTime  \n" +
440                 ",b.lastModifyTime   \n" +
441                 ",b.daysNotContacted " +
035491 442                 ",b.systemFlag " +
F 443                 ",b.cluesStatusFlag " +
7204e3 444                 ",@TotalRowCount as totalRowCount ,@pageCount as pageCount              \n";
05aec6 445         String where = " 1=1 ";
F 446         if (request.getSearchTxt() != null && request.getSearchTxt().size() > 0) {
7204e3 447             //拼接查询条件
05aec6 448             where += getSearchInfo(request);
7204e3 449         }
05aec6 450         String sql = "set nocount on ; \n" +
7204e3 451 //                "                 declare @key varchar(300)  \n" +
F 452 //                "                 select @key ="+1+" \n" +
453                 "                 declare @Limit int , @Page int ,@StartRowNo int ,@EndRowNo int ; \n" +
05aec6 454                 "                 select @Limit  = " + request.getPageSize() + " , @Page  = " + request.getPageNo() + "  ; \n" +
7204e3 455                 "                 declare @TotalRowCount int ,@pageCount int; \n" +
F 456                 " select @StartRowNo = (isnull(@Page,0) - 1) * isnull(@Limit,0) + 1 ; \n" +
457                 " select @EndRowNo = isnull(@Page,0) * isnull(@Limit,0) ; \n" +
05aec6 458                 " select @TotalRowCount =count(1),@pageCount=CEILING((COUNT(1)+0.0)/" + request.getPageSize() + ")  from t481101h a left join t481104h b on a.docCode=b.refCode where " + where + " \n" +
7204e3 459                 " SELECT * FROM ( \n" +
d32c21 460                 " select top 100 percent ROW_NUMBER() OVER (ORDER BY  a.docCode) AS NO,\n" +
05aec6 461                 fileds + "  from t481101h a left join t481104h b on a.docCode=b.refCode\n" +
F 462                 " where " + where +
7204e3 463                 " order by  a.docCode asc \n" +
F 464                 " ) t WHERE t.NO  BETWEEN @StartRowNo AND @EndRowNo";
465         List<T481104Entity> list = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(T481104Entity.class));
466         //增加联系人输出
05aec6 467         if (list != null && list.size() > 0) {
F 468             list.stream().forEach(x -> {
7204e3 469                 List<T482103Entity> query = this.jdbcTemplate.query("select main_customer_flag\n" +
F 470                         ",refCode,id           \n" +
471                         ",name              \n" +
472                         ",email             \n" +
473                         ",gender            \n" +
474                         ",post              \n" +
475                         ",remark            \n" +
476                         ",image_list        \n" +
477                         ",birth             \n" +
478                         ",post_grade        \n" +
479                         ",growth_level      \n" +
480                         ",create_time       \n" +
481                         ",update_time       \n" +
482                         ",DocVersion        \n from t482103 where refCode=" + GridUtils.prossSqlParm(x.getDocCode()), new BeanPropertyRowMapper<>(T482103Entity.class));
05aec6 483                 if (query != null && query.size() > 0) {
F 484                     query.stream().forEach(y -> {
7204e3 485                         //--社交平台
F 486                         List<T482111Entity> mediaList = this.jdbcTemplate.query("select \n" +
487                                 "refId,id           \n" +
488                                 ",value              \n" +
05aec6 489                                 ",type             from t482111 where refId=" + y.getId(), new BeanPropertyRowMapper<>(T482111Entity.class));
7204e3 490                         y.setMediaList(mediaList);
F 491                         //电话列表
492                         List<T482116Entity> telList = this.jdbcTemplate.query("select " +
493                                 "refId,id,areaCode,tel  from t482116 where refId=" + y.getId(), new BeanPropertyRowMapper<>(T482116Entity.class));
494                         y.setTelList(telList);
495                     });
496                 }
497                 x.setContactsList(query);
035491 498                 //附件的输出
F 499                 //处理图片,附件,生成调用url及相关信息
05aec6 500                 if (StringUtils.isNotBlank(x.getImageList())) {
035491 501                     FileStructEntity fileStructEntity = new FileStructEntity();
F 502                     fileStructEntity.setDbid(request.getDbid());
503                     fileStructEntity.setFormid(request.getFormId() + "");
504                     fileStructEntity.setFileStr(x.getImageList());
505                     x.setFiles(Utils.getFileEntities(fileStructEntity));
506                 }
7204e3 507             });
F 508         }
05aec6 509         Response response = new Response();
F 510         response.setTotalCount((list != null && list.size() > 0) ? list.get(0).getTotalRowCount() : 0);
511         response.setPageCount((list != null && list.size() > 0) ? list.get(0).getPageCount() : 0);
7204e3 512         response.setData(list);
F 513         return response;
d32c21 514     }
F 515     @Transactional(rollbackFor = Exception.class)
516     @Override
517     public void cluesDel(String docCode) {
518         //删除线索,需要把相关的联系人,跟进,日程,评论也删除
519         String sql="declare @docCode varchar(50)="+ GridUtils.prossSqlParm(docCode)+"\n" +
520                 " exec p481101Del @docCode";
521         this.doBaseExecute(sql);
522     }
523
524     @Override
525     public void cluesFail(T481104Entity entity) {
526         String sql="declare @docCode varchar(50)="+ GridUtils.prossSqlParm(entity.getDocCode())+",\n" +
527                 "@failStatus int=" +entity.getFailStatus()+",\n"+
528                 "@failStatusName varchar(50)="+ GridUtils.prossSqlParm(entity.getFailStatusName())+",\n" +
529                 "@failReason varchar(250)="+ GridUtils.prossSqlParm(entity.getFailReason())+"\n" +
530                 "update t481101h set fail_Status=@failStatus,fail_Status_Name=@failStatusName,fail_Reason=@failReason where docCode=@docCode\n";
531         this.doBaseExecute(sql);
7204e3 532     }
035491 533
F 534     @Override
05aec6 535     public T481101Entity get(CluesRequestEntity request) {
F 536         String fileds = "" +
537                 "a.DocCode                 \n" +
538                 ",a.FormID                 \n" +
539                 ",a.DocStatus              \n" +
540                 ",a.DocStatusName          \n" +
541                 ",a.companyid              \n" +
542                 ",a.companyname            \n" +
543                 ",a.EnterCode              \n" +
544                 ",a.EnterName              \n" +
545                 ",a.EnterDate              \n" +
546                 ",a.ModifyName             \n" +
547                 ",a.ModifyDate             \n" +
548                 ",a.PostName               \n" +
549                 ",a.PostDate               \n" +
550                 ",a.CreateUsercode         \n" +
551                 ",a.CreateUserName         \n" +
552                 ",a.Country                \n" +
553                 ",a.HDMemo                 \n" +
554                 ",a.clues_name             \n" +
555                 ",a.archive_time           \n" +
556                 ",a.order_time             \n" +
557                 ",a.lost_day_count         \n" +
558                 ",a.transfer_count         \n" +
559                 ",a.release_count          \n" +
560                 ",a.is_archive             \n" +
561                 ",a.archive_type           \n" +
562                 ",a.status_id              \n" +
563                 ",a.status                 \n" +
564                 ",a.follow_up_time         \n" +
565                 ",a.fail_type              \n" +
566                 ",a.fail_status            \n" +
567                 ",a.fail_status_name       \n" +
568                 ",a.fail_reason            \n" +
569                 ",a.read_flag              \n" +
570                 ",a.last_edit_user         \n" +
571                 ",a.edit_time              \n" +
572                 ",a.private_time           \n" +
573                 ",a.public_time            \n" +
574                 ",a.is_public              \n" +
575                 ",a.store_id               \n" +
576                 ",a.star                  \n" +
577                 ",a.transform_task_status  \n" +
578                 ",a.next_follow_up_time    \n" +
579                 ",a.duplicate_flag         \n" +
580                 ",a.tagList                \n" +
581                 ",a.homepage               \n" +
582                 ",a.address               \n" +
583                 ",a.origin_list            \n" +
584                 ",a.short_name             \n" +
585                 ",a.corporate_name         \n" +
586                 ",a.biz_type               \n" +
587                 ",a.tel_area_code          \n" +
588                 ",a.tel                    \n" +
589                 ",a.intention_level        \n" +
590                 ",a.annual_procurement     \n" +
591                 ",a.timezone               \n" +
592                 ",a.ad_keyword             \n" +
593                 ",a.image_list             \n" +
594                 ",a.scale_id               \n" +
595                 ",a.seller                 \n" +
596                 ",a.inquiry_origin         \n" +
597                 ",a.category_ids           \n" +
598                 ",a.inquiry_country        \n" +
599                 ",b.id               \n" +
600                 ",b.refCode           \n" +
601                 ",b.ownerCode         \n" +
602                 ",b.ownerName         \n" +
603                 ",b.enterTime         \n" +
604                 ",b.exitTime          \n" +
605                 ",b.isRead as hasRead          \n" +
606                 ",b.reasonForRollback \n" +
607                 ",b.costs             \n" +
608                 ",b.pinFlag  as hasPinFlag        \n" +
609                 ",b.firstFllowUpTime  \n" +
610                 ",b.lastModifyTime   \n" +
611                 ",b.daysNotContacted " +
612                 ",b.systemFlag " +
613                 ",b.cluesStatusFlag ";
614         String where = "  b.refCode= " + GridUtils.prossSqlParm(request.getDocCode());
615
616         String sql = "set nocount on ; \n" +
617                 " select \n" +
618                 fileds + "  from t481101h a left join t481104h b on a.docCode=b.refCode\n" +
619                 " where " + where;
620         T481104Entity entity = this.jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(T481104Entity.class));
621         //增加联系人输出
622         if (entity != null) {
623             List<T482103Entity> query = this.jdbcTemplate.query("select main_customer_flag\n" +
624                     ",refCode,id           \n" +
625                     ",name              \n" +
626                     ",email             \n" +
627                     ",gender            \n" +
628                     ",post              \n" +
629                     ",remark            \n" +
630                     ",image_list        \n" +
631                     ",birth             \n" +
632                     ",post_grade        \n" +
633                     ",growth_level      \n" +
634                     ",create_time       \n" +
635                     ",update_time       \n" +
636                     ",DocVersion        \n from t482103 where refCode=" + GridUtils.prossSqlParm(entity.getDocCode()), new BeanPropertyRowMapper<>(T482103Entity.class));
637             if (query != null && query.size() > 0) {
638                 query.stream().forEach(y -> {
639                     //--社交平台
640                     List<T482111Entity> mediaList = this.jdbcTemplate.query("select \n" +
641                             "refId,id           \n" +
642                             ",value              \n" +
643                             ",type             from t482111 where refId=" + y.getId(), new BeanPropertyRowMapper<>(T482111Entity.class));
644                     y.setMediaList(mediaList);
645                     //电话列表
646                     List<T482116Entity> telList = this.jdbcTemplate.query("select " +
647                             "refId,id,areaCode,tel  from t482116 where refId=" + y.getId(), new BeanPropertyRowMapper<>(T482116Entity.class));
648                     y.setTelList(telList);
649                 });
650             }
651             entity.setContactsList(query);
652             //附件的输出
653             //处理图片,附件,生成调用url及相关信息
654             if (StringUtils.isNotBlank(entity.getImageList())) {
655                 FileStructEntity fileStructEntity = new FileStructEntity();
656                 fileStructEntity.setDbid(request.getDbid());
657                 fileStructEntity.setFormid(request.getFormId() + "");
658                 fileStructEntity.setFileStr(entity.getImageList());
659                 entity.setFiles(Utils.getFileEntities(fileStructEntity));
660             }
661         }
662         return entity;
663     }
664
665     @Override
035491 666     public void attention(CluesRequestEntity cluesRequest) {
05aec6 667         String sql = "update a set a.pinFlag=" + cluesRequest.getPinFlag() + " from t481104h a where id=" + cluesRequest.getId();
035491 668         this.doBaseExecute(sql);
F 669     }
d32c21 670     @Transactional(rollbackFor = Exception.class)
F 671     @Override
672     public void newAssign(AssignCluesEntity assignClues) {
673         if(StringUtils.isBlank(assignClues.getOwnerCode())&&StringUtils.isBlank(assignClues.getOwnerCcCode())){
674             throw new ApplicationException("部门和用户不能都为空");
675         }
676         String sql = " declare @refCode varchar(20),@ownerCode varchar(20),@ownerName varchar(20)\n" +
677                 " ,@ownerCcCode varchar(20),@ownerCcName varchar(20),@ownerType int=0" +
678                 "select @refCode=" + GridUtils.prossSqlParm(assignClues.getDocCode()) + ",@ownerCode=" + GridUtils.prossSqlParm(assignClues.getOwnerCode()) + ",@ownerName=" + GridUtils.prossSqlParm(assignClues.getOwnerName()) + ",@ownerCcCode=" + GridUtils.prossSqlParm(assignClues.getOwnerCcCode()) + ",@ownerCcName=" + GridUtils.prossSqlParm(assignClues.getOwnerCcName()) + "\n";
679         if(StringUtils.isNotBlank(assignClues.getOwnerCcCode())) {
680             sql+=" select @ownerType=1 \n";//表示当前线索是分配到个人,而不是部门
681         }
682                 sql+=" insert into t481104h(refCode          \n" +
683                 ",ownerCode        \n" +
684                 ",ownerName        \n" +
685                 ",ownerCcCode        \n" +
686                 ",ownerCcName        \n" +
687                 ",ownerType       \n" +
688                 ",enterTime       \n)values(@refCode,@ownerCode,@ownerName,@ownerType,getdate())";
689         this.doBaseExecute(sql);
690     }
035491 691
F 692     @Transactional(rollbackFor = Exception.class)
7204e3 693     @Override
d32c21 694     public void assign(AssignCluesEntity assignClues,String userName) {
F 695         String sql = " declare @id int,@reasonForRollback nvarchar(300),@refCode varchar(20),@ownerCode varchar(20),@ownerName varchar(20)\n" +
696                 "select @refCode=" + GridUtils.prossSqlParm(assignClues.getDocCode()) + ",@ownerCode=" + GridUtils.prossSqlParm(assignClues.getOwnerCode()) + ",@ownerName=" + GridUtils.prossSqlParm(assignClues.getOwnerName()) + ",@reasonForRollback='线索已移出,原因:"+userName+"重新分配给"+assignClues.getOwnerName()+"'\n" +
697                 " select @id=id from t481104h where refCode=@refCode\n" +
698                 " update t481104h set exitTime=getDate(),reasonForRollback=@reasonForRollback where id=@id\n" +
7204e3 699                 " insert into t481104h(refCode          \n" +
F 700                 ",ownerCode        \n" +
701                 ",ownerName        \n" +
702                 ",enterTime       \n)values(@refCode,@ownerCode,@ownerName,getdate())";
703         this.doBaseExecute(sql);
704     }
035491 705
F 706     @Override
707     public void changeStatus(T481104Entity entity) {
05aec6 708         String sql = " update a set a.cluesStatusFlag=" + entity.getCluesStatusFlag() + " from t481104h a where id= " + entity.getId();
035491 709         this.doBaseExecute(sql);
F 710     }
711
7204e3 712     /**
F 713      * 拼接查询条件
05aec6 714      *
7204e3 715      * @param request
F 716      * @return
717      */
718     private String getSearchInfo(CluesRequestEntity request) {
d32c21 719         //自已创建或已发布给指定人员或属于当前部门
F 720         String where = " and((((a.CreateUsercode="+GridUtils.prossSqlParm(request.getCreateUsercode())+" or (isnull(a.isPush,0)=1 and b.ownerCode="+GridUtils.prossSqlParm(request.getCreateUsercode())+")) and isnull(b.reasonForRollback,'')='') or b.ownerCcCode="+GridUtils.prossSqlParm(request.getCccode())+") \n";
7204e3 721         Set<Map.Entry<String, String>> entries = request.getSearchTxt().entrySet();
F 722         for (Map.Entry<String, String> entry : entries) {
05aec6 723             if (entry.getKey().equalsIgnoreCase("cluesName")) {
F 724                 where += " and a.clues_name like '%" + entry.getValue() + "%'";
7204e3 725             }
05aec6 726             if (entry.getKey().equalsIgnoreCase("isRead")) {
F 727                 where += " and isnull(b.isRead,0)=" + entry.getValue();
7204e3 728             }
05aec6 729             if (entry.getKey().equalsIgnoreCase("pinFlag")) {
F 730                 where += " and isnull(b.pinFlag,0)=" + entry.getValue();
7204e3 731             }
05aec6 732             if (entry.getKey().equalsIgnoreCase("ownerCode")) {
d32c21 733                 where += " and b.ownerCode  in (select list from getinstr( '" + entry.getValue() + "'))";
035491 734             }
05aec6 735             if (entry.getKey().equalsIgnoreCase("systemFlag")) {
F 736                 where += " and isnull(b.systemFlag,0) = " + entry.getValue() + "";
035491 737             }
05aec6 738             if (entry.getKey().equalsIgnoreCase("cluesStatusFlag")) {
F 739                 where += " and isnull(b.cluesStatusFlag,0) = " + entry.getValue() + "";
035491 740             }
05aec6 741             if (entry.getKey().equalsIgnoreCase("tagList")) {
F 742                 where += " and a.tag_List like '%" + entry.getValue() + "%'";
035491 743             }
05aec6 744             if (entry.getKey().equalsIgnoreCase("failStatus")) {
F 745                 where += " and isnull(a.failStatus,0) = " + entry.getValue() + "";
035491 746             }
05aec6 747             if (entry.getKey().equalsIgnoreCase("cluesStatusFlag")) {
F 748                 where += " and isnull(b.cluesStatusFlag,0) = " + entry.getValue() + "";
035491 749             }
05aec6 750             if (entry.getKey().equalsIgnoreCase("originList")) {
F 751                 where += " and a.originList like '%" + entry.getValue() + "%'";
035491 752             }
05aec6 753             if (entry.getKey().equalsIgnoreCase("createUsercode")) {
d32c21 754                 where += " and a.createUsercode in (select list from getinstr( '" + entry.getValue() + "'))";
035491 755             }
05aec6 756             if (entry.getKey().equalsIgnoreCase("country")) {
F 757                 where += " and a.country = '" + entry.getValue() + "'";
7204e3 758             }
05aec6 759             if (entry.getKey().equalsIgnoreCase("lastModifyTime")) {
F 760                 String[] value = entry.getValue().split(";");
7204e3 761
d32c21 762                 where += " and (b.lastModifyTime >= DATEADD(day, -" + value[0] + ", CAST(GETDATE() AS date))  )";
7204e3 763             }
d32c21 764             //TODO 后期增加处理联系,未联系功能
F 765
766             //处理是查询我的线索还是所有线索
767             //481101是公海线索,481104是私海线索
768
769
7204e3 770         }
05aec6 771         return where + " )";
703a8b 772     }
F 773
ae692b 774     public String contactUpdateSql(List<T482103Entity> contactsList,String contactType) {
05aec6 775         if (contactsList == null || contactsList.size() == 0) {
F 776             return "";
777         }
778         String sql = "";
779         for (T482103Entity contact : contactsList) {
780             if (StringUtils.isNotBlank(contact.getRefCode()) && contact.getId() == null) {
781                 List<T482103Entity> temp = new ArrayList<T482103Entity>();
703a8b 782                 temp.add(contact);
ae692b 783                 sql += contactAddSql(temp,contactType);
703a8b 784                 continue;
F 785             }
05aec6 786             sql += "\nselect\n" +
F 787                     " @main_customer_flag=" + contact.getMainCustomerFlag() + "\n" +
788                     ",@id=" + contact.getId() + "\n" +
789                     ",@name=" + GridUtils.prossSqlParm(contact.getName()) + "\n" +
790                     ",@contact_email=" + GridUtils.prossSqlParm(contact.getEmail()) + "\n" +
791                     ",@gender=" + GridUtils.prossSqlParm(contact.getGender()) + "\n" +
792                     ",@post=" + GridUtils.prossSqlParm(contact.getPost()) + "\n" +
793                     ",@remark=" + GridUtils.prossSqlParm(contact.getRemark()) + "\n" +
794                     ",@contact_image_list =" + GridUtils.prossSqlParm(contact.getImageList()) + "\n" +
795                     ",@birth=" + GridUtils.prossSqlParm(contact.getBirth()) + "\n" +
796                     ",@post_grade=" + GridUtils.prossSqlParm(contact.getPostGrade()) + "\n" +
703a8b 797                     ",@update_time=getdate()\n       " +
7204e3 798                     " update t482103 set\n" +
703a8b 799                     "main_customer_flag=@main_customer_flag \n" +
F 800                     ",name=@name               \n" +
801                     ",email=@contact_email      \n" +
802                     ",gender=@gender             \n" +
803                     ",post=@post               \n" +
804                     ",remark=@remark             \n" +
805                     ",image_list=@contact_image_list \n" +
806                     ",birth=@birth              \n" +
807                     ",post_grade=@post_grade         \n" +
7204e3 808                     ",update_time=@update_time   from   t482103 where id=@id \n  " +
703a8b 809                     " select @last_inserted_id=@id\n" +
05aec6 810                     mediaUpdateSql(contact.getMediaList()) +
703a8b 811                     telListUpdateSql(contact.getTelList());
F 812
813         }
814         return sql;
035491 815     }
05aec6 816
F 817     @Transactional(rollbackFor = Exception.class)
035491 818     @Override
F 819     public void contactDel(Integer id) {
05aec6 820         String sql = "declare @id int=" + id + ",@mainCustomerFlag int \n" +
035491 821                 " select @mainCustomerFlag=isnull(main_Customer_Flag,0) from t482103 where id=@id\n" +
F 822                 " if isnull(@mainCustomerFlag,0)=1 \n" +
823                 " begin \n" +
824                 "  raiserror('联系人已设置为主要联系人,不能删除',16,1)" +
825                 "  return" +
826                 " end\n" +
827                 " delete from t482116 where refid=@id\n" +
828                 " delete from t482111 where refid=@id\n" +
829                 "  delete from t482103 where id=@id";
830         this.doBaseExecute(sql);
703a8b 831     }
F 832
833     /**
834      * 生成联系人信息sql
05aec6 835      *
703a8b 836      * @param contactsList
F 837      * @return
838      */
ae692b 839     public String contactAddSql(List<T482103Entity> contactsList,String contactType) {
05aec6 840         if (contactsList == null || contactsList.size() == 0) {
F 841             return "";
842         }
843         String sql = "";
844         for (T482103Entity contact : contactsList) {
845             sql += "\nselect\n" +
846                     " @main_customer_flag=" + contact.getMainCustomerFlag() + "\n" +
847                     ",@refCode=@doccode\n" +
848                     ",@name=" + GridUtils.prossSqlParm(contact.getName()) + "\n" +
849                     ",@contact_email=" + GridUtils.prossSqlParm(contact.getEmail()) + "\n" +
850                     ",@gender=" + GridUtils.prossSqlParm(contact.getGender()) + "\n" +
851                     ",@post=" + GridUtils.prossSqlParm(contact.getPost()) + "\n" +
852                     ",@remark=" + GridUtils.prossSqlParm(contact.getRemark()) + "\n" +
853                     ",@contact_image_list =" + GridUtils.prossSqlParm(contact.getImageList()) + "\n" +
854                     ",@birth=" + GridUtils.prossSqlParm(contact.getBirth()) + "\n" +
855                     ",@post_grade=" + GridUtils.prossSqlParm(contact.getPostGrade()) + "\n" +
856                     ",@create_time =getdate()      \n" +
857                     ",@update_time=getdate()\n       " +
858                     " insert into t482103(" +
859                     "main_customer_flag \n" +
860                     ",refCode            \n" +
861                     ",name               \n" +
862                     ",email      \n" +
863                     ",gender             \n" +
864                     ",post               \n" +
865                     ",remark             \n" +
866                     ",image_list \n" +
867                     ",birth              \n" +
d32c21 868                     ",contactType        \n" +
05aec6 869                     ",post_grade         \n" +
F 870                     ",create_time        \n" +
871                     ",update_time        " +
872                     ")values(" +
873                     "@main_customer_flag \n" +
874                     ",@refCode            \n" +
875                     ",@name               \n" +
876                     ",@contact_email      \n" +
877                     ",@gender             \n" +
878                     ",@post               \n" +
879                     ",@remark             \n" +
880                     ",@contact_image_list \n" +
881                     ",@birth              \n" +
ae692b 882                     ",'"+contactType+"'   \n" +
05aec6 883                     ",@post_grade         \n" +
F 884                     ",@create_time        \n" +
885                     ",@update_time        " +
886                     ")\n" +
887                     " SELECT @last_inserted_id=IDENT_CURRENT('t482103')\n" +
888                     mediaAddSql(contact.getMediaList()) +
889                     telListAddSql(contact.getTelList());
703a8b 890         }
F 891         return sql;
892     }
05aec6 893
703a8b 894     /**
F 895      * 生成社交平台信息sql
05aec6 896      *
703a8b 897      * @param mediaEntityList
F 898      * @return
899      */
7204e3 900     private String mediaAddSql(List<T482111Entity> mediaEntityList) {
05aec6 901         if (mediaEntityList == null || mediaEntityList.size() == 0) {
F 902             return "";
903         }
904         String sql = "";
905         for (T482111Entity contact : mediaEntityList) {
906             sql += "\nselect\n" +
907                     " @media_type=" + GridUtils.prossSqlParm(contact.getType()) + "\n" +
908                     ",@media_value=" + GridUtils.prossSqlParm(contact.getValue()) + "\n" +
909                     ",@media_id=" + contact.getId() + "\n" +
703a8b 910                     ",@media_refid=@last_inserted_id\n" +
7204e3 911                     " insert into t482111(" +
703a8b 912                     "type \n" +
F 913                     ",value,refid            \n" +
914                     ")values(" +
915                     "@media_type \n" +
916                     ",@media_value                 \n" +
917                     ",@media_refid            \n" +
918                     ")\n";
919         }
920         return sql;
921     }
05aec6 922
703a8b 923     /**
F 924      * 修改社交平台信息sql
05aec6 925      *
703a8b 926      * @param mediaEntityList
F 927      * @return
928      */
7204e3 929     private String mediaUpdateSql(List<T482111Entity> mediaEntityList) {
05aec6 930         if (mediaEntityList == null || mediaEntityList.size() == 0) {
F 931             return "";
035491 932         }
05aec6 933         String sql = "";
F 934         //增加删除,保证最新
935         String collectIds = mediaEntityList.stream().filter(x -> x.getId() != null && x.getId() != 0).map(x -> x.getId() + "").collect(Collectors.joining(","));
936         if (collectIds.equalsIgnoreCase("")) {
937             //没有修改,都是新增情况
938             sql = " delete from t482111 \n";
939         } else {
940             sql = " delete from t482111 where id not in(" + collectIds + ")\n";
941         }
942         for (T482111Entity mediaEntity : mediaEntityList) {
943             if (mediaEntity.getId() == null) {
944                 List<T482111Entity> temp = new ArrayList<>();
703a8b 945                 temp.add(mediaEntity);
05aec6 946                 sql += mediaAddSql(temp);
703a8b 947                 continue;
F 948             }
05aec6 949             sql += "\nselect\n" +
F 950                     " @media_type=" + GridUtils.prossSqlParm(mediaEntity.getType()) + "\n" +
951                     ",@media_value=" + GridUtils.prossSqlParm(mediaEntity.getValue()) + "\n" +
952                     ",@media_id=" + mediaEntity.getId() + "\n" +
7204e3 953                     "  update t482111 set " +
703a8b 954                     "type=@media_type \n" +
05aec6 955                     ",value=@media_value from t482111 where   id=@media_id       \n";
703a8b 956         }
035491 957
F 958
703a8b 959         return sql;
F 960     }
05aec6 961
703a8b 962     /**
F 963      * 生成电话列表信息sql
05aec6 964      *
703a8b 965      * @param telListEntities
F 966      * @return
967      */
7204e3 968     private String telListAddSql(List<T482116Entity> telListEntities) {
05aec6 969         if (telListEntities == null || telListEntities.size() == 0) {
F 970             return "";
971         }
972         String sql = "";
973         for (T482116Entity contact : telListEntities) {
974             sql += "\nselect\n" +
975                     " @areaCode=" + GridUtils.prossSqlParm(contact.getAreaCode()) + "\n" +
976                     ",@telList_tel=" + GridUtils.prossSqlParm(contact.getTel()) + "\n" +
977                     ",@telList_id=" + contact.getId() + "\n" +
703a8b 978                     ",@telList_refid=@last_inserted_id\n" +
7204e3 979                     " insert into t482116(" +
703a8b 980                     "areaCode \n" +
F 981                     ",tel ,refid           \n" +
982                     ")values(" +
983                     "@areaCode \n" +
984                     ",@telList_tel                 \n" +
985                     ",@telList_refid            \n" +
986                     ")\n";
987         }
988         return sql;
989     }
05aec6 990
703a8b 991     /**
F 992      * 生成电话列表信息sql
05aec6 993      *
703a8b 994      * @param telListEntities
F 995      * @return
996      */
7204e3 997     private String telListUpdateSql(List<T482116Entity> telListEntities) {
05aec6 998         if (telListEntities == null || telListEntities.size() == 0) {
F 999             return "";
1000         }
1001         String sql = "";
035491 1002         //增加删除,保证最新
05aec6 1003         String collectIds = telListEntities.stream().filter(x -> x.getId() != null && x.getId() != 0).map(x -> x.getId() + "").collect(Collectors.joining(","));
F 1004         if (collectIds.equalsIgnoreCase("")) {
1005             //没有修改,都是新增情况
1006             sql = " delete from t482116 \n";
1007         } else {
1008             sql = " delete from t482116 where id not in(" + collectIds + ")\n";
1009         }
1010         for (T482116Entity telListEntity : telListEntities) {
1011             if (telListEntity.getId() == null) {
1012                 List<T482116Entity> temp = new ArrayList<>();
703a8b 1013                 temp.add(telListEntity);
05aec6 1014                 sql += telListAddSql(temp);
703a8b 1015                 continue;
F 1016             }
05aec6 1017             sql += "\nselect\n" +
F 1018                     " @areaCode=" + GridUtils.prossSqlParm(telListEntity.getAreaCode()) + "\n" +
1019                     ",@telList_tel=" + GridUtils.prossSqlParm(telListEntity.getTel()) + "\n" +
703a8b 1020                     ",@telList_refid=@last_inserted_id\n" +
05aec6 1021                     ",@telList_id=" + telListEntity.getId() + "\n" +
7204e3 1022                     " update  t482116 set " +
703a8b 1023                     "areaCode=@areaCode \n" +
F 1024                     ",tel=@telList_tel            \n" +
035491 1025                     " from t482116 where id=@telList_id\n";
703a8b 1026         }
F 1027         return sql;
1028     }
1029 }