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