package com.mandi.fendan.service.impl;
|
|
import java.lang.reflect.InvocationTargetException;
|
import java.util.*;
|
|
import javax.annotation.Resource;
|
import javax.transaction.Transactional;
|
|
import com.mandi.fendan.mapper.FdMxWlgsMapper;
|
import com.mandi.system.persist.Login;
|
import com.mandi.system.persist.UserType;
|
import org.springframework.stereotype.Service;
|
|
import com.google.gson.JsonObject;
|
import com.mandi.fendan.persist.Fd_Company;
|
import com.mandi.fendan.persist.Fd_Vehicle;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
import org.apache.commons.lang3.StringUtils;
|
|
import com.mandi.basicconfig.mapper.NczsjMapper;
|
import com.mandi.basicconfig.penum.PrefixEnum;
|
import com.mandi.basicconfig.persist.Ncywdy;
|
import com.mandi.common.JSONobj;
|
import com.mandi.common.Wxhtmethod;
|
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_VehicleMapper;
|
import com.mandi.fendan.mapper.Fd_fhdqMapper;
|
import com.mandi.fendan.service.Ifd_companyService;
|
import com.mandi.fendan.util.Contants;
|
import com.mandi.common.Pinyinmethod;
|
@Service
|
public class Fd_CompanyService implements Ifd_companyService {
|
@Resource
|
private Fd_CompanyMapper cmper;
|
@Resource
|
private Fd_fhdqMapper dqper;
|
@Resource
|
private Fd_VehicleMapper vhper;
|
@Resource
|
private NczsjMapper zsjper;
|
|
@Resource
|
private FdMxWlgsMapper fdMxWlgsMapper;
|
|
@Override
|
public ObjectResult<Fd_Company> get(String id) {
|
ObjectResult<Fd_Company> prr = new ObjectResult<Fd_Company>();
|
if(!StringUtils.isBlank(id)){
|
Fd_Company fcy = cmper.get(id);
|
prr.setCode(0);
|
prr.setItem(fcy);
|
}else{
|
prr.setCode(1);
|
prr.setErrmsg("编号不能为空");;
|
}
|
|
return prr;
|
}
|
@Override
|
public ObjectResult<Fd_Company> getByCompanyNo(String companyNo) {
|
ObjectResult<Fd_Company> prr = new ObjectResult<Fd_Company>();
|
if(!StringUtils.isBlank(companyNo)){
|
Fd_Company fcy = cmper.getByCompanyNo(companyNo);
|
prr.setCode(0);
|
prr.setItem(fcy);
|
}else{
|
prr.setCode(1);
|
prr.setErrmsg("公司编号不能为空");;
|
}
|
|
return prr;
|
}
|
|
@Override
|
public PageResult<Map<String, Object>> getlist(String name, PageRequest pr) {
|
PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>();
|
List<Map<String, Object>> rl=new ArrayList<Map<String,Object>>();
|
Map<String, Object> mp=new HashMap<String, Object>();
|
mp.put("pagesize", pr.getPageSize());
|
mp.put("page", pr.getStart());
|
mp.put("name", name);
|
List<Fd_Company> list;
|
if(pr.isNeedPages())
|
{
|
int pages=cmper.getPages(mp);
|
pages=Daomethod.countpages(pages, pr.getPageSize());
|
prr.setPages(pages);
|
list =cmper.getList(mp);
|
}else{
|
list = cmper.getList1(mp);
|
}
|
|
if(list!=null){
|
for (Fd_Company fdc : list) {
|
String comNo=fdc.getCompanyNo();
|
Map<String, Object> rm=new HashMap<String, Object>();
|
try {
|
rm=BeanUtils.describe(fdc);
|
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
}
|
List<Ncywdy> cyl=this.cmper.getncYwdylist(comNo);
|
rm.put("ywList", cyl);
|
rl.add(rm);
|
}
|
}
|
prr.setCode(0);
|
prr.setList(rl);
|
return prr;
|
}
|
|
@Override
|
public List<Map<String, Object>> companytypehead(String search, int pagesize) {
|
|
return null;
|
}
|
|
@Override
|
public ObjectResult<Fd_Company> saveCompany(Fd_Company c,String ywdyNos) throws Exception {
|
ObjectResult<Fd_Company> orr=new ObjectResult<Fd_Company>();
|
if(c==null){
|
orr.setCode(1);
|
orr.setErrmsg("运输公司对象为空,不能保存");
|
return orr;
|
}
|
if(StringUtils.isEmpty(c.getName())){
|
orr.setCode(1);
|
orr.setErrmsg("运输公司名字为空,不能保存");
|
return orr;
|
}
|
String hdpinyin=Pinyinmethod.pinyinhds(c.getName());
|
String pinyin=Pinyinmethod.pinyins(c.getName());
|
c.setPinyin(pinyin);
|
c.setHdpinyin(hdpinyin);
|
String id=c.getId();
|
try {
|
Fd_Company c1= cmper.get(id);
|
if(c1!=null){
|
Fd_Company fcd=cmper.getByCompanyNo(c.getCompanyNo());
|
if(fcd!=null&&!fcd.getId().equals(c1.getId())){
|
orr.setCode(1);
|
orr.setErrmsg("运输公司编号已存在,不能保存,请修改!");
|
return orr;
|
}
|
|
c1.setCname(c.getCname());
|
c1.setHdpinyin(c.getHdpinyin());
|
c1.setPinyin(c.getPinyin());
|
c1.setNote(c.getNote());
|
c1.setCtime(new Date());
|
c1.setCompanyNo(c.getCompanyNo());
|
c1.setHasSPR(c.isHasSPR());
|
c1.setName(c.getName());
|
c1.setShortName(c.getShortName());
|
cmper.update(c1);
|
this.cmper.delCYnexus(c.getCompanyNo());
|
orr.setItem(c1);
|
}else{
|
if(StringUtils.isEmpty(c.getCompanyNo())){
|
JsonObject pfob=Wxhtmethod.postJsonStr(Contants.YKTgetPrefix_url,PrefixEnum.fd_Company.toString());
|
ObjectResult<String> pfor=new ObjectResult<String>();
|
String bsNo=JSONobj.getstring(pfob, "item");
|
int code=JSONobj.getint(pfob, "code");
|
String errmsg=JSONobj.getstring(pfob, "errmsg");
|
pfor.setCode(code);
|
pfor.setErrmsg(errmsg);
|
pfor.setItem(bsNo);
|
if(pfor==null||pfor.getCode()!=0){
|
orr.setCode(1);
|
orr.setErrmsg(pfor.getErrmsg());
|
return orr;
|
}
|
c.setCompanyNo(pfor.getItem());
|
}else{
|
Fd_Company fcd=cmper.getByCompanyNo(c.getCompanyNo());
|
if(fcd!=null){
|
orr.setCode(1);
|
orr.setErrmsg("运输公司编号已存在,不能保存,请修改!");
|
return orr;
|
}
|
}
|
c.setCtime(new Date());
|
c.setId(UUID.randomUUID()+"");
|
cmper.insert(c);
|
orr.setItem(c);
|
}
|
} catch (Exception e) {
|
throw new Exception(StringUtils.isEmpty(e.getMessage())?"物流公司保存出错!":e.getMessage());
|
}
|
//修改运输公司和业务单元关联表
|
if(!StringUtils.isEmpty(ywdyNos)){
|
for (String ywdyNo : ywdyNos.split(",")) {
|
Ncywdy ywdy=this.zsjper.getNcywdybyCode(ywdyNo);
|
if(ywdy==null)
|
continue;
|
this.cmper.insertCYnexus(c.getCompanyNo(), ywdyNo);
|
}
|
}
|
|
orr.setCode(0);
|
orr.setItem(c);
|
return orr;
|
}
|
|
@Override
|
public ObjectResult<Boolean> changeUsed(Fd_Company cp) {
|
|
return null;
|
}
|
|
@Override
|
@Transactional(rollbackOn=Exception.class)
|
public ObjectResult<Boolean> delCompany(String companyNo) throws Exception{
|
ObjectResult<Boolean> prr = new ObjectResult<Boolean>();
|
if(!StringUtils.isBlank(companyNo)){
|
|
try {
|
Fd_Vehicle fdv=this.vhper.selectbyCompanyNo(companyNo);
|
if(fdv!=null){
|
prr.setCode(1);
|
prr.setErrmsg("请先删除所属的该物流公司的车辆信息!");
|
return prr;
|
}
|
cmper.delByCompanyNo(companyNo);
|
this.dqper.delbywlgsCode(companyNo);
|
this.cmper.delCYnexus(companyNo);
|
prr.setCode(0);
|
prr.setItem(true);
|
} catch (Exception e) {
|
throw new Exception(StringUtils.isEmpty(e.getMessage())?"物流公司删除程序出错!":e.getMessage());
|
}
|
prr.setCode(0);
|
prr.setItem(true);
|
}else{
|
prr.setCode(1);
|
prr.setErrmsg("公司编号不能为空");
|
}
|
return prr;
|
|
}
|
|
|
@Override
|
public PageResult<Map<String, Object>> getcqList(String companyNo) {
|
PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
|
LinkedList<Map<String, Object>> rl=new LinkedList<>();
|
if(StringUtils.isNotBlank(companyNo)){
|
List<Ncywdy> l=this.cmper.getncYwdylist(companyNo);
|
|
Map<String, Ncywdy> map = new HashMap<>();
|
for (Ncywdy ncy : l) { // 排重
|
if (map.get(ncy.getCode()) == null)
|
map.put(ncy.getCode(), ncy);
|
}
|
int a = 0;
|
for (Map.Entry<String, Ncywdy> entry : map.entrySet()) {
|
String code = entry.getKey();
|
Map<String, Object> m = null;
|
if(Contants.nc_ywdy_ZZ.equals(code)){
|
m = new HashMap<>(2);
|
m.put("name","郑州厂区");
|
m.put("cqval",Contants.nc_ywdy_ZZ);
|
}else if(Contants.nc_ywdy_MS.equals(code)){
|
m = new HashMap<>(2);
|
m.put("name","明晟厂区");
|
m.put("cqval",Contants.nc_ywdy_MS);
|
}else if(Contants.nc_ywdy_YR.equals(code)){
|
m = new HashMap<>(2);
|
m.put("name","义瑞厂区");
|
m.put("cqval",Contants.nc_ywdy_YR);
|
} else{
|
if(a==0){ // 防止出现多个科技厂区
|
m = new HashMap<>(2);
|
m.put("name","科技厂区");
|
m.put("cqval",Contants.nc_ywdy_KJ);
|
a=1;
|
// 特殊需求 科技要放到第一个
|
rl.addFirst(m);
|
}
|
// 防止出现空行
|
continue;
|
}
|
rl.add(m);
|
}
|
prr.setList(rl);
|
}else{
|
Map<String, Object> m2=new HashMap<String, Object>();
|
m2.put("name","全部厂区");
|
m2.put("cqval","");
|
rl.add(m2);
|
Map<String, Object> m=new HashMap<String, Object>();
|
m.put("name","科技厂区");
|
m.put("cqval",Contants.nc_ywdy_KJ);
|
rl.add(m);
|
Map<String, Object> m1=new HashMap<String, Object>();
|
m1.put("name","郑州厂区");
|
m1.put("cqval",Contants.nc_ywdy_ZZ);
|
rl.add(m1);
|
Map<String, Object> m3=new HashMap<String, Object>();
|
m3.put("name","明晟厂区");
|
m3.put("cqval",Contants.nc_ywdy_MS);
|
rl.add(m3);
|
Map<String, Object> m4=new HashMap<String, Object>();
|
m4.put("name","义瑞厂区");
|
m4.put("cqval",Contants.nc_ywdy_YR);
|
rl.add(m4);
|
prr.setList(rl);
|
}
|
prr.setCode(0);
|
return prr;
|
}
|
@Override
|
public PageResult<Map<String, Object>> getFdCqList(String companyNo, Login login) {
|
PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
|
LinkedList<Map<String, Object>> rl=new LinkedList<>();
|
if (!UserType.admin.toString().equals(login.getWorkerno())) {
|
List<Map> l= fdMxWlgsMapper.selectChangqu(login.getUsername());
|
|
Map<String,Map> map = new HashMap<>();
|
for (Map map1 : l) { // 排重
|
if (map1.get(map1.get("fd_cq")) == null)
|
map.put(map1.get("fd_cq").toString(), map1);
|
}
|
int a = 0;
|
for (Map.Entry<String, Map> entry : map.entrySet()) {
|
String code = entry.getKey();
|
Map<String, Object> m = null;
|
if(Contants.nc_ywdy_ZZ.equals(code)){
|
m = new HashMap<>(2);
|
m.put("name","郑州厂区");
|
m.put("cqval",Contants.nc_ywdy_ZZ);
|
}else if(Contants.nc_ywdy_MS.equals(code)){
|
m = new HashMap<>(2);
|
m.put("name","明晟厂区");
|
m.put("cqval",Contants.nc_ywdy_MS);
|
}else if(Contants.nc_ywdy_YR.equals(code)){
|
m = new HashMap<>(2);
|
m.put("name","义瑞厂区");
|
m.put("cqval",Contants.nc_ywdy_YR);
|
} else{
|
if(a==0){ // 防止出现多个科技厂区
|
m = new HashMap<>(2);
|
m.put("name","科技厂区");
|
m.put("cqval",Contants.nc_ywdy_KJ);
|
a=1;
|
// 特殊需求 科技要放到第一个
|
rl.addFirst(m);
|
}
|
// 防止出现空行
|
continue;
|
}
|
rl.add(m);
|
}
|
prr.setList(rl);
|
}else{
|
Map<String, Object> m2=new HashMap<String, Object>();
|
m2.put("name","全部厂区");
|
m2.put("cqval","");
|
rl.add(m2);
|
Map<String, Object> m=new HashMap<String, Object>();
|
m.put("name","科技厂区");
|
m.put("cqval",Contants.nc_ywdy_KJ);
|
rl.add(m);
|
Map<String, Object> m1=new HashMap<String, Object>();
|
m1.put("name","郑州厂区");
|
m1.put("cqval",Contants.nc_ywdy_ZZ);
|
rl.add(m1);
|
Map<String, Object> m3=new HashMap<String, Object>();
|
m3.put("name","明晟厂区");
|
m3.put("cqval",Contants.nc_ywdy_MS);
|
rl.add(m3);
|
Map<String, Object> m4=new HashMap<String, Object>();
|
m4.put("name","义瑞厂区");
|
m4.put("cqval",Contants.nc_ywdy_YR);
|
rl.add(m4);
|
prr.setList(rl);
|
}
|
prr.setCode(0);
|
return prr;
|
}
|
|
|
}
|