Administrator
2023-03-10 1c4e40639d73faae3ba87156e0e4478c50b8ee33
提交 | 用户 | 时间
58d006 1 package com.mandi.fendan.service.impl;
A 2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.regex.Matcher;
7 import java.util.regex.Pattern;
8
9 import javax.annotation.Resource;
10
11 import org.apache.commons.lang3.StringUtils;
12 import org.springframework.stereotype.Service;
13 import org.springframework.transaction.annotation.Transactional;
14
15 import com.mandi.basicconfig.persist.Ncfhdq;
16 import com.mandi.dao.common.Daomethod;
17 import com.mandi.dao.common.ObjectResult;
18 import com.mandi.dao.common.PageRequest;
19 import com.mandi.dao.common.PageResult;
20 import com.mandi.fendan.mapper.Fd_CompanyMapper;
21 import com.mandi.fendan.mapper.Fd_fhdqMapper;
22 import com.mandi.fendan.persist.Fd_Company;
23 import com.mandi.fendan.persist.Fd_wlgs_fhdq;
24 import com.mandi.fendan.service.IFd_fhdqService;
25
26 @Service
27 public class Fd_fhdqService implements IFd_fhdqService{
28     
29     @Resource
30     private Fd_fhdqMapper dqper;
31     @Resource
32     private Fd_CompanyMapper fdcper;
33
34     @Override
35     public PageResult<Map<String, Object>> getList(PageRequest pr,String search, int state) {
36         PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
37         Map<String, Object> pmp=new HashMap<String, Object>();
38 //        List<Map<String, Object>> relist=new ArrayList<Map<String,Object>>();
39         if(pr==null){
40             pr=new PageRequest(0,30,null);
41         }
42         pmp.put("page",pr.getStart());
43         pmp.put("pagesize",pr.getPageSize());
44         if(!StringUtils.isEmpty(search)){
45             pmp.put("name",search);
46         }
47         if(state>0){
48             pmp.put("state",state>1?0:1);
49         }
50         if(pr.isNeedPages()){
51             int count=this.dqper.count(pmp);
52             int pages=Daomethod.countpages(count, pr.getPageSize());
53             prr.setPages(pages);
54         }
55         List<Map<String, Object>> l=this.dqper.getlist(pmp);
56 //        if(l!=null){
57 //            for (Map<String, Object> ncfhdq : l) {
58 //                Map<String, Object> rs=ncfhdq;
59 //                try {
60 //                    rs = BeanUtils.describe(ncfhdq);
61 //                } catch (IllegalAccessException | InvocationTargetException
62 //                        | NoSuchMethodException e) {
63 //                }
64 //                String code=(ncfhdq.get("code")+"");
65 //                List<Fd_Company> cl=this.dqper.getCbyNo(code);
66 //                rs.put("fd_companyS", cl);
67 //                relist.add(rs);
68 //            }
69 //        }
70         prr.setCode(0);
71         prr.setList(l);
72         return prr;
73     }
74
75     @Override
76     @Transactional(rollbackFor=Exception.class)
77     public ObjectResult<Boolean> savewlgs_fhdq(String fhdqNo, String wlgsNos,String ywdyNo,boolean xgxj)throws Exception {
78         ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
79         if(StringUtils.isBlank(fhdqNo)){
80             orr.setCode(1);
81             orr.setErrmsg("发货地区参数为空!");
82             return orr;
83         }
84         Pattern pattern = Pattern.compile("[0-9]*");
85         Matcher isNum = pattern.matcher(fhdqNo.charAt(0)+"");
86         if(fhdqNo.length()<2||!isNum.matches()){
87             orr.setCode(1);
88             orr.setErrmsg("发货地区编号验证不通过!");
89             return orr;
90         }
91         Ncfhdq dq=this.dqper.getbyCode(fhdqNo);
92         if(dq==null){
93             orr.setCode(1);
94             orr.setErrmsg("参数错误,发货地区字典错我!");
95             return orr;
96         }
97         if(!xgxj){
98             this.dqper.delbyCode(fhdqNo,ywdyNo);
99             if(!StringUtils.isEmpty(wlgsNos)){
100                 for (int i = 0; i <wlgsNos.split(",").length; i++) {
101                     String wlgsNo=wlgsNos.split(",")[i];
102                     Fd_Company fdc=this.fdcper.getByCompanyNo(wlgsNo);
103                     if(fdc!=null){
104                         Fd_wlgs_fhdq wldq=new Fd_wlgs_fhdq();
105                         wldq.setFhdqNo(fhdqNo);
106                         wldq.setWlgsNo(wlgsNo);
107                         wldq.setYwdyNo(ywdyNo);
108                         this.dqper.insertWlsg_fhdq(wldq);
109                     }
110                 }
111             }
112         }else{
113             String Str="";
114             if(fhdqNo.length()==2){
115                 Str=StringUtils.substring(fhdqNo,0, 2);
116             }else{
117                 if(StringUtils.substring(fhdqNo,2, 4).equals("00")){
118                     Str=StringUtils.substring(fhdqNo,0, 2);
119                 }else{
120                     Str=StringUtils.substring(fhdqNo,0, fhdqNo.length()-2);
121                 }
122             }
123             List<Ncfhdq> lr=this.dqper.getLikebydqNo(Str);
124             if(lr!=null){
125                 for (Ncfhdq dr : lr) {
126                     this.dqper.delbyCode(dr.getCode(),ywdyNo);
127                     if(!StringUtils.isEmpty(wlgsNos)){
128                         for (int i = 0; i <wlgsNos.split(",").length; i++) {
129                             String wlgsNo=wlgsNos.split(",")[i];
130                             Fd_Company fdc=this.fdcper.getByCompanyNo(wlgsNo);
131                             if(fdc!=null){
132                                 Fd_wlgs_fhdq wldq=new Fd_wlgs_fhdq();
133                                 wldq.setFhdqNo(dr.getCode());
134                                 wldq.setWlgsNo(wlgsNo);
135                                 wldq.setYwdyNo(ywdyNo);
136                                 this.dqper.insertWlsg_fhdq(wldq);
137                             }
138                         }
139                     }
140                 }
141             }
142             
143         }
144         orr.setCode(0);
145         orr.setItem(true);
146         return orr;
147     }
148
149 }