| @@ -2,18 +2,25 @@ package com.iformall.controller.market; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.annotation.TenantIgnore; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.dto.WxBillPayDTO; | |||
| import com.iformall.domain.po.AliBusinessCircleOrder; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxEnergyFees; | |||
| import com.iformall.domain.po.WxEnergyFeesTime; | |||
| import com.iformall.domain.po.WxEnergyMeterReading; | |||
| import com.iformall.domain.po.WxEnergyReadingCalcute; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.AlipayOrWxStatistics; | |||
| import com.iformall.enums.EnumBillAllType; | |||
| import com.iformall.enums.EnumEnergyMeterType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.AliBusinessCircleOrderService; | |||
| import com.iformall.service.WxEnergyService; | |||
| import com.iformall.utils.Constant; | |||
| @@ -30,15 +37,22 @@ import org.springframework.web.bind.annotation.ModelAttribute; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RequestParam; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.BufferedInputStream; | |||
| import java.io.File; | |||
| import java.io.FileOutputStream; | |||
| import java.io.IOException; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.concurrent.TimeUnit; | |||
| @RestController | |||
| @RequestMapping("energy") | |||
| @@ -49,7 +63,6 @@ public class WxEnergyController extends BaseController { | |||
| @Autowired | |||
| private WxEnergyService wxEnergyService; | |||
| @ApiOperation("表类型") | |||
| @GetMapping("meterTypeList") | |||
| public ResultData meterTypeList() { | |||
| @@ -148,4 +161,51 @@ public class WxEnergyController extends BaseController { | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("生成科目抄表计算数据") | |||
| @PostMapping("createReadingCalcute") | |||
| public ResultData createReadingCalcute(@RequestBody WxEnergyReadingCalcute record) { | |||
| record.updateTenantInfo(getTenantInfo()); | |||
| wxEnergyService.saveOrUpdateReadingCalcute(record,this.getUser()); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("科目抄表计算数据分页列表接口") | |||
| @GetMapping("readingCalcuteList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData readingCalcuteList(@ModelAttribute WxEnergyReadingCalcute record, Integer pageNum, Integer pageSize) { | |||
| record.updateTenantInfo(getTenantInfo()); | |||
| record.setSortColumns(BaseEntity.SortField.CreateTime_DESC); | |||
| PageInfo<WxEnergyReadingCalcute> page = wxEnergyService.readingCalcuteListAsPage(record, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("科目抄表计算记录导出") | |||
| @GetMapping("readingCalcuteExport") | |||
| public void readingCalcuteExport(@ModelAttribute WxEnergyReadingCalcute record, HttpServletRequest request, HttpServletResponse response) { | |||
| record.updateTenantInfo(getTenantInfo()); | |||
| WxEnergyReadingCalcute wrc = wxEnergyService.getReadingCalcuteById(record); | |||
| if (null == wrc) { | |||
| return; | |||
| } | |||
| wxEnergyService.exportReadingCalcute(wrc, request, response); | |||
| } | |||
| @ApiOperation("科目抄表计算记录导入-修改单价") | |||
| @PostMapping(value = "/importReading", consumes = "multipart/*") | |||
| public void importReading(@RequestParam("file") MultipartFile mFile,HttpServletRequest request, HttpServletResponse response) { | |||
| try { | |||
| //得到当前用户ID | |||
| MallUserInfo user = getUser(); | |||
| wxEnergyService.importReadingCalcute(mFile, user, request, response); | |||
| } catch (Exception e) { | |||
| logger.error("importReading error.",e); | |||
| throw new MallinkException(Result.ERROR,e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @@ -52,7 +52,8 @@ CREATE TABLE `wx_energy_meter_reading` ( | |||
| `floor_id` bigint(20) DEFAULT NULL COMMENT '楼层ID', | |||
| `price` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '单价', | |||
| PRIMARY KEY (`id`), | |||
| UNIQUE KEY `id_UNIQUE` (`id`) | |||
| UNIQUE KEY `id_UNIQUE` (`id`), | |||
| KEY `T_T_F` (`tenant_id`,`time_id`,`meter_id`) | |||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='能耗表抄表'; | |||
| @@ -86,6 +87,25 @@ CREATE TABLE `wx_energy_fees` ( | |||
| UNIQUE KEY `id_UNIQUE` (`id`) | |||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='能耗表'; | |||
| CREATE TABLE `wx_energy_reading_calcute` ( | |||
| `id` bigint(20) NOT NULL COMMENT '主键ID', | |||
| `tenant_id` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '租户ID', | |||
| `parent_tenant_id` varchar(5) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '父租户ID', | |||
| `create_time` timestamp NULL DEFAULT NULL, | |||
| `update_time` timestamp NULL DEFAULT NULL, | |||
| `create_by` bigint(20) DEFAULT NULL, | |||
| `create_by_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, | |||
| `update_by` bigint(20) DEFAULT NULL, | |||
| `update_by_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, | |||
| `remark` varchar(300) COLLATE utf8mb4_unicode_ci DEFAULT NULL, | |||
| `time_id` bigint(20) NOT NULL COMMENT '区间ID', | |||
| `fees_id` bigint(20) NOT NULL COMMENT '科目ID', | |||
| `is_calcuted` int(1) NOT NULL DEFAULT '0' COMMENT '是否已计算过', | |||
| `is_imported` int(1) NOT NULL DEFAULT '0' COMMENT '是否导入过', | |||
| PRIMARY KEY (`id`), | |||
| UNIQUE KEY `id_UNIQUE` (`id`), | |||
| UNIQUE KEY `T_T_F` (`tenant_id`,`time_id`,`fees_id`) | |||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='能耗表抄表'; | |||
| @@ -3,11 +3,18 @@ package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumYesOrNo; | |||
| import com.iformall.utils.DateUtils; | |||
| import cn.afterturn.easypoi.excel.annotation.Excel; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.LinkedHashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| */ | |||
| @@ -58,6 +65,7 @@ public class WxEnergyMeterReading extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="备注",name="remark") | |||
| private String remark; | |||
| @io.swagger.annotations.ApiModelProperty(value="区间ID",name="timeId") | |||
| private Long timeId; | |||
| @@ -82,7 +90,7 @@ public class WxEnergyMeterReading extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="楼层ID",name="floorId") | |||
| private Long floorId; | |||
| @io.swagger.annotations.ApiModelProperty(value="楼层ID",name="floorId") | |||
| @io.swagger.annotations.ApiModelProperty(value="单价",name="price") | |||
| private String price; | |||
| @TableField(exist = false) | |||
| @@ -93,4 +101,48 @@ public class WxEnergyMeterReading extends TenantEntity { | |||
| @TableField(exist = false) | |||
| private String shopIdsStr; | |||
| public static Map<String,String> generateExcelTitle() { | |||
| Map<String,String> excelTitle = new LinkedHashMap<String,String>(); | |||
| excelTitle.put("calcuteId", "批次编码"); | |||
| excelTitle.put("id", "编码"); | |||
| excelTitle.put("timeId", "时间区间"); | |||
| excelTitle.put("startTime", "开始日期"); | |||
| excelTitle.put("endTime", "截止日期"); | |||
| excelTitle.put("feesId", "科目"); | |||
| excelTitle.put("buildingId", "楼座"); | |||
| excelTitle.put("floorId", "楼层"); | |||
| excelTitle.put("shopId", "店铺号"); | |||
| excelTitle.put("meterId", "表号"); | |||
| excelTitle.put("preNumber", "上次抄表数"); | |||
| excelTitle.put("preTime", "上次抄表时间"); | |||
| excelTitle.put("curNumber", "本次抄表数"); | |||
| excelTitle.put("price", "单价(*)"); | |||
| return excelTitle; | |||
| } | |||
| public Map<String,Object> generateExcelData(Map<Long, String> buildingMap,Map<Long, String> floorMap,WxEnergyFeesTime time,WxEnergyFees fees,WxEnergyReadingCalcute calcute) { | |||
| Map<String,Object> excelObject = new HashMap<String,Object>(); | |||
| excelObject.put("calcuteId", calcute.getId()); | |||
| excelObject.put("id", this.getId()); | |||
| excelObject.put("timeId", time.getName()); | |||
| excelObject.put("startTime", DateUtils.formatDateTime(this.getStartTime())); | |||
| excelObject.put("endTime", DateUtils.formatDateTime(this.getEndTime())); | |||
| excelObject.put("feesId", fees.getName()); | |||
| String buildingName = buildingMap.get(this.getBuildingId()); | |||
| excelObject.put("buildingId", buildingName); | |||
| String floorName = floorMap.get(this.getFloorId()); | |||
| excelObject.put("floorId", floorName); | |||
| excelObject.put("shopId", this.getShopNumber()); | |||
| excelObject.put("meterId", this.getMeterName()); | |||
| excelObject.put("preNumber", this.getPreNumber()); | |||
| excelObject.put("preTime", DateUtils.formatDateTime(this.getPreTime())); | |||
| excelObject.put("curNumber", this.getCurNumber()); | |||
| if (calcute.getIsImported().intValue() == EnumYesOrNo.YES.getCode().intValue()) { | |||
| excelObject.put("price", this.getPrice()); | |||
| }else { | |||
| excelObject.put("price", fees.getPrice()); | |||
| } | |||
| return excelObject; | |||
| } | |||
| } | |||
| @@ -0,0 +1,62 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumYesOrNo; | |||
| import com.iformall.utils.DateUtils; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.LinkedHashMap; | |||
| import java.util.Map; | |||
| /** | |||
| */ | |||
| @TableName(value = "wx_energy_reading_calcute") | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class WxEnergyReadingCalcute extends TenantEntity { | |||
| private static final long serialVersionUID = 7009117540201976664L; | |||
| @io.swagger.annotations.ApiModelProperty(value="id",name="id") | |||
| private Long id; | |||
| @io.swagger.annotations.ApiModelProperty(value="createTime",name="createTime") | |||
| private Date createTime; | |||
| @io.swagger.annotations.ApiModelProperty(value="updateTime",name="updateTime") | |||
| private Date updateTime; | |||
| @io.swagger.annotations.ApiModelProperty(value="createBy",name="createBy") | |||
| private Long createBy; | |||
| @io.swagger.annotations.ApiModelProperty(value="createByName",name="createByName") | |||
| private String createByName; | |||
| @io.swagger.annotations.ApiModelProperty(value="updateBy",name="updateBy") | |||
| private Long updateBy; | |||
| @io.swagger.annotations.ApiModelProperty(value="updateByName",name="updateByName") | |||
| private String updateByName; | |||
| @io.swagger.annotations.ApiModelProperty(value="备注",name="remark") | |||
| private String remark; | |||
| @io.swagger.annotations.ApiModelProperty(value="区间ID",name="timeId") | |||
| private Long timeId; | |||
| @io.swagger.annotations.ApiModelProperty(value="科目ID",name="feesId") | |||
| private Long feesId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "isImported", name = "isImported") | |||
| private Integer isImported; | |||
| @io.swagger.annotations.ApiModelProperty(value = "isCalcuted", name = "isCalcuted") | |||
| private Integer isCalcuted; | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxEnergyReadingCalcute; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import java.util.List; | |||
| /** | |||
| */ | |||
| public interface WxEnergyReadingCalcuteMapper extends CommonMapper<WxEnergyReadingCalcute, Long> { | |||
| List<WxEnergyReadingCalcute> findList(WxEnergyReadingCalcute wxBillRent); | |||
| WxEnergyReadingCalcute selectById(@Param("id")Long id,@Param("tenantId")String tenantId); | |||
| } | |||
| @@ -1,11 +1,21 @@ | |||
| package com.iformall.service; | |||
| import java.io.File; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.WxEnergyFees; | |||
| import com.iformall.domain.po.WxEnergyFeesTime; | |||
| import com.iformall.domain.po.WxEnergyMeter; | |||
| import com.iformall.domain.po.WxEnergyMeterReading; | |||
| import com.iformall.domain.po.WxEnergyReadingCalcute; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| /** | |||
| */ | |||
| @@ -14,17 +24,26 @@ public interface WxEnergyService { | |||
| //费用区间 | |||
| PageInfo<WxEnergyFeesTime> timeListAsPage(WxEnergyFeesTime record, Integer pageIndex, Integer pageSize); | |||
| void saveOrUpdateTime(WxEnergyFeesTime record); | |||
| WxEnergyFeesTime getFeesTimeById(WxEnergyFeesTime record); | |||
| void setTimeIsDel(WxEnergyFeesTime record); | |||
| //费用科目 | |||
| PageInfo<WxEnergyFees> feesListAsPage(WxEnergyFees record, Integer pageIndex, Integer pageSize); | |||
| void saveOrUpdateFees(WxEnergyFees record); | |||
| WxEnergyFees getFeesById(WxEnergyFees record); | |||
| void setFeesIsDel(WxEnergyFees record); | |||
| //抄表数据 | |||
| PageInfo<WxEnergyMeterReading> readingListAsPage(WxEnergyMeterReading record, Integer pageIndex, Integer pageSize); | |||
| void saveOrUpdateReading(WxEnergyMeterReading record,MallUserInfo userInfo); | |||
| void commitReading(WxEnergyMeterReading record,MallUserInfo userInfo); | |||
| //抄表科目计算数据 | |||
| PageInfo<WxEnergyReadingCalcute> readingCalcuteListAsPage(WxEnergyReadingCalcute record, Integer pageIndex, Integer pageSize); | |||
| void saveOrUpdateReadingCalcute(WxEnergyReadingCalcute record,MallUserInfo userInfo); | |||
| WxEnergyReadingCalcute getReadingCalcuteById(WxEnergyReadingCalcute record); | |||
| void exportReadingCalcute(WxEnergyReadingCalcute record,HttpServletRequest request, HttpServletResponse response); | |||
| void importReadingCalcute(MultipartFile mFile, MallUserInfo user, HttpServletRequest request, HttpServletResponse response); | |||
| /** | |||
| * 根据实体查询列表 | |||
| * @param record | |||
| @@ -1,19 +1,41 @@ | |||
| package com.iformall.service.impl; | |||
| import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumYesOrNo; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import cn.afterturn.easypoi.excel.ExcelImportUtil; | |||
| import cn.afterturn.easypoi.excel.entity.ImportParams; | |||
| import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; | |||
| import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl; | |||
| import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; | |||
| import org.apache.shiro.session.UnknownSessionException; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Lazy; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.io.BufferedInputStream; | |||
| import java.io.File; | |||
| import java.io.FileOutputStream; | |||
| import java.io.IOException; | |||
| import java.util.*; | |||
| import java.util.concurrent.TimeUnit; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| /** | |||
| */ | |||
| @@ -31,6 +53,21 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| WxEnergyFeesTimeMapper wxEnergyFeesTimeMapper; | |||
| @Autowired | |||
| WxEnergyFeesMapper wxEnergyFeesMapper; | |||
| @Autowired | |||
| WxEnergyReadingCalcuteMapper wxEnergyReadingCalcuteMapper; | |||
| @Lazy | |||
| @Autowired | |||
| private WxMallBuildingService wxMallBuildingService; | |||
| @Lazy | |||
| @Autowired | |||
| WxMallFloorService wxMallFloorService; | |||
| @Autowired | |||
| ExcelService excelService; | |||
| @Autowired | |||
| private String fmUploadDir; | |||
| @Override | |||
| @@ -58,6 +95,12 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| } | |||
| } | |||
| @Override | |||
| public WxEnergyFeesTime getFeesTimeById(WxEnergyFeesTime record) { | |||
| return wxEnergyFeesTimeMapper.selectById(record.getId(), record.getTenantId()); | |||
| } | |||
| @Override | |||
| public void setTimeIsDel(WxEnergyFeesTime record) { | |||
| wxEnergyFeesTimeMapper.setIsDel(record.getId(), record.getTenantId(), record.getIsDel()); | |||
| @@ -88,6 +131,11 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| wxEnergyFeesMapper.updateById(record); | |||
| } | |||
| } | |||
| @Override | |||
| public WxEnergyFees getFeesById(WxEnergyFees record) { | |||
| return wxEnergyFeesMapper.selectById(record.getId(), record.getTenantId()); | |||
| } | |||
| @Override | |||
| public void setFeesIsDel(WxEnergyFees record) { | |||
| @@ -176,8 +224,215 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @Override | |||
| public PageInfo<WxEnergyReadingCalcute> readingCalcuteListAsPage(WxEnergyReadingCalcute record, Integer pageIndex, | |||
| Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxEnergyReadingCalcuteMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public void saveOrUpdateReadingCalcute(WxEnergyReadingCalcute record, MallUserInfo userInfo) { | |||
| Date date = new Date(); | |||
| if (record.getId() == null) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| record.setCreateTime(date); | |||
| record.setCreateBy(userInfo.getId()); | |||
| record.setCreateByName(userInfo.getName()); | |||
| record.setUpdateTime(date); | |||
| record.setUpdateBy(userInfo.getId()); | |||
| record.setUpdateByName(userInfo.getName()); | |||
| try { | |||
| wxEnergyReadingCalcuteMapper.insert(record); | |||
| } catch (Exception e) { | |||
| logger.error("保存租赁账单失败,e:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||
| } | |||
| } else { | |||
| record.setUpdateTime(date); | |||
| record.setUpdateBy(userInfo.getId()); | |||
| record.setUpdateByName(userInfo.getName()); | |||
| wxEnergyReadingCalcuteMapper.updateById(record); | |||
| } | |||
| } | |||
| @Override | |||
| public WxEnergyReadingCalcute getReadingCalcuteById(WxEnergyReadingCalcute record) { | |||
| return wxEnergyReadingCalcuteMapper.selectById(record.getId(), record.getTenantId()); | |||
| } | |||
| @Override | |||
| public void exportReadingCalcute(WxEnergyReadingCalcute record, HttpServletRequest request, HttpServletResponse response) { | |||
| WxEnergyFeesTime tq = new WxEnergyFeesTime(); | |||
| tq.updateTenantInfo(record); | |||
| tq.setId(record.getTimeId()); | |||
| WxEnergyFeesTime time = this.getFeesTimeById(tq); | |||
| if (null == time) { | |||
| return; | |||
| } | |||
| WxEnergyFees fq = new WxEnergyFees(); | |||
| fq.updateTenantInfo(record); | |||
| fq.setId(record.getFeesId()); | |||
| WxEnergyFees fees = this.getFeesById(fq); | |||
| if (null == fees) { | |||
| return; | |||
| } | |||
| Map<Long, String> buildingMap = wxMallBuildingService.getBuildingMap(record); | |||
| Map<Long, String> floorMap = wxMallFloorService.getFloorMap(record); | |||
| List<Map<String,Object>> execlList = new ArrayList<Map<String,Object>>(); | |||
| WxEnergyMeterReading rq = new WxEnergyMeterReading(); | |||
| rq.updateTenantInfo(record); | |||
| rq.setTimeId(tq.getId()); | |||
| PageInfo<WxEnergyMeterReading> page = this.readingListAsPage(rq, 1, 10000); | |||
| if (null != page && null != page.getList()) { | |||
| for (int i = 0 ; i < page.getList().size(); i++) { | |||
| WxEnergyMeterReading r = page.getList().get(i); | |||
| execlList.add(r.generateExcelData(buildingMap, floorMap, time, fees, record)); | |||
| } | |||
| } | |||
| excelService.exportExcel(WxEnergyMeterReading.generateExcelTitle(),execlList, "科目抄表.xlsx","sheet1", response); | |||
| } | |||
| private File handlerImportFile(MultipartFile mFile,String fileNamePre) { | |||
| if (mFile.isEmpty()) { | |||
| throw new MallinkException(Result.ERROR, "上传文件不能为空"); | |||
| } | |||
| String fpath = fmUploadDir; | |||
| File targetFile = new File(fpath); | |||
| if (!targetFile.exists()) { | |||
| targetFile.mkdirs(); | |||
| } | |||
| String fileName = fileNamePre + Math.round(Math.random() * 100000000000L); | |||
| int dot = mFile.getOriginalFilename().lastIndexOf('.'); | |||
| fileName = fileName + mFile.getOriginalFilename().substring(dot, mFile.getOriginalFilename().length()); | |||
| File lFile = new File(fpath + File.separator + fileName); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| try { | |||
| fos = new FileOutputStream(lFile); | |||
| fs = (BufferedInputStream) mFile.getInputStream(); | |||
| byte[] buffer = new byte[1024]; | |||
| int len = 0; | |||
| while ((len = fs.read(buffer)) != -1) { | |||
| fos.write(buffer, 0, len); | |||
| } | |||
| fos.close(); | |||
| fs.close(); | |||
| return lFile; | |||
| } catch (Exception e) { | |||
| logger.error("import error.",e); | |||
| throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "上传失败"); | |||
| } finally { | |||
| if (fos != null) { | |||
| try { | |||
| fos.close(); | |||
| } catch (IOException e) { | |||
| logger.error("import error.",e); | |||
| throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "上传失败"); | |||
| } | |||
| } | |||
| if (fs != null) { | |||
| try { | |||
| fs.close(); | |||
| } catch (IOException e) { | |||
| logger.error("import error.",e); | |||
| throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), "上传失败"); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| private ExcelImportResult handleImportFile(File file,Class dataClazz,String[] importFields,String[] needFields,IExcelDataHandler handler) { | |||
| ImportParams params = new ImportParams(); | |||
| // 需要验证 | |||
| params.setImportFields(importFields); | |||
| handler.setNeedHandlerFields(needFields); | |||
| params.setNeedVerify(true); | |||
| ExcelImportResult<WxEnergyMeterReading> datalist = null; | |||
| try { | |||
| datalist = ExcelImportUtil.importExcelMore(file, dataClazz, params); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage(),e); | |||
| // 删除缓存文件 | |||
| file.delete(); | |||
| return null; | |||
| } | |||
| // 删除缓存文件 | |||
| file.delete(); | |||
| if(datalist == null) { | |||
| logger.error("导入模板失败: 模板数据解析失败"); | |||
| return null; | |||
| } | |||
| return datalist; | |||
| } | |||
| private class ReadingExcelHandler extends ExcelDataHandlerDefaultImpl<Map> { | |||
| @Override | |||
| public Object importHandler(Map obj, String name, Object value) { | |||
| if (value == null) { | |||
| value = ""; | |||
| } | |||
| return super.importHandler(obj, name, value); | |||
| } | |||
| } | |||
| @Override | |||
| public void importReadingCalcute(MultipartFile mFile, MallUserInfo user, HttpServletRequest request, | |||
| HttpServletResponse response) { | |||
| File file = handlerImportFile(mFile,"energyReading"); | |||
| // 需要验证 | |||
| Map<String,String> excelTitle = WxEnergyMeterReading.generateExcelTitle(); | |||
| String[] needFields = new String[excelTitle.size()]; | |||
| int index = 0; | |||
| for (Iterator<String> it = excelTitle.keySet().iterator(); it.hasNext();) { | |||
| String fi = it.next(); | |||
| needFields[index] = fi; | |||
| index = index + 1; | |||
| } | |||
| ExcelImportResult<Map> datalist = handleImportFile(file,Map.class,needFields,needFields,new ReadingExcelHandler()); | |||
| if (null == datalist) { | |||
| return ; | |||
| } | |||
| List<Map> successList = datalist.getList(); | |||
| if(successList.size() > 0) { | |||
| try { | |||
| Long cuteId = (Long)successList.get(0).get("calcuteId"); | |||
| successList.parallelStream().forEach(reading -> { | |||
| Long id = (Long) reading.get("id"); | |||
| WxEnergyMeterReading r = new WxEnergyMeterReading(); | |||
| r.updateTenantInfo(user); | |||
| r.setId(id); | |||
| r.setPrice((String)reading.get("price")); | |||
| r.setUpdateBy(user.getId()); | |||
| r.setUpdateByName(user.getName()); | |||
| r.setUpdateTime(new Date()); | |||
| wxEnergyMeterReadingMapper.updateById(r); | |||
| }); | |||
| if (null != cuteId) { | |||
| WxEnergyReadingCalcute c= new WxEnergyReadingCalcute(); | |||
| c.updateTenantInfo(user); | |||
| c.setId(cuteId); | |||
| c.setIsImported(EnumYesOrNo.YES.getCode()); | |||
| c.setUpdateTime(new Date()); | |||
| c.setUpdateBy(user.getId()); | |||
| c.setUpdateByName(user.getName()); | |||
| wxEnergyReadingCalcuteMapper.updateById(c); | |||
| } | |||
| } catch (Exception e) { | |||
| logger.error("导入模板失败:"+e.getMessage(),e); | |||
| } | |||
| } | |||
| } | |||
| @@ -218,4 +473,8 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| } | |||
| } | |||
| @@ -0,0 +1,63 @@ | |||
| <?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"> | |||
| <mapper namespace="com.iformall.mapper.WxEnergyReadingCalcuteMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxEnergyReadingCalcute"> | |||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | |||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | |||
| <result column="create_by" jdbcType="BIGINT" property="createBy"/> | |||
| <result column="create_by_name" jdbcType="VARCHAR" property="createByName"/> | |||
| <result column="update_by" jdbcType="BIGINT" property="updateBy"/> | |||
| <result column="update_by_name" jdbcType="VARCHAR" property="updateByName"/> | |||
| <result column="remark" jdbcType="VARCHAR" property="remark"/> | |||
| <result column="time_id" jdbcType="BIGINT" property="timeId"/> | |||
| <result column="fees_id" jdbcType="BIGINT" property="feesId"/> | |||
| <result column="is_calcuted" jdbcType="INTEGER" property="isCalcuted"/> | |||
| <result column="is_imported" jdbcType="INTEGER" property="isImported"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`create_time`,`update_time`,`create_by`,`create_by_name`, | |||
| `update_by`,`update_by_name`,`remark`,`time_id`,`fees_id`,`is_calcuted`,`is_imported` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1=1 | |||
| <if test=" null != id ">and `id` = #{id}</if> | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| <if test=" null != createBy ">and `create_by` = #{createBy}</if> | |||
| <if test=" null != timeId ">and `time_id` = #{timeId}</if> | |||
| <if test=" null != feesId ">and `fees_id` = #{feesId}</if> | |||
| <if test=" null != isCalcuted ">and `is_calcuted` = #{isCalcuted}</if> | |||
| <if test=" null != isImported ">and `is_imported` = #{isImported}</if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxEnergyReadingCalcute" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from wx_energy_reading_calcute | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <select id="selectById" parameterType="HashMap" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from wx_energy_reading_calcute where id = #{id} and `tenant_id` = #{tenantId} | |||
| </select> | |||
| </mapper> | |||