Commit 59174d28 authored by 王夏晖's avatar 王夏晖

项目能耗价格后台维护

parent a5caa609
package org.rcisoft.business.manage.controller;
/*固定导入*/
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.manage.service.EnergyPriceService;
import org.rcisoft.business.manage.vo.EnergyPriceList;
import org.rcisoft.business.overview.entity.EnergyPrice;
import org.rcisoft.core.controller.PaginationController;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* Created by on 2018-5-16 14:34:55.
*/
@RestController
@RequestMapping("energyprice")
public class EnergyPriceController extends PaginationController<EnergyPrice> {
@Autowired
private EnergyPriceService energyPriceServiceImpl;
@ApiOperation(value="修改", notes="修改")
@PutMapping("/update")
public Result update(@RequestBody EnergyPriceList energyPriceList) {
PersistModel data = energyPriceServiceImpl.merge(energyPriceList);
return Result.builder(data);
}
@ApiOperation(value="查看", notes="查看")
@GetMapping(value = "/queryEnergyPrice")
public Map<String,Object> queryEnergyPrice(@RequestParam String proId) {
return energyPriceServiceImpl.queryEnergyPrice(proId);
}
}
package org.rcisoft.business.manage.service;
import org.rcisoft.business.manage.vo.EnergyPriceList;
import org.rcisoft.core.model.PersistModel;
import java.util.Map;
/**
* Created by on 2018-5-16 14:34:55.
*/
public interface EnergyPriceService {
/**
* 保存
* @return
*/
PersistModel save(EnergyPriceList energyPriceList);
/**
* 删除
* @return
*/
PersistModel delete(String proId);
/**
* 修改
* @return
*/
PersistModel merge(EnergyPriceList energyPriceList);
/**
* @return
*/
Map<String, Object> queryEnergyPrice(String proId);
}
...@@ -4,9 +4,13 @@ import lombok.extern.slf4j.Slf4j; ...@@ -4,9 +4,13 @@ import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.manage.entity.BusProject; import org.rcisoft.business.manage.entity.BusProject;
import org.rcisoft.business.manage.service.BusProjectAreaService; import org.rcisoft.business.manage.service.BusProjectAreaService;
import org.rcisoft.business.manage.service.BusProjectService; import org.rcisoft.business.manage.service.BusProjectService;
import org.rcisoft.business.manage.service.EnergyPriceService;
import org.rcisoft.business.manage.vo.BusProjectAreaList; import org.rcisoft.business.manage.vo.BusProjectAreaList;
import org.rcisoft.business.manage.vo.EnergyPriceList;
import org.rcisoft.business.manage.vo.EnergyPriceVo;
import org.rcisoft.business.overview.dao.BusProjectRepository; import org.rcisoft.business.overview.dao.BusProjectRepository;
import org.rcisoft.business.overview.entity.BusProjectArea; import org.rcisoft.business.overview.entity.BusProjectArea;
import org.rcisoft.business.overview.entity.EnergyPrice;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.business.manage.dao.ProjectRepository; import org.rcisoft.business.manage.dao.ProjectRepository;
...@@ -33,6 +37,8 @@ public class BusProjectServiceImpl implements BusProjectService { ...@@ -33,6 +37,8 @@ public class BusProjectServiceImpl implements BusProjectService {
private BusProjectRepository busProjectRepository; private BusProjectRepository busProjectRepository;
@Autowired @Autowired
private BusProjectAreaService busProjectAreaService; private BusProjectAreaService busProjectAreaService;
@Autowired
private EnergyPriceService energyPriceService;
/** /**
...@@ -75,7 +81,38 @@ public class BusProjectServiceImpl implements BusProjectService { ...@@ -75,7 +81,38 @@ public class BusProjectServiceImpl implements BusProjectService {
a3.setType("3"); a3.setType("3");
list.add(a3); list.add(a3);
busProjectAreaList.setBusProjectAreaList(list); busProjectAreaList.setBusProjectAreaList(list);
return busProjectAreaService.save(busProjectAreaList); PersistModel areaP = busProjectAreaService.save(busProjectAreaList);
//能耗价格
EnergyPriceList energyPriceList = new EnergyPriceList();
List<EnergyPriceVo> plist = new ArrayList<>();
for(int i=0;i<24;i++){
EnergyPriceVo ep_water = new EnergyPriceVo();
ep_water.setId(UUID.randomUUID().toString().replace("-",""));
ep_water.setProId(busProject.getJwnum());
ep_water.setPriceHour(String.valueOf(i));
ep_water.setPriceTp("1");
EnergyPriceVo ep_power = new EnergyPriceVo();
ep_power.setId(UUID.randomUUID().toString().replace("-",""));
ep_power.setProId(busProject.getJwnum());
ep_power.setPriceHour(String.valueOf(i));
ep_power.setPriceTp("2");
EnergyPriceVo ep_gas = new EnergyPriceVo();
ep_gas.setId(UUID.randomUUID().toString().replace("-",""));
ep_gas.setProId(busProject.getJwnum());
ep_gas.setPriceHour(String.valueOf(i));
ep_gas.setPriceTp("3");
plist.add(ep_water);
plist.add(ep_power);
plist.add(ep_gas);
}
energyPriceList.setEnergyPriceList(plist);
PersistModel priceP = energyPriceService.save(energyPriceList);
if(!areaP.isSuccessBySinglePersist()){
return areaP;
}
if(!priceP.isSuccessBySinglePersist()){
return priceP;
}
} }
return new PersistModel(line); return new PersistModel(line);
} }
...@@ -103,6 +140,7 @@ public class BusProjectServiceImpl implements BusProjectService { ...@@ -103,6 +140,7 @@ public class BusProjectServiceImpl implements BusProjectService {
return new PersistModel(line,message); return new PersistModel(line,message);
} }
@Transactional
@Override @Override
public PersistModel delete(BusProject busProject) { public PersistModel delete(BusProject busProject) {
int line = 0; int line = 0;
...@@ -123,7 +161,14 @@ public class BusProjectServiceImpl implements BusProjectService { ...@@ -123,7 +161,14 @@ public class BusProjectServiceImpl implements BusProjectService {
message = "ID为空,删除失败"; message = "ID为空,删除失败";
} }
if(line>0){ if(line>0){
return busProjectAreaService.delete(busProject.getProId()); PersistModel areaP = busProjectAreaService.delete(busProject.getProId());
PersistModel priceP = energyPriceService.delete(busProject.getProId());
if(!areaP.isSuccessBySinglePersist()){
return areaP;
}
if(!priceP.isSuccessBySinglePersist()){
return priceP;
}
} }
return new PersistModel(line,message); return new PersistModel(line,message);
} }
......
package org.rcisoft.business.manage.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.manage.service.EnergyPriceService;
import org.rcisoft.business.manage.vo.EnergyPriceList;
import org.rcisoft.business.manage.vo.EnergyPriceVo;
import org.rcisoft.business.overview.dao.EnergyPriceRepository;
import org.rcisoft.business.overview.entity.EnergyPrice;
import org.rcisoft.core.model.PersistModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by on 2018-5-16 14:34:55.
*/
@Service
@Transactional(readOnly = true,propagation = Propagation.NOT_SUPPORTED)
@Slf4j
public class EnergyPriceServiceImpl implements EnergyPriceService {
@Autowired
private EnergyPriceRepository energyPriceRepository;
/**
* 批量新增,新建项目时执行
* @param energyPriceList
* @return
*/
@Transactional
@Override
public PersistModel save(EnergyPriceList energyPriceList) {
int line = 0;
List<EnergyPriceVo> list = energyPriceList.getEnergyPriceList();
for(EnergyPriceVo energyPriceVo : list){
line = energyPriceRepository.insertSelective(energyPriceVo);
}
return new PersistModel(line);
}
@Override
public PersistModel delete(String proId) {
int line = 0;
String message = "";
Example example = new Example(EnergyPriceVo.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("proId",proId);
if(proId!=null && !proId.equals("")){
line = energyPriceRepository.deleteByExample(example);
}else{
line = 0;
message = "项目ID为空,删除失败";
}
return new PersistModel(line,message);
}
@Transactional
@Override
public PersistModel merge(EnergyPriceList energyPriceList) {
int line = 1;
String message = "";
List<EnergyPriceVo> list = energyPriceList.getEnergyPriceList();
for(EnergyPriceVo energyPriceVo : list){
Example example = new Example(EnergyPriceVo.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("id",energyPriceVo.getId());
if(energyPriceVo.getId()!=null && !energyPriceVo.getId().equals("")){
line = energyPriceRepository.updateByExampleSelective(energyPriceVo,example);
}else{
message = "ID为空,更新失败";
line = 0;
return new PersistModel(line,message);
}
}
return new PersistModel(line,message);
}
@Override
public Map<String, Object> queryEnergyPrice(String proId) {
Map<String, Object> result = new HashMap<>();
List<Map<String, Object>> list = energyPriceRepository.queryEnergyPrice(proId);
Map<String, Object> water_map = new HashMap<>();
Map<String, Object> power_map = new HashMap<>();
Map<String, Object> gas_map = new HashMap<>();
for(Map<String, Object> mp : list){
if(mp.get("P_TP")!=null && mp.get("P_TP").toString().equals("1")){
water_map.put(mp.get("P_HOUR").toString(),mp.get("P_PRICE"));
}else if(mp.get("P_TP")!=null && mp.get("P_TP").toString().equals("2")){
power_map.put(mp.get("P_HOUR").toString(),mp.get("P_PRICE"));
}else if(mp.get("P_TP")!=null && mp.get("P_TP").toString().equals("3")){
gas_map.put(mp.get("P_HOUR").toString(),mp.get("P_PRICE"));
}
}
result.put("water",water_map);
result.put("power",power_map);
result.put("gas",gas_map);
return result;
}
}
package org.rcisoft.business.manage.vo;
import java.util.List;
public class EnergyPriceList {
private List<EnergyPriceVo> energyPriceList;
public List<EnergyPriceVo> getEnergyPriceList() {
return energyPriceList;
}
public void setEnergyPriceList(List<EnergyPriceVo> energyPriceList) {
this.energyPriceList = energyPriceList;
}
}
package org.rcisoft.business.manage.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "energy_price")
public class EnergyPriceVo {
@Id
private String id;
@Column(name = "pro_id")
private String proId;
@Column(name = "p_hour")
private String priceHour;
@Column(name = "p_price")
private BigDecimal pricePrice;
@Column(name = "p_tp")
private String priceTp;
}
package org.rcisoft.business.overview.dao; package org.rcisoft.business.overview.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap; import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.overview.entity.EnergyPrice; import org.rcisoft.business.manage.vo.EnergyPriceVo;
import org.rcisoft.business.overview.vo.EnergyPriceVo;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Created by JiChao on 2018/4/11. * Created by JiChao on 2018/4/11.
* 概览 * 概览
*/ */
@Repository @Repository
public interface EnergyPriceRepository extends BaseMapper<EnergyPrice> { public interface EnergyPriceRepository extends BaseMapper<EnergyPriceVo> {
/** /**
* 根据项目id搜索水电气价格列表 * 根据项目id搜索水电气价格列表
* @param energyPrice proId:项目id,pHour:小时 * @param proId:项目id,pHour:小时
* @return * @return
*/ */
@Select("<script>select e.P_HOUR,SUM(IF(e.P_TP=1, e.P_PRICE, 0)) as WATER,SUM(IF(e.P_TP=2, e.P_PRICE, 0)) as ELEC,SUM(IF(e.P_TP=3, e.P_PRICE, 0)) as GAS from energy_price e where e.PRO_ID=#{proId} and e.P_HOUR=#{pHour}</script>") @Select("<script>select e.P_HOUR,SUM(IF(e.P_TP=1, e.P_PRICE, 0)) as WATER,SUM(IF(e.P_TP=2, e.P_PRICE, 0)) as ELEC,SUM(IF(e.P_TP=3, e.P_PRICE, 0)) as GAS from energy_price e where e.PRO_ID=#{proId} and e.P_HOUR=#{pHour}</script>")
@ResultMap("vo") @ResultMap("vo")
EnergyPriceVo getPrice(EnergyPrice energyPrice); EnergyPriceVo getPrice(@Param("proId") String proId,@Param("pHour") String pHour);
/**
* 查询项目能耗价格
* @param proId
* @return
*/
@Select("<script>select * from energy_price where pro_id = #{proId}</script>")
List<Map<String,Object>> queryEnergyPrice(@Param("proId") String proId);
} }
package org.rcisoft.business.overview.service; package org.rcisoft.business.overview.service;
import org.rcisoft.business.manage.vo.EnergyPriceVo;
import org.rcisoft.business.overview.entity.EnergyEmissionTotal; import org.rcisoft.business.overview.entity.EnergyEmissionTotal;
import org.rcisoft.business.overview.vo.EnergyCountMVo; import org.rcisoft.business.overview.vo.EnergyCountMVo;
import org.rcisoft.business.overview.vo.EnergyPriceVo;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import java.math.BigDecimal; import java.math.BigDecimal;
......
...@@ -2,12 +2,12 @@ package org.rcisoft.business.overview.service.impl; ...@@ -2,12 +2,12 @@ package org.rcisoft.business.overview.service.impl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.manage.vo.EnergyPriceVo;
import org.rcisoft.business.overview.dao.*; import org.rcisoft.business.overview.dao.*;
import org.rcisoft.business.overview.entity.*; import org.rcisoft.business.overview.entity.*;
import org.rcisoft.business.overview.service.OverViewService; import org.rcisoft.business.overview.service.OverViewService;
import org.rcisoft.business.overview.vo.BusEnergyPlanVo; import org.rcisoft.business.overview.vo.BusEnergyPlanVo;
import org.rcisoft.business.overview.vo.EnergyCountMVo; import org.rcisoft.business.overview.vo.EnergyCountMVo;
import org.rcisoft.business.overview.vo.EnergyPriceVo;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -294,10 +294,7 @@ public class OverViewServiceImpl implements OverViewService { ...@@ -294,10 +294,7 @@ public class OverViewServiceImpl implements OverViewService {
@Override @Override
public EnergyPriceVo getPrice(String proId) { public EnergyPriceVo getPrice(String proId) {
int i = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int i = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
EnergyPrice e = new EnergyPrice(); return overViewRepository.getPrice(proId,String.valueOf(i));
e.setProId(proId);
e.setPHour(String.valueOf(i));
return overViewRepository.getPrice(e);
} }
@Override @Override
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.rcisoft.business.overview.dao.EnergyPriceRepository"> <mapper namespace="org.rcisoft.business.overview.dao.EnergyPriceRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.overview.entity.EnergyPrice"> <resultMap id="BaseResultMap" type="org.rcisoft.business.manage.vo.EnergyPriceVo">
<id column="ID" jdbcType="VARCHAR" property="id"/> <id column="ID" jdbcType="VARCHAR" property="id"/>
<result column="PRO_ID" jdbcType="VARCHAR" property="proId"/> <result column="PRO_ID" jdbcType="VARCHAR" property="proId"/>
<result column="P_HOUR" jdbcType="VARCHAR" property="pHour"/> <result column="P_HOUR" jdbcType="VARCHAR" property="priceHour"/>
<result column="P_PRICE" jdbcType="DECIMAL" property="pPrice"/> <result column="P_PRICE" jdbcType="DECIMAL" property="pricePrice"/>
<result column="P_TP" jdbcType="CHAR" property="pTp"/> <result column="P_TP" jdbcType="CHAR" property="priceTp"/>
</resultMap> </resultMap>
<resultMap id="vo" type="org.rcisoft.business.overview.vo.EnergyPriceVo"> <resultMap id="vo" type="org.rcisoft.business.overview.vo.EnergyPriceVo">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment