package com.goafanti.admin.service.impl; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.goafanti.admin.bo.BusinessProjectBo; import com.goafanti.admin.bo.ProjectSizeBo; import com.goafanti.admin.service.BusinessProjectService; import com.goafanti.common.dao.BusinessProjectMapper; import com.goafanti.common.dao.BusinessVarietiesMapper; import com.goafanti.common.model.BusinessProject; import com.goafanti.common.model.BusinessVarieties; import com.goafanti.common.utils.StringUtils; import com.goafanti.core.mybatis.BaseMybatisDao; import com.goafanti.core.mybatis.page.Pagination; @Service public class BusinessProjectServiceImpl extends BaseMybatisDao implements BusinessProjectService { @Autowired BusinessProjectMapper businessProjectMapper; @Autowired BusinessVarietiesMapper businessVarietiesMapper; @Override public int insert(String bname, String cid, String country, String province, String city, String district) { BusinessProject bp=new BusinessProject(); bp.setId(UUID.randomUUID().toString()); bp.setBname(bname); bp.setCid(cid); bp.setCountry(country); if (1!=Integer.valueOf(country)) { bp.setProvince(province); bp.setCity(city); bp.setDistrict(district); } bp.setDeleteSign(0); //bp.setCreateId(TokenManager.getAdminId()); bp.setCreateId("f31c0d1a-05bc-4f5c-b4a8-95f983d24131"); bp.setCreateTime(new Date()); bp.setStatus("0"); return businessProjectMapper.insert(bp); } @SuppressWarnings("unchecked") @Override public Pagination listProject(String bname, String cid, String country,String province,String city,String district, String activityFlag, String status, Integer pNo, Integer pSize) { if (pNo == null || pNo < 0) { pNo = 1; } if (pSize == null || pSize < 0 || pSize > 10) { pSize = 10; } return (Pagination)findPage("findProjectListByPage", "findProjectListCount", disposeParams(bname, cid, country, province, city, district, activityFlag, status),pNo,pSize); } private Map disposeParams(String bname, String cid, String country,String province,String city,String district, String activityFlag, String status) { Map params = new HashMap<>(); if (StringUtils.isNotBlank(bname)) { params.put("bname", bname); } if (StringUtils.isNotBlank(cid)) { params.put("cid", cid); } if (StringUtils.isNotBlank(country)) { params.put("country", country); } if (StringUtils.isNotBlank(province)) { params.put("province", province); } if (StringUtils.isNotBlank(city)) { params.put("city", city); } if (StringUtils.isNotBlank(district)) { params.put("district", district); } if (StringUtils.isNotBlank(activityFlag)) { params.put("activityFlag", activityFlag); } if (StringUtils.isNotBlank(status)) { params.put("status", status); } return params; } @Override public int getBnamecount(String bname) { return businessProjectMapper.getBnamecount(bname); } @Override public int deleteProject(String id) { BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id); if (bp.getDeleteSign()==0) { bp.setDeleteSign(1); }else { bp.setDeleteSign(0); } return businessProjectMapper.updateByPrimaryKey(bp); } @Override public int updateStopProject(String id) { BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id); if (Integer.valueOf(bp.getStatus())==0) { bp.setStatus("1"); }else { bp.setStatus("0"); } return businessProjectMapper.updateByPrimaryKey(bp); } @Override public BusinessProjectBo orgProject(String id) { BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id); BusinessProjectBo bpo=new BusinessProjectBo(); BeanUtils.copyProperties(bp,bpo); String cname=getAllCname(bpo.getCid()); System.out.println(cname); bpo.setCname(cname); return bpo; } @Override public List> getAllCname() { List> list=new ArrayList>(); List listcid=businessVarietiesMapper.getListId(); for (String s : listcid) { Map map=new HashMap<>(); String cname=getAllCname(s); map.put("id", s); map.put("cname", cname); if (StringUtils.isNotBlank(cname)) { list.add(map); } } return list; } /** * 递归获取上级来获取全路径 * @param s ID * @return 路径 */ private String getAllCname(String s) { String cid=businessVarietiesMapper.getThisCid(s); String cname=businessVarietiesMapper.getThisCname(cid); BusinessVarieties bv=businessVarietiesMapper.selectByPrimaryKey(s); String sid=bv.getSuperId(); if (cid.length()>4) { String w=getAllCname(sid)+"-"+cname; return w; }else{ return cid.length()>3?cname:""; } } @Override public int updateAddOffset(String id) { BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id); if (null==bp.getOffset()) { bp.setOffset(new BigDecimal(1)); } if (bp.getOffset().compareTo(new BigDecimal(1))==-1) { bp.setOffset(bp.getOffset().add(new BigDecimal(0.01))); } return businessProjectMapper.updateByPrimaryKey(bp); } @Override public int updateSubtractOffset(String id) { BusinessProject bp=businessProjectMapper.selectByPrimaryKey(id); if (null==bp.getOffset()) { bp.setOffset(new BigDecimal(1)); } if (bp.getOffset().compareTo(new BigDecimal(0))==1) { bp.setOffset(bp.getOffset().subtract(new BigDecimal(0.01))); } return businessProjectMapper.updateByPrimaryKey(bp); } /*public ProjectSizeBo orgProjectSize(String id) { return null; }*/ }