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;
|
}
|
|
}
|