package com.caimei.service.user.impl; import com.caimei.entity.*; import com.caimei.mapper.products.HomePageMapper; import com.caimei.mapper.user.PersonalMapper; import com.caimei.service.user.PersonalService; import com.github.pagehelper.PageHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class PersonalServiceImpl implements PersonalService { protected static final Logger logger = LoggerFactory.getLogger(PersonalServiceImpl.class); @Autowired private PersonalMapper personalMapper; @Autowired private HomePageMapper homePageMapper; @Override public Club myCentre(CmOperationUser operationUser) { Club club = personalMapper.myCentre(operationUser); if (club != null) { Double ableUserMoney = club.getAbleUserMoney(); String userMoney = String.format("%.2f", ableUserMoney); club.setUserMoney(userMoney); //购物车数量 Integer count = homePageMapper.cartQuantity(club.getUserID()); if (count == null) count = 0; logger.info("------------PersonalServiceImpl.myCentre.count:" + count); club.setCartCount(count); } return club; } @Override public Map touchBalance(Integer index, Integer pageSize, int year, int month, CmUserBalanceRecord balanceRecord) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, calendar.getMinimum(Calendar.DATE)); String startTime = format.format(calendar.getTime()) + " 00:00:00"; balanceRecord.setStartTime(startTime); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DATE)); String endTime = format.format(calendar.getTime()) + " 23:59:59"; balanceRecord.setEndTime(endTime); if (index == null) index = 1; if (pageSize == null) pageSize = 10; PageHelper.startPage(index, pageSize); List list = personalMapper.touchBalance(balanceRecord); Page page = new Page<>(list); Double ableUserMoney = personalMapper.ableUserMoney(balanceRecord.getUserId()); if (ableUserMoney == null) ableUserMoney = 0d; String userMoney = String.format("%.2f", ableUserMoney); Map map = new HashMap(); map.put("page", page); map.put("ableUserMoney", userMoney); return map; } @Override public List address() { List list = personalMapper.findAllProvince(); for (Province province : list) { List cityList = personalMapper.findAllCity(province.getProvinceid()); province.setCitys(cityList); if (cityList != null && cityList.size() > 0) { for (City city : cityList) { List townList = personalMapper.findAllTown(city.getCityid()); city.setTowns(townList); } } } return list; } @Override public List
findAddress(Integer userID) { List
addressList = personalMapper.findAddress(userID); for (Address address : addressList) { Address cantonal = personalMapper.findCantonal(address.getTownID()); if (cantonal != null) { address.setProvince(cantonal.getProvince()); address.setCity(cantonal.getCity()); address.setTown(cantonal.getTown()); } } return addressList; } @Override public List getProvince() { List list = personalMapper.findAllProvince(); return list; } @Override public List getCity(Long provinceid) { return personalMapper.findAllCity(provinceid); } @Override public List getTown(Integer cityid) { return personalMapper.findAllTown(cityid); } @Override public void saveAddress(Address address) { if (address.getDefaultFlag() != null && address.getDefaultFlag().equals("1")) { Address addr = personalMapper.findDefaultAddress(address.getUserID()); if (addr != null) { addr.setDefaultFlag("0"); personalMapper.updateAddress(addr); } } if (address.getAddressID() == null) { personalMapper.saveAddress(address); } else { personalMapper.updateAddress(address); } } @Override public void deleteAddress(Integer addressID) { personalMapper.deleteAddress(addressID); } @Override public WxJsonModel invoice(UserInvoiceInfo userInvoiceInfo) { WxJsonModel res = WxJsonModel.newInstance(); UserInvoiceInfo invoiceInfo = personalMapper.findInvoice(userInvoiceInfo.getUserId()); if (invoiceInfo == null && userInvoiceInfo.getInvoiceTitle() != null) { personalMapper.invoice(userInvoiceInfo); } else if (invoiceInfo != null && userInvoiceInfo.getInvoiceTitle() != null) { personalMapper.updateInvoice(userInvoiceInfo); } UserInvoiceInfo info = personalMapper.findInvoice(userInvoiceInfo.getUserId()); return res.success(info); } }