package com.xzx.gc.system.service; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Dict; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.exception.RestException; import com.xzx.gc.common.utils.BusinessUtil; import com.xzx.gc.common.utils.RedisUtil; import com.xzx.gc.entity.*; import com.xzx.gc.model.admin.ItemModel; import com.xzx.gc.model.admin.OrderModel; import com.xzx.gc.model.admin.StorageModel; import com.xzx.gc.model.order.FenceDto; import com.xzx.gc.model.order.ItemDto; import com.xzx.gc.model.system.QueryParentDTO; import com.xzx.gc.model.system.SysEnvironmentalInfoListReq; import com.xzx.gc.model.system.SysEnvironmentalInfoReq; import com.xzx.gc.model.system.SysEnvironmentalInfoVo; import com.xzx.gc.system.mapper.AddressMapper; import com.xzx.gc.system.mapper.OrderItemInfoMapper; import com.xzx.gc.system.mapper.OrderStorageDetailMapper; import com.xzx.gc.system.mapper.SysEnvironmentalInfoMapper; import com.xzx.gc.util.DoubleUtil; import com.xzx.gc.util.SessionUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import tk.mybatis.mapper.entity.Example; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @Service @Transactional @Slf4j public class SysEnvironmentalInfoService{ @Autowired private SysEnvironmentalInfoMapper sysEnvironmentalInfoMapper; @Autowired private UserService userService; @Autowired private BusinessUtil businessUtil; @Autowired private PartnerGaodeService partnerGaodeService; @Autowired private FenceService fenceService; @Autowired private AddressMapper addressMapper; @Autowired private CityPartnerService cityPartnerService; @Autowired private AddressLevelService addressLevelService; @Autowired private OrderService orderService; @Autowired private OrderItemInfoMapper orderItemInfoMapper; @Autowired private OrderStorageDetailMapper orderStorageDetailMapper; @Autowired private SysItemPriceService sysItemPriceService; public List getSysEnvironmentalInfoList(SysEnvironmentalInfoReq sysEnvironmentalInfoReq) { //回收员ID String receiver = sysEnvironmentalInfoReq.getReceiver(); String townId=Constants.TIANXIN_CODE; int unionFlag = sysEnvironmentalInfoReq.getUnionFlag(); List byPartnerId=CollUtil.newArrayList(); //区域id 安卓会传送同时分类将显示所有合伙人区域下的分类取并集 String areaId = sysEnvironmentalInfoReq.getAreaId(); if (StrUtil.isBlank(areaId)) { if(StrUtil.isNotBlank(sysEnvironmentalInfoReq.getAddressId())){ AddressInfo addressInfo = addressMapper.selectByPrimaryKey(sysEnvironmentalInfoReq.getAddressId()); if(StrUtil.isNotBlank(addressInfo.getTownshipId())) { FenceDto fence = fenceService.getFence(addressInfo.getTownshipId(), false, addressInfo.getLongitude(), addressInfo.getLatitude(), true); if (StrUtil.isNotBlank(fence.getFenceId())) { townId = fenceService.findTownId(addressInfo.getTownshipId(), fence.getFenceId()); } }else { townId=Constants.DEFAULT_ID; } }else { //普通用户 String longitude = sysEnvironmentalInfoReq.getLongitude(); if(StrUtil.isNotBlank(longitude)){ String latitude = sysEnvironmentalInfoReq.getLatitude(); String location = longitude + "," + latitude; //根据用户经纬度查询位置 AddressLevelInfo byLocation = userService.findByLocation(location); if (byLocation != null) { townId = byLocation.getLevel3Id(); FenceDto fence = fenceService.getFence(townId, false, location.split(",")[0], location.split(",")[1], true); if(StrUtil.isNotBlank(fence.getFenceId())){ townId =fenceService.findTownId(townId, fence.getFenceId()); } } } } } else { townId=sysEnvironmentalInfoReq.getAreaId(); if(unionFlag==1) { //根据区域查询合伙人Id PartnerGaode byTownId = partnerGaodeService.findByTownId(townId); String partnerId = byTownId.getPartnerId(); //根据合伙人查询所有分类 byPartnerId =findByPartnerIdForSecond(partnerId); } } //要根据用户所在的市去查找对应的分类价格 List list; //type 1为大类 2为物品 Dict dict = Dict.create().set("type", 1); dict.set("cityId",townId); //是否首页展示 // if("1".equals(sysEnvironmentalInfoReq.getHomeFlag())){ // dict.set("showFlag","1"); // } list = sysEnvironmentalInfoMapper.getSysEnvironmentalInfoListWithMap(dict); if(CollUtil.isNotEmpty(list)){ setSecondList(list,townId,false,receiver); //合伙人区域下的分类取并集 if(unionFlag==1){ setUnion(list, byPartnerId); } }else { //取天心区的分类 但不显示价格 townId=Constants.TIANXIN_CODE; dict = Dict.create().set("type", 1); dict.set("cityId",townId); list = sysEnvironmentalInfoMapper.getSysEnvironmentalInfoListWithMap(dict); if(CollUtil.isNotEmpty(list)){ setSecondList(list,townId,true,receiver); } } return list; } public List homeAppliance(String townId) { townId=Constants.TIANXIN_CODE; List byCityId = getByTownIdForHome(townId); if(CollUtil.isEmpty(byCityId)){ townId=Constants.TIANXIN_CODE; byCityId=getByTownIdForHome(townId); } return byCityId; } private List getByTownIdForHome(String townId){ Dict dict = Dict.create().set("type", 1); dict.set("cityId",townId); List list = sysEnvironmentalInfoMapper.getSysEnvironmentalInfoListWithMap(dict); list=list.stream().filter(x->x.getItemType().equals(Constants.HOUSE_HOLD_ITEM_TYPE)||x.getItemType().equals(Constants.HOUSE_HOLD_OTHER_ITEM_TYPE)).collect(Collectors.toList()); if(CollUtil.isNotEmpty(list)){ setSecondList(list,townId,false,null); } return list; } public List findByPartnerIdForSecond(String partnerId){ Example example=new Example(SysEnvironmentalInfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("delFlag",Constants.DEL_NOT_FLAG); criteria.andEqualTo("partnerId",partnerId); criteria.andIsNotNull("parentId"); return sysEnvironmentalInfoMapper.selectByExample(example); } private void setUnion( List list,List byPartnerId){ List allList=CollUtil.newArrayList(); for (SysEnvironmentalInfoVo sysEnvironmentalInfoVo:list){ List list1 = sysEnvironmentalInfoVo.getList(); CollUtil.addAll(allList,list1); } for (SysEnvironmentalInfo sysEnvironmentalInfo : byPartnerId) { String itemType = sysEnvironmentalInfo.getItemType(); long count = allList.stream().filter(x -> x.getItemType().equals(itemType)).count(); if(count==0){ //不属于当前区域的价格全都置于0 SysEnvironmentalInfoVo sysEnvironmentalInfoVo=new SysEnvironmentalInfoVo(); BeanUtil.copyProperties(sysEnvironmentalInfo,sysEnvironmentalInfoVo); sysEnvironmentalInfoVo.setPrice(Constants.MONEY_INIT.toString()); sysEnvironmentalInfoVo.setSecondPrice(Constants.MONEY_INIT.toString()); sysEnvironmentalInfoVo.setPutStoragePrice(Constants.MONEY_INIT); allList.add(sysEnvironmentalInfoVo); } } for (int i = 0; i < list.size(); i++) { SysEnvironmentalInfoVo sysEnvironmentalInfoVo = list.get(i); if(i==0) { sysEnvironmentalInfoVo.setList(allList); }else { sysEnvironmentalInfoVo.setList(CollUtil.newArrayList()); } } } /** * 获取二级分类 * @param list * @param cityId * @param hidePrice 是否隐藏价格 */ private void setSecondList( List list,String cityId,boolean hidePrice,String receiver){ for (SysEnvironmentalInfoVo sysEnvironmentalInfoVo : list) { Long id = sysEnvironmentalInfoVo.getId(); if(hidePrice){ sysEnvironmentalInfoVo.setPutStoragePrice(null); sysEnvironmentalInfoVo.setSecondPrice(null); sysEnvironmentalInfoVo.setPrice(null); } Dict dict = Dict.create(); dict.set("parentId",id); dict.set("type",2); dict.set("cityId",cityId); List priceList=null; if(StrUtil.isNotBlank(receiver)) { priceList=sysItemPriceService.findPriceByUserId(receiver); } List sysEnvironmentalInfoList = sysEnvironmentalInfoMapper.getSysEnvironmentalInfoListWithMap(dict); for (SysEnvironmentalInfoVo environmentalInfoVo : sysEnvironmentalInfoList) { if(hidePrice){ environmentalInfoVo.setPutStoragePrice(null); environmentalInfoVo.setSecondPrice(null); environmentalInfoVo.setPrice(null); } //根据每个分类查询出回收员设定的价格 if(CollUtil.isNotEmpty(priceList)){ List byItemAndList = sysItemPriceService.findByItemAndList(priceList, environmentalInfoVo.getItemType()); environmentalInfoVo.setPriceList(byItemAndList); } } //查询所有分类的售卖次数 按合伙人区分 // if(businessUtil.getVersion(request.getHeader("version")).compareTo(Convert.toDouble(CommonEnum.版本号1点6.getValue()))>=0) { // if(CollUtil.isNotEmpty(sysEnvironmentalInfoList)){ // //根据区域查找合伙人 // String partnerId=null; // PartnerGaode byCityId=null; // if(level==2){ // byCityId = partnerGaodeService.findByCityId(cityId); // }else if(level==3){ // byCityId = partnerGaodeService.findByTownId(cityId); // } // // if(byCityId!=null){ // partnerId = byCityId.getPartnerId(); // List orderItemInfos = orderItemService.sumGroupTypeByPatnerId(partnerId); // if(CollUtil.isNotEmpty(orderItemInfos)){ // for (SysEnvironmentalInfoVo environmentalInfoVo : sysEnvironmentalInfoList) { // String itemType = environmentalInfoVo.getItemType(); // List collect = orderItemInfos.stream().filter(x -> x.getItemType().equals(itemType)).collect(Collectors.toList()); // if(CollUtil.isNotEmpty(collect)){ // int saleNum = collect.get(0).getSaleNum(); // String s = StringUtils.intChange2Str(saleNum); // environmentalInfoVo.setSaleNum(s); // } // } // } // } // } // } /** * 根据分类查订单分类 */ sysEnvironmentalInfoVo.setList(sysEnvironmentalInfoList); } } /** * 批量修改分类价格 */ public void batchUpdateSysEnvironmentalInfo(SysEnvironmentalInfoListReq infoListReq){ String areaId = infoListReq.getAreaId(); String partnerId = infoListReq.getPartnerId(); List sysEnvironmentalInfoList= infoListReq.getSysEnvironmentalInfoList(); if (CollUtil.isNotEmpty(sysEnvironmentalInfoList)){ for (SysEnvironmentalInfoReq req : sysEnvironmentalInfoList) { int unionFlag = req.getUnionFlag(); SysEnvironmentalInfo sysEnvironmentalInfo=new SysEnvironmentalInfo(); sysEnvironmentalInfo.setPrice(req.getPrice()); sysEnvironmentalInfo.setSecondPrice(req.getSecondPrice()); sysEnvironmentalInfo.setPutStoragePrice(businessUtil.changeMul(Convert.toBigDecimal(req.getPutStoragePrice()))); if(unionFlag==0){ //根据区域和itemType修改 Example example=new Example(SysEnvironmentalInfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("delFlag",Constants.DEL_NOT_FLAG); criteria.andEqualTo("cityId",areaId); criteria.andEqualTo("itemType",req.getItemType()); sysEnvironmentalInfoMapper.updateByExampleSelective(sysEnvironmentalInfo,example); }else if(unionFlag==1){ //应用到所有 根据合伙人和itemType修改 Example example=new Example(SysEnvironmentalInfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("delFlag",Constants.DEL_NOT_FLAG); criteria.andEqualTo("partnerId",partnerId); criteria.andEqualTo("itemType",req.getItemType()); sysEnvironmentalInfoMapper.updateByExampleSelective(sysEnvironmentalInfo,example); } } } } /** * 后台分类列表查询 * @param item * @return */ public Map querOperaIteml(ItemModel item) { List partnerIds = new ArrayList<>(); if(null!=item.getPartnerId()&&!"".equals(item.getPartnerId())){ partnerIds.add(item.getPartnerId()); }else{ partnerIds = cityPartnerService.queryPartnerByCurrent(); } if (null != partnerIds && partnerIds.size() > 0) { List townIds = cityPartnerService.queryTownIdsByPartnerId(partnerIds.get(0)); item.setTownIdList(townIds); } Map map = new HashMap<>(); PageHelper.startPage(item.getPageNum(),item.getLimitNum()); List list = sysEnvironmentalInfoMapper.queryOperaIteml(item); PageInfo pageInfo=new PageInfo<>(list); for (ItemModel itemModel : list) { String townId = itemModel.getCityId(); if (null != townId && !"".equals(townId)) { Map objmap = addressLevelService.queryCityByTownId(townId); String cityId = objmap.get("cid").toString(); String pid = objmap.get("pid").toString(); List> resList = new ArrayList<>(); List detailList = new ArrayList<>(); detailList.add(pid); detailList.add(cityId); detailList.add(townId); resList.add(detailList); itemModel.setResultArea(resList); } } map.put("data", list); map.put("count", pageInfo.getTotal()); map.put("code", 0); return map; } /** * 后台类别查询 * @param item * @return */ public Map queryOperateItemList(ItemModel item) { Map map = new HashMap<>(); PageHelper.startPage(item.getPageNum(),item.getLimitNum()); List list = sysEnvironmentalInfoMapper.queryOperateItemList(item); PageInfo pageInfo=new PageInfo<>(list); for (ItemModel obj : list) { obj = queryChildItem(obj); } map.put("data", list); map.put("count", pageInfo.getTotal()); map.put("code", 0); return map; } /** * 无限子类算法(时间有限) * * @param item * @return */ private ItemModel queryChildItem(ItemModel item) { List child = sysEnvironmentalInfoMapper.queryOperateItemChildren(item); List childm = new ArrayList<>(); for (ItemModel obj : child) { childm.add(obj); } item.setChildren(childm); for (ItemModel cObj : childm) { if (null != cObj.getParentId()) { queryChildItem(cObj); } } return item; } public Map updateOperateItem(ItemModel item) { Map map = new HashMap<>(); String cityId = item.getCityId(); PartnerGaode byTownId = partnerGaodeService.findByTownId(cityId); //根据区域查询围栏 List townIds = cityPartnerService.queryFenceIdByPartnerId(byTownId.getPartnerId()); List orderList = orderService.queryOrderByCityId(cityId,townIds); if(CollUtil.isNotEmpty(orderList)) { throw new RestException("存在待入库和入库中的订单"); } String title=item.getTitle(); SysEnvironmentalInfo sysEnvironmentalInfo = sysEnvironmentalInfoMapper.selectByPrimaryKey(item.getId()); if(!sysEnvironmentalInfo.getTitle().equals(title)){ SysEnvironmentalInfo byCityAndTitle = findByCityAndTitle(title, cityId); if(byCityAndTitle!=null){ throw new RestException("当前分类已存在"); } } // 对排序字段进行处理 setSort(item); int i = updateItem(item); //父类隐藏则子类都隐藏 if(0==Convert.toInt(item.getShowFlag(),1)) { if (sysEnvironmentalInfo.getParentId() == null) { List children = item.getChildren(); for (ItemModel child : children) { SysEnvironmentalInfo obj = new SysEnvironmentalInfo(); obj.setId(child.getId()); obj.setShowFlag(Convert.toShort(0)); sysEnvironmentalInfoMapper.updateByPrimaryKeySelective(obj); } } } setSortAggin(item); map.put("code", 0); map.put("num", i); return map; } private int updateItem(ItemModel item){ return sysEnvironmentalInfoMapper.updateItem(item); } private void setSort(ItemModel item) { ItemModel im = new ItemModel(); im.setLimit(1000); im.setParentId(item.getParentId()); List list = sysEnvironmentalInfoMapper.querIteml(im); // 找到原始的sort数据 int originalSort = item.getSort(); for (ItemModel imx : list) { if (originalSort <= imx.getSort()) { imx.setSort(imx.getSort() + 1); } } for (ItemModel imx : list) { updateItem(imx); } } private void setSortAggin(ItemModel item) { ItemModel im = new ItemModel(); im.setLimit(1000); im.setParentId(item.getParentId()); List list = sysEnvironmentalInfoMapper.querIteml(im); list.sort((x, y) -> Integer.compare(x.getSort(), y.getSort())); int f = 1; for (ItemModel itemModel : list) { itemModel.setSort(f++); } for (ItemModel itemModel : list) { updateItem(itemModel); } } /** * 根据城市和标题查询 * @param title * @param cityId * @return */ public SysEnvironmentalInfo findByCityAndTitle(String title,String cityId){ SysEnvironmentalInfo sysEnvironmentalInfo=new SysEnvironmentalInfo(); sysEnvironmentalInfo.setCityId(Convert.toInt(cityId)); sysEnvironmentalInfo.setTitle(title); sysEnvironmentalInfo.setDelFlag(0); return sysEnvironmentalInfoMapper.selectOne(sysEnvironmentalInfo); } public SysEnvironmentalInfo findById(Long id){ return sysEnvironmentalInfoMapper.selectByPrimaryKey(id); } public SysEnvironmentalInfo findByItemTypeAndAreaNotDel(String itemType,Integer areaId) { Example example=new Example(SysEnvironmentalInfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("itemType",itemType); criteria.andEqualTo("cityId",areaId); criteria.andEqualTo("delFlag",Constants.DEL_NOT_FLAG); SysEnvironmentalInfo sysEnvironmentalInfo1 = sysEnvironmentalInfoMapper.selectOneByExample(example); return sysEnvironmentalInfo1; } public Map addOperateParent(ItemModel item) { List townIdList = item.getTownIdList(); String cityId = townIdList.get(0); PartnerGaode byTownId = partnerGaodeService.findByTownId(cityId); item.setPartnerId(byTownId.getPartnerId()); String title = item.getTitle(); Map map = new HashMap<>(); Long parentId = item.getParentId(); //验证 如果是天心区 大类和物品都不能出现重复标题 不是天心区,则要验证物品不能出现重复名称 if(Constants.TIANXIN_CODE.equals(cityId)){ SysEnvironmentalInfo byCityAndTitle = findByCityAndTitle(title, cityId); if(byCityAndTitle!=null){ throw new RestException("已经有相同的物品"); } }else{ if(parentId!=null) { SysEnvironmentalInfo byCityAndTitle = findByCityAndTitle(title, cityId); if(byCityAndTitle!=null){ throw new RestException("已经有相同的物品"); } } } String itemType=System.currentTimeMillis() + "" + (int) (Math.random() * (10000 - 10) + 10); //添加大类 必须和总部保持一致 if(!Constants.TIANXIN_CODE.equals(cityId)&&parentId==null) { SysEnvironmentalInfo byCityAndTitle = findByCityAndTitle(title, Constants.TIANXIN_CODE); itemType=byCityAndTitle.getItemType(); } item.setItemType(itemType); item.setCreateTime(DateUtil.now()); // 对排序字段进行处理 setSort(item); int i = 0; for (String townId : townIdList) { item.setCityId(townId); i = sysEnvironmentalInfoMapper.insertItemOperate(item); } setSortAggin(item); map.put("count", i); map.put("code", 0); return map; } /** * 删除后台分类 * @param item * @return */ public Map delOperateItem(ItemModel item) { Map map = new HashMap<>(); ItemModel im = new ItemModel(); im.setLimit(10); im.setParentId(item.getId()); List list = sysEnvironmentalInfoMapper.querIteml(im); if (list.size() > 0) { map.put("code", -1); map.put("num", 0); return map; } int i = sysEnvironmentalInfoMapper.delItem(item); map.put("code", 0); map.put("num", i); return map; } public Map queryTypeData(StorageModel storageModel){ List partnerIds = new ArrayList<>(); if(StrUtil.isNotBlank(storageModel.getPartnerId())){ partnerIds.add(storageModel.getPartnerId()); }else{ partnerIds = cityPartnerService.queryPartnerByCurrent(); } Map lastMap = new HashMap<>(); Map detailImage = new HashMap<>(); if(null!=storageModel.getImageType()&&!"".equals(storageModel.getImageType())) { if (storageModel.getImageType().equals("day")) { lastMap.put("startTime", cn.hutool.core.date.DateUtil.today() +" 00:00:00"); lastMap.put("endTime",cn.hutool.core.date.DateUtil.today()+" 23:59:59"); } else { List> weekOrMonthImgList = com.xzx.gc.util.DateUtil.query12MonthStartTimeAndEndTime(); lastMap = weekOrMonthImgList.get(0); } } detailImage = queryPageSysStorageTypeName(lastMap.get("startTime"),lastMap.get("endTime"),storageModel.getTypeName(),storageModel.getPage(),storageModel.getLimit(),partnerIds,storageModel.getParentId(),storageModel.getDelFlag()); return detailImage; } private Map queryPageSysStorageTypeName(String startTime,String endTime,String typeName,int page,int limit,List partnerIds,String parentId,String delFlag){ String partnerId=""; if(null!=partnerIds&&partnerIds.size()>0){ partnerId = partnerIds.get(0); } PageHelper.startPage(page,limit); List list = sysEnvironmentalInfoMapper.findPage(partnerId,typeName,parentId,delFlag); for (SysEnvironmentalInfo sysEnvironmentalInfo : list) { ItemDto orderItem = orderItemInfoMapper.findByTypeAndPartnerAndTime(sysEnvironmentalInfo.getPartnerId(), sysEnvironmentalInfo.getItemType(), startTime, endTime); orderItem=orderItem==null?new ItemDto():orderItem; sysEnvironmentalInfo.setOldMoney(orderItem.getMoney()); ItemDto storageItem = orderStorageDetailMapper.findByTypeAndPartnerAndTime(sysEnvironmentalInfo.getPartnerId(), sysEnvironmentalInfo.getItemType(), startTime, endTime); storageItem=storageItem==null?new ItemDto():storageItem; BigDecimal moneyError = NumberUtil.sub(Convert.toBigDecimal(storageItem.getMoney()), Convert.toBigDecimal(orderItem.getMoney())); BigDecimal weightError = NumberUtil.sub(Convert.toBigDecimal(storageItem.getWeight()), Convert.toBigDecimal(orderItem.getWeight())); BigDecimal money = Convert.toBigDecimal(orderItem.getMoney()).divide(new BigDecimal("10000"),2); BigDecimal moneyErrorBig = new BigDecimal(moneyError.toString()).divide(new BigDecimal("10000"),2); BigDecimal weight = Convert.toBigDecimal(orderItem.getWeight()).divide(new BigDecimal("1000"),3); BigDecimal weightErrorBig = new BigDecimal(weightError.toString()).divide(new BigDecimal("1000"),3); sysEnvironmentalInfo.setMoney(DoubleUtil.roundTwo(money+"")); sysEnvironmentalInfo.setMoneyError(DoubleUtil.roundTwo(moneyErrorBig+"")); sysEnvironmentalInfo.setWeight(DoubleUtil.roundThree(weight+"")); sysEnvironmentalInfo.setWeightError(DoubleUtil.roundThree(weightErrorBig+"")); } PageInfo pageInfo = new PageInfo<>(list); int count = Convert.toInt(pageInfo.getTotal()); //总金额 BigDecimal totalMoney = new BigDecimal("0"); for (SysEnvironmentalInfo sysEnvironmentalInfo:list) { totalMoney = totalMoney.add(Convert.toBigDecimal(sysEnvironmentalInfo.getOldMoney())); } for (SysEnvironmentalInfo sysEnvironmentalInfo:list) { BigDecimal rate; if(totalMoney.compareTo(BigDecimal.ZERO)==0){ rate=BigDecimal.ZERO; }else { rate = Convert.toBigDecimal(sysEnvironmentalInfo.getOldMoney(), Constants.MONEY_INIT).divide(totalMoney, 2, RoundingMode.HALF_UP); } sysEnvironmentalInfo.setRate(rate.multiply(new BigDecimal("100")).toString()+"%"); } Map imageData = new HashMap<>(); imageData.put("totalMoney",DoubleUtil.roundTwo(totalMoney.toString())); imageData.put("data",list); imageData.put("count",count); return imageData; } public List queryParent(QueryParentDTO queryParentDTO) { Example example=new Example(SysEnvironmentalInfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("cityId",queryParentDTO.getCityId()); criteria.andIsNull("parentId"); return sysEnvironmentalInfoMapper.selectByExample(example); } }