diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighTyAgentPriceController.java b/hai-bweb/src/main/java/com/bweb/controller/HighTyAgentPriceController.java new file mode 100644 index 00000000..c2a3dc5b --- /dev/null +++ b/hai-bweb/src/main/java/com/bweb/controller/HighTyAgentPriceController.java @@ -0,0 +1,113 @@ +package com.bweb.controller; + +import com.alibaba.fastjson.JSONObject; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.security.UserCenter; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.HighGasOilPrice; +import com.hai.entity.HighMerchantStore; +import com.hai.entity.HighTyAgentPrice; +import com.hai.model.ResponseData; +import com.hai.service.HighGasOilPriceService; +import com.hai.service.HighMerchantStoreService; +import com.hai.service.HighTyAgentPriceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Controller +@RequestMapping(value = "/tyAgentPrice") +@Api(value = "订单接口") +public class HighTyAgentPriceController { + + private static Logger log = LoggerFactory.getLogger(HighTyAgentPriceController.class); + + @Resource + private HighTyAgentPriceService tyAgentPriceService; + + @Resource + private HighMerchantStoreService merchantStoreService; + + @Resource + private HighGasOilPriceService gasOilPriceService; + + @Resource + private UserCenter userCenter; + + @RequestMapping(value = "/editPrice", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "编辑价格") + public ResponseData editPrice(@RequestBody JSONObject body) { + try { + + if (body.getLong("tyAgentOilStationId") == null + || StringUtils.isBlank(body.getString("oilNoName")) + || StringUtils.isBlank(body.getString("oilNo")) + || body.getBigDecimal("priceRate") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); + } + + // 查询油站 + HighTyAgentPrice agentOilStation = tyAgentPriceService.getDetail(body.getLong("tyAgentOilStationId"), body.getString("oilNo")); + if (agentOilStation == null) { + agentOilStation = new HighTyAgentPrice(); + agentOilStation.setTyAgentOilStationId(body.getLong("tyAgentOilStationId")); + agentOilStation.setOilNoName(body.getString("oilNoName")); + agentOilStation.setOilNo(body.getString("oilNo")); + agentOilStation.setPriceRate(body.getBigDecimal("priceRate")); + } else { + agentOilStation.setPriceRate(body.getBigDecimal("priceRate")); + } + + tyAgentPriceService.editTyAgentPrice(agentOilStation); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("HighTyAgentPriceController --> editPrice() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getOilStationPrice", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "油站价格") + public ResponseData getOilStationPrice(@RequestParam(name = "oilStationId", required = true) Long oilStationId) { + try { + + List oilPriceList = gasOilPriceService.getGasOilPriceByStore(oilStationId); + + List> oilPriceMapList = new ArrayList<>(); + Map oilPriceMap; + + for (HighGasOilPrice price : oilPriceList) { + oilPriceMap = new HashMap<>(); + oilPriceMap.put("oilStationId", oilStationId); + oilPriceMap.put("oilNo", price.getOilNo()); + oilPriceMap.put("oilNoName", price.getOilNoName()); + + oilPriceMapList.add(oilPriceMap); + HighTyAgentPrice tyAgentPrice = tyAgentPriceService.getDetail(oilStationId, price.getOilNo().toString()); + } + + return ResponseMsgUtil.success(oilPriceList); + + } catch (Exception e) { + log.error("HighTyAgentPriceController --> getOilStationPrice() error!", e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/hai-service/src/main/java/com/hai/entity/HighTyAgentPrice.java b/hai-service/src/main/java/com/hai/entity/HighTyAgentPrice.java index 37b63ca6..e173b643 100644 --- a/hai-service/src/main/java/com/hai/entity/HighTyAgentPrice.java +++ b/hai-service/src/main/java/com/hai/entity/HighTyAgentPrice.java @@ -17,7 +17,7 @@ public class HighTyAgentPrice implements Serializable { private Long id; /** - * 代理商公司id + * 代理油站id */ private Long tyAgentOilStationId; diff --git a/hai-service/src/main/java/com/hai/service/HighGasOilPriceService.java b/hai-service/src/main/java/com/hai/service/HighGasOilPriceService.java index f31f0c72..10749587 100644 --- a/hai-service/src/main/java/com/hai/service/HighGasOilPriceService.java +++ b/hai-service/src/main/java/com/hai/service/HighGasOilPriceService.java @@ -26,7 +26,7 @@ public interface HighGasOilPriceService { * @param storeId * @return */ - HighGasOilPrice getGasOilPriceByStore(Long storeId); + List getGasOilPriceByStore(Long storeId); /** * 根据区域和油号查询门店 diff --git a/hai-service/src/main/java/com/hai/service/HighTyAgentPriceService.java b/hai-service/src/main/java/com/hai/service/HighTyAgentPriceService.java new file mode 100644 index 00000000..9b3d2c2e --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighTyAgentPriceService.java @@ -0,0 +1,24 @@ +package com.hai.service; + +import com.hai.entity.HighTyAgentPrice; + +/** + * 加油价格 + * @author hurui + */ +public interface HighTyAgentPriceService { + + /** + * 编辑价格 + * @param tyAgentPrice + */ + void editTyAgentPrice(HighTyAgentPrice tyAgentPrice); + + /** + * 根据代理油站id 查询详情 + * @param tyAgentOilStationId + * @return + */ + HighTyAgentPrice getDetail(Long tyAgentOilStationId, String oilNo); + +} diff --git a/hai-service/src/main/java/com/hai/service/impl/HighGasOilPriceServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighGasOilPriceServiceImpl.java index 0dcb3775..0716e5df 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighGasOilPriceServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighGasOilPriceServiceImpl.java @@ -40,14 +40,10 @@ public class HighGasOilPriceServiceImpl implements HighGasOilPriceService { } @Override - public HighGasOilPrice getGasOilPriceByStore(Long storeId) { + public List getGasOilPriceByStore(Long storeId) { HighGasOilPriceExample example = new HighGasOilPriceExample(); example.createCriteria().andMerchantStoreIdEqualTo(storeId); - List list = highGasOilPriceMapper.selectByExample(example); - if (list.size() > 0) { - return list.get(0); - } - return null; + return highGasOilPriceMapper.selectByExample(example); } @Override diff --git a/hai-service/src/main/java/com/hai/service/impl/HighTyAgentPriceServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighTyAgentPriceServiceImpl.java new file mode 100644 index 00000000..85e5bb32 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/HighTyAgentPriceServiceImpl.java @@ -0,0 +1,45 @@ +package com.hai.service.impl; + +import com.hai.dao.HighTyAgentPriceMapper; +import com.hai.entity.HighTyAgentPrice; +import com.hai.entity.HighTyAgentPriceExample; +import com.hai.service.HighTyAgentPriceService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +@Service("highTyAgentPriceService") +public class HighTyAgentPriceServiceImpl implements HighTyAgentPriceService { + + @Resource + private HighTyAgentPriceMapper tyAgentPriceMapper; + + @Override + public void editTyAgentPrice(HighTyAgentPrice tyAgentPrice) { + if (tyAgentPrice.getId() == null) { + tyAgentPrice.setCreateTime(new Date()); + tyAgentPrice.setUpdateTime(new Date()); + tyAgentPrice.setStatus(1); + tyAgentPriceMapper.insert(tyAgentPrice); + } else { + tyAgentPrice.setUpdateTime(new Date()); + tyAgentPriceMapper.updateByPrimaryKey(tyAgentPrice); + } + } + + @Override + public HighTyAgentPrice getDetail(Long tyAgentOilStationId, String oilNo) { + HighTyAgentPriceExample example = new HighTyAgentPriceExample(); + example.createCriteria() + .andStatusEqualTo(1) + .andTyAgentOilStationIdEqualTo(tyAgentOilStationId) + .andOilNoEqualTo(oilNo); + List list = tyAgentPriceMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } +}